These two actions, SoToVRMLAction SoToVRMLAction SoToVRMLAction and SoToVRML2Action SoToVRML2Action SoToVRML2Action , are applied in the same manner as any other action. They convert an Open Inventor scene graph to a VRML 1.0 format or VRML97 (X3D) format scene graph respectively.
Many options can be set. For instance, to keep unknown nodes, use the keepUnknownNodes() method. If shared geometry nodes in the input scene graph should be shared in the new scene graph, use the reuseGeometryNode() method. All these options must be set before applying the action.
As with other actions, the apply() method must be called on an Inventor scene graph.
getVRMLSceneGraph() returns a VRML 1.0-style scene graph.
getVRML2SceneGraph() returns a VRML 2.0-style scene graph.
The SoWriteAction SoWriteAction SoWriteAction action must be used to generate the VRML 1.0 (or 2.0) file. You must remember to specify the correct header string with the method SoOutput::setHeaderString() . You must also specify that the file is an ASCII file (the only storage mode available in VRML) with the method SoOutput::setBinary(FALSE) . The header strings should be:
#VRML V1.0 ascii
for VRML 1.0, and
#VRML V2.0 utf8
for VRML 2.0
Example 13.6. Example of conversion from Inventor format to VRML 2.0 format
This shows the conversion of an Inventor file containing a red cube with a translation (1, 0, 0) to a VRML 2.0 file using SoToVRML2Action.
Example 13.7. Extract of IvToVRMLAction.cxx
The example supplied in: $OIVHOME/src/Inventor/examples/Features/IvToVRMLAction/IvToVRMLAction.cxx
is a utility that takes an Open Inventor file (.iv file) as an input
parameter and generates a VRML 1.0 or VRML 2.0 file (depending on a command line option) as
output.
The following code fragment shows the use of SoToVRML2Action SoToVRML2Action SoToVRML2Action in the source code of IvToVRMLAction.cxx:
... Read Inventor input file in the separator umbrellaRoot. ... SoToVRML2Action *toVRML2Action = new SoToVRML2Action; toVRML2Action->apply(umbrellaRoot); SoNode *convertedRoot = (SoNode *) toVRML2Action->getVRML2SceneGraph(); convertedRoot->ref(); SoOutput out; out.openFile(outputfile); out.setBinary(FALSE); out.setHeaderString("#VRML V2.0 utf8"); SoWriteAction writeAction(&out); writeAction.apply(convertedRoot); out.closeFile();
... Read Inventor input file in the separator root. ... SoToVRML2Action toVRML2Action = new SoToVRML2Action(); toVRML2Action.apply(root); SoNode convertedRoot = (SoNode ) toVRML2Action.getVRML2SceneGraph(); SoOutput out = new SoOutput(); out.openFile(outputFile); out.setBinary(false); out.setHeaderString("#VRML V2.0 utf8"); SoWriteAction writeAction = new SoWriteAction(out); writeAction.apply(convertedRoot); out.closeFile();