Changeset 1071 for GTP/trunk/Lib/Geom
- Timestamp:
- 06/30/06 17:40:29 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/GTGeometry.vcproj
r1069 r1071 317 317 RelativePath=".\src\libs\vmi\src\simplify.cpp"> 318 318 </File> 319 <File320 RelativePath=".\src\libs\vmi\src\WriteTGA.cpp">321 </File>322 319 </Filter> 323 320 </Filter> … … 436 433 <File 437 434 RelativePath=".\include\VertexData.h"> 435 </File> 436 <File 437 RelativePath=".\src\libs\vmi\src\WriteTGA.cpp"> 438 438 </File> 439 439 <Filter -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodManager.h
r1069 r1071 22 22 { 23 23 public: 24 lodobj_dist_node_t(LodObject *o):dist2cam(0.0f),lodobj(o) ,must_recalculate_distance(true){}25 lodobj_dist_node_t(const lodobj_dist_node_t &c):dist2cam(c.dist2cam),lodobj(c.lodobj) ,must_recalculate_distance(c.must_recalculate_distance){}26 lodobj_dist_node_t(void):dist2cam(0.0f),lodobj(NULL) ,must_recalculate_distance(true){}24 lodobj_dist_node_t(LodObject *o):dist2cam(0.0f),lodobj(o){} 25 lodobj_dist_node_t(const lodobj_dist_node_t &c):dist2cam(c.dist2cam),lodobj(c.lodobj){} 26 lodobj_dist_node_t(void):dist2cam(0.0f),lodobj(NULL){} 27 27 float dist2cam; 28 28 LodObject *lodobj; 29 29 bool operator < (const lodobj_dist_node_t &o) const { return (dist2cam < o.dist2cam); } 30 bool must_recalculate_distance;31 30 }; 32 31 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodManager.cpp
r1069 r1071 18 18 { 19 19 public: 20 lodobj_idpos_node_t(LodObject *o):lodobj(o) {}20 lodobj_idpos_node_t(LodObject *o):lodobj(o),must_recalculate_distance(true),dist2cam(0.0f){} 21 21 LodObject *lodobj; 22 float dist2cam; // used to index the lodobj in the other map 23 bool must_recalculate_distance; 22 24 bool operator < (const lodobj_idpos_node_t &o) const { return (lodobj->GetUniqueID()<o.lodobj->GetUniqueID()); } 23 25 }; … … 45 47 if (camera_changed) 46 48 { 47 // if the camera has changed, recalculate all lodobject distances to it 48 float random_dist = SelectRandomDistance(); 49 49 // if the camera has changed, recalculate all lodobject distances to it 50 lodobj_dists.clear(); 51 for (std::map<Geometry::lodobj_idpos_node_t,Geometry::Vector3>::iterator it = lodobj_pos.begin(); it != lodobj_pos.end(); it++) 52 { 53 const lodobj_idpos_node_t & posnode = it->first; 54 const Vector3 & pos = it->second; 55 float newdist = CalculateDistToCamera(pos); 56 lodobj_dists[newdist] = lodobj_dist_node_t(posnode.lodobj); 57 } 50 58 camera_changed=false; 51 59 } 60 else 61 { 62 // if any of the objects changed its position, the distance must be recalculated 63 for (std::map<Geometry::lodobj_idpos_node_t,Geometry::Vector3>::iterator it = lodobj_pos.begin(); it != lodobj_pos.end(); it++) 64 { 65 const lodobj_idpos_node_t & posnode = it->first; 66 if (posnode.must_recalculate_distance) 67 { 68 const Vector3 & pos = it->second; 69 float newdist = CalculateDistToCamera(pos); 70 lodobj_dists[newdist] = lodobj_dist_node_t(posnode.lodobj); 71 /* lodobj_dists.erase(it);*/ 72 } 73 } 74 } 75 76 // select a tree to change its LOD 77 float random_dist = SelectRandomDistance(); 78 std::map<float,Geometry::lodobj_dist_node_t>::iterator nearest = lodobj_dists.upper_bound(random_dist); 52 79 } 53 80 -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshLoader.cpp
r1070 r1071 1381 1381 }; 1382 1382 1383 1384 class vertex_arranger_node 1383 class VertexArranger 1385 1384 { 1386 1385 public: 1387 int v, n, t; 1388 1389 vertex_arranger_node(void){ 1390 v=n=t=-1; 1391 } 1392 vertex_arranger_node(int iv, int in=-1, int it=-1){ 1393 v=iv; 1394 n=in; 1395 t=it; 1396 } 1397 1398 bool operator<(const vertex_arranger_node &vu) const { 1399 if (v<vu.v) return true; 1400 if (v>vu.v) return false; 1401 if (n<vu.n) return true; 1402 if (n>vu.n) return false; 1403 if (t<vu.t) return true; 1404 if (t>vu.t) return false; 1405 return false; 1406 } 1407 bool operator==(const vertex_arranger_node &vu) const { 1408 return (v==vu.v && v==vu.v && n==vu.n && n==vu.n && t==vu.t && t==vu.t); 1409 } 1386 VertexArranger(Geometry::Mesh *m){ 1387 mesh=m; 1388 current_submesh=0; 1389 current_tris=new int[m->mSubMeshCount]; 1390 for (int i=0; i<m->mSubMeshCount; i++) 1391 current_tris[i] = 0; 1392 } 1393 ~VertexArranger(void){ 1394 delete[] current_tris; 1395 } 1396 1397 void AddFace(int v1, int v2, int v3, int t1, int t2, int t3, int n1, int n2, int n3){ 1398 Geometry::SubMesh *submesh = mesh->mSubMesh + current_submesh; 1399 1400 vertex_arranger_node vertex1(v1,n1,t1); 1401 vertex_arranger_node vertex2(v2,n2,t2); 1402 vertex_arranger_node vertex3(v3,n3,t3); 1403 1404 int j = current_tris[current_submesh]; 1405 1406 std::map<vertex_arranger_node,int>::iterator res; 1407 res=vertex_map.find(vertex1); 1408 if (res==vertex_map.end()) 1409 { 1410 int val = vertex_map.size(); 1411 vertex_map[vertex1] = val; 1412 submesh->mIndex[j*3+0] = val; 1413 } 1414 else 1415 submesh->mIndex[j*3+0] = res->second; 1416 1417 res=vertex_map.find(vertex2); 1418 if (res==vertex_map.end()) 1419 { 1420 int val = vertex_map.size(); 1421 vertex_map[vertex2] = val; 1422 submesh->mIndex[j*3+1] = val; 1423 } 1424 else 1425 submesh->mIndex[j*3+1] = res->second; 1426 1427 res=vertex_map.find(vertex3); 1428 if (res==vertex_map.end()) 1429 { 1430 int val = vertex_map.size(); 1431 vertex_map[vertex3] = val; 1432 submesh->mIndex[j*3+2] = val; 1433 } 1434 else 1435 submesh->mIndex[j*3+2] = res->second; 1436 1437 current_tris[current_submesh] ++; 1438 } 1439 1440 int GetVertexCount(void) const { return vertex_map.size(); } 1441 1442 void SetCurrentSubMesh(int i){ current_submesh = i; } 1443 1444 class vertex_arranger_node 1445 { 1446 public: 1447 int v, n, t; 1448 1449 vertex_arranger_node(void){ 1450 v=n=t=-1; 1451 } 1452 vertex_arranger_node(int iv, int in=-1, int it=-1){ 1453 v=iv; 1454 n=in; 1455 t=it; 1456 } 1457 1458 bool operator<(const vertex_arranger_node &vu) const { 1459 if (v<vu.v) return true; 1460 if (v>vu.v) return false; 1461 if (n<vu.n) return true; 1462 if (n>vu.n) return false; 1463 if (t<vu.t) return true; 1464 if (t>vu.t) return false; 1465 return false; 1466 } 1467 bool operator==(const vertex_arranger_node &vu) const { 1468 return (v==vu.v && v==vu.v && n==vu.n && n==vu.n && t==vu.t && t==vu.t); 1469 } 1470 }; 1471 1472 /* VertexArranger::vertex_arranger_node *GetVertexInfo(void) const { 1473 vertex_arranger_node * vertex_list = new vertex_arranger_node[GetVertexCount()]; 1474 for (std::map<vertex_arranger_node,int>::const_iterator it=vertex_map.begin(); it!=vertex_map.end(); it++) 1475 vertex_list[it->second] = it->first; 1476 return vertex_list; 1477 } 1478 1479 const std::vector<int> GetIndexInfo(void) const { return indices; }*/ 1480 1481 void Arrange( const std::vector<Geometry::Vector3> & vertices, 1482 const std::vector<Geometry::Vector3> & normals, 1483 const std::vector<Geometry::Vector2> & texcoords){ 1484 1485 mesh->mVertexBuffer=new Geometry::VertexBuffer; 1486 mesh->mVertexBuffer->mVertexCount = GetVertexCount(); 1487 mesh->mVertexBuffer->mPosition = new Geometry::Vector3[mesh->mVertexBuffer->mVertexCount]; 1488 mesh->mVertexBuffer->mTexCoords = texcoords.empty()?NULL:new Geometry::Vector2[mesh->mVertexBuffer->mVertexCount]; 1489 mesh->mVertexBuffer->mNormal = normals.empty()?NULL:new Geometry::Vector3[mesh->mVertexBuffer->mVertexCount]; 1490 mesh->mVertexBuffer->mVertexInfo = Geometry::VERTEX_POSITION | (texcoords.empty()?0:Geometry::VERTEX_TEXCOORDS) | (normals.empty()?0:Geometry::VERTEX_NORMAL); 1491 1492 // sort the calculated vertices 1493 1494 vertex_arranger_node * vertex_list = new vertex_arranger_node[mesh->mVertexBuffer->mVertexCount]; 1495 for (std::map<vertex_arranger_node,int>::iterator it=vertex_map.begin(); it!=vertex_map.end(); it++) 1496 vertex_list[it->second] = it->first; 1497 1498 for (int i=0; i<mesh->mSubMeshCount; i++) 1499 mesh->mSubMesh[i].mVertexBuffer = mesh->mVertexBuffer; 1500 1501 for (int j=0; j<mesh->mVertexBuffer->mVertexCount; j++) 1502 { 1503 int vi = vertex_list[j].v; 1504 int ti = vertex_list[j].t; 1505 int ni = vertex_list[j].n; 1506 1507 Geometry::Vector3 auxpos(vertices[vi]); 1508 if (auxpos.x < mesh->mMeshBounds.minX) mesh->mMeshBounds.minX = auxpos.x; 1509 if (auxpos.y < mesh->mMeshBounds.minY) mesh->mMeshBounds.minY = auxpos.y; 1510 if (auxpos.z < mesh->mMeshBounds.minZ) mesh->mMeshBounds.minZ = auxpos.z; 1511 if (auxpos.x > mesh->mMeshBounds.maxX) mesh->mMeshBounds.maxX = auxpos.x; 1512 if (auxpos.y > mesh->mMeshBounds.maxY) mesh->mMeshBounds.maxY = auxpos.y; 1513 if (auxpos.z > mesh->mMeshBounds.maxZ) mesh->mMeshBounds.maxZ = auxpos.z; 1514 1515 mesh->mVertexBuffer->mPosition[j] = auxpos; 1516 mesh->mVertexBuffer->mNormal[j] = normals[ni]; 1517 if (texcoords.empty()==false) 1518 mesh->mVertexBuffer->mTexCoords[j] = texcoords[ti]; 1519 } 1520 1521 delete[] vertex_list; 1522 } 1523 1524 //private: 1525 std::map<vertex_arranger_node,int> vertex_map; 1526 Geometry::Mesh *mesh; 1527 int current_submesh; 1528 int *current_tris; 1410 1529 }; 1411 1530 … … 1532 1651 // fill up the mesh structure with the loaded information 1533 1652 1534 std::map<vertex_arranger_node,int> vertex_map;1653 VertexArranger vertex_arranger(mesh); 1535 1654 1536 1655 mesh->mSubMesh=new Geometry::SubMesh[mesh->mSubMeshCount]; … … 1544 1663 submesh->mIndexCount = vecfaces.size()*3; 1545 1664 submesh->mIndex=new Geometry::Index[submesh->mIndexCount]; 1665 1666 vertex_arranger.SetCurrentSubMesh(i); 1546 1667 1547 1668 for (std::vector<face_t>::const_iterator it=vecfaces.begin(); it!=vecfaces.end(); it++,j++) … … 1549 1670 const face_t & auxface = *it; 1550 1671 1551 vertex_arranger_node v1(auxface.v1,auxface.n1,auxface.t1); 1552 vertex_arranger_node v2(auxface.v2,auxface.n2,auxface.t2); 1553 vertex_arranger_node v3(auxface.v3,auxface.n3,auxface.t3); 1554 1555 std::map<vertex_arranger_node,int>::iterator res; 1556 res=vertex_map.find(v1); 1557 if (res==vertex_map.end()) 1558 { 1559 int val = vertex_map.size(); 1560 vertex_map[v1] = val; 1561 submesh->mIndex[j*3+0] = val; 1562 } 1563 else 1564 submesh->mIndex[j*3+0] = res->second; 1565 1566 res=vertex_map.find(v2); 1567 if (res==vertex_map.end()) 1568 { 1569 int val = vertex_map.size(); 1570 vertex_map[v2] = val; 1571 submesh->mIndex[j*3+1] = val; 1572 } 1573 else 1574 submesh->mIndex[j*3+1] = res->second; 1575 1576 res=vertex_map.find(v3); 1577 if (res==vertex_map.end()) 1578 { 1579 int val = vertex_map.size(); 1580 vertex_map[v3] = val; 1581 submesh->mIndex[j*3+2] = val; 1582 } 1583 else 1584 submesh->mIndex[j*3+2] = res->second; 1672 vertex_arranger.AddFace(auxface.v1,auxface.v2,auxface.v3, 1673 auxface.t1,auxface.t2,auxface.t3, 1674 auxface.n1,auxface.n2,auxface.n3); 1585 1675 } 1586 1676 } 1587 1677 1588 mesh->mVertexBuffer=new Geometry::VertexBuffer; 1589 mesh->mVertexBuffer->mVertexCount = vertex_map.size(); 1590 mesh->mVertexBuffer->mPosition = new Geometry::Vector3[mesh->mVertexBuffer->mVertexCount]; 1591 mesh->mVertexBuffer->mTexCoords = texcoords.empty()?NULL:new Geometry::Vector2[mesh->mVertexBuffer->mVertexCount]; 1592 mesh->mVertexBuffer->mNormal = normals.empty()?NULL:new Geometry::Vector3[mesh->mVertexBuffer->mVertexCount]; 1593 mesh->mVertexBuffer->mVertexInfo = Geometry::VERTEX_POSITION | (texcoords.empty()?0:Geometry::VERTEX_TEXCOORDS) | (normals.empty()?0:Geometry::VERTEX_NORMAL); 1594 1595 // sort the calculated vertices 1596 1597 vertex_arranger_node * vertex_list = new vertex_arranger_node[mesh->mVertexBuffer->mVertexCount]; 1598 for (std::map<vertex_arranger_node,int>::iterator it=vertex_map.begin(); it!=vertex_map.end(); it++) 1599 vertex_list[it->second] = it->first; 1600 1601 1602 for (int i=0; i<mesh->mSubMeshCount; i++) 1603 mesh->mSubMesh[i].mVertexBuffer=mesh->mVertexBuffer; 1604 1605 for (int j=0; j<mesh->mVertexBuffer->mVertexCount; j++) 1606 { 1607 int vi = vertex_list[j].v; 1608 int ti = vertex_list[j].t; 1609 int ni = vertex_list[j].n; 1610 1611 Geometry::Vector3 auxpos(vertices[vi]); 1612 if (auxpos.x < mesh->mMeshBounds.minX) mesh->mMeshBounds.minX = auxpos.x; 1613 if (auxpos.y < mesh->mMeshBounds.minY) mesh->mMeshBounds.minY = auxpos.y; 1614 if (auxpos.z < mesh->mMeshBounds.minZ) mesh->mMeshBounds.minZ = auxpos.z; 1615 if (auxpos.x > mesh->mMeshBounds.maxX) mesh->mMeshBounds.maxX = auxpos.x; 1616 if (auxpos.y > mesh->mMeshBounds.maxY) mesh->mMeshBounds.maxY = auxpos.y; 1617 if (auxpos.z > mesh->mMeshBounds.maxZ) mesh->mMeshBounds.maxZ = auxpos.z; 1618 1619 mesh->mVertexBuffer->mPosition[j] = auxpos; 1620 mesh->mVertexBuffer->mNormal[j] = normals[ni]; 1621 if (found_texcoords) 1622 mesh->mVertexBuffer->mTexCoords[j] = texcoords[ti]; 1623 } 1624 1625 delete[] vertex_list; 1626 } 1627 1678 vertex_arranger.Arrange(vertices,normals,texcoords); 1679 } 1680
Note: See TracChangeset
for help on using the changeset viewer.