From 09a8e5982419b0ff0e37a5737f45beb07174eb5e Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Thu, 11 May 2023 04:15:09 -0700 Subject: [PATCH] Create half-edge structure before converting from the C++ array `userface` to the C array `face`. PiperOrigin-RevId: 531161474 Change-Id: I77d425f4b5e52b2e41c6c9a2ef187495fefda5b8 --- src/user/user_mesh.cc | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index 90c3f8a8..4c44aecd 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -280,20 +280,9 @@ void mjCMesh::Compile(int vfs_provider) { throw mjCError(this, "face data must be a multiple of 3"); } - // copy from user - nface = (int)userface.size()/3; - face = VecToArray(userface, !file.empty()); - - // check vertices exist - for (auto vertex_index : userface) { - if (vertex_index>=nvert || vertex_index < 0) { - throw mjCError(this, "found index in userface that exceeds uservert size."); - } - } - // create half-edge structure (if mesh was in XML) if (useredge.empty()) { - for (int i=0; i=nvert || vertex_index < 0) { + throw mjCError(this, "found index in userface that exceeds uservert size."); + } + } } // check for inconsistent face orientations @@ -701,23 +701,6 @@ void mjCMesh::LoadOBJ(mjResource* resource) { userfacetexcoord.push_back(mesh_index.texcoord_index); } } - - for (int i = 0; i < face_indices.size(); i += 3) { - // add edges - const float *v0 = uservert.data() + 3*face_indices[i+0].vertex_index; - const float *v1 = uservert.data() + 3*face_indices[i+1].vertex_index; - const float *v2 = uservert.data() + 3*face_indices[i+2].vertex_index; - - // only consider edges if the face contribution is significant - mjtNum normal[3]; - if (_triangle(normal, nullptr, v0, v1, v2)>sqrt(mjMINVAL)) { - useredge.push_back(std::pair(face_indices[i+0].vertex_index, face_indices[i+1].vertex_index)); - useredge.push_back(std::pair(face_indices[i+1].vertex_index, face_indices[i+2].vertex_index)); - useredge.push_back(std::pair(face_indices[i+2].vertex_index, face_indices[i+0].vertex_index)); - } else { - // TODO(b/255525326) - } - } } // flip the second texcoord