Create half-edge structure before converting from the C++ array userface to the C array face.

PiperOrigin-RevId: 531161474
Change-Id: I77d425f4b5e52b2e41c6c9a2ef187495fefda5b8
This commit is contained in:
Alessio Quaglino
2023-05-11 04:15:09 -07:00
committed by Copybara-Service
parent 41a7049920
commit 09a8e59824
+12 -29
View File
@@ -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<nface; i++) {
for (int i=0; i<userface.size()/3; i++) {
int v0 = userface[3*i+0];
int v1 = userface[3*i+1];
int v2 = userface[3*i+2];
@@ -307,6 +296,17 @@ void mjCMesh::Compile(int vfs_provider) {
}
}
}
// 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.");
}
}
}
// 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