Changeset 1136 for GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Timestamp:
- 07/17/06 14:24:24 (18 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared/GTGeometry/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsConstructor.cpp
r1090 r1136 612 612 void LodStripsConstructor::Save(std::string filename) 613 613 { 614 unsigned int i, j;615 int 616 char 617 618 int vertexCount =this->cVerts.size();619 int changesCount =this->cCambios.size();620 int dataCount =this->cDatos.size();621 int cambiosCount =this->TOTALCAMBIOS;622 int size 614 //size_t i, j; 615 int k = 0; 616 char simp[256]; 617 618 int vertexCount = (int)this->cVerts.size(); 619 int changesCount = (int)this->cCambios.size(); 620 int dataCount = (int)this->cDatos.size(); 621 int cambiosCount = this->TOTALCAMBIOS; 622 int size = changesCount*sizeof(LODData) + 623 623 (vertexCount + dataCount + cambiosCount + 4)*sizeof(int) + 624 624 CHUNK_OVERHEAD_SIZE; … … 631 631 632 632 fwrite(&vertexCount, sizeof(int), 1, f); 633 for( i = 0; i < this->cVerts.size(); i++)633 for(size_t i = 0; i < this->cVerts.size(); i++) 634 634 { 635 635 int auxv = cVerts[i].Next; … … 648 648 this->TOTALINDICES = 0; 649 649 650 for( i = 0; i < this->cStrips.size(); i++)650 for(size_t i = 0; i < this->cStrips.size(); i++) 651 651 { 652 652 this->TOTALINDICES += int(this->cStrips[i].size()); … … 656 656 // Changes 657 657 fwrite(&changesCount, sizeof(int), 1, f); 658 for( i = 0; i < this->cCambios.size(); i++)658 for(size_t i = 0; i < this->cCambios.size(); i++) 659 659 { 660 660 LODData change= cCambios[i]; … … 682 682 683 683 fwrite(&dataCount, sizeof(int), 1, f); 684 for(i = 0; i < this->cDatos.size(); i++) 684 685 for(size_t i = 0; i < this->cDatos.size(); i++) 685 686 { 686 687 int data= cDatos[i]; … … 698 699 } 699 700 */ 700 701 701 702 702 // lines starting with a p. 703 703 // Chages made in a LOD. 704 704 fwrite(&cambiosCount, sizeof(int), 1, f); 705 for(i = 0; i < this->TOTALCAMBIOS; i++) 705 706 for(size_t i = 0; i < this->TOTALCAMBIOS; i++) 706 707 { 707 708 int cambio= pCambios[i]; … … 710 711 711 712 fclose(f); 712 713 713 714 714 /* … … 1247 1247 { 1248 1248 int num_no = 0; 1249 int i=0,j=0;1249 //int i=0,j=0; 1250 1250 1251 1251 if(this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer == true) … … 1272 1272 this->mGeoMesh->mVertexBuffer->mVertexInfo = this->meshoriginal->mSubMesh[0].mVertexBuffer->mVertexInfo; 1273 1273 1274 for( i = 0; i < this->mGeoMesh->mSubMeshCount; i++)1275 { 1276 this->mGeoMesh->mSubMesh[i].mVertexBuffer 1274 for(size_t i = 0; i < this->mGeoMesh->mSubMeshCount; i++) 1275 { 1276 this->mGeoMesh->mSubMesh[i].mVertexBuffer = this->mGeoMesh->mVertexBuffer; 1277 1277 this->mGeoMesh->mSubMesh[i].mSharedVertexBuffer = true; 1278 1278 } … … 1280 1280 int indice = 0; 1281 1281 1282 for ( j = 0; j < this->cVerts.size();j++)1282 for (size_t j = 0; j < this->cVerts.size(); j++) 1283 1283 { 1284 1284 //Copiamos las coordeandas de posicion … … 1335 1335 this->mGeoMesh->mSubMesh[0].mSharedVertexBuffer=false; 1336 1336 1337 int indice=0; 1338 for (j=0; j<this->cVerts.size(); j++) 1337 int indice = 0; 1338 1339 for (size_t j = 0; j < this->cVerts.size(); j++) 1339 1340 { 1340 1341 //Copiamos las coordeandas de posicion … … 1362 1363 } 1363 1364 1364 1365 1366 1365 int indice_acum = 0; 1367 for(i=0;i<this->mGeoMesh->mSubMeshCount;i++) 1366 1367 for(size_t i = 0; i < this->mGeoMesh->mSubMeshCount; i++) 1368 1368 { 1369 1369 Geometry::SubMesh & subMesh = meshoriginal->mSubMesh[i]; … … 1435 1435 } 1436 1436 } 1437 1438 1437 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
r1090 r1136 439 439 void LodStripsLibrary::LoadStripMesh(const LodStripsLibraryData *lodstripsdata, Mesh *geomesh) 440 440 { 441 FILE *fp;441 //FILE *fp; 442 442 SmallIntVector strip_aux; 443 LODRegisterType lod_register;443 //LODRegisterType lod_register; 444 444 std::vector <LODRegisterType> list_pos; 445 445 std::vector <unsigned int> p_changes; 446 int value;446 //int value; 447 447 int v = 0; 448 448 int t = -1; … … 450 450 int next = 0; 451 451 int c = -1; 452 char buff[80];452 //char buff[80]; 453 453 Index *index; 454 454 Index *indexBegin; … … 578 578 579 579 mStripsSubmesh = new int [geomesh->mSubMeshCount]; 580 for ( intsubmesh = 0; submesh < geomesh->mSubMeshCount; submesh++)580 for (size_t submesh = 0; submesh < geomesh->mSubMeshCount; submesh++) 581 581 { 582 582 mStripsSubmesh[submesh]=0; … … 612 612 dataRetrievalInterface->Begin(); 613 613 614 int counter =0;615 int target_submesh =0;616 int strip_count =0;617 618 for (unsigned int i=0; i<mTotalStrips; i++,strip_count++)614 int counter = 0; 615 int target_submesh = 0; 616 size_t strip_count = 0; 617 618 for (unsigned int i = 0; i < mTotalStrips; i++, strip_count++) 619 619 { 620 620 if (strip_count >= mGeoMesh->mSubMesh[target_submesh].mStripCount) 621 621 { 622 622 indices_x_submesh[target_submesh] = counter; 623 623 624 if (target_submesh==0) 625 { 624 626 offsets_x_submesh[target_submesh] = 0; 627 } 625 628 else 629 { 626 630 offsets_x_submesh[target_submesh] = indices_x_submesh[target_submesh-1] + offsets_x_submesh[target_submesh-1]; 627 628 counter = 0; 629 mStripsSubmesh[target_submesh] = strip_count; 630 strip_count = 0; 631 } 632 633 counter = 0; 634 mStripsSubmesh[target_submesh] = (int)strip_count; 635 strip_count = 0; 636 631 637 target_submesh++; 632 638 } … … 665 671 666 672 counter = 0; 667 mStripsSubmesh[target_submesh] = strip_count;673 mStripsSubmesh[target_submesh] = (int)strip_count; 668 674 strip_count = 0; 669 675 target_submesh++; -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp
r1090 r1136 17 17 18 18 // select the first triangle-list submesh as leaves submesh 19 mLeavesSubMesh = -1; 20 for (int i=0; i<treeGeoMesh->mSubMeshCount; i++) 19 mLeavesSubMesh = -1; 20 21 for (size_t i = 0; i < treeGeoMesh->mSubMeshCount; i++) 21 22 { 22 23 if (treeGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) 23 24 { 24 mLeavesSubMesh =i;25 mLeavesSubMesh = (uint32)i; 25 26 break; 26 27 } 27 } 28 } 28 29 29 30 // Cargar la copa del árbol -
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++) -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoMeshSaver.cpp
r1083 r1136 40 40 // Saves a Mesh into a file. 41 41 //--------------------------------------------------------------------------- 42 int GeoMeshSaver::save(Mesh *geoMesh, const char *fileNameMesh)43 { 44 intsize;42 size_t GeoMeshSaver::save(Mesh *geoMesh, const char *fileNameMesh) 43 { 44 size_t size; 45 45 String name(fileNameMesh); 46 SubMesh *geosubmesh; 46 47 47 48 mGeoMesh = new Mesh(); … … 64 65 unnormalizeModel(mGeoMesh); 65 66 66 if (leavesSubMesh>-1 && leavesVB) 67 { 68 Vector3 bmax(geoMesh->mMeshBounds.maxX,geoMesh->mMeshBounds.maxY,geoMesh->mMeshBounds.maxZ); 69 Vector3 bmin(geoMesh->mMeshBounds.minX,geoMesh->mMeshBounds.minY,geoMesh->mMeshBounds.minZ); 70 Vector3 center = (bmax+bmin)*0.5f; 71 float scale = geoMesh->mMeshBounds.scaleFactor; 72 73 mGeoMesh->mSubMesh[leavesSubMesh].mSharedVertexBuffer=false; 74 mGeoMesh->mSubMesh[leavesSubMesh].mStripCount=0; 75 mGeoMesh->mSubMesh[leavesSubMesh].mIndexCount=numindices; 76 int icount = mGeoMesh->mSubMesh[leavesSubMesh].mIndexCount; 77 mGeoMesh->mSubMesh[leavesSubMesh].mIndex=new Index[icount]; 78 for (int i=0; i<icount; i++) 79 mGeoMesh->mSubMesh[leavesSubMesh].mIndex[i]=indices[i]; 80 81 mGeoMesh->mSubMesh[leavesSubMesh].mType=GEO_TRIANGLE_LIST; 82 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer=new VertexBuffer(); 83 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mVertexInfo=VERTEX_POSITION; 84 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mVertexCount=leavesVB->mVertexCount;; 85 int vcount = mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mVertexCount; 86 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mPosition=new Vector3[vcount]; 87 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mNormal=new Vector3[vcount]; 88 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mTexCoords=new Vector2[vcount]; 89 for (int i=0; i<vcount; i++) 67 if ((leavesSubMesh > -1) && leavesVB) 68 { 69 // Gets the leaves submesh. 70 geosubmesh = &mGeoMesh->mSubMesh[leavesSubMesh]; 71 72 Vector3 bmax( geoMesh->mMeshBounds.maxX, 73 geoMesh->mMeshBounds.maxY, 74 geoMesh->mMeshBounds.maxZ); 75 76 Vector3 bmin( geoMesh->mMeshBounds.minX, 77 geoMesh->mMeshBounds.minY, 78 geoMesh->mMeshBounds.minZ); 79 80 Vector3 center = (bmax + bmin) * 0.5f; 81 82 float scale = geoMesh->mMeshBounds.scaleFactor; 83 84 geosubmesh->mSharedVertexBuffer = false; 85 geosubmesh->mStripCount = 0; 86 geosubmesh->mIndexCount = numindices; 87 88 size_t icount = geosubmesh->mIndexCount; 89 90 geosubmesh->mIndex = new Index[icount]; 91 92 for (size_t i = 0; i < icount; i++) 90 93 { 91 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mPosition[i].x = leavesVB->mPosition[i].x / scale + center.x; 92 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mPosition[i].y = leavesVB->mPosition[i].y / scale + center.y; 93 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mPosition[i].z = leavesVB->mPosition[i].z / scale + center.z; 94 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mNormal[i].x = leavesVB->mNormal[i].x; 95 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mNormal[i].y = leavesVB->mNormal[i].y; 96 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mNormal[i].z = leavesVB->mNormal[i].z; 97 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mTexCoords[i].x = leavesVB->mTexCoords[i].x; 98 mGeoMesh->mSubMesh[leavesSubMesh].mVertexBuffer->mTexCoords[i].y = leavesVB->mTexCoords[i].y; 94 geosubmesh->mIndex[i] = indices[i]; 95 } 96 97 geosubmesh->mType = GEO_TRIANGLE_LIST; 98 geosubmesh->mVertexBuffer = new VertexBuffer(); 99 geosubmesh->mVertexBuffer->mVertexInfo 100 = VERTEX_POSITION; 101 102 geosubmesh->mVertexBuffer->mVertexCount 103 = leavesVB->mVertexCount; 104 105 size_t vcount; 106 107 vcount = geosubmesh->mVertexBuffer->mVertexCount; 108 109 geosubmesh->mVertexBuffer->mPosition 110 = new Vector3[vcount]; 111 112 geosubmesh->mVertexBuffer->mNormal 113 = new Vector3[vcount]; 114 115 geosubmesh->mVertexBuffer->mTexCoords 116 = new Vector2[vcount]; 117 118 for (size_t i = 0; i < vcount; i++) 119 { 120 geosubmesh->mVertexBuffer->mPosition[i].x = leavesVB->mPosition[i].x / scale + center.x; 121 geosubmesh->mVertexBuffer->mPosition[i].y = leavesVB->mPosition[i].y / scale + center.y; 122 geosubmesh->mVertexBuffer->mPosition[i].z = leavesVB->mPosition[i].z / scale + center.z; 123 geosubmesh->mVertexBuffer->mNormal[i].x = leavesVB->mNormal[i].x; 124 geosubmesh->mVertexBuffer->mNormal[i].y = leavesVB->mNormal[i].y; 125 geosubmesh->mVertexBuffer->mNormal[i].z = leavesVB->mNormal[i].z; 126 geosubmesh->mVertexBuffer->mTexCoords[i].x = leavesVB->mTexCoords[i].x; 127 geosubmesh->mVertexBuffer->mTexCoords[i].y = leavesVB->mTexCoords[i].y; 99 128 } 100 129 } … … 126 155 { 127 156 // Header 128 writeChunkHeader(M_MESH, calcMeshSize(geoMesh));157 writeChunkHeader(M_MESH, (unsigned long)calcMeshSize(geoMesh)); 129 158 130 159 // Debug. … … 142 171 143 172 // Write submeshes. 144 for ( int i = 0; i < geoMesh->mSubMeshCount; i++)173 for (size_t i = 0; i < geoMesh->mSubMeshCount; i++) 145 174 { 146 175 writeSubMesh(&geoMesh->mSubMesh[i]); … … 157 186 { 158 187 159 for ( int i = 0; i< geoMesh->mBones.size(); i++)188 for (size_t i = 0; i< geoMesh->mBones.size(); i++) 160 189 { 161 190 writeMeshBoneAssignment(geoMesh->mBones[i]); … … 201 230 { 202 231 bool idx32bit; 203 unsigned longindexCount;204 Index *index;205 Index *indexBegin;206 Index *indexEnd;232 size_t indexCount; 233 //Index *index; 234 //Index *indexBegin; 235 //Index *indexEnd; 207 236 208 237 // Header. 209 writeChunkHeader(M_SUBMESH, calcSubMeshSize(geoSubMesh));238 writeChunkHeader(M_SUBMESH, (unsigned long)calcSubMeshSize(geoSubMesh)); 210 239 211 240 // Debug. … … 233 262 234 263 // Write index count. 235 writeInts( indexCount, 1);264 writeInts((unsigned long)indexCount, 1); 236 265 237 266 // bool indexes32Bit … … 291 320 */ 292 321 // Write the index array. 293 for ( int i = 0; i < geoSubMesh->mIndexCount; i++)322 for (size_t i = 0; i < geoSubMesh->mIndexCount; i++) 294 323 { 295 324 writeInts(geoSubMesh->mIndex[i], 1); … … 309 338 if (!geoSubMesh->mBones.empty()) 310 339 { 311 for ( int i = 0; i < geoSubMesh->mBones.size(); i++)340 for (size_t i = 0; i < geoSubMesh->mBones.size(); i++) 312 341 { 313 342 writeSubMeshBoneAssignment(geoSubMesh->mBones[i]); … … 355 384 356 385 // Calculate the size in bytes of the geometry chunk. 357 size = calcGeometrySize(vertexBuffer);386 size = (unsigned long)calcGeometrySize(vertexBuffer); 358 387 359 388 // Header. … … 366 395 << endl; 367 396 368 writeInts( vertexBuffer->mVertexCount,1);397 writeInts((unsigned long)vertexBuffer->mVertexCount,1); 369 398 370 399 // Vertex declaration. … … 561 590 (sizeof(float) * 7); 562 591 563 writeChunkHeader(M_MESH_BOUNDS, size);592 writeChunkHeader(M_MESH_BOUNDS, (unsigned long)size); 564 593 565 594 // Debug. … … 687 716 688 717 // Debug. 689 cout << "Length Skeleton Link: "690 << strlen(geoMesh->mSkeletonName)691 << endl;718 //cout << "Length Skeleton Link: " 719 // << strlen(geoMesh->mSkeletonName) 720 // << endl; 692 721 693 722 return size; … … 749 778 void GeoMeshSaver::writeSkeletonLink(const String& skelName) 750 779 { 751 writeChunkHeader(M_MESH_SKELETON_LINK, calcSkeletonLinkSize(mGeoMesh)); 780 writeChunkHeader( M_MESH_SKELETON_LINK, 781 (unsigned long)calcSkeletonLinkSize(mGeoMesh)); 752 782 753 783 // Debug. … … 755 785 << endl; 756 786 757 787 writeString(skelName); 758 788 } 759 789 … … 762 792 size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float); 763 793 764 writeChunkHeader(M_MESH_BONE_ASSIGNMENT, size);794 writeChunkHeader(M_MESH_BONE_ASSIGNMENT, (unsigned long)size); 765 795 766 796 // unsigned int vertexIndex; … … 776 806 size_t size = CHUNK_OVERHEAD_SIZE + sizeof(unsigned int) + sizeof(unsigned short)+ sizeof(float); 777 807 778 writeChunkHeader(M_SUBMESH_BONE_ASSIGNMENT, size);808 writeChunkHeader(M_SUBMESH_BONE_ASSIGNMENT, (unsigned long)size); 779 809 780 810 // unsigned int vertexIndex; … … 811 841 812 842 // Calculate center of the model. 813 cx = (maxx + minx) / 2.0 ;814 cy = (maxy + miny) / 2.0 ;815 cz = (maxz + minz) / 2.0 ;843 cx = (maxx + minx) / 2.0f; 844 cy = (maxy + miny) / 2.0f; 845 cz = (maxz + minz) / 2.0f; 816 846 817 847 // Translate around center then scale. 818 848 // For each submesh. 819 849 820 bool sharedScaled =false;821 822 for ( int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)850 bool sharedScaled = false; 851 852 for (size_t submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) 823 853 { 824 854 // Gets the actual submesh. … … 826 856 827 857 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer && sharedScaled) 858 { 828 859 continue; 860 } 829 861 830 862 // For each index of the strip. 831 for ( int i = 0; i < vertex_buffer->mVertexCount; i++)863 for (size_t i = 0; i < vertex_buffer->mVertexCount; i++) 832 864 { 833 865 vertex_buffer->mPosition[i].x /= scale; … … 841 873 // If is a shared vertex Buffer. 842 874 if (geoMesh->mSubMesh[submesh].mSharedVertexBuffer) 843 sharedScaled=true; 844 } 845 } 846 875 { 876 sharedScaled = true; 877 } 878 } 879 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoTreeSimpSequence.cpp
r1090 r1136 60 60 void TreeSimplificationSequence::Save(Serializer &s) 61 61 { 62 // Almacena la secuencia de simplificación en un fichero 63 /* char simp[256]; 64 65 // Nombre del mesh 66 sprintf(simp,"%s\n",meshName); 67 s.WriteData(simp,sizeof(char),strlen(simp)); 68 */ 62 // Stores simplification sequence. 69 63 unsigned short chunkid = 0xdcba; 70 64 s.WriteData(&chunkid,sizeof(unsigned short),1); 71 unsigned long size = mSteps.size()*8*sizeof(int) + CHUNK_OVERHEAD_SIZE; 65 66 unsigned long size = (unsigned long) 67 ( 68 mSteps.size()*8*sizeof(int) 69 + 70 CHUNK_OVERHEAD_SIZE 71 ); 72 72 73 s.WriteData(&size,sizeof(unsigned long),1); 73 74 74 int tam = mSteps.size(); 75 int tam = (int)mSteps.size(); 76 75 77 s.WriteData(&tam,sizeof(int),1); 76 for(unsigned int i=0; i<tam; i++) 78 79 for(int i=0; i<tam; i++) 77 80 { 78 81 Geometry::TreeSimplificationSequence::Step paso = mSteps.operator [](i);
Note: See TracChangeset
for help on using the changeset viewer.