Changeset 2088


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

Legend:

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

    r1600 r2088  
    33#include <iostream> 
    44#include <fstream> 
     5#include <gfx/geom/ProxGrid.h> 
     6#include "quadrics.h" 
    57 
    68using namespace std; 
     
    810using   namespace       simplif; 
    911 
    10 #include <gfx/geom/ProxGrid.h> 
    11 #include "quadrics.h" 
    12  
    13 //--------------------------------------------------------------------------- 
     12//------------------------------------------------------------------------- 
    1413//      Constructor 
    15 //--------------------------------------------------------------------------- 
     14//------------------------------------------------------------------------- 
    1615SimplificationMethod::SimplificationMethod(const Mesh *m) 
    1716{ 
    18         objmesh                                                 =       m; 
     17        mInitialMesh                            =       new Mesh(); 
     18        *mInitialMesh                           =       *m; 
    1919        mGeoMesh                                                =       NULL; 
    20         first_index_submesh     =       new unsigned int[objmesh->mSubMeshCount]; 
     20        first_index_submesh     =       new unsigned int[mInitialMesh->mSubMeshCount]; 
    2121        indexMeshLeaves                 =       -1; 
    2222 
     
    2525} 
    2626 
    27 //--------------------------------------------------------------------------- 
     27//------------------------------------------------------------------------- 
    2828//      Destructor 
    29 //--------------------------------------------------------------------------- 
     29//------------------------------------------------------------------------- 
    3030SimplificationMethod::~SimplificationMethod() 
    3131{ 
    32         delete heap; 
    33         delete [] first_index_submesh; 
    34 } 
    35  
    36 //--------------------------------------------------------------------------- 
     32        delete  heap; 
     33        delete  [] first_index_submesh; 
     34 
     35        delete  mInitialMesh; 
     36} 
     37 
     38//------------------------------------------------------------------------- 
    3739//      Recalculate the cost of the vertices of an edge 
    38 //--------------------------------------------------------------------------- 
     40//------------------------------------------------------------------------- 
    3941void SimplificationMethod::compute_pair_info(simplif::pair_info *auxpair) 
    4042{ 
     
    4850        simplif::real norm      =       v0_info.norm + v1_info.norm; 
    4951 
    50         auxpair->cost = simplif::quadrix_pair_target(Q, v0, v1, auxpair->candidate); 
     52        auxpair->cost = simplif::quadrix_pair_target(   Q, 
     53                                                                                                                                                                                                v0, 
     54                                                                                                                                                                                                v1, 
     55                                                                                                                                                                                                auxpair->candidate); 
    5156 
    5257        if ( simplif::will_weight_by_area ) 
     
    7479} 
    7580 
    76 //--------------------------------------------------------------------------- 
     81//------------------------------------------------------------------------- 
    7782//      Reasign the new vertex to the adequate face 
    78 //--------------------------------------------------------------------------- 
     83//------------------------------------------------------------------------- 
    7984int SimplificationMethod::predict_face( simplif::Face& F, 
    8085                                                                                                                                                                simplif::Vertex *v1, 
     
    8792        int nmapped = 0; 
    8893 
    89         if( F.vertex(0) == v1 || F.vertex(0) == v2 ) 
     94        if ( F.vertex(0) == v1 || F.vertex(0) == v2 ) 
    9095        { 
    9196                f1 = vnew;  nmapped++; 
     
    96101        } 
    97102 
    98         if( F.vertex(1) == v1 || F.vertex(1) == v2 ) 
     103        if ( F.vertex(1) == v1 || F.vertex(1) == v2 ) 
    99104        { 
    100105                f2 = vnew;  nmapped++; 
     
    105110        } 
    106111 
    107         if( F.vertex(2) == v1 || F.vertex(2) == v2 ) 
     112        if ( F.vertex(2) == v1 || F.vertex(2) == v2 ) 
    108113        { 
    109114                f3 = vnew;  nmapped++; 
     
    119124#define MESH_INVERSION_PENALTY 1e9 
    120125 
    121 //--------------------------------------------------------------------------- 
    122 //--------------------------------------------------------------------------- 
    123 simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, simplif::Vertex *v1, 
    124                                                                                                                                                  simplif::Vertex *v2, 
    125                                                                                                                                                  simplif::Vec3& vnew) 
     126//------------------------------------------------------------------------- 
     127//------------------------------------------------------------------------- 
     128simplif::real SimplificationMethod::pair_mesh_penalty(simplif::Model& M, 
     129                                                                                                                                                                                                                        simplif::Vertex *v1, 
     130                                                                                                                                                                                                                        simplif::Vertex *v2, 
     131                                                                                                                                                                                                                        simplif::Vec3& vnew) 
    126132{ 
    127133        static simplif::face_buffer changed; 
     
    166172} 
    167173 
    168 //--------------------------------------------------------------------------- 
     174//------------------------------------------------------------------------- 
    169175//      Returns true if the givens vertices are a valid pair 
    170 //--------------------------------------------------------------------------- 
     176//------------------------------------------------------------------------- 
    171177bool SimplificationMethod::check_for_pair(simplif::Vertex *v0, 
    172178                                                                                                                                                                        simplif::Vertex *v1) 
     
    185191} 
    186192 
    187 //--------------------------------------------------------------------------- 
     193//------------------------------------------------------------------------- 
    188194//      Create a new pair with two given vertices 
    189 //--------------------------------------------------------------------------- 
     195//------------------------------------------------------------------------- 
    190196simplif::pair_info *SimplificationMethod::new_pair(     simplif::Vertex *v0, 
    191197                                                                                                                                                                                                                simplif::Vertex *v1) 
     
    202208} 
    203209 
    204 //--------------------------------------------------------------------------- 
     210//------------------------------------------------------------------------- 
    205211//      Remove a given pair 
    206 //--------------------------------------------------------------------------- 
     212//------------------------------------------------------------------------- 
    207213void SimplificationMethod::delete_pair(simplif::pair_info *auxpair) 
    208214{ 
     
    221227} 
    222228 
    223 //--------------------------------------------------------------------------- 
     229//------------------------------------------------------------------------- 
    224230//      Contract a given pair 
    225 //--------------------------------------------------------------------------- 
     231//------------------------------------------------------------------------- 
    226232void SimplificationMethod::do_contract( simplif::Model& m, 
    227233                                                                                                                                                                simplif::pair_info *auxpair) 
    228234{ 
    229         simplif::Vertex *v0                                     = auxpair->v0; 
    230         simplif::Vertex *v1                                     = auxpair->v1; 
    231         simplif::vert_info& v0_info = vertex_info(v0); 
    232         simplif::vert_info& v1_info = vertex_info(v1); 
    233         simplif::Vec3 vnew                                      = auxpair->candidate; 
    234  
    235         int i; 
     235        simplif::Vertex                 *v0                     = auxpair->v0; 
     236        simplif::Vertex                 *v1                     = auxpair->v1; 
     237        simplif::Vec3                   vnew            = auxpair->candidate; 
     238        float                                                           x,y,z; 
     239        simplif::Vertex                 *aux_vert; 
     240 
     241        _float3_                                                removed_vert; 
     242        int                                                                     i; 
     243        vertex_map_str                  lb; 
     244        vertex_map_str                  ub; 
    236245         
    237246        // V0 must be always the alive vertex 
     
    239248        if (vnew == (*v0)) 
    240249        { 
     250                //      Coords of the removed vertex. 
     251                x       =       (*v1)[X]; 
     252                y       =       (*v1)[Y]; 
     253                z       =       (*v1)[Z]; 
     254 
     255                aux_vert        =       v1; 
     256        } 
     257        else 
     258        { 
     259                //      Coords of the removed vertex. 
     260                x       =       (*v0)[X]; 
     261                y       =       (*v0)[Y]; 
     262                z       =       (*v0)[Z]; 
     263 
    241264                //      Simplification step. 
    242                 simplifstep.mV0 = v0->vID; 
    243                 simplifstep.mV1 = v1->vID; 
    244         } 
    245         else 
    246         { 
    247                 //      Simplification step. 
    248                 simplifstep.mV0 = v1->vID; 
    249                 simplifstep.mV1 = v0->vID; 
    250                 v0->vID = v1->vID; 
    251         } 
    252  
    253         // Make v0 be the new vertex 
    254         v0_info.Q               += v1_info.Q; 
     265                aux_vert        =       v0; 
     266                v0      =       v1; 
     267                v1      =       aux_vert; 
     268        } 
     269 
     270        simplif::vert_info&     v0_info = vertex_info(v0); 
     271        simplif::vert_info&     v1_info = vertex_info(v1); 
     272 
     273        //      Simplification step. 
     274        simplifstep.mV0 = v0->vID; 
     275        simplifstep.mV1 = v1->vID; 
     276 
     277        //      Position of the vertex removed. 
     278        removed_vert    =       _float3_(x,y,z); 
     279 
     280        //      If position of the removed vertex is found. 
     281        if (vertexMultimap.end() != vertexMultimap.find(removed_vert)) 
     282        { 
     283                lb      =       vertexMultimap.lower_bound(removed_vert); 
     284                ub      =       vertexMultimap.upper_bound(removed_vert); 
     285 
     286                //      For each vertex. 
     287                while   (lb != ub) 
     288                { 
     289                        //      If removed vertex is found. 
     290                        if ((*lb).second == aux_vert->vID) 
     291                        { 
     292                                //      Debug. 
     293                                cout    <<      "to remove: " 
     294                                                        <<      (*lb).second 
     295                                                        <<      endl; 
     296 
     297                                //      Delete vertex that disappears. 
     298                                vertexMultimap.erase(lb); 
     299                                 
     300                                //      Break while. 
     301                                lb      =       ub; 
     302                        } 
     303                        else 
     304                        { 
     305                                //      Next iteration. 
     306                                lb++; 
     307                        } 
     308                } 
     309        } 
     310 
     311        //      Make v0 be the new vertex 
     312        v0_info.Q                       += v1_info.Q; 
    255313        v0_info.norm    += v1_info.norm; 
    256314 
    257315        simplif::Vec3 p(vnew); 
    258 /*      simplif::Vec3 v0antes(v0->operator[](simplif::X), 
    259                                                   v0->operator[](simplif::Y), 
    260                                                   v0->operator[](simplif::Z));*/ 
    261316 
    262317        //      Perform the actual contraction. 
     
    265320        changed.reset(); 
    266321        m.contract(v0, v1, vnew, changed); 
    267  
    268         std::cout << "Simp seq: " << simplifstep.mV1 << " --> " << simplifstep.mV0 << std::endl; 
    269  
    270 /*      simplif::Vec3 vdesp = p - v0antes; 
    271  
    272         //      Stores the displacement in the simplification step. 
    273         simplifstep.x   =       (float)vdesp[X]; 
    274         simplifstep.y = (float)vdesp[Y]; 
    275         simplifstep.z = (float)vdesp[Z];*/ 
    276322 
    277323        //      Stores the displacement in the simplification step. 
     
    360406        condemned.reset(); 
    361407 
     408        //      Recalculate pairs associated with v1. 
    362409        for (i  =       0;      i < v1_info.pairs.length(); i++) 
    363410        { 
     
    366413                simplif::Vertex *u; 
    367414 
    368                 if( p->v0 == v1 ) 
     415                if ( p->v0 == v1 ) 
    369416                { 
    370417                        u = p->v1; 
     
    372419                else 
    373420                { 
    374                         if( p->v1 == v1) 
     421                        if ( p->v1 == v1) 
    375422                        { 
    376423                                u = p->v0; 
     
    406453} 
    407454 
    408 //--------------------------------------------------------------------------- 
    409 //--------------------------------------------------------------------------- 
     455//------------------------------------------------------------------------- 
     456//------------------------------------------------------------------------- 
    410457bool SimplificationMethod::decimate_quadric(simplif::Vertex *v, 
    411458                                                                                                                                                                                simplif::Mat4& Q) 
     
    422469} 
    423470 
    424 //--------------------------------------------------------------------------- 
    425 //      Extract a pair from the heap, concract it and remove it form the heap 
    426 //--------------------------------------------------------------------------- 
     471//------------------------------------------------------------------------- 
     472//      Extract a pair from the heap, concract it and remove it from the heap. 
     473//------------------------------------------------------------------------- 
    427474void SimplificationMethod::decimate_contract(simplif::Model& m) 
    428475{ 
    429476        simplif::heap_node      *top; 
    430477        simplif::pair_info      *pair; 
    431         simplif::Vertex         *v0; 
    432         simplif::Vertex         *v1; 
    433         simplif::Vec3           candidate; 
     478        simplif::Vertex                 *v0; 
     479        simplif::Vertex                 *v1; 
     480        simplif::Vec3                           candidate; 
     481        _float3_                                                f0; 
     482        _float3_                                                f1; 
    434483 
    435484        for (;;) 
     
    460509                } 
    461510 
    462                 if (pair->isValid() && sharededge) 
     511                //      Coordinates of the pair. 
     512                f0      =       _float3_((*pair->v0)[X],(*pair->v0)[Y],(*pair->v0)[Z]); 
     513                f1      =       _float3_((*pair->v1)[X],(*pair->v1)[Y],(*pair->v1)[Z]); 
     514 
     515                if (pair->isValid() 
     516                                && 
     517                                sharededge 
     518                                && 
     519                                (vertexMultimap.find(f0) != vertexMultimap.end()) 
     520                                && 
     521                                (vertexMultimap.find(f1) != vertexMultimap.end())) 
    463522                { 
    464523                        break; 
    465524                } 
     525 
     526                //      Debug. 
     527                cout    <<      "Deleting pair (" 
     528                                        <<      pair->v0->vID 
     529                                        <<      "--" 
     530                                        <<      pair->v1->vID 
     531                                        <<      ")" 
     532                                        <<      endl; 
    466533 
    467534                //      Deletes repetitions of pair in heap. 
     
    470537 
    471538        //      Copy pair. 
     539<<<<<<< .mine 
     540        v0      =       new Vertex(     (*pair->v0)[X], 
     541                                                                                (*pair->v0)[Y], 
     542                                                                                (*pair->v0)[Z]); 
     543 
     544        v0->vID = pair->v0->vID; 
     545======= 
    472546        v0      =       new Vertex(     pair->v0->operator[](0), 
    473547                                                                                pair->v0->operator[](1), 
     
    475549        v0->vID = pair->v0->vID; 
    476550        v0->uniqID = pair->v0->uniqID; 
     551>>>>>>> .r2086 
    477552         
    478         v1      =       new Vertex(     pair->v1->operator[](0), 
    479                                                                                 pair->v1->operator[](1), 
    480                                                                                 pair->v1->operator[](2)); 
     553        v1      =       new Vertex(     (*pair->v1)[X], 
     554                                                                                (*pair->v1)[Y], 
     555                                                                                (*pair->v1)[Z]); 
    481556        v1->vID = pair->v1->vID; 
    482         v1->uniqID = pair->v1->uniqID; 
     557        v1->vID = pair->v1->vID; 
    483558 
    484559        candidate       =       pair->candidate; 
     
    488563 
    489564        //      Debug. 
    490         cout    <<      "Contracting..."        <<      endl; 
     565        cout    <<      "Contracting... " 
     566                                <<      endl; 
    491567 
    492568        //      Contract main pair. 
     
    499575        M0.validVertCount--; 
    500576 
    501         //      Find an edge of the same coordinates and different vertex identifiers. 
    502         removeTwinEdges(m,v0,v1,candidate); 
    503  
    504         //      Move vertex of non twin edges. 
    505         contractLonelyVertices(m,v0,v1,candidate); 
     577        //      Find twin vertices to the contracted one and contract them. 
     578        removeTwinVertices(m,v0,v1,candidate); 
    506579 
    507580        //      Free Memory. 
     
    510583} 
    511584 
    512 //--------------------------------------------------------------------------- 
    513 //      Contract lonely vertex that has the same coords that the contracted one. 
    514 //--------------------------------------------------------------------------- 
    515 void    SimplificationMethod::contractLonelyVertices(   simplif::Model  &m,     simplif::Vertex *v0, 
    516                                                                                                                                                         simplif::Vertex *v1, 
    517                                                                                                                                                         simplif::Vec3   candidate) 
    518 { 
    519         bool                            lonely_vertex_found; 
    520         simplif::Vertex         *vert; 
    521         simplif::Vertex         *new_vert; 
    522         simplif::Vertex         *lonely_vert; 
    523         simplif::Edge           *edge; 
    524         simplif::heap_node      *top; 
     585//------------------------------------------------------------------------- 
     586//      Find twin vertices to the contracted one and contract them. 
     587//------------------------------------------------------------------------- 
     588void SimplificationMethod::removeTwinVertices(simplif::Model    &m, 
     589                                                                                                                                                                                        simplif::Vertex *v0, 
     590                                                                                                                                                                                        simplif::Vertex *v1, 
     591                                                                                                                                                                                        simplif::Vec3           candidate) 
     592{ 
     593        bool                                                            twin_found; 
     594        simplif::Edge                           *edge; 
    525595        simplif::pair_info      *pair; 
     596        simplif::Vertex                 *vert; 
     597        simplif::Vertex                 *lonely_vert; 
     598        simplif::Vertex                 *new_vert; 
     599        vertex_map_str                  lb; 
     600        vertex_map_str                  ub; 
     601        vertex_map_str                  it; 
     602        _float3_                                                f0; 
     603        _float3_                                                f1; 
     604        simplif::Edge                           *econ; 
    526605        simplif::vert_info      new_vert_info; 
    527606        Geometry::GeoVertex     vertex_added; 
    528         simplif::Vertex         *take_bone_from_vert; 
    529  
    530         //      Gets the vertex that is not the candidate. 
    531         if ((*v0) == candidate) 
    532         { 
    533                 vert = v1; 
     607        simplif::Vertex                 *take_bone_from_vert; 
     608        float                                                           x,y,z; 
     609 
     610        if ((*v0) != (*v1)) 
     611        { 
     612                //      Gets the vertex that is not the candidate. 
     613                if ((*v1) == candidate) 
     614                { 
     615                        vert                                                            = v0; 
     616                        v0                                                                      =       v1; 
     617                        v1                                                                      =       vert; 
     618                } 
     619 
    534620                take_bone_from_vert = v0; 
    535         } 
    536         else if ((*v1) == candidate) 
    537         { 
    538                 vert = v0; 
    539                 take_bone_from_vert = v1; 
    540         } 
    541  
    542         //      For all vertex. 
    543         for (int        i = 0; i < heap->getSize();     i++) 
    544         { 
    545                 //      Initialize lonely vertex flag. 
    546                 lonely_vertex_found     =       false; 
    547  
    548                 //      Gets the current pair. 
    549                 top             =       heap->getElement(i); 
    550                 pair    =       (simplif::pair_info *)top->obj; 
    551  
    552                 if (pair->v0->isValid() && (*vert) == (*pair->v0)) 
    553                 { 
    554                         lonely_vert     =       pair->v0; 
    555                         lonely_vertex_found     =       true; 
    556                 } 
    557                 else if (pair->v1->isValid() && (*vert) == (*pair->v1)) 
    558                 { 
    559                         lonely_vert     =       pair->v1; 
    560                         lonely_vertex_found     =       true; 
    561                 } 
    562  
    563                 //      If a lonely vertex is found. Creates new vertex and contract. 
    564                 if (lonely_vertex_found) 
    565                 { 
    566                         new_vert        =       m.newVertex(candidate[X],candidate[Y],candidate[Z]);     
    567                         edge            =       m.newEdge(new_vert,lonely_vert); 
    568  
    569             // We assume here the there are the same number of vertices and texture coordinates and normals 
    570  
    571                         // assign a texture coordinate for the vbertex 
    572                         simplif::Vec2 newtexcoord = m.texcoord(lonely_vert->validID()); 
    573                         m.in_TexCoord(newtexcoord); 
    574  
    575                         // assign a normal coordinate for the vbertex 
    576                         simplif::Vec3 newnormal = m.normal(lonely_vert->validID()); 
    577                         m.in_Normal(newnormal); 
    578  
    579                         //      Adds new vertex information to simplification sequence. 
    580                         vertex_added.id                 =       new_vert->vID; 
    581                         vertex_added.bonefrom   =       take_bone_from_vert->vID; 
    582                         vertex_added.position   =       Vector3(candidate[X],candidate[Y],candidate[Z]); 
    583  
    584                         simplif::Vec2 tc = m.texcoord(new_vert->validID()); 
    585                         vertex_added.texcoord   =       Vector2(tc[X],tc[Y]); 
    586  
    587                         simplif::Vec3 vn = m.normal(new_vert->validID()); 
    588                         vertex_added.normal             =       Vector3(vn[X],vn[Y],vn[Z]); 
    589  
    590                         msimpseq->mNewVertices.push_back(vertex_added); 
    591  
    592                         pair                    =       new_pair(new_vert,lonely_vert); 
    593                         pair->candidate =       candidate; 
    594  
    595                         pair->notInHeap(); 
    596 /*                      vinfo(new_vert->validID()).Q            =       vinfo(lonely_vert->validID()).Q; 
    597                         vinfo(new_vert->validID()).norm =       vinfo(lonely_vert->validID()).norm;*/ 
    598  
    599                         //      Debug. 
    600                         cout    <<      "Contracting new pair..."       <<      endl; 
    601  
    602                         //      Contract twin pair. 
    603                         do_contract(m, pair); 
    604                         M0.validVertCount--; 
    605                 } 
    606         } 
    607 } 
    608  
    609 //--------------------------------------------------------------------------- 
    610 //      Find a twin edge of the given one. 
    611 //--------------------------------------------------------------------------- 
    612 void SimplificationMethod::removeTwinEdges(     simplif::Model  &m, 
    613                                                                                                                                                                                 simplif::Vertex *v0, 
    614                                                                                                                                                                                 simplif::Vertex *v1, 
    615                                                                                                                                                                                 simplif::Vec3           candidate) 
    616 { 
    617         bool                                                            twin_found; 
    618         simplif::heap_node      *top; 
    619         simplif::pair_info      *pair; 
    620         simplif::Vertex                 *aux_vert; 
    621  
    622         //      Find a twin edge in heap. 
    623         for (int        i       =       0;      i < heap->getSize(); i++) 
    624         { 
    625                 //      Initialize twin flag. 
    626                 twin_found      =       false; 
    627  
    628                 //      Gets the current pair. 
    629                 top             =       heap->getElement(i); 
    630                 pair    =       (simplif::pair_info *)top->obj; 
    631  
    632                 if (pair->v0->isValid()==false || pair->v1->isValid()==false) 
    633                         continue;  
    634  
    635                 if (v0->operator[](0) == pair->v0->operator[](0) 
    636                                 && 
    637                                 v0->operator[](1) == pair->v0->operator[](1) 
    638                                 && 
    639                                 v0->operator[](2) == pair->v0->operator[](2)) 
    640                 { 
    641                         if (v1->operator[](0) == pair->v1->operator[](0) 
    642                                         && 
    643                                         v1->operator[](1) == pair->v1->operator[](1) 
    644                                         && 
    645                                         v1->operator[](2) == pair->v1->operator[](2)) 
     621 
     622                f0      =       _float3_((*v0)[X],(*v0)[Y],(*v0)[Z]); 
     623                f1      =       _float3_((*v1)[X],(*v1)[Y],(*v1)[Z]); 
     624 
     625                while ((it = vertexMultimap.find(f1)) != vertexMultimap.end()) 
     626                { 
     627                        twin_found      =       false; 
     628 
     629                        lonely_vert     =       m.vertex((*it).second); 
     630 
     631                        for (int        i       =       0;      i < lonely_vert->edgeUses().length();   i++) 
     632                        { 
     633                                econ    =       lonely_vert->edgeUses()(i); 
     634 
     635                                if (((*econ->org()) == (*v0)) 
     636                                                || 
     637                                                ((*econ->dest()) == (*v0))) 
     638                                { 
     639                                        lb      =       vertexMultimap.lower_bound(f0); 
     640                                        ub      =       vertexMultimap.upper_bound(f0); 
     641 
     642                                        //      For each vertex. 
     643                                        while   (lb != ub) 
     644                                        { 
     645                                                //      If removed vertex is found. 
     646                                                if (((*lb).second == econ->org()->vID) 
     647                                                                || 
     648                                                                ((*lb).second == econ->dest()->vID)) 
     649                                                { 
     650                                                        twin_found      =       true; 
     651 
     652                                                        //      Break while. 
     653                                                        lb      =       ub; 
     654                                                } 
     655                                                else 
     656                                                { 
     657                                                        //      Next iteration. 
     658                                                        lb++; 
     659                                                } 
     660                                        } 
     661 
     662                                        break; 
     663                                } 
     664                        } 
     665 
     666                        //      If a twin edge has been found. 
     667                        if (twin_found) 
    646668                        { 
    647669                                //      Debug. 
    648                                 cout    <<      "Twin contracted (NO Swap)..."  <<      endl; 
    649  
    650                                 //      Active twin flag. 
    651                                 twin_found      = true; 
    652                         } 
    653                 } 
    654                 else 
    655                 { 
    656                         //      If there is a twin edge in reverse order. 
    657                         if (v0->operator[](0) == pair->v1->operator[](0) 
    658                                         && 
    659                                         v0->operator[](1) == pair->v1->operator[](1) 
    660                                         && 
    661                                         v0->operator[](2) == pair->v1->operator[](2)) 
    662                         { 
    663                                 if (v1->operator[](0) == pair->v0->operator[](0) 
    664                                                 && 
    665                                                 v1->operator[](1) == pair->v0->operator[](1) 
    666                                                 && 
    667                                                 v1->operator[](2) == pair->v0->operator[](2)) 
    668                                 { 
    669                                         //      Debug. 
    670                                         cout    <<      "Twin contracted (Swap)..."     <<      endl; 
    671  
    672                                         //      Swap. 
    673                                         aux_vert        =       pair->v0; 
    674                                         pair->v0        =       pair->v1; 
    675                                         pair->v1        =       aux_vert; 
    676  
    677                                         //      Active twin flag. 
    678                                         twin_found      =       true; 
    679                                 } 
    680                         } 
    681                 } 
    682  
     670                                cout    <<      "Twin Contracted..."    <<      endl; 
     671 
     672                                //      Extract twin edge from heap. 
     673                                pair    =       new_pair(econ->org(),econ->dest()); 
     674 
     675                                //      Copy candidate. 
     676                                pair->candidate =       candidate; 
     677 
     678                                pair->notInHeap(); 
     679 
     680                                //      Contract twin pair. 
     681                                do_contract(m, pair); 
     682                                M0.validVertCount--; 
     683                        } 
     684                        else 
     685                        { 
     686                                //      Debug. 
     687                                cout    <<      "Contracting new pair..."       <<      endl; 
     688 
     689                                new_vert        =       m.newVertex(candidate[X],candidate[Y],candidate[Z]); 
     690 
     691                                //      Add new vert to multimap. 
     692                                x       =       (*new_vert)[X]; 
     693                                y       =       (*new_vert)[Y]; 
     694                                z       =       (*new_vert)[Z]; 
     695 
     696                                //      Adds new vertex to multimap. 
     697                                vertexMultimap.insert(vertex_pair(_float3_(x,y,z),new_vert->vID)); 
     698 
     699                                //      Creates new edge. 
     700                                edge    =       m.newEdge(new_vert,lonely_vert); 
     701 
     702                                //      We assume here there are the same number of vertices 
     703                                //      and texture coordinates and normals. 
     704 
     705                                // Assign a texture coordinate for the vertex. 
     706                                simplif::Vec2 newtexcoord = m.texcoord(lonely_vert->vID); 
     707                                m.in_TexCoord(newtexcoord); 
     708 
     709                                //      Assign a normal coordinate for the vbertex. 
     710                                simplif::Vec3 newnormal = m.normal(lonely_vert->vID); 
     711                                m.in_Normal(newnormal); 
     712 
     713                                //      Adds new vertex information to simplification sequence. 
     714                                vertex_added.id                         =       new_vert->vID; 
     715 
     716                                vertex_added.bonefrom   =       take_bone_from_vert->vID; 
     717 
     718<<<<<<< .mine 
     719                                vertex_added.position   =       Vector3(candidate[X], 
     720                                                                                                                                                                candidate[Y], 
     721                                                                                                                                                                candidate[Z]); 
     722======= 
    683723                //      If a twin edge has been found. 
    684724                if (twin_found) 
    685725                { 
    686726                        heap->kill(i); 
    687  
    688                         //      Copy candidate. 
    689                         pair->candidate =       candidate; 
    690  
    691                         //      Contract twin pair. 
    692                         do_contract(m, pair); 
    693                         i--; 
    694                         M0.validVertCount--; 
    695                 } 
    696         } 
    697 } 
    698  
    699 //--------------------------------------------------------------------------- 
    700 //--------------------------------------------------------------------------- 
     727>>>>>>> .r2086 
     728 
     729                                simplif::Vec2 tc                        = m.texcoord(new_vert->vID); 
     730                                vertex_added.texcoord   =       Vector2(tc[X],tc[Y]); 
     731 
     732                                simplif::Vec3 vn                = m.normal(new_vert->vID); 
     733                                vertex_added.normal     =       Vector3(vn[X],vn[Y],vn[Z]); 
     734 
     735                                msimpseq->mNewVertices.push_back(vertex_added); 
     736 
     737                                pair                                            =       new_pair(new_vert,lonely_vert); 
     738                                pair->candidate =       candidate; 
     739                                pair->notInHeap(); 
     740 
     741                                //      Contract new pair. 
     742                                do_contract(m, pair); 
     743                                M0.validVertCount--; 
     744                        } 
     745                } 
     746        } 
     747} 
     748 
     749//------------------------------------------------------------------------- 
     750//------------------------------------------------------------------------- 
    701751simplif::real SimplificationMethod::decimate_error(simplif::Vertex *v) 
    702752{ 
     
    705755        simplif::real err = simplif::quadrix_evaluate_vertex(*v, info.Q); 
    706756 
    707     if( simplif::will_weight_by_area ) 
     757    if ( simplif::will_weight_by_area ) 
    708758                { 
    709759                        err /= info.norm; 
     
    713763} 
    714764 
    715 //--------------------------------------------------------------------------- 
     765//------------------------------------------------------------------------- 
    716766//      Extract the minimum cost of the the valid nodes (not simplified) 
    717 //--------------------------------------------------------------------------- 
     767//------------------------------------------------------------------------- 
    718768simplif::real SimplificationMethod::decimate_min_error() 
    719769{ 
     
    744794} 
    745795 
    746 //--------------------------------------------------------------------------- 
     796//------------------------------------------------------------------------- 
    747797//      Returns the maximum error by vertex 
    748 //--------------------------------------------------------------------------- 
     798//------------------------------------------------------------------------- 
    749799simplif::real SimplificationMethod::decimate_max_error(simplif::Model& m) 
    750800{ 
     
    760810} 
    761811 
    762 //--------------------------------------------------------------------------- 
     812//------------------------------------------------------------------------- 
    763813//      Initializations 
    764 //--------------------------------------------------------------------------- 
    765 void SimplificationMethod::decimate_init(simplif::Model& m, simplif::real limit) 
     814//------------------------------------------------------------------------- 
     815void SimplificationMethod::decimate_init(       simplif::Model  &m, 
     816                                                                                                                                                                        simplif::real   limit) 
    766817{ 
    767818        int i,j; 
     
    783834                } 
    784835        } 
    785  
    786         //      Sets the fill value of the vinfo buffer. 
    787         //vinfo.setFill(m.vertCount()); 
    788836 
    789837        //      For each face, recalculate constraints. 
     
    849897                        simplif::pair_info *pair = new_pair(m.edge(i)->org(), m.edge(i)->dest()); 
    850898                        //pointers_to_remove.push_back(pair); 
     899 
    851900                        compute_pair_info(pair); 
    852901                        pair_count++; 
     
    901950} 
    902951 
    903 //--------------------------------------------------------------------------- 
     952//------------------------------------------------------------------------- 
    904953//      Initilizations 
    905 //--------------------------------------------------------------------------- 
     954//------------------------------------------------------------------------- 
    906955void SimplificationMethod::simplifmethod_init(void) 
    907956{ 
     
    936985} 
    937986 
    938 //--------------------------------------------------------------------------- 
     987//------------------------------------------------------------------------- 
    939988//      Do the contractions till the required LOD (percentage option) 
    940 //--------------------------------------------------------------------------- 
     989//------------------------------------------------------------------------- 
    941990void SimplificationMethod::simplifmethod_run(int finalfaces,TIPOFUNC upb) 
    942991{ 
     
    9891038} 
    9901039 
    991 //--------------------------------------------------------------------------- 
     1040//------------------------------------------------------------------------- 
    9921041//      Do the contractions till the required LOD (number of vertices option) 
    993 //--------------------------------------------------------------------------- 
     1042//------------------------------------------------------------------------- 
    9941043void SimplificationMethod::simplifmethod_runv(int numvertices,TIPOFUNC upb) 
    9951044{ 
     
    10511100} 
    10521101 
    1053 //--------------------------------------------------------------------------- 
    1054 // Class to create a map without repeated vertices 
    1055 //--------------------------------------------------------------------------- 
    1056 class _float3_ 
    1057 { 
    1058         public: 
    1059  
    1060                 float x,y,z; 
    1061  
    1062                 _float3_(float x=0.0f, float y=0.0f, float z=0.0f) 
    1063                 { 
    1064                         this->x = x; this->y = y; this->z = z; 
    1065                 } 
    1066  
    1067                 _float3_(const _float3_ &f) 
    1068                 { 
    1069                         x=f.x; y=f.y; z=f.z; 
    1070                 } 
    1071  
    1072                 _float3_ & operator=(const _float3_ &f) 
    1073                 { 
    1074                         x=f.x; y=f.y; z=f.z; return *this; 
    1075                 } 
    1076  
    1077                 bool operator<(const _float3_ &f) const  
    1078                 {  
    1079                         if (x<f.x) return true; 
    1080                         if (x>f.x) return false; 
    1081                         if (y<f.y) return true; 
    1082                         if (y>f.y) return false; 
    1083                         if (z<f.z) return true; 
    1084                         if (z>f.z) return false; 
    1085                         return false; 
    1086                 } 
    1087 }; 
    1088  
    1089 //--------------------------------------------------------------------------- 
     1102//------------------------------------------------------------------------- 
    10901103//      Generate simplification model. 
    1091 //--------------------------------------------------------------------------- 
     1104//------------------------------------------------------------------------- 
    10921105void    SimplificationMethod::generateSimplifModel(void) 
    10931106{ 
    1094         int     face_index      =       0; 
     1107        int             face_index      =       0; 
     1108        int             vertID; 
     1109        float   x,y,z; 
    10951110 
    10961111        //      For each submesh. 
    10971112        bool added_vertices = false; 
    1098         for (size_t     i =     0;      i       <       objmesh->mSubMeshCount; i++) 
     1113        for (size_t     i =     0;      i       <       mInitialMesh->mSubMeshCount;    i++) 
    10991114        { 
    11001115                //      If is not a tree leaves submesh. 
     
    11031118                        //      For all the vertices of each submesh. 
    11041119                        for (   size_t  j       =       0; 
    1105                                         j < objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
     1120                                        j < mInitialMesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
    11061121                                        j++) 
    11071122                        { 
     1123                                x       =       mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 
     1124                                y       =       mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 
     1125                                z       =       mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 
     1126 
    11081127                                //      If the vertex is not in vertices_map, then is added. 
    1109                                 M0.in_Vertex(simplif::Vec3( 
    1110                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 
    1111                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
    1112                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
     1128                                vertID  =       M0.in_Vertex(simplif::Vec3( 
     1129                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x, 
     1130                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y, 
     1131                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z)); 
    11131132 
    11141133                                M0.in_Normal(simplif::Vec3( 
    1115                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 
    1116                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
    1117                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
     1134                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x, 
     1135                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y, 
     1136                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z)); 
    11181137 
    11191138                                M0.in_TexCoord(simplif::Vec2( 
    1120                                                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x, 
    1121                                                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
     1139                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x, 
     1140                                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y)); 
    11221141 
    11231142                                added_vertices = true; 
    1124                         } 
    1125                 }        
    1126                  
     1143 
     1144                                //      Add vertex to multimap. 
     1145                                vertexMultimap.insert(vertex_pair(_float3_(x,y,z),vertID)); 
     1146                        } 
     1147                } 
     1148 
    11271149                //      If is shared vertex buffer object. 
    1128                 if (objmesh->mSubMesh[i].mSharedVertexBuffer && added_vertices) 
     1150                if (mInitialMesh->mSubMesh[i].mSharedVertexBuffer && added_vertices) 
    11291151                { 
    11301152                        printf("Shared break"); 
     
    11341156 
    11351157        //      For each submesh. 
    1136         for (size_t     i = 0;  i < objmesh->mSubMeshCount;     i++) 
     1158        for (size_t     i = 0;  i < mInitialMesh->mSubMeshCount;        i++) 
    11371159        { 
    11381160                if (i != indexMeshLeaves) 
    11391161                { 
    1140                         for (Index      j       =       0;      j < objmesh->mSubMesh[i].mIndexCount;   j       +=      3) 
     1162                        for (   Geometry::Index j       =       0; 
     1163                                                j < mInitialMesh->mSubMesh[i].mIndexCount; 
     1164                                                j       +=      3) 
    11411165                        { 
    11421166                                //      +1 is required because the first index in the 
    11431167                                //      simplification method is 1 
    11441168                                //      Index of the vertex in vertices_map. 
    1145                                 Index index0    =               objmesh->mSubMesh[i].mIndex[j]; 
     1169                                Geometry::Index index0  =               mInitialMesh->mSubMesh[i].mIndex[j]; 
    11461170                                 
    1147                                 Index index1    =               objmesh->mSubMesh[i].mIndex[j + 1]; 
     1171                                Geometry::Index index1  =               mInitialMesh->mSubMesh[i].mIndex[j + 1]; 
    11481172                                 
    1149                                 Index index2    =               objmesh->mSubMesh[i].mIndex[j + 2]; 
     1173                                Geometry::Index index2  =               mInitialMesh->mSubMesh[i].mIndex[j + 2]; 
    11501174                                 
    11511175                                //      Create a triangle with its indices in vertices_map. 
     
    11631187} 
    11641188 
    1165 //--------------------------------------------------------------------------- 
     1189//------------------------------------------------------------------------- 
    11661190//      simplifmethod_init is executed to do some initalizations 
    11671191//      simplifmethod_run is executed to do the decimation 
    11681192//      Then, the simpified model is created and the decimation  
    11691193//      information is returned. 
    1170 //--------------------------------------------------------------------------- 
     1194//------------------------------------------------------------------------- 
    11711195MeshSimplificationSequence *SimplificationMethod::Decimate(     float lod, 
    11721196                                                                                                                                                                                                                                                int simpliftype, 
    11731197                                                                                                                                                                                                                                                TIPOFUNC upb) 
    11741198{ 
     1199        bool                                                                                            shared_vertex; 
     1200        unsigned        int                                                             vertex_count; 
     1201        std::map<int,int>::iterator     findit; 
     1202        //      Initialize      vertex count. 
     1203        vertex_count    =       0; 
     1204 
     1205        //      Initialize shared vertex buffer flag. 
     1206        shared_vertex   =       false; 
     1207 
     1208        //      Determines if the mesh have shared vertex buffer. 
     1209        for (int i = 0; i < mInitialMesh->mSubMeshCount;        i++) 
     1210        { 
     1211                if (mInitialMesh->mSubMesh[i].mSharedVertexBuffer) 
     1212                { 
     1213                        shared_vertex   =       true; 
     1214                        break; 
     1215                } 
     1216        } 
     1217 
    11751218        simplifmethod_init(); 
    11761219 
     
    11861229        } 
    11871230 
    1188         //      Store unique vertices by submesh (without repetitions). 
    1189         typedef std::map<int,int> MAPAINDIND; 
    1190  
    1191         //      Store all the indices by submesh (with repetitions). 
    1192         typedef std::vector<int> REPINDLIST; 
    1193  
    11941231        MAPAINDIND *unique_verts_inds_by_geo = 
    1195                                                                                                                 new MAPAINDIND[objmesh->mSubMeshCount]; 
    1196  
    1197         REPINDLIST *ver_inds_rep_by_geo = new REPINDLIST[objmesh->mSubMeshCount]; 
     1232                new MAPAINDIND[mInitialMesh->mSubMeshCount]; 
     1233 
     1234        MAPAINDIND      shared_vertex_map; 
     1235 
     1236        REPINDLIST *ver_inds_rep_by_geo = new REPINDLIST[mInitialMesh->mSubMeshCount]; 
    11981237 
    11991238        //      Index counter by submesh. 
    1200         int *inextvert = new int[objmesh->mSubMeshCount]; 
    1201  
    1202         for (unsigned int       i = 0;  i < objmesh->mSubMeshCount;     i++) 
     1239        int *inextvert = new int[mInitialMesh->mSubMeshCount]; 
     1240 
     1241        for (unsigned int       i = 0;  i < mInitialMesh->mSubMeshCount;        i++) 
    12031242        { 
    12041243                inextvert[i] = 0; 
     
    12071246        //      Construct the model. 
    12081247        std::cout << "M0.faceCount(): " << M0.faceCount() << std::endl; 
     1248 
     1249        //      For each face. 
    12091250        for (int        i = 0;  i < M0.faceCount();     i++) 
    12101251        { 
     
    12161257                        int igeo = auxface->igeo; 
    12171258 
    1218                         //      Insert to each submesh its triangles. 
    1219                         std::map<int,int>::iterator findit = 
    1220                                 unique_verts_inds_by_geo[igeo].find(auxface->vertex(0)->validID()); 
    1221                          
    1222                         if (findit == unique_verts_inds_by_geo[igeo].end()) 
    1223                         { 
    1224                                 //      If it is not added... add and map it. 
    1225                                 unique_verts_inds_by_geo[igeo][auxface->vertex(0)->validID()] = 
    1226                                                                                                                                                                                                                                                 inextvert[igeo]; 
    1227                                  
    1228                                 inextvert[igeo]++; 
    1229                         } 
    1230  
    1231                         findit = 
    1232                                 unique_verts_inds_by_geo[igeo].find(auxface->vertex(1)->validID()); 
    1233                          
    1234                         if (findit == unique_verts_inds_by_geo[igeo].end()) 
    1235                         { 
    1236                                 //      If it is not added... add and map it. 
    1237                                 unique_verts_inds_by_geo[igeo][auxface->vertex(1)->validID()] = 
    1238                                                                                                                                                                                                                                                 inextvert[igeo]; 
    1239                                 inextvert[igeo]++; 
    1240                         } 
    1241                          
    1242                         findit =  
    1243                                 unique_verts_inds_by_geo[igeo].find(auxface->vertex(2)->validID()); 
    1244                          
    1245                         if (findit == unique_verts_inds_by_geo[igeo].end()) 
    1246                         { 
    1247                                 //      If it is not added... add and map it. 
    1248                                 unique_verts_inds_by_geo[igeo][auxface->vertex(2)->validID()] =  
    1249                                                                                                                                                                                                                                                 inextvert[igeo]; 
    1250                                 inextvert[igeo]++; 
    1251                         } 
    1252  
    1253                         //      Total number of indices by submesh. 
    1254                         ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(0)->validID()); 
    1255                         ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(1)->validID()); 
    1256                         ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(2)->validID()); 
     1259                        //      For each index of the face. 
     1260                        for (size_t     j = 0; j < 3; j++) 
     1261                        { 
     1262                                if (shared_vertex) 
     1263                                { 
     1264                                        //      Insert to each submesh its triangles. 
     1265                                        findit =        shared_vertex_map.find(auxface->vertex(j)->vID); 
     1266 
     1267                                        if (findit == shared_vertex_map.end()) 
     1268                                        { 
     1269                                                //      If it is not added... add and map it. 
     1270                                                shared_vertex_map[auxface->vertex(j)->vID] =    vertex_count; 
     1271 
     1272                                                vertex_count++; 
     1273                                        } 
     1274                                } 
     1275                                else 
     1276                                { 
     1277                                        //      Insert to each submesh its triangles. 
     1278                                        findit =        unique_verts_inds_by_geo[igeo]. 
     1279                                                find(auxface->vertex(j)->vID); 
     1280 
     1281                                        if (findit == unique_verts_inds_by_geo[igeo].end()) 
     1282                                        { 
     1283                                                //      If it is not added... add and map it. 
     1284                                                unique_verts_inds_by_geo[igeo][auxface->vertex(j)->vID] = 
     1285                                                        inextvert[igeo]; 
     1286 
     1287                                                inextvert[igeo]++; 
     1288                                        } 
     1289                                } 
     1290 
     1291                                //      Total number of indices by submesh. 
     1292                                ver_inds_rep_by_geo[igeo].push_back(auxface->vertex(j)->vID); 
     1293                        } 
    12571294                } 
    12581295        } 
     
    12621299        mGeoMesh->mVertexBuffer =       new     VertexBuffer(); 
    12631300 
    1264         mGeoMesh->mSubMeshCount = objmesh->mSubMeshCount; 
     1301        mGeoMesh->mSubMeshCount = mInitialMesh->mSubMeshCount; 
    12651302 
    12661303        //      Memory allocation for the submeshes. 
    1267         mGeoMesh->mSubMesh = new SubMesh[objmesh->mSubMeshCount]; 
     1304        mGeoMesh->mSubMesh = new SubMesh[mInitialMesh->mSubMeshCount]; 
    12681305 
    12691306        //      Fill up bounding box settings. 
    1270         mGeoMesh->mMeshBounds.maxX                                      =       objmesh->mMeshBounds.maxX; 
    1271         mGeoMesh->mMeshBounds.maxY                                      =       objmesh->mMeshBounds.maxY; 
    1272         mGeoMesh->mMeshBounds.maxZ                                      =       objmesh->mMeshBounds.maxZ; 
    1273         mGeoMesh->mMeshBounds.minX                                      =       objmesh->mMeshBounds.minX; 
    1274         mGeoMesh->mMeshBounds.minY                                      =       objmesh->mMeshBounds.minY; 
    1275         mGeoMesh->mMeshBounds.minZ                                      =       objmesh->mMeshBounds.minZ; 
    1276         mGeoMesh->mMeshBounds.radius                            =       objmesh->mMeshBounds.radius; 
    1277         mGeoMesh->mMeshBounds.scaleFactor               =       objmesh->mMeshBounds.scaleFactor; 
     1307        mGeoMesh->mMeshBounds.maxX                                      =       mInitialMesh->mMeshBounds.maxX; 
     1308        mGeoMesh->mMeshBounds.maxY                                      =       mInitialMesh->mMeshBounds.maxY; 
     1309        mGeoMesh->mMeshBounds.maxZ                                      =       mInitialMesh->mMeshBounds.maxZ; 
     1310        mGeoMesh->mMeshBounds.minX                                      =       mInitialMesh->mMeshBounds.minX; 
     1311        mGeoMesh->mMeshBounds.minY                                      =       mInitialMesh->mMeshBounds.minY; 
     1312        mGeoMesh->mMeshBounds.minZ                                      =       mInitialMesh->mMeshBounds.minZ; 
     1313        mGeoMesh->mMeshBounds.radius                            =       mInitialMesh->mMeshBounds.radius; 
     1314        mGeoMesh->mMeshBounds.scaleFactor               =       mInitialMesh->mMeshBounds.scaleFactor; 
    12781315 
    12791316        //      Copy skeleton name. 
    1280         if (objmesh->hasSkeleton) 
     1317        if (mInitialMesh->hasSkeleton) 
    12811318        { 
    12821319                mGeoMesh->hasSkeleton   =       true; 
    12831320 
    1284                 strcpy(mGeoMesh->mSkeletonName,objmesh->mSkeletonName); 
    1285         } 
    1286  
    1287         //      Copy mesh bones. 
    1288         if (!objmesh->mBones.empty()) 
    1289         { 
    1290                 for (unsigned int j = 0; j < objmesh->mBones.size(); j++) 
    1291                 { 
    1292                         mGeoMesh->mBones.push_back(objmesh->mBones[j]); 
    1293                 } 
    1294         } 
    1295  
     1321                strcpy(mGeoMesh->mSkeletonName,mInitialMesh->mSkeletonName); 
     1322        } 
     1323 
     1324        //      If the mesh has shared vertex. 
     1325        if (shared_vertex) 
     1326        { 
     1327                fillUpSharedVertices(shared_vertex_map,ver_inds_rep_by_geo); 
     1328        } 
     1329        else 
     1330        { 
     1331                fillUpVertices(unique_verts_inds_by_geo,ver_inds_rep_by_geo); 
     1332        } 
     1333 
     1334        //------------------------// 
     1335        //      Bones reassignment.             // 
     1336        //------------------------// 
     1337        VertexBoneAssignment    bone; 
     1338        bool                                                                    vertex_found; 
     1339        MAPAINDIND::iterator    it; 
     1340 
     1341        addNewBoneAssignments(); 
     1342 
     1343        //      For each bone assignment. 
     1344        for (unsigned int i = 0; i < mInitialMesh->mBones.size(); i++) 
     1345        { 
     1346                bone.vertexIndex        =       mInitialMesh->mBones[i].vertexIndex; 
     1347                bone.boneIndex          =       mInitialMesh->mBones[i].boneIndex; 
     1348                bone.weight                             =       mInitialMesh->mBones[i].weight; 
     1349 
     1350                vertex_found    =       false; 
     1351 
     1352                //      If the vertex is found in the simplification model. 
     1353                if ((it = shared_vertex_map.find(bone.vertexIndex)) 
     1354                                != 
     1355                                shared_vertex_map.end()) 
     1356                { 
     1357                        bone.vertexIndex        =       (*it).second; 
     1358 
     1359                        mGeoMesh->mBones.push_back(bone); 
     1360                        vertex_found    =       true; 
     1361                } 
     1362        } 
     1363        //------------------------------------------------------------// 
     1364 
     1365        delete[] unique_verts_inds_by_geo; 
     1366        delete[] ver_inds_rep_by_geo; 
     1367        delete[] inextvert; 
     1368 
     1369        //      Store the simplification steps in MeshSimplificationSequence. 
     1370        int     acum    =       0; 
     1371 
     1372        for (size_t i   =       0; i < mInitialMesh->mSubMeshCount; i++) 
     1373        { 
     1374                if (mInitialMesh->mSubMesh[i].mSharedVertexBuffer) 
     1375                { 
     1376                        first_index_submesh[i]  =       0; 
     1377                } 
     1378                else 
     1379                { 
     1380                        first_index_submesh[i]  =       acum; 
     1381                } 
     1382 
     1383                acum    +=      (int)mInitialMesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
     1384        } 
     1385 
     1386        vector<int>     v0; 
     1387        vector<int>     v1; 
     1388        vector<int>     submesh0; 
     1389        vector<int>     submesh1; 
     1390 
     1391        return msimpseq; 
     1392} 
     1393 
     1394//------------------------------------------------------------------------- 
     1395//      Add bone assignments for new bones. 
     1396//------------------------------------------------------------------------- 
     1397void    SimplificationMethod::addNewBoneAssignments() 
     1398{ 
     1399        size_t  vertex_id; 
     1400        size_t  bones_count; 
     1401        VertexBoneAssignment bone; 
     1402        vector<VertexBoneAssignment>::iterator  it; 
     1403 
     1404        //      Copy new vertices. 
     1405        for (unsigned   int     i       =       0;      i < msimpseq->mNewVertices.size();      i++) 
     1406        { 
     1407                vertex_id       =       msimpseq->mNewVertices[i].id; 
     1408 
     1409                //      Initialize number of bones. 
     1410                bones_count     =       mInitialMesh->mBones.size(); 
     1411 
     1412                // check if my twin-vertex-bone has a bone assignment 
     1413                // we check only the GeoMesh bones because the lodstrips 
     1414                // only works for sharedvertex bones. 
     1415                for (int  j = 0; j < bones_count; j++) 
     1416                { 
     1417                        it      =       mInitialMesh->mBones.begin() + j; 
     1418 
     1419                        if (it->vertexIndex == msimpseq->mNewVertices[i].bonefrom) 
     1420                        { 
     1421                                bone.vertexIndex        = vertex_id; 
     1422                                bone.boneIndex          = it->boneIndex; 
     1423                                bone.weight                             = it->weight; 
     1424 
     1425                                mInitialMesh->mBones.push_back(bone); 
     1426                                bones_count++; 
     1427                        } 
     1428                } 
     1429        } 
     1430} 
     1431 
     1432//------------------------------------------------------------------------- 
     1433//      Erase submeshes that have not indices. 
     1434//------------------------------------------------------------------------- 
     1435void    SimplificationMethod::eraseVoidSubMeshes(Mesh   *geoMesh) 
     1436{ 
     1437        SubMesh *geosubmesh; 
     1438        size_t  valid_submesh_count; 
     1439        size_t  submesh; 
     1440 
     1441        valid_submesh_count     =       0; 
     1442 
     1443        //      For each submesh. 
     1444        for     (size_t i       =       0; i < geoMesh->mSubMeshCount;  i++) 
     1445        { 
     1446                //      Debug. 
     1447                cout    <<      "Indices of submesh " 
     1448                                        <<      i 
     1449                                        <<      ": " 
     1450                                        <<      geoMesh->mSubMesh[i].mIndexCount 
     1451                                        <<      endl; 
     1452 
     1453                if ((geoMesh->mSubMesh[i].mIndexCount > 0) 
     1454                                || 
     1455                                (indexMeshLeaves == i)) 
     1456                { 
     1457                        valid_submesh_count++; 
     1458                } 
     1459        } 
     1460 
     1461        //      Reassign submesh count. 
     1462        geoMesh->mSubMeshCount  =       valid_submesh_count; 
     1463 
     1464        //      Reserve memory for valid submeshes. 
     1465        geosubmesh      =       new     SubMesh[valid_submesh_count]; 
     1466 
     1467        submesh =       0; 
     1468         
     1469        //      For each submesh. 
     1470        for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 
     1471        { 
     1472                //      If leaves submesh is found. 
     1473                if (indexMeshLeaves == i) 
     1474                { 
     1475                        geosubmesh[i].mStripCount       =       0; 
     1476                        geosubmesh[i].mStrip                    =       NULL; 
     1477 
     1478                        geosubmesh[i].mSharedVertexBuffer       =       false; 
     1479 
     1480                        strcpy( geosubmesh[i].mMaterialName, 
     1481                                        mInitialMesh->mSubMesh[i].mMaterialName); 
     1482 
     1483                        //      Copy submesh bones. 
     1484                        if (!mInitialMesh->mSubMesh[i].mBones.empty()) 
     1485                        { 
     1486                                for (   size_t j = 0; 
     1487                                                j < mInitialMesh->mSubMesh[i].mBones.size(); 
     1488                                                j++) 
     1489                                { 
     1490                                        geosubmesh[i].mBones.push_back(mInitialMesh-> 
     1491                                                        mSubMesh[i].mBones[j]); 
     1492                                } 
     1493                        } 
     1494 
     1495                        //      Leaves mesh. 
     1496                        geosubmesh[i].mIndexCount       =        
     1497                                mInitialMesh->mSubMesh[i].mIndexCount; 
     1498 
     1499                        geosubmesh[i].mIndex    = 
     1500                                new Geometry::Index[geosubmesh[i].mIndexCount]; 
     1501 
     1502                        memcpy( geosubmesh[i].mIndex, 
     1503                                        mInitialMesh->mSubMesh[i].mIndex, 
     1504                                        mInitialMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
     1505 
     1506                        //      Copy the leaves submesh vertices. 
     1507                        geosubmesh[i].mVertexBuffer     = 
     1508                                mInitialMesh->mSubMesh[i].mVertexBuffer->Clone(); 
     1509 
     1510                        //      Next valid submesh. 
     1511                        submesh++; 
     1512                } 
     1513                else if (geoMesh->mSubMesh[i].mIndexCount > 0) 
     1514                { 
     1515                        geosubmesh[submesh].mSharedVertexBuffer = 
     1516                                                                        geoMesh->mSubMesh[i].mSharedVertexBuffer; 
     1517 
     1518                        geosubmesh[submesh].mVertexBuffer       =       geoMesh->mVertexBuffer; 
     1519 
     1520                        geosubmesh[submesh].mType                               =       geoMesh->mSubMesh[i].mType; 
     1521 
     1522                        geosubmesh[submesh].mStripCount =       geoMesh->mSubMesh[i].mStripCount; 
     1523 
     1524                        geosubmesh[submesh].mIndexCount =       geoMesh->mSubMesh[i].mIndexCount; 
     1525 
     1526                        //      Reserve memory for indices. 
     1527                        geosubmesh[submesh].mIndex      = 
     1528                                                                                                        new Index[geosubmesh[submesh].mIndexCount]; 
     1529 
     1530                        //      Copy indices. 
     1531                        memcpy( geosubmesh[submesh].mIndex, 
     1532                                        geoMesh->mSubMesh[i].mIndex, 
     1533                                        geoMesh->mSubMesh[i].mIndexCount * sizeof(Index)); 
     1534 
     1535                        //      Reserve memory for array of strips. 
     1536                        geosubmesh[submesh].mStrip      = 
     1537                                new Index*[geoMesh->mSubMesh[submesh].mStripCount]; 
     1538 
     1539                        //      Copy strip list of the submesh. 
     1540                        for (size_t j = 0; j < geoMesh->mSubMesh[i].mStripCount; j++) 
     1541                        { 
     1542                                geosubmesh[submesh].mStrip[j]   =       geoMesh->mSubMesh[i].mStrip[j]; 
     1543                        } 
     1544 
     1545                        strcpy( geosubmesh[submesh].mMaterialName, 
     1546                                        geoMesh->mSubMesh[i].mMaterialName); 
     1547 
     1548                        for (size_t     j       =       0;      j < geoMesh->mSubMesh[i].mBones.size(); j++) 
     1549                        { 
     1550                                geosubmesh[submesh].mBones 
     1551                                        .push_back(geoMesh->mSubMesh[i].mBones[j]); 
     1552                        } 
     1553 
     1554                        //      Next valid submesh. 
     1555                        submesh++; 
     1556                } 
     1557        } 
     1558 
     1559        //      Delete submeshes. 
     1560        delete  []geoMesh->mSubMesh; 
     1561 
     1562        geoMesh->mSubMesh       =       geosubmesh; 
     1563} 
     1564 
     1565//------------------------------------------------------------------------- 
     1566//      Fill up vertices. 
     1567//------------------------------------------------------------------------- 
     1568void    SimplificationMethod::fillUpVertices( 
     1569                                                                                                                        MAPAINDIND      *unique_verts_inds_by_geo, 
     1570                                                                                                                        REPINDLIST      *ver_inds_rep_by_geo) 
     1571{ 
    12961572        bool copiedShared = false; 
    12971573 
    12981574        //      For each submesh. 
    1299         for (size_t     i = 0;  i < objmesh->mSubMeshCount;     i++) 
     1575        for (size_t     i = 0;  i < mInitialMesh->mSubMeshCount;        i++) 
    13001576        { 
    13011577                mGeoMesh->mSubMesh[i].mStripCount       =       0; 
     
    13061582 
    13071583                strcpy( mGeoMesh->mSubMesh[i].mMaterialName, 
    1308                                 objmesh->mSubMesh[i].mMaterialName); 
     1584                                mInitialMesh->mSubMesh[i].mMaterialName); 
    13091585 
    13101586                //      Copy submesh bones. 
    1311                 if (!objmesh->mSubMesh[i].mBones.empty()) 
    1312                 { 
    1313                         for (unsigned int j = 0; j < objmesh->mSubMesh[i].mBones.size(); j++) 
    1314                         { 
    1315                                 mGeoMesh->mSubMesh[i].mBones.push_back(objmesh-> 
    1316                                                                                                                                                                 mSubMesh[i].mBones[j]); 
     1587                if (!mInitialMesh->mSubMesh[i].mBones.empty()) 
     1588                { 
     1589                        for (   unsigned int j = 0; 
     1590                                                j < mInitialMesh->mSubMesh[i].mBones.size(); 
     1591                                                j++) 
     1592                        { 
     1593                                mGeoMesh->mSubMesh[i].mBones.push_back(mInitialMesh-> 
     1594                                                mSubMesh[i].mBones[j]); 
    13171595                        } 
    13181596                } 
     
    13221600                        //      Indices vectors. 
    13231601                        mGeoMesh->mSubMesh[i].mIndexCount       =       ver_inds_rep_by_geo[i].size(); 
    1324                          
    1325                         mGeoMesh->mSubMesh[i].mIndex                    =       new Index[mGeoMesh-> 
    1326                                                                                                                                                                                 mSubMesh[i].mIndexCount]; 
     1602 
     1603                        mGeoMesh->mSubMesh[i].mIndex                    =       new Geometry::Index[mGeoMesh-> 
     1604                                mSubMesh[i].mIndexCount]; 
    13271605 
    13281606                        //      Store the indices. 
     
    13311609                                //      Obtain the indices that point at VertexBuffer. 
    13321610                                mGeoMesh->mSubMesh[i].mIndex[j] = 
    1333                                         unique_verts_inds_by_geo[i]. 
    1334                                                                 operator [](ver_inds_rep_by_geo[i]. 
    1335                                                                 operator [](j)); 
     1611                                        unique_verts_inds_by_geo[i][ver_inds_rep_by_geo[i][j]]; 
    13361612                        } 
    13371613 
     
    13551631 
    13561632                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount       = 
    1357                                                                                                                                         unique_verts_inds_by_geo[i].size(); 
    1358                          
     1633                                unique_verts_inds_by_geo[i].size(); 
     1634 
    13591635                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo        = 
    1360                                                                                         objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
     1636                                mInitialMesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
    13611637 
    13621638                        //      Allocate memory for position, normal and texutre coordinates. 
    13631639                        mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition  = 
    1364                                                 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1365                          
     1640                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1641 
    13661642                        mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal            = 
    1367                                                 new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1368                          
     1643                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1644 
    13691645                        mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 
    1370                                                 new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1371  
    1372                         for (   MAPAINDIND::iterator mapit = unique_verts_inds_by_geo[i].begin(); 
     1646                                new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1647 
     1648                        for (MAPAINDIND::iterator mapit = unique_verts_inds_by_geo[i].begin(); 
    13731649                                                mapit != unique_verts_inds_by_geo[i].end(); 
    13741650                                                mapit++) 
     
    13811657                                //      Construction of the submeshes. 
    13821658                                Vector3 v3(     (Real)M0.vertex(isrc)->operator [](0), 
    1383                                                                                 (Real)M0.vertex(isrc)->operator [](1), 
    1384                                                                                 (Real)M0.vertex(isrc)->operator [](2)); 
    1385                                  
     1659                                                (Real)M0.vertex(isrc)->operator [](1), 
     1660                                                (Real)M0.vertex(isrc)->operator [](2)); 
     1661 
    13861662                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[idst]    =       v3; 
    13871663 
    13881664                                //      Normal coordinates. 
    13891665                                Vector3 v3n(    (Real)M0.normal(isrc)(0), 
    1390                                                                                         (Real)M0.normal(isrc)(1), 
    1391                                                                                         (Real)M0.normal(isrc)(2)); 
    1392                                  
     1666                                                (Real)M0.normal(isrc)(1), 
     1667                                                (Real)M0.normal(isrc)(2)); 
     1668 
    13931669                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[idst]      =       v3n; 
    13941670 
    13951671                                //      Texture coordinates. 
    13961672                                Vector2 v2(     (Real)M0.texcoord(isrc)(0), 
    1397                                                                                 (Real)M0.texcoord(isrc)(1)); 
    1398                                  
     1673                                                (Real)M0.texcoord(isrc)(1)); 
     1674 
    13991675                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[idst]   =       v2; 
    14001676                        } 
    14011677                } 
     1678                //      Leaves mesh. 
    14021679                else 
    14031680                { 
    1404                         //      Leaves mesh. 
    1405                         mGeoMesh->mSubMesh[i].mIndexCount       =       objmesh->mSubMesh[i].mIndexCount; 
    1406                          
    1407                         mGeoMesh->mSubMesh[i].mIndex    =               new Index[mGeoMesh->mSubMesh[i].mIndexCount]; 
     1681                        mGeoMesh->mSubMesh[i].mIndexCount       =        
     1682                                                                                                                mInitialMesh->mSubMesh[i].mIndexCount; 
     1683 
     1684                        mGeoMesh->mSubMesh[i].mIndex    =                
     1685                                                new Geometry::Index[mGeoMesh->mSubMesh[i].mIndexCount]; 
    14081686 
    14091687                        //      Copy the leaves submesh indexes. 
    1410                         for (unsigned int       j       =       0;      j < mGeoMesh->mSubMesh[i].mIndexCount;  j++) 
    1411                         {        
    1412                                 mGeoMesh->mSubMesh[i].mIndex[j] =       objmesh->mSubMesh[i].mIndex[j]; 
     1688                        for (   unsigned int    j       =       0; 
     1689                                                j < mGeoMesh->mSubMesh[i].mIndexCount; 
     1690                                                j++) 
     1691                        { 
     1692                                mGeoMesh->mSubMesh[i].mIndex[j] =       mInitialMesh->mSubMesh[i].mIndex[j]; 
    14131693                        } 
    14141694 
    14151695                        //      Copy the leaves submesh vertices. 
    14161696                        mGeoMesh->mSubMesh[i].mVertexBuffer     =       new VertexBuffer(); 
    1417                          
     1697 
    14181698                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount       = 
    1419                                                                                                                 objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
    1420                          
     1699                                mInitialMesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
     1700 
    14211701                        mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo        = 
    1422                                                                                                                 objmesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
     1702                                mInitialMesh->mSubMesh[i].mVertexBuffer->mVertexInfo; 
    14231703 
    14241704                        //      Allocate memory for position, normal and texture coordinates. 
    14251705                        mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition  = 
    1426                                                         new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1427                          
     1706                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1707 
    14281708                        mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal    = 
    1429                                                         new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    1430                          
     1709                                new Vector3[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1710 
    14311711                        mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords = 
    1432                                                         new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
     1712                                new Vector2[mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount]; 
    14331713 
    14341714                        for (   unsigned int j = 0; 
     
    14381718                                //      Position. 
    14391719                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x     = 
    1440                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 
    1441                                  
     1720                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; 
     1721 
    14421722                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y     = 
    1443                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 
    1444                                  
     1723                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; 
     1724 
    14451725                                mGeoMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z     = 
    1446                                                                         objmesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 
     1726                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; 
    14471727 
    14481728                                //      Normals. 
    14491729                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x       = 
    1450                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 
    1451                                  
     1730                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].x; 
     1731 
    14521732                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y       = 
    1453                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 
    1454                                  
     1733                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].y; 
     1734 
    14551735                                mGeoMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z       = 
    1456                                                                         objmesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 
     1736                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mNormal[j].z; 
    14571737 
    14581738                                //      Textures. 
    14591739                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x    = 
    1460                                                                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 
    1461                                  
     1740                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].x; 
     1741 
    14621742                                mGeoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y    = 
    1463                                                                         objmesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 
    1464                         } 
    1465                 } 
    1466         } 
    1467  
    1468         delete[] unique_verts_inds_by_geo; 
    1469         delete[] ver_inds_rep_by_geo; 
    1470         delete[] inextvert; 
    1471  
    1472         //      Store the simplification steps in MeshSimplificationSequence. 
    1473         int     acum    =       0; 
    1474  
    1475         for (size_t i   =       0; i < objmesh->mSubMeshCount; i++) 
    1476         { 
    1477                 if (objmesh->mSubMesh[i].mSharedVertexBuffer) 
    1478                 { 
    1479                         first_index_submesh[i]  =       0; 
    1480                 } 
    1481                 else 
    1482                 { 
    1483                         first_index_submesh[i]  =       acum; 
    1484                 } 
    1485  
    1486                 acum    +=      (int)objmesh->mSubMesh[i].mVertexBuffer->mVertexCount; 
    1487         } 
    1488  
    1489         vector<int>     v0; 
    1490         vector<int>     v1; 
    1491         vector<int>     submesh0; 
    1492         vector<int>     submesh1; 
    1493  
    1494         return msimpseq; 
    1495 } 
    1496  
    1497 //--------------------------------------------------------------------------- 
     1743                                        mInitialMesh->mSubMesh[i].mVertexBuffer->mTexCoords[j].y; 
     1744                        } 
     1745                } 
     1746        } 
     1747} 
     1748 
     1749//------------------------------------------------------------------------- 
     1750//      Fill up shared vertices. 
     1751//------------------------------------------------------------------------- 
     1752void    SimplificationMethod::fillUpSharedVertices( 
     1753                                                                                                                MAPAINDIND      &shared_vertex_map, 
     1754                                                                                                                REPINDLIST      *ver_inds_rep_by_geo) 
     1755{ 
     1756        mGeoMesh->mVertexBuffer = new VertexBuffer(); 
     1757 
     1758        //      For each submesh. 
     1759        for (size_t     i = 0;  i < mInitialMesh->mSubMeshCount;        i++) 
     1760        { 
     1761                mGeoMesh-> 
     1762                        mSubMesh[i].mSharedVertexBuffer =       mInitialMesh-> 
     1763                                                                                                                                                                        mSubMesh[i].mSharedVertexBuffer; 
     1764 
     1765                //      Reassign submesh vertex buffers. 
     1766                mGeoMesh->mSubMesh[i].mVertexBuffer = mGeoMesh->mVertexBuffer; 
     1767 
     1768                mGeoMesh->mSubMesh[i].mStripCount       =       0; 
     1769                mGeoMesh->mSubMesh[i].mStrip                    =       NULL; 
     1770 
     1771                strcpy( mGeoMesh->mSubMesh[i].mMaterialName, 
     1772                                mInitialMesh->mSubMesh[i].mMaterialName); 
     1773 
     1774                //      Indices vectors. 
     1775                mGeoMesh->mSubMesh[i].mIndexCount       =       ver_inds_rep_by_geo[i].size(); 
     1776 
     1777                mGeoMesh->mSubMesh[i].mIndex                    =       new Geometry::Index[mGeoMesh-> 
     1778                                                                                                                                                                                                mSubMesh[i].mIndexCount]; 
     1779 
     1780                //      Store the indices. 
     1781                for (unsigned int       j = 0;  j < mGeoMesh->mSubMesh[i].mIndexCount;  j++) 
     1782                { 
     1783                        //      Obtain the indices that point at VertexBuffer. 
     1784                        mGeoMesh->mSubMesh[i].mIndex[j] = 
     1785                                shared_vertex_map[ver_inds_rep_by_geo[i][j]]; 
     1786                } 
     1787        } 
     1788 
     1789        mGeoMesh->mVertexBuffer->mVertexCount   =       shared_vertex_map.size(); 
     1790 
     1791        mGeoMesh->mVertexBuffer->mVertexInfo    =        
     1792                                                                                                                        mInitialMesh->mVertexBuffer->mVertexInfo; 
     1793 
     1794        //      Allocate memory for position, normal and texutre coordinates. 
     1795        mGeoMesh->mVertexBuffer->mPosition      = 
     1796                new Vector3[mGeoMesh->mVertexBuffer->mVertexCount]; 
     1797 
     1798        mGeoMesh->mVertexBuffer->mNormal                = 
     1799                new Vector3[mGeoMesh->mVertexBuffer->mVertexCount]; 
     1800 
     1801        mGeoMesh->mVertexBuffer->mTexCoords     = 
     1802                new Vector2[mGeoMesh->mVertexBuffer->mVertexCount]; 
     1803 
     1804        for (MAPAINDIND::iterator mapit = shared_vertex_map.begin(); 
     1805                        mapit != shared_vertex_map.end(); 
     1806                        mapit++) 
     1807        { 
     1808                //      Key and value. 
     1809                int isrc = mapit->first; 
     1810                int idst = mapit->second; 
     1811 
     1812                //      Vertex coordinate. 
     1813                //      Construction of the submeshes. 
     1814                Vector3 v3(     (Real)M0.vertex(isrc)->operator [](0), 
     1815                                                                (Real)M0.vertex(isrc)->operator [](1), 
     1816                                                                (Real)M0.vertex(isrc)->operator [](2)); 
     1817 
     1818                mGeoMesh->mVertexBuffer->mPosition[idst]        =       v3; 
     1819 
     1820                //      Normal coordinates. 
     1821                Vector3 v3n((Real)M0.normal(isrc)(0), 
     1822                                                                (Real)M0.normal(isrc)(1), 
     1823                                                                (Real)M0.normal(isrc)(2)); 
     1824 
     1825                mGeoMesh->mVertexBuffer->mNormal[idst]  =       v3n; 
     1826 
     1827                //      Texture coordinates. 
     1828                Vector2 v2(     (Real)M0.texcoord(isrc)(0), 
     1829                                                                (Real)M0.texcoord(isrc)(1)); 
     1830 
     1831                mGeoMesh->mVertexBuffer->mTexCoords[idst]       =       v2; 
     1832        } 
     1833} 
     1834 
     1835//------------------------------------------------------------------------- 
    14981836//      Set submesh leaves. 
    1499 //--------------------------------------------------------------------------- 
     1837//------------------------------------------------------------------------- 
    15001838void SimplificationMethod::setMeshLeaves(int meshLeaves) 
    15011839{ 
     
    15061844Mesh    *       SimplificationMethod::GetMesh() 
    15071845{ 
     1846        //      Delete void submeshes. 
     1847        eraseVoidSubMeshes(mGeoMesh); 
     1848 
    15081849        return  mGeoMesh; 
    15091850} 
Note: See TracChangeset for help on using the changeset viewer.