Ignore:
Timestamp:
07/05/06 17:15:14 (18 years ago)
Author:
gumbau
Message:

Extended Mesh implementation

Location:
GTP/trunk/Lib/Geom/shared/GTGeometry
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsConstructor.h

    r1070 r1078  
    5252- It also writes the LODStrips mesh into a file. 
    5353*/ 
    54         class LodStripsConstructor : public Serializable 
     54        class LodStripsConstructor/* : public Serializable*/ 
    5555        { 
    5656                protected: 
     
    145145 
    146146                        /// Load  
    147                         void Load(Serializer &s); 
     147                /*      void Load(Serializer &s);*/ 
    148148 
    149149                        /// Saves the multiresolution model into a LODStrip file and the 
    150150                        //      LODStrips mesh using the serializer given as a parameter. 
    151                         void Save (Serializer &s); 
     151                        //void Save (Serializer &s); 
     152                        void Save (std::string); 
     153 
     154                        void UpdateMesh(void); 
    152155 
    153156                        ///     GetMesh: Return de current Mesh. 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsLibrary.h

    r1070 r1078  
    7070 
    7171        */ 
     72        class LodStripsLibraryData 
     73        { 
     74        public: 
     75                SmallIntVector                                  mFileVertices; 
     76                std::vector     <LODRegisterType>       mFileChangesLOD; 
     77                LongVector                                              mData; 
     78                std::vector<unsigned int>               p_changes; 
     79        }; 
    7280        class LodStripsLibrary : public Geometry::LodObject 
    7381        { 
     
    125133 
    126134                        //      Loads Mesh. 
    127                         void    LoadStripMesh(char *name, Mesh *geomesh); 
     135                        void    LoadStripMesh(const LodStripsLibraryData &, Mesh *geomesh); 
    128136 
    129137                        Geometry::CREATEINDEXDATAFUNC create_index_data_func; 
     
    132140                        SmallIntVector  *mStrips; 
    133141 
    134                         void UpdateDataRetrievalInterface(void); 
     142                        void UpdateDataRetrievalInterface(void);                         
    135143 
    136144                public: 
     
    141149                         *      including the multiresolution object. 
    142150                        */ 
    143                         LodStripsLibrary(std::string, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL); 
     151                        LodStripsLibrary(const LodStripsLibraryData &, Mesh *geomesh, CREATEINDEXDATAFUNC idfun=NULL); 
    144152 
    145153                        /// Destructor. 
     
    164172                        /// Returns the number of vertices of the lowest LOD. 
    165173                        uint32  MinVertices(); 
     174 
     175                        int *indices_x_submesh; 
    166176        }; 
    167177} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h

    r1069 r1078  
    88#include "GeoMesh.h" 
    99#include "GeoLodStripsLibrary.h" 
     10#include "GeoTreeSimpSequence.h" 
    1011#include "GeoLodObject.h" 
    1112 
     
    2122/*              LodTreeLibrary( const LodTreeLibrary &); 
    2223                LodTreeLibrary(LodTreeLibrary*);*/ 
    23                 LodTreeLibrary( std::string trunkSimpSeqFile, 
    24                                                 std::string leafSimpSeqFile, 
     24                LodTreeLibrary( const LodStripsLibraryData &, 
     25                                                const TreeSimplificationSequence &, 
    2526                                                Geometry::Mesh *treeGeoMesh, 
    2627                                                uint32 leafSubMeshID 
     
    6768 
    6869//              const Geometry::SmallIntVector & GetStrip(uint32 istrip) const { return trunk->mStrips[istrip]; } 
     70                Geometry::LodStripsLibrary *trunk; 
    6971 
    7072        private: 
    71                 Geometry::LodStripsLibrary *trunk; 
    7273                Foliage *foliage; 
    7374 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp

    r1070 r1078  
    609609//      lodStripConstructor object. 
    610610//--------------------------------------------------------------------------- 
    611 void LodStripsConstructor::Save(Serializer &oSerializer) 
     611void LodStripsConstructor::Save(std::string filename) 
    612612{ 
    613613        unsigned int    i, j; 
     
    615615        char                                    simp[256]; 
    616616 
    617         //******************  1º CONSTRUCCION DEL FICHERO.LOD ********************* 
     617        int vertexCount = this->cVerts.size(); 
     618        int changesCount = this->cCambios.size(); 
     619        int dataCount = this->cDatos.size(); 
     620        int cambiosCount = this->TOTALCAMBIOS; 
     621        int size= dataCount*sizeof(LODData) + (vertexCount + changesCount + cambiosCount + 4)*sizeof(int); 
     622 
     623        FILE *f = fopen(filename.c_str(),"ab"); 
     624 
     625        unsigned short chunkid = 0xabcd; 
     626        fwrite(&chunkid,sizeof(unsigned short),1,f);     
     627        fwrite(&size,sizeof(unsigned long),1,f); 
     628 
     629        fwrite(&vertexCount, sizeof(int), 1, f); 
     630        for(i = 0; i < this->cVerts.size(); i++) 
     631        { 
     632                int auxv = cVerts[i].Next; 
     633                fwrite(&auxv, sizeof(int), 1, f); 
     634        } 
    618635 
    619636        //      VERTICES. 
    620         for(i = 0; i < this->cVerts.size(); i++) 
     637/*      for(i = 0; i < this->cVerts.size(); i++) 
    621638        { 
    622639                sprintf(simp,"v %d\n",cVerts[i].Next); 
    623640                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    624641        } 
    625  
     642*/ 
     643         
    626644        //      CSTRIPS. 
    627645        this->TOTALINDICES      =       0; 
     
    634652        //      lines starting with a d. 
    635653        //      Changes 
     654        fwrite(&changesCount, sizeof(int), 1, f); 
    636655        for(i = 0; i < this->cCambios.size(); i++) 
     656        { 
     657                LODData change= cCambios[i]; 
     658                fwrite(&change, sizeof(LODData), 1, f); 
     659        } 
     660 
     661 
     662/*      for(i = 0; i < this->cCambios.size(); i++) 
    637663        { 
    638664                sprintf(simp,"c\n"); 
     
    649675                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
    650676        } 
     677*/      //      Lines starting with a b. 
     678        //      Data. 
     679 
     680        fwrite(&dataCount, sizeof(int), 1, f); 
     681        for(i = 0; i < this->cDatos.size(); i++) 
     682        { 
     683                int data= cDatos[i]; 
     684                fwrite(&data, sizeof(int), 1, f); 
     685        } 
     686 
     687        sprintf(simp,"a\n"); 
     688/*      oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
     689         
     690        for(i = 0; i < this->cDatos.size(); i++) 
     691        { 
     692                sprintf(simp,"b %d\n",cDatos[i]); 
     693 
     694                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
     695        } 
     696*/ 
     697 
     698 
     699        //      lines starting with a p. 
     700        //      Chages made in a LOD. 
     701        fwrite(&cambiosCount, sizeof(int), 1, f); 
     702        for(i = 0; i < this->TOTALCAMBIOS; i++) 
     703        { 
     704                int cambio= pCambios[i]; 
     705                fwrite(&cambio, sizeof(int), 1, f); 
     706        } 
     707 
     708        fclose(f); 
     709 
     710 
     711/* 
     712        //      VERTICES. 
     713        for(i = 0; i < this->cVerts.size(); i++) 
     714        { 
     715                sprintf(simp,"v %d\n",cVerts[i].Next); 
     716                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
     717        } 
     718 
     719        //      CSTRIPS. 
     720        this->TOTALINDICES      =       0; 
     721         
     722        for(i = 0; i < this->cStrips.size(); i++) 
     723        { 
     724                this->TOTALINDICES += int(this->cStrips[i].size()); 
     725        } 
     726 
     727        //      lines starting with a d. 
     728        //      Changes 
     729        for(i = 0; i < this->cCambios.size(); i++) 
     730        { 
     731                sprintf(simp,"c\n"); 
     732                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
     733                 
     734                sprintf(simp, 
     735                                                "d %u %u %u %u %u\n", 
     736                                                cCambios[i].strip, 
     737                                                cCambios[i].nP, 
     738                                                cCambios[i].nL1, 
     739                                                cCambios[i].nL2, 
     740                                                cCambios[i].obligatory); 
     741                 
     742                oSerializer.WriteData(simp,sizeof(char),strlen(simp)); 
     743        } 
    651744        //      Lines starting with a b. 
    652745        //      Data. 
     
    670763        } 
    671764 
    672         oSerializer.WriteData("\n",sizeof(char),1); 
    673  
    674         //*******************  2º DEVOLVER EL MESH CON LAS MODIFICACIONES EFECTUADAS  ********************* 
    675         int num_no      =       0; 
    676  
    677         if(this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true) 
    678         { 
    679                 //mPosition 
    680                 delete[] this->mGeoMesh->mVertexBuffer->mPosition; 
    681                 this->mGeoMesh->mVertexBuffer->mPosition = new Vector3[this->cVerts.size()]; 
    682  
    683                 //mNormal 
    684                 if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    685                 { 
    686                         delete[] this->mGeoMesh->mVertexBuffer->mNormal; 
    687                         this->mGeoMesh->mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; 
    688                 } 
    689  
    690                 //mTexCoords 
    691                 if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    692                 { 
    693                         delete[] this->mGeoMesh->mVertexBuffer->mTexCoords; 
    694                         this->mGeoMesh->mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; 
    695                 } 
    696  
    697                 this->mGeoMesh->mVertexBuffer->mVertexCount     =       this->cVerts.size(); 
    698                 this->mGeoMesh->mVertexBuffer->mVertexInfo              =       this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; 
    699  
    700                 for(i = 0; i < this->mGeoMesh->mSubMeshCount; i++) 
    701                 { 
    702                         this->mGeoMesh->mSubMesh[i].mVertexBuffer                               =       this->mGeoMesh->mVertexBuffer; 
    703                         this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer =       true; 
    704                 } 
    705  
    706                 int     indice  =       0; 
    707  
    708                 for (j = 0; j < this->cVerts.size(); j++) 
    709                 { 
    710                         //Copiamos las coordeandas de posicion  
    711                         this->mGeoMesh->mVertexBuffer->mPosition[indice].x      =       this->cVerts[j].Vertex[0]; 
    712                         this->mGeoMesh->mVertexBuffer->mPosition[indice].y      =       this->cVerts[j].Vertex[1]; 
    713                         this->mGeoMesh->mVertexBuffer->mPosition[indice].z      =       this->cVerts[j].Vertex[2]; 
    714  
    715                         //Copiamos las normales 
    716                         if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    717                         { 
    718                                 this->mGeoMesh->mVertexBuffer->mNormal[indice].x        =       this->cVerts[j].Normal[0]; 
    719                                 this->mGeoMesh->mVertexBuffer->mNormal[indice].y        =       this->cVerts[j].Normal[1]; 
    720                                 this->mGeoMesh->mVertexBuffer->mNormal[indice].z        =       this->cVerts[j].Normal[2]; 
    721                         } 
    722  
    723                         //Copiamos las coordenadas de textura 
    724                         if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    725                         { 
    726                                 this->mGeoMesh->mVertexBuffer->mTexCoords[indice].x     =       this->cVerts[j].TexCoords[0]; 
    727                                 this->mGeoMesh->mVertexBuffer->mTexCoords[indice].y     =       this->cVerts[j].TexCoords[1]; 
    728                         } 
    729  
    730                         indice++; 
    731  
    732                 } 
    733  
    734                 this->mGeoMesh->mVertexBuffer->mVertexCount     =       indice; 
    735         } 
    736         else    //OSCAR 
    737         { 
    738                 //Supondre que solo tengo un submesh con vertices no compartidos 
    739                 //mPosition 
    740                 delete[]        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition; 
    741                  
    742                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition    =       new Vector3[this->cVerts.size()]; 
    743  
    744                 //mNormal 
    745                 if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    746                 { 
    747                         delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal; 
    748                         this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; 
    749                 } 
    750  
    751                 //mTexCoords 
    752                 if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    753                 { 
    754                         delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords; 
    755                         this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; 
    756                 } 
    757  
    758                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =this->cVerts.size(); 
    759                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; 
    760  
    761                 this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer=false; 
    762  
    763                 int indice=0; 
    764                 for (j=0; j<this->cVerts.size(); j++) 
    765                 { 
    766                         //Copiamos las coordeandas de posicion  
    767                         this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0]; 
    768                         this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1]; 
    769                         this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2]; 
    770  
    771                         //Copiamos las normales 
    772                         if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    773                         { 
    774                                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0]; 
    775                                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1]; 
    776                                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2]; 
    777                         } 
    778  
    779                         //Copiamos las coordenadas de textura 
    780                         if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    781                         { 
    782                                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0]; 
    783                                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1]; 
    784                         } 
    785                         indice++; 
    786                 } 
    787                 this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice; 
    788         } 
    789          
    790  
    791  
    792         int indice_acum = 0; 
    793         for(i=0;i<this->mGeoMesh->mSubMeshCount;i++) 
    794         { 
    795                 Geometry::SubMesh & subMesh = meshoriginal->mSubMesh[i]; 
    796                 Geometry::SubMesh & mGeoMeshSubMesh = this->mGeoMesh->mSubMesh[i]; 
    797  
    798                 for (size_t ind=0; ind < subMesh.mIndexCount; ind++)  
    799                 { 
    800                         Index indIndex = subMesh.mIndex[ind]; 
    801                         if (subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    802                         { 
    803                                 //Hay coordenadas de textura y normales 
    804                                 if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    805                                 { 
    806                                         for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
    807                                         { 
    808                                                 if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
    809                                                 { 
    810                                                         if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo])) 
    811                                                         { 
    812                                                                 if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo])) 
    813                                                                 { 
    814                                                                         mGeoMeshSubMesh.mIndex[ind]= int(indvo);//+indice_acum; 
    815                                                                 } 
    816                                                         } 
    817                                                 } 
    818                                         } 
    819                                 } 
    820                                 else            //Hay coordenadas de textura pero no hay normales 
    821                                 { 
    822                                         for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
    823                                         { 
    824                                                 if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
    825                                                 { 
    826                                                         if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo])) 
    827                                                         { 
    828                                                                 mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
    829                                                         } 
    830                                                 } 
    831                                         } 
    832                                 } 
    833                         } 
    834                         else 
    835                         { 
    836                                 // No hay coordenadas de textura pero si normales 
    837                                 if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    838                                 { 
    839                                         for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
    840                                         { 
    841                                                 if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
    842                                                 { 
    843                                                         if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo])) 
    844                                                         { 
    845                                                                 mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
    846                                                         } 
    847                                                 } 
    848                                         } 
    849                                 } 
    850                                 else            //No hay coordenadas de texturas ni normales 
    851                                 { 
    852                                         for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
    853                                         { 
    854                                                 if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
    855                                                 { 
    856                                                         mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
    857                                                 } 
    858                                         } 
    859                                 } 
    860                         } 
    861                 } 
    862         } 
    863          
     765        oSerializer.WriteData("\n",sizeof(char),1);     */ 
    864766} 
    865767 
     
    880782} 
    881783 
    882 void LodStripsConstructor::Load(Serializer &oSerializer) 
     784/*void LodStripsConstructor::Load(Serializer &oSerializer) 
    883785{ 
    884 } 
     786}*/ 
    885787 
    886788//--------------------------------------------------------------------------- 
     
    13391241} 
    13401242 
     1243void Geometry::LodStripsConstructor::UpdateMesh(void) 
     1244{ 
     1245        int num_no      =       0; 
     1246        int i=0,j=0; 
     1247 
     1248        if(this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true) 
     1249        { 
     1250                //mPosition 
     1251                delete[] this->mGeoMesh->mVertexBuffer->mPosition; 
     1252                this->mGeoMesh->mVertexBuffer->mPosition = new Vector3[this->cVerts.size()]; 
     1253 
     1254                //mNormal 
     1255                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1256                { 
     1257                        delete[] this->mGeoMesh->mVertexBuffer->mNormal; 
     1258                        this->mGeoMesh->mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; 
     1259                } 
     1260 
     1261                //mTexCoords 
     1262                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     1263                { 
     1264                        delete[] this->mGeoMesh->mVertexBuffer->mTexCoords; 
     1265                        this->mGeoMesh->mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; 
     1266                } 
     1267 
     1268                this->mGeoMesh->mVertexBuffer->mVertexCount     =       this->cVerts.size(); 
     1269                this->mGeoMesh->mVertexBuffer->mVertexInfo              =       this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; 
     1270 
     1271                for(i = 0; i < this->mGeoMesh->mSubMeshCount; i++) 
     1272                { 
     1273                        this->mGeoMesh->mSubMesh[i].mVertexBuffer                               =       this->mGeoMesh->mVertexBuffer; 
     1274                        this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer =       true; 
     1275                } 
     1276 
     1277                int     indice  =       0; 
     1278 
     1279                for (j = 0; j < this->cVerts.size(); j++) 
     1280                { 
     1281                        //Copiamos las coordeandas de posicion  
     1282                        this->mGeoMesh->mVertexBuffer->mPosition[indice].x      =       this->cVerts[j].Vertex[0]; 
     1283                        this->mGeoMesh->mVertexBuffer->mPosition[indice].y      =       this->cVerts[j].Vertex[1]; 
     1284                        this->mGeoMesh->mVertexBuffer->mPosition[indice].z      =       this->cVerts[j].Vertex[2]; 
     1285 
     1286                        //Copiamos las normales 
     1287                        if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1288                        { 
     1289                                this->mGeoMesh->mVertexBuffer->mNormal[indice].x        =       this->cVerts[j].Normal[0]; 
     1290                                this->mGeoMesh->mVertexBuffer->mNormal[indice].y        =       this->cVerts[j].Normal[1]; 
     1291                                this->mGeoMesh->mVertexBuffer->mNormal[indice].z        =       this->cVerts[j].Normal[2]; 
     1292                        } 
     1293 
     1294                        //Copiamos las coordenadas de textura 
     1295                        if (meshoriginal->mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     1296                        { 
     1297                                this->mGeoMesh->mVertexBuffer->mTexCoords[indice].x     =       this->cVerts[j].TexCoords[0]; 
     1298                                this->mGeoMesh->mVertexBuffer->mTexCoords[indice].y     =       this->cVerts[j].TexCoords[1]; 
     1299                        } 
     1300 
     1301                        indice++; 
     1302 
     1303                } 
     1304 
     1305                this->mGeoMesh->mVertexBuffer->mVertexCount     =       indice; 
     1306        } 
     1307        else    //OSCAR 
     1308        { 
     1309                //Supondre que solo tengo un submesh con vertices no compartidos 
     1310                //mPosition 
     1311                delete[]        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition; 
     1312                 
     1313                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition    =       new Vector3[this->cVerts.size()]; 
     1314 
     1315                //mNormal 
     1316                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1317                { 
     1318                        delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal; 
     1319                        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal = new Vector3[this->cVerts.size()]; 
     1320                } 
     1321 
     1322                //mTexCoords 
     1323                if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     1324                { 
     1325                        delete[] this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords; 
     1326                        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords = new Vector2[this->cVerts.size()]; 
     1327                } 
     1328 
     1329                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =this->cVerts.size(); 
     1330                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; 
     1331 
     1332                this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer=false; 
     1333 
     1334                int indice=0; 
     1335                for (j=0; j<this->cVerts.size(); j++) 
     1336                { 
     1337                        //Copiamos las coordeandas de posicion  
     1338                        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].x=this->cVerts[j].Vertex[0]; 
     1339                        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].y=this->cVerts[j].Vertex[1]; 
     1340                        this->mGeoMesh->mSubMesh[0].mVertexBuffer->mPosition[indice].z=this->cVerts[j].Vertex[2]; 
     1341 
     1342                        //Copiamos las normales 
     1343                        if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1344                        { 
     1345                                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].x=this->cVerts[j].Normal[0]; 
     1346                                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].y=this->cVerts[j].Normal[1]; 
     1347                                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mNormal[indice].z=this->cVerts[j].Normal[2]; 
     1348                        } 
     1349 
     1350                        //Copiamos las coordenadas de textura 
     1351                        if (meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     1352                        { 
     1353                                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].x=this->cVerts[j].TexCoords[0]; 
     1354                                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mTexCoords[indice].y=this->cVerts[j].TexCoords[1]; 
     1355                        } 
     1356                        indice++; 
     1357                } 
     1358                this->mGeoMesh->mSubMesh[0].mVertexBuffer->mVertexCount =indice; 
     1359        } 
     1360         
     1361 
     1362 
     1363        int indice_acum = 0; 
     1364        for(i=0;i<this->mGeoMesh->mSubMeshCount;i++) 
     1365        { 
     1366                Geometry::SubMesh & subMesh = meshoriginal->mSubMesh[i]; 
     1367                Geometry::SubMesh & mGeoMeshSubMesh = this->mGeoMesh->mSubMesh[i]; 
     1368 
     1369                for (size_t ind=0; ind < subMesh.mIndexCount; ind++)  
     1370                { 
     1371                        Index indIndex = subMesh.mIndex[ind]; 
     1372                        if (subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     1373                        { 
     1374                                //Hay coordenadas de textura y normales 
     1375                                if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1376                                { 
     1377                                        for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
     1378                                        { 
     1379                                                if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
     1380                                                { 
     1381                                                        if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo])) 
     1382                                                        { 
     1383                                                                if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo])) 
     1384                                                                { 
     1385                                                                        mGeoMeshSubMesh.mIndex[ind]= int(indvo);//+indice_acum; 
     1386                                                                } 
     1387                                                        } 
     1388                                                } 
     1389                                        } 
     1390                                } 
     1391                                else            //Hay coordenadas de textura pero no hay normales 
     1392                                { 
     1393                                        for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
     1394                                        { 
     1395                                                if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
     1396                                                { 
     1397                                                        if (igual(subMesh.mVertexBuffer->mTexCoords[indIndex],mGeoMeshSubMesh.mVertexBuffer->mTexCoords[indvo])) 
     1398                                                        { 
     1399                                                                mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
     1400                                                        } 
     1401                                                } 
     1402                                        } 
     1403                                } 
     1404                        } 
     1405                        else 
     1406                        { 
     1407                                // No hay coordenadas de textura pero si normales 
     1408                                if(subMesh.mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     1409                                { 
     1410                                        for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
     1411                                        { 
     1412                                                if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
     1413                                                { 
     1414                                                        if (igual(subMesh.mVertexBuffer->mNormal[indIndex],mGeoMeshSubMesh.mVertexBuffer->mNormal[indvo])) 
     1415                                                        { 
     1416                                                                mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
     1417                                                        } 
     1418                                                } 
     1419                                        } 
     1420                                } 
     1421                                else            //No hay coordenadas de texturas ni normales 
     1422                                { 
     1423                                        for (size_t indvo=0; indvo<mGeoMeshSubMesh.mVertexBuffer->mVertexCount; indvo++) 
     1424                                        { 
     1425                                                if (igual(subMesh.mVertexBuffer->mPosition[indIndex],mGeoMeshSubMesh.mVertexBuffer->mPosition[indvo])) 
     1426                                                { 
     1427                                                        mGeoMeshSubMesh.mIndex[ind]=int(indvo);//+indice_acum; 
     1428                                                } 
     1429                                        } 
     1430                                } 
     1431                        } 
     1432                } 
     1433        } 
     1434 
     1435} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp

    r1070 r1078  
    1717//      Constructors. 
    1818//----------------------------------------------------------------------------- 
    19 LodStripsLibrary::LodStripsLibrary(std::string  name, Mesh *geomesh, CREATEINDEXDATAFUNC idfun) 
     19LodStripsLibrary::LodStripsLibrary(const LodStripsLibraryData &lodstripsdata, Mesh *geomesh, CREATEINDEXDATAFUNC idfun) 
    2020:create_index_data_func(idfun?idfun:DefaultIndexDataCreator) 
    2121{ 
    22         const   char    *name_of_file; 
     22//      const   char    *name_of_file; 
    2323 
    2424        //      Sets the current lod. 
     
    2626 
    2727        //      Converts a String to const char *. 
    28         name_of_file    =       name.data(); 
     28//      name_of_file    =       name.data(); 
    2929 
    3030        //      Sets the global mesh. 
     
    3232 
    3333        dataRetrievalInterface=NULL; 
     34        indices_x_submesh = NULL; 
    3435         
    3536        //      Loads the Level Of Detail file. 
    36         LodStripsLibrary::LoadStripMesh((char*)name_of_file,mGeoMesh); 
     37        LodStripsLibrary::LoadStripMesh(lodstripsdata,mGeoMesh); 
    3738 
    3839        GoToLod(0.0f);   
     
    5556        if (dataRetrievalInterface) 
    5657                delete dataRetrievalInterface; 
     58        if (indices_x_submesh) 
     59                delete[] indices_x_submesh; 
    5760} 
    5861 
     
    427430//      LoadStripMesh 
    428431//----------------------------------------------------------------------------- 
    429 void LodStripsLibrary::LoadStripMesh(char *name, Mesh *geomesh) 
     432void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData &lodstripsdata, Mesh *geomesh) 
    430433{ 
    431434        FILE                                                                                                                    *fp; 
     
    447450 
    448451        //      For each one of the submeshes. 
     452        indices_x_submesh = new int[geomesh->mSubMeshCount]; 
    449453        for (unsigned int submesh       =       0; submesh < geomesh->mSubMeshCount; submesh++) 
    450454        { 
     
    487491                        int i; 
    488492                        i       = 0; 
     493                        indices_x_submesh[submesh] = 0; 
    489494                        //      For each index of the strip. 
    490495                        for (index = indexBegin; index < indexEnd; index++) 
    491496                        { 
    492497                                mFileStrips[t].push_back(indexBegin[i]); 
     498                                indices_x_submesh[submesh]++; 
    493499                                i++; 
    494500                        } 
     
    498504        //      TODO:   LOD file loaded in load file mesh process. 
    499505        //      Open the LOD file. 
    500         if ((fp = fopen (name, "r")) == NULL) 
     506/*      if ((fp = fopen (name, "r")) == NULL) 
    501507        { 
    502508                //      Error in open. 
     
    551557                } 
    552558                 
    553                 fclose(fp); 
     559                fclose(fp);*/ 
     560 
     561        mFileVertices = lodstripsdata.mFileVertices; 
     562        mFileChangesLOD = lodstripsdata.mFileChangesLOD; 
     563        mData = lodstripsdata.mData; 
     564        p_changes = lodstripsdata.p_changes; 
     565                 
    554566                 
    555567                //      Max / Min values for LOD. 
     
    572584                //Copy the data to the structure we will use 
    573585                CopyVectors2Arrays(); 
    574         } 
     586//      } 
    575587} 
    576588 
     
    581593        dataRetrievalInterface->Begin(); 
    582594 
    583         for (unsigned   int i=0; i<mTotalStrips; i++) 
    584         { 
     595        int counter = 0; 
     596        int target_submesh = 0; 
     597        int strip_count = 0; 
     598 
     599        for (unsigned   int i=0; i<mTotalStrips; i++, strip_count++) 
     600        { 
     601                if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 
     602                { 
     603                        indices_x_submesh[target_submesh] = counter; 
     604                        counter = 0; 
     605                        strip_count = 0; 
     606                        target_submesh++; 
     607                } 
    585608                for (SmallIntVector::iterator it=mStrips[i].begin(); it!=mStrips[i].end(); it++, ii++) 
     609                { 
    586610                        dataRetrievalInterface->SetIndex(ii,*it); 
     611                        counter++; 
     612                } 
    587613                dataRetrievalInterface->SetNumValidIndices(ii); 
    588614        } 
     615 
     616        if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 
     617        { 
     618                indices_x_submesh[target_submesh] = counter; 
     619                counter = 0; 
     620                strip_count = 0; 
     621                target_submesh++; 
     622        } 
     623 
    589624        dataRetrievalInterface->End(); 
    590625} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp

    r1070 r1078  
    55using namespace Geometry; 
    66 
    7 Geometry::LodTreeLibrary::LodTreeLibrary(std::string trunkSimpSeqFile, 
    8                                                                                  std::string leafSimpSeqFile, 
     7Geometry::LodTreeLibrary::LodTreeLibrary(const LodStripsLibraryData &lodstripsdata, 
     8                                                                                 const TreeSimplificationSequence &simpseq, 
    99                                                                                 Geometry::Mesh *treeGeoMesh, 
    1010                                                                                 uint32 leafSubMeshID/* 
     
    1414{ 
    1515        // Cargar el tronco 
    16         trunk = new LodStripsLibrary(trunkSimpSeqFile,treeGeoMesh); 
     16        trunk = new LodStripsLibrary(lodstripsdata,treeGeoMesh); 
    1717 
    1818        // Cargar la copa del árbol 
    1919        Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]); 
    20         foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str()); 
     20        foliage = new Foliage(leafsSubMesh,simpseq); 
    2121        GoToFoliageLod(1.0f); 
    2222} 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimpSequence.cpp

    r1009 r1078  
    6060{ 
    6161        // Almacena la secuencia de simplificación en un fichero 
    62         char simp[256]; 
     62/*      char simp[256]; 
    6363 
    6464        // Nombre del mesh 
    6565        sprintf(simp,"%s\n",meshName); 
    6666        s.WriteData(simp,sizeof(char),strlen(simp)); 
     67*/ 
     68        unsigned short chunkid = 0xdcba; 
     69        s.WriteData(&chunkid,sizeof(unsigned short),1); 
     70        unsigned long size = mSteps.size()*8*sizeof(int); 
     71        s.WriteData(&size,sizeof(unsigned long),1); 
    6772 
    68         for(unsigned int i=0; i<mSteps.size(); i++) 
     73        int tam = mSteps.size(); 
     74        s.WriteData(&tam,sizeof(int),1); 
     75        for(unsigned int i=0; i<tam; i++) 
    6976        { 
    7077                Geometry::TreeSimplificationSequence::Step paso = mSteps.operator [](i); 
    7178 
     79                s.WriteData(&paso.mV0,sizeof(int),1); 
     80                s.WriteData(&paso.mV1,sizeof(int),1); 
     81                s.WriteData(&paso.mT0,sizeof(int),1); 
     82                s.WriteData(&paso.mT1,sizeof(int),1); 
     83 
     84                s.WriteData(paso.mNewQuad,sizeof(int),4); 
     85 
    7286                // El último %u que recibe el sprintf es para indicar si un paso es dependiente del anterior. REVISAR 
    7387                // ------------------------------------------------------------------------ 
    74                 sprintf(simp,"%u %u %u %u &", paso.mV0, paso.mV1, paso.mT0, paso.mT1); 
     88/*              sprintf(simp,"%u %u %u %u &", paso.mV0, paso.mV1, paso.mT0, paso.mT1); 
    7589                s.WriteData(simp,sizeof(char),strlen(simp)); 
    7690 
    7791                // los quads 
    7892                sprintf(simp," %u %u %u %u\n",paso.mNewQuad[0],paso.mNewQuad[1],paso.mNewQuad[2],paso.mNewQuad[3]); 
    79                 s.WriteData(simp,sizeof(char),strlen(simp)); 
     93                s.WriteData(simp,sizeof(char),strlen(simp));*/ 
    8094                //s.WriteData("\n",sizeof(char),1); 
    8195        } 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp

    r1058 r1078  
    1010// Parameters --> None 
    1111//-------------------------------------------------------------------------------------------------------------------------------- 
    12 Foliage::Foliage(const Geometry::SubMesh *leavesSubMesh, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):  
     12Foliage::Foliage(const Geometry::SubMesh *leavesSubMesh, const Geometry::TreeSimplificationSequence & simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun, Geometry::CREATEINDEXDATAFUNC idfun):  
    1313Acth(NULL), 
    1414create_vertex_data_func(vdfun==NULL?Geometry::DefaultVertexDataCreator:vdfun), 
     
    304304 
    305305/// returns the number of total leafs 
    306 bool Foliage::ReadSimpSeq(const char *simpSeqFile) 
    307 { 
    308         FILE* fp_simpli; 
     306bool Foliage::ReadSimpSeq(const Geometry::TreeSimplificationSequence & simpSeq) 
     307{ 
     308        int tn, tv1,tv2, e=0; 
     309 
     310        tn = leafCount; 
     311        for (std::vector<Geometry::TreeSimplificationSequence::Step>::const_iterator it = simpSeq.mSteps.begin(); it != simpSeq.mSteps.end(); it++) 
     312        { 
     313                Leaves[tn].vertsLeaf[0] = it->mNewQuad[0]; 
     314                Leaves[tn].vertsLeaf[1] = it->mNewQuad[1]; 
     315                Leaves[tn].vertsLeaf[2] = it->mNewQuad[2]; 
     316                Leaves[tn].vertsLeaf[3] = it->mNewQuad[3]; 
     317 
     318                Leaves[tn].visible = 0; 
     319 
     320                GetNormalH  (Leaves[tn]); 
     321 
     322                tv1 = it->mV0/2; 
     323                tv2 = it->mT0/2; 
     324 
     325                Leaves[tn].childLeft= tv1; 
     326                Leaves[tn].childRight= tv2; 
     327 
     328                Leaves[tv1].parent = tn; 
     329                Leaves[tv2].parent = tn;                 
     330 
     331                tn++; 
     332        } 
     333 
     334/*      FILE* fp_simpli; 
    309335        char linea[256]; 
    310336        int v0, v1, v2, v3, tn, tv1,tv2, e=0; 
     
    350376        } 
    351377 
    352         fclose(fp_simpli); 
     378        fclose(fp_simpli);*/ 
    353379 
    354380        leafTotal=tn; 
  • GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.h

    r1058 r1078  
    66#include "VertexData.h" 
    77#include "Leaf.h" 
     8#include "GeoTreeSimpSequence.h" 
    89 
    910class ActiveLeafNode 
     
    2627                int active_leaf_count; 
    2728 
    28                 Foliage (const Geometry::SubMesh *, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); 
     29                Foliage (const Geometry::SubMesh *, const Geometry::TreeSimplificationSequence &, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); 
    2930                Foliage (const Foliage *); 
    3031                virtual ~Foliage (void); // Destructor 
     
    5657                void ReadLeafs(const Geometry::SubMesh *); 
    5758                void ReadVertices(const Geometry::SubMesh *); 
    58                 bool ReadSimpSeq(const char*); /// returns true when successful 
     59                bool ReadSimpSeq(const Geometry::TreeSimplificationSequence &); /// returns true when successful 
    5960                void FillRoot(void); 
    6061 
Note: See TracChangeset for help on using the changeset viewer.