Merge pull request #50282 from mortarroad/master-fix-convex-hull-winding

Fix winding of new convex hull implementation.
This commit is contained in:
Camille Mohr-Daurat 2021-08-20 08:20:23 -07:00 committed by GitHub
commit 21cf7e8617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -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.");
}