Changeset 2085


Ignore:
Timestamp:
02/05/07 13:26:58 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp

    r1560 r2085  
    1 /*========================================================================== 
     1/*======================================================================== 
    22 *      (C) 2005 Universitat Jaume I 
    3  *========================================================================== 
     3 *======================================================================== 
    44 *      PROYECT:        GAME TOOLS 
    5  *========================================================================== 
     5 *======================================================================== 
    66 *      CONTENT: 
    77 * 
    88 * 
    99 *      @file   GeoLodStripsLibrary.cpp 
    10  *===========================================================================*/ 
     10 *=======================================================================*/ 
    1111 
    1212#include "GeoLodStripsLibrary.h" 
     
    1515using   namespace       std; 
    1616 
    17 //----------------------------------------------------------------------------- 
     17//------------------------------------------------------------------------- 
    1818//      Constructor. 
    19 //----------------------------------------------------------------------------- 
    20 LodStripsLibrary::LodStripsLibrary(     const LodStripsLibraryData      *lodstripsdata, 
    21                                                                                                                                                 Mesh                                                                                            *geomesh, 
    22                                                                                                                                                 IndexData                                                                               *userindexdata) 
     19//------------------------------------------------------------------------- 
     20LodStripsLibrary::LodStripsLibrary( 
     21                                                                                                                const LodStripsLibraryData      *lodstripsdata, 
     22                                                                                                                Mesh                                                                                            *geomesh, 
     23                                                                                                                IndexData                                                                               *userindexdata) 
    2324{ 
    2425        //      Sets the current lod. 
     
    5960} 
    6061 
    61 //----------------------------------------------------------------------------- 
     62//------------------------------------------------------------------------- 
    6263//      Destructor 
    63 //----------------------------------------------------------------------------- 
     64//------------------------------------------------------------------------- 
    6465LodStripsLibrary::~LodStripsLibrary() 
    6566{ 
     
    7778} 
    7879 
    79 //----------------------------------------------------------------------------- 
     80//------------------------------------------------------------------------- 
    8081//      Public. 
    81 //----------------------------------------------------------------------------- 
    82  
    83 //----------------------------------------------------------------------------- 
     82//------------------------------------------------------------------------- 
     83 
     84//------------------------------------------------------------------------- 
    8485//      Go to the level of detail. 
    85 //----------------------------------------------------------------------------- 
     86//------------------------------------------------------------------------- 
    8687void LodStripsLibrary::GoToLod(float lodfactor) 
    8788{ 
     
    303304} 
    304305 
    305 //----------------------------------------------------------------------------- 
     306//------------------------------------------------------------------------- 
    306307//      Returns the number of vertices of the highest LOD. 
    307 //----------------------------------------------------------------------------- 
     308//------------------------------------------------------------------------- 
    308309uint32  LodStripsLibrary::MaxVertices() 
    309310{ 
     
    311312} 
    312313 
    313 //----------------------------------------------------------------------------- 
     314//------------------------------------------------------------------------- 
    314315//      Returns the number of vertices of the lowest LOD. 
    315 //----------------------------------------------------------------------------- 
     316//------------------------------------------------------------------------- 
    316317uint32  LodStripsLibrary::MinVertices() 
    317318{ 
     
    324325} 
    325326 
    326 //----------------------------------------------------------------------------- 
     327//------------------------------------------------------------------------- 
    327328//      Returns the number of triangles of the highest LOD. 
    328 //----------------------------------------------------------------------------- 
     329//------------------------------------------------------------------------- 
    329330uint32  LodStripsLibrary::MaxFaces() 
    330331{ 
     
    351352} 
    352353 
    353 //----------------------------------------------------------------------------- 
     354//------------------------------------------------------------------------- 
    354355//      Returns the number of triangles of the lowest LOD. 
    355 //----------------------------------------------------------------------------- 
     356//------------------------------------------------------------------------- 
    356357uint32  LodStripsLibrary::MinFaces() 
    357358{ 
     
    377378} 
    378379 
    379 //----------------------------------------------------------------------------- 
     380//------------------------------------------------------------------------- 
    380381//      Establishes the new LOD range. 
    381382//      Only the LODs in that range are stored and used. 
    382 //----------------------------------------------------------------------------- 
     383//------------------------------------------------------------------------- 
    383384void            LodStripsLibrary::TrimByLod(uint32 minLod, uint32 maxLod) 
    384385{ 
     
    390391} 
    391392/* 
    392 //----------------------------------------------------------------------------- 
     393//------------------------------------------------------------------------- 
    393394//      Get strip count. 
    394 //----------------------------------------------------------------------------- 
     395//------------------------------------------------------------------------- 
    395396uint32  LodStripsLibrary::GetStripCount() const 
    396397{ 
     
    398399} 
    399400 
    400 //----------------------------------------------------------------------------- 
     401//------------------------------------------------------------------------- 
    401402//      Get Index by strip. 
    402 //----------------------------------------------------------------------------- 
     403//------------------------------------------------------------------------- 
    403404uint32  LodStripsLibrary::GetIndexCountByStrip(uint32 istrip) const 
    404405{ 
     
    406407} 
    407408*/ 
    408 //----------------------------------------------------------------------------- 
     409//------------------------------------------------------------------------- 
    409410//      Private. 
    410 //----------------------------------------------------------------------------- 
    411  
    412 //----------------------------------------------------------------------------- 
     411//------------------------------------------------------------------------- 
     412 
     413//------------------------------------------------------------------------- 
    413414//      Copy a STL vector to a C array. 
    414 //----------------------------------------------------------------------------- 
     415//------------------------------------------------------------------------- 
    415416void LodStripsLibrary::CopyVectors2Arrays(void) 
    416417{ 
     
    452453        mCurrentRegLOD  =       changes_array; 
    453454         
    454         //      Copy strips. 
     455//      Copy strips. 
    455456//      unsigned int numDegenerated = 2*mTotalStrips - 2; 
    456457//      dataRetrievalInterface=create_index_data_func(total_strip_size,indexdata_user_data); // temporal! 
     
    493494} 
    494495 
    495 //----------------------------------------------------------------------------- 
     496//------------------------------------------------------------------------- 
    496497//      LoadStripMesh 
    497 //----------------------------------------------------------------------------- 
    498 void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh) 
    499 { 
    500         //FILE                                                                                                                  *fp; 
     498//------------------------------------------------------------------------- 
     499void LodStripsLibrary::LoadStripMesh( 
     500                                                                                                                const LodStripsLibraryData *lodstripsdata, 
     501                                                                                                                Mesh *geomesh) 
     502{ 
    501503        SmallIntVector                                                                          strip_aux; 
    502         //LODRegisterType                                                                               lod_register; 
    503504        std::vector                     <LODRegisterType>       list_pos; 
    504505        std::vector                     <unsigned int>          p_changes; 
    505         //int                                                                                                                           value; 
    506506        int                                                                                                                             v                       =       0; 
    507507        int                                                                                                                             t                       =       -1; 
     
    509509        int                                                                                                                             next    =       0; 
    510510        int                                                                                                                             c                       =       -1; 
    511         //char                                                                                                                  buff[80]; 
    512511        Index                                                                                                                   *index; 
    513512        Index                                                                                                                   *indexBegin; 
     
    520519 
    521520        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                { 
    524530                        totaltiras++; 
     531                } 
     532        } 
    525533 
    526534        submesh_x_strip = new int[totaltiras]; 
    527535 
    528536        int istrip = 0; 
    529         for (unsigned int submesh       =       0; submesh < geomesh->mSubMeshCount; submesh++) 
     537         
     538        for (   size_t  submesh =       0;      submesh < geomesh->mSubMeshCount;       submesh++) 
    530539        { 
    531540                geoSubMesh      =       &geomesh->mSubMesh[submesh]; 
     
    533542 
    534543                //      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++) 
    536547                { 
    537548                        // Insert an empty strip. 
     
    546557                        //      If the strips is not the first. (DEG!) 
    547558                        if (strip != 0) 
     559                        { 
    548560                                indexBegin++; 
     561                        } 
    549562 
    550563                        //      If is the final strip 
     
    567580                         
    568581                        if (submesh==0) 
     582                        { 
    569583                                offsets_x_submesh[submesh] = 0; 
     584                        } 
    570585                        else 
     586                        { 
    571587                                offsets_x_submesh[submesh] = indices_x_submesh[submesh-1]; 
     588                        } 
    572589 
    573590                        //      For each index of the strip. 
     
    577594                                indices_x_submesh[submesh]++; 
    578595                                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 
    646607        for (size_t     submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 
    647         {        
    648                 mStripsSubmesh[submesh]=0; 
    649         } 
    650  
    651                          
     608        { 
     609                mStripsSubmesh[submesh] =       0; 
     610        } 
     611 
    652612        //      Max / Min values for LOD. 
    653613        mLods                                                                                   =       int(p_changes.size()); 
     
    658618         
    659619        for (unsigned int i = 0; i < mLods; i++) 
     620        { 
    660621                mPChanges[i] = p_changes[i]; 
     622        } 
    661623 
    662624        mTotalVertices          =       int(mFileVertices.size()); 
     
    674636        size_t                          strip_count                     =       0; 
    675637        unsigned int    ii_submesh                      =       0; 
     638        uint32                          numdeg                                  =       0; 
    676639 
    677640        current_triangle_count = 0; 
     
    679642        // indices_x_submesh is calculated without degenerates,  
    680643        // 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        } 
    682648 
    683649        dataRetrievalInterface->Begin(target_submesh, 
     
    697663                        else 
    698664                        { 
    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]; 
    702669                        } 
    703670 
     
    709676                        dataRetrievalInterface->End(); 
    710677 
    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                        } 
    712682 
    713683                        dataRetrievalInterface->Begin(target_submesh, 
    714                                                                                                                                                 indices_x_submesh[target_submesh] + numdeg); 
     684                                                                                                                                                indices_x_submesh[target_submesh] 
     685                                                                                                                                                + 
     686                                                                                                                                                numdeg); 
    715687                         
    716                         current_triangle_count  +=      indices_x_submesh[target_submesh] + numdeg; 
     688                        current_triangle_count  +=      indices_x_submesh[target_submesh] 
     689                                                                                                                                        + 
     690                                                                                                                                        numdeg; 
    717691                } 
    718692 
     
    729703                                lastindex       =       *it; 
    730704 
    731                                 dataRetrievalInterface->SetIndex(ii_submesh,*it);                                
     705                                dataRetrievalInterface->SetIndex(ii_submesh,*it); 
    732706                                ii_submesh++; 
    733707                        } 
     
    754728                else 
    755729                { 
    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]; 
    759734                } 
    760735 
Note: See TracChangeset for help on using the changeset viewer.