source: GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp @ 774

Revision 774, 28.3 KB checked in by gumbau, 18 years ago (diff)

GTGeometry and GeoTool? initial imports

Line 
1#include <iostream>
2#include <fstream>
3
4#include "GeoLodStripsConstructor.h"
5
6using namespace Geometry;
7
8//--------------------------------------------------------------------------
9//Call GenerarModeloV and CopiarVectorsArraysNUEVAED to make changes
10//---------------------------------------------------------------------------
11//      Se utiliza en el constructor sobrecargado.
12void LodStripsConstructor::GenerarModeloCompleto(TIPOFUNC       upb)
13{       
14        float   percent;
15
16        percent =       10;
17
18        this->GenerarModeloV(upb);
19        this->CopiarVectors2ArraysNUEVAED();
20
21        //      Last updtate of the progress bar.
22        upb(percent);
23}
24
25//-----------------------------------------------------------------------------------
26//It makes Lods changes and count them
27//-----------------------------------------------------------------------------------
28void LodStripsConstructor::CalcularCambiosLODsVNuevaED(TIPOFUNC upb)
29{
30//      LODPosition                                             pos;
31//      vector  <LODPosition>   listaPos;
32        long            int                                                     k;
33        long            int                                                     i;
34        long            int                                                     t;
35        long            int                                                     r;
36        long            int                                                     v;
37        long            int                                                     p0;
38        long            int                                                     lod     =       0;
39        long            int                                                     sigue;
40        long            int                                                     ac[3]   =       {0,0,0};
41        long            int                                                     totalRegs       =       0;
42        long            int                                                     RegsCambios;
43        vector  <VECTORINT>                     TiraOriginal;
44        LODData                                                 regLOD;
45        LODChanges                                              listaCambios;
46        uint32                                                          CreaTira;
47        float   percent;
48        long    int     update;
49
50        //      Guardamos copia original.
51        TiraOriginal    =       this->cStrips;
52
53        this->MARCAVACIO        =       10 * this->cVerts.size();
54       
55        listaCambios.clear();
56
57        update  =       0;
58       
59        for     (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
60        {
61                update++;
62        }
63
64        update  =       update  / 20;
65        percent =       0.5;
66       
67        this->LodsDisp  =       this->TOTALCAMBIOS      =       lod;
68        pCambios                                =       new uint32[this->TOTALCAMBIOS];
69        pCambios[0]                     =       0;
70       
71        //      5 min.
72        for     (lod = 0; ((this->cVerts[lod].Next) != -1); lod++)
73        {
74                if ((lod % update) == 0)
75                {
76                        upb(percent);
77                }
78               
79                RegsCambios                             =       0;
80                regLOD.obligatory       =       this->Ordenacion[lod].obligatorio;
81               
82                for(t = 0; t < this->cStrips.size(); t++)
83                {
84                        //Inicializar
85                        regLOD.strip    =       this->MARCAVACIO;
86
87                        //PRIMERO: los cambios de los vertices
88                        totalRegs               =       0;
89                       
90                        for (v = 0; v < this->cStrips[t].size(); v++)
91                        {
92                                //      RESOLUCION VARIABLE MAL.
93                                if (this->cStrips[t][v] == lod)
94                                {
95                                        //Gestion de Tiras.
96                                        if (regLOD.strip == this->MARCAVACIO)
97                                        {
98                                                regLOD.strip    =       t;
99                                        }
100                                       
101                                        ++totalRegs;
102
103                                        cDatos.push_back(v);
104
105                                        this->cStrips[t][v]     =       this->cVerts[lod].Next;
106                                }
107                        }
108                       
109                        regLOD.nP       =       totalRegs;
110
111                        //SEGUNDO: Simplificaciones de Longitud 1
112                        // Cambio para simplifaciones de nivel 1 mayores de 2
113                        totalRegs       =       0;
114                        i                                       =       0;
115                        r                                       =       0;
116                        sigue                   =       0;
117                        k                                       =       this->cStrips[t].size()-3;
118                       
119                        while (i < k)
120                        {
121                                if (    (this->cStrips[t][i] == this->cStrips[t][i+1])
122                                                        &&
123                                                        (this->cStrips[t][i+1] == this->cStrips[t][i+2])
124                                                )
125                                {
126                                        //      Salvar el inicio de la repeticion.
127                                        if (!r)
128                                        {
129                                                p0      =       i;
130                                        }
131                                       
132                                        this->cStrips[t].erase(this->cStrips[t].begin()+i);
133                                        i--;
134                                        r++;
135                                       
136                                        if ((i+1) != this->cStrips[t].size()-1)
137                                        {
138                                                sigue   =       1;
139                                        }
140                                        else
141                                        {
142                                                sigue   =       0;
143                                        }
144                                       
145                                }
146                                else
147                                {
148                                        sigue   =       0;
149                                }
150
151                                if (!sigue && r)
152                                {
153                                        if (regLOD.strip == this->MARCAVACIO)
154                                        {
155                                                regLOD.strip    =       t;
156                                        }
157                                       
158                                        ++totalRegs;
159
160                                        cDatos.push_back(p0);
161                                        cDatos.push_back(r);
162
163                                        r       =       0;
164                                        k       =       this->cStrips[t].size()-r-3;
165                                }
166
167                                i++;
168                        }
169                       
170                        regLOD.nL1      =       totalRegs;
171
172                        //TERCERO: Simplificaciones de Longitud 2 tipo V1 V2 V1 V2 -> V1 V2
173                        totalRegs       =       0;
174                        i                                       =       0;
175                        r                                       =       0;
176                        sigue                   =       0;
177                        k                                       =       this->cStrips[t].size() - 4;
178                       
179                        while   (i < k)
180                        {
181                                if (    (this->cStrips[t][i] == this->cStrips[t][i+2])
182                                                        &&
183                                                        (this->cStrips[t][i+1] == this->cStrips[t][i+3])
184                                                )
185                                {
186                                        if (!r)
187                                        {
188                                                p0      =       i;
189                                        }
190                                       
191                                        this->cStrips[t].erase(this->cStrips[t].begin()+i);
192                                        this->cStrips[t].erase(this->cStrips[t].begin()+i);
193                                        r++;
194                                       
195                                        i       -=      2;
196                                       
197                                        if ((i+1) != this->cStrips[t].size()-3)
198                                        {
199                                                sigue   =       1;
200                                        }
201                                        else
202                                        {
203                                                sigue   =       0;
204                                        }
205                                       
206                                }
207                                else
208                                {
209                                        sigue   =       0;
210                                }
211
212                                if (!sigue && r)
213                                {
214                                        if (regLOD.strip == this->MARCAVACIO)
215                                        {
216                                                regLOD.strip    =       t;
217                                        }
218                                       
219                                        ++totalRegs;
220
221                                        cDatos.push_back(p0);
222                                        cDatos.push_back(r);
223                                       
224                                        r       =       0;
225                                        k       =       this->cStrips[t].size()-4-2*r;
226                                }
227
228                                i++;
229                        }
230                       
231                        regLOD.nL2      =       totalRegs;
232                       
233                        if (regLOD.strip != this->MARCAVACIO)
234                        {
235                                RegsCambios++;
236                                listaCambios.push_back(regLOD);
237                        }
238                }//     End for t.
239               
240                pCambios[lod]   =       RegsCambios;
241        }//     End for lod.
242
243        this->cCambios  =       listaCambios;
244
245        //      Guardar el numero de LODS disponibles.
246        this->TOTALCAMBIOS      =       this->LodsDisp=lod;
247
248        //Retornar a la lista original
249        this->cStrips   =       TiraOriginal;
250}
251
252//-----------------------------------------------------------------------
253//Put in order vertex of Mesh from simplification sequence
254//-----------------------------------------------------------------------
255void LodStripsConstructor::OrdenarModeloVQSLIM(TIPOFUNC upb)
256{
257        long int i;
258        long int j;
259        long int t;
260        long int v;
261        long int vSig;
262        long int k;
263        VECTORVERTEX                            Vertices;
264        VECTORVERTEX                            NuevosVerts;
265        vector  <VECTORINT>     NuevasTiras;
266        VECTORINT                                               tira;
267        vector  <Index>                 mV1Aux;
268        tipoOrden                                               Orden;
269        tipoOrden                                               *Ord;
270        bool                                                            bEncontrado;
271        long    int                                             c1;
272        long    int                                             c2;
273        //      Progress bar
274        float   percent;
275        long    int     update;
276
277        bEncontrado = false;
278
279        c1      =       0;
280        c2      =       0;
281       
282        update  =       geoMeshSQ->mSteps.size() / 20;
283        percent =       0.5;
284       
285        for     (i = 0; i < this->geoMeshSQ->mSteps.size(); i++)
286        {
287                if ((i % update) == 0)
288                {
289                        upb(percent);
290                }
291               
292                mV1Aux.push_back(this->geoMeshSQ->mSteps[i].mV1);
293
294                Orden.vQslimNext        =       this->geoMeshSQ->mSteps[i].mV0;
295                Orden.vQslim                    =       this->geoMeshSQ->mSteps[i].mV1;
296                Orden.obligatorio       =       this->geoMeshSQ->mSteps[i].obligatorio;
297                Orden.vLS                                       =       i;
298
299                Orden.x                                         =       this->geoMeshSQ->mSteps[i].x;
300                Orden.vLSNext                   =       -1;
301                Orden.cambio                    =       "n";
302
303                Ordenacion.push_back(Orden);
304        }
305
306        this->NumVertsRepetidos = c2;
307
308        update  =       Ordenacion.size() / 20;
309        percent =       0.5;
310
311        //      1 min.
312        //      Change all vertices that have x != 0.
313        for(i=0;i<Ordenacion.size();i++)
314        {
315                if ((i % update) == 0)
316                {
317                        upb(percent);
318                }
319
320                Ord     =       &(Ordenacion[i]);
321
322                if (Ord->x!=0)
323                {
324                        //      Change the simplification order.
325                        v                                                               =       Ord->vQslim;
326                        Ord->vQslim                     =       Ord->vQslimNext;
327                        Ord->vQslimNext =       v;
328
329                        for (j = i+1; j < Ordenacion.size(); j++)
330                        {
331                                if (Ordenacion[j].vQslim == Ord->vQslim)
332                                {
333                                        Ordenacion[j].vQslim    =       Ord->vQslimNext;
334                                        Ordenacion[j].cambio    =       "y";
335                                }
336                                else if (Ordenacion[j].vQslimNext == Ord->vQslim)
337                                {
338                                        Ordenacion[j].vQslimNext        =       Ord->vQslimNext;       
339                                        Ordenacion[j].cambio                    =       "y";
340                                }
341                        }
342                }
343        }
344
345        update  =       Ordenacion.size() / 20;
346        percent =       0.5;
347
348        //      3 seg.
349        //Ordenacion de los vertices
350        for(i = 0; i < Ordenacion.size(); i++)
351        {
352                if ((i % update) == 0)
353                {
354                        upb(percent);
355                }
356
357                c1++;
358                NuevosVerts.push_back(this->cVerts[Ordenacion[i].vQslim]);
359
360                cVerts[Ordenacion[i].vQslim].Next       =       -1;
361
362        }
363
364        //      Añadir aquellos vertices que no estaban en NuevosVerts
365        //      y no se simplificaban.
366        int cont                                =       0;
367        int contestaban =       0;
368
369        for(i = 0; i < this->cVerts.size(); i++)
370        {
371                if (this->cVerts[i].Next != -1)
372                {
373                        cont++;
374                        NuevosVerts.push_back(this->cVerts[i]);
375                        Orden.vLS                                       =       Ordenacion.size();
376                        Orden.obligatorio       = 0;
377                        Orden.vLSNext                   =       -1;
378                        Orden.vQslim                    =       i;
379                        Orden.vQslimNext        =       -1;
380
381                        Ordenacion.push_back(Orden);
382                }
383                else
384                {
385                        contestaban++;
386                }
387        }
388
389        update  =       Ordenacion.size() / 20;
390        percent =       0.5;
391       
392        //      2 min.
393        //      Calcular los siguiente teniendo en cuenta el QSLIM.
394        for (i = 0; i < Ordenacion.size(); i++)
395        {
396                if ((i % update) == 0)
397                {
398                        upb(percent);
399                }
400
401                v       =       Ordenacion[i].vQslimNext;
402
403                //Buscar ese vertice v cual es ahora
404                vSig    =       0;
405
406                for (t = 0; t < Ordenacion.size() && !vSig;t++)
407                {
408                        if (Ordenacion[t].vQslim==v)
409                        {
410                                vSig=Ordenacion[t].vLS;
411                        }
412                }
413
414                if (vSig!=0)
415                {
416                        Ordenacion[i].vLSNext   =       vSig;
417                }
418        }
419
420        //Creacion de nuevas tiras con las mismas dimensiones
421        for(t = 0; t < this->cStrips.size(); t++)
422        {
423                tira.clear();
424
425                for(i = 0; i < this->cStrips[t].size(); i++)
426                {
427                        tira.push_back(0);
428                }
429
430                NuevasTiras.push_back(tira);
431        }
432
433        update  =       NuevosVerts.size() / 40;
434        percent =       0.5;
435
436        k       =       0;
437
438        //      2 min.
439        //Cambiar los vertices de las tiras
440        for(v = 0; v < NuevosVerts.size(); v++)
441        {
442                if ((v % update) == 0)
443                {
444                        upb(percent);
445                }
446
447                for(t = 0; t < this->cStrips.size(); t++)
448                {
449                        for(i = 0; i < this->cStrips[t].size(); i++)
450                        {
451                                if (this->cStrips[t][i] == Ordenacion[v].vQslim)
452                                {
453                                        k++;
454                                        NuevasTiras[t][i]       =       v;
455                                }
456                        }
457                }
458        }
459
460        //Cambiar a Tiras Nuevas
461        this->cStrips   =       NuevasTiras;
462
463        //NuevosVerts y Ordenacion = tamaño.
464        for(i = 0; i < NuevosVerts.size(); i++)
465        {
466                NuevosVerts[i].Next     =       Ordenacion[i].vLSNext;
467        }
468
469        //Cambiar cVerts por nuevosVerts.
470        this->cVerts    =       NuevosVerts;
471
472        percent =       10;
473        upb(percent);
474}               
475
476//-----------------------------------------------------------------------------
477//      Constructor of LodStripsConstructor object from
478//      a Mesh and MeshSimplificationSequence
479//      Constructor del objeto LodStripsConstructor.
480//      Tomamos el Mesh y la secuencia de simplificacion que se pasan
481//      como parametros y llamamos a la funcion GenerarModeloCompleto para
482//      que se realicen las modificaciones a efectuar
483//-----------------------------------------------------------------------------
484LodStripsConstructor::LodStripsConstructor(const Mesh                                           *m,
485                                                                                                                const MeshSimplificationSequence        *ms,
486                                                                                                                        TIPOFUNC                                                                                                        upb)
487{
488        MARCA   =       TOTALTIRAS      =       TOTALVERTS      =       TOTALCAMBIOS    =       0;
489       
490        meshoriginal            =       m;
491        this->geoMesh           =       new Geometry::Mesh();
492        *this->geoMesh  =       *m;
493        this->geoMeshSQ = ms;
494
495        this->GenerarModeloCompleto(upb);
496}
497
498//---------------------------------------------
499//      Destructor LodStripsConstructor object
500//      Destructor de la clase LodStripsConstructor
501//---------------------------------------------
502LodStripsConstructor::~LodStripsConstructor()
503{
504        uint32 i,j;
505
506        delete [] vDatos;
507        delete [] vCambios;
508        vector <LODData> cCambiosTemp;
509        cCambios.swap(cCambiosTemp);
510
511        VECTORUNINT cDatosTemp;
512        cDatos.swap(cDatosTemp);
513
514        delete [] vStrips;
515
516        delete [] vVerts;
517
518        vector <VECTORINT> cStripsTemp;
519        cStrips.swap(cStripsTemp);;
520
521        VECTORVERTEX cVertsTemp;
522        cVerts.swap(cVertsTemp);
523
524        delete [] pCambios;
525
526        delete this->geoMesh;
527}
528
529//------------------------------------------------------------------------------
530//      build lod file with necessary information and save all changes at
531//      lodStripConstructor object
532//      Construimos el archivo Lod donde se guarda la informacion sobre los
533//      cambios realizados en el mesh
534//      y copiamos todos los cambios realizados sobre las estructuras que
535//      contienen los vertices y los indices
536//      modificados sobre el objeto Mesh de la clase
537//------------------------------------------------------------------------------
538void LodStripsConstructor::Save(Serializer &oSerializer)
539{
540        int             i,j,k=0,s;
541        char    simp[256];
542
543        Geometry::Index pos;
544        float                                           fx,     fy,     fz;
545
546        //******************  1º CONSTRUCCION DEL FICHERO.LOD *********************
547
548        //      VERTICES.
549        for(i = 0; i < this->cVerts.size(); i++)
550        {
551                sprintf(simp,"v %d\n",cVerts[i].Next);
552                oSerializer.WriteData(simp,sizeof(char),strlen(simp));
553        }
554
555        //      CSTRIPS.
556        this->TOTALINDICES      =       0;
557       
558        for(i = 0; i < this->cStrips.size(); i++)
559        {
560                this->TOTALINDICES += this->cStrips[i].size();
561        }
562
563        //      lines starting with a d.
564        //      Changes
565        for(i = 0; i < this->cCambios.size(); i++)
566        {
567                sprintf(simp,"c\n");
568                oSerializer.WriteData(simp,sizeof(char),strlen(simp));
569               
570                sprintf(simp,
571                                                "d %u %u %u %u %u\n",
572                                                cCambios[i].strip,
573                                                cCambios[i].nP,
574                                                cCambios[i].nL1,
575                                                cCambios[i].nL2,
576                                                cCambios[i].obligatory);
577               
578                oSerializer.WriteData(simp,sizeof(char),strlen(simp));
579        }
580
581        //      Lines starting with a b.
582        //      Data.
583        sprintf(simp,"a\n");
584        oSerializer.WriteData(simp,sizeof(char),strlen(simp));
585       
586        for(i = 0; i < this->cDatos.size(); i++)
587        {
588                sprintf(simp,"b %d\n",cDatos[i]);
589
590                oSerializer.WriteData(simp,sizeof(char),strlen(simp));
591        }
592
593        //      lines starting with a p.
594        //      Chages made in a LOD.
595        for(i = 0; i < this->TOTALCAMBIOS; i++)
596        {
597                sprintf(simp,"p %d\n",this->pCambios[i]);
598
599                oSerializer.WriteData(simp,sizeof(char),strlen(simp));
600        }
601
602        oSerializer.WriteData("\n",sizeof(char),1);
603
604        //*******************  2º DEVOLVER EL MESH CON LAS MODIFICACIONES EFECTUADAS  *********************
605        int num_no      =       0;
606
607        if(this->geoMesh->mSubMesh[0].mSharedVertexBuffer == true)
608        {
609                //mPosition
610                delete[] this->geoMesh->mVertexBuffer->mPosition;
611                this->geoMesh->mVertexBuffer->mPosition = new Vector3[this->cVerts.size()];
612
613                //mNormal
614                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
615                {
616                        delete[] this->geoMesh->mVertexBuffer->mNormal;
617                        this->geoMesh->mVertexBuffer->mNormal = new Vector3[this->cVerts.size()];
618                }
619
620                //mTexCoords
621                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
622                {
623                        delete[] this->geoMesh->mVertexBuffer->mTexCoords;
624                        this->geoMesh->mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()];
625                }
626
627                this->geoMesh->mVertexBuffer->mVertexCount      =       this->cVerts.size();
628                this->geoMesh->mVertexBuffer->mVertexInfo               =       this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo;
629
630                for(i = 0; i < this->geoMesh->mSubMeshCount; i++)
631                {
632                        this->geoMesh->mSubMesh[i].mVertexBuffer                                =       this->geoMesh->mVertexBuffer;
633                        this->geoMesh->mSubMesh[i].mSharedVertexBuffer  =       true;
634                }
635
636                int     indice  =       0;
637
638                for (j = 0; j < this->cVerts.size(); j++)
639                {
640                        //Copiamos las coordeandas de posicion
641                        this->geoMesh->mVertexBuffer->mPosition[indice].x       =       this->cVerts[j].Vertex[0];
642                        this->geoMesh->mVertexBuffer->mPosition[indice].y       =       this->cVerts[j].Vertex[1];
643                        this->geoMesh->mVertexBuffer->mPosition[indice].z       =       this->cVerts[j].Vertex[2];
644
645                        //Copiamos las normales
646                        if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
647                        {
648                                this->geoMesh->mVertexBuffer->mNormal[indice].x =       this->cVerts[j].Normal[0];
649                                this->geoMesh->mVertexBuffer->mNormal[indice].y =       this->cVerts[j].Normal[1];
650                                this->geoMesh->mVertexBuffer->mNormal[indice].z =       this->cVerts[j].Normal[2];
651                        }
652
653                        //Copiamos las coordenadas de textura
654                        if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
655                        {
656                                this->geoMesh->mVertexBuffer->mTexCoords[indice].x      =       this->cVerts[j].TexCoords[0];
657                                this->geoMesh->mVertexBuffer->mTexCoords[indice].y      =       this->cVerts[j].TexCoords[1];
658                        }
659
660                        indice++;
661
662                }
663
664                this->geoMesh->mVertexBuffer->mVertexCount      =       indice;
665        }
666        else    //OSCAR
667        {
668                //Supondre que solo tengo un submesh con vertices no compartidos
669                //mPosition
670                delete[]        this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition;
671               
672                this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition     =       new Vector3[this->cVerts.size()];
673
674                //mNormal
675                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
676                {
677                        delete[] this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal;
678                        this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal = new Vector3[this->cVerts.size()];
679                }
680
681                //mTexCoords
682                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
683                {
684                        delete[] this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords;
685                        this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()];
686                }
687
688                this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =this->cVerts.size();
689                this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo;
690
691                this->geoMesh->mSubMesh[0].mSharedVertexBuffer=false;
692
693                int indice=0;
694                for (j=0; j<this->cVerts.size(); j++)
695                {
696                        //Copiamos las coordeandas de posicion
697                        this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0];
698                        this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1];
699                        this->geoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2];
700
701                        //Copiamos las normales
702                        if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
703                        {
704                                this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0];
705                                this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1];
706                                this->geoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2];
707                        }
708
709                        //Copiamos las coordenadas de textura
710                        if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
711                        {
712                                this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0];
713                                this->geoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1];
714                        }
715                        indice++;
716                }
717                this->geoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice;
718        }
719       
720        int indice_acum = 0;
721        for(i=0;i<this->geoMesh->mSubMeshCount;i++)
722        {
723                for (size_t ind=0; ind < meshoriginal->mSubMesh[i].mIndexCount; ind++)
724                {
725                        if (meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS)
726                        {
727                                //Hay coordenadas de textura y normales
728                                if(meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
729                                {
730                                        for (size_t indvo=0; indvo<this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++)
731                                        {
732                                                if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo]))
733                                                {
734                                                        if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mNormal[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mNormal[indvo]))
735                                                        {
736                                                                if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mTexCoords[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[indvo]))
737                                                                {
738                                                                        this->geoMesh->mSubMesh[i].mIndex[ind]=indvo;//+indice_acum;
739                                                                }
740                                                        }
741                                                }
742                                        }
743                                }
744                                else            //Hay coordenadas de textura pero no hay normales
745                                {
746                                        for (size_t indvo=0; indvo<this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++)
747                                        {
748                                                if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo]))
749                                                {
750                                                        if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mTexCoords[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mTexCoords[indvo]))
751                                                        {
752                                                                this->geoMesh->mSubMesh[i].mIndex[ind]=indvo;//+indice_acum;
753                                                        }
754                                                }
755                                        }
756                                }
757                        }
758                        else
759                        {
760                                // No hay coordenadas de textura pero si normales
761                                if(meshoriginal->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL)
762                                {
763                                        for (size_t indvo=0; indvo<this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++)
764                                        {
765                                                if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo]))
766                                                {
767                                                        if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mNormal[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mNormal[indvo]))
768                                                        {
769                                                                this->geoMesh->mSubMesh[i].mIndex[ind]=indvo;//+indice_acum;
770                                                        }
771                                                }
772                                        }
773                                }
774                                else            //No hay coordenadas de texturas ni normales
775                                {
776                                        for (size_t indvo=0; indvo<this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount; indvo++)
777                                        {
778                                                if (igual(meshoriginal->mSubMesh[i].mVertexBuffer->mPosition[meshoriginal->mSubMesh[i].mIndex[ind]],this->geoMesh->mSubMesh[i].mVertexBuffer->mPosition[indvo]))
779                                                {
780                                                        this->geoMesh->mSubMesh[i].mIndex[ind]=indvo;//+indice_acum;
781                                                }
782                                        }
783                                }
784                        }
785                }
786
787        }
788
789}
790
791int LodStripsConstructor::igual(Geometry::Vector3 vo,Geometry::Vector3 vc)
792{
793        if (vo.x==vc.x && vo.y==vc.y && vo.z==vc.z)
794                return 1;
795        else
796                return 0;
797}
798
799int LodStripsConstructor::igual(Geometry::Vector2 vo,Geometry::Vector2 vc)
800{
801        if (vo.x==vc.x && vo.y==vc.y)
802                return 1;
803        else
804                return 0;
805}
806
807void LodStripsConstructor::Load(Serializer &oSerializer)
808{
809}
810
811//-----------------------------------------------------------------------------------------------
812//Call leeVerticesyTirasDeMesh, OrdenarModeloVQSLIM and CalcularCambiosLODsVNuevaED to make changes
813//at vertex and index strutures
814//Llama a los metodos que realizan los cambios sobre las estructuras que contienen la informacion
815//de los vertices y los indices
816//-----------------------------------------------------------------------------------------------
817void LodStripsConstructor::GenerarModeloV(TIPOFUNC      upb)
818{
819        long int        max;
820        long int        t;
821        long int        i;
822        float                   percent;
823
824        percent =       10;
825
826        this->leeVerticesyTirasDeMesh();
827
828        upb(percent);
829
830        //      6 min.
831        this->OrdenarModeloVQSLIM(upb);
832
833        //Calcular el tamaño maximo de tira
834        max     =       0;
835
836        for(i = 0; i < this->TOTALTIRAS; i++)
837        {
838                t       =       this->cStrips[i].size();
839               
840                if (t > max)
841                {
842                        max     =       t;
843                }
844        }
845
846        this->MARCA     =       max + 1;
847
848        //      5 min.
849        this->CalcularCambiosLODsVNuevaED(upb);
850
851}
852
853//-----------------------------------------------------------------------------------------
854//It fills structs with vertex and index information
855//Rellena estructuras de datos que contienen la informacion de vertices y tiras modificadas
856//-----------------------------------------------------------------------------------------
857void LodStripsConstructor::CopiarVectors2ArraysNUEVAED()
858{
859        int32                           i;
860        int32                           j;
861        int32                           *vertex;
862        int32                           tActual;
863        uint32                  max;
864        uint32                  t;
865        uint32                  CreaTira;
866        VECTORINT               tira;
867        LODData                 RegLOD;
868        LODChanges      listaCambios;
869
870        //      ALLOCATE----------------
871        this->TOTALVERTS        =       this->cVerts.size();
872        this->TOTALTIRAS        =       this->cStrips.size();
873        this->vVerts                    =       new tipoVertice[this->TOTALVERTS];
874        this->lStripsV          =       new VECTORINT[this->TOTALTIRAS];
875        this->vDatos                    =       new uint32[cDatos.size()];
876       
877        //      Calcular el tamaño maximo de tira y el numero de caras total.
878        max                                                             =       0;
879        this->TOTALCARAS        =       0;
880
881        for     (i = 0; i < this->cStrips.size(); i++)
882        {
883                t       =       this->cStrips[i].size();
884               
885                if (t > max)
886                {
887                        max     =       t;
888                }
889
890                this->TOTALCARAS        +=      (t-2);
891        }
892       
893        this->vStrips   =       Allocate2DArrayINT(this->TOTALTIRAS,max+1);
894        this->MARCA             =       this->cVerts.size();
895        vCambios                        =       new LODData[this->cCambios.size()];
896       
897        //      Rellenar vChanges.
898        for     (i = 0; i < this->cCambios.size();++i)
899        {
900                vCambios[i]     =       cCambios[i];
901        }
902       
903        for (i = 0; i < this->cStrips.size(); i++)
904        {
905                for (j = 0; j < this->cStrips[i].size(); j++)
906                {
907                        //      Rellenar el array vStrips.
908                        this->vStrips[i][j]     = this->cStrips[i][j];
909                       
910                        //      Rellenar el vVector.
911                        this->lStripsV[i].push_back(this->cStrips[i][j]);
912                }
913               
914                this->vStrips[i][j]     =       this->MARCA;
915        }
916
917        for (i = 0; i < cDatos.size(); i++)
918        {
919                vDatos[i]       =       cDatos[i];
920        }
921       
922        pCurrentData    =       vDatos;
923
924        //      Meter los vertices en vVerts.
925        for     (i = 0; i < this->cVerts.size(); i++)
926        {
927                this->vVerts[i] =       this->cVerts[i];
928        }
929
930}
931
932//---------------------------------------------------------------------------------------------------
933//It fills cVerts and cStrips with original Mesh vertex and strips information
934//Rellena las estructuras cVerts Y cStrips a partir de de los vertices y las tiras del mesh original
935//---------------------------------------------------------------------------------------------------
936void LodStripsConstructor::leeVerticesyTirasDeMesh()
937{
938        tipoVertice     vAux;
939        VECTORINT               tira;
940        size_t                  i;
941        size_t                  j;
942        bool                            error;
943
944        error   =       false;
945       
946        if(this->geoMesh->mSubMeshCount == 1)
947        {
948                error   =       false;
949        }
950        else
951        {
952                for     (i = 0; i < this->geoMesh->mSubMeshCount;i++)
953                {
954                        if      (this->geoMesh->mSubMesh[i].mSharedVertexBuffer == true)
955                        {
956                                error   =       false;
957                        }
958                        else
959                        {
960                                error   =       true;
961                                break;
962                        }
963                }
964        }
965       
966        if(!error)
967        {
968                if      (       (this->geoMesh->mSubMesh[0].mSharedVertexBuffer == true)
969                                        &&
970                                        (this->geoMesh->mSubMeshCount > 1)
971                                )
972                {
973                        for     (j = 0; j < this->geoMesh->mVertexBuffer->mVertexCount; j++)
974                        {
975                                //      Si hay mas de un submesh ListaIndices no se rellena correctamente
976                                vAux.Vertex[0] = this->geoMesh->mVertexBuffer->mPosition[j].x;
977                                vAux.Vertex[1] = this->geoMesh->mVertexBuffer->mPosition[j].y;
978                                vAux.Vertex[2] = this->geoMesh->mVertexBuffer->mPosition[j].z;
979
980                                //      Añadimos las normales en cVerts.
981                                if      (       this->geoMesh->mVertexBuffer->mVertexInfo
982                                                        &
983                                                        Geometry::VERTEX_NORMAL
984                                                )
985                                {
986                                        vAux.Normal[0] = this->geoMesh->mVertexBuffer->mNormal[j].x;
987                                        vAux.Normal[1] = this->geoMesh->mVertexBuffer->mNormal[j].y;
988                                        vAux.Normal[2] = this->geoMesh->mVertexBuffer->mNormal[j].z;
989                                }
990
991                                //      Añadimos las coordenadas de textura a cVerts.
992                                if      (       this->geoMesh->mVertexBuffer->mVertexInfo
993                                                        &
994                                                        Geometry::VERTEX_TEXCOORDS
995                                                )
996                                {
997                                        vAux.TexCoords[0] = this->geoMesh->mVertexBuffer->mTexCoords[j].x;
998                                        vAux.TexCoords[1] = this->geoMesh->mVertexBuffer->mTexCoords[j].y;
999                                }
1000
1001                                vAux.Next                       =       -10;
1002                                vAux.numMesh    =       0;
1003                       
1004                                vAux.obligatorio        =       0;
1005                               
1006                                this->cVerts.push_back(vAux);
1007                        }
1008                }
1009                else
1010                {
1011                        for     (i = 0; i < this->geoMesh->mSubMeshCount; i++)
1012                        {
1013                                for     (       j = 0;
1014                                                        j < this->geoMesh->mSubMesh[i].mVertexBuffer->mVertexCount;
1015                                                        j++)
1016                                {
1017                                        //      Si hay mas de un submesh ListaIndices
1018                                        //      no se rellena correctamente.
1019                                        vAux.Vertex[0] = this->geoMesh->mSubMesh[i].
1020                                                                                                                                                                        mVertexBuffer->mPosition[j].x;
1021                                        vAux.Vertex[1] = this->geoMesh->mSubMesh[i].
1022                                                                                                                                                                        mVertexBuffer->mPosition[j].y;
1023                                        vAux.Vertex[2] = this->geoMesh->mSubMesh[i].
1024                                                                                                                                                                        mVertexBuffer->mPosition[j].z;
1025                                        //      Añadimos las normales en cVerts.
1026                                        vAux.Normal[0] = this->geoMesh->mSubMesh[i].
1027                                                                                                                                                                        mVertexBuffer->mNormal[j].x;
1028                                        vAux.Normal[1] = this->geoMesh->mSubMesh[i].
1029                                                                                                                                                                        mVertexBuffer->mNormal[j].y;
1030                                        vAux.Normal[2] = this->geoMesh->mSubMesh[i].
1031                                                                                                                                                                        mVertexBuffer->mNormal[j].z;
1032
1033                                        //      Añadimos las coordenadas de textura a cVerts.
1034                                        vAux.TexCoords[0]       =       this->geoMesh->mSubMesh[i].
1035                                                                                                                                                                                        mVertexBuffer->mTexCoords[j].x;
1036                                        vAux.TexCoords[1] = this->geoMesh->mSubMesh[i].
1037                                                                                                                                                                                        mVertexBuffer->mTexCoords[j].y;
1038
1039                                        vAux.Next                       =       -10;
1040                                        vAux.numMesh    =       i;
1041                                       
1042                                        this->cVerts.push_back(vAux);
1043                                }
1044                        }
1045                }       
1046
1047                Index   indice_acum;
1048                Index   num_vert;
1049
1050                num_vert        =       0;
1051               
1052                for     (i = 0; i < this->geoMesh->mSubMeshCount; i++)
1053                {
1054                        indice_acum     =       0;
1055                       
1056                        for     (j = 0; j < this->geoMesh->mSubMesh[i].mStripCount; j++)
1057                        {
1058                                Index   *aux    =       this->geoMesh->mSubMesh[i].mStrip[j];
1059                               
1060                                if (j != 0)
1061                                {
1062                                        // La primera tira no empieza por índices repetidos.
1063                                        aux     =       aux+1;
1064                                       
1065                                        indice_acum++;
1066                                }
1067                               
1068                                if (j+1 < this->geoMesh->mSubMesh[i].mStripCount)
1069                                {
1070                                        Index   *siguiente      =       this->geoMesh->mSubMesh[i].mStrip[j+1];
1071                                       
1072                                        tira.clear();
1073                                       
1074                                        while (aux != siguiente)
1075                                        {
1076                                                tira.push_back(*aux);
1077                                                indice_acum++;
1078                                               
1079                                                aux     =       aux + 1;
1080                                        }
1081                                       
1082                                        tira.pop_back();
1083                                        this->cStrips.push_back(tira);
1084                                }
1085                                else
1086                                {
1087                                        // Insertar los indices de la última tira en el cStrips
1088                                        tira.clear();
1089                                       
1090                                        for     (       unsigned int k = indice_acum;
1091                                                                k < this->geoMesh->mSubMesh[i].mIndexCount;
1092                                                                k++)
1093                                        {
1094                                                tira.push_back(this->geoMesh->mSubMesh[i].mIndex[k]);
1095                                        }
1096                                       
1097                                        this->cStrips.push_back(tira);
1098                                }
1099                        }
1100                       
1101                        num_vert        +=      this->geoMesh->mSubMesh[i].
1102                                                                                                                                                mVertexBuffer->mVertexCount;
1103                }
1104
1105                this->TOTALVERTS        =       cVerts.size();
1106                this->TOTALTIRAS        =       cStrips.size();
1107        }
1108        else
1109        {
1110                //      Error.
1111        }
1112}
1113
1114///     GetMesh: Return de current Mesh.
1115Mesh    *       LodStripsConstructor::GetMesh()
1116{
1117        Mesh            *mesh_built;
1118
1119        mesh_built              =       new Mesh();
1120        *mesh_built             =       *geoMesh;
1121
1122        return  mesh_built;
1123}
1124
Note: See TracBrowser for help on using the repository browser.