Changeset 2083 for GTP/trunk/Lib/Geom
- Timestamp:
- 02/05/07 13:26:30 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMesh.cpp
r1070 r2083 4 4 using namespace std; 5 5 6 //------------------------------------------------------------------------- --6 //------------------------------------------------------------------------- 7 7 // Cosntructor. 8 //------------------------------------------------------------------------- --8 //------------------------------------------------------------------------- 9 9 Mesh::Mesh(): 10 10 mVertexBuffer(0), mSubMeshCount(0), mSubMesh(0), hasSkeleton(false) … … 19 19 } 20 20 21 //------------------------------------------------------------------------- --21 //------------------------------------------------------------------------- 22 22 // Destroyer. 23 //------------------------------------------------------------------------- --23 //------------------------------------------------------------------------- 24 24 Mesh::~Mesh() 25 25 { … … 28 28 } 29 29 30 //------------------------------------------------------------------------- --30 //------------------------------------------------------------------------- 31 31 // Copy constructor. 32 //------------------------------------------------------------------------- --32 //------------------------------------------------------------------------- 33 33 Mesh::Mesh(const Mesh &mesh) 34 34 { … … 171 171 } 172 172 173 //------------------------------------------------------------------------- --173 //------------------------------------------------------------------------- 174 174 // Assignment operator. 175 //------------------------------------------------------------------------- --175 //------------------------------------------------------------------------- 176 176 Mesh &Mesh::operator =(const Mesh &mesh) 177 177 { … … 192 192 193 193 // For each submesh. 194 for (size_t i = 0; i < mesh.mSubMeshCount; i++)194 for (size_t i = 0; i < mesh.mSubMeshCount; i++) 195 195 { 196 196 mSubMesh[i].mSharedVertexBuffer = mesh.mSubMesh[i].mSharedVertexBuffer; //.false; … … 210 210 } 211 211 212 for(size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 212 for ( size_t s = 0; 213 s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 214 s++) 213 215 { 214 216 mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; … … 286 288 } 287 289 288 //------------------------------------------------------------------------- --290 //------------------------------------------------------------------------- 289 291 // Load mesh. 290 //------------------------------------------------------------------------- --292 //------------------------------------------------------------------------- 291 293 void Mesh::Load(Serializer &s) 292 294 { … … 326 328 } 327 329 328 //------------------------------------------------------------------------- --330 //------------------------------------------------------------------------- 329 331 // Save mesh. 330 //------------------------------------------------------------------------- --332 //------------------------------------------------------------------------- 331 333 void Mesh::Save(Serializer &s) 332 334 { … … 348 350 } 349 351 350 //------------------------------------------------------------------------- --352 //------------------------------------------------------------------------- 351 353 // Export to obj mesh. 352 //------------------------------------------------------------------------- --354 //------------------------------------------------------------------------- 353 355 void Mesh::exportToOBJ(char *fileName) 354 356 { 357 size_t vertex_count; 358 359 vertex_count = 0; 360 355 361 std::ofstream obj(fileName); 356 362 357 363 obj << "begin" << std::endl; 364 365 for (size_t j = 0; j < mVertexBuffer->mVertexCount; j++) 366 { 367 obj << "v " 368 << mVertexBuffer->mPosition[j].x 369 << " " 370 << mVertexBuffer->mPosition[j].y 371 << " " 372 << mVertexBuffer->mPosition[j].z 373 << " " 374 << std::endl; 375 } 358 376 359 377 // Vertices. 360 378 for (size_t i = 0; i < mSubMeshCount; i++) 361 379 { 362 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 363 { 364 obj << "v " 380 if (!mSubMesh[i].mSharedVertexBuffer) 381 { 382 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 383 { 384 obj << "v " 365 385 << mSubMesh[i].mVertexBuffer->mPosition[j].x 366 386 << " " … … 370 390 << " " 371 391 << std::endl; 392 } 393 } 394 } 395 396 // Normals. 397 for (size_t j = 0; j < mVertexBuffer->mVertexCount; j++) 398 { 399 obj << "vn " 400 << mVertexBuffer->mNormal[j].x 401 << " " 402 << mVertexBuffer->mNormal[j].y 403 << " " 404 << mVertexBuffer->mNormal[j].z 405 << " " 406 << std::endl; 407 } 408 409 for (size_t i = 0; i < mSubMeshCount; i++) 410 { 411 if (!mSubMesh[i].mSharedVertexBuffer) 412 { 413 for (size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 414 { 415 obj << "vn " 416 << mSubMesh[i].mVertexBuffer->mNormal[j].x 417 << " " 418 << mSubMesh[i].mVertexBuffer->mNormal[j].y 419 << " " 420 << mSubMesh[i].mVertexBuffer->mNormal[j].z 421 << " " 422 << std::endl; 423 } 372 424 } 373 425 } … … 378 430 for (size_t j = 0; j < mSubMesh[i].mIndexCount; j = j + 3) 379 431 { 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 } 432 int a = mSubMesh[i].mIndex[j] + 1 + vertex_count; 433 int b = mSubMesh[i].mIndex[j+1] + 1 + vertex_count; 434 int c = mSubMesh[i].mIndex[j+2] + 1 + vertex_count; 435 obj << "f " << a << "//" << a << " " 436 << b << "//" << b << " " 437 << c << "//" << c << " " 438 << std::endl; 439 440 } 441 vertex_count += mSubMesh[i].mVertexBuffer->mVertexCount; 388 442 } 389 443 390 444 obj << "end" << std::endl; 391 445 392 446 obj.close(); 393 447 } 394 448 395 //------------------------------------------------------------------------- --449 //------------------------------------------------------------------------- 396 450 // Transform to shared vertex mesh. 397 //------------------------------------------------------------------------- --451 //------------------------------------------------------------------------- 398 452 Mesh *Mesh::toSharedVertex() 399 453 { … … 536 590 } 537 591 538 /* 592 539 593 // Copy mesh bones. 540 594 if (!mBones.empty()) … … 545 599 } 546 600 } 547 */548 601 549 602 return mesh;
Note: See TracChangeset
for help on using the changeset viewer.