SoInput, SoOutput, SoWriteAction, SoSearchAction使用

本文介绍如何使用Inventor进行场景搜索,查找场景中的光源,并在未找到光源的情况下添加方向光灯。代码示例涵盖了从读取场景文件到应用搜索动作和写入操作的完整流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*------------------------------------------------------------ * Search Action example. * Read in a scene from a file. * Search through the scene looking for a light. * If none exists, add a directional light to the scene * and print out the modified scene. *-----------------------------------------------------------*/ #include <Inventor/SoDB.h> #include <Inventor/actions/SoSearchAction.h> #include <Inventor/actions/SoWriteAction.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoSeparator.h> int main(int, char **) { // Initialize Inventor SoDB::init(); #ifdef WIN32 SoOutput conOut; conOut.setFilePointer(__AllocConsole()); #endif // Open and read input scene graph SoInput sceneInput; if (! sceneInput.openFile("../data/bird.iv")) return 1; SoSeparator *root = SoDB::readAll(&sceneInput); if (root == NULL) return 1; root->ref(); // // CODE FOR The Inventor Mentor STARTS HERE SoSearchAction mySearchAction; // Look for first existing light derived from class SoLight mySearchAction.setType(SoLight::getClassTypeId()); mySearchAction.setInterest(SoSearchAction::FIRST); mySearchAction.apply(root); if (mySearchAction.getPath() == NULL) { // No lights found // Add a default directional light to the scene SoDirectionalLight *myLight = new SoDirectionalLight; root->insertChild(myLight, 0); } // CODE FOR The Inventor Mentor ENDS HERE // #ifdef WIN32 SoWriteAction myWriteAction(&conOut); #else SoWriteAction myWriteAction; #endif myWriteAction.apply(root); // #ifdef WIN32 // conOut.flushFile(); // #endif root->unref(); // The usual exit(0) has been replaced with exit(1) to enable the console // window showing the output to stay on the screen until the user deletes it exit(1); return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值