bool VRMLSceneFileType::write(Node * const node, std::ostream &os, Char8 const *fileNameOrExtension) const { // This is a hack but should be safer. std::ofstream *osf = dynamic_cast<std::ofstream *>(&os); if(osf != NULL) osf->close(); VRMLWriteAction *pWriter = VRMLWriteAction::create(); // parse options bool inlineTex = false; if(getOptionAs<bool>("inlineTextures", inlineTex)) { if(inlineTex) pWriter->addOptions(VRMLWriteAction::OSGPixelTextures); else pWriter->subOptions(VRMLWriteAction::OSGPixelTextures); } pWriter->open(fileNameOrExtension); pWriter->write(node); pWriter->close(); delete pWriter; return true; }
int main (int argc, char **argv) { NodePtr node; osgInit(argc, argv); NodePtr pScene = Node::create(); GroupPtr pSceneGroup = Group::create(); pScene->setCore(pSceneGroup); setName(pScene, "foo"); setName(pSceneGroup, "bar"); NodePtr pSceneChild = Node::create(); // NodeCorePtr pSceneChildCore = Group::create(); NodeCorePtr pSceneChildCore = makeSphereGeo(3, 1); pSceneChild->setCore(pSceneChildCore); setName(pSceneChild, "foo1"); // setName(pSceneChildCore, "bar1"); pScene->addChild(pSceneChild); pSceneChild = Node::create(); // pSceneChildCore = Group::create(); // pSceneChildCore = makeSphereGeo(3, 1); pSceneChild->setCore(pSceneChildCore); // setName(pSceneChild, "foo2"); setName(pSceneChildCore, "bar2"); pScene->addChild(pSceneChild); pSceneChild = Node::create(); pSceneChildCore = Group::create(); pSceneChild->setCore(pSceneChildCore); setName(pSceneChild, "foo3"); setName(pSceneChildCore, "bar3"); pScene->addChild(pSceneChild); pSceneChild = Node::create(); pSceneChildCore = Group::create(); pSceneChild->setCore(pSceneChildCore); setName(pSceneChild, "foo4"); setName(pSceneChildCore, "bar4"); pScene->addChild(pSceneChild); pSceneChild = Node::create(); // pSceneChildCore = Group::create(); pSceneChild->setCore(pSceneChildCore); setName(pSceneChild, "foo4"); // setName(pSceneChildCore, "bar4"); pScene->addChild(pSceneChild); VRMLWriteAction *pWriter = VRMLWriteAction::create(); pWriter->addOptions(VRMLWriteAction::OSGNoNormals); //VRMLWriteAction::OSGNoIndent | pWriter->open((argc > 2) ? argv[2] : "test.wrl"); pWriter->write(pScene); pWriter->close(); return 0; }