Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure triangles are always oriented correctly #61

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/kernel/topology/faces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use parry2d_f64::{
bounding_volume::AABB,
query::{Ray as Ray2, RayCast as _},
shape::Triangle as Triangle2,
utils::point_in_triangle::{corner_direction, Orientation},
};
use parry3d_f64::{
math::Isometry, query::Ray as Ray3, shape::Triangle as Triangle3,
Expand Down Expand Up @@ -216,7 +217,22 @@ pub fn triangulate(vertices: &[Point<2>]) -> Vec<Triangle2> {
let i1 = triangle[1];
let i2 = triangle[2];

triangles.push([vertices[i0], vertices[i2], vertices[i1]].into());
let v0 = vertices[i0];
let v1 = vertices[i1];
let v2 = vertices[i2];

let triangle = match corner_direction(&v0, &v1, &v2) {
Orientation::Ccw => [v0, v1, v2].into(),
Orientation::Cw => [v0, v2, v1].into(),
Orientation::None => {
panic!(
"Triangle returned from triangulation isn't actually a\
triangle"
);
}
};

triangles.push(triangle);
}

triangles
Expand Down