#include <OSG3DSLoader.h>
Inheritance diagram for LMesh:

Public Member Functions | |
| LMesh () | |
| virtual | ~LMesh () |
| void | Clear () |
| uint | GetVertexCount () |
| void | SetVertexArraySize (uint value) |
| uint | GetTriangleCount () |
| void | SetTriangleArraySize (uint value) |
| const LVector4 & | GetVertex (uint index) |
| const LVector3 & | GetNormal (uint index) |
| const LVector2 & | GetUV (uint index) |
| const LVector3 & | GetTangent (uint index) |
| const LVector3 & | GetBinormal (uint index) |
| void | SetVertex (const LVector4 &vec, uint index) |
| void | SetNormal (const LVector3 &vec, uint index) |
| void | SetUV (const LVector2 &vec, uint index) |
| void | SetTangent (const LVector3 &vec, uint index) |
| void | SetBinormal (const LVector3 &vec, uint index) |
| const LTriangle & | GetTriangle (uint index) |
| LTriangle2 | GetTriangle2 (uint index) |
| LMatrix4 | GetMatrix () |
| void | SetMatrix (LMatrix4 m) |
| void | Optimize (LOptimizationLevel value) |
| void | SetTri (const LTri &tri, uint index) |
| LTri & | GetTri (uint index) |
| uint | GetMaterial (uint index) |
| uint | AddMaterial (uint id) |
| uint | GetMaterialCount () |
| virtual const std::string & | GetName () |
| virtual void | SetName (const std::string &value) |
| bool | IsObject (const std::string &name) |
Protected Member Functions | |
| void | CalcNormals (bool useSmoothingGroups) |
| void | CalcTextureSpace () |
| void | TransformVertices () |
Protected Attributes | |
| std::vector< LVector4 > | m_vertices |
| std::vector< LVector3 > | m_normals |
| std::vector< LVector3 > | m_binormals |
| std::vector< LVector3 > | m_tangents |
| std::vector< LVector2 > | m_uv |
| std::vector< LTriangle > | m_triangles |
| std::vector< LTri > | m_tris |
| LMatrix4 | m_matrix |
| std::vector< uint > | m_materials |
| std::string | m_name |
Definition at line 227 of file OSG3DSLoader.h.
| LMesh::LMesh | ( | ) |
| LMesh::~LMesh | ( | ) | [virtual] |
| void LMesh::Clear | ( | ) |
Definition at line 395 of file OSG3DSLoader.cpp.
References LoadIdentityMatrix(), m_binormals, m_materials, m_matrix, m_normals, m_tangents, m_triangles, m_tris, m_uv, and m_vertices.
Referenced by LMesh(), and ~LMesh().
00396 { 00397 m_vertices.clear(); 00398 m_normals.clear(); 00399 m_uv.clear(); 00400 m_tangents.clear(); 00401 m_binormals.clear(); 00402 m_triangles.clear(); 00403 m_tris.clear(); 00404 m_materials.clear(); 00405 LoadIdentityMatrix(m_matrix); 00406 }
| uint LMesh::GetVertexCount | ( | ) |
Definition at line 408 of file OSG3DSLoader.cpp.
References m_vertices.
Referenced by L3DS::ReadMesh().
00409 { 00410 return m_vertices.size(); 00411 }
| void LMesh::SetVertexArraySize | ( | uint | value | ) |
Definition at line 413 of file OSG3DSLoader.cpp.
References m_binormals, m_normals, m_tangents, m_uv, and m_vertices.
Referenced by L3DS::ReadMesh().
00414 { 00415 m_vertices.resize(value); 00416 m_normals.resize(value); 00417 m_uv.resize(value); 00418 m_tangents.resize(value); 00419 m_binormals.resize(value); 00420 }
| uint LMesh::GetTriangleCount | ( | ) |
Definition at line 422 of file OSG3DSLoader.cpp.
References m_triangles.
Referenced by OSG::A3DSSceneFileType::createMesh(), and L3DS::ReadFaceList().
00423 { 00424 return m_triangles.size(); 00425 }
| void LMesh::SetTriangleArraySize | ( | uint | value | ) |
Definition at line 427 of file OSG3DSLoader.cpp.
References m_triangles, and m_tris.
Referenced by L3DS::ReadFaceList().
00428 { 00429 m_triangles.resize(value); 00430 m_tris.resize(value); 00431 }
Definition at line 433 of file OSG3DSLoader.cpp.
References m_vertices.
Referenced by GetTriangle2().
00434 { 00435 return m_vertices[index]; 00436 }
Definition at line 438 of file OSG3DSLoader.cpp.
References m_normals.
Referenced by GetTriangle2().
00439 { 00440 return m_normals[index]; 00441 }
Definition at line 443 of file OSG3DSLoader.cpp.
References m_uv.
Referenced by GetTriangle2().
00444 { 00445 return m_uv[index]; 00446 }
Definition at line 448 of file OSG3DSLoader.cpp.
References m_tangents.
00449 { 00450 return m_tangents[index]; 00451 }
Definition at line 453 of file OSG3DSLoader.cpp.
References m_binormals.
00454 { 00455 return m_binormals[index]; 00456 }
Definition at line 458 of file OSG3DSLoader.cpp.
References m_vertices.
Referenced by L3DS::ReadMesh().
00459 { 00460 if (index >= m_vertices.size()) 00461 return; 00462 m_vertices[index] = vec; 00463 }
Definition at line 465 of file OSG3DSLoader.cpp.
References m_normals, and m_vertices.
00466 { 00467 if (index >= m_vertices.size()) 00468 return; 00469 m_normals[index] = vec; 00470 }
Definition at line 472 of file OSG3DSLoader.cpp.
References m_uv, and m_vertices.
Referenced by L3DS::ReadMesh().
00473 { 00474 if (index >= m_vertices.size()) 00475 return; 00476 m_uv[index] = vec; 00477 }
Definition at line 479 of file OSG3DSLoader.cpp.
References m_tangents, and m_vertices.
00480 { 00481 if (index >= m_vertices.size()) 00482 return; 00483 m_tangents[index] = vec; 00484 }
Definition at line 486 of file OSG3DSLoader.cpp.
References m_binormals, and m_vertices.
00487 { 00488 if (index >= m_vertices.size()) 00489 return; 00490 m_binormals[index] = vec; 00491 }
Definition at line 493 of file OSG3DSLoader.cpp.
References m_triangles.
Referenced by GetTriangle2().
00494 { 00495 return m_triangles[index]; 00496 }
| LTriangle2 LMesh::GetTriangle2 | ( | uint | index | ) |
Definition at line 498 of file OSG3DSLoader.cpp.
References _4to3(), LTriangle::a, LTriangle::b, LTriangle::c, CrossProduct(), LTriangle2::faceNormal, GetNormal(), GetTriangle(), GetUV(), GetVertex(), m_tris, LTriangle2::materialId, NormalizeVector(), SubtractVectors(), LTriangle2::textureCoords, LTriangle2::vertexNormals, and LTriangle2::vertices.
Referenced by OSG::A3DSSceneFileType::createMesh().
00499 { 00500 LTriangle2 f; 00501 LTriangle t = GetTriangle(index); 00502 f.vertices[0] = GetVertex(t.a); 00503 f.vertices[1] = GetVertex(t.b); 00504 f.vertices[2] = GetVertex(t.c); 00505 00506 f.vertexNormals[0] = GetNormal(t.a); 00507 f.vertexNormals[1] = GetNormal(t.b); 00508 f.vertexNormals[2] = GetNormal(t.c); 00509 00510 f.textureCoords[0] = GetUV(t.a); 00511 f.textureCoords[1] = GetUV(t.b); 00512 f.textureCoords[2] = GetUV(t.c); 00513 00514 LVector3 a, b; 00515 00516 a = SubtractVectors(_4to3(f.vertices[1]), _4to3(f.vertices[0])); 00517 b = SubtractVectors(_4to3(f.vertices[1]), _4to3(f.vertices[2])); 00518 00519 f.faceNormal = CrossProduct(b, a); 00520 00521 f.faceNormal = NormalizeVector(f.faceNormal); 00522 00523 f.materialId = m_tris[index].materialId; 00524 00525 return f; 00526 }
| LMatrix4 LMesh::GetMatrix | ( | ) |
Definition at line 528 of file OSG3DSLoader.cpp.
References m_matrix.
00529 { 00530 return m_matrix; 00531 }
| void LMesh::SetMatrix | ( | LMatrix4 | m | ) |
Definition at line 533 of file OSG3DSLoader.cpp.
References m_matrix.
Referenced by L3DS::ReadMesh().
00534 { 00535 m_matrix = m; 00536 }
| void LMesh::Optimize | ( | LOptimizationLevel | value | ) |
Definition at line 789 of file OSG3DSLoader.cpp.
References CalcNormals(), CalcTextureSpace(), oFull, oNone, oSimple, and TransformVertices().
00790 { 00791 switch (value) 00792 { 00793 case oNone: 00794 TransformVertices(); 00795 break; 00796 case oSimple: 00797 //TransformVertices(); 00798 CalcNormals(false); 00799 break; 00800 case oFull: 00801 //TransformVertices(); 00802 CalcNormals(true); 00803 CalcTextureSpace(); 00804 break; 00805 } 00806 }
Definition at line 808 of file OSG3DSLoader.cpp.
References m_triangles, and m_tris.
Referenced by L3DS::ReadFaceList().
00809 { 00810 if (index >= m_triangles.size()) 00811 return; 00812 m_tris[index] = tri; 00813 }
Definition at line 815 of file OSG3DSLoader.cpp.
References m_tris.
Referenced by L3DS::ReadFaceList().
00816 { 00817 return m_tris[index]; 00818 }
Definition at line 820 of file OSG3DSLoader.cpp.
References m_materials.
Referenced by OSG::A3DSSceneFileType::createMesh().
00821 { 00822 return m_materials[index]; 00823 }
Definition at line 825 of file OSG3DSLoader.cpp.
References m_materials.
Referenced by L3DS::ReadFaceList().
00826 { 00827 m_materials.push_back(id); 00828 return m_materials.size()-1; 00829 }
| uint LMesh::GetMaterialCount | ( | ) |
Definition at line 831 of file OSG3DSLoader.cpp.
References m_materials.
Referenced by OSG::A3DSSceneFileType::createMesh().
00832 { 00833 return m_materials.size(); 00834 }
| void LMesh::CalcNormals | ( | bool | useSmoothingGroups | ) | [protected] |
Definition at line 544 of file OSG3DSLoader.cpp.
References _4to3(), CrossProduct(), m_binormals, m_normals, m_tangents, m_triangles, m_tris, m_uv, m_vertices, NormalizeVector(), size, SubtractVectors(), LVector3::x, LVector3::y, LVector3::z, and zero3.
Referenced by Optimize().
00545 { 00546 uint i; 00547 // first calculate the face normals 00548 for (i=0; i<m_triangles.size(); i++) 00549 { 00550 LVector3 a, b; 00551 a = SubtractVectors(_4to3(m_vertices[m_tris[i].b]), _4to3(m_vertices[m_tris[i].a])); 00552 b = SubtractVectors(_4to3(m_vertices[m_tris[i].b]), _4to3(m_vertices[m_tris[i].c])); 00553 m_tris[i].normal = NormalizeVector(CrossProduct(b, a)); 00554 } 00555 00556 std::vector< std::vector<int> > array; 00557 array.resize(m_vertices.size()); 00558 for (i=0; i<m_triangles.size(); i++) 00559 { 00560 uint k = m_tris[i].a; 00561 array[k].push_back(i); 00562 00563 k = m_tris[i].b; 00564 array[k].push_back(i); 00565 00566 k = m_tris[i].c; 00567 array[k].push_back(i); 00568 } 00569 00570 LVector3 temp; 00571 00572 if (!useSmoothingGroups) 00573 { 00574 // now calculate the normals without using smoothing groups 00575 for (i=0; i<m_vertices.size(); i++) 00576 { 00577 temp = zero3; 00578 int t = array[i].size(); 00579 00580 for (int k=0; k<t; k++) 00581 { 00582 temp.x += m_tris[array[i][k]].normal.x; 00583 temp.y += m_tris[array[i][k]].normal.y; 00584 temp.z += m_tris[array[i][k]].normal.z; 00585 } 00586 m_normals[i] = NormalizeVector(temp); 00587 } 00588 } 00589 else 00590 { 00591 // now calculate the normals _USING_ smoothing groups 00592 // I'm assuming a triangle can only belong to one smoothing group at a time! 00593 std::vector<ulong> smGroups; 00594 std::vector< std::vector <uint> > smList; 00595 00596 uint loop_size = m_vertices.size(); 00597 00598 for (i=0; i<loop_size; i++) 00599 { 00600 int t = array[i].size(); 00601 00602 if (t == 0) 00603 continue; 00604 00605 smGroups.clear(); 00606 smList.clear(); 00607 smGroups.push_back(m_tris[array[i][0]].smoothingGroups); 00608 smList.resize(smGroups.size()); 00609 smList[smGroups.size()-1].push_back(array[i][0]); 00610 00611 // first build a list of smoothing groups for the vertex 00612 for (int k=0; k<t; k++) 00613 { 00614 bool found = false; 00615 for (uint j=0; j<smGroups.size(); j++) 00616 { 00617 if (m_tris[array[i][k]].smoothingGroups == smGroups[j]) 00618 { 00619 smList[j].push_back(array[i][k]); 00620 found = true; 00621 } 00622 } 00623 if (!found) 00624 { 00625 smGroups.push_back(m_tris[array[i][k]].smoothingGroups); 00626 smList.resize(smGroups.size()); 00627 smList[smGroups.size()-1].push_back(array[i][k]); 00628 } 00629 } 00630 // now we have the list of faces for the vertex sorted by smoothing groups 00631 00632 00633 // now duplicate the vertices so that there's only one smoothing group "per vertex" 00634 if (smGroups.size() > 1) 00635 for (uint j=1; j< smGroups.size(); j++) 00636 { 00637 m_vertices.push_back(m_vertices[i]); 00638 m_normals.push_back(m_normals[i]); 00639 m_uv.push_back(m_uv[i]); 00640 m_tangents.push_back(m_tangents[i]); 00641 m_binormals.push_back(m_binormals[i]); 00642 00643 uint t = m_vertices.size()-1; 00644 for (uint h=0; h<smList[j].size(); h++) 00645 { 00646 if (m_tris[smList[j][h]].a == i) 00647 m_tris[smList[j][h]].a = t; 00648 if (m_tris[smList[j][h]].b == i) 00649 m_tris[smList[j][h]].b = t; 00650 if (m_tris[smList[j][h]].c == i) 00651 m_tris[smList[j][h]].c = t; 00652 } 00653 } 00654 } 00655 00656 // now rebuild a face list for each vertex, since the old one is invalidated 00657 for (i=0; i<array.size(); i++) 00658 array[i].clear(); 00659 array.clear(); 00660 array.resize(m_vertices.size()); 00661 for (i=0; i<m_triangles.size(); i++) 00662 { 00663 uint k = m_tris[i].a; 00664 array[k].push_back(i); 00665 00666 k = m_tris[i].b; 00667 array[k].push_back(i); 00668 00669 k = m_tris[i].c; 00670 array[k].push_back(i); 00671 } 00672 00673 // now compute the normals 00674 for (i=0; i<m_vertices.size(); i++) 00675 { 00676 temp = zero3; 00677 int t = array[i].size(); 00678 00679 for (int k=0; k<t; k++) 00680 { 00681 temp.x += m_tris[array[i][k]].normal.x; 00682 temp.y += m_tris[array[i][k]].normal.y; 00683 temp.z += m_tris[array[i][k]].normal.z; 00684 } 00685 m_normals[i] = NormalizeVector(temp); 00686 } 00687 00688 } 00689 00690 // copy m_tris to m_triangles 00691 for (i=0; i<m_triangles.size(); i++) 00692 { 00693 m_triangles[i].a = m_tris[i].a; 00694 m_triangles[i].b = m_tris[i].b; 00695 m_triangles[i].c = m_tris[i].c; 00696 } 00697 }
| void LMesh::CalcTextureSpace | ( | ) | [protected] |
Definition at line 699 of file OSG3DSLoader.cpp.
References CrossProduct(), m_binormals, m_normals, m_tangents, m_triangles, m_tris, m_uv, m_vertices, NormalizeVector(), LVector3::x, LVector3::y, LVector3::z, and zero3.
Referenced by Optimize().
00700 { 00701 // a understandable description of how to do that can be found here: 00702 // http://members.rogers.com/deseric/tangentspace.htm 00703 // first calculate the tangent for each triangle 00704 LVector3 x_vec, 00705 y_vec, 00706 z_vec; 00707 LVector3 v1, v2; 00708 for (uint i=0; i<m_triangles.size(); i++) 00709 { 00710 v1.x = m_vertices[m_tris[i].b].x - m_vertices[m_tris[i].a].x; 00711 v1.y = m_uv[m_tris[i].b].x - m_uv[m_tris[i].a].x; 00712 v1.z = m_uv[m_tris[i].b].y - m_uv[m_tris[i].a].y; 00713 00714 v2.x = m_vertices[m_tris[i].c].x - m_vertices[m_tris[i].a].x; 00715 v2.y = m_uv[m_tris[i].c].x - m_uv[m_tris[i].a].x; 00716 v2.z = m_uv[m_tris[i].c].y - m_uv[m_tris[i].a].y; 00717 00718 x_vec = CrossProduct(v1, v2); 00719 00720 v1.x = m_vertices[m_tris[i].b].y - m_vertices[m_tris[i].a].y; 00721 v1.y = m_uv[m_tris[i].b].x - m_uv[m_tris[i].a].x; 00722 v1.z = m_uv[m_tris[i].b].y - m_uv[m_tris[i].a].y; 00723 00724 v2.x = m_vertices[m_tris[i].c].y - m_vertices[m_tris[i].a].y; 00725 v2.y = m_uv[m_tris[i].c].x - m_uv[m_tris[i].a].x; 00726 v2.z = m_uv[m_tris[i].c].y - m_uv[m_tris[i].a].y; 00727 00728 y_vec = CrossProduct(v1, v2); 00729 00730 v1.x = m_vertices[m_tris[i].b].z - m_vertices[m_tris[i].a].z; 00731 v1.y = m_uv[m_tris[i].b].x - m_uv[m_tris[i].a].x; 00732 v1.z = m_uv[m_tris[i].b].y - m_uv[m_tris[i].a].y; 00733 00734 v2.x = m_vertices[m_tris[i].c].z - m_vertices[m_tris[i].a].z; 00735 v2.y = m_uv[m_tris[i].c].x - m_uv[m_tris[i].a].x; 00736 v2.z = m_uv[m_tris[i].c].y - m_uv[m_tris[i].a].y; 00737 00738 z_vec = CrossProduct(v1, v2); 00739 00740 m_tris[i].tangent.x = -(x_vec.y/x_vec.x); 00741 m_tris[i].tangent.y = -(y_vec.y/y_vec.x); 00742 m_tris[i].tangent.z = -(z_vec.y/z_vec.x); 00743 00744 m_tris[i].binormal.x = -(x_vec.z/x_vec.x); 00745 m_tris[i].binormal.y = -(y_vec.z/y_vec.x); 00746 m_tris[i].binormal.z = -(z_vec.z/z_vec.x); 00747 00748 } 00749 00750 // now for each vertex build a list of face that share this vertex 00751 std::vector< std::vector<int> > array; 00752 array.resize(m_vertices.size()); 00753 for (size_t i=0; i<m_triangles.size(); i++) 00754 { 00755 uint k = m_tris[i].a; 00756 array[k].push_back(i); 00757 00758 k = m_tris[i].b; 00759 array[k].push_back(i); 00760 00761 k = m_tris[i].c; 00762 array[k].push_back(i); 00763 } 00764 00765 // now average the tangents and compute the binormals as (tangent X normal) 00766 for (size_t i=0; i<m_vertices.size(); i++) 00767 { 00768 v1 = zero3; 00769 v2 = zero3; 00770 int t = array[i].size(); 00771 00772 for (int k=0; k<t; k++) 00773 { 00774 v1.x += m_tris[array[i][k]].tangent.x; 00775 v1.y += m_tris[array[i][k]].tangent.y; 00776 v1.z += m_tris[array[i][k]].tangent.z; 00777 00778 v2.x += m_tris[array[i][k]].binormal.x; 00779 v2.y += m_tris[array[i][k]].binormal.y; 00780 v2.z += m_tris[array[i][k]].binormal.z; 00781 } 00782 m_tangents[i] = NormalizeVector(v1); 00783 //m_binormals[i] = NormalizeVector(v2); 00784 00785 m_binormals[i] = NormalizeVector(CrossProduct(m_tangents[i], m_normals[i])); 00786 } 00787 }
| void LMesh::TransformVertices | ( | ) | [protected] |
Definition at line 538 of file OSG3DSLoader.cpp.
References m_matrix, m_vertices, and VectorByMatrix().
Referenced by Optimize().
00539 { 00540 for (uint i=0; i<m_vertices.size(); i++) 00541 m_vertices[i] = VectorByMatrix(m_matrix, m_vertices[i]); 00542 }
| const std::string & LObject::GetName | ( | ) | [virtual, inherited] |
Definition at line 234 of file OSG3DSLoader.cpp.
References LObject::m_name.
Referenced by OSG::A3DSSceneFileType::createMesh().
00235 { 00236 return m_name; 00237 }
| void LObject::SetName | ( | const std::string & | value | ) | [virtual, inherited] |
Definition at line 229 of file OSG3DSLoader.cpp.
References LObject::m_name.
Referenced by L3DS::ReadCamera(), L3DS::ReadLight(), L3DS::ReadMaterial(), and L3DS::ReadMesh().
| bool LObject::IsObject | ( | const std::string & | name | ) | [inherited] |
std::vector<LVector4> LMesh::m_vertices [protected] |
Definition at line 286 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetVertex(), GetVertexCount(), SetBinormal(), SetNormal(), SetTangent(), SetUV(), SetVertex(), SetVertexArraySize(), and TransformVertices().
std::vector<LVector3> LMesh::m_normals [protected] |
Definition at line 287 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetNormal(), SetNormal(), and SetVertexArraySize().
std::vector<LVector3> LMesh::m_binormals [protected] |
Definition at line 288 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetBinormal(), SetBinormal(), and SetVertexArraySize().
std::vector<LVector3> LMesh::m_tangents [protected] |
Definition at line 289 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetTangent(), SetTangent(), and SetVertexArraySize().
std::vector<LVector2> LMesh::m_uv [protected] |
Definition at line 290 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetUV(), SetUV(), and SetVertexArraySize().
std::vector<LTriangle> LMesh::m_triangles [protected] |
Definition at line 293 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetTriangle(), GetTriangleCount(), SetTri(), and SetTriangleArraySize().
std::vector<LTri> LMesh::m_tris [protected] |
Definition at line 296 of file OSG3DSLoader.h.
Referenced by CalcNormals(), CalcTextureSpace(), Clear(), GetTri(), GetTriangle2(), SetTri(), and SetTriangleArraySize().
LMatrix4 LMesh::m_matrix [protected] |
Definition at line 299 of file OSG3DSLoader.h.
Referenced by Clear(), GetMatrix(), SetMatrix(), and TransformVertices().
std::vector<uint> LMesh::m_materials [protected] |
Definition at line 302 of file OSG3DSLoader.h.
Referenced by AddMaterial(), Clear(), GetMaterial(), and GetMaterialCount().
std::string LObject::m_name [protected, inherited] |
Definition at line 140 of file OSG3DSLoader.h.
Referenced by LObject::GetName(), LObject::IsObject(), LObject::LObject(), and LObject::SetName().