[774] | 1 | /* ==========================================================================
|
---|
| 2 | * (C) 2005 Universitat Jaume I
|
---|
| 3 | * ==========================================================================
|
---|
| 4 | * PROYECT: GAME TOOLS
|
---|
| 5 | * ==========================================================================*/
|
---|
| 6 | /** CONTENT:
|
---|
| 7 | *
|
---|
| 8 | *
|
---|
| 9 | * @file GeoMeshLoader.cpp
|
---|
| 10 | /*===========================================================================*/
|
---|
| 11 | #include "GeoMeshLoader.h"
|
---|
| 12 |
|
---|
| 13 | using namespace Geometry;
|
---|
| 14 | using namespace std;
|
---|
| 15 |
|
---|
| 16 | // Jump a chunk.
|
---|
| 17 | void GeoMeshLoader::jumpChunk(FILE *f)
|
---|
| 18 | {
|
---|
| 19 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 20 |
|
---|
| 21 | // Return to the begin of the chunk.
|
---|
| 22 | fseek(f,long_actual,SEEK_CUR);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | // Read a chunk.
|
---|
| 26 | unsigned short GeoMeshLoader::readChunk(FILE *f)
|
---|
| 27 | {
|
---|
| 28 | unsigned short id;
|
---|
| 29 |
|
---|
| 30 | fread(&id,sizeof(unsigned short),1,f);
|
---|
| 31 | fread(&long_actual,sizeof(unsigned long),1,f);
|
---|
| 32 |
|
---|
| 33 | return id;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | // Read geometry vertex element.
|
---|
| 37 | void GeoMeshLoader::readGeometryVertexElement(FILE *f, Mesh *geoMesh)
|
---|
| 38 | {
|
---|
| 39 | unsigned short source;
|
---|
| 40 | GeometryElement aux;
|
---|
| 41 | int i;
|
---|
| 42 | bool encontrado;
|
---|
| 43 | VertexElementType vType;
|
---|
| 44 |
|
---|
| 45 | i = 0;
|
---|
| 46 | encontrado = false;
|
---|
| 47 |
|
---|
| 48 | // VertexElementSemantic vSemantic;
|
---|
| 49 | // unsigned short source; // buffer bind source
|
---|
| 50 | fread(&source,sizeof(unsigned short),1,f);
|
---|
| 51 |
|
---|
| 52 | // unsigned short type; // VertexElementType
|
---|
| 53 | fread(&aux.type,sizeof(unsigned short),1,f);
|
---|
| 54 |
|
---|
| 55 | vType = static_cast<VertexElementType>(aux.type);
|
---|
| 56 |
|
---|
| 57 | if (vType == VET_FLOAT3)
|
---|
| 58 | {
|
---|
| 59 | printf("%u es float3 ",aux.type);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | if (vType == VET_FLOAT4)
|
---|
| 63 | {
|
---|
| 64 | printf("%u es float4 ",aux.type);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | if (vType == VET_FLOAT2)
|
---|
| 68 | {
|
---|
| 69 | printf("%u es float2 ",aux.type);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | // unsigned short semantic; // VertexElementSemantic
|
---|
| 73 | fread(&aux.semantic,sizeof(unsigned short),1,f);
|
---|
| 74 |
|
---|
| 75 | // vSemantic = static_cast<VertexElementSemantic>(tmp);
|
---|
| 76 | // unsigned short offset; // start offset in buffer in bytes
|
---|
| 77 | fread(&aux.offset,sizeof(unsigned short),1,f);
|
---|
| 78 |
|
---|
| 79 | // unsigned short index; // index of the semantic
|
---|
| 80 | /*
|
---|
| 81 | VES_POSITION Position, 3 reals per vertex.
|
---|
| 82 | VES_BLEND_WEIGHTS Blending weights.
|
---|
| 83 | VES_BLEND_INDICES Blending indices.
|
---|
| 84 | VES_NORMAL Normal, 3 reals per vertex.
|
---|
| 85 | VES_DIFFUSE Diffuse colours.
|
---|
| 86 | VES_SPECULAR Specular colours.
|
---|
| 87 | VES_TEXTURE_COORDINATES Texture coordinates.
|
---|
| 88 | VES_BINORMAL Binormal (Y axis if normal is Z).
|
---|
| 89 | VES_TANGENT Tangent (X axis if normal is Z).
|
---|
| 90 | */
|
---|
| 91 | fread(&aux.index,sizeof(unsigned short),1,f);
|
---|
| 92 |
|
---|
| 93 | while ((i < list.size()) && (!encontrado))
|
---|
| 94 | {
|
---|
| 95 | if (list[i].source==source)
|
---|
| 96 | {
|
---|
| 97 | encontrado = true;
|
---|
| 98 | }
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
| 101 | i++;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | if (encontrado)
|
---|
| 106 | {
|
---|
| 107 | list[i].list.push_back(aux);
|
---|
| 108 | }
|
---|
| 109 | else
|
---|
| 110 | {
|
---|
| 111 | GT aux2;
|
---|
| 112 |
|
---|
| 113 | aux2.source = source;
|
---|
| 114 | aux2.list.push_back(aux);
|
---|
| 115 | list.push_back(aux2);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | // Debug.
|
---|
| 119 | cout << "Finish Vertex Element" << endl;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | // Read geometry vertex declaration.
|
---|
| 123 | void GeoMeshLoader::readGeometryVertexDeclaration(FILE *f, Mesh *geoMesh)
|
---|
| 124 | {
|
---|
| 125 | unsigned short chunkID;
|
---|
| 126 | // Find optional geometry chunks
|
---|
| 127 | if (!feof(f))
|
---|
| 128 | {
|
---|
| 129 | chunkID = readChunk(f);
|
---|
| 130 |
|
---|
| 131 | while(!feof(f) && (chunkID == M_GEOMETRY_VERTEX_ELEMENT ))
|
---|
| 132 | {
|
---|
| 133 | switch (chunkID)
|
---|
| 134 | {
|
---|
| 135 | case M_GEOMETRY_VERTEX_ELEMENT:
|
---|
| 136 | cout << "M_GEOMETRY_VERTEX_ELEMENT" << endl;
|
---|
| 137 | readGeometryVertexElement(f, geoMesh);
|
---|
| 138 | break;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | // Get next chunk
|
---|
| 142 | if (!feof(f))
|
---|
| 143 | {
|
---|
| 144 | chunkID = readChunk(f);
|
---|
| 145 | }
|
---|
| 146 | }// End while.
|
---|
| 147 |
|
---|
| 148 | if (!feof(f))
|
---|
| 149 | {
|
---|
| 150 | // Backpedal back to start of non-submesh chunk
|
---|
| 151 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | }// End if (!feof(f))
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | // Read geometry vertex buffer.
|
---|
| 158 | void GeoMeshLoader::readGeometryVertexBuffer(FILE *f, Mesh *geoMesh, int option)
|
---|
| 159 | {
|
---|
| 160 | unsigned short bindIndex;
|
---|
| 161 | unsigned short vertexSize;
|
---|
| 162 | unsigned short headerID;
|
---|
| 163 | int i;
|
---|
| 164 | float aux;
|
---|
| 165 | int k;
|
---|
| 166 | bool encontrado;
|
---|
| 167 | float x,y,z;
|
---|
| 168 | SubMesh *geoSubMesh;
|
---|
| 169 | VertexBuffer *vertex_buffer;
|
---|
| 170 |
|
---|
| 171 | i = 0;
|
---|
| 172 | k = 0;
|
---|
| 173 | encontrado = false;
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | if (option == GEOMESH_BUILD)
|
---|
| 177 | {
|
---|
| 178 | // If is the main mesh.
|
---|
| 179 | if (currentSubMesh == -1)
|
---|
| 180 | {
|
---|
| 181 | vertex_buffer = geoMesh->mVertexBuffer;
|
---|
| 182 | }
|
---|
| 183 | // If is a submesh.
|
---|
| 184 | else
|
---|
| 185 | {
|
---|
| 186 | // Gets the current submesh
|
---|
| 187 | geoSubMesh = &geoMesh->mSubMesh[currentSubMesh];
|
---|
| 188 | vertex_buffer = geoSubMesh->mVertexBuffer;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | // Index to bind this buffer to
|
---|
| 193 | fread(&bindIndex,sizeof(unsigned short),1,f);
|
---|
| 194 |
|
---|
| 195 | // Per-vertex size, must agree with declaration at this index
|
---|
| 196 | fread(&vertexSize,sizeof(unsigned short),1,f);
|
---|
| 197 |
|
---|
| 198 | // Debug.
|
---|
| 199 | cout << "Per-vertex size: "
|
---|
| 200 | << vertexSize
|
---|
| 201 | << endl;
|
---|
| 202 |
|
---|
| 203 | // Check for vertex data header
|
---|
| 204 | headerID = readChunk(f);
|
---|
| 205 |
|
---|
| 206 | if (headerID != M_GEOMETRY_VERTEX_BUFFER_DATA)
|
---|
| 207 | {
|
---|
| 208 | cout << "Can't find vertex buffer data area"
|
---|
| 209 | << endl;
|
---|
| 210 | }
|
---|
| 211 | else
|
---|
| 212 | {
|
---|
| 213 | cout << "M_GEOMETRY_VERTEX_BUFFER_DATA" << endl;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | while ((i<list.size())&&(!encontrado))
|
---|
| 217 | {
|
---|
| 218 | if (list[i].source == bindIndex)
|
---|
| 219 | {
|
---|
| 220 | encontrado = true;
|
---|
| 221 | }
|
---|
| 222 | else
|
---|
| 223 | {
|
---|
| 224 | i++;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | // Considero q los van por grupitos de vertices+normales+...
|
---|
| 229 | // para cada uno de los vertices
|
---|
| 230 | if (encontrado)
|
---|
| 231 | {
|
---|
| 232 | FILE * salida;
|
---|
| 233 | salida=fopen(nom_salida,"a");
|
---|
| 234 | cout << "----->Leo los vertices"
|
---|
| 235 | << endl;
|
---|
| 236 |
|
---|
| 237 | for (k=0;k<numVertices;k++)
|
---|
| 238 | {
|
---|
| 239 | //Para cada uno de los elementos de ese source.
|
---|
| 240 | for(int j=0;j<list[i].list.size();j++)
|
---|
| 241 | {
|
---|
| 242 | // Son posiciones, vertices
|
---|
| 243 | if (list[i].list[j].semantic==1)
|
---|
| 244 | {
|
---|
| 245 | fread(&x,sizeof(float),1,f);
|
---|
| 246 | fread(&y,sizeof(float),1,f);
|
---|
| 247 | fread(&z,sizeof(float),1,f);
|
---|
| 248 |
|
---|
| 249 | if (option == GEOMESH_BUILD)
|
---|
| 250 | {
|
---|
| 251 | vertex_buffer->mVertexInfo |= VERTEX_POSITION;
|
---|
| 252 | vertex_buffer->mPosition[k].x = x;
|
---|
| 253 | vertex_buffer->mPosition[k].y = y;
|
---|
| 254 | vertex_buffer->mPosition[k].z = z;
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 | // si no son vertices no lo quiero
|
---|
| 258 | else
|
---|
| 259 | {
|
---|
| 260 | //Se tendría que hacer con un fseek
|
---|
| 261 | if (list[i].list[j].type==2) //Son 3 floats
|
---|
| 262 | {
|
---|
| 263 | fread(&x,sizeof(float),1,f);
|
---|
| 264 | fread(&y,sizeof(float),1,f);
|
---|
| 265 | fread(&z,sizeof(float),1,f);
|
---|
| 266 |
|
---|
| 267 | if (option == GEOMESH_BUILD)
|
---|
| 268 | {
|
---|
| 269 | vertex_buffer->mVertexInfo |= VERTEX_NORMAL;
|
---|
| 270 | vertex_buffer->mNormal[k].x = x;
|
---|
| 271 | vertex_buffer->mNormal[k].y = y;
|
---|
| 272 | vertex_buffer->mNormal[k].z = z;
|
---|
| 273 | }
|
---|
| 274 | }
|
---|
| 275 | if (list[i].list[j].type==1) //Son 2 floats
|
---|
| 276 | {
|
---|
| 277 | fread(&x,sizeof(float),1,f);
|
---|
| 278 | fread(&y,sizeof(float),1,f);
|
---|
| 279 |
|
---|
| 280 | if (option == GEOMESH_BUILD)
|
---|
| 281 | {
|
---|
| 282 | vertex_buffer->mVertexInfo |= VERTEX_TEXCOORDS;
|
---|
| 283 | vertex_buffer->mTexCoords[k].x = x;
|
---|
| 284 | vertex_buffer->mTexCoords[k].y = y;
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 | fclose(salida);
|
---|
| 291 | }
|
---|
| 292 | else
|
---|
| 293 | {
|
---|
| 294 | cout << "Error"
|
---|
| 295 | << endl;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | // Read geometry.
|
---|
| 301 | void GeoMeshLoader::readGeometry(FILE *f, Mesh *geoMesh, int option)
|
---|
| 302 | {
|
---|
| 303 | SubMesh *geoSubMesh;
|
---|
| 304 | VertexBuffer *vertex_buffer;
|
---|
| 305 |
|
---|
| 306 | fread(&numVertices,sizeof(unsigned int),1,f);
|
---|
| 307 |
|
---|
| 308 | if (option == GEOMESH_BUILD)
|
---|
| 309 | {
|
---|
| 310 | if (currentSubMesh == -1)
|
---|
| 311 | {
|
---|
| 312 | // Get the current vertex buffer.
|
---|
| 313 | vertex_buffer = geoMesh->mVertexBuffer;
|
---|
| 314 | }
|
---|
| 315 | else
|
---|
| 316 | {
|
---|
| 317 | // Get the current submesh.
|
---|
| 318 | geoSubMesh = &geoMesh->mSubMesh[currentSubMesh];
|
---|
| 319 |
|
---|
| 320 | // Create the VertexBuffer of the submesh.
|
---|
| 321 | geoSubMesh->mVertexBuffer = new VertexBuffer();
|
---|
| 322 |
|
---|
| 323 | // Get the current vertex buffer.
|
---|
| 324 | vertex_buffer = geoSubMesh->mVertexBuffer;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | // Initialize the VertexBuffer of the current submesh.
|
---|
| 328 | vertex_buffer->mVertexCount = numVertices;
|
---|
| 329 |
|
---|
| 330 | // Initialize the position array.
|
---|
| 331 | vertex_buffer->mPosition = new Vector3[numVertices];
|
---|
| 332 |
|
---|
| 333 | // Initialize the normal array.
|
---|
| 334 | vertex_buffer->mNormal = new Vector3[numVertices];
|
---|
| 335 |
|
---|
| 336 | // Initialize the texture coords array.
|
---|
| 337 | vertex_buffer->mTexCoords = new Vector2[numVertices];
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | // Find optional geometry chunks
|
---|
| 341 | if (!feof(f))
|
---|
| 342 | {
|
---|
| 343 | unsigned short chunkID = readChunk(f);
|
---|
| 344 |
|
---|
| 345 | while(!feof(f) &&
|
---|
| 346 | (chunkID == M_GEOMETRY_VERTEX_DECLARATION ||
|
---|
| 347 | chunkID == M_GEOMETRY_VERTEX_BUFFER ))
|
---|
| 348 | {
|
---|
| 349 | switch (chunkID)
|
---|
| 350 | {
|
---|
| 351 | case M_GEOMETRY_VERTEX_DECLARATION:
|
---|
| 352 | cout<<"M_GEOMETRY_VERTEX_DECLARATION\n";
|
---|
| 353 | readGeometryVertexDeclaration(f, geoMesh);
|
---|
| 354 | break;
|
---|
| 355 | case M_GEOMETRY_VERTEX_BUFFER:
|
---|
| 356 | cout<<"M_GEOMETRY_VERTEX_BUFFER\n";
|
---|
| 357 | readGeometryVertexBuffer(f, geoMesh,option);
|
---|
| 358 | break;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | // Get next chunk.
|
---|
| 362 | if (!feof(f))
|
---|
| 363 | {
|
---|
| 364 | chunkID = readChunk(f);
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 | if (!feof(f))
|
---|
| 368 | {
|
---|
| 369 | // Backpedal back to start of non-submesh chunk.
|
---|
| 370 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | // Read a submesh operation.
|
---|
[826] | 376 | void GeoMeshLoader::readSubMeshOperation( FILE *f,
|
---|
| 377 | Mesh *geoMesh,
|
---|
| 378 | int option)
|
---|
[774] | 379 | {
|
---|
| 380 | unsigned short opType;
|
---|
| 381 | fread(&opType,sizeof(unsigned short),1,f);
|
---|
| 382 | printf("\tLa render operation es %d\n",opType);
|
---|
| 383 |
|
---|
| 384 | if (option == GEOMESH_BUILD)
|
---|
| 385 | {
|
---|
| 386 | if (opType == 5)
|
---|
| 387 | {
|
---|
[826] | 388 | geoMesh->mSubMesh[currentSubMesh].mType = GEO_TRIANGLE_STRIPS;
|
---|
[774] | 389 | }
|
---|
| 390 | else
|
---|
| 391 | {
|
---|
[826] | 392 | geoMesh->mSubMesh[currentSubMesh].mType = GEO_TRIANGLE_LIST;
|
---|
[774] | 393 | }
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | // Read a submesh.
|
---|
| 398 | void GeoMeshLoader::readSubMesh(FILE *f, Mesh *geoMesh, int option)
|
---|
| 399 | {
|
---|
| 400 | SubMesh *geoSubMesh;
|
---|
| 401 | unsigned short chunkID;
|
---|
| 402 | char materialName[255];
|
---|
| 403 | bool useSharedVertices;
|
---|
| 404 | unsigned int numIndices;
|
---|
| 405 | bool idx32bit;
|
---|
| 406 | FILE *salida;
|
---|
| 407 |
|
---|
| 408 | switch (option)
|
---|
| 409 | {
|
---|
| 410 | case SUBMESH_COUNT:
|
---|
| 411 | geoMesh->mSubMeshCount++;
|
---|
| 412 | break;
|
---|
| 413 | case GEOMESH_BUILD:
|
---|
| 414 |
|
---|
| 415 | // Debug.
|
---|
| 416 | cout << "Build GEOMESH" << endl;
|
---|
| 417 |
|
---|
| 418 | // Initialize the new subMesh.
|
---|
| 419 | geoSubMesh = &geoMesh->mSubMesh[currentSubMesh];
|
---|
| 420 |
|
---|
| 421 | cout << "Current SubMesh: "
|
---|
| 422 | << currentSubMesh
|
---|
| 423 | << endl;
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | //La vacio antes de leer el mesh
|
---|
| 427 | list.clear();
|
---|
| 428 |
|
---|
| 429 | fgets(materialName,255,f);
|
---|
| 430 | printf("\tmaterialName: %s",materialName);
|
---|
| 431 |
|
---|
| 432 | fread(&useSharedVertices,sizeof(bool),1,f);
|
---|
| 433 |
|
---|
| 434 | if (option == GEOMESH_BUILD)
|
---|
| 435 | {
|
---|
| 436 | // Obtain the flag of vertex shared.
|
---|
| 437 | geoSubMesh->mSharedVertexBuffer = useSharedVertices;
|
---|
| 438 |
|
---|
| 439 | if (useSharedVertices)
|
---|
| 440 | {
|
---|
| 441 | // The VB of the submesh points to the VB of the mesh.
|
---|
| 442 | geoSubMesh->mVertexBuffer = geoMesh->mVertexBuffer;
|
---|
| 443 |
|
---|
| 444 | cout << "\tUse Shared Vertices"
|
---|
| 445 | << endl;
|
---|
| 446 |
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | fread(&numIndices,sizeof(unsigned int),1,f);
|
---|
| 451 | printf("\tnumIndices: %u\n",numIndices);
|
---|
| 452 | printf("\tnumTriangles: %u\n",numIndices/3);
|
---|
| 453 | fread(&idx32bit,sizeof(bool),1,f);
|
---|
| 454 |
|
---|
| 455 | if (option == GEOMESH_BUILD)
|
---|
| 456 | {
|
---|
| 457 | // Sets the index count of the submesh.
|
---|
| 458 | geoSubMesh->mIndexCount = numIndices;
|
---|
| 459 |
|
---|
| 460 | // Create the index arrar for this submesh.
|
---|
| 461 | geoSubMesh->mIndex = new Index[numIndices];
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | if (idx32bit)
|
---|
| 465 | {
|
---|
| 466 | printf("\tSon 32 bits por indice\n");
|
---|
| 467 | }
|
---|
| 468 | else
|
---|
| 469 | {
|
---|
| 470 | printf("\tSon 16 bits por indice\n");
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | salida = fopen(nom_salida,"a");
|
---|
| 474 |
|
---|
| 475 | fprintf(salida,"\n#----->Leo un subMesh:");
|
---|
| 476 |
|
---|
| 477 | if (useSharedVertices)
|
---|
| 478 | {
|
---|
| 479 | fprintf(salida," shared vertices");
|
---|
| 480 | }
|
---|
| 481 | else
|
---|
| 482 | {
|
---|
| 483 | fprintf(salida,
|
---|
| 484 | " no shared vertices %d triangles",
|
---|
| 485 | numIndices/3);
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | fprintf(salida,"\n# Indexes:");
|
---|
| 489 |
|
---|
| 490 | //Sumo uno a los vertices porque en el obj no puede hacer un vertice 0
|
---|
| 491 | if (idx32bit)
|
---|
| 492 | {
|
---|
| 493 | unsigned int aux;
|
---|
| 494 |
|
---|
| 495 | for (int i = 0; i < numIndices; i++)
|
---|
| 496 | {
|
---|
| 497 | fread(&aux,sizeof(unsigned int),1,f);
|
---|
| 498 |
|
---|
| 499 | if (option == GEOMESH_BUILD)
|
---|
| 500 | {
|
---|
| 501 | geoSubMesh->mIndex[i] = aux;
|
---|
| 502 | }
|
---|
| 503 | }
|
---|
| 504 | }
|
---|
| 505 | else
|
---|
| 506 | {
|
---|
| 507 | unsigned short aux;
|
---|
| 508 |
|
---|
| 509 | for (int i = 0; i < numIndices; i++)
|
---|
| 510 | {
|
---|
| 511 | fread(&aux,sizeof(unsigned short),1,f);
|
---|
| 512 |
|
---|
| 513 | if (option == GEOMESH_BUILD)
|
---|
| 514 | {
|
---|
| 515 | geoSubMesh->mIndex[i] = aux;
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | fclose(salida);
|
---|
| 521 |
|
---|
| 522 | // M_GEOMETRY chunk
|
---|
| 523 | // (Optional: present only if useSharedVertices = false)
|
---|
| 524 | if (!useSharedVertices)
|
---|
| 525 | {
|
---|
| 526 | chunkID = readChunk(f);
|
---|
| 527 |
|
---|
| 528 | if (chunkID != M_GEOMETRY)
|
---|
| 529 | {
|
---|
| 530 | printf("Missing geometry data in mesh file\n"); //Error
|
---|
| 531 | }
|
---|
| 532 |
|
---|
| 533 | readGeometry(f, geoMesh, option);
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | // Find all bone assignments (if present)
|
---|
| 537 | if (!feof(f))
|
---|
| 538 | {
|
---|
| 539 | chunkID = readChunk(f);
|
---|
| 540 | while(!feof(f) &&
|
---|
| 541 | (chunkID == M_SUBMESH_BONE_ASSIGNMENT ||
|
---|
| 542 | chunkID == M_SUBMESH_OPERATION))
|
---|
| 543 | {
|
---|
| 544 | switch(chunkID)
|
---|
| 545 | {
|
---|
| 546 | case M_SUBMESH_OPERATION:
|
---|
| 547 |
|
---|
| 548 | cout<<"M_SUBMESH_OPERATION\n";
|
---|
[826] | 549 |
|
---|
[774] | 550 | readSubMeshOperation(f, geoMesh, option);
|
---|
[826] | 551 |
|
---|
[774] | 552 | break;
|
---|
| 553 | case M_SUBMESH_BONE_ASSIGNMENT:
|
---|
| 554 | jumpChunk(f);
|
---|
| 555 | break;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | if (!feof(f))
|
---|
| 559 | {
|
---|
| 560 | chunkID = readChunk(f);
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | }
|
---|
| 564 | if (!feof(f))
|
---|
| 565 | {
|
---|
| 566 | // Backpedal back to start of chunk
|
---|
| 567 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 568 | }
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | // Read a mesh lod information.
|
---|
| 574 | void GeoMeshLoader::readMeshLodInfo(FILE *f, Mesh *geoMesh)
|
---|
| 575 | {
|
---|
| 576 | unsigned short chunkID;
|
---|
| 577 | unsigned short i;
|
---|
| 578 | unsigned short aux;
|
---|
| 579 | bool aux2;
|
---|
| 580 |
|
---|
| 581 | // unsigned short numLevels;
|
---|
| 582 | fread(&aux,sizeof(unsigned short),1,f);
|
---|
| 583 | // bool manual;
|
---|
| 584 | // (true for manual alternate meshes, false for generated)
|
---|
| 585 | fread(&aux2,sizeof(bool),1,f);
|
---|
| 586 |
|
---|
| 587 | // Loop from 1 rather than 0 (full detail index is not in file)
|
---|
| 588 | for (i = 1; i < aux; ++i)
|
---|
| 589 | {
|
---|
| 590 | chunkID = readChunk(f);
|
---|
| 591 | if (chunkID != M_MESH_LOD_USAGE)
|
---|
| 592 | {
|
---|
| 593 | printf("Missing M_MESH_LOD_USAGE chunk\n"); //Error
|
---|
| 594 | }
|
---|
| 595 | else printf("\tM_MESH_LOD_USAGE (%d bytes) ",long_actual);
|
---|
| 596 | jumpChunk(f);
|
---|
| 597 |
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | // Read a submesh name table.
|
---|
| 602 | void GeoMeshLoader::readSubMeshNameTable(FILE *f, Mesh *geoMesh)
|
---|
| 603 | {
|
---|
| 604 | unsigned short chunkID;
|
---|
| 605 | unsigned short subMeshIndex;
|
---|
| 606 | char string[255];
|
---|
| 607 |
|
---|
| 608 | if (!feof(f))
|
---|
| 609 | {
|
---|
| 610 | chunkID = readChunk(f);
|
---|
| 611 |
|
---|
| 612 | while (!feof(f) && (chunkID == M_SUBMESH_NAME_TABLE_ELEMENT ))
|
---|
| 613 | {
|
---|
| 614 | printf("M_SUBMESH_NAME_TABLE_ELEMENT %d bytes\n",long_actual);
|
---|
| 615 |
|
---|
| 616 | // Read in the index of the submesh.
|
---|
| 617 | fread(&subMeshIndex,sizeof(unsigned short),1,f);
|
---|
| 618 |
|
---|
| 619 | // Read in the String and map it to its index.
|
---|
| 620 | fgets(string,255,f);
|
---|
| 621 | printf("index %u name %s\n",subMeshIndex,string);
|
---|
| 622 |
|
---|
| 623 | // If we're not end of file get the next chunk ID
|
---|
| 624 | if (!feof(f))
|
---|
| 625 | {
|
---|
| 626 | chunkID = readChunk(f);
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
| 629 | if (!feof(f))
|
---|
| 630 | {
|
---|
| 631 | // Backpedal back to start of chunk
|
---|
| 632 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 | }
|
---|
| 636 |
|
---|
| 637 | // Read a mesh file.
|
---|
| 638 | void GeoMeshLoader::readMesh(FILE *f, Mesh *geoMesh, int option)
|
---|
| 639 | {
|
---|
| 640 | unsigned short chunkID;
|
---|
| 641 | bool nada;
|
---|
| 642 |
|
---|
| 643 | // Debug.
|
---|
| 644 | cout << "Read Mesh"
|
---|
| 645 | << endl;
|
---|
| 646 |
|
---|
| 647 | // Create the VertexBuffer of the mesh.
|
---|
| 648 | geoMesh->mVertexBuffer = new VertexBuffer();
|
---|
| 649 | geoMesh->mVertexBuffer->mVertexCount = 0;
|
---|
| 650 |
|
---|
| 651 | //La vacio antes de leer el mesh
|
---|
| 652 | list.clear();
|
---|
| 653 |
|
---|
| 654 | // bool skeletallyAnimated
|
---|
| 655 | fread(&nada,sizeof(bool),1,f);
|
---|
| 656 |
|
---|
| 657 | // Find all subchunks
|
---|
| 658 | if (!feof(f))
|
---|
| 659 | {
|
---|
| 660 | chunkID = readChunk(f);
|
---|
| 661 |
|
---|
| 662 | while(!feof(f) &&
|
---|
| 663 | (chunkID == M_GEOMETRY ||
|
---|
| 664 | chunkID == M_SUBMESH ||
|
---|
| 665 | chunkID == M_MESH_SKELETON_LINK ||
|
---|
| 666 | chunkID == M_MESH_BONE_ASSIGNMENT ||
|
---|
| 667 | chunkID == M_MESH_LOD ||
|
---|
| 668 | chunkID == M_MESH_BOUNDS ||
|
---|
| 669 | chunkID == M_SUBMESH_NAME_TABLE ||
|
---|
| 670 | chunkID == M_EDGE_LISTS))
|
---|
| 671 | {
|
---|
| 672 | switch(chunkID)
|
---|
| 673 | {
|
---|
| 674 | case M_GEOMETRY:
|
---|
| 675 |
|
---|
| 676 | // Debug.
|
---|
| 677 | cout << "Geometry" << endl;
|
---|
| 678 |
|
---|
| 679 | readGeometry(f, geoMesh, option);
|
---|
| 680 | break;
|
---|
| 681 |
|
---|
| 682 | case M_SUBMESH:
|
---|
| 683 |
|
---|
| 684 | cout << "SubMesh" << endl;
|
---|
| 685 |
|
---|
| 686 | if (option == GEOMESH_BUILD)
|
---|
| 687 | {
|
---|
| 688 | // Increments the current submesh.
|
---|
| 689 | currentSubMesh++;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | readSubMesh(f, geoMesh, option);
|
---|
| 693 |
|
---|
| 694 | break;
|
---|
| 695 |
|
---|
| 696 | case M_MESH_SKELETON_LINK:
|
---|
| 697 |
|
---|
| 698 | cout << "M_MESH_SKELETON_LINK "
|
---|
| 699 | << long_actual
|
---|
| 700 | << " bytes\n";
|
---|
| 701 |
|
---|
| 702 | jumpChunk(f);
|
---|
| 703 | break;
|
---|
| 704 |
|
---|
| 705 | case M_MESH_BONE_ASSIGNMENT:
|
---|
| 706 |
|
---|
| 707 | cout << "M_MESH_BONE_ASSIGNMENT "
|
---|
| 708 | << long_actual
|
---|
| 709 | << " bytes\n";
|
---|
| 710 |
|
---|
| 711 | break;
|
---|
| 712 |
|
---|
| 713 | case M_MESH_LOD:
|
---|
| 714 |
|
---|
| 715 | cout << "M_MESH_LOD\n";
|
---|
| 716 | readMeshLodInfo(f, geoMesh);
|
---|
| 717 | break;
|
---|
| 718 |
|
---|
| 719 | case M_MESH_BOUNDS:
|
---|
| 720 |
|
---|
| 721 | cout << "M_MESH_BOUNDS "
|
---|
| 722 | << long_actual
|
---|
| 723 | << " bytes\n";
|
---|
| 724 |
|
---|
| 725 | jumpChunk(f);
|
---|
| 726 | break;
|
---|
| 727 |
|
---|
| 728 | case M_SUBMESH_NAME_TABLE:
|
---|
| 729 |
|
---|
| 730 | cout << "M_SUBMESH_NAME_TABLE "
|
---|
| 731 | << long_actual
|
---|
| 732 | << " bytes\n";
|
---|
| 733 |
|
---|
| 734 | readSubMeshNameTable(f, geoMesh);
|
---|
| 735 | break;
|
---|
| 736 |
|
---|
| 737 | case M_EDGE_LISTS:
|
---|
| 738 |
|
---|
| 739 | cout << "M_EDGE_LISTS "
|
---|
| 740 | << long_actual
|
---|
| 741 | << " bytes\n";
|
---|
| 742 |
|
---|
| 743 | jumpChunk(f);
|
---|
| 744 | break;
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | if (!feof(f))
|
---|
| 748 | {
|
---|
| 749 | chunkID = readChunk(f);
|
---|
| 750 | }
|
---|
| 751 |
|
---|
| 752 | }
|
---|
| 753 |
|
---|
| 754 | if (!feof(f))
|
---|
| 755 | {
|
---|
| 756 | // Backpedal back to start of chunk
|
---|
| 757 | fseek(f,-(long)CHUNK_OVERHEAD_SIZE,1);
|
---|
| 758 | printf("Malo\n");
|
---|
| 759 | }
|
---|
| 760 | }
|
---|
| 761 |
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | /*
|
---|
| 765 | Allocate memory to the array of strips
|
---|
| 766 | */
|
---|
[826] | 767 | SubMesh* GeoMeshLoader::BuildStripsGeoSubMesh(SubMesh* geoSubMesh)
|
---|
[774] | 768 | {
|
---|
| 769 | bool head_found;
|
---|
| 770 | bool tail_found;
|
---|
| 771 | int strip_count;
|
---|
| 772 | int tailIndex;
|
---|
| 773 | size_t tail;
|
---|
| 774 |
|
---|
[826] | 775 |
|
---|
| 776 | head_found = false;
|
---|
| 777 | tail_found = false;
|
---|
| 778 | geoSubMesh->mStripCount = 1;
|
---|
| 779 |
|
---|
| 780 | // Foreachone of the indices.
|
---|
| 781 | // Obtains the number of triangle strips.
|
---|
| 782 | for (int i = 0; i < (geoSubMesh->mIndexCount - 1); i++)
|
---|
[774] | 783 | {
|
---|
[826] | 784 | if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1])
|
---|
[774] | 785 | {
|
---|
[826] | 786 | if (head_found)
|
---|
[774] | 787 | {
|
---|
[826] | 788 | tail_found = true;
|
---|
[774] | 789 | }
|
---|
| 790 | else
|
---|
| 791 | {
|
---|
[826] | 792 | head_found = true;
|
---|
| 793 | }
|
---|
[774] | 794 |
|
---|
[826] | 795 | // Jump one index.
|
---|
| 796 | i++;
|
---|
| 797 | }
|
---|
| 798 | else
|
---|
| 799 | {
|
---|
| 800 | // Increments the number of triangle strips.
|
---|
| 801 | if (tail_found)
|
---|
| 802 | {
|
---|
| 803 | geoSubMesh->mStripCount++;
|
---|
[774] | 804 | }
|
---|
[826] | 805 |
|
---|
| 806 | head_found = false;
|
---|
| 807 | tail_found = false;
|
---|
[774] | 808 | }
|
---|
[826] | 809 | }
|
---|
[774] | 810 |
|
---|
[826] | 811 | geoSubMesh->mStrip = (Index**) malloc( sizeof(Index*)
|
---|
| 812 | *
|
---|
| 813 | geoSubMesh->mStripCount);
|
---|
[774] | 814 |
|
---|
[826] | 815 | // Number of strips. Initially there is one triangle strip.
|
---|
| 816 | strip_count = 1;
|
---|
[774] | 817 |
|
---|
[826] | 818 | head_found = false;
|
---|
| 819 | tail_found = false;
|
---|
[774] | 820 |
|
---|
[826] | 821 | // Initialize the fist triangle strip.
|
---|
| 822 | geoSubMesh->mStrip[0] = &geoSubMesh->mIndex[0];
|
---|
[774] | 823 |
|
---|
[826] | 824 | // Foreachone of the indices.
|
---|
| 825 | // Assigns the beginning of the triangle strips.
|
---|
| 826 | for(int i = 0;i < (geoSubMesh->mIndexCount - 1); i++)
|
---|
| 827 | {
|
---|
| 828 | if(geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1])
|
---|
[774] | 829 | {
|
---|
[826] | 830 | if(head_found)
|
---|
[774] | 831 | {
|
---|
[826] | 832 | if (!tail_found)
|
---|
[774] | 833 | {
|
---|
[826] | 834 | tailIndex = i;
|
---|
[774] | 835 | }
|
---|
| 836 |
|
---|
[826] | 837 | tail_found = true;
|
---|
[774] | 838 | }
|
---|
| 839 | else
|
---|
| 840 | {
|
---|
[826] | 841 | head_found = true;
|
---|
| 842 | }
|
---|
[774] | 843 |
|
---|
[826] | 844 | // Jump one index.
|
---|
| 845 | i++;
|
---|
| 846 | }
|
---|
| 847 | else
|
---|
| 848 | {
|
---|
| 849 | // Increments the number of triangle strips.
|
---|
| 850 | if(tail_found)
|
---|
| 851 | {
|
---|
| 852 | geoSubMesh->mStrip[strip_count++] = &geoSubMesh->mIndex[tailIndex];
|
---|
[774] | 853 | }
|
---|
[826] | 854 |
|
---|
| 855 | head_found = false;
|
---|
| 856 | tail_found = false;
|
---|
[774] | 857 | }
|
---|
| 858 | }
|
---|
| 859 |
|
---|
[891] | 860 | // Remove degenerate triangles of a submesh given.
|
---|
| 861 | geoSubMesh = removeDegenerateTriangles(geoSubMesh);
|
---|
| 862 |
|
---|
[826] | 863 | return geoSubMesh;
|
---|
[774] | 864 | }
|
---|
| 865 |
|
---|
[891] | 866 | // Remove degenerate triangles of a submesh given.
|
---|
| 867 | SubMesh * GeoMeshLoader::removeDegenerateTriangles(SubMesh *geoSubMesh)
|
---|
| 868 | {
|
---|
| 869 | Index *indices;
|
---|
| 870 | Index *index;
|
---|
| 871 | Index *indexBegin;
|
---|
| 872 | Index *indexEnd;
|
---|
| 873 | Index *new_strip_starts;
|
---|
| 874 | size_t new_index_count;
|
---|
| 875 | size_t current_index;
|
---|
| 876 |
|
---|
| 877 | // Stores the new starts of strips.
|
---|
| 878 | new_strip_starts = new Index[geoSubMesh->mStripCount];
|
---|
| 879 |
|
---|
| 880 | // Calculate the new index count.
|
---|
| 881 | new_index_count = geoSubMesh->mIndexCount
|
---|
| 882 | -
|
---|
| 883 | (2 * geoSubMesh->mStripCount)
|
---|
| 884 | +
|
---|
| 885 | 2;
|
---|
| 886 |
|
---|
| 887 | // Auxiliar index array.
|
---|
| 888 | indices = new Index[new_index_count];
|
---|
| 889 |
|
---|
| 890 | // Initialize the current index;
|
---|
| 891 | current_index = 0;
|
---|
| 892 |
|
---|
| 893 | // For each one of the strips.
|
---|
| 894 | for (int strip = 0; strip < geoSubMesh->mStripCount; strip++)
|
---|
| 895 | {
|
---|
| 896 | // Stars of strip without degenerate triangles.
|
---|
| 897 | new_strip_starts[strip] = current_index;
|
---|
| 898 |
|
---|
| 899 | // First index of the strip.
|
---|
| 900 | indexBegin = geoSubMesh->mStrip[strip];
|
---|
| 901 |
|
---|
| 902 | // If is the final strip
|
---|
| 903 | if (strip == (geoSubMesh->mStripCount - 1))
|
---|
| 904 | {
|
---|
| 905 | // The end of the index array.
|
---|
| 906 | indexEnd = &geoSubMesh->mIndex[geoSubMesh->mIndexCount];
|
---|
| 907 | }
|
---|
| 908 | else
|
---|
| 909 | {
|
---|
| 910 | // The beginning of the next strip.
|
---|
| 911 | indexEnd = geoSubMesh->mStrip[strip + 1];
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 | int i;
|
---|
| 915 | i = 0;
|
---|
| 916 |
|
---|
| 917 | // If is not the first strip.
|
---|
| 918 | if (strip != 0)
|
---|
| 919 | {
|
---|
| 920 | indexBegin++;
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | // If is not the last strip.
|
---|
| 924 | if (strip != (geoSubMesh->mStripCount - 1))
|
---|
| 925 | {
|
---|
| 926 | indexEnd--;
|
---|
| 927 | }
|
---|
| 928 |
|
---|
| 929 | // For each index of the strip.
|
---|
| 930 | for (index = indexBegin; index < indexEnd; index++)
|
---|
| 931 | {
|
---|
| 932 | indices[current_index++] = indexBegin[i];
|
---|
| 933 |
|
---|
| 934 | // Increments i.
|
---|
| 935 | i++;
|
---|
| 936 | }
|
---|
| 937 |
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | // Free Index memory.
|
---|
| 941 | delete []geoSubMesh->mIndex;
|
---|
| 942 |
|
---|
| 943 | // Update index count.
|
---|
| 944 | geoSubMesh->mIndexCount = new_index_count;
|
---|
| 945 |
|
---|
| 946 | geoSubMesh->mIndex = new Index[new_index_count];
|
---|
| 947 |
|
---|
| 948 | // Store new index array without degenerate triangles.
|
---|
| 949 | for (size_t i = 0; i < geoSubMesh->mIndexCount; i++)
|
---|
| 950 | {
|
---|
| 951 | geoSubMesh->mIndex[i] = indices[i];
|
---|
| 952 | }
|
---|
| 953 |
|
---|
| 954 | // Free auxiliar index array;
|
---|
| 955 | delete []indices;
|
---|
| 956 |
|
---|
| 957 | // Update start of the strip.
|
---|
| 958 | for (int strip = 0; strip < geoSubMesh->mStripCount; strip++)
|
---|
| 959 | {
|
---|
| 960 | geoSubMesh->mStrip[strip] = &geoSubMesh->mIndex[new_strip_starts[strip]];
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | // Free auxiliar strip starts.
|
---|
| 964 | delete []new_strip_starts;
|
---|
| 965 |
|
---|
| 966 | return geoSubMesh;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
[774] | 969 | // Loads a mesh.
|
---|
| 970 | Mesh* GeoMeshLoader::load(char *nameFileMesh)
|
---|
| 971 | {
|
---|
| 972 | unsigned short uno;
|
---|
| 973 | unsigned short chunkID;
|
---|
| 974 | char version[255];
|
---|
| 975 | char kk;
|
---|
| 976 | FILE *salida;
|
---|
| 977 | FILE *pFile;
|
---|
[826] | 978 | SubMesh *geosubmesh;
|
---|
[774] | 979 |
|
---|
| 980 | // Initialize the current submesh;
|
---|
| 981 | currentSubMesh = -1;
|
---|
| 982 |
|
---|
| 983 | std::cout << "Load a new Mesh"
|
---|
| 984 | << std::endl;
|
---|
| 985 |
|
---|
| 986 | // Initialize the return value.
|
---|
| 987 | geoMesh = new Mesh();
|
---|
| 988 |
|
---|
| 989 | // Open the mesh file.
|
---|
| 990 | pFile = fopen( nameFileMesh, "rb" );
|
---|
| 991 |
|
---|
| 992 | if (!pFile)
|
---|
| 993 | {
|
---|
| 994 | printf("No he encontrado el fichero\n");
|
---|
| 995 | exit(0);
|
---|
| 996 | }
|
---|
| 997 |
|
---|
| 998 | // Count the submeshes
|
---|
| 999 | // and next build the geomesh.
|
---|
| 1000 | for (int option = 0; option < 2;option++)
|
---|
| 1001 | {
|
---|
| 1002 | fread(&uno,sizeof(unsigned short),1,pFile);
|
---|
| 1003 |
|
---|
| 1004 | if (uno != M_HEADER)
|
---|
| 1005 | {
|
---|
| 1006 | cout << "no se ha encontrado el header"
|
---|
| 1007 | << endl;
|
---|
| 1008 | }
|
---|
| 1009 |
|
---|
| 1010 | // Read version.
|
---|
| 1011 | fgets(version,255,pFile);
|
---|
| 1012 |
|
---|
| 1013 | cout << version << endl;
|
---|
| 1014 |
|
---|
| 1015 | if (strcmp(version,"[MeshSerializer_v1.30]\n"))
|
---|
| 1016 | {
|
---|
| 1017 | cout <<
|
---|
| 1018 | "No se puede trabajar con versiones de"
|
---|
| 1019 | <<
|
---|
| 1020 | " .mesh diferentes de la 1.3"
|
---|
| 1021 | <<
|
---|
| 1022 | endl;
|
---|
| 1023 | }
|
---|
| 1024 |
|
---|
| 1025 | salida = fopen(nom_salida,"w");
|
---|
| 1026 |
|
---|
| 1027 | fprintf(salida,"# Empiezo el fichero:");
|
---|
| 1028 |
|
---|
| 1029 | fclose(salida);
|
---|
| 1030 |
|
---|
| 1031 | while(!feof(pFile))
|
---|
| 1032 | {
|
---|
| 1033 | chunkID = readChunk(pFile);
|
---|
| 1034 |
|
---|
| 1035 | switch (chunkID)
|
---|
| 1036 | {
|
---|
| 1037 | case M_MESH:
|
---|
| 1038 | readMesh(pFile, geoMesh, option);
|
---|
| 1039 | break;
|
---|
| 1040 | }
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
| 1043 | // Create the submesh array
|
---|
| 1044 | if (option == SUBMESH_COUNT)
|
---|
| 1045 | {
|
---|
| 1046 | cout << "---------------"
|
---|
| 1047 | << endl;
|
---|
| 1048 |
|
---|
| 1049 | cout << "SubMesh Count: "
|
---|
| 1050 | << geoMesh->mSubMeshCount
|
---|
| 1051 | << endl;
|
---|
| 1052 |
|
---|
| 1053 | geoMesh->mSubMesh = new SubMesh[geoMesh->mSubMeshCount];
|
---|
| 1054 | }
|
---|
| 1055 |
|
---|
| 1056 | if (feof(pFile))
|
---|
| 1057 | {
|
---|
| 1058 | cout << "------->Hemos llegado al final del fichero"
|
---|
| 1059 | << endl;
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | //cout << "Press enter to exit\n";
|
---|
| 1063 |
|
---|
| 1064 | // Move the curso to the begining of the file.
|
---|
| 1065 | fseek(pFile,0,SEEK_SET);
|
---|
| 1066 | }
|
---|
| 1067 |
|
---|
| 1068 | // Goes to the end of the file.
|
---|
| 1069 | fseek(pFile,0,SEEK_END);
|
---|
| 1070 |
|
---|
| 1071 | // Gets the size of the file.
|
---|
| 1072 | mFileSize = ftell(pFile);
|
---|
| 1073 |
|
---|
| 1074 | // Close the mesh file.
|
---|
| 1075 | fclose(pFile);
|
---|
| 1076 |
|
---|
[826] | 1077 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
|
---|
[774] | 1078 | {
|
---|
[826] | 1079 | // Gets the actual submesh.
|
---|
| 1080 | geosubmesh = &geoMesh->mSubMesh[submesh];
|
---|
| 1081 |
|
---|
| 1082 | if (geosubmesh->mType == Geometry::GEO_TRIANGLE_STRIPS)
|
---|
| 1083 | {
|
---|
| 1084 | // Fill the strips list.
|
---|
| 1085 | geosubmesh = BuildStripsGeoSubMesh(geosubmesh);
|
---|
| 1086 | }
|
---|
[774] | 1087 | }
|
---|
| 1088 |
|
---|
| 1089 | return geoMesh;
|
---|
| 1090 | }
|
---|
| 1091 |
|
---|
| 1092 | // Get the size in bytes of the file.
|
---|
| 1093 | size_t GeoMeshLoader::getFileSize()
|
---|
| 1094 | {
|
---|
| 1095 | return mFileSize;
|
---|
| 1096 | }
|
---|
| 1097 |
|
---|
| 1098 | // Constructor
|
---|
| 1099 | GeoMeshLoader::GeoMeshLoader()
|
---|
| 1100 | {
|
---|
| 1101 | nom_salida = "salida22.obj";
|
---|
| 1102 | geoMesh = NULL;
|
---|
| 1103 | mFileSize = 0;
|
---|
| 1104 | }
|
---|
| 1105 |
|
---|
| 1106 | // Destroyer.
|
---|
| 1107 | GeoMeshLoader::~GeoMeshLoader()
|
---|
| 1108 | {
|
---|
| 1109 | delete geoMesh;
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|