Ignore:
Timestamp:
07/17/06 14:24:24 (18 years ago)
Author:
gumbau
Message:
 
File:
1 edited

Legend:

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

    r1098 r1136  
    4949        unsigned        short           source; 
    5050        GeometryElement         aux; 
    51         int                                                             i; 
     51        size_t                                          i; 
    5252        bool                                                    found; 
    5353        VertexElementType       vType; 
    5454 
    55         i                                               =       0; 
     55        i                       =       0; 
    5656        found   =       false; 
    5757 
     
    162162        unsigned        short   vertexSize; 
    163163        unsigned        short   headerID; 
    164         int                                                     i; 
    165         float                                           aux; 
    166         int                                                     k; 
     164        size_t                                  i; 
     165        //float                                         aux; 
     166        size_t                                  k; 
    167167        bool                                            found; 
    168168        float                                           x,y,z; 
     
    170170        VertexBuffer            *vertex_buffer; 
    171171 
    172         i                                               =       0; 
    173         k                                               =       0; 
     172        i                       =       0; 
     173        k                       =       0; 
    174174        found   =       false; 
    175175         
     
    228228                { 
    229229                        //      For each element in this source. 
    230                         for(int j       =       0;      j < list[i].list.size();        j++) 
     230                        for(size_t j    =       0;      j < list[i].list.size();        j++) 
    231231                        { 
    232232                                //      Positions. 
     
    466466                unsigned int aux; 
    467467 
    468                 for (int i = 0; i < numIndices; i++) 
     468                for (size_t     i = 0; i < numIndices; i++) 
    469469                { 
    470470                        fread(&aux,sizeof(unsigned int),1,f); 
     
    472472                        if (option == GEOMESH_BUILD) 
    473473                        { 
    474                                         geoSubMesh->mIndex[i]   =       aux; 
     474                                geoSubMesh->mIndex[i]   =       aux; 
    475475                        } 
    476476                } 
     
    480480                unsigned short aux; 
    481481 
    482                 for (int i = 0; i < numIndices; i++) 
     482                for (size_t     i = 0; i < numIndices; i++) 
    483483                { 
    484484                        fread(&aux,sizeof(unsigned short),1,f); 
     
    866866        bool            head_found; 
    867867        bool            tail_found; 
    868         int                     strip_count; 
    869         int                     tailIndex; 
    870         size_t  tail; 
    871  
     868        size_t  strip_count; 
     869        size_t  tailIndex; 
     870        //size_t        tail; 
    872871 
    873872        head_found                                                      =       false; 
     
    877876        //      Foreachone of the indices. 
    878877        //      Obtains the number of triangle strips. 
    879         for (int i = 0; i < (geoSubMesh->mIndexCount - 1); i++) 
     878        for (size_t     i = 0; i < (geoSubMesh->mIndexCount - 1); i++) 
    880879        { 
    881880                if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1]) 
     
    906905        } 
    907906 
    908         geoSubMesh->mStrip              =       (Index**) malloc(       sizeof(Index*) 
    909                         * 
    910                         geoSubMesh->mStripCount); 
     907        geoSubMesh->mStrip      =       (Index**) malloc(       sizeof(Index*) 
     908                                                                                                * 
     909                                                                                                geoSubMesh->mStripCount); 
    911910 
    912911        //      Number of strips. Initially there is one triangle strip. 
    913912        strip_count     =       1; 
    914  
    915         head_found                                              =       false; 
    916         tail_found                                              =       false; 
     913        head_found      =       false; 
     914        tail_found      =       false; 
    917915 
    918916        //      Initialize the fist triangle strip. 
     
    921919        //      Foreachone of the indices. 
    922920        //      Assigns the beginning of the triangle strips. 
    923         for(int i = 0;i < (geoSubMesh->mIndexCount - 1); i++) 
     921        for(size_t      i = 0;i < (geoSubMesh->mIndexCount - 1); i++) 
    924922        { 
    925923                if(geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1]) 
     
    991989         
    992990        //      For each one of the strips. 
    993         for (int strip = 0; strip < geoSubMesh->mStripCount; strip++) 
     991        for (size_t     strip = 0; strip < geoSubMesh->mStripCount; strip++) 
    994992        { 
    995993                //      Stars of strip without degenerate triangles. 
    996                 new_strip_starts[strip] =       current_index; 
     994                new_strip_starts[strip] =       (Index)current_index; 
    997995                 
    998996                //      First index of the strip. 
     
    10551053 
    10561054        //      Update start of the strip. 
    1057         for (int        strip   =       0; strip < geoSubMesh->mStripCount; strip++) 
     1055        for (size_t     strip   =       0; strip < geoSubMesh->mStripCount; strip++) 
    10581056        { 
    10591057                geoSubMesh->mStrip[strip]       =       &geoSubMesh->mIndex[new_strip_starts[strip]]; 
     
    10741072        unsigned        short   chunkID; 
    10751073        char            version[255]; 
    1076         char            kk; 
    10771074        FILE            *pFile; 
    10781075        SubMesh         *geosubmesh; 
     
    11961193                if (!mError) 
    11971194                { 
    1198                         for (int submesh = 0;   submesh < geoMesh->mSubMeshCount; submesh++) 
     1195                        for (size_t     submesh = 0;    submesh < geoMesh->mSubMeshCount; submesh++) 
    11991196                        { 
    12001197                                //      Gets the actual submesh. 
     
    12381235void    GeoMeshLoader::normalizeModel(Mesh      *geoMesh) 
    12391236{ 
    1240         unsigned        int     i; 
    12411237        float                                   maxx, minx, maxy, miny, maxz, minz; 
    12421238        float                                   cx, cy, cz, w, h, d, max; 
     
    12531249         
    12541250        //      For each submesh. 
    1255         for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     1251        for (size_t     submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
    12561252        { 
    12571253                //      Gets the actual submesh. 
     
    12591255 
    12601256                //      For each index of the strip. 
    1261                 for (int i = 0; i < vertex_buffer->mVertexCount; i++) 
     1257                for (size_t     i = 0; i < vertex_buffer->mVertexCount; i++) 
    12621258                { 
    12631259                        if (maxx < vertex_buffer->mPosition[i].x) 
     
    13051301 
    13061302        //      Calculate center of the model. 
    1307         cx = (maxx + minx) / 2.0; 
    1308         cy = (maxy + miny) / 2.0; 
    1309         cz = (maxz + minz) / 2.0; 
     1303        cx = (maxx + minx) / 2.0f; 
     1304        cy = (maxy + miny) / 2.0f; 
     1305        cz = (maxz + minz) / 2.0f; 
    13101306 
    13111307 
     
    13261322         
    13271323        //      Calculate unitizing scale factor. 
    1328         scale = 1.0 / max; 
     1324        scale = 1.0f / max; 
    13291325 
    13301326        geoMesh->mMeshBounds.scaleFactor                =       scale; 
    13311327 
    13321328 
    1333         bool *sharedmesh; 
    1334         sharedmesh= new bool[geoMesh->mSubMeshCount]; 
    1335         bool firstsharedmesh= true; 
    1336         for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     1329        bool    *sharedmesh; 
     1330 
     1331        sharedmesh      =       new bool[geoMesh->mSubMeshCount]; 
     1332 
     1333        bool    firstsharedmesh =       true; 
     1334 
     1335        for (size_t     submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
    13371336        { 
    13381337                if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 
    1339                         sharedmesh[submesh]= true; 
     1338                { 
     1339                        sharedmesh[submesh]     =       true; 
     1340                } 
    13401341                else 
    1341                         sharedmesh[submesh]= false; 
     1342                { 
     1343                        sharedmesh[submesh]     =       false; 
     1344                } 
    13421345        } 
    13431346 
    13441347        //      Translate around center then scale. 
    13451348        //      For each submesh. 
    1346         for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
    1347         { 
    1348  
     1349        for (size_t     submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 
     1350        { 
    13491351                //      If is a shared vertex Buffer. 
    13501352                if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 
    13511353                { 
    13521354                        if (!firstsharedmesh) 
     1355                        { 
    13531356                                continue; 
     1357                        } 
    13541358                        else 
    1355                                 firstsharedmesh= false; 
     1359                        { 
     1360                                firstsharedmesh =       false; 
     1361                        } 
    13561362                } 
    13571363 
     
    13601366 
    13611367                //      For each index of the strip. 
    1362                 for (int i = 0; i < vertex_buffer->mVertexCount; i++) 
     1368                for (size_t     i       =       0;      i < vertex_buffer->mVertexCount;        i++) 
    13631369                { 
    13641370                        vertex_buffer->mPosition[i].x -= cx; 
     
    13691375                        vertex_buffer->mPosition[i].z *= scale; 
    13701376                } 
    1371  
    13721377        } 
    13731378 
     
    13881393GeoMeshLoader::GeoMeshLoader() 
    13891394{ 
    1390         geoMesh                 =       NULL; 
    1391         mFileSize               =       0; 
     1395        geoMesh                         =       NULL; 
     1396        mFileSize                       =       0; 
    13921397        lodstripsdata   =       NULL; 
    13931398        treesimpseq             =       NULL; 
     
    14001405{ 
    14011406        if (geoMesh) 
     1407        { 
    14021408                delete  geoMesh; 
     1409        } 
     1410 
    14031411        if (lodstripsdata) 
     1412        { 
    14041413                delete lodstripsdata; 
     1414        } 
     1415 
    14051416        if (treesimpseq) 
     1417        { 
    14061418                delete treesimpseq; 
     1419        } 
    14071420} 
    14081421 
     
    14101423//      Read bones of the submesh. 
    14111424//--------------------------------------------------------------------------- 
    1412 void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, SubMesh* geoSubMesh,int option) 
     1425void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, 
     1426                                                                                                                                                                                        SubMesh* geoSubMesh, 
     1427                                                                                                                                                                                        int option) 
    14131428{ 
    14141429        if (option == GEOMESH_BUILD) 
     
    14421457                // float weight 
    14431458                fread(&(assign.weight),sizeof(float),1,f); 
    1444  
    14451459 
    14461460                geoMesh->mBones.push_back(assign); 
     
    14931507{ 
    14941508public: 
    1495         VertexArranger(Geometry::Mesh *m){ 
    1496                 mesh=m; 
    1497                 current_submesh=0; 
    1498                 current_tris=new int[m->mSubMeshCount]; 
    1499                 for (int i=0; i<m->mSubMeshCount; i++) 
    1500                         current_tris[i] = 0; 
    1501         } 
    1502         ~VertexArranger(void){ 
     1509 
     1510        VertexArranger(Geometry::Mesh *m) 
     1511        { 
     1512                mesh                                            =       m; 
     1513                current_submesh =       0; 
     1514                current_tris            =       new int[m->mSubMeshCount]; 
     1515 
     1516                for (size_t     i       =       0;      i < m->mSubMeshCount;   i++) 
     1517                { 
     1518                        current_tris[i] =       0; 
     1519                } 
     1520        } 
     1521 
     1522        ~VertexArranger(void) 
     1523        { 
    15031524                delete[] current_tris; 
    15041525        } 
     
    15171538                if (res==vertex_map.end()) 
    15181539                { 
    1519                         int val = vertex_map.size(); 
     1540                        int val = (int)vertex_map.size(); 
    15201541                        vertex_map[vertex1] = val; 
    15211542                        submesh->mIndex[j*3+0] = val; 
     
    15271548                if (res==vertex_map.end()) 
    15281549                { 
    1529                         int val = vertex_map.size(); 
     1550                        int val = (int)vertex_map.size(); 
    15301551                        vertex_map[vertex2] = val; 
    15311552                        submesh->mIndex[j*3+1] = val; 
     
    15371558                if (res==vertex_map.end()) 
    15381559                { 
    1539                         int val = vertex_map.size(); 
     1560                        int val = (int)vertex_map.size(); 
    15401561                        vertex_map[vertex3] = val; 
    15411562                        submesh->mIndex[j*3+2] = val; 
    15421563                } 
    15431564                else 
     1565                { 
    15441566                        submesh->mIndex[j*3+2] = res->second; 
     1567                } 
    15451568 
    15461569                current_tris[current_submesh] ++; 
    15471570        } 
    15481571 
    1549         int GetVertexCount(void) const { return vertex_map.size(); } 
    1550  
    1551         void SetCurrentSubMesh(int i){ current_submesh = i; } 
     1572        int GetVertexCount(void) const 
     1573        { 
     1574                return (int)vertex_map.size(); 
     1575        } 
     1576 
     1577        void SetCurrentSubMesh(int i) 
     1578        { 
     1579                current_submesh = i; 
     1580        } 
    15521581         
    15531582        class vertex_arranger_node 
     
    16051634                        vertex_list[it->second] = it->first; 
    16061635 
    1607                 for (int i=0; i<mesh->mSubMeshCount; i++) 
     1636                for (   size_t  i       =       0;      i < mesh->mSubMeshCount;        i++) 
     1637                { 
    16081638                        mesh->mSubMesh[i].mVertexBuffer = mesh->mVertexBuffer; 
     1639                } 
    16091640                 
    1610                 for (int j=0; j<mesh->mVertexBuffer->mVertexCount; j++) 
     1641                for (size_t     j       =       0;      j < mesh->mVertexBuffer->mVertexCount;  j++) 
    16111642                {                
    16121643                        int vi = vertex_list[j].v; 
     
    16151646 
    16161647                        Geometry::Vector3 auxpos(vertices[vi]); 
    1617                         if (auxpos.x < mesh->mMeshBounds.minX) mesh->mMeshBounds.minX = auxpos.x; 
    1618                         if (auxpos.y < mesh->mMeshBounds.minY) mesh->mMeshBounds.minY = auxpos.y; 
    1619                         if (auxpos.z < mesh->mMeshBounds.minZ) mesh->mMeshBounds.minZ = auxpos.z; 
    1620                         if (auxpos.x > mesh->mMeshBounds.maxX) mesh->mMeshBounds.maxX = auxpos.x; 
    1621                         if (auxpos.y > mesh->mMeshBounds.maxY) mesh->mMeshBounds.maxY = auxpos.y; 
    1622                         if (auxpos.z > mesh->mMeshBounds.maxZ) mesh->mMeshBounds.maxZ = auxpos.z; 
    1623  
    1624                         mesh->mVertexBuffer->mPosition[j] = auxpos; 
    1625                         mesh->mVertexBuffer->mNormal[j] = normals[ni]; 
    1626                         if (texcoords.empty()==false) 
    1627                                 mesh->mVertexBuffer->mTexCoords[j] = texcoords[ti];              
     1648 
     1649                        if (auxpos.x < mesh->mMeshBounds.minX) 
     1650                        { 
     1651                                mesh->mMeshBounds.minX = auxpos.x; 
     1652                        } 
     1653 
     1654                        if (auxpos.y < mesh->mMeshBounds.minY) 
     1655                        { 
     1656                                mesh->mMeshBounds.minY = auxpos.y; 
     1657                        } 
     1658 
     1659                        if (auxpos.z < mesh->mMeshBounds.minZ) 
     1660                        { 
     1661                                mesh->mMeshBounds.minZ = auxpos.z; 
     1662                        } 
     1663 
     1664                        if (auxpos.x > mesh->mMeshBounds.maxX) 
     1665                        { 
     1666                                mesh->mMeshBounds.maxX = auxpos.x; 
     1667                        } 
     1668 
     1669                        if (auxpos.y > mesh->mMeshBounds.maxY) 
     1670                        { 
     1671                                mesh->mMeshBounds.maxY = auxpos.y; 
     1672                        } 
     1673 
     1674                        if (auxpos.z > mesh->mMeshBounds.maxZ) 
     1675                        { 
     1676                                mesh->mMeshBounds.maxZ = auxpos.z; 
     1677                        } 
     1678 
     1679                        mesh->mVertexBuffer->mPosition[j]       =       auxpos; 
     1680                        mesh->mVertexBuffer->mNormal[j]         =       normals[ni]; 
     1681 
     1682                        if (texcoords.empty() == false) 
     1683                        { 
     1684                                mesh->mVertexBuffer->mTexCoords[j] = texcoords[ti]; 
     1685                        } 
    16281686                } 
    16291687 
     
    16321690 
    16331691//private: 
    1634         std::map<vertex_arranger_node,int> vertex_map; 
    1635         Geometry::Mesh *mesh; 
    1636         int current_submesh; 
    1637         int *current_tris; 
     1692        std::map<vertex_arranger_node,int>      vertex_map; 
     1693        Geometry::Mesh                                                                                  *mesh; 
     1694        int                                                                                                                                     current_submesh; 
     1695        int                                                                                                                                     *current_tris; 
    16381696}; 
    16391697 
     
    17341792        { 
    17351793                // calculate face normals 
    1736                 for (int i=0, inormal=0; i<mesh->mSubMeshCount; i++) 
     1794                for (size_t i=0, inormal=0; i<mesh->mSubMeshCount; i++) 
    17371795                { 
    17381796                        Geometry::SubMesh *submesh = mesh->mSubMesh+i; 
     
    17421800                        { 
    17431801                                face_t & auxface = *it; 
    1744                                 auxface.n1 = inormal; 
    1745                                 auxface.n2 = inormal; 
    1746                                 auxface.n3 = inormal; 
     1802 
     1803                                auxface.n1 = (int)inormal; 
     1804                                auxface.n2 = (int)inormal; 
     1805                                auxface.n3 = (int)inormal; 
     1806 
    17471807                                Geometry::Vector3 v1,v2,v3,v31,v21,nor; 
    17481808                                v1 = vertices[auxface.v1]; 
     
    17631823                  
    17641824        mesh->mSubMesh=new Geometry::SubMesh[mesh->mSubMeshCount]; 
    1765         for (int i=0; i<mesh->mSubMeshCount; i++) 
     1825        for (size_t     i       =       0;      i < mesh->mSubMeshCount;        i++) 
    17661826        { 
    17671827                Geometry::SubMesh *submesh = mesh->mSubMesh+i; 
     
    17731833                submesh->mIndex=new Geometry::Index[submesh->mIndexCount]; 
    17741834 
    1775                 vertex_arranger.SetCurrentSubMesh(i); 
     1835                vertex_arranger.SetCurrentSubMesh((int)i); 
    17761836                 
    17771837                for (std::vector<face_t>::const_iterator it=vecfaces.begin(); it!=vecfaces.end(); it++,j++) 
Note: See TracChangeset for help on using the changeset viewer.