Ignore:
Timestamp:
09/28/06 17:49:37 (18 years ago)
Author:
gumbau
Message:

Updated modules to the new interface and the new simplification algorithm improvements.

File:
1 edited

Legend:

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

    r1136 r1526  
    2727void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb) 
    2828{ 
    29 //      LODPosition                                             pos; 
    30 //      vector  <LODPosition>   listaPos; 
    31         long            int                                                     k; 
    32         long            int                                                     i; 
    33         unsigned long           int             t; 
    34         long            int                                                     r; 
    35         unsigned long           int             v; 
    36         long            int                                                     p0; 
    37         long            int                                                     lod     =       0; 
    38         long            int                                                     sigue; 
    39         long            int                                                     ac[3]   =       {0,0,0}; 
    40         long            int                                                     totalRegs       =       0; 
    41         long            int                                                     RegsCambios; 
    42         std::vector<std::vector<int> >                  TiraOriginal; 
    43         LODData                                                                 regLOD; 
    44         //LODChanges                                                    listaCambios; 
    45         std::vector<LODData>                                            listaCambios; 
    46         float                                                                           percent; 
    47         float                                                                           increment; 
    48         long            int                                                     update; 
     29        long            int                                     k; 
     30        long            int                                     i; 
     31        unsigned long           int                     t; 
     32        long            int                                     r; 
     33        unsigned long           int                     v; 
     34        long            int                                     p0; 
     35        long            int                                     lod     =       0; 
     36        long            int                                     sigue; 
     37        long            int                                     ac[3]   =       {0,0,0}; 
     38        long            int                                     totalRegs       =       0; 
     39        long            int                                     RegsCambios; 
     40        std::vector<std::vector<int> >  TiraOriginal; 
     41        LODData                                                 regLOD; 
     42        std::vector<LODData>                    listaCambios; 
     43        float                                                   percent; 
     44        float                                                   increment; 
     45        long            int                                     update; 
    4946 
    5047        //      Saves original copy. 
     
    6865         
    6966        this->LodsDisp  =       this->TOTALCAMBIOS      =       lod; 
    70         pCambios                                =       new uint32[this->TOTALCAMBIOS]; 
    71         pCambios[0]                     =       0; 
     67        pCambios                =       new uint32[this->TOTALCAMBIOS]; 
     68        pCambios[0]             =       0; 
    7269         
    7370        for     (lod = 0; ((this->cVerts[lod].Next) != -1); lod++) 
    7471        { 
    75 /*              if (update      != (int)(increment * lod)) 
    76                 { 
    77                         update  =       (int)(increment * lod); 
    78                         upb(percent); 
    79                 }*/ 
    80  
    8172                tipoVertice & cVertsLOD = this->cVerts[lod]; 
    8273                 
    8374                RegsCambios                             =       0; 
    84                 regLOD.obligatory       =       this->Ordenacion[lod].obligatorio; 
     75                regLOD.obligatory       =       this->Ordenacion[lod].obligatory; 
    8576                 
    8677                for(t = 0; t < this->cStrips.size(); t++) 
    8778                { 
    88  
    8979                        std::vector<int> & cStripsT = this->cStrips[t]; 
    9080 
     
    10191                                        //      Strips. 
    10292                                        if (regLOD.strip == this->MARCAVACIO) 
    103                                         { 
    104                                                 regLOD.strip    =       t; 
    105                                         } 
     93                                                regLOD.strip = t; 
    10694                                         
    10795                                        ++totalRegs; 
     
    118106                        //      Changes for simplification of level 1 to greater than 2. 
    119107                        totalRegs       =       0; 
    120                         i                                       =       0; 
    121                         r                                       =       0; 
    122                         sigue                   =       0; 
    123                         k                                       =       long(cStripsT.size()-3); 
     108                        i                       =       0; 
     109                        r                       =       0; 
     110                        sigue           =       0; 
     111                        k                       =       long(cStripsT.size()-3); 
    124112                         
    125113                        while (i < k) 
     
    305293        long int vSig; 
    306294        long int k; 
    307         VECTORVERTEX                            Vertices; 
     295        VECTORVERTEX                    Vertices; 
    308296        std::vector<tipoVertice>                NuevosVerts; 
    309         //vector        <VECTORINT>     NuevasTiras; 
    310         std::vector<std::vector<int> > NuevasTiras; 
    311 //      VECTORINT                                               tira; 
    312         std::vector<int> tira; 
    313         vector  <Index>                 mV1Aux; 
    314         tipoOrden                                               Orden; 
    315         tipoOrden                                               *Ord; 
    316         bool                                                            bEncontrado; 
    317         long    int                                             c1; 
    318         long    int                                             c2; 
     297        std::vector<std::vector<int> >  NuevasTiras; 
     298        std::vector<int>                tira; 
     299        tipoOrden                               Orden; 
     300        tipoOrden                               *Ord; 
     301        bool                                    bEncontrado; 
     302 
     303 
    319304        //      Progress bar 
    320305        float                   percent; 
     
    326311        size_t  mStepsSize = mGeoMeshSQ->mSteps.size(); 
    327312 
    328         c1                                      =       0; 
    329         c2                                      =       0; 
    330          
    331313        update                  =       -1; 
    332314        percent                 =       1.0; 
     
    341323                } 
    342324                 
    343                 const Geometry::MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 
    344  
    345                 mV1Aux.push_back(theStep.mV1); 
     325                const MeshSimplificationSequence::Step & theStep = this->mGeoMeshSQ->mSteps[i]; 
    346326 
    347327                Orden.vQslimNext        =       theStep.mV0; 
    348                 Orden.vQslim                    =       theStep.mV1; 
    349                 Orden.obligatorio       =       theStep.obligatorio; 
    350                 Orden.vLS                                       =       i; 
    351  
    352                 Orden.x                                         =       theStep.x; 
    353                 Orden.vLSNext                   =       -1; 
    354                 Orden.cambio                    =       "n"; 
     328                Orden.vQslim            =       theStep.mV1; 
     329                Orden.obligatory        =       theStep.obligatory; 
     330                Orden.vLS                       =       i; 
     331 
     332                Orden.x                         =       theStep.x; 
     333                Orden.vLSNext           =       -1; 
     334                Orden.cambio            =       "n"; 
    355335 
    356336                Ordenacion.push_back(Orden); 
    357337        } 
    358338         
    359         this->NumVertsRepetidos = c2; 
    360339 
    361340        update          =       -1; 
     
    363342        percent         =       1.0; 
    364343 
    365         //      Change all vertices that have x != 0. 
    366         for(i   =       0;      i < Ordenacion.size();  i++) 
    367         { 
    368                 if (update      != (int)(i * increment)) 
    369                 { 
    370                         update  = (int)(i * increment); 
    371                         upb(percent); 
    372                 } 
    373                  
    374                 Ord     =       &(Ordenacion[i]); 
    375  
    376                 if (Ord->x!=0) 
    377                 { 
    378                         //      Change the simplification order. 
    379                         v                                                               =       Ord->vQslim; 
    380                         Ord->vQslim                     =       Ord->vQslimNext; 
    381                         Ord->vQslimNext =       v; 
    382  
    383                         for (j = i+1; j < Ordenacion.size(); j++) 
    384                         { 
    385                                 tipoOrden & ordJ = Ordenacion[j]; 
    386                                 if (ordJ.vQslim == Ord->vQslim) 
    387                                 { 
    388                                         ordJ.vQslim     =       Ord->vQslimNext; 
    389                                         ordJ.cambio     =       "y"; 
    390                                 } 
    391                                 else if (ordJ.vQslimNext == Ord->vQslim) 
    392                                 { 
    393                                         ordJ.vQslimNext =       Ord->vQslimNext;         
    394                                         ordJ.cambio                     =       "y"; 
    395                                 } 
    396                         } 
    397                 } 
    398         } 
    399  
    400344        update          =       -1; 
    401345        increment       =       (float)(10.0) / (float)(Ordenacion.size()); 
     
    412356                } 
    413357 
    414                 c1++; 
    415                 NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]); 
    416  
    417                 cVerts[Ordenacion[i].vQslim].Next       =       -1; 
     358                int OrdvQslim = Ordenacion[i].vQslim; 
     359                int OrdvQslimNext = Ordenacion[i].vQslimNext; 
     360 
     361                NuevosVerts.push_back(this->cVerts[OrdvQslim]); 
     362 
     363                cVerts[OrdvQslim].Next  =       -1; 
    418364 
    419365        } 
     
    421367        //      Añadir aquellos vertices que no estaban en NuevosVerts  
    422368        //      y no se simplificaban. 
    423         int cont                                =       0; 
     369        int cont                =       0; 
    424370        int contestaban =       0; 
    425371 
     
    431377                        cont++; 
    432378                        NuevosVerts.push_back(this->cVerts[i]); 
    433                         Orden.vLS                                       =       int(Ordenacion.size()); 
    434                         Orden.obligatorio       = 0; 
    435                         Orden.vLSNext                   =       -1; 
    436                         Orden.vQslim                    =       i; 
     379                        Orden.vLS                       =       int(Ordenacion.size()); 
     380                        Orden.obligatory        = 0; 
     381                        Orden.vLSNext           =       -1; 
     382                        Orden.vQslim            =       i; 
    437383                        Orden.vQslimNext        =       -1; 
    438384 
     
    466412                for (t = 0; t < Ordenacion.size() && !vSig;t++) 
    467413                { 
    468                         if (Ordenacion[t].vQslim==v) 
    469                         { 
    470                                 vSig=Ordenacion[t].vLS; 
    471                         } 
    472                 } 
    473  
    474                 if (vSig!=0) 
     414                        if (Ordenacion[t].vQslim == v) 
     415                        { 
     416                                vSig    =       Ordenacion[t].vLS; 
     417                        } 
     418                } 
     419 
     420                if (vSig != 0) 
    475421                { 
    476422                        Ordenacion[i].vLSNext   =       vSig; 
     
    485431 
    486432                size_t  cStripsSizeT = this->cStrips[t].size(); 
     433 
    487434                for(i = 0; i < cStripsSizeT; i++) 
     435                { 
    488436                        tira.push_back(0); 
     437                } 
    489438 
    490439                NuevasTiras.push_back(tira); 
     
    499448        //      2 min. 
    500449        //Cambiar los vertices de las tiras 
    501         size_t  NuevosVertsSize = NuevosVerts.size();    
     450        size_t  NuevosVertsSize = NuevosVerts.size(); 
     451 
    502452        for(v = 0; v < NuevosVertsSize; v++) 
    503453        { 
     
    515465                        std::vector<int> & NuevasTirasT = NuevasTiras[t]; 
    516466                        size_t  cStripsSizeT = thisStrip.size(); 
     467 
    517468                        for(i = 0; i < cStripsSizeT; i++) 
    518469                        { 
     
    531482        //NuevosVerts y Ordenacion = tamaño. 
    532483        NuevosVertsSize = NuevosVerts.size(); 
     484 
    533485        for(i = 0; i < NuevosVertsSize; i++) 
    534486        { 
     
    563515         
    564516        this->mGeoMeshSQ        =       const_cast<MeshSimplificationSequence*>(ms); 
     517 
     518        //      Add new vertices to mesh. 
     519        AddNewVertices(); 
    565520 
    566521        //      Set the leaves submesh. 
     
    612567void LodStripsConstructor::Save(std::string filename) 
    613568{ 
    614         //size_t        i, j; 
    615         int                     k       =       0; 
    616         char            simp[256]; 
    617  
    618569        int vertexCount         =       (int)this->cVerts.size(); 
    619570        int changesCount        =       (int)this->cCambios.size(); 
    620         int dataCount                   =       (int)this->cDatos.size(); 
     571        int dataCount           =       (int)this->cDatos.size(); 
    621572        int cambiosCount        =       this->TOTALCAMBIOS; 
    622         int size                                        =       changesCount*sizeof(LODData) +  
     573        int size                        =       changesCount*sizeof(LODData) +  
    623574                                (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) + 
    624575                                CHUNK_OVERHEAD_SIZE; 
     
    630581        fwrite(&size,sizeof(unsigned long),1,f); 
    631582 
     583        // VERTICES 
    632584        fwrite(&vertexCount, sizeof(int), 1, f); 
    633585        for(size_t      i = 0; i < this->cVerts.size(); i++) 
     
    636588                fwrite(&auxv, sizeof(int), 1, f); 
    637589        } 
    638  
    639         //      VERTICES. 
    640 /*      for(i = 0; i < this->cVerts.size(); i++) 
    641         { 
    642                 sprintf(simp,"v %d\n",cVerts[i].Next); 
    643                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    644         } 
    645 */ 
    646590         
    647591        //      CSTRIPS. 
     
    649593         
    650594        for(size_t      i = 0; i < this->cStrips.size(); i++) 
    651         { 
    652595                this->TOTALINDICES += int(this->cStrips[i].size()); 
    653         } 
    654596 
    655597        //      lines starting with a d. 
     
    662604        } 
    663605 
    664  
    665 /*      for(i = 0; i < this->cCambios.size(); i++) 
    666         { 
    667                 sprintf(simp,"c\n"); 
    668                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    669                  
    670                 sprintf(simp, 
    671                                                 "d %u %u %u %u %u\n", 
    672                                                 cCambios[i].strip, 
    673                                                 cCambios[i].nP, 
    674                                                 cCambios[i].nL1, 
    675                                                 cCambios[i].nL2, 
    676                                                 cCambios[i].obligatory); 
    677                  
    678                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    679         } 
    680 */      //      Lines starting with a b. 
    681606        //      Data. 
    682  
    683607        fwrite(&dataCount, sizeof(int), 1, f); 
    684  
    685608        for(size_t      i = 0; i < this->cDatos.size(); i++) 
    686609        { 
     
    688611                fwrite(&data, sizeof(int), 1, f); 
    689612        } 
    690  
    691         sprintf(simp,"a\n"); 
    692 /*      oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    693          
    694         for(i = 0; i < this->cDatos.size(); i++) 
    695         { 
    696                 sprintf(simp,"b %d\n",cDatos[i]); 
    697  
    698                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    699         } 
    700 */ 
    701613 
    702614        //      lines starting with a p. 
     
    711623 
    712624        fclose(f); 
    713  
    714 /* 
    715         //      VERTICES. 
    716         for(i = 0; i < this->cVerts.size(); i++) 
    717         { 
    718                 sprintf(simp,"v %d\n",cVerts[i].Next); 
    719                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    720         } 
    721  
    722         //      CSTRIPS. 
    723         this->TOTALINDICES      =       0; 
    724          
    725         for(i = 0; i < this->cStrips.size(); i++) 
    726         { 
    727                 this->TOTALINDICES += int(this->cStrips[i].size()); 
    728         } 
    729  
    730         //      lines starting with a d. 
    731         //      Changes 
    732         for(i = 0; i < this->cCambios.size(); i++) 
    733         { 
    734                 sprintf(simp,"c\n"); 
    735                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    736                  
    737                 sprintf(simp, 
    738                                                 "d %u %u %u %u %u\n", 
    739                                                 cCambios[i].strip, 
    740                                                 cCambios[i].nP, 
    741                                                 cCambios[i].nL1, 
    742                                                 cCambios[i].nL2, 
    743                                                 cCambios[i].obligatory); 
    744                  
    745                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    746         } 
    747         //      Lines starting with a b. 
    748         //      Data. 
    749         sprintf(simp,"a\n"); 
    750         oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    751          
    752         for(i = 0; i < this->cDatos.size(); i++) 
    753         { 
    754                 sprintf(simp,"b %d\n",cDatos[i]); 
    755  
    756                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    757         } 
    758  
    759         //      lines starting with a p. 
    760         //      Chages made in a LOD. 
    761         for(i = 0; i < this->TOTALCAMBIOS; i++) 
    762         { 
    763                 sprintf(simp,"p %d\n",this->pCambios[i]); 
    764  
    765                 oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    766         } 
    767  
    768         oSerializer.WriteData("\n",sizeof(char),1);     */ 
    769625} 
    770626 
     
    815671        for(i = 0; i < this->TOTALTIRAS; i++) 
    816672        { 
    817                 t       =       long(this->cStrips[i].size()); 
     673                t = long(this->cStrips[i].size()); 
    818674                 
    819675                if (t > max) 
    820                 { 
    821                         max     =       t; 
    822                 } 
     676                        max     = t; 
    823677        } 
    824678 
     
    970824                                } 
    971825 
    972                                 vAux.Next                       =       -10; 
    973                                 vAux.numMesh    =       0; 
    974                          
    975                                 vAux.obligatorio        =       0; 
     826                                vAux.Next               =       -10; 
     827                                vAux.numMesh    =       0;                       
     828                                vAux.obligatory =       0; 
    976829                                 
    977830                                this->cVerts.push_back(vAux); 
     
    11701023                { 
    11711024                        assign.boneIndex        =       0; 
    1172                         assign.weight                   =       1; 
    1173  
    1174                         for (   size_t  m = copy_vb->mVertexCount; 
     1025                        assign.weight           =       1; 
     1026 
     1027                        for (size_t     m = copy_vb->mVertexCount; 
    11751028                                                m < mesh_vb->mVertexCount; 
    11761029                                                m++) 
    11771030                        { 
    11781031                                assign.vertexIndex      =       (unsigned int)m; 
    1179                                  
    11801032                                mesh_bones->push_back(assign); 
    11811033                        } 
     
    11851037                        { 
    11861038                                n       =       (*mesh_bones)[m].vertexIndex; 
    1187  
    11881039                                o       =       0; 
    11891040                                 
    1190                                 while (!(       (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x) 
    1191                                                                         && 
    1192                                                                         (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y) 
    1193                                                                         && 
    1194                                                                         (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 
     1041                                while (!(       (mesh_vb->mPosition[n].x == copy_vb->mPosition[o].x)    && 
     1042                                                        (mesh_vb->mPosition[n].y == copy_vb->mPosition[o].y)    && 
     1043                                                        (mesh_vb->mPosition[n].z == copy_vb->mPosition[o].z))) 
    11951044                                { 
    11961045                                        o++; 
     
    12001049                                 
    12011050                                while ((*copy_bones)[p].vertexIndex != o) 
    1202                                 { 
    12031051                                        p++; 
    1204                                 } 
    12051052 
    12061053                                //      Same bone for 'm' and 'p'. 
     
    12441091} 
    12451092 
    1246 void Geometry::LodStripsConstructor::UpdateMesh(void) 
     1093void LodStripsConstructor::UpdateMesh(void) 
    12471094{ 
    12481095        int num_no      =       0; 
     
    13031150 
    13041151                        indice++; 
    1305  
    13061152                } 
    13071153 
     
    14361282        } 
    14371283} 
     1284 
     1285//--------------------------------------------------------------------------- 
     1286//      Add new vertices to mesh. 
     1287//--------------------------------------------------------------------------- 
     1288void LodStripsConstructor::AddNewVertices() 
     1289{ 
     1290        int                             num_vertices; 
     1291        SubMesh                 *geosubmesh; 
     1292        VertexBuffer    *vertex_buffer; 
     1293        VertexBuffer    *new_vertex_buffer; 
     1294 
     1295        //      Gets old vertex buffer. 
     1296        vertex_buffer   =       mGeoMesh->mVertexBuffer; 
     1297         
     1298        num_vertices    =       vertex_buffer->mVertexCount 
     1299                                                                        + 
     1300                                                mGeoMeshSQ->mNewVertices.size(); 
     1301 
     1302        //      Initialize auxiliar vertex buffer. 
     1303        new_vertex_buffer       =       new     VertexBuffer(); 
     1304 
     1305        new_vertex_buffer->mVertexCount =       num_vertices; 
     1306         
     1307        new_vertex_buffer->mPosition            =       new     Vector3[num_vertices]; 
     1308        new_vertex_buffer->mNormal                      =       new     Vector3[num_vertices]; 
     1309        new_vertex_buffer->mTexCoords           =       new     Vector2[num_vertices]; 
     1310 
     1311        new_vertex_buffer->mVertexInfo  =       vertex_buffer->mVertexInfo; 
     1312 
     1313        //      Num old vertices. 
     1314        num_vertices    =       vertex_buffer->mVertexCount; 
     1315 
     1316        //      Copy the old vertex buffer. 
     1317        for     (unsigned       int     i       =       0;      i < num_vertices;       i++) 
     1318        { 
     1319                new_vertex_buffer->mPosition[i] =       vertex_buffer->mPosition[i]; 
     1320                new_vertex_buffer->mNormal[i]   =       vertex_buffer->mNormal[i]; 
     1321                new_vertex_buffer->mTexCoords[i]=       vertex_buffer->mTexCoords[i]; 
     1322        } 
     1323 
     1324 
     1325        //      Copy new vertices. 
     1326        for (unsigned   int     i       =       0;      i < mGeoMeshSQ->mNewVertices.size();    i++) 
     1327        { 
     1328                new_vertex_buffer->mPosition[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].position; 
     1329                new_vertex_buffer->mTexCoords[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].texcoord; 
     1330                new_vertex_buffer->mNormal[num_vertices + i] = mGeoMeshSQ->mNewVertices[i].normal; 
     1331 
     1332                // check if my twin-vertex-bone has a bone assignment 
     1333                // we check only the GeoMesh bones because the lodstrips only works for sharedvertex bones 
     1334                for (std::vector<VertexBoneAssignment>::iterator it = mGeoMesh->mBones.begin(); it != mGeoMesh->mBones.end(); it ++) 
     1335                { 
     1336                        if (it->vertexIndex == mGeoMeshSQ->mNewVertices[i].bonefrom) 
     1337                        { 
     1338                                VertexBoneAssignment vba; 
     1339                                vba.boneIndex = it->boneIndex; 
     1340                                vba.vertexIndex = mGeoMeshSQ->mNewVertices[i].id; 
     1341                                vba.weight = it->weight; 
     1342                                mGeoMesh->mBones.push_back(vba); 
     1343                        } 
     1344                } 
     1345        } 
     1346 
     1347        //      For each submesh. 
     1348        for (unsigned int submesh       =       0; submesh < mGeoMesh->mSubMeshCount; submesh++) 
     1349        { 
     1350                geosubmesh      =       &mGeoMesh->mSubMesh[submesh]; 
     1351 
     1352                geosubmesh->mVertexBuffer       =       new_vertex_buffer; 
     1353        } 
     1354 
     1355        delete  vertex_buffer; 
     1356         
     1357        mGeoMesh->mVertexBuffer =       new_vertex_buffer; 
     1358} 
     1359 
Note: See TracChangeset for help on using the changeset viewer.