bison -ydv vrml.y mv y.tab.c vrml.tab.cpp mv y.tab.h vrml.tab.h flex -I vrml.l mv lex.yy.c vrml.yy.cppWhen you make the library with no compiler flags, you can only load a VRML file, modify the scene graph Infomation and save the scene graph into a VRML file . If you want to draw the geometries or execute the behaviors, you have to set the following compiler flag .
| COMPILER FLAG | PURPOSE REQUIREMENTS |
|---|---|
| SUPPORT_OPENGL | Drawing geometry nodes using OpenGL? . OpenGL? 1.1 library |
| SUPPORT_GLUT | Drawing geometry nodes using GLUT with OpenGL? GLUT 3.x library |
| SUPPORT_JPEG | Loading JPEG image files in ImageTexture? nodes Independent JPEG Group's library |
| SUPPORT_PNG | Loading JPEG image files in ImageTexture? nodes libpng / zlib |
| SUPPORT_JSAI | Executing behaviors in Script nodes. Java Development Kit 1.1.x CyberVRML97 for Java Release 1.0.2a |
| SUPPORT_OLDCPP | Supports some old c++ compilers. |
class SceneGraph {
////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////
SceneGraph();
////////////////////////////////////////////////////////
// File input / output
////////////////////////////////////////////////////////
void load(char *filename);
void add(char *filename);
void save(char *filename);
////////////////////////////////////////////////////////
// Add a node
////////////////////////////////////////////////////////
void addNode(Node *node);
////////////////////////////////////////////////////////
// Get a first list node
////////////////////////////////////////////////////////
Node getNodes()
////////////////////////////////////////////////////////
// Get a first specific node in scene graph
////////////////////////////////////////////////////////
AnchorNode *getAnchorNodes()
AppearanceNode *getAppearanceNodes()
AudioClipNode *getAudioClipNodes()
BackgroundNode *getBackgroundNodes()
BillboardNode *getBillboardNodes()
BoxNode *getBoxeNodes()
CollisionNode *getCollisionNodes()
ColorNode *getColorNodes()
ColorinterpolatorNode *getColorinterpolatorNodes()
ConeNode *getConeNodes()
CoordinateNode *getCoordinateNodes()
CoordinateinterpolatorNode *getCoordinateinterpolatorNodes()
CylinderNode *getCylinderNodes()
CylinderSensorNode *getCylinderSensorNodes()
DirectionalLightNode *getDirectionalLightNodes()
ElevationGridNode *getElevationGridNodes()
ExtrusionNode *getExtrusionNodes()
FogNode *getFogNodes()
FontStyleNode *getFontStyleNodes()
GroupNode *getGroupNodes()
Ima*getextureNode *getIma*getextureNodes()
IndexedFaceSetNode *getIndexedFaceSetNodes()
IndexedLineSetNode *getIndexedLineSetNodes()
InlineNode *getInlineNodes()
LodNode *getLodNodes()
MaterialNode *getMaterialNodes()
MovieTextureNode *getMovieTextureNodes()
NavigationInfoNode *getNavigationInfoNodes()
NormalNode *getNormalNodes()
NormalinterpolatorNode *getNormalinterpolatorNodes()
OrientationinterpolatorNode *getOrientationinterpolatorNodes()
PixelTextureNode *getPixelTextureNodes()
PlaneSensorNode *getPlaneSensorNodes()
PointLightNode *getPointLightNodes()
PointSetNode *getPointSetNodes()
PositioninterpolatorNode *getPositioninterpolatorNodes()
ProximitySensorNode *getProximitySensorNodes()
ScalarinterpolatorNode *getScalarinterpolatorNodes()
ScriptNode *getScriptNodes()
ShapeNode *getShapeNodes()
SoundNode *getSoundNodes()
SphereNode *getSphereNodes()
SphereSensorNode *getSphereSensorNodes()
SpotLightNode *getSpotLightNodes()
SwitchNode *getSwitchNodes()
TextNode *getTextNodes()
TextureCoordinateNode *getTextureCoordinateNodes()
TextureTransformNode *getTextureTransformNodes()
TimeSensorNode *getTimeSensorNodes()
TouchSensorNode *getTouchSensorNodes()
TransformNode *getTransformNodes()
ViewpointNode *getViewpointNodes()
VisibilitySensorNode *getVisibilitySensorNodes()
WorldInfoNode *getWorldInfoNodes()
////////////////////////////////////////////////////////
// Find a first specific node in scene graph
////////////////////////////////////////////////////////
AnchorNode *findAnchorNode();
AppearanceNode *findAppearanceNode();
AudioClipNode *findAudioClipNode();
BackgroundNode *findBackgroundNode();
BillboardNode *findBillboardNode();
BoxNode *findBoxeNode();
CollisionNode *findCollisionNode();
ColorNode *findColorNode();
ColorInterpolatorNode *findColorInterpolatorNode();
ConeNode *findConeNode();
CoordinateNode *findCoordinateNode();
CoordinateInterpolatorNode *findCoordinateInterpolatorNode();
CylinderNode *findCylinderNode();
CylinderSensorNode *findCylinderSensorNode();
DirectionalLightNode *findDirectionalLightNode();
ElevationGridNode *findElevationGridNode();
ExtrusionNode *findExtrusionNode();
FogNode *findFogNode();
FontStyleNode *findFontStyleNode();
GroupNode *findGroupNode();
ImageTextureNode *findImageTextureNode();
IndexedFaceSetNode *findIndexedFaceSetNode();
IndexedLineSetNode *findIndexedLineSetNode();
InlineNode *findInlineNode();
LodNode *findLodNode();
MaterialNode *findMaterialNode();
MovieTextureNode *findMovieTextureNode();
NavigationInfoNode *findNavigationInfoNode();
NormalNode *findNormalNode();
NormalInterpolatorNode *findNormalInterpolatorNode();
OrientationInterpolatorNode *findOrientationInterpolatorNode();
PixelTextureNode *findPixelTextureNode();
PlaneSensorNode *findPlaneSensorNode();
PointLightNode *findPointLightNode();
PointSetNode *findPointSetNode();
PositionInterpolatorNode *findPositionInterpolatorNode();
ProximitySensorNode *findProximitySensorNode();
ScalarInterpolatorNode *findScalarInterpolatorNode();
ScriptNode *findScriptNode();
ShapeNode *findShapeNode();
SoundNode *findSoundNode();
SphereNode *findSphereNode();
SphereSensorNode *findSphereSensorNode();
SpotLightNode *findSpotLightNode();
SwitchNode *findSwitchNode();
TextNode *findTextNode();
TextureCoordinateNode *findTextureCoordinateNode();
TextureTransformNode *findTextureTransformNode();
TimeSensorNode *findTimeSensorNode();
TouchSensorNode *findTouchSensorNode();
TransformNode *findTransformNode();
ViewpointNode *findViewpointNode();
VisibilitySensorNode *findVisibilitySensorNode();
WorldInfoNode *findWorldInfoNode();
////////////////////////////////////////////////////////
// for Java (JSAI)
////////////////////////////////////////////////////////
setJavaEnv(char *javaClassPath, jint (JNICALL *printfn)(FILE *fp, const char *format, va_list args));
////////////////////////////////////////////////////////
// Update all node and route Infomation
////////////////////////////////////////////////////////
void update();
}
Use load() to load a scene graph information from a VRML file, and use save() to save a current scene graph information as a VRML file. The sample is below.
SceneGraph *sceneGraph = new SceneGraph();
sceneGraph->load("world.wrl");
..........
sceneGraph->save("newworld.wrl");
After the loading , the SceneGraph? instance has instances of the VRML nodes using Node class. The Node class is a super class of all VRML node classes. There are two ways to get the nodes.
The first way is to use getNodes() of SceneGraph? class with next() and getChildNodes() of Node class. For example, if you want to get all viewpoint nodes in the scene graph .....
void GetViewpointInfomation(Node *node)
{
if (node->isViewpointNode()) {
ViewpointNode *view = (Viewpoint *)node;
// Get a viewpoint information
..........
}
for (Node *cnode=node->getChildNodes(); cnode; cnode=cnode->next())
GetViewpointInfomation(cnode);
}
void main()
{
..........
SceneGraph *sceneGraph = new SceneGraph();
sceneGraph->load("world.wrl");
for (Node *node=sceneGraph->getNodes(); node; node=node->next())
GetViewpointInfomation(node);
..........
}
The second way is to use getNodes() of SceneGraph? class with only nextTraversal() of Node class. The way is handier than the first one. For example, if you want to get all viewpoint nodes in the scene graph .....
void main()
{
..........
SceneGraph *sceneGraph = new SceneGraph();
sceneGraph->load("world.wrl");
for (Node *node=sceneGraph->getNodes(); node; node=node->nextTraversal())
if (node->isViewpoint()) {
ViewpointNode *view = (ViewpointNode *)node;
// Get a viewpoint information
..........
}
}
..........
}
If you want to get only nodes of the same type, use find*Node() instead of getNodes(). For example, if you want to get only viewpoint nodes in the scene graph .....
void main()
{
..........
SceneGraph *sceneGraph = new SceneGraph();
sceneGraph->load("world.wrl");
for (ViewpointNode *view=sceneGraph->findViewpointNode();
view; view=view->nextTraversal()) {
// Get a viewpoint information
..........
}
..........
}
Use update() to update the internal nodes and routes to execute the behaviors in the scene graph.
class Node {
////////////////////////////////////////////////////////
// Get a define and type name
////////////////////////////////////////////////////////
char *getType()
char *getName()
////////////////////////////////////////////////////////
// Get a next node of list
////////////////////////////////////////////////////////
Node *next ()
Node *nextTraversal ()
////////////////////////////////////////////////////////
// Add a child node
////////////////////////////////////////////////////////
void addChildNode(Node *node)
////////////////////////////////////////////////////////
// Remove the node
////////////////////////////////////////////////////////
void remove ()
////////////////////////////////////////////////////////
// Get a first child node
////////////////////////////////////////////////////////
Node *getChildNodes()
////////////////////////////////////////////////////////
// Get a first specific child node
////////////////////////////////////////////////////////
AnchorNode *getAnchorNodes()
AppearanceNode *getAppearanceNodes()
AudioClipNode *getAudioClipNodes()
BackgroundNode *getBackgroundNodes()
BillboardNode *getBillboardNodes()
BoxNode *getBoxeNodes()
CollisionNode *getCollisionNodes()
ColorNode *getColorNodes()
ColorinterpolatorNode *getColorinterpolatorNodes()
ConeNode *getConeNodes()
CoordinateNode *getCoordinateNodes()
CoordinateinterpolatorNode *getCoordinateinterpolatorNodes()
CylinderNode *getCylinderNodes()
CylinderSensorNode *getCylinderSensorNodes()
DirectionalLightNode *getDirectionalLightNodes()
ElevationGridNode *getElevationGridNodes()
ExtrusionNode *getExtrusionNodes()
FogNode *getFogNodes()
FontStyleNode *getFontStyleNodes()
GroupNode *getGroupNodes()
Ima*getextureNode *getIma*getextureNodes()
IndexedFaceSetNode *getIndexedFaceSetNodes()
IndexedLineSetNode *getIndexedLineSetNodes()
InlineNode *getInlineNodes()
LodNode *getLodNodes()
MaterialNode *getMaterialNodes()
MovieTextureNode *getMovieTextureNodes()
NavigationInfoNode *getNavigationInfoNodes()
NormalNode *getNormalNodes()
NormalinterpolatorNode *getNormalinterpolatorNodes()
OrientationinterpolatorNode *getOrientationinterpolatorNodes()
PixelTextureNode *getPixelTextureNodes()
PlaneSensorNode *getPlaneSensorNodes()
PointLightNode *getPointLightNodes()
PointSetNode *getPointSetNodes()
PositioninterpolatorNode *getPositioninterpolatorNodes()
ProximitySensorNode *getProximitySensorNodes()
ScalarinterpolatorNode *getScalarinterpolatorNodes()
ScriptNode *getScriptNodes()
ShapeNode *getShapeNodes()
SoundNode *getSoundNodes()
SphereNode *getSphereNodes()
SphereSensorNode *getSphereSensorNodes()
SpotLightNode *getSpotLightNodes()
SwitchNode *getSwitchNodes()
TextNode *getTextNodes()
TextureCoordinateNode *getTextureCoordinateNodes()
TextureTransformNode *getTextureTransformNodes()
TimeSensorNode *getTimeSensorNodes()
TouchSensorNode *getTouchSensorNodes()
TransformNode *getTransformNodes()
ViewpointNode *getViewpointNodes()
VisibilitySensorNode *getVisibilitySensorNodes()
WorldInfoNode *getWorldInfoNodes()
////////////////////////////////////////////////////////
// Confirm the node type
////////////////////////////////////////////////////////
int isAnchorNode()
int isAppearanceNode()
int isAudioClipNode()
int isBackgroundNode()
int isBillboardNode()
int isBoxNode()
int isCollisionNode()
int isColorNode()
int isColorinterpolatorNode()
int isConeNode()
int isCoordinateNode()
int isCoordinateinterpolatorNode()
int isCylinderNode()
int isCylinderSensorNode()
int isDirectionalLightNode()
int isElevationGridNode()
int isExtrusionNode()
int isFogNode()
int isFontStyleNode()
int isGroupNode()
int isImageTextureNode()
int isIndexedFaceSetNode()
int isIndexedLineSetNode()
int isInlineNode()
int isLodNode()
int isMaterialNode()
int isMovieTextureNode()
int isNavigationInfoNode()
int isNormalNode()
int isNormalinterpolatorNode()
int isOrientationinterpolatorNode()
int isPixelTextureNode()
int isPlaneSensorNode()
int isPointLightNode()
int isPointSetNode()
int isPositioninterpolatorNode()
int isProximitySensorNode()
int isScalarinterpolatorNode()
int isScriptNode()
int isShapeNode()
int isSoundNode()
int isSphereNode()
int isSphereSensorNode()
int isSpotLightNode()
int isSwitchNode()
int isTextNode()
int isTextureCoordinateNode()
int isTextureTransformNode()
int isTimeSensorNode()
int isTouchSensorNode()
int isTransformNode()
int isViewpointNode()
int isVisibilitySensorNode()
int isWorldInfoNode()
////////////////////////////////////////////////////////
// Get fields
////////////////////////////////////////////////////////
Field *getEventIn(char *fieldName)
Field *getEventOut(char *fieldName)
Field *getExposedField(char *fieldName)
Field *getField(char *fieldName)
////////////////////////////////////////////////////////
// Update internal Infomation
////////////////////////////////////////////////////////
void update()
}
If you want to get a next node from a current node, use next(). The method returns a next node in the list, or returns NULL if the next node does not exist. The method is overriden in the sub classes, ViewpointNode? class etc. The overriden method returns a next node which is the same node type. For example, the method of AppearanceNode? class is overrided as below.
class AppearanceNode : public Node {
AppearanceNode *next() { return (AppearanceNode *)Node::next(getType()); }
}
The nextTraversal() is similer to the next(), but the method tries to get a next node from the parent node when the next node does not exist. This method is overriden in the sub classes, too.
class AppearanceNode : public Node {
AppearanceNode *nextTraversal() {return (AppearanceNode *)Node::nextTraversalByType(getType());
}
class AnchorNode extends GroupingNode {
// Description
char *getDescription()
// Parameter
int getNParameters()
char *getParameter(int index)
// URL
int getNUrls()
char *getUrl(int index)
}
SceneGraph sg;
sg.load("world.wrl");
// Remove first PointLight node
PointLightNode *plight = sg.findPointLightNode();
if (plight != NULL)
plight->remove();
// Add a new spehere
ShapeNode *shape = new ShapeNode();
sg.addNode(shape);
Appearancenode *app = new AppearanceNode();
shape->addChildNode(app);
MaterialNode *mat = new MaterialNode();
mat->setDiffuseColor(1.0f, 0.0f, 0.0f); // Red
app->addChildNode(mat);
SphereNode *sphere = new SphereNode();
shape->addChildNode(sphere);
sphere->setRadius(10.0f);
sg.save("new_world.wrl");
If you want to display the new added nodes, you have to call SceneGrpah? ::initialize() to rebuild the display lists of OpenGL? .