Ignore:
Timestamp:
04/30/07 08:16:31 (17 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

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

    r2323 r2341  
    104104} 
    105105 
    106  
    107  
    108106//------------------------------------------------------------------------- 
    109107//      Repaint the FPS label. 
     
    156154                                                                                cb_menuFileSave_i(o,v); 
    157155} 
     156 
    158157 
    159158//------------------------------------------------------------------------- 
     
    10861085                                stripify(); 
    10871086 
     1087                                //      Debug. 
     1088                                //writeStrips(mGeoMesh); 
     1089 
    10881090                                break; 
    10891091 
     
    12981300{ 
    12991301        char                                    *file_name      =       NULL; 
     1302        char                                    *ptr; 
     1303        char                                    message[255]; 
    13001304        GeoMeshSaver    *mesh_saver; 
    13011305        Serializer              *oSerializer; 
     1306        int                                             answer_yes; 
    13021307 
    13031308        //      Sets the progress bar to process bar. 
     
    13201325                        if (file_name) 
    13211326                        { 
    1322                                 //      Undo the simplification changes. 
    1323                                 undo(); 
    1324  
    1325                                 //      Stripify the mesh object. 
    1326                                 stripify(); 
    1327  
    1328                                 //      Reset the build bar. 
    1329                                 mBuildBar->position(0); 
    1330  
    1331                                 //      Simplification sequence. 
    1332                                 oMeshSimpSequence =     mMeshSimplifier->GetSimplificationSequence(); 
    1333  
    1334                                 //      If the simplification sequence and the mesh exist. 
    1335                                 if (oMeshSimpSequence && mGeoMesh) 
    1336                                 { 
    1337                                         oLodStrip       =       new LodStripsConstructor(       mGeoMesh, 
    1338                                                                                                                                                                                                 oMeshSimpSequence, 
    1339                                                                                                                                                                                                 idMeshLeaves, 
    1340                                                                                                                                                                                                 progress_function); 
    1341  
    1342                                         oLodStrip->UpdateMesh(); 
    1343  
    1344                                         //      Deletes the previous mesh. 
    1345                                         delete mUndoMesh; 
    1346  
    1347                                         mUndoMesh       =       new Mesh(); 
    1348  
    1349                                         //      Sets the undo mesh. 
    1350                                         *mUndoMesh      =       *mGeoMesh; 
    1351  
    1352                                         delete  mGeoMesh; 
    1353  
    1354                                         mGeoMesh        =       oLodStrip->GetMesh(); 
    1355  
    1356                                         geoMeshView->setMesh(mGeoMesh); 
    1357  
    1358                                         mesh_saver      =       new     GeoMeshSaver(); 
    1359  
    1360                                         mesh_saver->leavesSubMesh       =       idMeshLeaves; 
    1361                                         mesh_saver->leavesVB                    =       origSubMeshVB; 
    1362                                         mesh_saver->numindices          =       orig_numindices; 
    1363                                         mesh_saver->indices                             =       orig_indices; 
    1364  
    1365                                         mesh_saver->save(mGeoMesh,file_name); 
    1366  
    1367                                         delete  mesh_saver; 
    1368  
    1369                                         oLodStrip->Save(file_name); 
     1327                                //      Cut extension. 
     1328                                ptr     =       strtok(file_name,"."); 
     1329 
     1330                                //      If has extension. 
     1331                                if (ptr) 
     1332                                { 
     1333                                        strcpy(file_name,ptr); 
     1334                                } 
     1335 
     1336                                //      Adds mesh extension. 
     1337                                strcat(file_name,".mesh"); 
     1338 
     1339                                //      If File Exists. 
     1340                                if (fileExists(file_name)) 
     1341                                { 
     1342                                        //      Compose message. 
     1343                                        strcpy(message,"Do you want to replace "); 
     1344                                        strcat(message,filename_name(file_name)); 
     1345                                        strcat(message,"?"); 
     1346 
     1347                                        //      Question. 
     1348                                        answer_yes      =       fltk::ask(message); 
     1349                                } 
     1350 
     1351                                //      If answer yes to replace question 
     1352                                //      or if file not exists. 
     1353                                if (answer_yes) 
     1354                                { 
     1355 
     1356                                        //      Undo the simplification changes. 
     1357                                        undo(); 
     1358 
     1359                                        //      Stripify the mesh object. 
     1360                                        stripify(); 
     1361 
     1362                                        //      Reset the build bar. 
     1363                                        mBuildBar->position(0); 
     1364 
     1365                                        //      Simplification sequence. 
     1366                                        oMeshSimpSequence =     mMeshSimplifier->GetSimplificationSequence(); 
     1367 
     1368                                        //      If the simplification sequence and the mesh exist. 
     1369                                        if (oMeshSimpSequence && mGeoMesh) 
     1370                                        { 
     1371                                                oLodStrip       =       new LodStripsConstructor(       mGeoMesh, 
     1372                                                                oMeshSimpSequence, 
     1373                                                                idMeshLeaves, 
     1374                                                                progress_function); 
     1375 
     1376                                                oLodStrip->UpdateMesh(); 
     1377 
     1378                                                //      Deletes the previous mesh. 
     1379                                                delete mUndoMesh; 
     1380 
     1381                                                mUndoMesh       =       new Mesh(); 
     1382 
     1383                                                //      Sets the undo mesh. 
     1384                                                *mUndoMesh      =       *mGeoMesh; 
     1385 
     1386                                                delete  mGeoMesh; 
     1387 
     1388                                                mGeoMesh        =       oLodStrip->GetMesh(); 
     1389 
     1390                                                geoMeshView->setMesh(mGeoMesh); 
     1391 
     1392                                                mesh_saver      =       new     GeoMeshSaver(); 
     1393 
     1394                                                mesh_saver->leavesSubMesh       =       idMeshLeaves; 
     1395                                                mesh_saver->leavesVB                    =       origSubMeshVB; 
     1396                                                mesh_saver->numindices          =       orig_numindices; 
     1397                                                mesh_saver->indices                             =       orig_indices; 
     1398 
     1399                                                mesh_saver->save(mGeoMesh,file_name); 
     1400 
     1401                                                delete  mesh_saver; 
     1402 
     1403                                                oLodStrip->Save(file_name); 
     1404                                        } 
    13701405                                } 
    13711406                                else 
     
    18371872{ 
    18381873        char                                            type[10]; 
     1874 
    18391875        unsigned        int             group_index; 
    18401876        unsigned        int             group_count; 
    18411877        unsigned        int             bone_count; 
     1878 
    18421879        fltk::ItemGroup **info_group; 
    18431880         
     
    18671904                        char    *skel_name              =       new char[256]; 
    18681905                        char    *bone_assig             =       new char[256]; 
     1906 
    18691907                        sprintf(group_name,"Skeleton"); 
    18701908                        info_group[group_index] = new fltk::ItemGroup(group_name); 
     
    18791917                                bone_count      +=      mGeoMesh->mSubMesh[i].mBones.size(); 
    18801918                        } 
     1919 
    18811920                        sprintf(bone_assig,"Bone assignamets: %d",bone_count); 
    18821921                        new fltk::Item(bone_assig); 
     
    18861925                } 
    18871926 
    1888                 for(int i=0; i<mGeoMesh->mSubMeshCount;i++) 
     1927                for(int i       =       0; i < mGeoMesh->mSubMeshCount; i++) 
    18891928                { 
    18901929                        char    *group_name     =       new char[256]; 
     
    19071946 
    19081947                        //      Submesh identifier. 
    1909                         sprintf(group_name,"SubMesh %d %s",i,type); 
     1948                        sprintf(group_name, 
     1949                                                        "SubMesh %d %s:%s", 
     1950                                                        i, 
     1951                                                        type, 
     1952                                                        mGeoMesh->mSubMesh[i].mName); 
    19101953                         
    19111954                        info_group[group_index] = new fltk::ItemGroup(group_name); 
    19121955                        info_group[group_index]->begin(); 
    19131956                        fltk::Item *sharedGeometry; 
     1957 
    19141958                        if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer) 
    19151959                        { 
     
    19221966 
    19231967                        //      Adds material name. 
    1924                         char *cadena2=new char[100]; 
     1968                        char *cadena2   =       new char[100]; 
    19251969                        sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName); 
    19261970                         
    19271971                        fltk::Item      *geomaterial    =       new fltk::Item(cadena2); 
    19281972                         
    1929                         char *cadena3=new char[100]; 
     1973                        char *cadena3   =       new char[100]; 
    19301974                         
    1931                         sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); 
     1975                        sprintf(cadena3, 
     1976                                                        "Number of indexes: %d", 
     1977                                                        mGeoMesh->mSubMesh[i].mIndexCount); 
     1978 
    19321979                        fltk::Item *numberIndex = new fltk::Item(cadena3); 
     1980 
    19331981                        if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST) 
    19341982                        { 
    1935                                 fltk::Item *type = new fltk::Item("Triangle List"); 
     1983                                fltk::Item      *type   =       new fltk::Item("Triangle List"); 
    19361984                        } 
    19371985                        else 
    19381986                        { 
    1939                                 fltk::Item *type = new fltk::Item("Triangle Strips"); 
     1987                                fltk::Item      *type   =       new fltk::Item("Triangle Strips"); 
    19401988                        } 
    19411989 
    1942                         char *cadenavertex=new char[30]; 
    1943                         sprintf(cadenavertex, "Number of vertices: %d",mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); 
    1944                         fltk::Item *numberVertex = new fltk::Item(cadenavertex); 
    1945  
    1946                         if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1990                        char *cadenavertex      =       new char[30]; 
     1991 
     1992                        sprintf(cadenavertex, 
     1993                                                        "Number of vertices: %d", 
     1994                                                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); 
     1995 
     1996                        fltk::Item      *numberVertex   =       new fltk::Item(cadenavertex); 
     1997 
     1998                        if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo 
     1999                                        & 
     2000                                        Geometry::VERTEX_NORMAL) 
    19472001                        { 
    1948                                 fltk::Item *normals = new fltk::Item("Normals: Yes"); 
     2002                                fltk::Item      *normals        =       new fltk::Item("Normals: Yes"); 
    19492003                        } 
    19502004                        else 
    19512005                        { 
    1952                                 fltk::Item *normals = new fltk::Item("Normals: No"); 
     2006                                fltk::Item *normals     =       new fltk::Item("Normals: No"); 
    19532007                        } 
    19542008 
    1955                         if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     2009                        if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo 
     2010                                        & 
     2011                                        Geometry::VERTEX_TEXCOORDS) 
    19562012                        { 
    1957                                 fltk::Item *textures = new fltk::Item("Textures: Yes"); 
     2013                                fltk::Item      *textures       =       new fltk::Item("Textures: Yes"); 
    19582014                        } 
    19592015                        else 
    19602016                        { 
    1961                                 fltk::Item *textures = new fltk::Item("Textures: No"); 
     2017                                fltk::Item      *textures       =       new fltk::Item("Textures: No"); 
    19622018                        } 
    19632019 
    1964  
    19652020                        info_group[group_index]->end(); 
    19662021                } 
     2022 
    19672023                ogeometry->end(); 
    19682024                this->mMeshInfo->add(ogeometry); 
     
    20572113                                        break; 
    20582114                                case    GEO_TRIANGLE_STRIPS: 
    2059                                         triangle_count  +=      geoSubMesh->mIndexCount - 2; 
     2115                                        triangle_count  +=      geoSubMesh->mIndexCount 
     2116                                                                                                                        - 
     2117                                                                                                                        2; 
    20602118                                        break; 
    20612119                        } 
     
    20642122 
    20652123        return  triangle_count; 
     2124} 
     2125 
     2126//------------------------------------------------------------------------- 
     2127//      Get the number of degenerated triangles. 
     2128//------------------------------------------------------------------------- 
     2129size_t  GeoMeshViewUI::getDegeneratedCount(Geometry::Mesh       *geoMesh) 
     2130{ 
     2131        size_t  degenerated; 
     2132        size_t  same_index; 
     2133        SubMesh *geoSubMesh; 
     2134 
     2135        //      Initialize the degenerated count. 
     2136        degenerated     =       0; 
     2137 
     2138        //      Initiazlize same index count. 
     2139        same_index = 1; 
     2140 
     2141        //      For each submesh. 
     2142        for (size_t     submesh =       0; submesh < geoMesh->mSubMeshCount; submesh++) 
     2143        { 
     2144                //      Gets the actual submesh. 
     2145                geoSubMesh      =       &geoMesh->mSubMesh[submesh]; 
     2146 
     2147                if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) 
     2148                { 
     2149                        //      Find degenerated triangles. 
     2150                        for (size_t     i = 0; i < (geoSubMesh->mIndexCount - 1); i++) 
     2151                        { 
     2152                                if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 1]) 
     2153                                { 
     2154                                        same_index++; 
     2155                                } 
     2156                                else 
     2157                                { 
     2158                                        if (same_index > 1) 
     2159                                        { 
     2160                                                degenerated     +=      same_index; 
     2161                                        } 
     2162                                        else if (i < (geoSubMesh->mIndexCount - 2)) 
     2163                                        { 
     2164                                                if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i + 2]) 
     2165                                                { 
     2166                                                        degenerated++; 
     2167                                                } 
     2168                                        } 
     2169 
     2170                                        same_index      = 1; 
     2171                                } 
     2172                        } 
     2173                } 
     2174        } 
     2175 
     2176        return  degenerated; 
    20662177} 
    20672178 
     
    24602571        static char     vertices_value[50]; 
    24612572        static char     triangles_value[50]; 
     2573        static char     degenerated_value[50]; 
    24622574        static char     strips_value[50]; 
    24632575         
     
    24712583 
    24722584        mTriangles->label(triangles_value); 
     2585 
     2586        //      Translate the degenerated count to a char value. 
     2587        sprintf(degenerated_value,"Degenerated %d",getDegeneratedCount(mGeoMesh)); 
     2588 
     2589        mDegenerated->label(degenerated_value); 
    24732590 
    24742591        //      Translate the triangle count to a char value. 
     
    26792796} 
    26802797 
     2798//------------------------------------------------------------------------- 
    26812799//      Set textures to mesh model. 
     2800//------------------------------------------------------------------------- 
    26822801void GeoMeshViewUI::setTextures() 
    26832802{ 
     
    32413360                        { 
    32423361                                fltk::Widget* o; 
    3243                                 o = mStrips = new fltk::Widget(354, 3, 30, 15, "Strips"); 
     3362                                o = mDegenerated = new fltk::Widget(354, 3, 30, 15, "Degenerated"); 
     3363                                o->box(fltk::NO_BOX); 
     3364                                o->labelfont(fltk::HELVETICA_BOLD); 
     3365                                o->color((fltk::Color)0xe0dfe300); 
     3366                        } 
     3367 
     3368                        { 
     3369                                fltk::Widget* o; 
     3370                                o = mStrips = new fltk::Widget(454, 3, 30, 15, "Strips"); 
    32443371                                o->box(fltk::NO_BOX); 
    32453372                                o->labelfont(fltk::HELVETICA_BOLD); 
     
    33203447} 
    33213448 
     3449//------------------------------------------------------------------------- 
     3450//      Write file of strips. 
     3451//------------------------------------------------------------------------- 
     3452void    GeoMeshViewUI::writeStrips(Mesh *geomesh) 
     3453{ 
     3454        Index                   *index; 
     3455        Index                   *indexBegin; 
     3456        Index                   *indexEnd; 
     3457        SubMesh         *geosubmesh; 
     3458 
     3459        ofstream        out ("strips.txt"); 
     3460 
     3461        //      For each submesh. 
     3462        for     (size_t submesh =       0;      submesh < geomesh->mSubMeshCount;       submesh++) 
     3463        { 
     3464                geosubmesh      =       &geomesh->mSubMesh[submesh]; 
     3465 
     3466                //      For each one of the strips. 
     3467                for (size_t strip = 0; strip < geosubmesh->mStripCount; strip++) 
     3468                { 
     3469                        //      First index of the strip. 
     3470                        indexBegin      =       geosubmesh->mStrip[strip]; 
     3471 
     3472                        //      If is the final strip 
     3473                        if (strip       == (geosubmesh->mStripCount - 1)) 
     3474                        { 
     3475                                //      The end of the index array. 
     3476                                indexEnd        =       &geosubmesh->mIndex[geosubmesh->mIndexCount]; 
     3477                        } 
     3478                        else 
     3479                        { 
     3480                                //      The beginning of the next strip. 
     3481                                indexEnd        = geosubmesh->mStrip[strip + 1]; 
     3482                        } 
     3483 
     3484                        for (index = indexBegin; index < indexEnd; index++) 
     3485                        { 
     3486                                out <<  index[0] 
     3487                                                <<      " "; 
     3488                        } 
     3489 
     3490                        out     <<      endl; 
     3491                } 
     3492        } 
     3493 
     3494        out.close(); 
     3495} 
     3496 
Note: See TracChangeset for help on using the changeset viewer.