| 1016 | } |
| 1017 | |
| 1018 | Ref<SceneGraph::Node> XMLLoader::loadTriangleMesh(const Ref<XML>& xml) |
| 1019 | { |
| 1020 | Ref<SceneGraph::MaterialNode> material = loadMaterial(xml->child("material")); |
| 1021 | Ref<SceneGraph::TriangleMeshNode> mesh = new SceneGraph::TriangleMeshNode(material,BBox1f(0,1),0); |
| 1022 | |
| 1023 | if (Ref<XML> animation = xml->childOpt("animated_positions")) { |
| 1024 | for (size_t i=0; i<animation->size(); i++) |
| 1025 | mesh->positions.push_back(loadVec3faArray(animation->child(i))); |
| 1026 | } else { |
| 1027 | mesh->positions.push_back(loadVec3faArray(xml->childOpt("positions"))); |
| 1028 | if (xml->hasChild("positions2")) |
| 1029 | mesh->positions.push_back(loadVec3faArray(xml->childOpt("positions2"))); |
| 1030 | } |
| 1031 | |
| 1032 | if (Ref<XML> animation = xml->childOpt("animated_normals")) { |
| 1033 | for (size_t i=0; i<animation->size(); i++) |
| 1034 | mesh->normals.push_back(loadVec3faArray(animation->child(i))); |
| 1035 | } |
| 1036 | else if (Ref<XML> normalbuf = xml->childOpt("normals")) { |
| 1037 | auto vec = loadVec3faArray(normalbuf); |
| 1038 | if (vec.size()) |
| 1039 | for (size_t i=0; i<mesh->numTimeSteps(); i++) |
| 1040 | mesh->normals.push_back(vec); |
| 1041 | } |
| 1042 | |
| 1043 | mesh->texcoords = loadVec2fArray(xml->childOpt("texcoords")); |
| 1044 | |
| 1045 | std::vector<Vec3i> triangles = loadVec3iArray(xml->childOpt("triangles")); |
| 1046 | for (size_t i=0; i<triangles.size(); i++) |
| 1047 | mesh->triangles.push_back(SceneGraph::TriangleMeshNode::Triangle(triangles[i].x,triangles[i].y,triangles[i].z)); |
| 1048 | |
| 1049 | mesh->verify(); |
| 1050 | return mesh.dynamicCast<SceneGraph::Node>(); |
| 1051 | } |
| 1052 | |
| 1053 | Ref<SceneGraph::Node> XMLLoader::loadQuadMesh(const Ref<XML>& xml) |
| 1054 | { |