diff options
author | Camille Mohr-Daurat <pouleyKetchoup@gmail.com> | 2021-08-20 08:20:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-20 08:20:23 -0700 |
commit | 21cf7e86170155a7aff913657b8acbe87f86ef70 (patch) | |
tree | 93795b21c3db2f2397519848c2dd383c6e66f750 | |
parent | f5422c55fc47523beb1f246ca2c22a467272d641 (diff) | |
parent | 054c7a125f6176a8343cd36faa0ee93b47dc7b30 (diff) |
Merge pull request #50282 from mortarroad/master-fix-convex-hull-winding
Fix winding of new convex hull implementation.
-rw-r--r-- | core/math/convex_hull.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/math/convex_hull.cpp b/core/math/convex_hull.cpp index 682a7ea39e..21cb0efe20 100644 --- a/core/math/convex_hull.cpp +++ b/core/math/convex_hull.cpp @@ -2278,9 +2278,18 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3 e = e->get_next_edge_of_face(); } while (e != e_start); + // reverse indices: Godot wants clockwise, but this is counter-clockwise + if (face.indices.size() > 2) { + // reverse all but the first index. + int *indices = face.indices.ptrw(); + for (int c = 0; c < (face.indices.size() - 1) / 2; c++) { + SWAP(indices[c + 1], indices[face.indices.size() - 1 - c]); + } + } + // compute normal if (face.indices.size() >= 3) { - face.plane = Plane(r_mesh.vertices[face.indices[0]], r_mesh.vertices[face.indices[2]], r_mesh.vertices[face.indices[1]]); + face.plane = Plane(r_mesh.vertices[face.indices[0]], r_mesh.vertices[face.indices[1]], r_mesh.vertices[face.indices[2]]); } else { WARN_PRINT("Too few vertices per face."); } |