Ignore:
Timestamp:
05/24/06 11:49:33 (18 years ago)
Author:
gumbau
Message:
 
Location:
GTP/trunk/Lib/Geom/shared/GTGeometry
Files:
66 added
1 edited

Legend:

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

    r983 r984  
    555555//      Initilizations 
    556556//--------------------------------------------------------------------------- 
    557 void SimplificationMethod::simplfmethod_init(void) 
     557void SimplificationMethod::simplifmethod_init(void) 
    558558{ 
    559559        int i; 
    560560 
    561         // Convertir la estructura geomesh a modelo qslim 
     561        // Change mesh structure. 
    562562        geomesh2simplifModel(); 
    563563 
     
    586586//      Do the contractions till the required LOD (percentage option) 
    587587//--------------------------------------------------------------------------- 
    588 void SimplificationMethod::simplfmethod_run(int finalfaces,TIPOFUNC upb) 
     588void SimplificationMethod::simplifmethod_run(int finalfaces,TIPOFUNC upb) 
    589589{ 
    590590        decimate_init(M0, qslim::pair_selection_tolerance); 
     
    629629//      Do the contractions till the required LOD (number of vertices option) 
    630630//--------------------------------------------------------------------------- 
    631 void SimplificationMethod::simplfmethod_runv(int numvertices,TIPOFUNC upb) 
     631void SimplificationMethod::simplifmethod_runv(int numvertices,TIPOFUNC upb) 
    632632{ 
    633633        decimate_init(M0, qslim::pair_selection_tolerance); 
     
    719719                { 
    720720                        //If the model has texture information 
    721                         /*                      if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)  
    722                                                         { 
    723                         //For all the vertices of each submesh 
    724                         for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
    725                         { 
    726                         _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    727                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    728                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
    729  
    730                         std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
    731                         if (mit==vertices_map.end()) 
    732                         { 
    733                         //If the vertex is not in vertices_map, then is added 
    734                         simplifindex=M0.in_Vertex(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    735                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    736                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
    737                         M0.in_Normal(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
    738                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
    739                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
    740  
    741                         M0.in_TexCoord(qslim::Vec2(objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x,  
    742                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
    743                         vertices_map[auxvert] = num_final_verts; 
    744                         num_final_verts ++; 
    745  
    746                         std::vector<int> v; 
    747                         submeshmap[simplifindex]=v; 
    748                         submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
    749                         std::vector<int> v2; 
    750                         vertexbuffermap[simplifindex]=v2; 
    751                         vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
    752  
    753                         // Debug 
    754                         num_final_verts2++; 
    755                         } 
    756                         else 
    757                         { 
    758                         //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
    759                         simplifindex = mit->second; 
    760                         submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
    761                         vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
    762  
    763                         // Debug 
    764                         num_repeated_verts++; 
    765                         }        
    766                         } 
     721                        if (objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS)  
     722                        { 
     723                                //For all the vertices of each submesh 
     724                                for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
     725                                { 
     726                                        _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
     727                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
     728                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
     729 
     730                                        std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
     731                                        if (mit==vertices_map.end()) 
     732                                        { 
     733                                                //If the vertex is not in vertices_map, then is added 
     734                                                simplifindex=M0.in_Vertex(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
     735                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
     736                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
     737                                                M0.in_Normal(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
     738                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
     739                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
     740 
     741                                                M0.in_TexCoord(qslim::Vec2(objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x,  
     742                                                                        objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
     743                                                vertices_map[auxvert] = num_final_verts; 
     744                                                num_final_verts ++; 
     745 
     746                                                std::vector<int> v; 
     747                                                submeshmap[simplifindex]=v; 
     748                                                submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
     749                                                std::vector<int> v2; 
     750                                                vertexbuffermap[simplifindex]=v2; 
     751                                                vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
     752 
     753                                                // Debug 
     754                                                num_final_verts2++; 
     755                                        } 
     756                                        else 
     757                                        { 
     758                                                //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
     759                                                simplifindex = mit->second; 
     760                                                submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
     761                                                vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
     762 
     763                                                // Debug 
     764                                                num_repeated_verts++; 
     765                                        }        
     766                                } 
    767767                        } 
    768768                        else //the model has not texture information 
    769                         { */ 
    770                         //For all the vertices of each submesh 
    771                         for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
    772                         { 
    773                                 _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    774                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    775                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
    776  
    777                                 std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
    778                                 if (mit==vertices_map.end()) 
    779                                 { 
    780                                         //If the vertex is not in vertices_map, then is added 
    781                                         simplifindex=M0.in_Vertex(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
    782                                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    783                                                                 objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
    784                                         M0.in_Normal(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
    785                                                                 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
    786                                                                 objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
    787                                         M0.in_TexCoord(qslim::Vec2(0.0,0.0)); 
    788                                         vertices_map[auxvert] = num_final_verts; 
    789                                         num_final_verts ++; 
    790  
    791                                         std::vector<int> v; 
    792                                         submeshmap[simplifindex]=v; 
    793                                         submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
    794                                         std::vector<int> v2; 
    795                                         vertexbuffermap[simplifindex]=v2; 
    796                                         vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
    797                                 } 
    798                                 else 
    799                                 { 
    800                                         //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
    801                                         simplifindex = mit->second; 
    802                                         submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
    803                                         vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
    804                                 }        
    805                         } 
    806                         /*      }*/ 
     769                        {  
     770                                //For all the vertices of each submesh 
     771                                for (size_t j=0; j<objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
     772                                { 
     773                                        _float3_ auxvert(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
     774                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
     775                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z); 
     776 
     777                                        std::map<_float3_,int>::iterator mit = vertices_map.find(auxvert); 
     778                                        if (mit==vertices_map.end()) 
     779                                        { 
     780                                                //If the vertex is not in vertices_map, then is added 
     781                                                simplifindex=M0.in_Vertex(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x,  
     782                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
     783                                                                        objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
     784                                                M0.in_Normal(qslim::Vec3(objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x,  
     785                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
     786                                                                        objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
     787                                                M0.in_TexCoord(qslim::Vec2(0.0,0.0)); 
     788                                                vertices_map[auxvert] = num_final_verts; 
     789                                                num_final_verts ++; 
     790 
     791                                                std::vector<int> v; 
     792                                                submeshmap[simplifindex]=v; 
     793                                                submeshmap[simplifindex].push_back((int)i); //Add the index of the mesh that contains the vertex 
     794                                                std::vector<int> v2; 
     795                                                vertexbuffermap[simplifindex]=v2; 
     796                                                vertexbuffermap[simplifindex].push_back((int)j); //Add the index of vertex in the submesh 
     797                                        } 
     798                                        else 
     799                                        { 
     800                                                //the vertex is already in vertices_map, so store the reference of the first one with the same space coodinates 
     801                                                simplifindex = mit->second; 
     802                                                submeshmap[simplifindex].push_back((int)i); //Submeshes that contains the vertex 
     803                                                vertexbuffermap[simplifindex].push_back((int)j); //Indices of the vertex buffers that contains the vertex 
     804                                        }        
     805                                } 
     806                        } 
    807807                        if (objmesh->mSubMesh[i].mSharedVertexBuffer) 
    808808                        { 
     
    936936                                                                                                                                                                                                                                                TIPOFUNC upb) 
    937937{ 
    938         simplfmethod_init(); 
     938        simplifmethod_init(); 
    939939 
    940940        if (simpliftype == 0) 
    941941        { 
    942942                //Percentage option 
    943                 simplfmethod_run((int)(number_of_triangles*lod),upb); 
     943                simplifmethod_run((int)(number_of_triangles*lod),upb); 
    944944        } 
    945945        else 
    946946        { 
    947947                //Number of vertices option 
    948                 simplfmethod_runv((int)lod,upb); 
     948                simplifmethod_runv((int)lod,upb); 
    949949        } 
    950950 
     
    956956 
    957957        MAPAINDIND *unique_verts_inds_by_geo = new MAPAINDIND[objmesh->mSubMeshCount];  
    958         REPINDLIST *ver_inds_repes_x_geo        = new REPINDLIST[objmesh->mSubMeshCount];  
     958        REPINDLIST *ver_inds_rep_by_geo         = new REPINDLIST[objmesh->mSubMeshCount];  
    959959 
    960960        //      Index counter by submesh. 
     
    966966        } 
    967967 
    968         qslim::Vertex *auxvertex; 
    969968 
    970969        //      Construct the model. 
     
    974973                { 
    975974                        qslim::Face *auxface    =       M0.face(i); 
    976                         auxvertex                                                       =       NULL; 
    977975 
    978976                        //      Determine to which submesh pertains the triangle. 
     
    10031001 
    10041002                        //      Total number of indices by submesh. 
    1005                         ver_inds_repes_x_geo[igeo].push_back(auxface->vertex(0)->validID()); 
    1006                         ver_inds_repes_x_geo[igeo].push_back(auxface->vertex(1)->validID()); 
    1007                         ver_inds_repes_x_geo[igeo].push_back(auxface->vertex(2)->validID()); 
     1003                        ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(0)->validID()); 
     1004                        ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(1)->validID()); 
     1005                        ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(2)->validID()); 
    10081006                } 
    10091007        } 
     
    10691067                { 
    10701068                        //      Indices vectors. 
    1071                         mGeoMesh->mSubMesh[i].mIndexCount       =       ver_inds_repes_x_geo[i].size(); 
     1069                        mGeoMesh->mSubMesh[i].mIndexCount       =       ver_inds_rep_by_geo[i].size(); 
    10721070                        mGeoMesh->mSubMesh[i].mIndex                    =       new Index[mGeoMesh-> 
    10731071                                                                                                                                                                                                                mSubMesh[i].mIndexCount]; 
     
    10771075                        { 
    10781076                                //      Obtain the indices that point at VertexBuffer. 
    1079                                 mGeoMesh->mSubMesh[i].mIndex[j] =       unique_verts_inds_by_geo[i].operator [](ver_inds_repes_x_geo[i].operator [](j)); 
     1077                                mGeoMesh->mSubMesh[i].mIndex[j] =       unique_verts_inds_by_geo[i].operator [](ver_inds_rep_by_geo[i].operator [](j)); 
    10801078                        } 
    10811079 
     
    11721170 
    11731171        delete[] unique_verts_inds_by_geo; 
    1174         delete[] ver_inds_repes_x_geo; 
     1172        delete[] ver_inds_rep_by_geo; 
    11751173        delete[] inextvert; 
    11761174 
Note: See TracChangeset for help on using the changeset viewer.