- Timestamp:
- 07/17/06 14:24:24 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshLoader.cpp
r1098 r1136 49 49 unsigned short source; 50 50 GeometryElement aux; 51 inti;51 size_t i; 52 52 bool found; 53 53 VertexElementType vType; 54 54 55 i 55 i = 0; 56 56 found = false; 57 57 … … 162 162 unsigned short vertexSize; 163 163 unsigned short headerID; 164 inti;165 float aux;166 intk;164 size_t i; 165 //float aux; 166 size_t k; 167 167 bool found; 168 168 float x,y,z; … … 170 170 VertexBuffer *vertex_buffer; 171 171 172 i 173 k 172 i = 0; 173 k = 0; 174 174 found = false; 175 175 … … 228 228 { 229 229 // 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++) 231 231 { 232 232 // Positions. … … 466 466 unsigned int aux; 467 467 468 for ( inti = 0; i < numIndices; i++)468 for (size_t i = 0; i < numIndices; i++) 469 469 { 470 470 fread(&aux,sizeof(unsigned int),1,f); … … 472 472 if (option == GEOMESH_BUILD) 473 473 { 474 474 geoSubMesh->mIndex[i] = aux; 475 475 } 476 476 } … … 480 480 unsigned short aux; 481 481 482 for ( inti = 0; i < numIndices; i++)482 for (size_t i = 0; i < numIndices; i++) 483 483 { 484 484 fread(&aux,sizeof(unsigned short),1,f); … … 866 866 bool head_found; 867 867 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; 872 871 873 872 head_found = false; … … 877 876 // Foreachone of the indices. 878 877 // Obtains the number of triangle strips. 879 for ( inti = 0; i < (geoSubMesh->mIndexCount - 1); i++)878 for (size_t i = 0; i < (geoSubMesh->mIndexCount - 1); i++) 880 879 { 881 880 if (geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1]) … … 906 905 } 907 906 908 geoSubMesh->mStrip 909 *910 geoSubMesh->mStripCount);907 geoSubMesh->mStrip = (Index**) malloc( sizeof(Index*) 908 * 909 geoSubMesh->mStripCount); 911 910 912 911 // Number of strips. Initially there is one triangle strip. 913 912 strip_count = 1; 914 915 head_found = false; 916 tail_found = false; 913 head_found = false; 914 tail_found = false; 917 915 918 916 // Initialize the fist triangle strip. … … 921 919 // Foreachone of the indices. 922 920 // Assigns the beginning of the triangle strips. 923 for( inti = 0;i < (geoSubMesh->mIndexCount - 1); i++)921 for(size_t i = 0;i < (geoSubMesh->mIndexCount - 1); i++) 924 922 { 925 923 if(geoSubMesh->mIndex[i] == geoSubMesh->mIndex[i+1]) … … 991 989 992 990 // For each one of the strips. 993 for ( intstrip = 0; strip < geoSubMesh->mStripCount; strip++)991 for (size_t strip = 0; strip < geoSubMesh->mStripCount; strip++) 994 992 { 995 993 // Stars of strip without degenerate triangles. 996 new_strip_starts[strip] = current_index;994 new_strip_starts[strip] = (Index)current_index; 997 995 998 996 // First index of the strip. … … 1055 1053 1056 1054 // Update start of the strip. 1057 for ( int strip = 0; strip < geoSubMesh->mStripCount; strip++)1055 for (size_t strip = 0; strip < geoSubMesh->mStripCount; strip++) 1058 1056 { 1059 1057 geoSubMesh->mStrip[strip] = &geoSubMesh->mIndex[new_strip_starts[strip]]; … … 1074 1072 unsigned short chunkID; 1075 1073 char version[255]; 1076 char kk;1077 1074 FILE *pFile; 1078 1075 SubMesh *geosubmesh; … … 1196 1193 if (!mError) 1197 1194 { 1198 for ( intsubmesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)1195 for (size_t submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 1199 1196 { 1200 1197 // Gets the actual submesh. … … 1238 1235 void GeoMeshLoader::normalizeModel(Mesh *geoMesh) 1239 1236 { 1240 unsigned int i;1241 1237 float maxx, minx, maxy, miny, maxz, minz; 1242 1238 float cx, cy, cz, w, h, d, max; … … 1253 1249 1254 1250 // For each submesh. 1255 for ( intsubmesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)1251 for (size_t submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 1256 1252 { 1257 1253 // Gets the actual submesh. … … 1259 1255 1260 1256 // For each index of the strip. 1261 for ( inti = 0; i < vertex_buffer->mVertexCount; i++)1257 for (size_t i = 0; i < vertex_buffer->mVertexCount; i++) 1262 1258 { 1263 1259 if (maxx < vertex_buffer->mPosition[i].x) … … 1305 1301 1306 1302 // 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; 1310 1306 1311 1307 … … 1326 1322 1327 1323 // Calculate unitizing scale factor. 1328 scale = 1.0 / max;1324 scale = 1.0f / max; 1329 1325 1330 1326 geoMesh->mMeshBounds.scaleFactor = scale; 1331 1327 1332 1328 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++) 1337 1336 { 1338 1337 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 1339 sharedmesh[submesh]= true; 1338 { 1339 sharedmesh[submesh] = true; 1340 } 1340 1341 else 1341 sharedmesh[submesh]= false; 1342 { 1343 sharedmesh[submesh] = false; 1344 } 1342 1345 } 1343 1346 1344 1347 // Translate around center then scale. 1345 1348 // 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 { 1349 1351 // If is a shared vertex Buffer. 1350 1352 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 1351 1353 { 1352 1354 if (!firstsharedmesh) 1355 { 1353 1356 continue; 1357 } 1354 1358 else 1355 firstsharedmesh= false; 1359 { 1360 firstsharedmesh = false; 1361 } 1356 1362 } 1357 1363 … … 1360 1366 1361 1367 // 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++) 1363 1369 { 1364 1370 vertex_buffer->mPosition[i].x -= cx; … … 1369 1375 vertex_buffer->mPosition[i].z *= scale; 1370 1376 } 1371 1372 1377 } 1373 1378 … … 1388 1393 GeoMeshLoader::GeoMeshLoader() 1389 1394 { 1390 geoMesh = NULL;1391 mFileSize = 0;1395 geoMesh = NULL; 1396 mFileSize = 0; 1392 1397 lodstripsdata = NULL; 1393 1398 treesimpseq = NULL; … … 1400 1405 { 1401 1406 if (geoMesh) 1407 { 1402 1408 delete geoMesh; 1409 } 1410 1403 1411 if (lodstripsdata) 1412 { 1404 1413 delete lodstripsdata; 1414 } 1415 1405 1416 if (treesimpseq) 1417 { 1406 1418 delete treesimpseq; 1419 } 1407 1420 } 1408 1421 … … 1410 1423 // Read bones of the submesh. 1411 1424 //--------------------------------------------------------------------------- 1412 void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, SubMesh* geoSubMesh,int option) 1425 void GeoMeshLoader::readSubMeshBoneAssignment(FILE* f, 1426 SubMesh* geoSubMesh, 1427 int option) 1413 1428 { 1414 1429 if (option == GEOMESH_BUILD) … … 1442 1457 // float weight 1443 1458 fread(&(assign.weight),sizeof(float),1,f); 1444 1445 1459 1446 1460 geoMesh->mBones.push_back(assign); … … 1493 1507 { 1494 1508 public: 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 { 1503 1524 delete[] current_tris; 1504 1525 } … … 1517 1538 if (res==vertex_map.end()) 1518 1539 { 1519 int val = vertex_map.size();1540 int val = (int)vertex_map.size(); 1520 1541 vertex_map[vertex1] = val; 1521 1542 submesh->mIndex[j*3+0] = val; … … 1527 1548 if (res==vertex_map.end()) 1528 1549 { 1529 int val = vertex_map.size();1550 int val = (int)vertex_map.size(); 1530 1551 vertex_map[vertex2] = val; 1531 1552 submesh->mIndex[j*3+1] = val; … … 1537 1558 if (res==vertex_map.end()) 1538 1559 { 1539 int val = vertex_map.size();1560 int val = (int)vertex_map.size(); 1540 1561 vertex_map[vertex3] = val; 1541 1562 submesh->mIndex[j*3+2] = val; 1542 1563 } 1543 1564 else 1565 { 1544 1566 submesh->mIndex[j*3+2] = res->second; 1567 } 1545 1568 1546 1569 current_tris[current_submesh] ++; 1547 1570 } 1548 1571 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 } 1552 1581 1553 1582 class vertex_arranger_node … … 1605 1634 vertex_list[it->second] = it->first; 1606 1635 1607 for (int i=0; i<mesh->mSubMeshCount; i++) 1636 for ( size_t i = 0; i < mesh->mSubMeshCount; i++) 1637 { 1608 1638 mesh->mSubMesh[i].mVertexBuffer = mesh->mVertexBuffer; 1639 } 1609 1640 1610 for ( int j=0; j<mesh->mVertexBuffer->mVertexCount;j++)1641 for (size_t j = 0; j < mesh->mVertexBuffer->mVertexCount; j++) 1611 1642 { 1612 1643 int vi = vertex_list[j].v; … … 1615 1646 1616 1647 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 } 1628 1686 } 1629 1687 … … 1632 1690 1633 1691 //private: 1634 std::map<vertex_arranger_node,int> 1635 Geometry::Mesh 1636 int 1637 int 1692 std::map<vertex_arranger_node,int> vertex_map; 1693 Geometry::Mesh *mesh; 1694 int current_submesh; 1695 int *current_tris; 1638 1696 }; 1639 1697 … … 1734 1792 { 1735 1793 // 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++) 1737 1795 { 1738 1796 Geometry::SubMesh *submesh = mesh->mSubMesh+i; … … 1742 1800 { 1743 1801 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 1747 1807 Geometry::Vector3 v1,v2,v3,v31,v21,nor; 1748 1808 v1 = vertices[auxface.v1]; … … 1763 1823 1764 1824 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++) 1766 1826 { 1767 1827 Geometry::SubMesh *submesh = mesh->mSubMesh+i; … … 1773 1833 submesh->mIndex=new Geometry::Index[submesh->mIndexCount]; 1774 1834 1775 vertex_arranger.SetCurrentSubMesh( i);1835 vertex_arranger.SetCurrentSubMesh((int)i); 1776 1836 1777 1837 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.