CyberVRML97 for CC

Introduction

CyberVRML97 for C++ is a development library of VRML97/2.0 applications. Using the library, you can read and write the VRML files, set and get the scene graph information, draw the geometries, run the behaviors easily. Please check the project site on SourceForge.net to get the source codes and documents.

Setup

The library has c++ program files and parser files. At first, you need to create a header file and two source files from the parser files, "vrml.l" and "vrml.y", using lex and yacc programs; flex and bison, for example.
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.cpp
When 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 Overview

SceneGraph Class

SceneGraph class is a top class of the library. The important methods is below.
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.

Node Class

Although you may not create instances of Node class directly, but it is a important class because the class is a super class of all VRML node classes. Node class is a sub class of LinkedListNode class. Thus the all nodes are managed as list structure, and a node can have the other nodes as the child. The important methods are below.

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()); 
}

Node information

If you want to get information of a node, use get*() to get a value from the single fields (SF*), SFInt32 etc, or use getN*() and get*() to get valuse of the multi fields (MF*), MFInt32 etc. For example, AnchorNode class has the following methods to get the Infomation. About the other nodes, please confirm the header files.
class AnchorNode extends GroupingNode { 
// Description 
char *getDescription() 
// Parameter 
int getNParameters() 
char *getParameter(int index) 
// URL 
int getNUrls() 
char *getUrl(int index) 
}

SceneGraph Assembly

You can add or remove all VRML nodes into the SceneGraph dynamically. In the following code, a VRML file is loaded into the SceneGraph. Then, the fitst PointLight node is removed, a new spehere geometry is added, and the SceneGraph is saved into other VRML file.
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.

Other

PROTO

Only the SF* fields are supported, and the MF* fields are ignored. EXTERNPROTO is not supported.

Script

Java of VRML 2.0 specification (JSAI) is supported as the script language. In current version, the processEvents() method and the eventsProcessed() method are not supported.

License

CyberVRML97 for C++ is provided "AS IS". Licenser disclaims all warranties, including but not limited to, all express or implied warranties of merchant ability and fitness for a particular purpose. Everyone can use the CyberVRML97 for commerce or personal purposes free. However, If you want to distribute your software using the CyberVRML97, you have to add state that "Portions of this software is based in part on the CyberVRML97 package written by Satoshi Konno" into the program or document.
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2011-02-02 - SatoshiKonno
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 2014 by Satoshi Konno Powerd by TWiki logoTWiki.