Changeset 2085 for GTP/trunk/Lib/Geom
- Timestamp:
- 02/05/07 13:26:58 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
r1560 r2085 1 /*======================================================================== ==1 /*======================================================================== 2 2 * (C) 2005 Universitat Jaume I 3 *======================================================================== ==3 *======================================================================== 4 4 * PROYECT: GAME TOOLS 5 *======================================================================== ==5 *======================================================================== 6 6 * CONTENT: 7 7 * 8 8 * 9 9 * @file GeoLodStripsLibrary.cpp 10 *======================================================================= ====*/10 *=======================================================================*/ 11 11 12 12 #include "GeoLodStripsLibrary.h" … … 15 15 using namespace std; 16 16 17 //------------------------------------------------------------------------- ----17 //------------------------------------------------------------------------- 18 18 // Constructor. 19 //----------------------------------------------------------------------------- 20 LodStripsLibrary::LodStripsLibrary( const LodStripsLibraryData *lodstripsdata, 21 Mesh *geomesh, 22 IndexData *userindexdata) 19 //------------------------------------------------------------------------- 20 LodStripsLibrary::LodStripsLibrary( 21 const LodStripsLibraryData *lodstripsdata, 22 Mesh *geomesh, 23 IndexData *userindexdata) 23 24 { 24 25 // Sets the current lod. … … 59 60 } 60 61 61 //------------------------------------------------------------------------- ----62 //------------------------------------------------------------------------- 62 63 // Destructor 63 //------------------------------------------------------------------------- ----64 //------------------------------------------------------------------------- 64 65 LodStripsLibrary::~LodStripsLibrary() 65 66 { … … 77 78 } 78 79 79 //------------------------------------------------------------------------- ----80 //------------------------------------------------------------------------- 80 81 // Public. 81 //------------------------------------------------------------------------- ----82 83 //------------------------------------------------------------------------- ----82 //------------------------------------------------------------------------- 83 84 //------------------------------------------------------------------------- 84 85 // Go to the level of detail. 85 //------------------------------------------------------------------------- ----86 //------------------------------------------------------------------------- 86 87 void LodStripsLibrary::GoToLod(float lodfactor) 87 88 { … … 303 304 } 304 305 305 //------------------------------------------------------------------------- ----306 //------------------------------------------------------------------------- 306 307 // Returns the number of vertices of the highest LOD. 307 //------------------------------------------------------------------------- ----308 //------------------------------------------------------------------------- 308 309 uint32 LodStripsLibrary::MaxVertices() 309 310 { … … 311 312 } 312 313 313 //------------------------------------------------------------------------- ----314 //------------------------------------------------------------------------- 314 315 // Returns the number of vertices of the lowest LOD. 315 //------------------------------------------------------------------------- ----316 //------------------------------------------------------------------------- 316 317 uint32 LodStripsLibrary::MinVertices() 317 318 { … … 324 325 } 325 326 326 //------------------------------------------------------------------------- ----327 //------------------------------------------------------------------------- 327 328 // Returns the number of triangles of the highest LOD. 328 //------------------------------------------------------------------------- ----329 //------------------------------------------------------------------------- 329 330 uint32 LodStripsLibrary::MaxFaces() 330 331 { … … 351 352 } 352 353 353 //------------------------------------------------------------------------- ----354 //------------------------------------------------------------------------- 354 355 // Returns the number of triangles of the lowest LOD. 355 //------------------------------------------------------------------------- ----356 //------------------------------------------------------------------------- 356 357 uint32 LodStripsLibrary::MinFaces() 357 358 { … … 377 378 } 378 379 379 //------------------------------------------------------------------------- ----380 //------------------------------------------------------------------------- 380 381 // Establishes the new LOD range. 381 382 // Only the LODs in that range are stored and used. 382 //------------------------------------------------------------------------- ----383 //------------------------------------------------------------------------- 383 384 void LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod) 384 385 { … … 390 391 } 391 392 /* 392 //------------------------------------------------------------------------- ----393 //------------------------------------------------------------------------- 393 394 // Get strip count. 394 //------------------------------------------------------------------------- ----395 //------------------------------------------------------------------------- 395 396 uint32 LodStripsLibrary::GetStripCount() const 396 397 { … … 398 399 } 399 400 400 //------------------------------------------------------------------------- ----401 //------------------------------------------------------------------------- 401 402 // Get Index by strip. 402 //------------------------------------------------------------------------- ----403 //------------------------------------------------------------------------- 403 404 uint32 LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const 404 405 { … … 406 407 } 407 408 */ 408 //------------------------------------------------------------------------- ----409 //------------------------------------------------------------------------- 409 410 // Private. 410 //------------------------------------------------------------------------- ----411 412 //------------------------------------------------------------------------- ----411 //------------------------------------------------------------------------- 412 413 //------------------------------------------------------------------------- 413 414 // Copy a STL vector to a C array. 414 //------------------------------------------------------------------------- ----415 //------------------------------------------------------------------------- 415 416 void LodStripsLibrary::CopyVectors2Arrays(void) 416 417 { … … 452 453 mCurrentRegLOD = changes_array; 453 454 454 455 // Copy strips. 455 456 // unsigned int numDegenerated = 2*mTotalStrips - 2; 456 457 // dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal! … … 493 494 } 494 495 495 //------------------------------------------------------------------------- ----496 //------------------------------------------------------------------------- 496 497 // LoadStripMesh 497 //----------------------------------------------------------------------------- 498 void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh) 499 { 500 //FILE *fp; 498 //------------------------------------------------------------------------- 499 void LodStripsLibrary::LoadStripMesh( 500 const LodStripsLibraryData *lodstripsdata, 501 Mesh *geomesh) 502 { 501 503 SmallIntVector strip_aux; 502 //LODRegisterType lod_register;503 504 std::vector <LODRegisterType> list_pos; 504 505 std::vector <unsigned int> p_changes; 505 //int value;506 506 int v = 0; 507 507 int t = -1; … … 509 509 int next = 0; 510 510 int c = -1; 511 //char buff[80];512 511 Index *index; 513 512 Index *indexBegin; … … 520 519 521 520 int totaltiras = 0; 522 for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 523 for (unsigned int strip = 0; strip < geomesh->mSubMesh[submesh].mStripCount; strip++) 521 522 for ( unsigned int submesh = 0; 523 submesh < geomesh->mSubMeshCount; 524 submesh++) 525 { 526 for ( unsigned int strip = 0; 527 strip < geomesh->mSubMesh[submesh].mStripCount; 528 strip++) 529 { 524 530 totaltiras++; 531 } 532 } 525 533 526 534 submesh_x_strip = new int[totaltiras]; 527 535 528 536 int istrip = 0; 529 for (unsigned int submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 537 538 for ( size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 530 539 { 531 540 geoSubMesh = &geomesh->mSubMesh[submesh]; … … 533 542 534 543 // For each one of the strips. 535 for (unsigned int strip = 0; strip < geoSubMesh->mStripCount; strip++, istrip++) 544 for ( unsigned int strip = 0; 545 strip < geoSubMesh->mStripCount; 546 strip++, istrip++) 536 547 { 537 548 // Insert an empty strip. … … 546 557 // If the strips is not the first. (DEG!) 547 558 if (strip != 0) 559 { 548 560 indexBegin++; 561 } 549 562 550 563 // If is the final strip … … 567 580 568 581 if (submesh==0) 582 { 569 583 offsets_x_submesh[submesh] = 0; 584 } 570 585 else 586 { 571 587 offsets_x_submesh[submesh] = indices_x_submesh[submesh-1]; 588 } 572 589 573 590 // For each index of the strip. … … 577 594 indices_x_submesh[submesh]++; 578 595 i++; 579 } 580 } 581 } 582 583 // TODO: LOD file loaded in load file mesh process. 584 // Open the LOD file. 585 /* if ((fp = fopen (name, "r")) == NULL) 586 { 587 // Error in open. 588 } 589 else 590 { 591 mTotalChanges = 0; 592 593 while (!feof (fp)) 594 { 595 fgets (buff, 80, fp); 596 597 if (*buff == 'v') 598 { 599 sscanf (buff+2,"%d",&value); 600 601 mFileVertices.push_back(value); 602 v++; 603 } 604 else if ( (*buff == 'c') || (*buff == 'd')) 605 { 606 if (*buff == 'c') 607 { 608 c++; 609 } 610 else 611 { 612 unsigned int a; 613 unsigned int b; 614 unsigned int c; 615 unsigned int d; 616 617 sscanf (buff+2,"%u %u %u %u\n",&a,&b,&c,&d); 618 lod_register.strip = a; 619 lod_register.position = b; 620 lod_register.vertexRepetition = c; 621 lod_register.edgeRepetition = d; 622 623 mFileChangesLOD.push_back(lod_register); 624 } 625 } 626 else if (*buff=='b') 627 { 628 sscanf(buff+2,"%u",&value); 629 mData.push_back(value); 630 } 631 else if (*buff=='p') 632 { 633 sscanf (buff+2,"%u",&value); 634 p_changes.push_back(value); 635 } 636 } 637 638 fclose(fp);*/ 639 640 mFileVertices = lodstripsdata->mFileVertices; 641 mFileChangesLOD = lodstripsdata->mFileChangesLOD; 642 mData = lodstripsdata->mData; 643 p_changes = lodstripsdata->p_changes; 644 645 mStripsSubmesh = new int [geomesh->mSubMeshCount]; 596 } 597 } 598 } 599 600 mFileVertices = lodstripsdata->mFileVertices; 601 mFileChangesLOD = lodstripsdata->mFileChangesLOD; 602 mData = lodstripsdata->mData; 603 p_changes = lodstripsdata->p_changes; 604 605 mStripsSubmesh = new int [geomesh->mSubMeshCount]; 606 646 607 for (size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 647 { 648 mStripsSubmesh[submesh]=0; 649 } 650 651 608 { 609 mStripsSubmesh[submesh] = 0; 610 } 611 652 612 // Max / Min values for LOD. 653 613 mLods = int(p_changes.size()); … … 658 618 659 619 for (unsigned int i = 0; i < mLods; i++) 620 { 660 621 mPChanges[i] = p_changes[i]; 622 } 661 623 662 624 mTotalVertices = int(mFileVertices.size()); … … 674 636 size_t strip_count = 0; 675 637 unsigned int ii_submesh = 0; 638 uint32 numdeg = 0; 676 639 677 640 current_triangle_count = 0; … … 679 642 // indices_x_submesh is calculated without degenerates, 680 643 // we must add the degenerate indices added here 681 uint32 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2; 644 if (mGeoMesh->mSubMesh[target_submesh].mStripCount > 0) 645 { 646 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount * 2 - 2; 647 } 682 648 683 649 dataRetrievalInterface->Begin(target_submesh, … … 697 663 else 698 664 { 699 offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1] 700 + 701 offsets_x_submesh[target_submesh-1]; 665 offsets_x_submesh[target_submesh] = 666 indices_x_submesh[target_submesh-1] 667 + 668 offsets_x_submesh[target_submesh-1]; 702 669 } 703 670 … … 709 676 dataRetrievalInterface->End(); 710 677 711 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2; 678 if (mGeoMesh->mSubMesh[target_submesh].mStripCount > 0) 679 { 680 numdeg = mGeoMesh->mSubMesh[target_submesh].mStripCount*2 - 2; 681 } 712 682 713 683 dataRetrievalInterface->Begin(target_submesh, 714 indices_x_submesh[target_submesh] + numdeg); 684 indices_x_submesh[target_submesh] 685 + 686 numdeg); 715 687 716 current_triangle_count += indices_x_submesh[target_submesh] + numdeg; 688 current_triangle_count += indices_x_submesh[target_submesh] 689 + 690 numdeg; 717 691 } 718 692 … … 729 703 lastindex = *it; 730 704 731 dataRetrievalInterface->SetIndex(ii_submesh,*it); 705 dataRetrievalInterface->SetIndex(ii_submesh,*it); 732 706 ii_submesh++; 733 707 } … … 754 728 else 755 729 { 756 offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1] 757 + 758 offsets_x_submesh[target_submesh-1]; 730 offsets_x_submesh[target_submesh] = 731 indices_x_submesh[target_submesh - 1] 732 + 733 offsets_x_submesh[target_submesh - 1]; 759 734 } 760 735
Note: See TracChangeset
for help on using the changeset viewer.