1 /* 2 PLIB - A Suite of Portable Game Libraries 3 Copyright (C) 1998,2002 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 $Id: ssgLoaderWriterStuff.h 1935 2004-05-04 12:37:33Z wolfram_kuss $ 22 */ 23 24 //#include "ssgLocal.h" 25 26 // ******************** small utility functions ************************ 27 28 void ssgAccumVerticesAndFaces( ssgEntity* node, sgMat4 transform, ssgVertexArray* vertices, 29 ssgIndexArray* indices, SGfloat epsilon, 30 ssgSimpleStateArray* ssa = NULL, 31 ssgIndexArray* materialIndices = NULL, 32 ssgTexCoordArray *texCoordArray = NULL); 33 34 /* 35 ssgTriangulate - 36 Triangulate a simple polygon (possibly concave, but not self-intersecting). 37 The number of triangles written to 'triangles' is returned, which is always 38 less than or equal to num - 2. The polygon index array 'indices' may be null, 39 in which case an identity mapping is assumed. 40 Note that the implementation is optimized for small polygons, and since 41 the algorithm is O(num^2) it is not efficient on large polygons. 42 */ 43 int _ssgTriangulate( sgVec3 *vertices, int *indices, int num, int *triangles ); 44 45 46 // ******************** class ssgLoaderWriterMesh ************************ 47 48 class ssgListOfLists : public ssgSimpleList 49 // list of POINTERs to ssgSimpleLists 50 { 51 public: 52 53 virtual ssgBase *clone ( int clone_flags = 0 ) { return NULL; }; // Fixme NIV14: 2do ssgSimpleList(sizeof (ssgSimpleList *),init)54 ssgListOfLists ( int init = 3 ) : ssgSimpleList ( sizeof(ssgSimpleList*), init ) {} get(unsigned int n)55 class ssgSimpleList **get ( unsigned int n ) { return (class ssgSimpleList **) raw_get ( n ) ; } add(class ssgSimpleList ** thing)56 void add ( class ssgSimpleList **thing ) { raw_add ( (char *) thing ) ; } ; set(class ssgSimpleList ** thing,unsigned int n)57 void set ( class ssgSimpleList **thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ; 58 59 virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) {}; // Fixme NIV14: 2do 60 } ; 61 62 //ssgSimpleState* 63 64 class ssgSimpleStateList : public ssgSimpleList 65 // list of POINTERs to ssgSimpleStates 66 { 67 public: 68 69 virtual ssgBase *clone ( int clone_flags = 0 ) { return NULL; }; // Fixme NIV14: 2do ssgSimpleList(sizeof (ssgSimpleState *),init)70 ssgSimpleStateList( int init = 3 ) : ssgSimpleList ( sizeof(ssgSimpleState*), init ) {} get(unsigned int n)71 class ssgSimpleState **get ( unsigned int n ) { return (class ssgSimpleState **) raw_get ( n ) ; } add(class ssgSimpleState ** thing)72 void add ( class ssgSimpleState **thing ) { raw_add ( (char *) thing ) ; } ; set(class ssgSimpleState ** thing,unsigned int n)73 void set ( class ssgSimpleState **thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ; 74 virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) {}; // Fixme NIV14: 2do 75 } ; 76 77 class ssgLoaderWriterMesh 78 { 79 // ***** general **** 80 char *name; 81 // array of Vec3s: 82 class ssgVertexArray *theVertices; 83 // one index per face: 84 class ssgIndexArray *materialIndices; 85 86 // Each sublist is of type ssgIndexArray and contains the indexes of the vertices: 87 class ssgListOfLists *theFaces; 88 // material list: 89 class ssgSimpleStateList *theMaterials; 90 91 // ***** mode switches ***** 92 int textureCoordinatesArePerVertex; // and not per vertex and face (bTCs_are_per_vertex) 93 // ***** complicated (texture coordinates are per face and vertex) mode ***** 94 // Each sublist is of type ssgTexCoordArray and contains the texture coordinates 95 class ssgListOfLists *perFaceAndVertexTextureCoordinate2Lists; // was: tCPFAV = TextureCoordinatesPerFaceAndVertex 96 97 // ***** easy (texture coordinates are per vertex) mode ********* 98 class ssgTexCoordArray *perVertexTextureCoordinates2; // was: tCPV = TextureCoordinatesPerVertex 99 100 void addOneNodeToSSGFromPerVertexTextureCoordinates2( class ssgVertexArray *theVertices, 101 class ssgTexCoordArray *theTextureCoordinates2, 102 class ssgListOfLists *theFaces, 103 class ssgSimpleState *currentState,// Pfusch, kludge. NIV135 104 class ssgLoaderOptions* current_options, 105 class ssgBranch *curr_branch_ ); // was: AddOneNode2SSGFromCPV 106 void addOneNodeToSSGFromPerFaceAndVertexTextureCoordinates2( class ssgVertexArray *theVertices, 107 class ssgListOfLists *theTextureCoordinate2Lists, 108 class ssgListOfLists *theFaces, 109 class ssgSimpleState *currentState,// Pfusch, kludge. NIV135 110 class ssgLoaderOptions* current_options, 111 class ssgBranch *curr_branch_ ); // was: AddOneNodeToSSGFromCPFAV 112 113 public: 114 getVertices(void)115 class ssgVertexArray *getVertices(void) { return theVertices; } 116 void setVertices( class ssgVertexArray *vertexArray ); getPerVertexTextureCoordinates2(void)117 class ssgTexCoordArray *getPerVertexTextureCoordinates2(void) { return perVertexTextureCoordinates2; } 118 void setPerVertexTextureCoordinates2( class ssgTexCoordArray *texCoordArray ); 119 void setName( const char *meshName ); 120 121 void addToSSG( 122 class ssgSimpleState *currentstate, 123 class ssgLoaderOptions* currentOptions, 124 class ssgBranch *curr_branch_ ); 125 126 // construction/destruction: 127 ssgLoaderWriterMesh(); 128 ~ssgLoaderWriterMesh(); 129 void reInit(void); 130 void deletePerFaceAndVertexTextureCoordinates2(); // was: deleteTCPFAV 131 132 // creation: 133 void createVertices( int numReservedVertices = 8 ) ; // was: ThereAreNVertices 134 void addVertex( sgVec3 v ) ; 135 136 void createFaces( int numReservedFaces = 3 ) ; // was: ThereAreNFaces 137 void addFace( ssgIndexArray **indexArray ) ; 138 void addFaceFromIntegerArray( int numVertices, int *vertices );// AddFaceFromCArray 139 140 void createPerFaceAndVertexTextureCoordinates2( int numReservedTextureCoordinate2Lists = 3 ) ; // ThereAreNTCPFAV 141 void addPerFaceAndVertexTextureCoordinate2( ssgTexCoordArray **textureCoordinateArray ) ; // addTCPFAV 142 143 void createPerVertexTextureCoordinates2( int numReservedTextureCoordinates2 = 3 ); // was: ThereAreNTCPV 144 void addPerVertexTextureCoordinate2( sgVec2 textureCoordinate ); // was; addTCPV 145 146 void createMaterialIndices( int numReservedMaterialIndices = 3 ); // ThereAreNMaterialIndexes 147 void addMaterialIndex( short materialIndex ) ; 148 149 void createMaterials( int numReservedMaterials = 3 ); // was: ThereAreNMaterials 150 void addMaterial( class ssgSimpleState **simpleState ) ; 151 getNumVertices(void)152 unsigned int getNumVertices(void) { return theVertices->getNum(); } ; getNumFaces(void)153 unsigned int getNumFaces (void) { return theFaces->getNum(); } ; getNumMaterials(void)154 unsigned int getNumMaterials(void) { return theMaterials->getNum(); } ; 155 156 157 // tools: 158 int checkMe(); 159 }; 160 161 162