Changeset 1549


Ignore:
Timestamp:
10/02/06 14:17:27 (18 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared/GeoTool
Files:
13 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h

    r1058 r1549  
    1919 
    2020namespace Geometry{ class LodTreeLibrary; } 
     21 
     22using   namespace       Geometry; 
     23using   namespace       std; 
    2124 
    2225class GeoMeshView : public fltk::GlWindow 
     
    3942 
    4043        GeoMeshView(int                                         x, 
    41                         int                                             y, 
    42                         int                                             w, 
    43                         int                                             h, 
    44                         const   char            *l                                                      =       0, 
    45                         GeoMeshViewUI   *geoMeshViewUI  =       0); 
     44                                                        int                                             y, 
     45                                                        int                                             w, 
     46                                                        int                                             h, 
     47                                                        const   char            *l                                                      =       0, 
     48                                                        GeoMeshViewUI   *geoMeshViewUI  =       0); 
    4649 
    4750        /*      This function is callalled by the zoom slider 
     
    5558         * and the initialize button in GeoMeshViewUI. 
    5659         */ 
    57         void v_angle(float angle){vAng=angle;}; 
     60        void v_angle(float angle){vAng  =       angle;}; 
    5861         
    5962        // Return the rotation about the vertical (y ) axis. 
     
    6669         * initialize button in GeoMeshViewUI. 
    6770         */ 
    68         void h_angle(float angle){hAng=angle;}; 
     71        void h_angle(float angle){hAng  =       angle;}; 
    6972         
    7073        // the rotation about the horizontal (x ) axis. 
     
    7679         * initialize button in GeoMeshViewUI. 
    7780         */ 
    78         void panx(float x){xshift=x;}; 
     81        void panx(float x){xshift       =       x;}; 
    7982         
    8083        /* Sets the y shift of the cube view camera. 
     
    8386         * initialize button in GeoMeshViewUI. 
    8487         */ 
    85         void pany(float y){yshift=y;}; 
     88        void pany(float y){yshift       =       y;}; 
    8689 
    8790        //      Wire model. 
     
    116119        void    activeLodTree(){mLodTree        =       true;} 
    117120        void    deactiveLodTree(){mLodTree      =       false;} 
    118  
    119121 
    120122        //      Ilumination modes. 
     
    134136#endif 
    135137        } 
     138 
    136139        void    restoreContext() 
    137140        { 
     
    196199        void    LoadTexture(const char *); 
    197200        void    LoadTextureSubMesh(int isubmesh, const char *); 
     201        void    addTexFile(const char *); 
     202        void    changeTexFile(int isubmesh, const char *); 
    198203 
    199204        int getSubMeshCount(void) const { return mSubMeshCount; } 
     
    294299        //      Idetifier of Visualization List. 
    295300        GLuint  mIdVisualList; 
     301 
     302        //      List of texture files of the mesh. 
     303        vector<string>  mMeshTexFiles; 
    296304}; 
    297305 
  • GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshViewUI.h

    r1543 r1549  
    435435        int numSubMeshNames; 
    436436        char **SubMeshNames; 
    437  
    438437}; 
    439438 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp

    r1543 r1549  
    451451void GeoMeshView::setMesh(Mesh  *geomesh) 
    452452{ 
    453         GLfloat color_blanco[]  =       {1.0f,1.0f,1.0f,1.0f}; 
     453        GLfloat white_color[]   =       {1.0f,1.0f,1.0f,1.0f}; 
    454454 
    455455        this->geoMesh                   =       geomesh; 
     
    461461        refreshVertices(geomesh); 
    462462         
    463         glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco); 
     463        glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,white_color); 
    464464 
    465465        if (current_texture_submesh) 
     
    470470        current_texture_submesh =       new GLuint[getSubMeshCount()]; 
    471471 
    472         for (int i=0; i<getSubMeshCount(); i++) 
     472        for (int i      =       0; i < getSubMeshCount(); i++) 
    473473        { 
    474474                current_texture_submesh[i]      =       0; 
     475 
     476                LoadTextureSubMesh(i,   mMeshTexFiles[i].c_str()); 
    475477        } 
    476478} 
     
    709711                        //      The end of the index array. 
    710712                        indexEnd        = &geosubmesh->mIndex[geosubmesh->mIndexCount]; 
    711             size= indexEnd - indexBegin; 
     713                        size= indexEnd - indexBegin; 
    712714                } 
    713715                else 
     
    716718                        indexEnd        = geosubmesh->mStrip[strip + 1]; 
    717719 
    718                 for (index = indexBegin; index < indexEnd; index++) 
    719                 { 
    720                         size++; 
    721                 } 
     720                        for (index = indexBegin; index < indexEnd; index++) 
     721                        { 
     722                                size++; 
     723                        } 
    722724                        //      Remove degenerated 
    723725                        //indexEnd--; 
     
    744746 
    745747 
    746         //VERTEX ARRAYS 
    747         glEnableClientState(GL_VERTEX_ARRAY); 
    748         glEnableClientState(GL_NORMAL_ARRAY); 
    749         if (usetex) 
    750                 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
    751         else 
    752                 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
     748                //VERTEX ARRAYS 
     749                glEnableClientState(GL_VERTEX_ARRAY); 
     750                glEnableClientState(GL_NORMAL_ARRAY); 
     751 
     752                if (usetex) 
     753                { 
     754                        glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
     755                } 
     756                else 
     757                { 
     758                        glDisableClientState(GL_TEXTURE_COORD_ARRAY); 
     759                } 
    753760 
    754761                glVertexPointer(3, GL_FLOAT, 0, geosubmesh->mVertexBuffer->mPosition); 
    755762                glNormalPointer(GL_FLOAT, 0, geosubmesh->mVertexBuffer->mNormal); 
     763 
    756764                if (usetex) 
     765                { 
    757766                        glTexCoordPointer(2, GL_FLOAT, 0, geosubmesh->mVertexBuffer->mTexCoords); 
     767                } 
    758768 
    759769                glDrawElements( GL_TRIANGLE_STRIP, 
    760                         size 
    761                         , 
    762                         GL_UNSIGNED_INT, 
    763                         indexBegin 
    764                         ); 
    765  
    766         if (submesh==leavesSubMesh) 
    767         { 
    768                 glDisable(GL_ALPHA_TEST); 
    769                 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0); 
    770         } 
    771  
    772         } 
    773  
     770                                                                                size, 
     771                                                                                GL_UNSIGNED_INT, 
     772                                                                                indexBegin); 
     773 
     774                if (submesh == leavesSubMesh) 
     775                { 
     776                        glDisable(GL_ALPHA_TEST); 
     777                        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0); 
     778                } 
     779        } 
    774780}//End drawTriangleStrip. 
    775781 
     
    12211227        { 
    12221228                disableColorStrips(); 
     1229 
    12231230                //glDisable(GL_LIGHTING); 
    1224                 glColor3d(0.0, 0.0, 0.0); 
    1225  
    1226                 GLfloat color[] =       {0.0f,0.0f,0.0f,1.0f}; 
     1231 
     1232                GLfloat color[4]; 
     1233 
     1234                if (mSolid) 
     1235                { 
     1236                        glColor3d(0.0, 0.0, 0.0); 
     1237                        color[0]        =       0.0f; 
     1238                        color[1]        =       0.0f; 
     1239                        color[2]        =       0.0f; 
     1240                        color[3]        =       1.0f; 
     1241                } 
     1242                else 
     1243                { 
     1244                        glColor3d(1.0, 1.0, 1.0); 
     1245                        color[0]        =       1.0f; 
     1246                        color[1]        =       1.0f; 
     1247                        color[2]        =       1.0f; 
     1248                        color[3]        =       1.0f; 
     1249                } 
    12271250 
    12281251                glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color); 
     
    12821305} 
    12831306 
     1307//      Add texture file name to the list of texture files of mesh. 
     1308void    GeoMeshView::addTexFile(const char *imgfile) 
     1309{ 
     1310        mMeshTexFiles.push_back(string(imgfile)); 
     1311} 
     1312 
     1313//      Change texture file of a given submesh. 
     1314void    GeoMeshView::changeTexFile(int isubmesh, const char *imgfile) 
     1315{ 
     1316        mMeshTexFiles[isubmesh] =       string(imgfile); 
     1317} 
     1318 
    12841319void    GeoMeshView::resetTextures(void) 
    12851320{ 
     1321        //      Clears texture files list. 
     1322        mMeshTexFiles.clear(); 
     1323 
    12861324        if (current_texture) 
    12871325        { 
  • GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp

    r1543 r1549  
    4242                strcpy(filename,fcho->value()); 
    4343                geoMeshView->LoadTexture(filename); 
     44 
     45                //      For each submesh. 
     46                for (int i      =       0; i < mGeoMesh->mSubMeshCount; i++) 
     47                { 
     48                        geoMeshView->changeTexFile(i,filename); 
     49                } 
     50 
     51                //      Refresh mesh. 
     52                geoMeshView->setMesh(mGeoMesh); 
    4453        } 
    4554} 
     
    5362 
    5463 
    55 inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i(fltk::Item *item, void *) 
    56 { 
     64inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i(     fltk::Item *item, 
     65                                                                                                                                                                                                                                                void *) 
     66{ 
     67        fltk::FileChooser       *fcho; 
     68 
    5769        static char pattern[] = "*.{jpg|tga|png|bmp}"; 
    5870 
    59         const char * label = item->label(); 
    60         int isubmesh = label[strlen(label)-1]-48; 
    61  
    62         fltk::FileChooser       *fcho = new fltk::FileChooser("",pattern,fltk::FileChooser::CREATE,"Open image file"); 
     71        const char *label       =       item->label(); 
     72        int isubmesh                    =       label[strlen(label)-1]-48; 
     73 
     74        fcho    =       new fltk::FileChooser("", 
     75                                                                                                                                pattern, 
     76                                                                                                                                fltk::FileChooser::CREATE, 
     77                                                                                                                                "Open image file"); 
    6378        fcho->exec(); 
    64         char filename[256]=""; 
     79 
     80        char filename[256]      =       ""; 
     81 
    6582        if (fcho->value()) 
    6683        { 
    6784                strcpy(filename,fcho->value()); 
    68                 geoMeshView->LoadTextureSubMesh(isubmesh,filename); 
    69         } 
     85 
     86                geoMeshView->changeTexFile(isubmesh,filename); 
     87 
     88                //      Refresh mesh. 
     89                geoMeshView->setMesh(mGeoMesh); 
     90        } 
     91 
    7092} 
    7193 
     
    957979} 
    958980 
    959 VertexBuffer *origSubMeshVB=NULL; 
    960 int orig_numindices=0; 
    961 Index *orig_indices=NULL; 
     981VertexBuffer *origSubMeshVB     =       NULL; 
     982int orig_numindices                                     =       0; 
     983Index *orig_indices                                     =       NULL; 
    962984 
    963985//--------------------------------------------------------------------------- 
     
    973995        mProcessBar->position(0); 
    974996 
    975         origSubMeshVB=NULL; 
     997        origSubMeshVB   =       NULL; 
    976998     
    977999        //      Initialize error flag. 
     
    9821004        { 
    9831005                //      Choose between aplication state. 
    984                 switch(mApplicationState) 
     1006                switch (mApplicationState) 
    9851007                { 
    9861008                        //      Stripify state. 
     
    11481170                //      Refresh geometry attributes. 
    11491171                refreshApplicationBar(); 
    1150  
    1151                 //      Set textures. 
    1152                 geoMeshView->resetTextures(); 
    1153                 setTextures(); 
    11541172        } 
    11551173         
     
    11981216        { 
    11991217                //      Choose between aplication state. 
    1200                 if (mApplicationState==LODSTRIPS_AUTO || mApplicationState==LODTREES_AUTO) 
     1218                if (mApplicationState == LODSTRIPS_AUTO 
     1219                                || 
     1220                                mApplicationState == LODTREES_AUTO) 
    12011221                { 
    12021222                        file_name       =       fltk::file_chooser("Build LOD","*.mesh",""); 
     
    12151235 
    12161236                                //      Simplification sequence. 
    1217                                 //oMeshSimpSequence = new MeshSimplificationSequence(); 
    1218  
    1219                                 //      Loads a simplification sequence file. 
    1220                                 //oMeshSimpSequence->Load(Serializer("SimplifSequence.txt",Serializer::READ)); 
    1221  
    1222                                 //      Simplification sequence. 
    12231237                                oMeshSimpSequence =     mMeshSimplifier->GetSimplificationSequence(); 
    12241238 
     
    12261240                                if (oMeshSimpSequence && mGeoMesh) 
    12271241                                { 
    1228                                         oLodStrip               =       new LodStripsConstructor(       mGeoMesh, 
    1229                                                         oMeshSimpSequence, 
    1230                                                         idMeshLeaves, 
    1231                                                         progress_function); 
     1242                                        oLodStrip       =       new LodStripsConstructor(       mGeoMesh, 
     1243                                                                                                                                                                                                oMeshSimpSequence, 
     1244                                                                                                                                                                                                idMeshLeaves, 
     1245                                                                                                                                                                                                progress_function); 
    12321246 
    12331247                                        oLodStrip->UpdateMesh(); 
     
    12481262 
    12491263                                        mesh_saver      =       new     GeoMeshSaver(); 
    1250                                         //                                      file_name[strlen(file_name) - 4]        =       '\0'; 
    1251  
    1252                                         mesh_saver->leavesSubMesh=idMeshLeaves; 
    1253                                         mesh_saver->leavesVB=origSubMeshVB; 
    1254                                         mesh_saver->numindices=orig_numindices; 
    1255                                         mesh_saver->indices=orig_indices; 
     1264 
     1265                                        mesh_saver->leavesSubMesh       =       idMeshLeaves; 
     1266                                        mesh_saver->leavesVB                    =       origSubMeshVB; 
     1267                                        mesh_saver->numindices          =       orig_numindices; 
     1268                                        mesh_saver->indices                             =       orig_indices; 
     1269 
    12561270                                        mesh_saver->save(mGeoMesh,file_name); 
     1271 
    12571272                                        delete  mesh_saver; 
     1273 
    12581274                                        oLodStrip->Save(file_name); 
    12591275 
    12601276                                        //      Delete simplified mesh. 
    12611277                                        delete  mMeshSimplifier; 
    1262                                         //      Close file. 
    1263                                         //                                              delete  oSerializer;                             
    12641278                                } 
    12651279                                else 
     
    12691283                                } 
    12701284 
    1271                                 //      Deletes the siplification sequence object. 
    1272                                 //delete        oMeshSimpSequence; 
    1273  
    1274                                 if (mApplicationState==LODTREES_AUTO) 
    1275                                 { 
    1276                                         //      Open file chooser dialog. 
    1277 /*                                      file_name       =       fltk::file_chooser("Build LOD","*",""); 
    1278                                          
    1279                                         if (!file_name) 
    1280                                         { 
    1281                                                 break; 
    1282                                         }*/ 
    1283  
    1284                                         std::cout << "Creando secuencia de simplificacion de hojas..."; 
    1285                                          
     1285                                if (mApplicationState == LODTREES_AUTO) 
     1286                                { 
    12861287                                        createLeavesSequence(file_name); 
    1287                                          
    1288                                         std::cout << "OK!" << std::endl;                 
    12891288                                } 
    12901289                        } 
     
    12931292                //      Refresh data aplication. 
    12941293                refreshApplicationBar(); 
    1295  
    1296                 //      Set textures. 
    1297                 geoMeshView->resetTextures(); 
    1298                 setTextures(); 
    12991294        }        
    13001295} 
     
    22782273                //      Repaint the window. 
    22792274                mMainWindow->redraw(); 
    2280  
    2281                 //      Set textures. 
    2282                 geoMeshView->resetTextures(); 
    2283                 setTextures(); 
    22842275        } 
    22852276} 
     
    24472438                        mMB->label(char_value); 
    24482439 
     2440                        //      Set textures. 
     2441                        geoMeshView->resetTextures(); 
     2442                        setTextures(); 
     2443 
    24492444                        //      Visualize mesh. 
    24502445                        geoMeshView->setMesh(mGeoMesh); 
    24512446                         
    2452                         //      Set textures. 
    2453                         geoMeshView->resetTextures(); 
    2454                         setTextures(); 
    2455  
    24562447                        //      Hide right panel. 
    24572448                        hideRightPanel(); 
     
    25112502                material        = string(mGeoMesh->mSubMesh[submesh].mMaterialName); 
    25122503 
     2504                //      If exists material. 
    25132505                if (loader->existsMaterial(material)) 
    2514                 {                        
     2506                { 
     2507                        //      Gets file name. 
    25152508                        filename        =       loader->getTextureFileName(material); 
    25162509 
    2517                         geoMeshView->LoadTextureSubMesh(submesh,        filename.c_str()); 
     2510                        geoMeshView->addTexFile(filename.c_str()); 
     2511                } 
     2512                //      If not exists material. 
     2513                else 
     2514                { 
     2515                        //      File name empty. 
     2516                        filename        =       string(); 
     2517 
     2518                        geoMeshView->addTexFile(filename.c_str()); 
    25182519                } 
    25192520        } 
Note: See TracChangeset for help on using the changeset viewer.