Move 2D benchmarks into their own directory/crate.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d",
|
members = [ "build/rapier2d", "build/rapier_testbed2d", "examples2d", "benchmarks2d",
|
||||||
"build/rapier3d", "build/rapier_testbed3d", "examples3d", "benchmarks3d" ]
|
"build/rapier3d", "build/rapier_testbed3d", "examples3d", "benchmarks3d" ]
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|||||||
27
benchmarks2d/Cargo.toml
Normal file
27
benchmarks2d/Cargo.toml
Normal file
@@ -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"
|
||||||
82
benchmarks2d/all_benchmarks2.rs
Normal file
82
benchmarks2d/all_benchmarks2.rs
Normal file
@@ -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()
|
||||||
|
}
|
||||||
72
benchmarks2d/heightfield2.rs
Normal file
72
benchmarks2d/heightfield2.rs
Normal file
@@ -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()
|
||||||
|
}
|
||||||
60
benchmarks2d/pyramid2.rs
Normal file
60
benchmarks2d/pyramid2.rs
Normal file
@@ -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()
|
||||||
|
}
|
||||||
@@ -11,18 +11,12 @@ use rapier_testbed2d::Testbed;
|
|||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
mod add_remove2;
|
mod add_remove2;
|
||||||
mod balls2;
|
|
||||||
mod boxes2;
|
|
||||||
mod capsules2;
|
|
||||||
mod debug_box_ball2;
|
mod debug_box_ball2;
|
||||||
mod heightfield2;
|
mod heightfield2;
|
||||||
mod joints2;
|
mod joints2;
|
||||||
mod kinematic2;
|
mod platform2;
|
||||||
mod pyramid2;
|
mod pyramid2;
|
||||||
mod sensor2;
|
mod sensor2;
|
||||||
mod stress_joint_ball2;
|
|
||||||
mod stress_joint_fixed2;
|
|
||||||
mod stress_joint_prismatic2;
|
|
||||||
|
|
||||||
fn demo_name_from_command_line() -> Option<String> {
|
fn demo_name_from_command_line() -> Option<String> {
|
||||||
let mut args = std::env::args();
|
let mut args = std::env::args();
|
||||||
@@ -58,21 +52,12 @@ pub fn main() {
|
|||||||
|
|
||||||
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
|
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
|
||||||
("Add remove", add_remove2::init_world),
|
("Add remove", add_remove2::init_world),
|
||||||
("Balls", balls2::init_world),
|
|
||||||
("Boxes", boxes2::init_world),
|
|
||||||
("Capsules", capsules2::init_world),
|
|
||||||
("Heightfield", heightfield2::init_world),
|
("Heightfield", heightfield2::init_world),
|
||||||
("Joints", joints2::init_world),
|
("Joints", joints2::init_world),
|
||||||
("Kinematic", kinematic2::init_world),
|
("Platform", platform2::init_world),
|
||||||
("Pyramid", pyramid2::init_world),
|
("Pyramid", pyramid2::init_world),
|
||||||
("Sensor", sensor2::init_world),
|
("Sensor", sensor2::init_world),
|
||||||
("(Debug) box ball", debug_box_ball2::init_world),
|
("(Debug) box ball", debug_box_ball2::init_world),
|
||||||
("(Stress test) joint ball", stress_joint_ball2::init_world),
|
|
||||||
("(Stress test) joint fixed", stress_joint_fixed2::init_world),
|
|
||||||
(
|
|
||||||
"(Stress test) joint prismatic",
|
|
||||||
stress_joint_prismatic2::init_world,
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Lexicographic sort, with stress tests moved at the end of the list.
|
// Lexicographic sort, with stress tests moved at the end of the list.
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
||||||
if i == 0 || i == nsubdivs {
|
if i == 0 || i == nsubdivs {
|
||||||
80.0
|
8.0
|
||||||
} else {
|
} else {
|
||||||
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
|
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Create the cubes
|
* Create the cubes
|
||||||
*/
|
*/
|
||||||
let num = 26;
|
let num = 20;
|
||||||
let rad = 0.5;
|
let rad = 0.5;
|
||||||
|
|
||||||
let shift = rad * 2.0;
|
let shift = rad * 2.0;
|
||||||
@@ -41,7 +41,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let centery = shift / 2.0;
|
let centery = shift / 2.0;
|
||||||
|
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
for j in 0usize..num * 5 {
|
for j in 0usize..num {
|
||||||
let x = i as f32 * shift - centerx;
|
let x = i as f32 * shift - centerx;
|
||||||
let y = j as f32 * shift + centery + 3.0;
|
let y = j as f32 * shift + centery + 3.0;
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
testbed.look_at(Point2::new(0.0, 0.0), 10.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// in order to be able to compare rapier with Box2D,
|
// in order to be able to compare rapier with Box2D,
|
||||||
// we set it to 0.4.
|
// we set it to 0.4.
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
let numi = 100; // Num vertical nodes.
|
let numi = 10; // Num vertical nodes.
|
||||||
let numk = 100; // Num horizontal nodes.
|
let numk = 10; // Num horizontal nodes.
|
||||||
let shift = 1.0;
|
let shift = 1.0;
|
||||||
|
|
||||||
let mut body_handles = Vec::new();
|
let mut body_handles = Vec::new();
|
||||||
@@ -30,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let fk = k as f32;
|
let fk = k as f32;
|
||||||
let fi = i as f32;
|
let fi = i as f32;
|
||||||
|
|
||||||
let status = if i == 0 && (k % 4 == 0 || k == numk - 1) {
|
let status = if i == 0 && k == 0 {
|
||||||
BodyStatus::Static
|
BodyStatus::Static
|
||||||
} else {
|
} else {
|
||||||
BodyStatus::Dynamic
|
BodyStatus::Dynamic
|
||||||
@@ -66,7 +66,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 5.0);
|
testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let centery = shift / 2.0 + 3.04;
|
let centery = shift / 2.0 + 3.04;
|
||||||
|
|
||||||
for i in 0usize..num {
|
for i in 0usize..num {
|
||||||
for j in 0usize..num * 50 {
|
for j in 0usize..num {
|
||||||
let x = i as f32 * shift - centerx;
|
let x = i as f32 * shift - centerx;
|
||||||
let y = j as f32 * shift + centery;
|
let y = j as f32 * shift + centery;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* Ground
|
||||||
*/
|
*/
|
||||||
let ground_size = 100.0;
|
let ground_size = 10.0;
|
||||||
let ground_thickness = 1.0;
|
let ground_thickness = 1.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
@@ -25,7 +25,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Create the cubes
|
* Create the cubes
|
||||||
*/
|
*/
|
||||||
let num = 100;
|
let num = 10;
|
||||||
let rad = 0.5;
|
let rad = 0.5;
|
||||||
|
|
||||||
let shift = rad * 2.0;
|
let shift = rad * 2.0;
|
||||||
@@ -51,7 +51,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(Point2::new(0.0, 2.5), 5.0);
|
testbed.look_at(Point2::new(0.0, 2.5), 20.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user