| 1251 | } |
| 1252 | |
| 1253 | Ref<SceneGraph::Node> SceneGraph::convert_triangles_to_quads ( Ref<SceneGraph::TriangleMeshNode> tmesh ) |
| 1254 | { |
| 1255 | Ref<SceneGraph::QuadMeshNode> qmesh = new SceneGraph::QuadMeshNode(tmesh->material,tmesh->time_range,0); |
| 1256 | |
| 1257 | for (auto& p : tmesh->positions) |
| 1258 | qmesh->positions.push_back(p); |
| 1259 | |
| 1260 | qmesh->normals = tmesh->normals; |
| 1261 | qmesh->texcoords = tmesh->texcoords; |
| 1262 | |
| 1263 | for (size_t i=0; i<tmesh->triangles.size(); i++) |
| 1264 | { |
| 1265 | const int a0 = tmesh->triangles[i+0].v0; |
| 1266 | const int a1 = tmesh->triangles[i+0].v1; |
| 1267 | const int a2 = tmesh->triangles[i+0].v2; |
| 1268 | if (i+1 == tmesh->triangles.size()) { |
| 1269 | qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a0,a1,a2,a2)); |
| 1270 | continue; |
| 1271 | } |
| 1272 | |
| 1273 | const int b0 = tmesh->triangles[i+1].v0; |
| 1274 | const int b1 = tmesh->triangles[i+1].v1; |
| 1275 | const int b2 = tmesh->triangles[i+1].v2; |
| 1276 | const std::pair<int,int> q = quad_index3(a0,a1,a2,b0,b1,b2); |
| 1277 | const int a3 = q.second; |
| 1278 | if (a3 == -1) { |
| 1279 | qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a0,a1,a2,a2)); |
| 1280 | continue; |
| 1281 | } |
| 1282 | |
| 1283 | if (q.first == -1) qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a1,a2,a3,a0)); |
| 1284 | else if (q.first == 0) qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a3,a1,a2,a0)); |
| 1285 | else if (q.first == 1) qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a0,a1,a3,a2)); |
| 1286 | else if (q.first == 2) qmesh->quads.push_back(SceneGraph::QuadMeshNode::Quad(a1,a2,a3,a0)); |
| 1287 | i++; |
| 1288 | } |
| 1289 | return qmesh.dynamicCast<SceneGraph::Node>(); |
| 1290 | } |
| 1291 | |
| 1292 | Ref<SceneGraph::Node> SceneGraph::convert_triangles_to_quads(Ref<SceneGraph::Node> node, float prop) |
| 1293 | { |
nothing calls this directly
no test coverage detected