diff options
Diffstat (limited to 'benchmarks3d')
| -rw-r--r-- | benchmarks3d/Cargo.toml | 6 | ||||
| -rw-r--r-- | benchmarks3d/all_benchmarks3.rs | 2 | ||||
| -rw-r--r-- | benchmarks3d/convex_polyhedron3.rs (renamed from benchmarks3d/harness_capsules3.rs) | 43 | ||||
| -rw-r--r-- | benchmarks3d/heightfield3.rs | 8 | ||||
| -rw-r--r-- | benchmarks3d/trimesh3.rs | 39 |
5 files changed, 55 insertions, 43 deletions
diff --git a/benchmarks3d/Cargo.toml b/benchmarks3d/Cargo.toml index 1ae91e4..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" @@ -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/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/harness_capsules3.rs b/benchmarks3d/convex_polyhedron3.rs index 4632811..30d77ac 100644 --- a/benchmarks3d/harness_capsules3.rs +++ b/benchmarks3d/convex_polyhedron3.rs @@ -1,10 +1,11 @@ -extern crate nalgebra as na; - +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::harness::Harness; +use rapier_testbed3d::Testbed; -pub fn init_world(harness: &mut Harness) { +pub fn init_world(testbed: &mut Testbed) { /* * World */ @@ -29,27 +30,39 @@ pub fn init_world(harness: &mut Harness) { * 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 shifty = rad * 4.0; + 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 { for k in 0usize..num { let x = i as f32 * shift - centerx + offset; - let y = j as f32 * shifty + centery + 3.0; + 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<f32> = 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 collider = ColliderBuilder::capsule_y(rad, rad).build(); + let collider = ColliderBuilder::round_convex_hull(&points, border_rad) + .unwrap() + .build(); colliders.insert(collider, handle, &mut bodies); } } @@ -58,15 +71,13 @@ pub fn init_world(harness: &mut Harness) { } /* - * Set up the harness. + * Set up the testbed. */ - harness.set_world(bodies, colliders, joints); + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin()); } fn main() { - let harness = &mut Harness::new_empty(); - init_world(harness); - harness.set_max_steps(10000); - harness.run(); - println!("{}", harness.state.timestep_id); + let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]); + testbed.run() } 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. + <f32 as ComplexField>::sin(x) + <f32 as ComplexField>::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. + <f32 as ComplexField>::sin(x) + <f32 as ComplexField>::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); |
