Ignore:
Timestamp:
06/09/06 14:26:57 (18 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

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

    r986 r1009  
    1010        mVertexBuffer(0), mSubMeshCount(0), mSubMesh(0), hasSkeleton(false) 
    1111{ 
    12         mMeshBounds.maxX                                        =       0.0; 
    13         mMeshBounds.maxY                                        =       0.0; 
    14         mMeshBounds.maxZ                                        =       0.0; 
    15         mMeshBounds.minX                                        =       0.0; 
    16         mMeshBounds.minY                                        =       0.0; 
    17         mMeshBounds.minZ                                        =       0.0; 
     12        mMeshBounds.maxX                                =       0.0; 
     13        mMeshBounds.maxY                                =       0.0; 
     14        mMeshBounds.maxZ                                =       0.0; 
     15        mMeshBounds.minX                                =       0.0; 
     16        mMeshBounds.minY                                =       0.0; 
     17        mMeshBounds.minZ                                =       0.0; 
    1818        mMeshBounds.scaleFactor =       0.0; 
    1919} 
     
    2424Mesh::~Mesh() 
    2525{ 
    26         delete[] mSubMesh; 
    27         delete mVertexBuffer; 
    28 } 
    29  
     26        delete  []      mSubMesh; 
     27        delete  mVertexBuffer; 
     28} 
    3029 
    3130//--------------------------------------------------------------------------- 
    3231//      Copy constructor. 
    3332//--------------------------------------------------------------------------- 
    34 Mesh::Mesh(const Mesh &objmesh)  
    35 { 
    36         // constructor copia 
     33Mesh::Mesh(const Mesh &mesh) 
     34{ 
    3735        mVertexBuffer   =       new VertexBuffer(); 
    38         mSubMeshCount   =       objmesh.mSubMeshCount; 
    39         mSubMesh                        =       new SubMesh[objmesh.mSubMeshCount]; 
     36        mSubMeshCount   =       mesh.mSubMeshCount; 
     37        mSubMesh                        =       new SubMesh[mesh.mSubMeshCount]; 
    4038 
    4139        //      Fill up bounding box settings. 
    42         mMeshBounds.maxX                                        =       objmesh.mMeshBounds.maxX; 
    43         mMeshBounds.maxY                                        =       objmesh.mMeshBounds.maxY; 
    44         mMeshBounds.maxZ                                        =       objmesh.mMeshBounds.maxZ; 
    45         mMeshBounds.minX                                        =       objmesh.mMeshBounds.minX; 
    46         mMeshBounds.minY                                        =       objmesh.mMeshBounds.minY; 
    47         mMeshBounds.minZ                                        =       objmesh.mMeshBounds.minZ; 
    48         mMeshBounds.radius                              =       objmesh.mMeshBounds.radius; 
    49         mMeshBounds.scaleFactor         =       objmesh.mMeshBounds.scaleFactor; 
     40        mMeshBounds.maxX                                        =       mesh.mMeshBounds.maxX; 
     41        mMeshBounds.maxY                                        =       mesh.mMeshBounds.maxY; 
     42        mMeshBounds.maxZ                                        =       mesh.mMeshBounds.maxZ; 
     43        mMeshBounds.minX                                        =       mesh.mMeshBounds.minX; 
     44        mMeshBounds.minY                                        =       mesh.mMeshBounds.minY; 
     45        mMeshBounds.minZ                                        =       mesh.mMeshBounds.minZ; 
     46        mMeshBounds.radius                              =       mesh.mMeshBounds.radius; 
     47        mMeshBounds.scaleFactor         =       mesh.mMeshBounds.scaleFactor; 
    5048         
    5149        //      For each submesh. 
    52         for(size_t i = 0; i < objmesh.mSubMeshCount; i++) 
     50        for (size_t i = 0; i < mesh.mSubMeshCount; i++) 
    5351        { 
    5452                mSubMesh[i].mSharedVertexBuffer                                 =       false; 
    5553                mSubMesh[i].mVertexBuffer                                                               =       new VertexBuffer(); 
    56                 mSubMesh[i].mVertexBuffer->mPosition            =       new Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    57                 mSubMesh[i].mVertexBuffer->mNormal                      =       new Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    58                 mSubMesh[i].mVertexBuffer->mTexCoords   = new Vector2[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    59                 mSubMesh[i].mVertexBuffer->mVertexCount =       objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
    60                 mSubMesh[i].mVertexBuffer->mVertexInfo  =       objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 
    61                 mSubMesh[i].mType                                                                                               =       objmesh.mSubMesh[i].mType; 
    62                 strcpy(mSubMesh[i].mMaterialName,objmesh.mSubMesh[i].mMaterialName); 
    63                  
    64                 if(objmesh.mSubMesh[i].mSharedVertexBuffer)  
    65                 { 
    66                         for(size_t s    =       0; 
    67                                         s<objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
     54                mSubMesh[i].mVertexBuffer->mPosition            =       new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     55                mSubMesh[i].mVertexBuffer->mNormal                      =       new Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     56                mSubMesh[i].mVertexBuffer->mTexCoords   = new Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     57                mSubMesh[i].mVertexBuffer->mVertexCount =       mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
     58                mSubMesh[i].mVertexBuffer->mVertexInfo  =       mesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 
     59                mSubMesh[i].mType                                                                                               =       mesh.mSubMesh[i].mType; 
     60 
     61                strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName); 
     62                 
     63                if (mesh.mSubMesh[i].mSharedVertexBuffer) 
     64                { 
     65                        for (size_t     s       =       0; 
     66                                        s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
    6867                                        s++) 
    6968                        { 
    70                                 //      Copy mPosition. 
    71                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 
     69                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 
    7270                                { 
    73                                         mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mVertexBuffer->mPosition[s].x; 
    74                                         mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mVertexBuffer->mPosition[s].y; 
    75                                         mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mVertexBuffer->mPosition[s].z; 
     71                                        mSubMesh[i].mVertexBuffer->mPosition[s].x       =       mesh.mVertexBuffer->mPosition[s].x; 
     72                                        mSubMesh[i].mVertexBuffer->mPosition[s].y       =       mesh.mVertexBuffer->mPosition[s].y; 
     73                                        mSubMesh[i].mVertexBuffer->mPosition[s].z       =       mesh.mVertexBuffer->mPosition[s].z; 
    7674                                } 
    7775                                 
    78                                 //      Copy mNormal. 
    79                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 
     76                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 
    8077                                { 
    81                                         mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mVertexBuffer->mNormal[s].x; 
    82                                         mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mVertexBuffer->mNormal[s].y; 
    83                                         mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mVertexBuffer->mNormal[s].z; 
     78                                        mSubMesh[i].mVertexBuffer->mNormal[s].x =       mesh.mVertexBuffer->mNormal[s].x; 
     79                                        mSubMesh[i].mVertexBuffer->mNormal[s].y =       mesh.mVertexBuffer->mNormal[s].y; 
     80                                        mSubMesh[i].mVertexBuffer->mNormal[s].z =       mesh.mVertexBuffer->mNormal[s].z; 
    8481                                } 
    8582 
    86                                 //      Copy mTexCoords. 
    87                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
     83                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
    8884                                { 
    89                                         mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mVertexBuffer->mTexCoords[s].x; 
    90                                         mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mVertexBuffer->mTexCoords[s].y; 
     85                                        mSubMesh[i].mVertexBuffer->mTexCoords[s].x      =       mesh.mVertexBuffer->mTexCoords[s].x; 
     86                                        mSubMesh[i].mVertexBuffer->mTexCoords[s].y      =       mesh.mVertexBuffer->mTexCoords[s].y; 
    9187                                } 
    9288                        } 
    93                         objmesh.mSubMesh[i].mSharedVertexBuffer = false; 
     89                         
     90                        mesh.mSubMesh[i].mSharedVertexBuffer    =       false; 
    9491                } 
    9592                else 
    9693                { 
    97                         for(size_t s = 0; s < objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 
    98                         { 
    99                                 //      Copy mPosition. 
    100                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 
     94                        for     (size_t s       =       0;      s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 
     95                        { 
     96                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_POSITION) 
    10197                                { 
    102                                         mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 
    103                                         mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 
    104                                         mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 
     98                                        mSubMesh[i].mVertexBuffer->mPosition[s].x       =       mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 
     99                                        mSubMesh[i].mVertexBuffer->mPosition[s].y       =       mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 
     100                                        mSubMesh[i].mVertexBuffer->mPosition[s].z       =       mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 
    105101                                } 
    106102                                 
    107                                 //Copiamos mNormal 
    108                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 
     103                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_NORMAL) 
    109104                                { 
    110                                         mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 
    111                                         mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 
    112                                         mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 
     105                                        mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 
     106                                        mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 
     107                                        mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 
    113108                                } 
    114109 
    115                                 //Copiamos mTexCoords 
    116                                 if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
     110                                if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & VERTEX_TEXCOORDS) 
    117111                                { 
    118                                         mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 
    119                                         mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 
     112                                        mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 
     113                                        mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 
    120114                                } 
    121115                        } 
     
    124118                 
    125119                // Copy indices. 
    126                 mSubMesh[i].mIndexCount =       objmesh.mSubMesh[i].mIndexCount; 
     120                mSubMesh[i].mIndexCount =       mesh.mSubMesh[i].mIndexCount; 
    127121                mSubMesh[i].mIndex                      =       new Index[mSubMesh[i].mIndexCount]; 
    128122                 
    129                 memcpy(mSubMesh[i].mIndex,objmesh.mSubMesh[i].mIndex,objmesh.mSubMesh[i].mIndexCount*sizeof(Index)); 
     123                memcpy( mSubMesh[i].mIndex, 
     124                                                mesh.mSubMesh[i].mIndex, 
     125                                                mesh.mSubMesh[i].mIndexCount * sizeof(Index)); 
    130126 
    131127                // Copy strips. 
    132                 __w64 int offset        =       0; // offset between memory positions. 
    133                 mSubMesh[i].mStripCount=objmesh.mSubMesh[i].mStripCount; 
    134                 if (objmesh.mSubMesh[i].mStripCount>0)  
    135                 { 
    136                         mSubMesh[i].mStrip = new Index*[objmesh.mSubMesh[i].mStripCount]; 
    137  
    138                         offset  = &(mSubMesh[i].mIndex[0]) - &(objmesh.mSubMesh[i].mIndex[0]); 
    139                         for (size_t j=0;j<objmesh.mSubMesh[i].mStripCount;j++) 
    140                         { 
    141                                 mSubMesh[i].mStrip[j]=objmesh.mSubMesh[i].mStrip[j] + offset; 
     128                // offset between memory positions. 
     129                __w64   int     offset                          =       0;  
     130                mSubMesh[i].mStripCount =       mesh.mSubMesh[i].mStripCount; 
     131                 
     132                if (mesh.mSubMesh[i].mStripCount > 0) 
     133                { 
     134                        mSubMesh[i].mStrip      =       new Index*[mesh.mSubMesh[i].mStripCount]; 
     135 
     136                        offset  = &(mSubMesh[i].mIndex[0]) - &(mesh.mSubMesh[i].mIndex[0]); 
     137                         
     138                        for (size_t     j       =       0;      j < mesh.mSubMesh[i].mStripCount;       j++) 
     139                        { 
     140                                mSubMesh[i].mStrip[j]   =       mesh.mSubMesh[i].mStrip[j] + offset; 
    142141                        } 
    143142                } 
    144143 
    145144                //      Copy submesh bones. 
    146                 if (!objmesh.mSubMesh[i].mBones.empty()) 
    147                 { 
    148                         for (unsigned int j = 0; j < objmesh.mSubMesh[i].mBones.size(); j++) 
    149                         { 
    150                                 mSubMesh[i].mBones.push_back(objmesh.mSubMesh[i].mBones[j]); 
     145                if (!mesh.mSubMesh[i].mBones.empty()) 
     146                { 
     147                        for (unsigned int j = 0; j < mesh.mSubMesh[i].mBones.size(); j++) 
     148                        { 
     149                                mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]); 
    151150                        } 
    152151                } 
     
    154153         
    155154        //      Copy skeleton name. 
    156         if (objmesh.hasSkeleton) 
     155        if (mesh.hasSkeleton) 
    157156        { 
    158157                hasSkeleton     =       true; 
    159158                 
    160                 strcpy(mSkeletonName,objmesh.mSkeletonName); 
     159                strcpy(mSkeletonName,   mesh.mSkeletonName); 
    161160        } 
    162161 
    163162        //      Copy mesh bones. 
    164         if (!objmesh.mBones.empty()) 
    165         { 
    166                 for (unsigned int j = 0; j < objmesh.mBones.size(); j++) 
    167                 { 
    168                         mBones.push_back(objmesh.mBones[j]); 
     163        if (!mesh.mBones.empty()) 
     164        { 
     165                for (unsigned   int     j       =       0;      j < mesh.mBones.size(); j++) 
     166                { 
     167                        mBones.push_back(mesh.mBones[j]); 
    169168                } 
    170169        } 
     
    175174//      Assignment operator. 
    176175//--------------------------------------------------------------------------- 
    177 Mesh &Mesh::operator =(const Geometry::Mesh &objmesh) 
    178 { 
    179         // Operador de asignación 
    180         bool copiados   =       false; // indica si los vértices compartidos han sido copiados 
     176Mesh &Mesh::operator =(const    Mesh &mesh) 
     177{ 
     178        bool copied             =       false; 
    181179        mVertexBuffer   =       new VertexBuffer(); 
    182         mSubMeshCount   =       objmesh.mSubMeshCount; 
    183         mSubMesh                        =       new Geometry::SubMesh[objmesh.mSubMeshCount]; 
     180        mSubMeshCount   =       mesh.mSubMeshCount; 
     181        mSubMesh                        =       new Geometry::SubMesh[mesh.mSubMeshCount]; 
    184182         
    185183        //      Fill up bounding box settings. 
    186         mMeshBounds.maxX                                        =       objmesh.mMeshBounds.maxX; 
    187         mMeshBounds.maxY                                        =       objmesh.mMeshBounds.maxY; 
    188         mMeshBounds.maxZ                                        =       objmesh.mMeshBounds.maxZ; 
    189         mMeshBounds.minX                                        =       objmesh.mMeshBounds.minX; 
    190         mMeshBounds.minY                                        =       objmesh.mMeshBounds.minY; 
    191         mMeshBounds.minZ                                        =       objmesh.mMeshBounds.minZ; 
    192         mMeshBounds.radius                              =       objmesh.mMeshBounds.radius; 
    193         mMeshBounds.scaleFactor         =       objmesh.mMeshBounds.scaleFactor; 
     184        mMeshBounds.maxX                                        =       mesh.mMeshBounds.maxX; 
     185        mMeshBounds.maxY                                        =       mesh.mMeshBounds.maxY; 
     186        mMeshBounds.maxZ                                        =       mesh.mMeshBounds.maxZ; 
     187        mMeshBounds.minX                                        =       mesh.mMeshBounds.minX; 
     188        mMeshBounds.minY                                        =       mesh.mMeshBounds.minY; 
     189        mMeshBounds.minZ                                        =       mesh.mMeshBounds.minZ; 
     190        mMeshBounds.radius                              =       mesh.mMeshBounds.radius; 
     191        mMeshBounds.scaleFactor         =       mesh.mMeshBounds.scaleFactor; 
    194192 
    195193        //      For each submesh. 
    196         for(size_t i = 0; i < objmesh.mSubMeshCount; i++) 
    197         { 
    198                 mSubMesh[i].mSharedVertexBuffer                                 =       objmesh.mSubMesh[i].mSharedVertexBuffer; //.false; 
     194        for(size_t      i       =       0;      i < mesh.mSubMeshCount; i++) 
     195        { 
     196                mSubMesh[i].mSharedVertexBuffer                                 =       mesh.mSubMesh[i].mSharedVertexBuffer; //.false; 
    199197                mSubMesh[i].mVertexBuffer                                                               =       new Geometry::VertexBuffer(); 
    200                 mSubMesh[i].mVertexBuffer->mPosition            =       new Geometry::Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    201                 mSubMesh[i].mVertexBuffer->mNormal                      =       new Geometry::Vector3[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    202                 mSubMesh[i].mVertexBuffer->mTexCoords           =       new Geometry::Vector2[objmesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
    203                 mSubMesh[i].mVertexBuffer->mVertexCount =       objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
    204                 mSubMesh[i].mVertexBuffer->mVertexInfo  =       objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 
    205                 mSubMesh[i].mType                                       =       objmesh.mSubMesh[i].mType; 
    206                 strcpy(mSubMesh[i].mMaterialName,objmesh.mSubMesh[i].mMaterialName); 
    207  
    208                 if (objmesh.mSubMesh[i].mSharedVertexBuffer && !copiados) 
     198                mSubMesh[i].mVertexBuffer->mPosition            =       new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     199                mSubMesh[i].mVertexBuffer->mNormal                      =       new Geometry::Vector3[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     200                mSubMesh[i].mVertexBuffer->mTexCoords           =       new Geometry::Vector2[mesh.mSubMesh[i].mVertexBuffer->mVertexCount]; 
     201                mSubMesh[i].mVertexBuffer->mVertexCount =       mesh.mSubMesh[i].mVertexBuffer->mVertexCount; 
     202                mSubMesh[i].mVertexBuffer->mVertexInfo  =       mesh.mSubMesh[i].mVertexBuffer->mVertexInfo; 
     203                mSubMesh[i].mType                                                                                               =       mesh.mSubMesh[i].mType; 
     204                strcpy(mSubMesh[i].mMaterialName,mesh.mSubMesh[i].mMaterialName); 
     205 
     206                if (mesh.mSubMesh[i].mSharedVertexBuffer && !copied) 
    209207                { 
    210208                        mVertexBuffer   =       mSubMesh[i].mVertexBuffer; 
    211                         copiados                        =       true; 
    212                 } 
    213  
    214                 for(size_t s = 0; s < objmesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 
    215                 { 
    216                         //Copiamos mPosition 
    217                         //if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_POSITION) 
    218                         //{ 
    219                                 mSubMesh[i].mVertexBuffer->mPosition[s].x = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 
    220                                 mSubMesh[i].mVertexBuffer->mPosition[s].y = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 
    221                                 mSubMesh[i].mVertexBuffer->mPosition[s].z = objmesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 
    222                         //} 
    223                         //Copiamos mNormal 
    224                         if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
    225                         { 
    226                                 mSubMesh[i].mVertexBuffer->mNormal[s].x = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 
    227                                 mSubMesh[i].mVertexBuffer->mNormal[s].y = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 
    228                                 mSubMesh[i].mVertexBuffer->mNormal[s].z = objmesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 
    229                         } 
    230  
    231                         //Copiamos mTexCoords 
    232                         if (objmesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
    233                         { 
    234                                 mSubMesh[i].mVertexBuffer->mTexCoords[s].x = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 
    235                                 mSubMesh[i].mVertexBuffer->mTexCoords[s].y = objmesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 
    236                         } 
    237                 } 
    238  
    239                 // Copiar los indices 
    240                 mSubMesh[i].mIndexCount =       objmesh.mSubMesh[i].mIndexCount; 
     209                        copied                          =       true; 
     210                } 
     211 
     212                for(size_t s = 0; s < mesh.mSubMesh[i].mVertexBuffer->mVertexCount; s++) 
     213                { 
     214                        mSubMesh[i].mVertexBuffer->mPosition[s].x = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].x; 
     215                        mSubMesh[i].mVertexBuffer->mPosition[s].y = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].y; 
     216                        mSubMesh[i].mVertexBuffer->mPosition[s].z = mesh.mSubMesh[i].mVertexBuffer->mPosition[s].z; 
     217 
     218                        if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) 
     219                        { 
     220                                mSubMesh[i].mVertexBuffer->mNormal[s].x = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].x; 
     221                                mSubMesh[i].mVertexBuffer->mNormal[s].y = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].y; 
     222                                mSubMesh[i].mVertexBuffer->mNormal[s].z = mesh.mSubMesh[i].mVertexBuffer->mNormal[s].z; 
     223                        } 
     224 
     225                        if (mesh.mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) 
     226                        { 
     227                                mSubMesh[i].mVertexBuffer->mTexCoords[s].x = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].x; 
     228                                mSubMesh[i].mVertexBuffer->mTexCoords[s].y = mesh.mSubMesh[i].mVertexBuffer->mTexCoords[s].y; 
     229                        } 
     230                } 
     231 
     232                //      Copy indices. 
     233                mSubMesh[i].mIndexCount =       mesh.mSubMesh[i].mIndexCount; 
    241234                mSubMesh[i].mIndex                      =       new Index[mSubMesh[i].mIndexCount]; 
    242235 
    243236                memcpy( mSubMesh[i].mIndex, 
    244                                                 objmesh.mSubMesh[i].mIndex, 
    245                                                 objmesh.mSubMesh[i].mIndexCount*sizeof(Geometry::Index)); 
    246  
    247                 // Copiar las tiras 
    248                 __w64 offset    =       0; // desplazamiento entre posiciones de memoria. 
    249                 mSubMesh[i].mStripCount =       objmesh.mSubMesh[i].mStripCount; 
    250  
    251                 if (objmesh.mSubMesh[i].mStripCount>0)  
    252                 { 
    253                         mSubMesh[i].mStrip      =       new Index*[objmesh.mSubMesh[i].mStripCount]; 
    254                         offset  =       &(mSubMesh[i].mIndex[0]) - &(objmesh.mSubMesh[i].mIndex[0]); 
    255                          
    256                         for (size_t j = 0; j < objmesh.mSubMesh[i].mStripCount; j++) 
    257                         { 
    258                                 mSubMesh[i].mStrip[j]   =       objmesh.mSubMesh[i].mStrip[j] + offset; 
     237                                                mesh.mSubMesh[i].mIndex, 
     238                                                mesh.mSubMesh[i].mIndexCount*sizeof(Geometry::Index)); 
     239 
     240                // Copy strips. 
     241                __w64 offset                                            =       0; 
     242                mSubMesh[i].mStripCount =       mesh.mSubMesh[i].mStripCount; 
     243 
     244                if (mesh.mSubMesh[i].mStripCount > 0) 
     245                { 
     246                        mSubMesh[i].mStrip      =       new Index*[mesh.mSubMesh[i].mStripCount]; 
     247 
     248                        offset                                                  =       &(mSubMesh[i].mIndex[0]) 
     249                                                                                                                - 
     250                                                                                                                &(mesh.mSubMesh[i].mIndex[0]); 
     251                         
     252                        for (size_t     j       =       0;      j < mesh.mSubMesh[i].mStripCount;       j++) 
     253                        { 
     254                                mSubMesh[i].mStrip[j]   =       mesh.mSubMesh[i].mStrip[j] + offset; 
    259255                        } 
    260256                } 
    261257                 
    262258                //      Copy submesh bones. 
    263                 if (!objmesh.mSubMesh[i].mBones.empty()) 
    264                 { 
    265                         for (unsigned int j = 0; j < objmesh.mSubMesh[i].mBones.size(); j++) 
    266                         { 
    267                                 mSubMesh[i].mBones.push_back(objmesh.mSubMesh[i].mBones[j]); 
     259                if (!mesh.mSubMesh[i].mBones.empty()) 
     260                { 
     261                        for (unsigned   int     j       =       0;      j < mesh.mSubMesh[i].mBones.size();     j++) 
     262                        { 
     263                                mSubMesh[i].mBones.push_back(mesh.mSubMesh[i].mBones[j]); 
    268264                        } 
    269265                } 
     
    271267 
    272268        //      Copy skeleton name. 
    273         if (objmesh.hasSkeleton) 
     269        if (mesh.hasSkeleton) 
    274270        { 
    275271                hasSkeleton     =       true; 
    276272                 
    277                 strcpy(mSkeletonName,objmesh.mSkeletonName); 
     273                strcpy(mSkeletonName,   mesh.mSkeletonName); 
    278274        } 
    279275 
    280276        //      Copy mesh bones. 
    281         if (!objmesh.mBones.empty()) 
    282         { 
    283                 for (unsigned int j = 0; j < objmesh.mBones.size(); j++) 
    284                 { 
    285                         mBones.push_back(objmesh.mBones[j]); 
     277        if (!mesh.mBones.empty()) 
     278        { 
     279                for (unsigned   int     j       =       0;      j < mesh.mBones.size(); j++) 
     280                { 
     281                        mBones.push_back(mesh.mBones[j]); 
    286282                } 
    287283        } 
     
    297293        bool sharedVertexBuffer = false; 
    298294 
    299         //Clear Data 
    300         delete[] mSubMesh;  mSubMesh = 0; 
    301         delete   mVertexBuffer; mVertexBuffer = 0; 
     295        //      Clear Data. 
     296        delete  []      mSubMesh; 
     297         
     298        mSubMesh = 0; 
     299         
     300        delete  mVertexBuffer; 
     301         
     302        mVertexBuffer = 0; 
    302303        mSubMeshCount = 0; 
    303304         
    304305        s.ReadArray(&sharedVertexBuffer,1); 
     306         
    305307        if (sharedVertexBuffer) 
    306308        { 
     
    308310                mVertexBuffer->Load(s); 
    309311        } 
    310         s.ReadArray(&mSubMeshCount,1); 
    311         mSubMesh = new SubMesh[mSubMeshCount]; 
    312         for(size_t i = 0; i < mSubMeshCount; ++i) 
     312         
     313        s.ReadArray(&mSubMeshCount,     1); 
     314         
     315        mSubMesh        =       new SubMesh[mSubMeshCount]; 
     316         
     317        for(size_t      i       =       0;      i < mSubMeshCount;      i++) 
    313318        { 
    314319                mSubMesh[i].Load(s); 
     320                 
    315321                if (mSubMesh[i].mSharedVertexBuffer && sharedVertexBuffer) 
    316322                { 
    317                         mSubMesh[i].mVertexBuffer = mVertexBuffer; 
     323                        mSubMesh[i].mVertexBuffer       =       mVertexBuffer; 
    318324                } 
    319325        } 
     
    325331void Mesh::Save(Serializer &s) 
    326332{ 
    327         bool sharedVertexBuffer = (mVertexBuffer != 0); 
     333        bool sharedVertexBuffer =       (mVertexBuffer != 0); 
     334         
    328335        s.WriteArray(&sharedVertexBuffer, 1); 
     336         
    329337        if (sharedVertexBuffer) 
    330338        { 
    331339                mVertexBuffer->Save(s); 
    332340        } 
     341         
    333342        s.WriteArray(&mSubMeshCount,1); 
    334         for(size_t i = 0; i < mSubMeshCount; ++i) 
     343         
     344        for(size_t      i       =       0;      i < mSubMeshCount;      i++) 
    335345        { 
    336346                mSubMesh[i].Save(s); 
     
    341351//      Export to obj mesh. 
    342352//--------------------------------------------------------------------------- 
    343 void Mesh::exportToOBJ(char *nomfich) 
    344 { 
    345         // Genera un fichero obj con vértices, triángulos 
    346  
    347         std::ofstream obj(nomfich); 
     353void Mesh::exportToOBJ(char *fileName) 
     354{ 
     355        std::ofstream obj(fileName); 
     356         
    348357        obj << "begin" << std::endl; 
    349         // Vértices 
    350         for (size_t i=0; i < mSubMeshCount; i++)  
    351         { 
    352                 for (size_t j=0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++)  
     358 
     359        // Vertices. 
     360        for (size_t     i       =       0;      i < mSubMeshCount;      i++) 
     361        { 
     362                for (size_t     j       =       0;      j < mSubMesh[i].mVertexBuffer->mVertexCount;    j++) 
    353363                {        
    354                         obj << "v " <<  mSubMesh[i].mVertexBuffer->mPosition[j].x << " " << 
    355                                 mSubMesh[i].mVertexBuffer->mPosition[j].y << " " << 
    356                                 mSubMesh[i].mVertexBuffer->mPosition[j].z << " " << std::endl; 
    357                 } 
    358         } 
    359  
    360  
    361         // Caras 
    362         for (size_t i=0; i < mSubMeshCount; i++)  
    363         { 
    364                 for (size_t j=0; j < mSubMesh[i].mIndexCount; j=j+3)  
     364                        obj     <<      "v " 
     365                                        <<      mSubMesh[i].mVertexBuffer->mPosition[j].x 
     366                                        <<      " " 
     367                                        <<      mSubMesh[i].mVertexBuffer->mPosition[j].y 
     368                                        <<      " " 
     369                                        <<      mSubMesh[i].mVertexBuffer->mPosition[j].z 
     370                                        <<      " " 
     371                                        <<      std::endl; 
     372                } 
     373        } 
     374 
     375        // Faces. 
     376        for (size_t     i       =       0;      i < mSubMeshCount;      i++) 
     377        { 
     378                for (size_t     j = 0;  j < mSubMesh[i].mIndexCount;    j       =       j + 3) 
    365379                {        
    366                         obj << "f " <<  mSubMesh[i].mIndex[j]+1 << " " <<  
    367                                 mSubMesh[i].mIndex[j+1]+1 << " " <<  
    368                                 mSubMesh[i].mIndex[j+2]+1 << std::endl; 
    369                 } 
    370         } 
    371  
    372         obj << "end" << std::endl; 
     380                        obj     <<      "f " 
     381                                        <<      mSubMesh[i].mIndex[j] + 1 
     382                                        <<      " "      
     383                                        <<      mSubMesh[i].mIndex[j + 1] + 1 
     384                                        <<      " " 
     385                                        <<      mSubMesh[i].mIndex[j + 2] + 1 
     386                                        <<      std::endl; 
     387                } 
     388        } 
     389 
     390        obj     <<      "end"   <<      std::endl; 
     391         
    373392        obj.close(); 
    374393} 
     
    380399{ 
    381400        // Move all vertex to the shared vertex buffer. 
    382         Mesh *mesh = new Mesh(); 
     401        Mesh    *mesh   =       new Mesh(); 
    383402 
    384403        if (mSubMesh[0].mSharedVertexBuffer) 
     
    390409         
    391410        mesh->mVertexBuffer     =       new VertexBuffer(); 
    392         mesh->mSubMeshCount =   mSubMeshCount; 
    393          
    394         // Reserva memoria para los submeshes 
    395         mesh->mSubMesh  =       new SubMesh[mSubMeshCount]; 
     411        mesh->mSubMeshCount     =       mSubMeshCount; 
     412        mesh->mSubMesh                  =       new SubMesh[mSubMeshCount]; 
    396413 
    397414        //      Fill up bounding box settings. 
     
    418435                strcpy(mesh->mSubMesh[i].mMaterialName,mSubMesh[i].mMaterialName); 
    419436                 
    420                 // copiar los índices 
     437                // Copy indices. 
    421438                mesh->mSubMesh[i].mIndexCount   =       mSubMesh[i].mIndexCount; 
    422439                mesh->mSubMesh[i].mIndex                        =       new Index[mSubMesh[i].mIndexCount]; 
     
    429446                acumVerts       +=      long(mSubMesh[i].mVertexBuffer->mVertexCount); 
    430447 
    431                 // Copiar las tiras 
    432                 int offset      =       0; // desplazamiento entre posiciones de memoria. 
     448                // Copy strips. 
     449                int offset      =       0; 
    433450                 
    434451                mesh->mSubMesh[i].mStripCount   =       mSubMesh[i].mStripCount; 
     
    440457                        offset  =       int(&(mesh->mSubMesh[i].mIndex[0]) - &(mSubMesh[i].mIndex[0])); 
    441458                         
    442                         for (size_t j = 0;      j < mSubMesh[i].mStripCount;    j++) 
    443                         { 
    444                                 mesh->mSubMesh[i].mStrip[j] = mSubMesh[i].mStrip[j] + offset; 
     459                        for (size_t     j       =       0;      j < mSubMesh[i].mStripCount;    j++) 
     460                        { 
     461                                mesh->mSubMesh[i].mStrip[j]     =       mSubMesh[i].mStrip[j] + offset; 
    445462                        } 
    446463                } 
     
    454471        mesh->mVertexBuffer->mTexCoords         =       new Vector2[mesh->mVertexBuffer->mVertexCount]; 
    455472 
    456         // copiar los vértices 
    457473        acumVerts       =       0; 
    458474         
    459475        size_t  newIndex; 
    460476         
    461         for (size_t i = 0; i < mSubMeshCount;   i++) 
    462         { 
    463                 for(size_t j = 0; j < mSubMesh[i].mVertexBuffer->mVertexCount; j++) 
     477        for (size_t     i       =       0;      i < mSubMeshCount;      i++) 
     478        { 
     479                for     (size_t j       =       0;      j < mSubMesh[i].mVertexBuffer->mVertexCount;    j++) 
    464480                { 
    465481                        newIndex        =       acumVerts + j; 
Note: See TracChangeset for help on using the changeset viewer.