diff options
| -rw-r--r-- | crates/rapier2d-f64/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/rapier2d/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/rapier3d-f64/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/rapier3d/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples3d/all_examples3.rs | 2 | ||||
| -rw-r--r-- | examples3d/debug_internal_edges3.rs | 60 | ||||
| -rw-r--r-- | examples3d/trimesh3.rs | 6 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 12 |
8 files changed, 82 insertions, 6 deletions
diff --git a/crates/rapier2d-f64/Cargo.toml b/crates/rapier2d-f64/Cargo.toml index 4e8c611..989ff14 100644 --- a/crates/rapier2d-f64/Cargo.toml +++ b/crates/rapier2d-f64/Cargo.toml @@ -49,7 +49,7 @@ vec_map = { version = "0.8", optional = true } instant = { version = "0.1", features = [ "now" ], optional = true } num-traits = "0.2" nalgebra = "0.31" -parry2d-f64 = "0.11" +parry2d-f64 = "^0.11.1" simba = "0.7" approx = "0.5" rayon = { version = "1", optional = true } diff --git a/crates/rapier2d/Cargo.toml b/crates/rapier2d/Cargo.toml index df6f0f6..0981216 100644 --- a/crates/rapier2d/Cargo.toml +++ b/crates/rapier2d/Cargo.toml @@ -49,7 +49,7 @@ vec_map = { version = "0.8", optional = true } instant = { version = "0.1", features = [ "now" ], optional = true } num-traits = "0.2" nalgebra = "0.31" -parry2d = "0.11" +parry2d = "^0.11.1" simba = "0.7" approx = "0.5" rayon = { version = "1", optional = true } diff --git a/crates/rapier3d-f64/Cargo.toml b/crates/rapier3d-f64/Cargo.toml index 93216c7..590fdf0 100644 --- a/crates/rapier3d-f64/Cargo.toml +++ b/crates/rapier3d-f64/Cargo.toml @@ -49,7 +49,7 @@ vec_map = { version = "0.8", optional = true } instant = { version = "0.1", features = [ "now" ], optional = true } num-traits = "0.2" nalgebra = "0.31" -parry3d-f64 = "0.11" +parry3d-f64 = "^0.11.1" simba = "0.7" approx = "0.5" rayon = { version = "1", optional = true } diff --git a/crates/rapier3d/Cargo.toml b/crates/rapier3d/Cargo.toml index 43d0d90..8acd591 100644 --- a/crates/rapier3d/Cargo.toml +++ b/crates/rapier3d/Cargo.toml @@ -49,7 +49,7 @@ vec_map = { version = "0.8", optional = true } instant = { version = "0.1", features = [ "now" ], optional = true } num-traits = "0.2" nalgebra = "0.31" -parry3d = "0.11" +parry3d = "^0.11.1" simba = "0.7" approx = "0.5" rayon = { version = "1", optional = true } diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs index f599fdb..749cec0 100644 --- a/examples3d/all_examples3.rs +++ b/examples3d/all_examples3.rs @@ -34,6 +34,7 @@ mod heightfield3; mod joints3; // mod joints3; mod character_controller3; +mod debug_internal_edges3; mod keva3; mod locked_rotations3; mod newton_cradle3; @@ -114,6 +115,7 @@ pub fn main() { debug_dynamic_collider_add3::init_world, ), ("(Debug) friction", debug_friction3::init_world), + ("(Debug) internal edges", debug_internal_edges3::init_world), ("(Debug) triangle", debug_triangle3::init_world), ("(Debug) trimesh", debug_trimesh3::init_world), ("(Debug) cylinder", debug_cylinder3::init_world), diff --git a/examples3d/debug_internal_edges3.rs b/examples3d/debug_internal_edges3.rs new file mode 100644 index 0000000..7112fb0 --- /dev/null +++ b/examples3d/debug_internal_edges3.rs @@ -0,0 +1,60 @@ +use rapier3d::prelude::*; +use rapier_testbed3d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let impulse_joints = ImpulseJointSet::new(); + let multibody_joints = MultibodyJointSet::new(); + + let heights = DMatrix::zeros(100, 100); + let heightfield = HeightField::new(heights, vector![60.0, 1.0, 60.0]); + let rotation = vector![0.0, 0.0, 0.0]; // vector![-0.1, 0.0, 0.0]; + colliders + .insert(ColliderBuilder::new(SharedShape::new(heightfield.clone())).rotation(rotation)); + + // let mut trimesh = TriMesh::from(heightfield); + // trimesh.set_flags(TriMeshFlags::MERGE_DUPLICATE_VERTICES) + // colliders.insert(ColliderBuilder::new(SharedShape::new(trimesh.clone())).rotation(rotation)); + // // NOTE: we add a sensor just because we want the testbed to display the mesh’s wireframe. + // colliders.insert( + // ColliderBuilder::new(SharedShape::new(trimesh)) + // .sensor(true) + // .rotation(rotation), + // ); + + // Dynamic rigid bodies. + let rigid_body = RigidBodyBuilder::dynamic() + .translation(vector![4.0, 0.5, 0.0]) + .linvel(vector![0.0, -40.0, 20.0]) + .can_sleep(false); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::ball(0.5); + colliders.insert_with_parent(collider, handle, &mut bodies); + + let rigid_body = RigidBodyBuilder::dynamic() + .translation(vector![0.0, 0.5, 0.0]) + .linvel(vector![0.0, -4.0, 20.0]) + .can_sleep(false); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(0.5, 0.5, 0.5); + colliders.insert_with_parent(collider, handle, &mut bodies); + + let rigid_body = RigidBodyBuilder::dynamic() + .translation(vector![8.0, 0.2, 0.0]) + .linvel(vector![0.0, -4.0, 20.0]) + .can_sleep(false); + let handle = bodies.insert(rigid_body); + let collider = + ColliderBuilder::cylinder(0.5, 0.2).rotation(vector![0.0, 0.0, std::f32::consts::PI / 2.0]); + colliders.insert_with_parent(collider, handle, &mut bodies); + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, impulse_joints, multibody_joints); + testbed.look_at(point![10.0, 10.0, 10.0], Point::origin()); +} diff --git a/examples3d/trimesh3.rs b/examples3d/trimesh3.rs index 729fc3e..edbb539 100644 --- a/examples3d/trimesh3.rs +++ b/examples3d/trimesh3.rs @@ -38,7 +38,11 @@ pub fn init_world(testbed: &mut Testbed) { let rigid_body = RigidBodyBuilder::fixed(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::trimesh(vertices, indices); + let collider = ColliderBuilder::trimesh_with_flags( + vertices, + indices, + TriMeshFlags::MERGE_DUPLICATE_VERTICES, + ); colliders.insert_with_parent(collider, handle, &mut bodies); /* diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 723b3e1..95ae273 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -9,7 +9,7 @@ use crate::parry::transformation::vhacd::VHACDParameters; use crate::pipeline::{ActiveEvents, ActiveHooks}; use na::Unit; use parry::bounding_volume::Aabb; -use parry::shape::Shape; +use parry::shape::{Shape, TriMeshFlags}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[derive(Clone)] @@ -550,6 +550,16 @@ impl ColliderBuilder { Self::new(SharedShape::trimesh(vertices, indices)) } + /// Initializes a collider builder with a triangle mesh shape defined by its vertex and index buffers and + /// flags controlling its pre-processing. + pub fn trimesh_with_flags( + vertices: Vec<Point<Real>>, + indices: Vec<[u32; 3]>, + flags: TriMeshFlags, + ) -> Self { + Self::new(SharedShape::trimesh_with_flags(vertices, indices, flags)) + } + /// Initializes a collider builder with a compound shape obtained from the decomposition of /// the given trimesh (in 3D) or polyline (in 2D) into convex parts. pub fn convex_decomposition(vertices: &[Point<Real>], indices: &[[u32; DIM]]) -> Self { |
