Changeset 1024 for GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Timestamp:
- 06/20/06 13:02:00 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r1014 r1024 59 59 { 60 60 return msimpsequence; 61 } 62 63 //--------------------------------------------------------------------------- 64 // Sort mesh bones. 65 //--------------------------------------------------------------------------- 66 void MeshSimplifier::sortBones() 67 { 68 Mesh *mesh_copy; 69 int n; 70 int o; 71 int p; 72 VertexBoneAssignment assign; 73 VertexBuffer *mesh_vb; 74 VertexBuffer *undo_vb; 75 SubMesh *geosubmesh; 76 SubMesh *undosubmesh; 77 78 // Gets a copy of the mesh. 79 mesh_copy = new Mesh(); 80 *mesh_copy = *mGeoMesh; 81 82 // For each submesh. 83 for (size_t i = 0; i < mGeoMesh->mSubMeshCount; i++) 84 { 85 geosubmesh = &mGeoMesh->mSubMesh[i]; 86 undosubmesh = &mesh_copy->mSubMesh[i]; 87 88 // If there is submesh bones. 89 if (!geosubmesh->mBones.empty()) 90 { 91 assign.boneIndex = 0; 92 assign.weight = 1; 93 94 geosubmesh->mBones.clear(); 95 96 for (int m = 0; m < geosubmesh->mVertexBuffer->mVertexCount; m++) 97 { 98 assign.vertexIndex = m; 99 100 geosubmesh->mBones.push_back(assign); 101 } 102 103 // Change bones. 104 for (int m = 0; m < geosubmesh->mBones.size(); m++) 105 { 106 n = geosubmesh->mBones[m].vertexIndex; 107 108 // Initialize o. 109 o = 0; 110 111 mesh_vb = geosubmesh->mVertexBuffer; 112 undo_vb = undosubmesh->mVertexBuffer; 113 114 while (!( 115 (mesh_vb->mPosition[n].x == undo_vb->mPosition[o].x) 116 && 117 (mesh_vb->mPosition[n].y == undo_vb->mPosition[o].y) 118 && 119 (mesh_vb->mPosition[n].z == undo_vb->mPosition[o].z) 120 )) 121 { 122 o++; 123 } 124 125 // Initialize p. 126 p = 0; 127 128 while (undosubmesh->mBones[p].vertexIndex != o) 129 { 130 p++; 131 } 132 133 // Same bone for 'm' and 'p'. 134 geosubmesh->mBones[m].boneIndex = undosubmesh->mBones[p].boneIndex; 135 } 136 } 137 } 138 139 // Delete copy of the mesh. 140 delete mesh_copy; 61 141 } 62 142 … … 306 386 307 387 //--------------------------------------------------------------------------- 308 // Init vmi mesh structure for a geometry mesh given. 388 // Class for join triangle holes. 389 //--------------------------------------------------------------------------- 390 class _coord_ 391 { 392 public: 393 float x,y,z; 394 inline _coord_( float x = 0.0f, 395 float y = 0.0f, 396 float z = 0.0f) 397 { this->x = x; this->y = y; this->z = z; } 398 399 inline _coord_(const _coord_ &f) 400 { 401 x = f.x; 402 y=f.y; 403 z=f.z; 404 } 405 406 inline _coord_ & operator=(const _coord_ &f) 407 { 408 x = f.x; 409 y = f.y; 410 z = f.z; 411 412 return *this; 413 } 414 415 inline bool operator<(const _coord_ &f) const 416 { 417 if (x<f.x-0.0001) return true; 418 if (x>f.x+0.0001) return false; 419 if (y<f.y-0.0001) return true; 420 if (y>f.y+0.0001) return false; 421 if (z<f.z-0.0001) return true; 422 if (z>f.z+0.0001) return false; 423 424 return false; 425 } 426 }; 427 428 //--------------------------------------------------------------------------- 429 // Initialize the mesh of VMI module. 309 430 //--------------------------------------------------------------------------- 310 431 VMI::Mesh * ViewPointDrivenSimplifier::initMeshStructure(Mesh *geoMesh) … … 360 481 361 482 printf("Adding vertices..."); 362 363 483 // Fill up vertices. 484 std::map<_coord_, int> uniquevertices; 485 std::map<int, int> newindices; 364 486 for (i = 0; i < vertex_buffer->mVertexCount; i++) 365 487 { 488 _coord_ vertex_aux; 489 vertex_aux.x= vertex_buffer->mPosition[i].x; 490 vertex_aux.y= vertex_buffer->mPosition[i].y; 491 vertex_aux.z= vertex_buffer->mPosition[i].z; 492 //New index 493 if (uniquevertices.find(vertex_aux)==uniquevertices.end()) 494 { 495 uniquevertices[vertex_aux]= i; 496 newindices[i]= i; 497 498 VMI::INTVECTOR intvectoraux; 499 intvectoraux.push_back(i); 500 VMI::inversemap[i]= intvectoraux; 501 502 }else//The map of unique vertices already contains this vertex 503 { 504 int newindex= uniquevertices[vertex_aux]; 505 newindices[i]= newindex; 506 507 VMI::inversemap[newindex].push_back(i);; 508 } 509 366 510 // Vertices start at 0. 367 511 vmi_mesh->vertices[i].x = vertex_buffer->mPosition[i].x; … … 394 538 vmi_mesh->triangles[index].id = index; 395 539 vmi_mesh->triangles[index].submesh = submesh; 396 vmi_mesh->triangles[index].indices[0] = geosubmesh->mIndex[(3 * i)];397 vmi_mesh->triangles[index].indices[1] = geosubmesh->mIndex[(3 * i) + 1];398 vmi_mesh->triangles[index].indices[2] = geosubmesh->mIndex[(3 * i) + 2];540 vmi_mesh->triangles[index].indices[0] = newindices[geosubmesh->mIndex[(3 * i)]]; 541 vmi_mesh->triangles[index].indices[1] = newindices[geosubmesh->mIndex[(3 * i) + 1]]; 542 vmi_mesh->triangles[index].indices[2] = newindices[geosubmesh->mIndex[(3 * i) + 2]]; 399 543 400 544 vmi_mesh->triangles[index].area = computeTriangleArea(vmi_mesh->vertices, -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/include/change.h
r1009 r1024 4 4 #include "mesh.h" 5 5 #include <vector> 6 #include <map> 6 7 7 8 namespace VMI 8 9 { 10 typedef std::vector<int> INTVECTOR; 11 9 12 typedef struct change 10 13 { … … 63 66 // Save simplification sequence in Geometry Game Tools format. 64 67 extern void saveSimplificationSequence(Change *c); 68 69 extern std::map<int, INTVECTOR> inversemap; 65 70 } 66 71 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/vmi/src/change.cpp
r1009 r1024 332 332 } 333 333 334 namespace VMI{ 335 std::map<int, INTVECTOR> inversemap; 336 } 337 334 338 // Save simplification sequence in Geometry Game Tools format. 335 339 extern void VMI::saveSimplificationSequence(Change *c) 336 340 { 337 vmiStep step; 338 step.mV0 = c->u; 339 step.mV1 = c->v; 340 341 // If only one triangle has been deleted. 342 if (c->numDel == 1) 343 { 344 step.mT0 = c->deleted[0].id; 345 step.mT1 = c->deleted[0].id; 346 } 347 // If two triangles have been deleted. 348 else 349 { 350 step.mT0 = c->deleted[0].id; 351 step.mT1 = c->deleted[1].id; 352 } 353 354 step.x = 0.0; 355 step.y = 0.0; 356 step.z = 0.0; 357 358 // Write obligatory field. 359 step.obligatory = 0; 360 361 // List of new triangles. 362 // For each modified triangle. 363 for (int i = 0; i < c->numMod; i++) 364 { 365 step.mModfaces.push_back(c->modified[i].id); 366 } 367 368 // Add step to list of changes. 369 mVMISteps.push_back(step); 370 } 371 341 342 int stepnum= 1; 343 for(INTVECTOR::iterator it= inversemap[c->u].begin(); it!=inversemap[c->u].end(); it++) 344 { 345 vmiStep step; 346 step.mV0 = *it; 347 step.mV1 = c->v; 348 349 // If only one triangle has been deleted. 350 if (c->numDel == 1) 351 { 352 step.mT0 = c->deleted[0].id; 353 step.mT1 = c->deleted[0].id; 354 } 355 // If two triangles have been deleted. 356 else 357 { 358 step.mT0 = c->deleted[0].id; 359 step.mT1 = c->deleted[1].id; 360 } 361 362 step.x = 0.0; 363 step.y = 0.0; 364 step.z = 0.0; 365 366 // Write obligatory field. 367 if (stepnum==inversemap[c->u].size()) 368 step.obligatory = 0; 369 else 370 step.obligatory = 1; 371 stepnum++; 372 373 // List of new triangles. 374 // For each modified triangle. 375 for (int i = 0; i < c->numMod; i++) 376 { 377 step.mModfaces.push_back(c->modified[i].id); 378 } 379 380 // Add step to list of changes. 381 mVMISteps.push_back(step); 382 } 383 }
Note: See TracChangeset
for help on using the changeset viewer.