Ignore:
Timestamp:
07/05/06 17:15:14 (18 years ago)
Author:
gumbau
Message:

Extended Mesh implementation

Location:
GTP/trunk/Lib/Geom/shared/GeoTool/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp

    r1071 r1078  
    642642//      Read a mesh file. 
    643643//--------------------------------------------------------------------------- 
     644 
     645#include "GeoLodStripsLibrary.h" 
     646#include "GeoLodStripsConstructor.h" 
     647 
    644648void GeoMeshLoader::readMesh(FILE       *f, Mesh        *geoMesh, int option) 
    645649{ 
     
    670674                                 chunkID == M_MESH_BOUNDS || 
    671675                                 chunkID == M_SUBMESH_NAME_TABLE || 
    672                                  chunkID == M_EDGE_LISTS)) 
     676                                 chunkID == M_EDGE_LISTS || 
     677                                 chunkID == 0xabcd ||  
     678                                 chunkID == 0xdcba)) 
    673679                { 
    674680                        switch(chunkID) 
    675681                        { 
     682                                case 0xabcd: 
     683                                        cout << "LODSTRIPS_Chunk" << endl; 
     684                                        int                             aux,v,c; 
     685                                        LODRegisterType lod_register; 
     686                                        LODData                 dataaux; 
     687                                        int                             tam; 
     688 
     689                                        fread(&tam, sizeof(int), 1, f); 
     690                                        lodstripsdata.mFileVertices.clear(); 
     691                                        for (v=0; v<tam; v++) 
     692                                        { 
     693                                                fread(&aux, sizeof(int), 1, f); 
     694                                                lodstripsdata.mFileVertices.push_back(aux); 
     695                                        } 
     696 
     697                                        lodstripsdata.mFileChangesLOD.clear(); 
     698                                        fread(&tam, sizeof(int), 1, f); 
     699                                        for (c=0; c<tam; c++) 
     700                                        { 
     701                                                fread(&dataaux, sizeof(LODData), 1, f); 
     702                                                lod_register.strip= dataaux.strip; 
     703                                                lod_register.position= dataaux.nP; 
     704                                                lod_register.vertexRepetition= dataaux.nL1; 
     705                                                lod_register.edgeRepetition= dataaux.nL2; 
     706                                                //lod_register.obligatory=false; 
     707                                                //lod_register.obligatory= dataaux.obligatory; 
     708 
     709                                                lodstripsdata.mFileChangesLOD.push_back(lod_register); 
     710                                        } 
     711                                         
     712                                        lodstripsdata.mData.clear(); 
     713                                        fread(&tam, sizeof(int), 1, f); 
     714                                        for (int b=0; b<tam; b++) 
     715                                        { 
     716                                                fread(&aux, sizeof(int), 1, f); 
     717                                                lodstripsdata.mData.push_back(aux); 
     718                                        } 
     719 
     720                                        lodstripsdata.p_changes.clear(); 
     721                                        fread(&tam, sizeof(int), 1, f); 
     722                                        for (int p=0; p<tam; p++) 
     723                                        { 
     724                                                fread(&aux, sizeof(int), 1, f); 
     725                                                lodstripsdata.p_changes.push_back(aux); 
     726                                        }                                        
     727 
     728                                        break; 
     729 
     730                                case 0xdcba: 
     731                                        cout << "LODTREES_Chunk" << endl; 
     732                                        int size; 
     733                                        fread(&size, sizeof(int), 1, f); 
     734                                        treesimpseq.mSteps.clear(); 
     735                                        for (int i=0; i<size; i++) 
     736                                        { 
     737                                                Geometry::TreeSimplificationSequence::Step auxstep; 
     738                                                fread(&auxstep.mV0,sizeof(int),1,f); 
     739                                                fread(&auxstep.mV1,sizeof(int),1,f); 
     740                                                fread(&auxstep.mT0,sizeof(int),1,f); 
     741                                                fread(&auxstep.mT1,sizeof(int),1,f); 
     742                                                fread(auxstep.mNewQuad,sizeof(int),4,f); 
     743                                                treesimpseq.mSteps.push_back(auxstep); 
     744                                        } 
     745 
     746                                        break; 
     747 
     748 
    676749                                case M_GEOMETRY: 
    677750 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r1070 r1078  
    892892        current_strip = 0; 
    893893 
     894        int begin_index = 0; 
     895 
    894896        //      For each submesh. 
    895897        for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     
    966968                }*/ 
    967969 
     970                int indices_to_render = lodStripsLib->indices_x_submesh[submesh]; 
     971 
     972 
    968973                glBegin(GL_TRIANGLE_STRIP); 
    969                 for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++) 
     974                //for (int index = 0; index < lodStripsLib->dataRetrievalInterface->GetNumValidIndices(); index ++) 
     975                for (int index = begin_index; index < indices_to_render+begin_index; index ++) 
    970976                { 
    971977                        position = lodStripsLib->dataRetrievalInterface->GetIndex(index); 
     
    10011007                } 
    10021008                glEnd(); 
     1009                begin_index += indices_to_render; 
    10031010 
    10041011        } 
     
    10261033        // DRAW THE TRUNK AS A LODSTRIP OBJECT 
    10271034 
     1035        int begin_index = 0; 
     1036 
    10281037        //      For each submesh. 
    10291038        for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     
    11021111 
    11031112                }*/ 
     1113         
     1114                int indices_to_render = lodTreeLib->trunk->indices_x_submesh[submesh]; 
     1115                         
    11041116                glBegin(GL_TRIANGLE_STRIP); 
    1105                 for (int index = 0; index < lodTreeLib->CurrentLOD_Trunk_Indices()->GetNumValidIndices(); index ++) 
     1117                for (int index = begin_index; index < lodTreeLib->trunk->indices_x_submesh[submesh]; index ++) 
    11061118                { 
    11071119                        position = lodTreeLib->CurrentLOD_Trunk_Indices()->GetIndex(index); 
     
    11371149                } 
    11381150                glEnd(); 
     1151                begin_index += indices_to_render; 
    11391152 
    11401153        } 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r1070 r1078  
    811811        if (mGeoMesh != NULL) 
    812812        { 
    813                 fcho    =       new fltk::FileChooser("", 
     813/*              fcho    =       new fltk::FileChooser("", 
    814814                                "*.lod", 
    815815                                fltk::FileChooser::CREATE, 
     
    820820                //      If a file was selected. 
    821821                if (fcho->value()) 
    822                 { 
     822                {*/ 
    823823                        //      Build lod strips library. 
    824                         setLodStripsLibrary(string(fcho->value()), mGeoMesh); 
     824                        setLodStripsLibrary(geoMeshLoader->lodstripsdata, mGeoMesh); 
    825825 
    826826                        //      Sets the aplication mode. 
    827827                        mApplicationState       =       VISUALIZE_LODSTRIPS; 
    828                 } 
     828        /*      } 
    829829 
    830830                //      Free memory. 
    831                 delete  fcho; 
     831                delete  fcho;*/ 
    832832 
    833833                //      Hide the right panel. 
     
    883883 
    884884                //      If an object is loaded. 
    885                 if (mGeoMesh != NULL) 
     885/*              if (mGeoMesh != NULL) 
    886886                { 
    887887                        fcho    =       new fltk::FileChooser("", 
    888                                         "*.lod", 
     888                                        "*.mesh", 
    889889                                        fltk::FileChooser::CREATE, 
    890890                                        "Open Lod file"); 
     
    908908                                if (fcho->value()) 
    909909                                { 
    910                                         std::string leafseqFile(fcho->value()); 
    911  
    912                                         setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID); 
     910                                        std::string leafseqFile(fcho->value());*/ 
     911 
     912                                        //setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID); 
     913                                        setLodTreesLibrary(geoMeshLoader->lodstripsdata, geoMeshLoader->treesimpseq, mGeoMesh, leafsSubMeshID); 
    913914 
    914915                                        //      Sets the aplication mode. 
    915916                                        mApplicationState       =       VISUALIZE_LODTREES; 
    916                                 } 
     917/*                              } 
    917918                        } 
    918919 
    919920                        //      Free memory. 
    920921                        delete  fcho; 
    921  
     922*/ 
    922923                        //      Hide the right panel. 
    923924                        hideRightPanel(); 
     
    932933                        //      Repaint the window. 
    933934                        mMainWindow->redraw(); 
    934                 } 
     935/*              }*/ 
    935936        } 
    936937} 
     
    12431244        { 
    12441245                //      Choose between aplication state. 
    1245                 switch(mApplicationState) 
     1246                if (mApplicationState==LODSTRIPS_AUTO || mApplicationState==LODTREES_AUTO) 
    12461247                { 
    1247                         //      Build the LOD file. 
    1248                         case    LODTREES_AUTO: 
    1249  
    1250                                 //      Open file chooser dialog. 
    1251                                 file_name       =       fltk::file_chooser("Build LOD","*",""); 
    1252                                  
    1253                                 if (!file_name) 
    1254                                 { 
    1255                                         break; 
    1256                                 } 
    1257  
    1258                                 std::cout << "Creando secuencia de simplificacion de hojas..."; 
    1259                                  
    1260                                 createLeavesSequence(file_name+std::string(".leafseq")); 
    1261                                  
    1262                                 std::cout << "OK!" << std::endl; 
    1263  
    1264                                 /*                              TreeSimplificationSequence * auxTreeSimpSequence = new TreeSimplificationSequence(); 
    1265                                                                         auxTreeSimpSequence->Load(Serializer("leavesSimplification.txt",Serializer::READ)); 
    1266  
    1267                                                                         if (auxTreeSimpSequence && mGeoMesh) 
    1268                                                                         { 
    1269                                                                         LodTreeConstructor * auxLodTreeConstructor = new LodTreeConstructor(mGeoMesh,auxTreeSimpSequence); 
    1270                                                                         delete auxLodTreeConstructor; 
    1271                                                                         } 
    1272                                                                         else 
    1273                                                                         { 
    1274                                                                         fltk::alert("There is no leaf simplification sequence."); 
    1275                                                                         break; 
    1276                                                                         } 
    1277  
    1278  
    1279                                                                         delete auxTreeSimpSequence;*/ 
    1280  
    1281                         case    LODSTRIPS_AUTO: 
    1282  
    1283                                 //      Builder 
    1284                                 if (!file_name) 
    1285                                 { 
    1286                                         file_name       =       fltk::file_chooser("Build LOD","*",""); 
    1287                                 } 
    1288                                  
    1289                                 //      If a file was selected. 
    1290                                 if (file_name) 
    1291                                 { 
    1292                                         //      Undo the simplification changes. 
    1293                                         undo(); 
    1294  
    1295                                         //      Stripify the mesh object. 
    1296                                         stripify(); 
    1297  
    1298                                         //      Reset the build bar. 
    1299                                         mBuildBar->position(0); 
    1300  
    1301                                         //      Simplification sequence. 
    1302                                         oMeshSimpSequence = new MeshSimplificationSequence(); 
    1303  
    1304                                         //      Loads a simplification sequence file. 
    1305                                         oMeshSimpSequence->Load(Serializer(     "SimplifSequence.txt", 
    1306                                                                                                                                                                                         Serializer::READ)); 
    1307  
    1308                                         //      If the simplification sequence and the mesh exist. 
    1309                                         if (oMeshSimpSequence && mGeoMesh) 
     1248                        file_name       =       fltk::file_chooser("Build LOD","*.mesh",""); 
     1249                         
     1250                        //      If a file was selected. 
     1251                        if (file_name) 
     1252                        { 
     1253                                //      Undo the simplification changes. 
     1254                                undo(); 
     1255 
     1256                                //      Stripify the mesh object. 
     1257                                stripify(); 
     1258 
     1259                                //      Reset the build bar. 
     1260                                mBuildBar->position(0); 
     1261 
     1262                                //      Simplification sequence. 
     1263                                oMeshSimpSequence = new MeshSimplificationSequence(); 
     1264 
     1265                                //      Loads a simplification sequence file. 
     1266                                oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 
     1267 
     1268                                //      If the simplification sequence and the mesh exist. 
     1269                                if (oMeshSimpSequence && mGeoMesh) 
     1270                                { 
     1271                                        oLodStrip               =       new LodStripsConstructor(       mGeoMesh, 
     1272                                                        oMeshSimpSequence, 
     1273                                                        idMeshLeaves, 
     1274                                                        progress_function); 
     1275 
     1276//                                              oSerializer     = new Serializer(file_name,Serializer::Mode::WRITE); 
     1277 
     1278                    oLodStrip->UpdateMesh(); 
     1279 
     1280                                        //      Deletes the previous mesh. 
     1281                                        delete mUndoMesh; 
     1282 
     1283                                        mUndoMesh       =       new Mesh(); 
     1284 
     1285                                        //      Sets the undo mesh. 
     1286                                        *mUndoMesh      =       *mGeoMesh; 
     1287 
     1288                                        delete  mGeoMesh; 
     1289 
     1290                                        mGeoMesh        =       oLodStrip->GetMesh(); 
     1291 
     1292                                        geoMeshView->setMesh(mGeoMesh); 
     1293 
     1294                                        mesh_saver      =       new     GeoMeshSaver(); 
     1295//                                      file_name[strlen(file_name) - 4]        =       '\0'; 
     1296                                         
     1297                                        mesh_saver->leavesSubMesh=idMeshLeaves; 
     1298                                        mesh_saver->leavesVB=origSubMeshVB; 
     1299                                        mesh_saver->numindices=orig_numindices; 
     1300                                        mesh_saver->indices=orig_indices; 
     1301                                        mesh_saver->save(mGeoMesh,file_name); 
     1302                                        delete  mesh_saver; 
     1303                                        oLodStrip->Save(file_name); 
     1304                                        //      Close file. 
     1305//                                              delete  oSerializer;                             
     1306                                } 
     1307                                else 
     1308                                { 
     1309                                        //      Error message. 
     1310                                        fltk::alert("There is no simplification sequence."); 
     1311                                } 
     1312 
     1313                                //      Deletes the siplification sequence object. 
     1314                                delete  oMeshSimpSequence; 
     1315 
     1316                                if (mApplicationState==LODTREES_AUTO) 
     1317                                { 
     1318                                        //      Open file chooser dialog. 
     1319/*                                      file_name       =       fltk::file_chooser("Build LOD","*",""); 
     1320                                         
     1321                                        if (!file_name) 
    13101322                                        { 
    1311                                                 oLodStrip               =       new LodStripsConstructor(       mGeoMesh, 
    1312                                                                 oMeshSimpSequence, 
    1313                                                                 idMeshLeaves, 
    1314                                                                 progress_function); 
    1315  
    1316                                                 oSerializer     =       new Serializer( strcat(file_name,".lod"), 
    1317                                                                                                                                                                         Serializer::Mode::WRITE); 
    1318  
    1319                                                 oLodStrip->Save(*oSerializer); 
    1320  
    1321                                                 //      Close file. 
    1322                                                 delete  oSerializer; 
    1323  
    1324                                                 //      Deletes the previous mesh. 
    1325                                                 delete mUndoMesh; 
    1326  
    1327                                                 mUndoMesh       =       new Mesh(); 
    1328  
    1329                                                 //      Sets the undo mesh. 
    1330                                                 *mUndoMesh      =       *mGeoMesh; 
    1331  
    1332                                                 delete  mGeoMesh; 
    1333  
    1334                                                 mGeoMesh        =       oLodStrip->GetMesh(); 
    1335  
    1336                                                 geoMeshView->setMesh(mGeoMesh); 
    1337  
    1338                                                 mesh_saver      =       new     GeoMeshSaver(); 
    1339                                                 file_name[strlen(file_name) - 4]        =       '\0'; 
    1340                                                  
    1341                                                 mesh_saver->leavesSubMesh=idMeshLeaves; 
    1342                                                 mesh_saver->leavesVB=origSubMeshVB; 
    1343                                                 mesh_saver->numindices=orig_numindices; 
    1344                                                 mesh_saver->indices=orig_indices; 
    1345                                                 mesh_saver->save(mGeoMesh,strcat(file_name,".mesh")); 
    1346                                                  
    1347                                                 delete  mesh_saver; 
    1348                                         } 
    1349                                         else 
    1350                                         { 
    1351                                                 //      Error message. 
    1352                                                 fltk::alert("There is no simplification sequence."); 
    1353                                         } 
    1354  
    1355                                         //      Deletes the siplification sequence object. 
    1356                                         delete  oMeshSimpSequence; 
    1357                                 } 
    1358                                 break; 
     1323                                                break; 
     1324                                        }*/ 
     1325 
     1326                                        std::cout << "Creando secuencia de simplificacion de hojas..."; 
     1327                                         
     1328                                        createLeavesSequence(file_name); 
     1329                                         
     1330                                        std::cout << "OK!" << std::endl;                 
     1331                                } 
     1332                        } 
    13591333                } 
     1334 
    13601335                //      Refresh data aplication. 
    13611336                refreshApplicationBar(); 
     
    22362211        tree_sequencer  =       mTreeSimplifier->GetSimplificationSequence(); 
    22372212         
    2238         tree_sequencer->putMeshName(nombremesh);  
    2239         tree_sequencer->Save(Serializer(filename,Serializer::WRITE)); 
     2213        tree_sequencer->putMeshName(nombremesh);         
     2214        tree_sequencer->Save(Serializer(filename,Serializer::APPEND)); 
    22402215 
    22412216        delete  tree_sequencer; 
     
    23922367//      Initialize the lodstripslibrary for visualization. 
    23932368//--------------------------------------------------------------------------- 
    2394 void    GeoMeshViewUI::setLodStripsLibrary(std::string lodfile, Mesh    *geomesh) 
     2369void    GeoMeshViewUI::setLodStripsLibrary(const Geometry::LodStripsLibraryData &loddata, Mesh  *geomesh) 
    23952370{ 
    23962371        //      If there is no lod strips object. 
     
    24012376 
    24022377        //      New lod strips object. 
    2403         lodStripsLib    =       new     LodStripsLibrary(lodfile, geomesh); 
     2378        lodStripsLib    =       new     LodStripsLibrary(loddata, geomesh); 
    24042379 
    24052380        //      Sets the slider range. 
     
    24172392//      Initialize the lodTreelibrary for visualization. 
    24182393//--------------------------------------------------------------------------- 
    2419 //void  GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh     *geomesh) 
    2420 void    GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh *geomesh, uint32 ileafSubMesh) 
    2421  
     2394void    GeoMeshViewUI::setLodTreesLibrary(const LodStripsLibraryData &lodstripsdata, const TreeSimplificationSequence &treesimpseq, Mesh *geomesh, uint32 ileafSubMesh) 
    24222395{ 
    24232396        //      If there is no lod strips object. 
     
    24282401 
    24292402        //      New lod strips object. 
    2430 /*      lodTreeLib      =       new     Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj", 
    2431                                                                                 "\\\\quake\\home\\\Modelos\\betula_populifolia\\hojas.obj", 
    2432                                                                                 "\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");*/ 
    2433  
    2434         lodTreeLib = new Geometry::LodTreeLibrary(lodfile,leafseqfile,geomesh,ileafSubMesh); 
     2403 
     2404        lodTreeLib = new Geometry::LodTreeLibrary(lodstripsdata,treesimpseq,geomesh,ileafSubMesh); 
    24352405 
    24362406        //      Sets the slider range. 
    2437 //      mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); 
    2438 //      mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod()); 
    24392407        mLodStripSlider->range(0.0f,1.0f); 
    24402408        mLodTreeSlider->range(0.0f,1.0f); 
Note: See TracChangeset for help on using the changeset viewer.