Open Inventor显示区域设置SoReoriganizeAction

The code below is an example of a program that applies an SoReorganizeAction on a scene graph, converting all shapes into shapes that can be rendered using vertex array or VBO rendering.

#include <Inventor/SoDB.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoCoordinate3.h> #include <Inventor/nodes/SoCoordinate4.h> #include <Inventor/nodes/SoNormal.h> #include <Inventor/nodes/SoTextureCoordinate2.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/actions/SoWriteAction.h> #include <Inventor/actions/SoSearchAction.h> #include <Inventor/errors/SoDebugError.h> #include <Inventor/nodes/SoShapeHints.h> #include <Inventor/SoInput.h> #include <Inventor/SoOutput.h> #include <Inventor/SoInteraction.h> #include <Inventor/actions/SoReorganizeAction.h> #include <cassert> #include <cstdio> static void strip_node(SoType type, SoNode * root) { SoSearchAction sa; sa.setType(type); sa.setSearchingAll(TRUE); sa.setInterest(SoSearchAction::ALL); sa.apply(root); SoPathList & pl = sa.getPaths(); for (int i = 0; i < pl.getLength(); i++) { SoFullPath * p = (SoFullPath*) pl[i]; if (p->getTail()->isOfType(type)) { SoGroup * g = (SoGroup*) p->getNodeFromTail(1); g->removeChild(p->getIndexFromTail(0)); } } sa.reset(); } int main(int argc, char ** argv ) { if (argc < 3) { fprintf(stderr,"Usage: reorganize <infile> <outfile> [nostrip]/n"); return -1; } SbBool strip = TRUE; if (argc > 3) { if (strcmp(argv[3], "nostrip") == 0) strip = FALSE; else { fprintf(stderr,"Usage: reorganize <infile> <outfile> [nostrip]/n"); return -1; } } SoDB::init(); SoInteraction::init(); SoInput input; SbBool ok = input.openFile(argv[1]); if (!ok) { fprintf(stderr,"Unable to open file./n"); return -1; } SoSeparator * root = SoDB::readAll(&input); SbBool vrml1 = input.isFileVRML1(); SbBool vrml2 = input.isFileVRML2(); if (vrml2) { fprintf(stderr,"VRML2 not supported yet/n"); return -1; } if (!root) { fprintf(stderr,"Unable to read file./n"); return -1; } root->ref(); fprintf(stderr,"Applying SoReorganizeAction..."); SoReorganizeAction reorg; reorg.apply(root); fprintf(stderr,"done/n"); SoOutput out; if (out.openFile(argv[2])) { if (strip) { // strip coord3, texcoord and normal nodes fprintf(stderr,"stripping old nodes from scene graph/n"); strip_node(SoCoordinate3::getClassTypeId(), root); strip_node(SoCoordinate4::getClassTypeId(), root); strip_node(SoNormal::getClassTypeId(), root); strip_node(SoTextureCoordinate2::getClassTypeId(), root); } fprintf(stderr,"writing target/n"); SoWriteAction wa(&out); wa.apply(root); } root->unref(); return 0; } // main()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值