Skip to content

Commit

Permalink
Fix emitting duplicate edges for convex hulls
Browse files Browse the repository at this point in the history
  • Loading branch information
mortarroad authored and lekoder committed Dec 18, 2021
1 parent 0fe3e4e commit f6a4b04
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/math/convex_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,10 +2268,21 @@ Error ConvexHullComputer::convex_hull(const Vector3 *p_points, int32_t p_point_c

r_mesh.vertices = ch.vertices;

r_mesh.edges.resize(ch.edges.size());
// Copy the edges over. There's two "half-edges" for every edge, so we pick only one of them.
r_mesh.edges.resize(ch.edges.size() / 2);
uint32_t edges_copied = 0;
for (uint32_t i = 0; i < ch.edges.size(); i++) {
r_mesh.edges.write[i].a = (&ch.edges[i])->get_source_vertex();
r_mesh.edges.write[i].b = (&ch.edges[i])->get_target_vertex();
uint32_t a = (&ch.edges[i])->get_source_vertex();
uint32_t b = (&ch.edges[i])->get_target_vertex();
if (a < b) { // Copy only the "canonical" edge. For the reverse edge, this will be false.
ERR_BREAK(edges_copied >= (uint32_t)r_mesh.edges.size());
r_mesh.edges.write[edges_copied].a = a;
r_mesh.edges.write[edges_copied].b = b;
edges_copied++;
}
}
if (edges_copied != (uint32_t)r_mesh.edges.size()) {
ERR_PRINT("Invalid edge count.");
}

r_mesh.faces.resize(ch.faces.size());
Expand Down

0 comments on commit f6a4b04

Please sign in to comment.