- Timestamp:
- 06/09/06 14:26:57 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsLibrary.h
r1007 r1009 21 21 //typedef unsigned long int SmallInt; 22 22 typedef unsigned long SmallInt; 23 typedef unsigned long 24 typedef long 23 typedef unsigned long ULong; 24 typedef long Long; 25 25 26 26 typedef struct … … 101 101 Mesh *mGeoMesh; 102 102 103 /* 104 Copa STL vectors to C arrays. 105 */ 103 // Copa STL vectors to C arrays. 106 104 void CopyVectors2Arrays(); 107 105 108 /* 109 Loads Mesh 110 */ 106 // Loads Mesh. 111 107 void LoadStripMesh(char *name, Mesh *geomesh); 112 108 … … 159 155 } 160 156 157 #endif 161 158 162 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoSerializer.h
r980 r1009 6 6 #include "GeoVector3.h" 7 7 8 namespace Geometry {9 8 namespace Geometry 9 { 10 10 /// Serializer interface 11 11 /** Serializer is a helper class than manages file input/output. 12 12 */ 13 14 15 13 class Serializer 14 { 15 public: 16 16 17 enum Mode18 {19 READ,20 WRITE,21 APPEND22 };17 enum Mode 18 { 19 READ, 20 WRITE, 21 APPEND 22 }; 23 23 24 ///Constructor25 Serializer(String name, Mode mode);24 /// Constructor. 25 Serializer(String name, Mode mode); 26 26 27 ///Destructor28 virtual ~Serializer();27 /// Destructor. 28 virtual ~Serializer(); 29 29 30 /// Copy constructor31 //Serializer(const Serializer&);30 /// Copy constructor. 31 //Serializer(const Serializer&); 32 32 33 /// Assignment operator34 //Serializer& operator =(const Serializer&);33 /// Assignment operator. 34 //Serializer& operator =(const Serializer&); 35 35 36 public: 36 37 37 public: 38 void WriteData(const void* const buf, size_t size, size_t count); 39 void WriteArray(const float* const pfloat, size_t count); 40 void WriteArray(const uint16* const pShort, size_t count); 41 void WriteArray(const uint32* const pInt, size_t count); 42 void WriteArray(const bool* const pLong, size_t count); 43 void WriteArray(const Vector3* const pvector3, size_t count); 44 void WriteArray(const Vector2* const pvector3, size_t count); 45 46 void ReadData(void *buf, size_t size, size_t count); 47 void miReadData2(void *buf, size_t size, size_t count); 48 char *miReadData(char *pDest, size_t pDestsize); 49 void ReadArray(bool *pDest, size_t count); 50 void ReadArray(float *pDest, size_t count); 51 void ReadArray(uint16 *pDest, size_t count); 52 void ReadArray(uint32 *pDest, size_t count); 53 void ReadArray(Vector3 *pDest, size_t count); 54 void ReadArray(Vector2 *pDest, size_t count); 38 void WriteData(const void* const buf, size_t size, size_t count); 39 void WriteArray(const float* const pfloat, size_t count); 40 void WriteArray(const uint16* const pShort, size_t count); 41 void WriteArray(const uint32* const pInt, size_t count); 42 void WriteArray(const bool* const pLong, size_t count); 43 void WriteArray(const Vector3* const pvector3, size_t count); 44 void WriteArray(const Vector2* const pvector3, size_t count); 55 45 56 // GPR. 57 void WriteData(const String &string); 58 void WriteData(const char *string); 59 // fin GPR. 46 void ReadData(void *buf, size_t size, size_t count); 47 char * ReadData(char *pDest, size_t pDestsize); 48 void ReadArray(bool *pDest, size_t count); 49 void ReadArray(float *pDest, size_t count); 50 void ReadArray(uint16 *pDest, size_t count); 51 void ReadArray(uint32 *pDest, size_t count); 52 void ReadArray(Vector3 *pDest, size_t count); 53 void ReadArray(Vector2 *pDest, size_t count); 60 54 61 virtual size_t GetSize() 62 { 63 return mSize; 64 } 55 void WriteData(const String &string); 56 void WriteData(const char *string); 65 57 66 int serializereof() { 67 return feof(mFile); 68 } 58 virtual size_t GetSize() 59 { 60 return mSize; 61 } 69 62 70 protected: 63 int serializereof() { 64 return feof(mFile); 65 } 71 66 72 size_t mSize; 73 FILE *mFile; 74 Mode mMode; 67 protected: 75 68 76 void FlipToLittleEndian(void *pData, size_t size, size_t count = 1); 77 void FlipFromLittleEndian(void *pData, size_t size, size_t count = 1); 78 void FlipEndian(void *pData, size_t size, size_t count); 79 void FlipEndian(void *pData, size_t size); 80 }; 69 size_t mSize; 70 FILE *mFile; 71 Mode mMode; 72 73 void FlipToLittleEndian(void *pData, size_t size, size_t count = 1); 74 void FlipFromLittleEndian(void *pData, size_t size, size_t count = 1); 75 void FlipEndian(void *pData, size_t size, size_t count); 76 void FlipEndian(void *pData, size_t size); 77 }; 81 78 82 79 } 83 80 81 #endif 84 82 85 #endif -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoSubMesh.h
r980 r1009 51 51 char mMaterialName[255]; ///< Material name 52 52 53 //OSCAR54 53 std::vector <VertexBoneAssignment> mBones; 55 54 }; … … 57 56 58 57 #endif 58 -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoVertexBuffer.h
r774 r1009 8 8 9 9 10 namespace Geometry {11 10 namespace Geometry 11 { 12 12 /// VertexBuffer interface Class 13 13 /** … … 40 40 void Save(Serializer &s); 41 41 42 42 unsigned int mVertexInfo; ///< Type of info stored by vertex 43 43 size_t mVertexCount; ///< Number of vertices 44 Vector3 *mPosition; ///< Position array of each Vertex, only valid if (vertexInfo & VERTEX_POSITON) == true 44 45 /// Position array of each Vertex, only valid if (vertexInfo & VERTEX_POSITON) == true 46 Vector3 *mPosition; 47 45 48 Vector3 *mNormal; ///< Normal array of each Vertex, only valid if (vertexInfo & VERTEX_NORMAL) == true 46 49 Vector2 *mTexCoords;///< Texture Coordinates array of each Vertex, only valid if (vertexInfo & VERTEX_TEXCOORDS) == true … … 50 53 51 54 #endif 55 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
r1007 r1009 1 /* 1 /*========================================================================== 2 2 * (C) 2005 Universitat Jaume I 3 * 3 *========================================================================== 4 4 * PROYECT: GAME TOOLS 5 * ==========================================================================*/6 /** CONTENT: 7 8 9 10 /*===========================================================================*/5 *========================================================================== 6 * CONTENT: 7 * 8 * 9 * @file GeoLodStripsLibrary.cpp 10 *===========================================================================*/ 11 11 12 12 #include "GeoLodStripsLibrary.h" … … 47 47 //----------------------------------------------------------------------------- 48 48 49 / *50 Go to the level of detail.51 */ 49 //----------------------------------------------------------------------------- 50 // Go to the level of detail. 51 //----------------------------------------------------------------------------- 52 52 uint32 LodStripsLibrary::GoToLod(uint32 newLOD) 53 53 { … … 308 308 309 309 310 / *311 Gets the maximum level of detail.312 */ 310 //----------------------------------------------------------------------------- 311 // Gets the maximum level of detail. 312 //----------------------------------------------------------------------------- 313 313 uint32 LodStripsLibrary::MaxLod() 314 314 { … … 316 316 } 317 317 318 / *319 Gets the minimum level of detail.320 */ 318 //----------------------------------------------------------------------------- 319 // Gets the minimum level of detail. 320 //----------------------------------------------------------------------------- 321 321 uint32 LodStripsLibrary::MinLod() 322 322 { … … 324 324 } 325 325 326 /// Returns the number of vertices of the highest LOD. 326 //----------------------------------------------------------------------------- 327 // Returns the number of vertices of the highest LOD. 328 //----------------------------------------------------------------------------- 327 329 uint32 LodStripsLibrary::MaxVertices() 328 330 { … … 330 332 } 331 333 332 /// Returns the number of vertices of the lowest LOD. 334 //----------------------------------------------------------------------------- 335 // Returns the number of vertices of the lowest LOD. 336 //----------------------------------------------------------------------------- 333 337 uint32 LodStripsLibrary::MinVertices() 334 338 { … … 341 345 } 342 346 343 /// Returns the number of triangles of the highest LOD. 347 //----------------------------------------------------------------------------- 348 // Returns the number of triangles of the highest LOD. 349 //----------------------------------------------------------------------------- 344 350 uint32 LodStripsLibrary::MaxFaces() 345 351 { … … 364 370 } 365 371 366 /// Returns the number of triangles of the lowest LOD. 372 //----------------------------------------------------------------------------- 373 // Returns the number of triangles of the lowest LOD. 374 //----------------------------------------------------------------------------- 367 375 uint32 LodStripsLibrary::MinFaces() 368 376 { … … 386 394 } 387 395 388 /// Establishes the new LOD range. 389 /// Only the LODs in that range are stored and used. 396 //----------------------------------------------------------------------------- 397 // Establishes the new LOD range. 398 // Only the LODs in that range are stored and used. 399 //----------------------------------------------------------------------------- 390 400 void LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod) 391 401 { … … 397 407 } 398 408 409 //----------------------------------------------------------------------------- 410 // Get strip count. 411 //----------------------------------------------------------------------------- 399 412 uint32 LodStripsLibrary::GetStripCount() const 400 413 { … … 402 415 } 403 416 417 //----------------------------------------------------------------------------- 418 // Get Index by strip. 419 //----------------------------------------------------------------------------- 404 420 uint32 LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const 405 421 { … … 411 427 //----------------------------------------------------------------------------- 412 428 413 / *414 Copy a STL vector to a C array.415 */ 429 //----------------------------------------------------------------------------- 430 // Copy a STL vector to a C array. 431 //----------------------------------------------------------------------------- 416 432 void LodStripsLibrary::CopyVectors2Arrays() 417 433 { … … 487 503 488 504 //----------------------------------------------------------------------------- 489 // 505 // LoadStripMesh 490 506 //----------------------------------------------------------------------------- 491 507 void LodStripsLibrary::LoadStripMesh(char *name, Mesh *geomesh) -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMesh.cpp
r986 r1009 10 10 mVertexBuffer(0), mSubMeshCount(0), mSubMesh(0), hasSkeleton(false) 11 11 { 12 mMeshBounds.maxX 13 mMeshBounds.maxY 14 mMeshBounds.maxZ 15 mMeshBounds.minX 16 mMeshBounds.minY 17 mMeshBounds.minZ 12 mMeshBounds.maxX = 0.0; 13 mMeshBounds.maxY = 0.0; 14 mMeshBounds.maxZ = 0.0; 15 mMeshBounds.minX = 0.0; 16 mMeshBounds.minY = 0.0; 17 mMeshBounds.minZ = 0.0; 18 18 mMeshBounds.scaleFactor = 0.0; 19 19 } … … 24 24 Mesh::~Mesh() 25 25 { 26 delete[] mSubMesh; 27 delete mVertexBuffer; 28 } 29 26 delete [] mSubMesh; 27 delete mVertexBuffer; 28 } 30 29 31 30 //--------------------------------------------------------------------------- 32 31 // Copy constructor. 33 32 //--------------------------------------------------------------------------- 34 Mesh::Mesh(const Mesh &objmesh) 35 { 36 // constructor copia 33 Mesh::Mesh(const Mesh &mesh) 34 { 37 35 mVertexBuffer = new VertexBuffer(); 38 mSubMeshCount = objmesh.mSubMeshCount;39 mSubMesh = new SubMesh[ objmesh.mSubMeshCount];36 mSubMeshCount = mesh.mSubMeshCount; 37 mSubMesh = new SubMesh[mesh.mSubMeshCount]; 40 38 41 39 // Fill up bounding box settings. 42 mMeshBounds.maxX = objmesh.mMeshBounds.maxX;43 mMeshBounds.maxY = objmesh.mMeshBounds.maxY;44 mMeshBounds.maxZ = objmesh.mMeshBounds.maxZ;45 mMeshBounds.minX = objmesh.mMeshBounds.minX;46 mMeshBounds.minY = objmesh.mMeshBounds.minY;47 mMeshBounds.minZ = objmesh.mMeshBounds.minZ;48 mMeshBounds.radius = objmesh.mMeshBounds.radius;49 mMeshBounds.scaleFactor = objmesh.mMeshBounds.scaleFactor;40 mMeshBounds.maxX = mesh.mMeshBounds.maxX; 41 mMeshBounds.maxY = mesh.mMeshBounds.maxY; 42 mMeshBounds.maxZ = mesh.mMeshBounds.maxZ; 43 mMeshBounds.minX = mesh.mMeshBounds.minX; 44 mMeshBounds.minY = mesh.mMeshBounds.minY; 45 mMeshBounds.minZ = mesh.mMeshBounds.minZ; 46 mMeshBounds.radius = mesh.mMeshBounds.radius; 47 mMeshBounds.scaleFactor = mesh.mMeshBounds.scaleFactor; 50 48 51 49 // For each submesh. 52 for (size_t i = 0; i < objmesh.mSubMeshCount; i++)50 for (size_t i = 0; i < mesh.mSubMeshCount; i++) 53 51 { 54 52 mSubMesh[i].mSharedVertexBuffer = false; 55 53 mSubMesh[i].mVertexBuffer = new VertexBuffer(); 56 mSubMesh[i].mVertexBuffer->mPosition = new Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 57 mSubMesh[i].mVertexBuffer->mNormal = new Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 58 mSubMesh[i].mVertexBuffer->mTexCoords = new Vector2[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 59 mSubMesh[i].mVertexBuffer->mVertexCount = objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; 60 mSubMesh[i].mVertexBuffer->mVertexInfo = objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 61 mSubMesh[i].mType = objmesh.mSubMesh[i].mType; 62 strcpy(mSubMesh[i].mMaterialName,objmesh.mSubMesh[i].mMaterialName); 63 64 if(objmesh.mSubMesh[i].mSharedVertexBuffer) 65 { 66 for(size_t s = 0; 67 s<objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; 54 mSubMesh[i].mVertexBuffer->mPosition = new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 55 mSubMesh[i].mVertexBuffer->mNormal = new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 56 mSubMesh[i].mVertexBuffer->mTexCoords = new Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 57 mSubMesh[i].mVertexBuffer->mVertexCount = mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 58 mSubMesh[i].mVertexBuffer->mVertexInfo = mesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 59 mSubMesh[i].mType = mesh.mSubMesh[i].mType; 60 61 strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName); 62 63 if (mesh.mSubMesh[i].mSharedVertexBuffer) 64 { 65 for (size_t s = 0; 66 s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 68 67 s++) 69 68 { 70 // Copy mPosition. 71 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 69 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 72 70 { 73 mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mVertexBuffer->mPosition[s].x;74 mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mVertexBuffer->mPosition[s].y;75 mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mVertexBuffer->mPosition[s].z;71 mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mVertexBuffer->mPosition[s].x; 72 mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mVertexBuffer->mPosition[s].y; 73 mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mVertexBuffer->mPosition[s].z; 76 74 } 77 75 78 // Copy mNormal. 79 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 76 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 80 77 { 81 mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mVertexBuffer->mNormal[s].x;82 mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mVertexBuffer->mNormal[s].y;83 mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mVertexBuffer->mNormal[s].z;78 mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mVertexBuffer->mNormal[s].x; 79 mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mVertexBuffer->mNormal[s].y; 80 mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mVertexBuffer->mNormal[s].z; 84 81 } 85 82 86 // Copy mTexCoords. 87 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 83 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 88 84 { 89 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mVertexBuffer->mTexCoords[s].x;90 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mVertexBuffer->mTexCoords[s].y;85 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mVertexBuffer->mTexCoords[s].x; 86 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mVertexBuffer->mTexCoords[s].y; 91 87 } 92 88 } 93 objmesh.mSubMesh[i].mSharedVertexBuffer = false; 89 90 mesh.mSubMesh[i].mSharedVertexBuffer = false; 94 91 } 95 92 else 96 93 { 97 for(size_t s = 0; s < objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 98 { 99 // Copy mPosition. 100 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 94 for (size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 95 { 96 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 101 97 { 102 mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].x;103 mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].y;104 mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].z;98 mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 99 mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 100 mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 105 101 } 106 102 107 //Copiamos mNormal 108 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 103 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 109 104 { 110 mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].x;111 mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].y;112 mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].z;105 mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 106 mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 107 mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 113 108 } 114 109 115 //Copiamos mTexCoords 116 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 110 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 117 111 { 118 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x;119 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y;112 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 113 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 120 114 } 121 115 } … … 124 118 125 119 // Copy indices. 126 mSubMesh[i].mIndexCount = objmesh.mSubMesh[i].mIndexCount;120 mSubMesh[i].mIndexCount = mesh.mSubMesh[i].mIndexCount; 127 121 mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount]; 128 122 129 memcpy(mSubMesh[i].mIndex,objmesh.mSubMesh[i].mIndex,objmesh.mSubMesh[i].mIndexCount*sizeof(Index)); 123 memcpy( mSubMesh[i].mIndex, 124 mesh.mSubMesh[i].mIndex, 125 mesh.mSubMesh[i].mIndexCount * sizeof(Index)); 130 126 131 127 // Copy strips. 132 __w64 int offset = 0; // offset between memory positions. 133 mSubMesh[i].mStripCount=objmesh.mSubMesh[i].mStripCount; 134 if (objmesh.mSubMesh[i].mStripCount>0) 135 { 136 mSubMesh[i].mStrip = new Index*[objmesh.mSubMesh[i].mStripCount]; 137 138 offset = &(mSubMesh[i].mIndex[0]) - &(objmesh.mSubMesh[i].mIndex[0]); 139 for (size_t j=0;j<objmesh.mSubMesh[i].mStripCount;j++) 140 { 141 mSubMesh[i].mStrip[j]=objmesh.mSubMesh[i].mStrip[j] + offset; 128 // offset between memory positions. 129 __w64 int offset = 0; 130 mSubMesh[i].mStripCount = mesh.mSubMesh[i].mStripCount; 131 132 if (mesh.mSubMesh[i].mStripCount > 0) 133 { 134 mSubMesh[i].mStrip = new Index*[mesh.mSubMesh[i].mStripCount]; 135 136 offset = &(mSubMesh[i].mIndex[0]) - &(mesh.mSubMesh[i].mIndex[0]); 137 138 for (size_t j = 0; j < mesh.mSubMesh[i].mStripCount; j++) 139 { 140 mSubMesh[i].mStrip[j] = mesh.mSubMesh[i].mStrip[j] + offset; 142 141 } 143 142 } 144 143 145 144 // Copy submesh bones. 146 if (! objmesh.mSubMesh[i].mBones.empty())147 { 148 for (unsigned int j = 0; j < objmesh.mSubMesh[i].mBones.size(); j++)149 { 150 mSubMesh[i].mBones.push_back( objmesh.mSubMesh[i].mBones[j]);145 if (!mesh.mSubMesh[i].mBones.empty()) 146 { 147 for (unsigned int j = 0; j < mesh.mSubMesh[i].mBones.size(); j++) 148 { 149 mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]); 151 150 } 152 151 } … … 154 153 155 154 // Copy skeleton name. 156 if ( objmesh.hasSkeleton)155 if (mesh.hasSkeleton) 157 156 { 158 157 hasSkeleton = true; 159 158 160 strcpy(mSkeletonName, objmesh.mSkeletonName);159 strcpy(mSkeletonName, mesh.mSkeletonName); 161 160 } 162 161 163 162 // Copy mesh bones. 164 if (! objmesh.mBones.empty())165 { 166 for (unsigned int j = 0; j < objmesh.mBones.size();j++)167 { 168 mBones.push_back( objmesh.mBones[j]);163 if (!mesh.mBones.empty()) 164 { 165 for (unsigned int j = 0; j < mesh.mBones.size(); j++) 166 { 167 mBones.push_back(mesh.mBones[j]); 169 168 } 170 169 } … … 175 174 // Assignment operator. 176 175 //--------------------------------------------------------------------------- 177 Mesh &Mesh::operator =(const Geometry::Mesh &objmesh) 178 { 179 // Operador de asignación 180 bool copiados = false; // indica si los vértices compartidos han sido copiados 176 Mesh &Mesh::operator =(const Mesh &mesh) 177 { 178 bool copied = false; 181 179 mVertexBuffer = new VertexBuffer(); 182 mSubMeshCount = objmesh.mSubMeshCount;183 mSubMesh = new Geometry::SubMesh[ objmesh.mSubMeshCount];180 mSubMeshCount = mesh.mSubMeshCount; 181 mSubMesh = new Geometry::SubMesh[mesh.mSubMeshCount]; 184 182 185 183 // Fill up bounding box settings. 186 mMeshBounds.maxX = objmesh.mMeshBounds.maxX;187 mMeshBounds.maxY = objmesh.mMeshBounds.maxY;188 mMeshBounds.maxZ = objmesh.mMeshBounds.maxZ;189 mMeshBounds.minX = objmesh.mMeshBounds.minX;190 mMeshBounds.minY = objmesh.mMeshBounds.minY;191 mMeshBounds.minZ = objmesh.mMeshBounds.minZ;192 mMeshBounds.radius = objmesh.mMeshBounds.radius;193 mMeshBounds.scaleFactor = objmesh.mMeshBounds.scaleFactor;184 mMeshBounds.maxX = mesh.mMeshBounds.maxX; 185 mMeshBounds.maxY = mesh.mMeshBounds.maxY; 186 mMeshBounds.maxZ = mesh.mMeshBounds.maxZ; 187 mMeshBounds.minX = mesh.mMeshBounds.minX; 188 mMeshBounds.minY = mesh.mMeshBounds.minY; 189 mMeshBounds.minZ = mesh.mMeshBounds.minZ; 190 mMeshBounds.radius = mesh.mMeshBounds.radius; 191 mMeshBounds.scaleFactor = mesh.mMeshBounds.scaleFactor; 194 192 195 193 // For each submesh. 196 for(size_t i = 0; i < objmesh.mSubMeshCount;i++)197 { 198 mSubMesh[i].mSharedVertexBuffer = objmesh.mSubMesh[i].mSharedVertexBuffer; //.false;194 for(size_t i = 0; i < mesh.mSubMeshCount; i++) 195 { 196 mSubMesh[i].mSharedVertexBuffer = mesh.mSubMesh[i].mSharedVertexBuffer; //.false; 199 197 mSubMesh[i].mVertexBuffer = new Geometry::VertexBuffer(); 200 mSubMesh[i].mVertexBuffer->mPosition = new Geometry::Vector3[ objmesh.mSubMesh[i].mVertexBuffer->mVertexCount];201 mSubMesh[i].mVertexBuffer->mNormal = new Geometry::Vector3[ objmesh.mSubMesh[i].mVertexBuffer->mVertexCount];202 mSubMesh[i].mVertexBuffer->mTexCoords = new Geometry::Vector2[ objmesh.mSubMesh[i].mVertexBuffer->mVertexCount];203 mSubMesh[i].mVertexBuffer->mVertexCount = objmesh.mSubMesh[i].mVertexBuffer->mVertexCount;204 mSubMesh[i].mVertexBuffer->mVertexInfo = objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo;205 mSubMesh[i].mType = objmesh.mSubMesh[i].mType;206 strcpy(mSubMesh[i].mMaterialName, objmesh.mSubMesh[i].mMaterialName);207 208 if ( objmesh.mSubMesh[i].mSharedVertexBuffer && !copiados)198 mSubMesh[i].mVertexBuffer->mPosition = new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 199 mSubMesh[i].mVertexBuffer->mNormal = new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 200 mSubMesh[i].mVertexBuffer->mTexCoords = new Geometry::Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 201 mSubMesh[i].mVertexBuffer->mVertexCount = mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 202 mSubMesh[i].mVertexBuffer->mVertexInfo = mesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 203 mSubMesh[i].mType = mesh.mSubMesh[i].mType; 204 strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName); 205 206 if (mesh.mSubMesh[i].mSharedVertexBuffer && !copied) 209 207 { 210 208 mVertexBuffer = mSubMesh[i].mVertexBuffer; 211 copiados = true; 212 } 213 214 for(size_t s = 0; s < objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 215 { 216 //Copiamos mPosition 217 //if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_POSITION) 218 //{ 219 mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 220 mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 221 mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 222 //} 223 //Copiamos mNormal 224 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 225 { 226 mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 227 mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 228 mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 229 } 230 231 //Copiamos mTexCoords 232 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 233 { 234 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 235 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 236 } 237 } 238 239 // Copiar los indices 240 mSubMesh[i].mIndexCount = objmesh.mSubMesh[i].mIndexCount; 209 copied = true; 210 } 211 212 for(size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 213 { 214 mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 215 mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 216 mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 217 218 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 219 { 220 mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 221 mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 222 mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 223 } 224 225 if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 226 { 227 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 228 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 229 } 230 } 231 232 // Copy indices. 233 mSubMesh[i].mIndexCount = mesh.mSubMesh[i].mIndexCount; 241 234 mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount]; 242 235 243 236 memcpy( mSubMesh[i].mIndex, 244 objmesh.mSubMesh[i].mIndex, 245 objmesh.mSubMesh[i].mIndexCount*sizeof(Geometry::Index)); 246 247 // Copiar las tiras 248 __w64 offset = 0; // desplazamiento entre posiciones de memoria. 249 mSubMesh[i].mStripCount = objmesh.mSubMesh[i].mStripCount; 250 251 if (objmesh.mSubMesh[i].mStripCount>0) 252 { 253 mSubMesh[i].mStrip = new Index*[objmesh.mSubMesh[i].mStripCount]; 254 offset = &(mSubMesh[i].mIndex[0]) - &(objmesh.mSubMesh[i].mIndex[0]); 255 256 for (size_t j = 0; j < objmesh.mSubMesh[i].mStripCount; j++) 257 { 258 mSubMesh[i].mStrip[j] = objmesh.mSubMesh[i].mStrip[j] + offset; 237 mesh.mSubMesh[i].mIndex, 238 mesh.mSubMesh[i].mIndexCount*sizeof(Geometry::Index)); 239 240 // Copy strips. 241 __w64 offset = 0; 242 mSubMesh[i].mStripCount = mesh.mSubMesh[i].mStripCount; 243 244 if (mesh.mSubMesh[i].mStripCount > 0) 245 { 246 mSubMesh[i].mStrip = new Index*[mesh.mSubMesh[i].mStripCount]; 247 248 offset = &(mSubMesh[i].mIndex[0]) 249 - 250 &(mesh.mSubMesh[i].mIndex[0]); 251 252 for (size_t j = 0; j < mesh.mSubMesh[i].mStripCount; j++) 253 { 254 mSubMesh[i].mStrip[j] = mesh.mSubMesh[i].mStrip[j] + offset; 259 255 } 260 256 } 261 257 262 258 // Copy submesh bones. 263 if (! objmesh.mSubMesh[i].mBones.empty())264 { 265 for (unsigned int j = 0; j < objmesh.mSubMesh[i].mBones.size();j++)266 { 267 mSubMesh[i].mBones.push_back( objmesh.mSubMesh[i].mBones[j]);259 if (!mesh.mSubMesh[i].mBones.empty()) 260 { 261 for (unsigned int j = 0; j < mesh.mSubMesh[i].mBones.size(); j++) 262 { 263 mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]); 268 264 } 269 265 } … … 271 267 272 268 // Copy skeleton name. 273 if ( objmesh.hasSkeleton)269 if (mesh.hasSkeleton) 274 270 { 275 271 hasSkeleton = true; 276 272 277 strcpy(mSkeletonName, objmesh.mSkeletonName);273 strcpy(mSkeletonName, mesh.mSkeletonName); 278 274 } 279 275 280 276 // Copy mesh bones. 281 if (! objmesh.mBones.empty())282 { 283 for (unsigned int j = 0; j < objmesh.mBones.size();j++)284 { 285 mBones.push_back( objmesh.mBones[j]);277 if (!mesh.mBones.empty()) 278 { 279 for (unsigned int j = 0; j < mesh.mBones.size(); j++) 280 { 281 mBones.push_back(mesh.mBones[j]); 286 282 } 287 283 } … … 297 293 bool sharedVertexBuffer = false; 298 294 299 //Clear Data 300 delete[] mSubMesh; mSubMesh = 0; 301 delete mVertexBuffer; mVertexBuffer = 0; 295 // Clear Data. 296 delete [] mSubMesh; 297 298 mSubMesh = 0; 299 300 delete mVertexBuffer; 301 302 mVertexBuffer = 0; 302 303 mSubMeshCount = 0; 303 304 304 305 s.ReadArray(&sharedVertexBuffer,1); 306 305 307 if (sharedVertexBuffer) 306 308 { … … 308 310 mVertexBuffer->Load(s); 309 311 } 310 s.ReadArray(&mSubMeshCount,1); 311 mSubMesh = new SubMesh[mSubMeshCount]; 312 for(size_t i = 0; i < mSubMeshCount; ++i) 312 313 s.ReadArray(&mSubMeshCount, 1); 314 315 mSubMesh = new SubMesh[mSubMeshCount]; 316 317 for(size_t i = 0; i < mSubMeshCount; i++) 313 318 { 314 319 mSubMesh[i].Load(s); 320 315 321 if (mSubMesh[i].mSharedVertexBuffer && sharedVertexBuffer) 316 322 { 317 mSubMesh[i].mVertexBuffer =mVertexBuffer;323 mSubMesh[i].mVertexBuffer = mVertexBuffer; 318 324 } 319 325 } … … 325 331 void Mesh::Save(Serializer &s) 326 332 { 327 bool sharedVertexBuffer = (mVertexBuffer != 0); 333 bool sharedVertexBuffer = (mVertexBuffer != 0); 334 328 335 s.WriteArray(&sharedVertexBuffer, 1); 336 329 337 if (sharedVertexBuffer) 330 338 { 331 339 mVertexBuffer->Save(s); 332 340 } 341 333 342 s.WriteArray(&mSubMeshCount,1); 334 for(size_t i = 0; i < mSubMeshCount; ++i) 343 344 for(size_t i = 0; i < mSubMeshCount; i++) 335 345 { 336 346 mSubMesh[i].Save(s); … … 341 351 // Export to obj mesh. 342 352 //--------------------------------------------------------------------------- 343 void Mesh::exportToOBJ(char *nomfich) 344 { 345 // Genera un fichero obj con vértices, triángulos 346 347 std::ofstream obj(nomfich); 353 void Mesh::exportToOBJ(char *fileName) 354 { 355 std::ofstream obj(fileName); 356 348 357 obj << "begin" << std::endl; 349 // Vértices 350 for (size_t i=0; i < mSubMeshCount; i++) 351 { 352 for (size_t j=0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 358 359 // Vertices. 360 for (size_t i = 0; i < mSubMeshCount; i++) 361 { 362 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 353 363 { 354 obj << "v " << mSubMesh[i].mVertexBuffer->mPosition[j].x << " " << 355 mSubMesh[i].mVertexBuffer->mPosition[j].y << " " << 356 mSubMesh[i].mVertexBuffer->mPosition[j].z << " " << std::endl; 357 } 358 } 359 360 361 // Caras 362 for (size_t i=0; i < mSubMeshCount; i++) 363 { 364 for (size_t j=0; j < mSubMesh[i].mIndexCount; j=j+3) 364 obj << "v " 365 << mSubMesh[i].mVertexBuffer->mPosition[j].x 366 << " " 367 << mSubMesh[i].mVertexBuffer->mPosition[j].y 368 << " " 369 << mSubMesh[i].mVertexBuffer->mPosition[j].z 370 << " " 371 << std::endl; 372 } 373 } 374 375 // Faces. 376 for (size_t i = 0; i < mSubMeshCount; i++) 377 { 378 for (size_t j = 0; j < mSubMesh[i].mIndexCount; j = j + 3) 365 379 { 366 obj << "f " << mSubMesh[i].mIndex[j]+1 << " " << 367 mSubMesh[i].mIndex[j+1]+1 << " " << 368 mSubMesh[i].mIndex[j+2]+1 << std::endl; 369 } 370 } 371 372 obj << "end" << std::endl; 380 obj << "f " 381 << mSubMesh[i].mIndex[j] + 1 382 << " " 383 << mSubMesh[i].mIndex[j + 1] + 1 384 << " " 385 << mSubMesh[i].mIndex[j + 2] + 1 386 << std::endl; 387 } 388 } 389 390 obj << "end" << std::endl; 391 373 392 obj.close(); 374 393 } … … 380 399 { 381 400 // Move all vertex to the shared vertex buffer. 382 Mesh *mesh =new Mesh();401 Mesh *mesh = new Mesh(); 383 402 384 403 if (mSubMesh[0].mSharedVertexBuffer) … … 390 409 391 410 mesh->mVertexBuffer = new VertexBuffer(); 392 mesh->mSubMeshCount = mSubMeshCount; 393 394 // Reserva memoria para los submeshes 395 mesh->mSubMesh = new SubMesh[mSubMeshCount]; 411 mesh->mSubMeshCount = mSubMeshCount; 412 mesh->mSubMesh = new SubMesh[mSubMeshCount]; 396 413 397 414 // Fill up bounding box settings. … … 418 435 strcpy(mesh->mSubMesh[i].mMaterialName,mSubMesh[i].mMaterialName); 419 436 420 // copiar los índices437 // Copy indices. 421 438 mesh->mSubMesh[i].mIndexCount = mSubMesh[i].mIndexCount; 422 439 mesh->mSubMesh[i].mIndex = new Index[mSubMesh[i].mIndexCount]; … … 429 446 acumVerts += long(mSubMesh[i].mVertexBuffer->mVertexCount); 430 447 431 // Cop iar las tiras432 int offset = 0; // desplazamiento entre posiciones de memoria.448 // Copy strips. 449 int offset = 0; 433 450 434 451 mesh->mSubMesh[i].mStripCount = mSubMesh[i].mStripCount; … … 440 457 offset = int(&(mesh->mSubMesh[i].mIndex[0]) - &(mSubMesh[i].mIndex[0])); 441 458 442 for (size_t j =0; j < mSubMesh[i].mStripCount; j++)443 { 444 mesh->mSubMesh[i].mStrip[j] =mSubMesh[i].mStrip[j] + offset;459 for (size_t j = 0; j < mSubMesh[i].mStripCount; j++) 460 { 461 mesh->mSubMesh[i].mStrip[j] = mSubMesh[i].mStrip[j] + offset; 445 462 } 446 463 } … … 454 471 mesh->mVertexBuffer->mTexCoords = new Vector2[mesh->mVertexBuffer->mVertexCount]; 455 472 456 // copiar los vértices457 473 acumVerts = 0; 458 474 459 475 size_t newIndex; 460 476 461 for (size_t i = 0;i < mSubMeshCount; i++)462 { 463 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount;j++)477 for (size_t i = 0; i < mSubMeshCount; i++) 478 { 479 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 464 480 { 465 481 newIndex = acumVerts + j; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimpSequence.cpp
r1007 r1009 20 20 char name[256]; 21 21 22 if (s. miReadData(buffer,256) != NULL)22 if (s.ReadData(buffer,256) != NULL) 23 23 { 24 24 sscanf(buffer,"%s",&name); … … 27 27 } 28 28 29 while (s. miReadData(buffer,256) != NULL)29 while (s.ReadData(buffer,256) != NULL) 30 30 { 31 31 Geometry::MeshSimplificationSequence::Step simplifstep; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r1007 r1009 310 310 msimpsequence = new MeshSimplificationSequence(); 311 311 312 // Debug.313 cout << "GetMeshsimpSequence VMI"314 << endl;315 316 312 // For each simplification step. 317 313 for (unsigned int i = 0; i < VMI::mVMISteps.size(); i++) … … 336 332 } 337 333 338 // Debug.339 cout << "Step "340 << i341 << " added."342 << endl;343 344 334 msimpsequence->mSteps.push_back(current_step); 345 335 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshStripifier.cpp
r986 r1009 19 19 //----------------------------------------------------------------------------- 20 20 21 /// InitList: 21 //----------------------------------------------------------------------------- 22 /// InitList. 23 //----------------------------------------------------------------------------- 22 24 BOOL CustomStripifier::InitList(PLISTHEAD LHead) 23 25 { … … 33 35 } 34 36 35 /// AddHead: 37 //----------------------------------------------------------------------------- 38 /// AddHead. 39 //----------------------------------------------------------------------------- 36 40 BOOL CustomStripifier::AddHead(PLISTHEAD LHead, PLISTINFO LInfo) 37 41 { … … 8620 8624 //----------------------------------------------------------------------------- 8621 8625 8622 /// Stripify: 8626 //----------------------------------------------------------------------------- 8627 // Stripify. 8628 //----------------------------------------------------------------------------- 8623 8629 int CustomStripifier::Stripify() 8624 8630 { … … 8638 8644 } 8639 8645 8640 /// GetMesh: Return de current Mesh. 8646 //----------------------------------------------------------------------------- 8647 // GetMesh: Return de current Mesh. 8648 //----------------------------------------------------------------------------- 8641 8649 Mesh* CustomStripifier::GetMesh() 8642 8650 { … … 8649 8657 } 8650 8658 8659 //----------------------------------------------------------------------------- 8651 8660 // Set the progress bar function. 8661 //----------------------------------------------------------------------------- 8652 8662 void CustomStripifier::SetProgressFunc(TIPOFUNC upb) 8653 8663 { … … 8656 8666 } 8657 8667 8668 //----------------------------------------------------------------------------- 8658 8669 // Sets what is the submesh that stores the leaves. 8670 //----------------------------------------------------------------------------- 8659 8671 void CustomStripifier::SetSubMeshLeaves(size_t submesh) 8660 8672 { -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoSerializer.cpp
r980 r1009 1 1 #include "GeoSerializer.h" 2 2 3 4 namespace Geometry 5 { 6 //--------------------------------------------------------------------- 7 Serializer::Serializer(String name, Mode mode) 8 : mMode(mode) 9 { 10 char *char_mode = 0; 11 switch (mMode) 12 { 13 case READ : 14 char_mode = "rb"; 15 break; 16 case APPEND: 17 char_mode = "a+b"; 18 break; 19 case WRITE: 20 char_mode = "wb"; 21 break; 22 } 23 24 mFile = fopen(name.c_str(),char_mode); 25 mSize = 0; 26 assert(mFile); 27 } 28 29 //--------------------------------------------------------------------- 30 Serializer::~Serializer() 31 { 32 fflush(mFile); 33 fclose(mFile); 34 } 35 36 //--------------------------------------------------------------------- 37 void Serializer::WriteArray(const float* const pFloat, size_t count) 38 { 39 # if GEO_ENDIAN == GEO_ENDIAN_BIG 40 float *float_to_write = (float *)malloc(sizeof(float) * count); 41 memcpy(float_to_write, pFloat, sizeof(float) * count); 42 43 flipToLittleEndian(float_to_write, sizeof(float), count); 44 writeData(float_to_write, sizeof(float), count); 45 46 free(float_to_write); 3 using namespace Geometry; 4 5 //--------------------------------------------------------------------------- 6 // Constructor. 7 //--------------------------------------------------------------------------- 8 Serializer::Serializer(String name, Mode mode): mMode(mode) 9 { 10 char *char_mode = 0; 11 12 switch (mMode) 13 { 14 case READ : 15 char_mode = "rb"; 16 break; 17 case APPEND: 18 char_mode = "a+b"; 19 break; 20 case WRITE: 21 char_mode = "wb"; 22 break; 23 } 24 25 mFile = fopen(name.c_str(),char_mode); 26 mSize = 0; 27 28 assert(mFile); 29 } 30 31 //--------------------------------------------------------------------------- 32 // Destroyer. 33 //--------------------------------------------------------------------------- 34 Serializer::~Serializer() 35 { 36 fflush(mFile); 37 fclose(mFile); 38 } 39 40 //--------------------------------------------------------------------------- 41 // Write array of floats. 42 //--------------------------------------------------------------------------- 43 void Serializer::WriteArray(const float* const pFloat, size_t count) 44 { 45 # if GEO_ENDIAN == GEO_ENDIAN_BIG 46 float *float_to_write = (float *)malloc(sizeof(float) * count); 47 memcpy(float_to_write, pFloat, sizeof(float) * count); 48 49 flipToLittleEndian(float_to_write, sizeof(float), count); 50 writeData(float_to_write, sizeof(float), count); 51 52 free(float_to_write); 47 53 # else 48 WriteData(pFloat, sizeof(float), count); 49 # endif 50 } 51 52 //--------------------------------------------------------------------- 53 void Serializer::WriteArray(const uint16* const pShort, size_t count = 1) 54 { 55 # if GEO_ENDIAN == GEO_ENDIAN_BIG 56 unsigned short *short_to_write = (unsigned short *)malloc(sizeof(unsigned short) * count); 57 memcpy(short_to_write, pShort, sizeof(unsigned short) * count); 58 59 flipToLittleEndian(short_to_write, sizeof(unsigned short), count); 60 WriteData(short_to_write, sizeof(unsigned short), count); 61 62 free(short_to_write); 54 WriteData(pFloat, sizeof(float), count); 55 # endif 56 } 57 58 //--------------------------------------------------------------------------- 59 // Write array of shots. 60 //--------------------------------------------------------------------------- 61 void Serializer::WriteArray(const uint16* const pShort, size_t count = 1) 62 { 63 # if GEO_ENDIAN == GEO_ENDIAN_BIG 64 unsigned short *short_to_write = (unsigned short *)malloc(sizeof(unsigned short) * count); 65 memcpy(short_to_write, pShort, sizeof(unsigned short) * count); 66 67 flipToLittleEndian(short_to_write, sizeof(unsigned short), count); 68 WriteData(short_to_write, sizeof(unsigned short), count); 69 70 free(short_to_write); 63 71 # else 64 WriteData(pShort, sizeof(unsigned short), count); 65 # endif 66 } 67 68 //--------------------------------------------------------------------- 69 void Serializer::WriteArray(const uint32* const pInt, size_t count = 1) 70 { 71 # if GEO_ENDIAN == GEO_ENDIAN_BIG 72 unsigned int *int_to_write = (unsigned int *)malloc(sizeof(unsigned int) * count); 73 memcpy(int_to_write, pInt, sizeof(unsigned int) * count); 74 75 FlipToLittleEndian(int_to_write, sizeof(unsigned int), count); 76 WriteData(int_to_write, sizeof(unsigned int), count); 77 78 free(int_to_write); 72 WriteData(pShort, sizeof(unsigned short), count); 73 # endif 74 } 75 76 //--------------------------------------------------------------------------- 77 // Write array of integers. 78 //--------------------------------------------------------------------------- 79 void Serializer::WriteArray(const uint32* const pInt, size_t count = 1) 80 { 81 # if GEO_ENDIAN == GEO_ENDIAN_BIG 82 unsigned int *int_to_write = (unsigned int *)malloc(sizeof(unsigned int) * count); 83 memcpy(int_to_write, pInt, sizeof(unsigned int) * count); 84 85 FlipToLittleEndian(int_to_write, sizeof(unsigned int), count); 86 WriteData(int_to_write, sizeof(unsigned int), count); 87 88 free(int_to_write); 79 89 # else 80 WriteData(pInt, sizeof(unsigned int), count); 81 # endif 82 } 83 84 //--------------------------------------------------------------------- 85 void Serializer::WriteArray(const bool* const pBool, size_t count = 1) 86 { 87 //TODO: Apple has problems 88 WriteData(pBool, sizeof(bool), count); 89 } 90 91 //--------------------------------------------------------------------- 92 void Serializer::WriteArray(const Vector3* const pDest, size_t count) 93 { 94 for(size_t i = 0; i < count; ++i) 95 { 96 WriteArray(pDest[i].val,3); 97 } 98 } 99 100 //--------------------------------------------------------------------- 101 void Serializer::WriteArray(const Vector2* const pDest, size_t count) 102 { 103 for(size_t i = 0; i < count; ++i) 104 { 105 WriteArray(pDest[i].val,2); 106 } 107 } 108 109 //--------------------------------------------------------------------- 110 void Serializer::WriteData(const void* const buf, size_t size, size_t count) 111 { 112 size_t wcount = fwrite((void* const)buf, size, count, mFile); 113 assert(wcount == count); 114 mSize += size*count; 115 } 116 117 //--------------------------------------------------------------------- 118 void Serializer::ReadData(void *pDest, size_t size, size_t count) 119 { 120 size_t rcount = fread(pDest,size,count,mFile); 121 assert(rcount == count); 122 mSize += size*count; 123 }; 124 125 126 // JGA 127 char * Serializer::miReadData(char *pDest, size_t pDestsize) 128 { 129 return fgets(pDest, (int)pDestsize, mFile); 130 }; 131 132 void Serializer::miReadData2(void *pDest, size_t size, size_t count) 133 { 134 size_t rcount = fread(pDest,size,count,mFile); 135 assert(rcount == count); 136 mSize += size*count; 137 }; 138 // fin JGA 139 140 // GPR. 141 void Serializer::WriteData(const String &string) 142 { 143 fputs(string.c_str(), mFile); 144 145 // Write terminating newline char 146 //fputc('\n', mFile); 147 148 mSize += string.length(); 149 } 150 // fin GPR 151 152 void Serializer::WriteData(const char *string) 153 { 154 fputs(string, mFile); 155 156 // Write terminating newline char 157 //fputc('\n', mFile); 158 159 mSize += strlen(string) /*+ 1*/; 160 } 161 162 //--------------------------------------------------------------------- 163 void Serializer::ReadArray(bool *pDest, size_t count) 164 { 165 //TODO:: Apple has problmes with bools 166 ReadData(pDest,sizeof(bool), count); 167 } 168 169 //--------------------------------------------------------------------- 170 void Serializer::ReadArray(float *pDest, size_t count) 171 { 172 ReadData(pDest, sizeof(float), count); 173 FlipFromLittleEndian(pDest, sizeof(float), count); 174 } 175 176 //--------------------------------------------------------------------- 177 void Serializer::ReadArray(unsigned short *pDest, size_t count) 178 { 179 ReadData(pDest, sizeof(unsigned short), count); 180 FlipFromLittleEndian(pDest, sizeof(unsigned short), count); 181 } 182 183 //--------------------------------------------------------------------- 184 void Serializer::ReadArray(unsigned int *pDest, size_t count) 185 { 186 ReadData(pDest, sizeof(unsigned int), count); 187 FlipFromLittleEndian(pDest, sizeof(unsigned int), count); 188 } 189 190 //--------------------------------------------------------------------- 191 void Serializer::ReadArray(Vector3 *pDest, size_t count) 192 { 193 for(size_t i = 0; i < count; ++i) 194 { 195 ReadArray(pDest[i].val,3); 196 } 197 } 198 199 //--------------------------------------------------------------------- 200 void Serializer::ReadArray(Vector2 *pDest, size_t count) 201 { 202 for(size_t i = 0; i < count; ++i) 203 { 204 ReadArray(pDest[i].val,2); 205 } 206 } 207 208 //--------------------------------------------------------------------- 209 void Serializer::FlipToLittleEndian(void *pData, size_t size, size_t count) 210 { 211 # if GEO_ENDIAN == GEO_ENDIAN_BIG 212 FlipEndian(pData, size, count); 213 # endif 214 } 215 216 void Serializer::FlipFromLittleEndian(void *pData, size_t size, size_t count) 217 { 218 # if GEO_ENDIAN == GEO_ENDIAN_BIG 219 FlipEndian(pData, size, count); 220 # endif 221 } 222 223 void Serializer::FlipEndian(void *pData, size_t size, size_t count) 224 { 225 for(unsigned int index = 0; index < count; index++) 226 { 227 FlipEndian((void *)((char*)pData + (index * size)), size); 228 } 229 } 230 231 void Serializer::FlipEndian(void *pData, size_t size) 232 { 233 char swapByte; 234 for(unsigned int byteIndex = 0; byteIndex < size/2; byteIndex++) 235 { 236 swapByte = *((char *)pData + byteIndex); 237 *((char *)pData + byteIndex) = *((char *)pData + size - byteIndex - 1); 238 *((char *)pData + size - byteIndex - 1) = swapByte; 239 } 240 } 241 242 } 243 90 WriteData(pInt, sizeof(unsigned int), count); 91 # endif 92 } 93 94 //--------------------------------------------------------------------------- 95 // Write array of booleans. 96 //--------------------------------------------------------------------------- 97 void Serializer::WriteArray(const bool* const pBool, size_t count = 1) 98 { 99 //TODO: Apple has problems 100 WriteData(pBool, sizeof(bool), count); 101 } 102 103 //--------------------------------------------------------------------------- 104 // Write array of Vector3. 105 //--------------------------------------------------------------------------- 106 void Serializer::WriteArray(const Vector3* const pDest, size_t count) 107 { 108 for(size_t i = 0; i < count; ++i) 109 { 110 WriteArray(pDest[i].val,3); 111 } 112 } 113 114 //--------------------------------------------------------------------------- 115 // Write array of Vector2. 116 //--------------------------------------------------------------------------- 117 void Serializer::WriteArray(const Vector2* const pDest, size_t count) 118 { 119 for(size_t i = 0; i < count; ++i) 120 { 121 WriteArray(pDest[i].val,2); 122 } 123 } 124 125 //--------------------------------------------------------------------------- 126 // Write data. 127 //--------------------------------------------------------------------------- 128 void Serializer::WriteData(const void* const buf, size_t size, size_t count) 129 { 130 size_t wcount = fwrite((void* const)buf, size, count, mFile); 131 assert(wcount == count); 132 mSize += size*count; 133 } 134 135 //--------------------------------------------------------------------------- 136 // Read data. 137 //--------------------------------------------------------------------------- 138 void Serializer::ReadData(void *pDest, size_t size, size_t count) 139 { 140 size_t rcount = fread(pDest,size,count,mFile); 141 assert(rcount == count); 142 mSize += size*count; 143 } 144 145 //--------------------------------------------------------------------------- 146 // Read data. 147 //--------------------------------------------------------------------------- 148 char * Serializer::ReadData(char *pDest, size_t pDestsize) 149 { 150 return fgets(pDest, (int)pDestsize, mFile); 151 } 152 153 //--------------------------------------------------------------------------- 154 // Write data. 155 //--------------------------------------------------------------------------- 156 void Serializer::WriteData(const String &string) 157 { 158 fputs(string.c_str(), mFile); 159 160 // Write terminating newline char 161 //fputc('\n', mFile); 162 163 mSize += string.length(); 164 } 165 166 //--------------------------------------------------------------------------- 167 // Write string data. 168 //--------------------------------------------------------------------------- 169 void Serializer::WriteData(const char *string) 170 { 171 fputs(string, mFile); 172 173 // Write terminating newline char 174 //fputc('\n', mFile); 175 176 mSize += strlen(string) /*+ 1*/; 177 } 178 179 //--------------------------------------------------------------------------- 180 // Read array of booleans. 181 //--------------------------------------------------------------------------- 182 void Serializer::ReadArray(bool *pDest, size_t count) 183 { 184 //TODO:: Apple has problmes with bools 185 ReadData(pDest,sizeof(bool), count); 186 } 187 188 //--------------------------------------------------------------------------- 189 // Read array of floats. 190 //--------------------------------------------------------------------------- 191 void Serializer::ReadArray(float *pDest, size_t count) 192 { 193 ReadData(pDest, sizeof(float), count); 194 FlipFromLittleEndian(pDest, sizeof(float), count); 195 } 196 197 //--------------------------------------------------------------------------- 198 // Read array of unsigned shots. 199 //--------------------------------------------------------------------------- 200 void Serializer::ReadArray(unsigned short *pDest, size_t count) 201 { 202 ReadData(pDest, sizeof(unsigned short), count); 203 FlipFromLittleEndian(pDest, sizeof(unsigned short), count); 204 } 205 206 //--------------------------------------------------------------------------- 207 // Read array of unsigned integers. 208 //--------------------------------------------------------------------------- 209 void Serializer::ReadArray(unsigned int *pDest, size_t count) 210 { 211 ReadData(pDest, sizeof(unsigned int), count); 212 FlipFromLittleEndian(pDest, sizeof(unsigned int), count); 213 } 214 215 //--------------------------------------------------------------------------- 216 // Read array of Vector3. 217 //--------------------------------------------------------------------------- 218 void Serializer::ReadArray(Vector3 *pDest, size_t count) 219 { 220 for(size_t i = 0; i < count; ++i) 221 { 222 ReadArray(pDest[i].val,3); 223 } 224 } 225 226 //--------------------------------------------------------------------------- 227 // Read array of Vector2. 228 //--------------------------------------------------------------------------- 229 void Serializer::ReadArray(Vector2 *pDest, size_t count) 230 { 231 for(size_t i = 0; i < count; ++i) 232 { 233 ReadArray(pDest[i].val,2); 234 } 235 } 236 237 //--------------------------------------------------------------------------- 238 // Flip to Little Endian. 239 //--------------------------------------------------------------------------- 240 void Serializer::FlipToLittleEndian(void *pData, size_t size, size_t count) 241 { 242 # if GEO_ENDIAN == GEO_ENDIAN_BIG 243 FlipEndian(pData, size, count); 244 # endif 245 } 246 247 //--------------------------------------------------------------------------- 248 // Flip from Little Endian. 249 //--------------------------------------------------------------------------- 250 void Serializer::FlipFromLittleEndian(void *pData, size_t size, size_t count) 251 { 252 # if GEO_ENDIAN == GEO_ENDIAN_BIG 253 FlipEndian(pData, size, count); 254 # endif 255 } 256 257 //--------------------------------------------------------------------------- 258 // Flip Endian. 259 //--------------------------------------------------------------------------- 260 void Serializer::FlipEndian(void *pData, size_t size, size_t count) 261 { 262 for(unsigned int index = 0; index < count; index++) 263 { 264 FlipEndian((void *)((char*)pData + (index * size)), size); 265 } 266 } 267 268 //--------------------------------------------------------------------------- 269 // Flip Endian. 270 //--------------------------------------------------------------------------- 271 void Serializer::FlipEndian(void *pData, size_t size) 272 { 273 char swapByte; 274 for(unsigned int byteIndex = 0; byteIndex < size/2; byteIndex++) 275 { 276 swapByte = *((char *)pData + byteIndex); 277 *((char *)pData + byteIndex) = *((char *)pData + size - byteIndex - 1); 278 *((char *)pData + size - byteIndex - 1) = swapByte; 279 } 280 } 281 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoSubMesh.cpp
r980 r1009 3 3 using namespace Geometry; 4 4 5 //--------------------------------------------------------------------------- 6 // Constructor. 7 //--------------------------------------------------------------------------- 5 8 SubMesh::SubMesh(): 6 mIndex(0), mVertexBuffer(0), mIndexCount(0),mSharedVertexBuffer(false), mStrip(0), mStripCount(0), mType(GEO_TRIANGLE_LIST) 9 mIndex(0), 10 mVertexBuffer(0), 11 mIndexCount(0), 12 mSharedVertexBuffer(false), 13 mStrip(0), 14 mStripCount(0), 15 mType(GEO_TRIANGLE_LIST) 7 16 { 8 17 strcpy(mMaterialName,""); 9 18 } 10 19 20 //--------------------------------------------------------------------------- 21 // Destroyer. 22 //--------------------------------------------------------------------------- 11 23 SubMesh::~SubMesh() 12 24 { 13 delete[] mIndex; 14 if (!mSharedVertexBuffer) delete mVertexBuffer; 15 } 16 17 void SubMesh::Load(Serializer &s) 18 { 19 //Clear Data: 20 delete[] mIndex; mIndex = 0; 25 delete [] mIndex; 26 21 27 if (!mSharedVertexBuffer) 22 28 { 23 29 delete mVertexBuffer; 24 mVertexBuffer = 0;25 30 } 26 mIndexCount = 0; 31 } 27 32 28 //Load Data from Serializer 29 s.ReadArray(&mSharedVertexBuffer,1); 33 //--------------------------------------------------------------------------- 34 // Load data from a serializer. 35 //--------------------------------------------------------------------------- 36 void SubMesh::Load(Serializer &s) 37 { 38 // Clear Data. 39 delete [] mIndex; 40 41 mIndex = 0; 42 43 if (!mSharedVertexBuffer) 44 { 45 delete mVertexBuffer; 46 47 mVertexBuffer = 0; 48 } 49 50 mIndexCount = 0; 51 52 // Load Data from Serializer. 53 s.ReadArray(&mSharedVertexBuffer, 1); 54 30 55 if (mSharedVertexBuffer) 31 56 { 32 mVertexBuffer =0;57 mVertexBuffer = 0; 33 58 } 34 59 else 35 60 { 36 mVertexBuffer = new VertexBuffer(); 61 mVertexBuffer = new VertexBuffer(); 62 37 63 mVertexBuffer->Load(s); 38 } ;64 } 39 65 40 s.ReadArray(&mIndexCount,1); 41 mIndex = new Index[mIndexCount]; 42 s.ReadArray(mIndex,mIndexCount); 66 s.ReadArray(&mIndexCount, 1); 67 68 mIndex = new Index[mIndexCount]; 69 70 s.ReadArray(mIndex, mIndexCount); 43 71 } 44 72 73 //--------------------------------------------------------------------------- 74 // Save data to a serializer. 75 //--------------------------------------------------------------------------- 45 76 void SubMesh::Save(Serializer &s) 46 77 { 47 s.WriteArray(&mSharedVertexBuffer,1); 78 s.WriteArray(&mSharedVertexBuffer, 1); 79 48 80 if (!mSharedVertexBuffer) 49 81 { 50 82 mVertexBuffer->Save(s); 51 83 } 52 s.WriteArray(&mIndexCount,1); 53 s.WriteArray(mIndex,mIndexCount); 84 85 s.WriteArray(&mIndexCount, 1); 86 s.WriteArray(mIndex, mIndexCount); 54 87 } 88 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimpSequence.cpp
r774 r1009 23 23 int cont; 24 24 25 if (s. miReadData(buffer,256) != NULL)25 if (s.ReadData(buffer,256) != NULL) 26 26 { 27 27 sscanf(buffer,"%s",&nombre); … … 30 30 } 31 31 32 while (s. miReadData(buffer,256) != NULL)32 while (s.ReadData(buffer,256) != NULL) 33 33 { 34 34 Geometry::TreeSimplificationSequence::Step pasosimp; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoVertexBuffer.cpp
r774 r1009 3 3 using namespace Geometry; 4 4 5 //--------------------------------------------------------------------- 5 //--------------------------------------------------------------------------- 6 // Destroyer. 7 //--------------------------------------------------------------------------- 6 8 VertexBuffer::~VertexBuffer() 7 9 { 8 delete [] mPosition;9 delete [] mNormal;10 delete [] mTexCoords;10 delete [] mPosition; 11 delete [] mNormal; 12 delete [] mTexCoords; 11 13 } 12 14 13 //--------------------------------------------------------------------- 15 //--------------------------------------------------------------------------- 16 // Save to a serializer. 17 //--------------------------------------------------------------------------- 14 18 void VertexBuffer::Save(Serializer &s) 15 19 { 16 s.WriteArray(&mVertexInfo,1); 17 s.WriteArray(&mVertexCount,1); 20 s.WriteArray(&mVertexInfo, 1); 21 s.WriteArray(&mVertexCount, 1); 22 18 23 if (mVertexInfo & VERTEX_POSITION) 19 24 { … … 30 35 } 31 36 32 //--------------------------------------------------------------------- 37 //--------------------------------------------------------------------------- 38 // Loads from a serializer. 39 //--------------------------------------------------------------------------- 33 40 void VertexBuffer::Load(Serializer &s) 34 41 { 35 //Clear data 36 delete[] mPosition; mPosition = 0; 37 delete[] mNormal; mNormal = 0; 38 delete[] mTexCoords; mTexCoords = 0; 42 // Clear data. 43 delete [] mPosition; 44 45 mPosition = 0; 46 47 delete [] mNormal; 48 49 mNormal = 0; 50 51 delete [] mTexCoords; 52 53 mTexCoords = 0; 39 54 40 55 s.ReadArray(&mVertexInfo,1); 41 56 s.ReadArray(&mVertexCount,1); 57 42 58 if (mVertexInfo & VERTEX_POSITION) 43 59 { 44 mPosition = new Vector3[mVertexCount]; 60 mPosition = new Vector3[mVertexCount]; 61 45 62 s.ReadArray(mPosition, mVertexCount); 46 63 } 64 47 65 if (mVertexInfo & VERTEX_NORMAL) 48 66 { 49 mNormal = new Vector3[mVertexCount]; 67 mNormal = new Vector3[mVertexCount]; 68 50 69 s.ReadArray(mNormal, mVertexCount); 51 70 } 71 52 72 if (mVertexInfo & VERTEX_TEXCOORDS) 53 73 { 54 mTexCoords = new Vector2[mVertexCount]; 74 mTexCoords = new Vector2[mVertexCount]; 75 55 76 s.ReadArray(mTexCoords, mVertexCount); 56 77 } 57 78 } 58 79 59 //--------------------------------------------------------------------- 80 //--------------------------------------------------------------------------- 81 // Copy contents of vertex buffer to another. 82 //--------------------------------------------------------------------------- 60 83 VertexBuffer *VertexBuffer::Clone() const 61 84 { 62 VertexBuffer *vnew =new VertexBuffer();63 vnew->mVertexInfo =mVertexInfo;64 vnew->mVertexCount =mVertexCount;65 vnew->mPosition =new Vector3[mVertexCount];66 vnew->mNormal =new Vector3[mVertexCount];67 vnew->mTexCoords =new Vector2[mVertexCount];85 VertexBuffer *vnew = new VertexBuffer(); 86 vnew->mVertexInfo = mVertexInfo; 87 vnew->mVertexCount = mVertexCount; 88 vnew->mPosition = new Vector3[mVertexCount]; 89 vnew->mNormal = new Vector3[mVertexCount]; 90 vnew->mTexCoords = new Vector2[mVertexCount]; 68 91 69 92 memcpy(vnew->mPosition, mPosition, mVertexCount*sizeof(Vector3)); 70 93 memcpy(vnew->mNormal, mNormal, mVertexCount*sizeof(Vector3)); 71 94 memcpy(vnew->mTexCoords, mTexCoords, mVertexCount*sizeof(Vector2)); 72 return vnew; 95 96 return vnew; 73 97 } 98 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp
r1007 r1009 369 369 mVMISteps.push_back(step); 370 370 } 371
Note: See TracChangeset
for help on using the changeset viewer.