Replace Kiss3d by Bevy for the testbed renderer.

This commit is contained in:
Crozet Sébastien
2021-05-16 17:49:20 +02:00
parent f350ac35d9
commit 1a84bf2af3
88 changed files with 2327 additions and 3940 deletions

View File

@@ -17,7 +17,8 @@ rand = "0.8"
getrandom = { version = "0.2", features = [ "js" ] }
Inflector = "0.11"
nalgebra = "0.26"
kiss3d = "0.31"
wasm-bindgen = "0.2"
obj-rs = { version = "0.6", default-features = false }
[dependencies.rapier_testbed3d]
path = "../build/rapier_testbed3d"
@@ -32,3 +33,8 @@ path = "./all_examples3.rs"
[[bin]]
name = "harness_capsules3"
path = "./harness_capsules3.rs"
#[lib]
#crate-type = ["cdylib", "rlib"]
#path = "./all_examples3_wasm.rs"

View File

@@ -7,7 +7,7 @@ use wasm_bindgen::prelude::*;
use inflector::Inflector;
use rapier_testbed3d::Testbed;
use rapier_testbed3d::{Testbed, TestbedApp};
use std::cmp::Ordering;
mod ccd3;
@@ -131,7 +131,6 @@ pub fn main() {
.position(|builder| builder.0.to_camel_case().as_str() == demo.as_str())
.unwrap_or(0);
let testbed = Testbed::from_builders(i, builders);
let testbed = TestbedApp::from_builders(i, builders);
testbed.run()
}

View File

@@ -0,0 +1,136 @@
#![allow(dead_code)]
extern crate nalgebra as na;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use inflector::Inflector;
use rapier_testbed3d::{Testbed, TestbedApp};
use std::cmp::Ordering;
mod ccd3;
mod collision_groups3;
mod compound3;
mod convex_decomposition3;
mod convex_polyhedron3;
mod damping3;
mod debug_add_remove_collider3;
mod debug_big_colliders3;
mod debug_boxes3;
mod debug_cylinder3;
mod debug_dynamic_collider_add3;
mod debug_friction3;
mod debug_infinite_fall3;
mod debug_prismatic3;
mod debug_rollback3;
mod debug_shape_modification3;
mod debug_triangle3;
mod debug_trimesh3;
mod domino3;
mod fountain3;
mod heightfield3;
mod joints3;
mod keva3;
mod locked_rotations3;
mod one_way_platforms3;
mod platform3;
mod primitives3;
mod restitution3;
mod sensor3;
mod trimesh3;
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()?;
// if hash.len() > 0 {
// Some(hash[1..].to_string())
// } else {
// None
// }
}
#[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![
("Fountain", fountain3::init_world),
("Primitives", primitives3::init_world),
("CCD", ccd3::init_world),
("Collision groups", collision_groups3::init_world),
("Compound", compound3::init_world),
("Convex decomposition", convex_decomposition3::init_world),
("Convex polyhedron", convex_polyhedron3::init_world),
("Damping", damping3::init_world),
("Domino", domino3::init_world),
("Heightfield", heightfield3::init_world),
("Joints", joints3::init_world),
("Locked rotations", locked_rotations3::init_world),
("One-way platforms", one_way_platforms3::init_world),
("Platform", platform3::init_world),
("Restitution", restitution3::init_world),
("Sensor", sensor3::init_world),
("TriMesh", trimesh3::init_world),
("Keva tower", keva3::init_world),
(
"(Debug) add/rm collider",
debug_add_remove_collider3::init_world,
),
("(Debug) big colliders", debug_big_colliders3::init_world),
("(Debug) boxes", debug_boxes3::init_world),
(
"(Debug) dyn. coll. add",
debug_dynamic_collider_add3::init_world,
),
("(Debug) friction", debug_friction3::init_world),
("(Debug) triangle", debug_triangle3::init_world),
("(Debug) trimesh", debug_trimesh3::init_world),
("(Debug) cylinder", debug_cylinder3::init_world),
("(Debug) infinite fall", debug_infinite_fall3::init_world),
("(Debug) prismatic", debug_prismatic3::init_world),
("(Debug) rollback", debug_rollback3::init_world),
(
"(Debug) shape modification",
debug_shape_modification3::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 = TestbedApp::from_builders(i, builders);
testbed.run()
}

View File

@@ -30,9 +30,15 @@ fn create_wall(
colliders.insert(collider, handle, bodies);
k += 1;
if k % 2 == 0 {
testbed.set_body_color(handle, Point3::new(255. / 255., 131. / 255., 244.0 / 255.));
testbed.set_initial_body_color(
handle,
Point3::new(255. / 255., 131. / 255., 244.0 / 255.),
);
} else {
testbed.set_body_color(handle, Point3::new(131. / 255., 255. / 255., 244.0 / 255.));
testbed.set_initial_body_color(
handle,
Point3::new(131. / 255., 255. / 255., 244.0 / 255.),
);
}
}
}
@@ -114,10 +120,10 @@ pub fn init_world(testbed: &mut Testbed) {
.build();
let handle = bodies.insert(rigid_body);
colliders.insert(collider.clone(), handle, &mut bodies);
testbed.set_body_color(handle, Point3::new(0.2, 0.2, 1.0));
testbed.set_initial_body_color(handle, Point3::new(0.2, 0.2, 1.0));
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |_, mut graphics, physics, events, _| {
testbed.add_callback(move |mut graphics, physics, events, _| {
while let Ok(prox) = events.intersection_events.try_recv() {
let color = if prox.intersecting {
Point3::new(1.0, 1.0, 0.0)
@@ -145,8 +151,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -39,7 +39,7 @@ pub fn init_world(testbed: &mut Testbed) {
.build();
let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies);
testbed.set_collider_initial_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0));
testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0));
/*
* A blue floor that will collide with the BLUE group only.
@@ -50,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) {
.build();
let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies);
testbed.set_collider_initial_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0));
testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0));
/*
* Create the cubes
@@ -84,7 +84,7 @@ pub fn init_world(testbed: &mut Testbed) {
.build();
colliders.insert(collider, handle, &mut bodies);
testbed.set_body_color(handle, color);
testbed.set_initial_body_color(handle, color);
}
}
}
@@ -95,8 +95,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -93,8 +93,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -1,10 +1,11 @@
use kiss3d::loader::obj;
use na::{Point3, Translation3};
use na::Point3;
use obj::raw::object::Polygon;
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
use rapier3d::parry::bounding_volume::{self, BoundingVolume};
use rapier3d::parry::bounding_volume;
use rapier_testbed3d::Testbed;
use std::path::Path;
use std::fs::File;
use std::io::BufReader;
/*
* NOTE: The `r` macro is only here to convert from f64 to the `N` scalar type.
@@ -42,47 +43,45 @@ pub fn init_world(testbed: &mut Testbed) {
for (igeom, obj_path) in geoms.into_iter().enumerate() {
let deltas = na::one();
let mtl_path = Path::new("");
let mut shapes = Vec::new();
println!("Parsing and decomposing: {}", obj_path);
let obj = obj::parse_file(&Path::new(&obj_path), &mtl_path, "");
let input = BufReader::new(File::open(obj_path).unwrap());
if let Ok(model) = obj {
let meshes: Vec<_> = model
if let Ok(model) = obj::raw::parse_obj(input) {
let mut vertices: Vec<_> = model
.positions
.iter()
.map(|v| Point3::new(v.0, v.1, v.2))
.collect();
use std::iter::FromIterator;
let indices: Vec<_> = model
.polygons
.into_iter()
.map(|mesh| mesh.1.to_trimesh().unwrap())
.flat_map(|p| match p {
Polygon::P(idx) => idx.into_iter(),
Polygon::PT(idx) => Vec::from_iter(idx.into_iter().map(|i| i.0)).into_iter(),
Polygon::PN(idx) => Vec::from_iter(idx.into_iter().map(|i| i.0)).into_iter(),
Polygon::PTN(idx) => Vec::from_iter(idx.into_iter().map(|i| i.0)).into_iter(),
})
.collect();
// Compute the size of the model, to scale it and have similar size for everything.
let mut aabb =
bounding_volume::details::point_cloud_aabb(&deltas, &meshes[0].coords[..]);
for mesh in meshes[1..].iter() {
aabb.merge(&bounding_volume::details::point_cloud_aabb(
&deltas,
&mesh.coords[..],
));
}
let center = aabb.center().coords;
let aabb = bounding_volume::details::point_cloud_aabb(&deltas, &vertices);
let center = aabb.center();
let diag = (aabb.maxs - aabb.mins).norm();
for mut trimesh in meshes.into_iter() {
trimesh.translate_by(&Translation3::from(-center));
trimesh.scale_by_scalar(6.0 / diag);
vertices
.iter_mut()
.for_each(|p| *p = (*p - center.coords) * 6.0 / diag);
let vertices = trimesh.coords;
let indices: Vec<_> = trimesh
.indices
.unwrap_unified()
.into_iter()
.map(|idx| [idx.x, idx.y, idx.z])
.collect();
let indices: Vec<_> = indices
.chunks(3)
.map(|idx| [idx[0] as u32, idx[1] as u32, idx[2] as u32])
.collect();
let decomposed_shape = SharedShape::convex_decomposition(&vertices, &indices);
shapes.push(decomposed_shape);
}
let decomposed_shape = SharedShape::convex_decomposition(&vertices, &indices);
shapes.push(decomposed_shape);
// let compound = SharedShape::compound(compound_parts);
@@ -122,7 +121,7 @@ fn models() -> Vec<String> {
"media/models/hornbug.obj".to_string(),
"media/models/octopus_decimated.obj".to_string(),
"media/models/rabbit_decimated.obj".to_string(),
"media/models/rust_logo.obj".to_string(),
// "media/models/rust_logo.obj".to_string(),
"media/models/rust_logo_simplified.obj".to_string(),
"media/models/screwdriver_decimated.obj".to_string(),
"media/models/table.obj".to_string(),

View File

@@ -71,8 +71,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(30.0, 30.0, 30.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -34,12 +34,13 @@ pub fn init_world(testbed: &mut Testbed) {
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
colliders.insert(collider, ball_handle, &mut bodies);
testbed.add_callback(move |mut window, mut graphics, physics, _, _| {
testbed.add_callback(move |_, physics, _, _| {
// Remove then re-add the ground collider.
let removed_collider_handle = ground_collider_handle;
let coll = physics
.colliders
.remove(
ground_collider_handle,
removed_collider_handle,
&mut physics.islands,
&mut physics.bodies,
true,
@@ -48,10 +49,6 @@ pub fn init_world(testbed: &mut Testbed) {
ground_collider_handle = physics
.colliders
.insert(coll, ground_handle, &mut physics.bodies);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.add_collider(window, ground_collider_handle, &physics.colliders);
}
});
/*
@@ -60,8 +57,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -43,8 +43,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -44,8 +44,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -58,8 +58,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -45,7 +45,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut extra_colliders = Vec::new();
let snapped_frame = 51;
testbed.add_callback(move |mut window, mut graphics, physics, _, _| {
testbed.add_callback(move |mut graphics, physics, _, _| {
step += 1;
// Add a bigger ball collider
@@ -57,8 +57,8 @@ pub fn init_world(testbed: &mut Testbed) {
.colliders
.insert(collider, ball_handle, &mut physics.bodies);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.add_collider(window, new_ball_collider_handle, &physics.colliders);
if let Some(graphics) = &mut graphics {
graphics.add_collider(new_ball_collider_handle, &physics.colliders);
}
extra_colliders.push(new_ball_collider_handle);
@@ -79,6 +79,10 @@ pub fn init_world(testbed: &mut Testbed) {
step = snapped_frame;
for handle in &extra_colliders {
if let Some(graphics) = &mut graphics {
graphics.remove_collider(*handle, &physics.colliders);
}
physics
.colliders
.remove(*handle, &mut physics.islands, &mut physics.bodies, true);
@@ -102,8 +106,8 @@ pub fn init_world(testbed: &mut Testbed) {
.colliders
.insert(coll, ground_handle, &mut physics.bodies);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.add_collider(window, new_ground_collider_handle, &physics.colliders);
if let Some(graphics) = &mut graphics {
graphics.add_collider(new_ground_collider_handle, &physics.colliders);
}
extra_colliders.push(new_ground_collider_handle);
@@ -115,8 +119,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -41,10 +41,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
}

View File

@@ -48,8 +48,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.look_at(Point3::new(100.0, -10.0, 100.0), Point3::origin());
testbed.set_world(bodies, colliders, joints);
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -103,8 +103,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -44,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut step = 0;
let snapped_frame = 51;
testbed.add_callback(move |_, _, physics, _, _| {
testbed.add_callback(move |_, physics, _, _| {
step += 1;
// Snap the ball velocity or restore it.
@@ -70,8 +70,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -44,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut step = 0;
let snapped_frame = 51;
testbed.add_callback(move |_, _, physics, _, _| {
testbed.add_callback(move |_, physics, _, _| {
step += 1;
// Snap the ball velocity or restore it.
@@ -116,8 +116,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -41,8 +41,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -24,16 +24,16 @@ pub fn init_world(testbed: &mut Testbed) {
Point3::new(-width, -width, width),
];
let idx = vec![
[0, 1, 2],
[0, 2, 3],
[0, 2, 1],
[0, 3, 2],
[4, 5, 6],
[4, 6, 7],
[0, 4, 7],
[0, 7, 3],
[1, 5, 6],
[1, 6, 2],
[3, 2, 7],
[2, 6, 7],
[1, 6, 5],
[1, 2, 6],
[3, 7, 2],
[2, 7, 6],
[0, 1, 5],
[0, 5, 4],
];
@@ -54,6 +54,7 @@ pub fn init_world(testbed: &mut Testbed) {
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::trimesh(vtx, idx).build();
colliders.insert(collider, handle, &mut bodies);
testbed.set_initial_body_color(handle, Point3::new(0.3, 0.3, 0.3));
/*
* Set up the testbed.
@@ -61,8 +62,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width).build();
colliders.insert(collider, handle, &mut bodies);
testbed.set_body_color(handle, colors[i % 2]);
testbed.set_initial_body_color(handle, colors[i % 2]);
} else {
skip -= 1;
}
@@ -78,8 +78,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -25,7 +25,7 @@ pub fn init_world(testbed: &mut Testbed) {
colliders.insert(collider, handle, &mut bodies);
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |mut window, mut graphics, physics, _, run_state| {
testbed.add_callback(move |mut graphics, physics, _, run_state| {
let rigid_body = RigidBodyBuilder::new_dynamic()
.translation(0.0, 10.0, 0.0)
.build();
@@ -40,8 +40,8 @@ pub fn init_world(testbed: &mut Testbed) {
.colliders
.insert(collider, handle, &mut physics.bodies);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.add(window, handle, &physics.bodies, &physics.colliders);
if let Some(graphics) = &mut graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
}
if physics.bodies.len() > MAX_NUMBER_OF_BODIES {
@@ -68,8 +68,8 @@ pub fn init_world(testbed: &mut Testbed) {
&mut physics.joints,
);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.remove_body_nodes(window, *handle);
if let Some(graphics) = &mut graphics {
graphics.remove_body(*handle);
}
}
}
@@ -85,8 +85,3 @@ pub fn init_world(testbed: &mut Testbed) {
// .velocity_based_erp = 0.2;
testbed.look_at(Point3::new(-30.0, 4.0, -30.0), Point3::new(0.0, 1.0, 0.0));
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Add-remove", init_world)]);
testbed.run()
}

View File

@@ -97,8 +97,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -472,8 +472,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(15.0, 5.0, 42.0), Point3::new(13.0, 1.0, 1.0));
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Joints", init_world)]);
testbed.run()
}

View File

@@ -51,7 +51,7 @@ pub fn build_block(
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
colliders.insert(collider, handle, bodies);
testbed.set_body_color(handle, color0);
testbed.set_initial_body_color(handle, color0);
std::mem::swap(&mut color0, &mut color1);
}
}
@@ -73,7 +73,7 @@ pub fn build_block(
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
colliders.insert(collider, handle, bodies);
testbed.set_body_color(handle, color0);
testbed.set_initial_body_color(handle, color0);
std::mem::swap(&mut color0, &mut color1);
}
}
@@ -137,8 +137,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -59,8 +59,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(10.0, 3.0, 0.0), Point3::new(0.0, 3.0, 0.0));
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -100,7 +100,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Spawn cubes at regular intervals and apply a custom gravity
* depending on their position.
*/
testbed.add_callback(move |mut window, mut graphics, physics, _, run_state| {
testbed.add_callback(move |graphics, physics, _, run_state| {
if run_state.timestep_id % 50 == 0 && physics.bodies.len() <= 7 {
// Spawn a new cube.
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build();
@@ -112,8 +112,8 @@ pub fn init_world(testbed: &mut Testbed) {
.colliders
.insert(collider, handle, &mut physics.bodies);
if let (Some(graphics), Some(window)) = (&mut graphics, &mut window) {
graphics.add(window, handle, &physics.bodies, &physics.colliders);
if let Some(graphics) = graphics {
graphics.add_body(handle, &physics.bodies, &physics.colliders);
}
}
@@ -139,8 +139,3 @@ pub fn init_world(testbed: &mut Testbed) {
);
testbed.look_at(Point3::new(-100.0, 0.0, 0.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -65,7 +65,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Setup a callback to control the platform.
*/
let mut count = 0;
testbed.add_callback(move |_, _, physics, _, run_state| {
testbed.add_callback(move |_, physics, _, run_state| {
count += 1;
if count % 100 > 50 {
return;
@@ -95,8 +95,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(-10.0, 5.0, -10.0), Point3::origin());
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Kinematic body", init_world)]);
testbed.run()
}

View File

@@ -73,8 +73,3 @@ pub fn init_world(testbed: &mut 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()
}

View File

@@ -49,8 +49,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(0.0, 3.0, 30.0), Point3::new(0.0, 3.0, 0.0));
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
testbed.run()
}

View File

@@ -46,7 +46,7 @@ pub fn init_world(testbed: &mut Testbed) {
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
colliders.insert(collider, handle, &mut bodies);
testbed.set_body_color(handle, Point3::new(0.5, 0.5, 1.0));
testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0));
}
}
@@ -70,10 +70,10 @@ pub fn init_world(testbed: &mut Testbed) {
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
testbed.set_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0));
testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0));
// Callback that will be executed on the main loop to handle proximities.
testbed.add_callback(move |_, mut graphics, physics, events, _| {
testbed.add_callback(move |mut graphics, physics, events, _| {
while let Ok(prox) = events.intersection_events.try_recv() {
let color = if prox.intersecting {
Point3::new(1.0, 1.0, 0.0)
@@ -101,8 +101,3 @@ pub fn init_world(testbed: &mut Testbed) {
testbed.set_world(bodies, colliders, joints);
testbed.look_at(Point3::new(-6.0, 4.0, -6.0), Point3::new(0.0, 1.0, 0.0));
}
fn main() {
let testbed = Testbed::from_builders(0, vec![("Sensor", init_world)]);
testbed.run()
}

View File

@@ -102,8 +102,3 @@ pub fn init_world(testbed: &mut 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()
}