summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorMax Hilbrunner <mhilbrunner@users.noreply.github.com>2021-09-07 21:50:16 +0200
committerGitHub <noreply@github.com>2021-09-07 21:50:16 +0200
commitf8fb2bc0b44a355d62c41fe89703ea4194716de5 (patch)
treef2f7510e3b32277c9af1efa4b9d77e257c1aefe4 /core/math
parent3f6a01e848a4c5b59ac69cd7d807f0dc4545715b (diff)
parent75dd294732a5670eb1978515a02cac109d169b3b (diff)
Merge pull request #52097 from mortarroad/master-fix-convex-hull-double-edges
Fix emitting duplicate edges for convex hulls
Diffstat (limited to 'core/math')
-rw-r--r--core/math/convex_hull.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp
index 21cb0efe20..f67035c803 100644
--- a/core/math/convex_hull.cpp
+++ b/core/math/convex_hull.cpp
@@ -2260,10 +2260,21 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3
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());