1 /* 2 PLIB - A Suite of Portable Game Libraries 3 Copyright (C) 1998,2002, 2002 William Lachance, Steve Baker 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 For further information visit http://plib.sourceforge.net 20 */ 21 22 class ssgListOfNodes : public ssgSimpleList 23 // list of POINTERs to ssgBase 24 // used for storing/querying DEF'd info 25 { 26 public: 27 28 virtual ssgBase *clone ( int clone_flags = 0 ) { return NULL; }; // Fixme NIV14: 2do ssgSimpleList(sizeof (ssgBase *),init)29 ssgListOfNodes ( int init = 3 ) : ssgSimpleList ( sizeof(ssgBase*), init ) {} get(unsigned int n)30 class ssgBase *get ( unsigned int n ) { return *( (class ssgBase **) raw_get ( n ) ) ; } add(class ssgBase * thing)31 void add ( class ssgBase *thing ) { raw_add ( (char *) &thing ) ; } ; replace(class ssgBase * thing,unsigned int n)32 void replace( class ssgBase *thing, unsigned int n ) { raw_set( (char *) &thing, n); } 33 34 virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) {}; // Fixme NIV14: 2do 35 }; 36 37 38 class _nodeIndex 39 { 40 private: 41 ssgListOfNodes *nodeList; 42 public: _nodeIndex()43 _nodeIndex() 44 { 45 nodeList = new ssgListOfNodes(); 46 } ~_nodeIndex()47 ~_nodeIndex() 48 { 49 for( int i=0; i<nodeList->getNum(); i++ ) 50 { 51 ssgBase *extractedThing = nodeList->get( i ); 52 if( extractedThing->getRef() == 0 ) 53 delete( extractedThing ); 54 } 55 } 56 insert(ssgBase * thing)57 void insert( ssgBase *thing ) 58 { 59 // replace the node if a node with an identical tag already exists 60 for( int i=0; i<nodeList->getNum(); i++ ) 61 { 62 ssgBase *tempThing = nodeList->get( i ); 63 if( !strcmp( tempThing->getName(), thing->getName() ) ) 64 { 65 nodeList->replace( thing, i ); 66 ulSetError(UL_DEBUG, "Replaced element %i.", i); 67 return; 68 } 69 } 70 // otherwise add it to end of list 71 nodeList->add( thing ); 72 } 73 extract(char * defName)74 ssgBase * extract( char *defName ) 75 { 76 for( int i=0; i<nodeList->getNum(); i++ ) 77 { 78 ssgBase *extractedThing = nodeList->get( i ); 79 if( !strcmp( extractedThing->getName(), defName ) ) 80 return extractedThing; 81 } 82 83 return NULL; 84 } 85 }; 86 87 // the current properties for a certain point in scene traversal 88 class _traversalState 89 { 90 private: 91 ssgVertexArray *vertices; 92 ssgTexCoordArray *textureCoordinates; 93 ssgTransform *transform; 94 ssgTexture *texture; 95 bool textureCoordinatesArePerFaceAndVertex; 96 GLenum frontFace; 97 bool enableCullFace; 98 99 public: 100 getEnableCullFace()101 bool getEnableCullFace() { return enableCullFace; } setEnableCullFace(bool newEnableCullFace)102 void setEnableCullFace( bool newEnableCullFace ) { enableCullFace = newEnableCullFace; } 103 getFrontFace(void)104 GLenum getFrontFace( void ) { return frontFace; } setFrontFace(GLenum newFrontFace)105 void setFrontFace( GLenum newFrontFace ) { frontFace = newFrontFace; } 106 getTransform(void)107 ssgTransform * getTransform( void ) { return transform; } setTransform(ssgTransform * newTransform)108 void setTransform( ssgTransform *newTransform ) { transform = newTransform; } 109 getVertices(void)110 ssgVertexArray * getVertices( void ) { return vertices; } setVertices(ssgVertexArray * newVertices)111 void setVertices( ssgVertexArray *newVertices ) { vertices = newVertices; } 112 getTextureCoordinates(void)113 ssgTexCoordArray *getTextureCoordinates( void ) { return textureCoordinates; } setTextureCoordinates(ssgTexCoordArray * newTextureCoordinates)114 void setTextureCoordinates( ssgTexCoordArray *newTextureCoordinates ) { textureCoordinates = newTextureCoordinates; } 115 getTexture(void)116 ssgTexture * getTexture( void ) { return texture; } setTexture(ssgTexture * newTexture)117 void setTexture( ssgTexture *newTexture ) { texture = newTexture; } 118 areTextureCoordinatesArePerFaceAndVertex(void)119 bool areTextureCoordinatesArePerFaceAndVertex( void ) { return textureCoordinatesArePerFaceAndVertex; } 120 clone()121 _traversalState *clone() { return new _traversalState(*this); } _traversalState()122 _traversalState() { vertices = NULL; textureCoordinates = NULL; transform = NULL; texture = NULL; textureCoordinatesArePerFaceAndVertex = TRUE; enableCullFace = FALSE; } 123 }; 124 125 // tags for functions which may actually modify the scene graph 126 struct _parseTag 127 { 128 const char *token ; 129 bool (*func) ( ssgBranch *parentBranch, _traversalState *parentData, char *defName ) ; 130 } ; 131 132 // the vrml1 common subset that is shared with inventor 133 bool vrml1_parseCoordinate3( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 134 bool vrml1_parseTextureCoordinate2( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 135 bool vrml1_parseShapeHints( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 136 bool vrml1_parseMatrixTransform( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 137 bool vrml1_parseScale( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 138 bool vrml1_parseRotation( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 139 bool vrml1_parseTranslation( ssgBranch *parentBranch, _traversalState *currentData, char *defName ); 140 bool vrml1_parseUseDirective( ssgBranch *parentBranch, _traversalState *currentData, char *useName, char *defName ); 141 bool vrml1_parseCoordIndex( ssgLoaderWriterMesh *loaderMesh, _traversalState *currentData ); 142 bool vrml1_parseTextureCoordIndex( ssgLoaderWriterMesh *loaderMesh, _traversalState *currentData ); 143 bool parseUnidentified(); 144 145 void applyTransform( ssgTransform *currentTransform, _traversalState *currentData ); 146 void mergeTransformNodes( ssgTransform *newTransform, ssgTransform *oldTransform1, ssgTransform *oldTransform2 ); 147 bool parseVec( SGfloat *v, int vSize ); 148 ssgIndexArray * parseIndexArray( _traversalState *currentData ); 149 150 extern _ssgParser vrmlParser; 151