From 9bf1321f8f1d2e116f44c2461a53f302c4ef4171 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 8 Dec 2020 17:31:49 +0100 Subject: Outsource the contact manifold, SAT, and some shapes. --- benchmarks3d/heightfield3.rs | 8 ++++++-- benchmarks3d/trimesh3.rs | 39 +++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'benchmarks3d') diff --git a/benchmarks3d/heightfield3.rs b/benchmarks3d/heightfield3.rs index 4f8211c..fc64856 100644 --- a/benchmarks3d/heightfield3.rs +++ b/benchmarks3d/heightfield3.rs @@ -1,4 +1,4 @@ -use na::{DMatrix, Point3, Vector3}; +use na::{ComplexField, DMatrix, Point3, Vector3}; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; use rapier3d::geometry::{ColliderBuilder, ColliderSet}; use rapier_testbed3d::Testbed; @@ -23,7 +23,11 @@ pub fn init_world(testbed: &mut Testbed) { } else { let x = i as f32 * ground_size.x / (nsubdivs as f32); let z = j as f32 * ground_size.z / (nsubdivs as f32); - x.sin() + z.cos() + + // NOTE: make sure we use the sin/cos from simba to ensure + // cross-platform determinism of the example when the + // enhanced_determinism feature is enabled. + ::sin(x) + ::cos(z) } }); diff --git a/benchmarks3d/trimesh3.rs b/benchmarks3d/trimesh3.rs index ce1d1c5..e0701f1 100644 --- a/benchmarks3d/trimesh3.rs +++ b/benchmarks3d/trimesh3.rs @@ -1,6 +1,6 @@ -use na::Point3; +use na::{ComplexField, DMatrix, Point3, Vector3}; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField}; use rapier_testbed3d::Testbed; pub fn init_world(testbed: &mut Testbed) { @@ -14,28 +14,27 @@ pub fn init_world(testbed: &mut Testbed) { /* * Ground */ - let ground_size = 200.0f32; - let ground_height = 1.0; + let ground_size = Vector3::new(200.0, 1.0, 200.0); let nsubdivs = 20; - let quad = rapier3d::ncollide::procedural::quad(ground_size, ground_size, nsubdivs, nsubdivs); - let indices = quad - .flat_indices() - .chunks(3) - .map(|is| Point3::new(is[0], is[2], is[1])) - .collect(); - let mut vertices = quad.coords; + let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| { + if i == 0 || i == nsubdivs || j == 0 || j == nsubdivs { + 10.0 + } else { + let x = i as f32 * ground_size.x / (nsubdivs as f32); + let z = j as f32 * ground_size.z / (nsubdivs as f32); - // ncollide generates a quad with `z` as the normal. - // so we switch z and y here and set a random altitude at each point. - for p in vertices.iter_mut() { - p.z = p.y; - p.y = (p.x.sin() + p.z.cos()) * ground_height; - - if p.x.abs() == ground_size / 2.0 || p.z.abs() == ground_size / 2.0 { - p.y = 10.0; + // NOTE: make sure we use the sin/cos from simba to ensure + // cross-platform determinism of the example when the + // enhanced_determinism feature is enabled. + ::sin(x) + ::cos(z) } - } + }); + + // Here we will build our trimesh from the mesh representation of an + // heightfield. + let heightfield = HeightField::new(heights, ground_size); + let (vertices, indices) = heightfield.to_trimesh(); let rigid_body = RigidBodyBuilder::new_static().build(); let handle = bodies.insert(rigid_body); -- cgit From cc6d1b973002b4d366bc81ec6bf9e8240ad7b404 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 14 Dec 2020 15:51:43 +0100 Subject: Outsource the Shape trait, wquadtree, and shape types. --- benchmarks3d/all_benchmarks3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'benchmarks3d') diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs index dfbbc51..fa81d87 100644 --- a/benchmarks3d/all_benchmarks3.rs +++ b/benchmarks3d/all_benchmarks3.rs @@ -55,7 +55,7 @@ pub fn main() { ("Heightfield", heightfield3::init_world), ("Stacks", stacks3::init_world), ("Pyramid", pyramid3::init_world), - ("Trimesh", trimesh3::init_world), + ("TriMesh", trimesh3::init_world), ("Joint ball", joint_ball3::init_world), ("Joint fixed", joint_fixed3::init_world), ("Joint revolute", joint_revolute3::init_world), -- cgit From 5386f08c9b8e2d602ec0c64c59aab150921d0250 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Thu, 17 Dec 2020 18:52:51 +0100 Subject: Fix trimesh benchmark name for backward compatibility of bench results. --- benchmarks3d/all_benchmarks3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'benchmarks3d') diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs index fa81d87..dfbbc51 100644 --- a/benchmarks3d/all_benchmarks3.rs +++ b/benchmarks3d/all_benchmarks3.rs @@ -55,7 +55,7 @@ pub fn main() { ("Heightfield", heightfield3::init_world), ("Stacks", stacks3::init_world), ("Pyramid", pyramid3::init_world), - ("TriMesh", trimesh3::init_world), + ("Trimesh", trimesh3::init_world), ("Joint ball", joint_ball3::init_world), ("Joint fixed", joint_fixed3::init_world), ("Joint revolute", joint_revolute3::init_world), -- cgit From 486fbd972f7951edf2d576c7c6bcbd02dcc28011 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 21 Dec 2020 16:01:22 +0100 Subject: Add example for 3D convex polyhedron. --- benchmarks3d/all_benchmarks3.rs | 2 ++ benchmarks3d/convex_polyhedron3.rs | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 benchmarks3d/convex_polyhedron3.rs (limited to 'benchmarks3d') diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs index dfbbc51..f35cb8e 100644 --- a/benchmarks3d/all_benchmarks3.rs +++ b/benchmarks3d/all_benchmarks3.rs @@ -14,6 +14,7 @@ mod balls3; mod boxes3; mod capsules3; mod compound3; +mod convex_polyhedron3; mod heightfield3; mod joint_ball3; mod joint_fixed3; @@ -52,6 +53,7 @@ pub fn main() { ("Boxes", boxes3::init_world), ("Capsules", capsules3::init_world), ("Compound", compound3::init_world), + ("Convex polyhedron", convex_polyhedron3::init_world), ("Heightfield", heightfield3::init_world), ("Stacks", stacks3::init_world), ("Pyramid", pyramid3::init_world), diff --git a/benchmarks3d/convex_polyhedron3.rs b/benchmarks3d/convex_polyhedron3.rs new file mode 100644 index 0000000..07bfb98 --- /dev/null +++ b/benchmarks3d/convex_polyhedron3.rs @@ -0,0 +1,71 @@ +use na::Point3; +use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier3d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed3d::Testbed; + +pub fn init_world(testbed: &mut Testbed) { + /* + * World + */ + let mut bodies = RigidBodySet::new(); + let mut colliders = ColliderSet::new(); + let joints = JointSet::new(); + + /* + * Ground + */ + let ground_size = 200.1; + let ground_height = 0.1; + + let rigid_body = RigidBodyBuilder::new_static() + .translation(0.0, -ground_height, 0.0) + .build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); + colliders.insert(collider, handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 8; + let rad = 1.0; + + let shift = rad * 2.0 + rad; + let centerx = shift * (num / 2) as f32; + let centery = shift / 2.0; + let centerz = shift * (num / 2) as f32; + + let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5; + + for j in 0usize..47 { + for i in 0..num { + for k in 0usize..num { + let x = i as f32 * shift - centerx + offset; + let y = j as f32 * shift + centery + 3.0; + let z = k as f32 * shift - centerz + offset; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); + let handle = bodies.insert(rigid_body); + let cylinder = rapier3d::cdl::shape::Cylinder::new(rad, rad).to_trimesh(4); + let collider = ColliderBuilder::round_convex_hull(&cylinder.0, 0.1) + .unwrap() + .build(); + colliders.insert(collider, handle, &mut bodies); + } + } + + offset -= 0.05 * rad * (num as f32 - 1.0); + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]); + testbed.run() +} -- cgit From ed529fb8dd2cfeb9020a8cffd5b825d7d1f8ce92 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 29 Dec 2020 11:42:57 +0100 Subject: Move the harness example to the examples folder. --- benchmarks3d/Cargo.toml | 4 --- benchmarks3d/harness_capsules3.rs | 72 --------------------------------------- 2 files changed, 76 deletions(-) delete mode 100644 benchmarks3d/harness_capsules3.rs (limited to 'benchmarks3d') diff --git a/benchmarks3d/Cargo.toml b/benchmarks3d/Cargo.toml index 1ae91e4..03194df 100644 --- a/benchmarks3d/Cargo.toml +++ b/benchmarks3d/Cargo.toml @@ -25,7 +25,3 @@ path = "../build/rapier3d" [[bin]] name = "all_benchmarks3" path = "all_benchmarks3.rs" - -[[bin]] -name = "harness_capsules3" -path = "harness_capsules3.rs" diff --git a/benchmarks3d/harness_capsules3.rs b/benchmarks3d/harness_capsules3.rs deleted file mode 100644 index 4632811..0000000 --- a/benchmarks3d/harness_capsules3.rs +++ /dev/null @@ -1,72 +0,0 @@ -extern crate nalgebra as na; - -use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; -use rapier3d::geometry::{ColliderBuilder, ColliderSet}; -use rapier_testbed3d::harness::Harness; - -pub fn init_world(harness: &mut Harness) { - /* - * World - */ - let mut bodies = RigidBodySet::new(); - let mut colliders = ColliderSet::new(); - let joints = JointSet::new(); - - /* - * Ground - */ - let ground_size = 200.1; - let ground_height = 0.1; - - let rigid_body = RigidBodyBuilder::new_static() - .translation(0.0, -ground_height, 0.0) - .build(); - let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build(); - colliders.insert(collider, handle, &mut bodies); - - /* - * Create the cubes - */ - let num = 8; - let rad = 1.0; - - let shift = rad * 2.0 + rad; - let shifty = rad * 4.0; - let centerx = shift * (num / 2) as f32; - let centery = shift / 2.0; - let centerz = shift * (num / 2) as f32; - - let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5; - - for j in 0usize..47 { - for i in 0..num { - for k in 0usize..num { - let x = i as f32 * shift - centerx + offset; - let y = j as f32 * shifty + centery + 3.0; - let z = k as f32 * shift - centerz + offset; - - // Build the rigid body. - let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); - let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::capsule_y(rad, rad).build(); - colliders.insert(collider, handle, &mut bodies); - } - } - - offset -= 0.05 * rad * (num as f32 - 1.0); - } - - /* - * Set up the harness. - */ - harness.set_world(bodies, colliders, joints); -} - -fn main() { - let harness = &mut Harness::new_empty(); - init_world(harness); - harness.set_max_steps(10000); - harness.run(); - println!("{}", harness.state.timestep_id); -} -- cgit From aa61fe65e3ff0289ecab57b4053a3410cf6d4a87 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Mon, 4 Jan 2021 15:14:25 +0100 Subject: Add support of 64-bits reals. --- benchmarks3d/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'benchmarks3d') diff --git a/benchmarks3d/Cargo.toml b/benchmarks3d/Cargo.toml index 03194df..16399c9 100644 --- a/benchmarks3d/Cargo.toml +++ b/benchmarks3d/Cargo.toml @@ -14,7 +14,7 @@ enhanced-determinism = [ "rapier3d/enhanced-determinism" ] [dependencies] rand = "0.7" Inflector = "0.11" -nalgebra = "0.23" +nalgebra = "0.24" [dependencies.rapier_testbed3d] path = "../build/rapier_testbed3d" -- cgit From d1ed279c4e70c46928c84cf9b7f4a1db539fd7cb Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Wed, 6 Jan 2021 12:22:46 +0100 Subject: Tesbted physx backend: add heightfield, trimesh, and convex mesh support. --- benchmarks3d/convex_polyhedron3.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'benchmarks3d') diff --git a/benchmarks3d/convex_polyhedron3.rs b/benchmarks3d/convex_polyhedron3.rs index 07bfb98..30d77ac 100644 --- a/benchmarks3d/convex_polyhedron3.rs +++ b/benchmarks3d/convex_polyhedron3.rs @@ -1,4 +1,6 @@ use na::Point3; +use rand::distributions::{Distribution, Standard}; +use rand::{rngs::StdRng, SeedableRng}; use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; use rapier3d::geometry::{ColliderBuilder, ColliderSet}; use rapier_testbed3d::Testbed; @@ -28,14 +30,19 @@ pub fn init_world(testbed: &mut Testbed) { * Create the cubes */ let num = 8; + let scale = 2.0; let rad = 1.0; + let border_rad = 0.1; - let shift = rad * 2.0 + rad; + let shift = border_rad * 2.0 + scale; let centerx = shift * (num / 2) as f32; let centery = shift / 2.0; let centerz = shift * (num / 2) as f32; - let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5; + let mut offset = -(num as f32) * shift * 0.5; + + let mut rng = StdRng::seed_from_u64(0); + let distribution = Standard; for j in 0usize..47 { for i in 0..num { @@ -44,11 +51,16 @@ pub fn init_world(testbed: &mut Testbed) { let y = j as f32 * shift + centery + 3.0; let z = k as f32 * shift - centerz + offset; + let mut points = Vec::new(); + for _ in 0..10 { + let pt: Point3 = distribution.sample(&mut rng); + points.push(pt * scale); + } + // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); let handle = bodies.insert(rigid_body); - let cylinder = rapier3d::cdl::shape::Cylinder::new(rad, rad).to_trimesh(4); - let collider = ColliderBuilder::round_convex_hull(&cylinder.0, 0.1) + let collider = ColliderBuilder::round_convex_hull(&points, border_rad) .unwrap() .build(); colliders.insert(collider, handle, &mut bodies); -- cgit