diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-09-28 10:58:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-28 10:58:35 +0200 |
| commit | 90dffc59ed45e5b95c2a40699cb91d285a206e0e (patch) | |
| tree | fa25c9c94bf4cd18a84f1a8c2bea327cd875af5f | |
| parent | 3080c6e7d2e7bad0ac55095ccc24b1ac8bd5449a (diff) | |
| parent | e7466e2f6923d24e987a34f8ebaf839346af8d4e (diff) | |
| download | rapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.tar.gz rapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.tar.bz2 rapier-90dffc59ed45e5b95c2a40699cb91d285a206e0e.zip | |
Merge pull request #20 from dimforge/benchbot
Split benchmarks from examples
| -rw-r--r-- | Cargo.toml | 6 | ||||
| -rw-r--r-- | benchmarks2d/Cargo.toml | 27 | ||||
| -rw-r--r-- | benchmarks2d/all_benchmarks2.rs | 82 | ||||
| -rw-r--r-- | benchmarks2d/balls2.rs (renamed from examples2d/balls2.rs) | 2 | ||||
| -rw-r--r-- | benchmarks2d/boxes2.rs (renamed from examples2d/boxes2.rs) | 2 | ||||
| -rw-r--r-- | benchmarks2d/capsules2.rs (renamed from examples2d/capsules2.rs) | 4 | ||||
| -rw-r--r-- | benchmarks2d/heightfield2.rs | 72 | ||||
| -rw-r--r-- | benchmarks2d/joint_ball2.rs (renamed from examples2d/stress_joint_ball2.rs) | 2 | ||||
| -rw-r--r-- | benchmarks2d/joint_fixed2.rs (renamed from examples2d/stress_joint_fixed2.rs) | 2 | ||||
| -rw-r--r-- | benchmarks2d/joint_prismatic2.rs (renamed from examples2d/stress_joint_prismatic2.rs) | 0 | ||||
| -rw-r--r-- | benchmarks2d/pyramid2.rs | 60 | ||||
| -rw-r--r-- | benchmarks3d/Cargo.toml | 27 | ||||
| -rw-r--r-- | benchmarks3d/all_benchmarks3.rs | 91 | ||||
| -rw-r--r-- | benchmarks3d/balls3.rs | 58 | ||||
| -rw-r--r-- | benchmarks3d/boxes3.rs (renamed from examples3d/boxes3.rs) | 2 | ||||
| -rw-r--r-- | benchmarks3d/capsules3.rs (renamed from examples3d/capsules3.rs) | 2 | ||||
| -rw-r--r-- | benchmarks3d/compound3.rs | 76 | ||||
| -rw-r--r-- | benchmarks3d/heightfield3.rs | 78 | ||||
| -rw-r--r-- | benchmarks3d/joint_ball3.rs (renamed from examples3d/stress_joint_ball3.rs) | 2 | ||||
| -rw-r--r-- | benchmarks3d/joint_fixed3.rs (renamed from examples3d/stress_joint_fixed3.rs) | 2 | ||||
| -rw-r--r-- | benchmarks3d/joint_prismatic3.rs (renamed from examples3d/stress_joint_prismatic3.rs) | 0 | ||||
| -rw-r--r-- | benchmarks3d/joint_revolute3.rs (renamed from examples3d/stress_joint_revolute3.rs) | 0 | ||||
| -rw-r--r-- | benchmarks3d/keva3.rs (renamed from examples3d/stress_keva3.rs) | 8 | ||||
| -rw-r--r-- | benchmarks3d/pyramid3.rs (renamed from examples3d/pyramid3.rs) | 4 | ||||
| -rw-r--r-- | benchmarks3d/stacks3.rs | 191 | ||||
| -rw-r--r-- | benchmarks3d/trimesh3.rs | 88 | ||||
| -rw-r--r-- | build/rapier_testbed2d/Cargo.toml | 1 | ||||
| -rw-r--r-- | build/rapier_testbed3d/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples2d/add_remove2.rs | 2 | ||||
| -rw-r--r-- | examples2d/all_examples2.rs | 19 | ||||
| -rw-r--r-- | examples2d/debug_box_ball2.rs | 2 | ||||
| -rw-r--r-- | examples2d/heightfield2.rs | 12 | ||||
| -rw-r--r-- | examples2d/joints2.rs | 10 | ||||
| -rw-r--r-- | examples2d/platform2.rs (renamed from examples2d/kinematic2.rs) | 8 | ||||
| -rw-r--r-- | examples2d/pyramid2.rs | 8 | ||||
| -rw-r--r-- | examples2d/sensor2.rs | 4 | ||||
| -rw-r--r-- | examples3d/add_remove3.rs | 2 | ||||
| -rw-r--r-- | examples3d/all_examples3.rs | 32 | ||||
| -rw-r--r-- | examples3d/balls3.rs | 29 | ||||
| -rw-r--r-- | examples3d/compound3.rs | 4 | ||||
| -rw-r--r-- | examples3d/debug_boxes3.rs | 2 | ||||
| -rw-r--r-- | examples3d/debug_triangle3.rs | 2 | ||||
| -rw-r--r-- | examples3d/domino3.rs | 4 | ||||
| -rw-r--r-- | examples3d/heightfield3.rs | 8 | ||||
| -rw-r--r-- | examples3d/joints3.rs | 4 | ||||
| -rw-r--r-- | examples3d/keva3.rs | 144 | ||||
| -rw-r--r-- | examples3d/platform3.rs (renamed from examples3d/kinematic3.rs) | 6 | ||||
| -rw-r--r-- | examples3d/primitives3.rs | 75 | ||||
| -rw-r--r-- | examples3d/sensor3.rs | 6 | ||||
| -rw-r--r-- | examples3d/stacks3.rs | 36 | ||||
| -rw-r--r-- | examples3d/trimesh3.rs | 8 | ||||
| -rw-r--r-- | src/geometry/collider.rs | 16 | ||||
| -rw-r--r-- | src_testbed/testbed.rs | 32 |
53 files changed, 1170 insertions, 195 deletions
@@ -1,12 +1,12 @@ [workspace] -members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d", - "build/rapier3d", "build/rapier_testbed3d", "examples3d" ] +members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d", "benchmarks2d", + "build/rapier3d", "build/rapier_testbed3d", "examples3d", "benchmarks3d" ] [patch.crates-io] #wrapped2d = { git = "https://github.com/Bastacyclop/rust_box2d.git" } [profile.release] -debug = false +#debug = true codegen-units = 1 #opt-level = 1 #lto = true diff --git a/benchmarks2d/Cargo.toml b/benchmarks2d/Cargo.toml new file mode 100644 index 0000000..b1ee8db --- /dev/null +++ b/benchmarks2d/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "rapier-benchmarks-2d" +version = "0.1.0" +authors = [ "Sébastien Crozet <developer@crozet.re>" ] +edition = "2018" + +[features] +parallel = [ "rapier2d/parallel", "rapier_testbed2d/parallel" ] +simd-stable = [ "rapier2d/simd-stable" ] +simd-nightly = [ "rapier2d/simd-nightly" ] +other-backends = [ "rapier_testbed2d/other-backends" ] +enhanced-determinism = [ "rapier2d/enhanced-determinism" ] + +[dependencies] +rand = "0.7" +Inflector = "0.11" +nalgebra = "0.22" + +[dependencies.rapier_testbed2d] +path = "../build/rapier_testbed2d" + +[dependencies.rapier2d] +path = "../build/rapier2d" + +[[bin]] +name = "all_benchmarks2" +path = "./all_benchmarks2.rs"
\ No newline at end of file diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs new file mode 100644 index 0000000..9a7a607 --- /dev/null +++ b/benchmarks2d/all_benchmarks2.rs @@ -0,0 +1,82 @@ +#![allow(dead_code)] + +extern crate nalgebra as na; + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::prelude::*; + +use inflector::Inflector; + +use rapier_testbed2d::Testbed; +use std::cmp::Ordering; + +mod balls2; +mod boxes2; +mod capsules2; +mod heightfield2; +mod joint_ball2; +mod joint_fixed2; +mod joint_prismatic2; +mod pyramid2; + +fn demo_name_from_command_line() -> Option<String> { + let mut args = std::env::args(); + + while let Some(arg) = args.next() { + if &arg[..] == "--example" { + return args.next(); + } + } + + None +} + +#[cfg(any(target_arch = "wasm32", target_arch = "asmjs"))] +fn demo_name_from_url() -> Option<String> { + None + // let window = stdweb::web::window(); + // let hash = window.location()?.search().ok()?; + // Some(hash[1..].to_string()) +} + +#[cfg(not(any(target_arch = "wasm32", target_arch = "asmjs")))] +fn demo_name_from_url() -> Option<String> { + None +} + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] +pub fn main() { + let demo = demo_name_from_command_line() + .or_else(|| demo_name_from_url()) + .unwrap_or(String::new()) + .to_camel_case(); + + let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ + ("Balls", balls2::init_world), + ("Boxes", boxes2::init_world), + ("Capsules", capsules2::init_world), + ("Heightfield", heightfield2::init_world), + ("Pyramid", pyramid2::init_world), + ("(Stress test) joint ball", joint_ball2::init_world), + ("(Stress test) joint fixed", joint_fixed2::init_world), + ( + "(Stress test) joint prismatic", + joint_prismatic2::init_world, + ), + ]; + + // Lexicographic sort, with stress tests moved at the end of the list. + builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + (true, true) | (false, false) => a.0.cmp(b.0), + (true, false) => Ordering::Greater, + (false, true) => Ordering::Less, + }); + + let i = builders + .iter() + .position(|builder| builder.0.to_camel_case().as_str() == demo.as_str()) + .unwrap_or(0); + let testbed = Testbed::from_builders(i, builders); + + testbed.run() +} diff --git a/examples2d/balls2.rs b/benchmarks2d/balls2.rs index 4c85d86..6791505 100644 --- a/examples2d/balls2.rs +++ b/benchmarks2d/balls2.rs @@ -50,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new(status).translation(x, y).build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::ball(rad).density(1.0).build(); + let collider = ColliderBuilder::ball(rad).build(); colliders.insert(collider, handle, &mut bodies); } } diff --git a/examples2d/boxes2.rs b/benchmarks2d/boxes2.rs index 8b09def..4fb9bf3 100644 --- a/examples2d/boxes2.rs +++ b/benchmarks2d/boxes2.rs @@ -55,7 +55,7 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(rad, rad).density(1.0).build(); + let collider = ColliderBuilder::cuboid(rad, rad).build(); colliders.insert(collider, handle, &mut bodies); } } diff --git a/examples2d/capsules2.rs b/benchmarks2d/capsules2.rs index 041edf5..76633bc 100644 --- a/examples2d/capsules2.rs +++ b/benchmarks2d/capsules2.rs @@ -56,9 +56,7 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::capsule_y(rad * 1.5, rad) - .density(1.0) - .build(); + let collider = ColliderBuilder::capsule_y(rad * 1.5, rad).build(); colliders.insert(collider, handle, &mut bodies); } } diff --git a/benchmarks2d/heightfield2.rs b/benchmarks2d/heightfield2.rs new file mode 100644 index 0000000..95fed6c --- /dev/null +++ b/benchmarks2d/heightfield2.rs @@ -0,0 +1,72 @@ +use na::{DVector, Point2, Vector2}; +use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed2d::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 = Vector2::new(50.0, 1.0); + let nsubdivs = 2000; + + let heights = DVector::from_fn(nsubdivs + 1, |i, _| { + if i == 0 || i == nsubdivs { + 80.0 + } else { + (i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0 + } + }); + + let rigid_body = RigidBodyBuilder::new_static().build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::heightfield(heights, ground_size).build(); + colliders.insert(collider, handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 26; + let rad = 0.5; + + let shift = rad * 2.0; + let centerx = shift * (num / 2) as f32; + let centery = shift / 2.0; + + for i in 0..num { + for j in 0usize..num * 5 { + let x = i as f32 * shift - centerx; + let y = j as f32 * shift + centery + 3.0; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let handle = bodies.insert(rigid_body); + + if j % 2 == 0 { + let collider = ColliderBuilder::cuboid(rad, rad).build(); + colliders.insert(collider, handle, &mut bodies); + } else { + let collider = ColliderBuilder::ball(rad).build(); + colliders.insert(collider, handle, &mut bodies); + } + } + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point2::new(0.0, 50.0), 10.0); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Heightfield", init_world)]); + testbed.run() +} diff --git a/examples2d/stress_joint_ball2.rs b/benchmarks2d/joint_ball2.rs index 55db1b7..ecfdc47 100644 --- a/examples2d/stress_joint_ball2.rs +++ b/benchmarks2d/joint_ball2.rs @@ -37,7 +37,7 @@ pub fn init_world(testbed: &mut Testbed) { .translation(fk * shift, -fi * shift) .build(); let child_handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::ball(rad).density(1.0).build(); + let collider = ColliderBuilder::ball(rad).build(); colliders.insert(collider, child_handle, &mut bodies); // Vertical joint. diff --git a/examples2d/stress_joint_fixed2.rs b/benchmarks2d/joint_fixed2.rs index 31b3e4f..32a219e 100644 --- a/examples2d/stress_joint_fixed2.rs +++ b/benchmarks2d/joint_fixed2.rs @@ -42,7 +42,7 @@ pub fn init_world(testbed: &mut Testbed) { .translation(x + fk * shift, y - fi * shift) .build(); let child_handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::ball(rad).density(1.0).build(); + let collider = ColliderBuilder::ball(rad).build(); colliders.insert(collider, child_handle, &mut bodies); // Vertical joint. diff --git a/examples2d/stress_joint_prismatic2.rs b/benchmarks2d/joint_prismatic2.rs index 91ef48e..91ef48e 100644 --- a/examples2d/stress_joint_prismatic2.rs +++ b/benchmarks2d/joint_prismatic2.rs diff --git a/benchmarks2d/pyramid2.rs b/benchmarks2d/pyramid2.rs new file mode 100644 index 0000000..e6a715b --- /dev/null +++ b/benchmarks2d/pyramid2.rs @@ -0,0 +1,60 @@ +use na::Point2; +use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet}; +use rapier2d::geometry::{ColliderBuilder, ColliderSet}; +use rapier_testbed2d::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 = 100.0; + let ground_thickness = 1.0; + + let rigid_body = RigidBodyBuilder::new_static().build(); + let ground_handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build(); + colliders.insert(collider, ground_handle, &mut bodies); + + /* + * Create the cubes + */ + let num = 100; + let rad = 0.5; + + let shift = rad * 2.0; + let centerx = shift * (num as f32) / 2.0; + let centery = shift / 2.0 + ground_thickness + rad * 1.5; + + for i in 0usize..num { + for j in i..num { + let fj = j as f32; + let fi = i as f32; + let x = (fi * shift / 2.0) + (fj - fi) * shift - centerx; + let y = fi * shift + centery; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::cuboid(rad, rad).build(); + colliders.insert(collider, handle, &mut bodies); + } + } + + /* + * Set up the testbed. + */ + testbed.set_world(bodies, colliders, joints); + testbed.look_at(Point2::new(0.0, 2.5), 5.0); +} + +fn main() { + let testbed = Testbed::from_builders(0, vec![("Balls", init_world)]); + testbed.run() +} diff --git a/benchmarks3d/Cargo.toml b/benchmarks3d/Cargo.toml new file mode 100644 index 0000000..81c843a --- /dev/null +++ b/benchmarks3d/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "rapier-benchmarks-3d" +version = "0.1.0" +authors = [ "Sébastien Crozet <developer@crozet.re>" ] +edition = "2018" + +[features] +parallel = [ "rapier3d/parallel", "rapier_testbed3d/parallel" ] +simd-stable = [ "rapier3d/simd-stable" ] +simd-nightly = [ "rapier3d/simd-nightly" ] +other-backends = [ "rapier_testbed3d/other-backends" ] +enhanced-determinism = [ "rapier3d/enhanced-determinism" ] + +[dependencies] +rand = "0.7" +Inflector = "0.11" +nalgebra = "0.22" + +[dependencies.rapier_testbed3d] +path = "../build/rapier_testbed3d" + +[dependencies.rapier3d] +path = "../build/rapier3d" + +[[bin]] +name = "all_benchmarks3" +path = "all_benchmarks3.rs" diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs new file mode 100644 index 0000000..dfbbc51 --- /dev/null +++ b/benchmarks3d/all_benchmarks3.rs @@ -0,0 +1,91 @@ +#![allow(dead_code)] + +extern crate nalgebra as na; + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::prelude::*; + +use inflector::Inflector; + +use rapier_testbed3d::Testbed; +use std::cmp::Ordering; + +mod balls3; +mod boxes3; +mod capsules3; +mod compound3; +mod heightfield3; +mod joint_ball3; +mod joint_fixed3; +mod joint_prismatic3; +mod joint_revolute3; +mod keva3; +mod pyramid3; +mod stacks3; +mod trimesh3; + +enum Command { + Run(String), + List, + RunAll, +} + +fn parse_command_line() -> Command { + let mut args = std::env::args(); + + while let Some(arg) = args.next() { + if &arg[..] == "--example" { + return Command::Run(args.next().unwrap_or(String::new())); + } else if &arg[..] == "--list" { + return Command::List; + } + } + + Command::RunAll +} + +pub fn main() { + let command = parse_command_line(); + + let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ + ("Balls", balls3::init_world), + ("Boxes", boxes3::init_world), + ("Capsules", capsules3::init_world), + ("Compound", compound3::init_world), + ("Heightfield", heightfield3::init_world), + ("Stacks", stacks3::init_world), + ("Pyramid", pyramid3::init_world), + ("Trimesh", trimesh3::init_world), + ("Joint ball", joint_ball3::init_world), + ("Joint fixed", joint_fixed3::init_world), + ("Joint revolute", joint_revolute3::init_world), + ("Joint prismatic", joint_prismatic3::init_world), + ("Keva tower", keva3::init_world), + ]; + + // Lexicographic sort, with stress tests moved at the end of the list. + builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + (true, true) | (false, false) => a.0.cmp(b.0), + (true, false) => Ordering::Greater, + (false, true) => Ordering::Less, + }); + + match command { + Command::Run(demo) => { + if let Some(i) = builders + .iter() + .position(|builder| builder.0.to_camel_case().as_str() == demo.as_str()) + { + Testbed::from_builders(0, vec![builders[i]]).run() + } else { + eprintln!("Invalid example to run provided: '{}'", demo); + } + } + Command::RunAll => Testbed::from_builders(0, builders).run(), + Command::List => { + for builder in &builders { + println!("{}", builder.0.to_camel_case()) + } + } + } +} diff --git a/benchmarks3d/balls3.rs b/benchmarks3d/balls3.rs new file mode 100644 index 0000000..bdbe75e --- /dev/null +++ b/benchmarks3d/balls3.rs @@ -0,0 +1,58 @@ +use na::Point3; +use rapier3d::dynamics::{BodyStatus, 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(); + + /* + * Create the balls + */ + let num = 20; + let rad = 1.0; + + let shift = rad * 2.0 + 1.0; + let centerx = shift * (num as f32) / 2.0; + let centery = shift / 2.0; + let centerz = shift * (num as f32) / 2.0; + + for i in 0..num { + for j in 0usize..num { + for k in 0..num { + let x = i as f32 * shift - centerx; + let y = j as f32 * shift + centery; + let z = k as f32 * shift - centerz; + + let status = if j == 0 { + BodyStatus::Static + } else { + BodyStatus::Dynamic + }; + let density = 0.477; + + // Build the rigid body. + let rigid_body = RigidBodyBuilder::new(status).translation(x, y, z).build(); + let handle = bodies.insert(rigid_body); + let collider = ColliderBuilder::ball(rad).density(density).build(); + colliders.insert(collider, handle, &mut bodies); + } + } + } + + /* + * 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![("Balls", init_world)]); + testbed.run() +} diff --git a/examples3d/boxes3.rs b/benchmarks3d/boxes3.rs index eb8a472..0eb31f5 100644 --- a/examples3d/boxes3.rs +++ b/benchmarks3d/boxes3.rs @@ -47,7 +47,7 @@ pub fn init_world(testbed: &mut Testbed) { // Build the rigid body. let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build(); let handle = bodies.insert(rigid_body); - let collider = ColliderBuilder::cuboid(rad, rad, rad).density(1.0).build(); + let collider = ColliderBuilder::cuboid(rad, rad, rad).build(); colliders.insert(collider, handle, &mut bodies); } } diff --git a/examples3d/capsules3.rs b/benchmarks3d/capsules3.rs index e6aad40..0e8ad94 100644 --- a/examples3d/capsules3.rs +++ b/benchmarks3d/capsules3.rs @@ -48,7 +48,7 @@ pub fn init_world(testbed: &mut Testbed) { // 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).density(1.0).build(); + let collider = ColliderBuilder::capsule_y(rad, rad).build(); colliders.insert(collider, handle, &mut bodies); } } diff --git a/benchmarks3d/compound3.rs b/benchmarks3d/compound3.rs new file mode 100644 index 0000000..a8a9939 --- /dev/null +++ b/benchmarks3d/compound3.rs @@ -0,0 +1,76 @@ +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 = 0.2; + + let shift = rad * 4.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..25 { + for i in 0..num { + for k in 0usize..num { + let x = i as f32 * shift * 5.0 - centerx + offset; + let y = j as f32 * (shift * 5.0) + centery + 3.0; + let z = |
