- Timestamp:
- 03/30/07 11:38:28 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSimplifier.cpp
r2291 r2300 42 42 43 43 //------------------------------------------------------------------------- 44 // Erase submeshes that have not indices. 45 //------------------------------------------------------------------------- 46 void MeshSimplifier::eraseVoidSubMeshes(Mesh *geoMesh) 47 { 48 SubMesh *geosubmesh; 49 size_t valid_submesh_count; 50 size_t submesh; 51 52 valid_submesh_count = 0; 53 54 // For each submesh. 55 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 56 { 57 // Debug. 58 cout << "Indices of submesh " 59 << i 60 << ": " 61 << geoMesh->mSubMesh[i].mIndexCount 62 << endl; 63 64 if ((geoMesh->mSubMesh[i].mIndexCount > 0) 65 || 66 (indexMeshLeaves == i)) 67 { 68 valid_submesh_count++; 69 } 70 } 71 72 // Reassign submesh count. 73 geoMesh->mSubMeshCount = valid_submesh_count; 74 75 // Reserve memory for valid submeshes. 76 geosubmesh = new SubMesh[valid_submesh_count]; 77 78 submesh = 0; 79 80 // For each submesh. 81 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 82 { 83 // If leaves submesh is found. 84 if (indexMeshLeaves == i) 85 { 86 geosubmesh[i].mStripCount = 0; 87 geosubmesh[i].mStrip = NULL; 88 89 geosubmesh[i].mSharedVertexBuffer = false; 90 91 strcpy( geosubmesh[i].mMaterialName, 92 mInitialMesh->mSubMesh[i].mMaterialName); 93 94 // Copy submesh bones. 95 if (!mInitialMesh->mSubMesh[i].mBones.empty()) 96 { 97 for ( size_t j = 0; 98 j < mInitialMesh->mSubMesh[i].mBones.size(); 99 j++) 100 { 101 geosubmesh[i].mBones.push_back(mInitialMesh-> 102 mSubMesh[i].mBones[j]); 103 } 104 } 105 106 // Leaves mesh. 107 geosubmesh[i].mIndexCount = 108 mInitialMesh->mSubMesh[i].mIndexCount; 109 110 geosubmesh[i].mIndex = 111 new Geometry::Index[geosubmesh[i].mIndexCount]; 112 113 memcpy( geosubmesh[i].mIndex, 114 mInitialMesh->mSubMesh[i].mIndex, 115 mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 116 117 // Copy the leaves submesh vertices. 118 geosubmesh[i].mVertexBuffer = 119 mInitialMesh->mSubMesh[i].mVertexBuffer->Clone(); 120 121 // Next valid submesh. 122 submesh++; 123 } 124 else if (geoMesh->mSubMesh[i].mIndexCount > 0) 125 { 126 geosubmesh[submesh].mSharedVertexBuffer = 127 geoMesh->mSubMesh[i].mSharedVertexBuffer; 128 129 geosubmesh[submesh].mVertexBuffer = geoMesh->mVertexBuffer; 130 131 geosubmesh[submesh].mType = geoMesh->mSubMesh[i].mType; 132 133 geosubmesh[submesh].mStripCount = geoMesh->mSubMesh[i].mStripCount; 134 135 geosubmesh[submesh].mIndexCount = geoMesh->mSubMesh[i].mIndexCount; 136 137 // Reserve memory for indices. 138 geosubmesh[submesh].mIndex = 139 new Index[geosubmesh[submesh].mIndexCount]; 140 141 // Copy indices. 142 memcpy( geosubmesh[submesh].mIndex, 143 geoMesh->mSubMesh[i].mIndex, 144 geoMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 145 146 // Reserve memory for array of strips. 147 geosubmesh[submesh].mStrip = 148 new Index*[geoMesh->mSubMesh[submesh].mStripCount]; 149 150 // Copy strip list of the submesh. 151 for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++) 152 { 153 geosubmesh[submesh].mStrip[j] = geoMesh->mSubMesh[i].mStrip[j]; 154 } 155 156 strcpy( geosubmesh[submesh].mMaterialName, 157 geoMesh->mSubMesh[i].mMaterialName); 158 159 for (size_t j = 0; j < geoMesh->mSubMesh[i].mBones.size(); j++) 160 { 161 geosubmesh[submesh].mBones 162 .push_back(geoMesh->mSubMesh[i].mBones[j]); 163 } 164 165 // Next valid submesh. 166 submesh++; 167 } 168 } 169 170 // Delete submeshes. 171 delete []geoMesh->mSubMesh; 172 173 geoMesh->mSubMesh = geosubmesh; 174 } 175 176 //------------------------------------------------------------------------- 44 177 // Returns the simplified mesh. 45 178 //------------------------------------------------------------------------- 46 179 Mesh * MeshSimplifier::GetMesh() 47 180 { 181 // Delete void submeshes. 182 eraseVoidSubMeshes(mGeoMesh); 183 48 184 return mGeoMesh; 49 185 } … … 146 282 // method to perform an image based simplification. 147 283 //------------------------------------------------------------------------- 148 voidGeometryBasedSimplifier::Simplify(Real paramlod)284 int GeometryBasedSimplifier::Simplify(Real paramlod) 149 285 { 150 286 SimplificationMethod *m_qslim = new SimplificationMethod(mInitialMesh); … … 157 293 158 294 delete m_qslim; 295 296 return NO_GL_ERROR; 159 297 } 160 298 … … 165 303 // perform an image based simplification. 166 304 //------------------------------------------------------------------------- 167 voidGeometryBasedSimplifier::Simplify(uint32 numvertices)305 int GeometryBasedSimplifier::Simplify(uint32 numvertices) 168 306 { 169 307 SimplificationMethod *m_qslim = new SimplificationMethod(mInitialMesh); … … 176 314 177 315 delete m_qslim; 316 317 return NO_GL_ERROR; 178 318 } 179 319 … … 235 375 // Loads the vmi mesh structure for a geometry mesh given. 236 376 VMI::mesh = initMeshStructure(mGeoMesh); 377 } 378 379 // Init VMI options. 380 int ViewPointDrivenSimplifier::init(void) 381 { 382 int error; 237 383 238 384 // RGB and Alpha. … … 245 391 glewInit(); 246 392 247 VMI::init();393 error = VMI::init(); 248 394 249 395 if (VMI::bLoadCamerasFromFile == GL_FALSE) … … 256 402 257 403 VMI::initialIs = VMI::initIs(VMI::numCameras); 404 405 return error; 258 406 } 259 407 … … 273 421 /// LOD factor in a range of [0,1]. Implements the 274 422 /// Simplifier::Simplify method to perform an image based simplification. 275 void ViewPointDrivenSimplifier::Simplify(Real percent) 276 { 423 int ViewPointDrivenSimplifier::Simplify(Real percent) 424 { 425 int error; 426 427 error = init(); 428 277 429 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * percent); 278 430 … … 284 436 } 285 437 286 VMI::display(); 287 288 // Cleans firts simplification. 289 VMI::freeMemory(); 290 291 VMI::mesh = initMeshStructure(mInitialMesh); 292 293 VMI::contractInitialMesh(VMI::mesh); 294 295 // Load a geometry mesh for vmi mesh. 296 loadMesh(); 297 298 GetMeshSimpSequence(); 299 300 // Sort bones. 301 bonesReassignament(); 438 if (error == NO_GL_ERROR) 439 { 440 VMI::display(); 441 442 // Cleans firts simplification. 443 VMI::freeMemory(); 444 445 VMI::mesh = initMeshStructure(mInitialMesh); 446 447 VMI::contractInitialMesh(VMI::mesh); 448 449 // Load a geometry mesh for vmi mesh. 450 loadMesh(); 451 452 GetMeshSimpSequence(); 453 454 // Sort bones. 455 bonesReassignament(); 456 } 457 458 return error; 302 459 } 303 460 … … 308 465 /// an image based simplification. 309 466 //------------------------------------------------------------------------- 310 voidViewPointDrivenSimplifier::Simplify(uint32 numVertices)467 int ViewPointDrivenSimplifier::Simplify(uint32 numVertices) 311 468 { 312 469 float percent; 470 int error; 471 472 error = init(); 313 473 314 474 percent = (numVertices * 100.0) / VMI::mesh->numVertices; 315 475 316 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles * (percent / 100)); 476 VMI::numDemandedTriangles = (int)(VMI::mesh->numTriangles 477 * 478 (percent / 100)); 317 479 318 480 if ((VMI::numDemandedTriangles == 0) … … 323 485 } 324 486 325 VMI::display(); 326 327 // Cleans firts simplification. 328 VMI::freeMemory(); 329 330 VMI::mesh = initMeshStructure(mInitialMesh); 331 332 VMI::contractInitialMesh(VMI::mesh); 333 334 // Load a geometry mesh for vmi mesh. 335 loadMesh(); 336 337 GetMeshSimpSequence(); 338 339 // Sort bones. 340 bonesReassignament(); 487 if (error == NO_GL_ERROR) 488 { 489 VMI::display(); 490 491 // Cleans firts simplification. 492 VMI::freeMemory(); 493 494 VMI::mesh = initMeshStructure(mInitialMesh); 495 496 VMI::contractInitialMesh(VMI::mesh); 497 498 // Load a geometry mesh for vmi mesh. 499 loadMesh(); 500 501 GetMeshSimpSequence(); 502 503 // Sort bones. 504 bonesReassignament(); 505 } 506 507 return error; 341 508 } 342 509
Note: See TracChangeset
for help on using the changeset viewer.