aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2020-11-19 15:48:50 +0100
committerGitHub <noreply@github.com>2020-11-19 15:48:50 +0100
commite571a0628de5ce420646b3cb8b316acf1b134e8f (patch)
tree3e836ca8fee3f6ddfe838ecbef97ec0d824d7056
parent3f619d81ffc7899330e94ac34d3992a508dcf41b (diff)
parent49dfe74a1bd21081fcdfc73489430f7515b09e93 (diff)
downloadrapier-e571a0628de5ce420646b3cb8b316acf1b134e8f.tar.gz
rapier-e571a0628de5ce420646b3cb8b316acf1b134e8f.tar.bz2
rapier-e571a0628de5ce420646b3cb8b316acf1b134e8f.zip
Merge pull request #62 from dimforge/salva
Testbed: remove code related to salva and add a plugin system
-rw-r--r--build/rapier_testbed2d/Cargo.toml1
-rw-r--r--src/dynamics/rigid_body.rs6
-rw-r--r--src/geometry/shape.rs2
-rw-r--r--src_testbed/engine.rs121
-rw-r--r--src_testbed/lib.rs4
-rw-r--r--src_testbed/plugin.rs12
-rw-r--r--src_testbed/testbed.rs270
7 files changed, 105 insertions, 311 deletions
diff --git a/build/rapier_testbed2d/Cargo.toml b/build/rapier_testbed2d/Cargo.toml
index 08c0893..273595f 100644
--- a/build/rapier_testbed2d/Cargo.toml
+++ b/build/rapier_testbed2d/Cargo.toml
@@ -39,7 +39,6 @@ flexbuffers = "0.1"
Inflector = "0.11"
md5 = "0.7"
-
[dependencies.rapier2d]
path = "../rapier2d"
version = "0.3"
diff --git a/src/dynamics/rigid_body.rs b/src/dynamics/rigid_body.rs
index a1a23a0..303d1a0 100644
--- a/src/dynamics/rigid_body.rs
+++ b/src/dynamics/rigid_body.rs
@@ -370,6 +370,12 @@ impl RigidBody {
self.apply_impulse(impulse, wake_up);
self.apply_torque_impulse(torque_impulse, wake_up);
}
+
+ /// The velocity of the given world-space point on this rigid-body.
+ pub fn velocity_at_point(&self, point: &Point<f32>) -> Vector<f32> {
+ let dpt = point - self.world_com;
+ self.linvel + self.angvel.gcross(dpt)
+ }
}
/// A builder for rigid-bodies.
diff --git a/src/geometry/shape.rs b/src/geometry/shape.rs
index ec43bf7..5c96f68 100644
--- a/src/geometry/shape.rs
+++ b/src/geometry/shape.rs
@@ -64,6 +64,8 @@ pub trait Shape: RayCast<f32> + PointQuery<f32> + DowncastSync {
None
}
+ // TODO: add a compute_local_aabb method?
+
/// Computes the AABB of this shape.
fn compute_aabb(&self, position: &Isometry<f32>) -> AABB<f32>;
diff --git a/src_testbed/engine.rs b/src_testbed/engine.rs
index 52b9ca9..ff5e1ef 100644
--- a/src_testbed/engine.rs
+++ b/src_testbed/engine.rs
@@ -15,15 +15,11 @@ use rapier::dynamics::{RigidBodyHandle, RigidBodySet};
use rapier::geometry::{Collider, ColliderHandle, ColliderSet};
//use crate::objects::capsule::Capsule;
//use crate::objects::convex::Convex;
-//#[cfg(feature = "fluids")]
-//use crate::objects::fluid::Fluid as FluidNode;
//#[cfg(feature = "dim3")]
//use crate::objects::mesh::Mesh;
//use crate::objects::plane::Plane;
//#[cfg(feature = "dim2")]
//use crate::objects::polyline::Polyline;
-//#[cfg(feature = "fluids")]
-//use crate::objects::FluidRenderingMode;
use crate::objects::capsule::Capsule;
#[cfg(feature = "dim3")]
use crate::objects::cone::Cone;
@@ -58,22 +54,12 @@ impl GraphicsWindow for Window {
pub struct GraphicsManager {
rand: Pcg32,
b2sn: HashMap<RigidBodyHandle, Vec<Node>>,
- #[cfg(feature = "fluids")]
- f2sn: HashMap<FluidHandle, FluidNode>,
- #[cfg(feature = "fluids")]
- boundary2sn: HashMap<BoundaryHandle, FluidNode>,
b2color: HashMap<RigidBodyHandle, Point3<f32>>,
c2color: HashMap<ColliderHandle, Point3<f32>>,
b2wireframe: HashMap<RigidBodyHandle, bool>,
- #[cfg(feature = "fluids")]
- f2color: HashMap<FluidHandle, Point3<f32>>,
ground_color: Point3<f32>,
camera: Camera,
ground_handle: Option<RigidBodyHandle>,
- #[cfg(feature = "fluids")]
- fluid_rendering_mode: FluidRenderingMode,
- #[cfg(feature = "fluids")]
- render_boundary_particles: bool,
}
impl GraphicsManager {
@@ -96,21 +82,11 @@ impl GraphicsManager {
camera,
rand: Pcg32::seed_from_u64(0),
b2sn: HashMap::new(),
- #[cfg(feature = "fluids")]
- f2sn: HashMap::new(),
- #[cfg(feature = "fluids")]
- boundary2sn: HashMap::new(),
b2color: HashMap::new(),
c2color: HashMap::new(),
- #[cfg(feature = "fluids")]
- f2color: HashMap::new(),
ground_color: Point3::new(0.5, 0.5, 0.5),
b2wireframe: HashMap::new(),
ground_handle: None,
- #[cfg(feature = "fluids")]
- fluid_rendering_mode: FluidRenderingMode::StaticColor,
- #[cfg(feature = "fluids")]
- render_boundary_particles: false,
}
}
@@ -118,20 +94,6 @@ impl GraphicsManager {
self.ground_handle = handle
}
- #[cfg(feature = "fluids")]
- pub fn set_fluid_rendering_mode(&mut self, mode: FluidRenderingMode) {
- self.fluid_rendering_mode = mode;
- }
-
- #[cfg(feature = "fluids")]
- pub fn enable_boundary_particles_rendering(&mut self, enabled: bool) {
- self.render_boundary_particles = enabled;
-
- for sn in self.boundary2sn.values_mut() {
- sn.scene_node_mut().set_visible(enabled);
- }
- }
-
pub fn clear(&mut self, window: &mut Window) {
for sns in self.b2sn.values_mut() {
for sn in sns.iter_mut() {
@@ -141,17 +103,7 @@ impl GraphicsManager {
}
}
- #[cfg(feature = "fluids")]
- for sn in self.f2sn.values_mut().chain(self.boundary2sn.values_mut()) {
- let node = sn.scene_node_mut();
- window.remove_graphics_node(node);
- }
-
self.b2sn.clear();
- #[cfg(feature = "fluids")]
- self.f2sn.clear();
- #[cfg(feature = "fluids")]
- self.boundary2sn.clear();
self.c2color.clear();
self.b2color.clear();
self.b2wireframe.clear();
@@ -170,15 +122,6 @@ impl GraphicsManager {
self.b2sn.remove(&body);
}
- #[cfg(feature = "fluids")]
- pub fn set_fluid_color(&mut self, f: FluidHandle, color: Point3<f32>) {
- self.f2color.insert(f, color);
-
- if let Some(n) = self.f2sn.get_mut(&f) {
- n.set_color(color)
- }
- }
-
pub fn set_body_color(&mut self, b: RigidBodyHandle, color: Point3<f32>) {
self.b2color.insert(b, color);
@@ -234,6 +177,10 @@ impl GraphicsManager {
}
}
+ pub fn next_color(&mut self) -> Point3<f32> {
+ Self::gen_color(&mut self.rand)
+ }
+
fn gen_color(rng: &mut Pcg32) -> Point3<f32> {
let mut color: Point3<f32> = rng.gen();
color *= 1.5;
@@ -258,49 +205,6 @@ impl GraphicsManager {
color
}
- #[cfg(feature = "fluids")]
- pub fn add_fluid(
- &mut self,
- window: &mut Window,
- handle: FluidHandle,
- fluid: &Fluid<f32>,
- particle_radius: f32,
- ) {
- let rand = &mut self.rand;
- let color = *self
- .f2color
- .entry(handle)
- .or_insert_with(|| Self::gen_color(rand));
-
- self.add_fluid_with_color(window, handle, fluid, particle_radius, color);
- }
-
- #[cfg(feature = "fluids")]
- pub fn add_boundary(
- &mut self,
- window: &mut Window,
- handle: BoundaryHandle,
- boundary: &Boundary<f32>,
- particle_radius: f32,
- ) {
- let color = self.ground_color;
- let node = FluidNode::new(particle_radius, &boundary.positions, color, window);
- self.boundary2sn.insert(handle, node);
- }
-
- #[cfg(feature = "fluids")]
- pub fn add_fluid_with_color(
- &mut self,
- window: &mut Window,
- handle: FluidHandle,
- fluid: &Fluid<f32>,
- particle_radius: f32,
- color: Point3<f32>,
- ) {
- let node = FluidNode::new(particle_radius, &fluid.positions, color, window);
- self.f2sn.insert(handle, node);
- }
-
pub fn add(
&mut self,
window: &mut Window,
@@ -642,23 +546,6 @@ impl GraphicsManager {
}
*/
- #[cfg(feature = "fluids")]
- pub fn draw_fluids(&mut self, liquid_world: &LiquidWorld<f32>) {
- for (i, fluid) in liquid_world.fluids().iter() {
- if let Some(node) = self.f2sn.get_mut(&i) {
- node.update_with_fluid(fluid, self.fluid_rendering_mode)
- }
- }
-
- if self.render_boundary_particles {
- for (i, boundary) in liquid_world.boundaries().iter() {
- if let Some(node) = self.boundary2sn.get_mut(&i) {
- node.update_with_boundary(boundary)
- }
- }
- }
- }
-
pub fn draw(&mut self, _bodies: &RigidBodySet, colliders: &ColliderSet, window: &mut Window) {
// use kiss3d::camera::Camera;
// println!(
diff --git a/src_testbed/lib.rs b/src_testbed/lib.rs
index e077bb1..21ac06a 100644
--- a/src_testbed/lib.rs
+++ b/src_testbed/lib.rs
@@ -22,7 +22,8 @@ extern crate bitflags;
extern crate log;
pub use crate::engine::GraphicsManager;
-pub use crate::testbed::Testbed;
+pub use crate::plugin::TestbedPlugin;
+pub use crate::testbed::{PhysicsState, Testbed};
#[cfg(all(feature = "dim2", feature = "other-backends"))]
mod box2d_backend;
@@ -32,6 +33,7 @@ mod nphysics_backend;
pub mod objects;
#[cfg(all(feature = "dim3", feature = "other-backends"))]
mod physx_backend;
+mod plugin;
mod testbed;
mod ui;
diff --git a/src_testbed/plugin.rs b/src_testbed/plugin.rs
new file mode 100644
index 0000000..7ad018b
--- /dev/null
+++ b/src_testbed/plugin.rs
@@ -0,0 +1,12 @@
+use crate::testbed::PhysicsState;
+use kiss3d::window::Window;
+use na::Point3;
+
+pub trait TestbedPlugin {
+ fn init_graphics(&mut self, window: &mut Window, gen_color: &mut dyn FnMut() -> Point3<f32>);
+ fn clear_graphics(&mut self, window: &mut Window);
+ fn run_callbacks(&mut self, window: &mut Window, physics: &mut PhysicsState, t: f32);
+ fn step(&mut self, physics: &mut PhysicsState);
+ fn draw(&mut self);
+ fn profiling_string(&self) -> String;
+}
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs
index 66b5953..07b4570 100644
--- a/src_testbed/testbed.rs
+++ b/src_testbed/testbed.rs
@@ -4,8 +4,7 @@ use std::path::Path;
use std::rc::Rc;
use crate::engine::GraphicsManager;
-#[cfg(feature = "fluids")]
-use crate::objects::FluidRenderingMode;
+use crate::plugin::TestbedPlugin;
use crate::ui::TestbedUi;
use crossbeam::channel::Receiver;
use kiss3d::camera::Camera;
@@ -29,8 +28,6 @@ use rapier::geometry::{
};
use rapier::math::Vector;
use rapier::pipeline::{ChannelEventCollector, PhysicsPipeline, QueryPipeline};
-#[cfg(feature = "fluids")]
-use salva::{coupling::ColliderCouplingSet, object::FluidHandle, LiquidWorld};
#[cfg(all(feature = "dim2", feature = "other-backends"))]
use crate::box2d_backend::Box2dWorld;
@@ -185,6 +182,8 @@ pub struct PhysicsState {
pub joints: JointSet,
pub pipeline: PhysicsPipeline,
pub query_pipeline: QueryPipeline,
+ pub integration_parameters: IntegrationParameters,
+ pub gravity: Vector<f32>,
}
impl PhysicsState {
@@ -197,6 +196,8 @@ impl PhysicsState {
joints: JointSet::new(),
pipeline: PhysicsPipeline::new(),
query_pipeline: QueryPipeline::new(),
+ integration_parameters: IntegrationParameters::default(),
+ gravity: Vector::y() * -9.81,
}
}
}
@@ -225,25 +226,14 @@ pub struct TestbedState {
pub timestep_id: usize,
}
-#[cfg(feature = "fluids")]
-struct FluidsState {
- world: LiquidWorld<f32>,
- coupling: ColliderCouplingSet<f32, RigidBodyHandle>,
-}
-
pub struct Testbed {
builders: Vec<(&'static str, fn(&mut Testbed))>,
- #[cfg(feature = "fluids")]
- fluids: Option<FluidsState>,
- gravity: Vector<f32>,
- integration_parameters: IntegrationParameters,
physics: PhysicsState,
graphics: GraphicsManager,
nsteps: usize,
camera_locked: bool, // Used so that the camera can remain the same before and after we change backend or press the restart button.
callbacks: Callbacks,
- #[cfg(feature = "fluids")]
- callbacks_fluids: CallbacksFluids,
+ plugins: Vec<Box<dyn TestbedPlugin>>,
time: f32,
hide_counters: bool,
// persistant_contacts: HashMap<ContactId, bool>,
@@ -264,20 +254,6 @@ pub struct Testbed {
type Callbacks =
Vec<Box<dyn FnMut(&mut Window, &mut PhysicsState, &PhysicsEvents, &mut GraphicsManager, f32)>>;
-#[cfg(feature = "fluids")]
-type CallbacksFluids = Vec<
- Box<
- dyn FnMut(
- &mut Window,
- &mut LiquidWorld<f32>,
- &mut ColliderCouplingSet<f32, RigidBodyHandle>,
- &mut PhysicsState,
- &mut GraphicsManager,
- f32,
- ),
- >,
->;
-
impl Testbed {
pub fn new_empty() -> Testbed {
let graphics = GraphicsManager::new();
@@ -330,8 +306,6 @@ impl Testbed {
thread_pool,
};
- let gravity = Vector::y() * -9.81;
- let integration_parameters = IntegrationParameters::default();
let contact_channel = crossbeam::channel::unbounded();
let proximity_channel = crossbeam::channel::unbounded();
let event_handler = ChannelEventCollector::new(proximity_channel.0, contact_channel.0);
@@ -343,14 +317,9 @@ impl Testbed {
Testbed {
builders: Vec::new(),
- #[cfg(feature = "fluids")]
- fluids: None,
- gravity,
- integration_parameters,
physics,
callbacks: Vec::new(),
- #[cfg(feature = "fluids")]
- callbacks_fluids: Vec::new(),
+ plugins: Vec::new(),
graphics,
nsteps: 1,
camera_locked: false,
@@ -404,6 +373,14 @@ impl Testbed {
self.hide_counters = false;
}
+ pub fn integration_parameters_mut(&mut self) -> &mut IntegrationParameters {
+ &mut self.physics.integration_parameters
+ }
+
+ pub fn physics_state_mut(&mut self) -> &mut PhysicsState {
+ &mut self.physics
+ }
+
pub fn set_world(&mut self, bodies: RigidBodySet, colliders: ColliderSet, joints: JointSet) {
self.set_world_with_gravity(bodies, colliders, joints, Vector::y() * -9.81)
}
@@ -417,7 +394,7 @@ impl Testbed {
) {
println!("Num bodies: {}", bodies.len());
println!("Num joints: {}", joints.len());
- self.gravity = gravity;
+ self.physics.gravity = gravity;
self.physics.bodies = bodies;
self.physics.colliders = colliders;
self.physics.joints = joints;
@@ -451,8 +428,8 @@ impl Testbed {
|| self.state.selected_backend == PHYSX_BACKEND_TWO_FRICTION_DIR
{
self.physx = Some(PhysxWorld::from_rapier(
- self.gravity,
- &self.integration_parameters,
+ self.physics.gravity,
+ &self.physics.integration_parameters,
&self.physics.bodies,
&self.physics.colliders,
&self.physics.joints,
@@ -466,7 +443,7 @@ impl Testbed {
{
if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics = Some(NPhysicsWorld::from_rapier(
- self.gravity,
+ self.physics.gravity,
&self.physics.bodies,
&self.physics.colliders,
&self.physics.joints,
@@ -475,19 +452,6 @@ impl Testbed {
}
}
- #[cfg(feature = "fluids")]
- pub fn set_liquid_world(
- &mut self,
- mut liquid_world: LiquidWorld<f32>,
- coupling: ColliderCouplingSet<f32, RigidBodyHandle>,
- ) {
- liquid_world.counters.enable();
- self.fluids = Some(FluidsState {
- world: liquid_world,
- coupling,
- });
- }
-
pub fn set_builders(&mut self, builders: Vec<(&'static str, fn(&mut Self))>) {
self.state.example_names = builders.iter().map(|e| e.0).collect();
self.builders = builders
@@ -515,25 +479,10 @@ impl Testbed {
self.graphics.set_collider_initial_color(collider, color);
}
- #[cfg(feature = "fluids")]
- pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3<f32>) {
- self.graphics.set_fluid_color(fluid, color);
- }
-
pub fn set_body_wireframe(&mut self, body: RigidBodyHandle, wireframe_enabled: bool) {
self.graphics.set_body_wireframe(body, wireframe_enabled);
}
- #[cfg(feature = "fluids")]
- pub fn set_fluid_rendering_mode(&mut self, mode: FluidRenderingMode) {
- self.graphics.set_fluid_rendering_mode(mode)
- }
-
- #[cfg(feature = "fluids")]
- pub fn enable_boundary_particles_rendering(&mut self, enabled: bool) {
- self.graphics.enable_boundary_particles_rendering(enabled)
- }
-
// pub fn world(&self) -> &Box<WorldOwner> {
// &self.world
// }
@@ -576,13 +525,21 @@ impl Testbed {
fn clear(&mut self, window: &mut Window) {
self.callbacks.clear();
- #[cfg(feature = "fluids")]
- self.callbacks_fluids.clear();
// self.persistant_contacts.clear();
// self.state.grabbed_object = None;
// self.state.grabbed_object_constraint = None;
self.state.can_grab_behind_ground = false;
self.graphics.clear(window);
+
+ for plugin in &mut self.plugins {
+ plugin.clear_graphics(window);
+ }
+
+ self.plugins.clear();
+ }
+
+ pub fn add_plugin(&mut self, plugin: impl TestbedPlugin + 'static) {
+ self.plugins.push(Box::new(plugin));
}
pub fn add_callback<
@@ -594,23 +551,6 @@ impl Testbed {
self.callbacks.push(Box::new(callback));
}
- #[cfg(feature = "fluids")]
- pub fn add_callback_with_fluids<
- F: FnMut(
- &mut Window,
- &mut LiquidWorld<f32>,
- &mut ColliderCouplingSet<f32, RigidBodyHandle>,
- &mut PhysicsState,
- &mut GraphicsManager,
- f32,
- ) + 'static,
- >(
- &mut self,
- callback: F,
- ) {
- self.callbacks_fluids.push(Box::new(callback));
- }
-
pub fn run(mut self) {
let mut args = env::args();
let mut benchmark_mode = false;
@@ -649,11 +589,11 @@ impl Testbed {
&& (backend_id == PHYSX_BACKEND_PATCH_FRICTION
|| backend_id == PHYSX_BACKEND_TWO_FRICTION_DIR)
{
- self.integration_parameters.max_velocity_iterations = 1;
- self.integration_parameters.max_position_iterations = 4;
+ self.physics.integration_parameters.max_velocity_iterations = 1;
+ self.physics.integration_parameters.max_position_iterations = 4;
} else {
- self.integration_parameters.max_velocity_iterations = 4;
- self.integration_parameters.max_position_iterations = 1;
+ self.physics.integration_parameters.max_velocity_iterations = 4;
+ self.physics.integration_parameters.max_position_iterations = 1;
}
// Init world.
(builder.1)(&mut self);
@@ -665,14 +605,12 @@ impl Testbed {
if self.state.selected_backend == RAPIER_BACKEND {
#[cfg(feature = "parallel")]
{
- let gravity = &self.gravity;
- let params = &self.integration_parameters;
let physics = &mut self.physics;
let event_handler = &self.event_handler;
self.state.thread_pool.install(|| {
physics.pipeline.step(
- gravity,
- params,
+ &physics.gravity,
+ &physics.integration_parameters,
&mut physics.broad_phase,
&mut physics.narrow_phase,
&mut physics.bodies,
@@ -685,8 +623,8 @@ impl Testbed {
#[cfg(not(feature = "parallel"))]
self.physics.pipeline.step(
- &self.gravity,
- &self.integration_parameters,
+ &self.physics.gravity,
+ &self.physics.integration_parameters,
&mut self.physics.broad_phase,
&mut self.physics.narrow_phase,
&mut self.physics.bodies,
@@ -700,25 +638,6 @@ impl Testbed {
self.physics
.query_pipeline
.update(&self.physics.bodies, &self.physics.colliders);
-
- #[cfg(feature = "fluids")]
- {
- fluids_time = instant::now();
- if let Some(fluids) = &mut self.fluids {
- let dt = self.world.timestep();
- let gravity = &self.world.gravity;
- fluids.world.step_with_coupling(
- dt,
- gravity,
- &mut fluids.coupling.as_manager_mut(
- &self.physics.colliders,
- &mut self.physics.bodies,
- ),
- );
- }
-
- fluids_time = instant::now() - fluids_time;
- }
}
#[cfg(all(feature = "dim2", feature = "other-backends"))]
@@ -743,7 +662,7 @@ impl Testbed {
// println!("Step");
self.physx.as_mut().unwrap().step(
&mut self.physics.pipeline.counters,
- &self.integration_parameters,
+ &self.physics.integration_parameters,
);
self.physx.as_mut().unwrap().sync(
&mut self.physics.bodies,
@@ -757,7 +676,7 @@ impl Testbed {
if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics.as_mut().unwrap().step(
&mut self.physics.pipeline.counters,
- &self.integration_parameters,
+ &self.physics.integration_parameters,
);
self.nphysics.as_mut().unwrap().sync(
&mut self.physics.bodies,
@@ -1254,8 +1173,14 @@ impl State for Testbed {
}
fn step(&mut self, window: &mut Window) {
+ let prev_example = self.state.selected_example;
+
if let Some(ui) = &mut self.ui {
- ui.update(window, &mut self.integration_parameters, &mut self.state);
+ ui.update(
+ window,
+ &mut self.physics.integration_parameters,
+ &mut self.state,
+ );
}
// Handle UI actions.
@@ -1299,7 +1224,13 @@ impl State for Testbed {
.action_flags
.set(TestbedActionFlags::EXAMPLE_CHANGED, false);
self.clear(window);
+
+ if self.state.selected_example != prev_example {
+ self.physics.integration_parameters = IntegrationParameters::default();
+ }
+
self.builders[self.state.selected_example].1(self);
+
self.camera_locked = false;
}
@@ -1338,6 +1269,11 @@ impl State for Testbed {
if let Ok(w) = snapshot.restore() {
self.clear(window);
self.graphics.clear(window);
+
+ for plugin in &mut self.plugins {
+ plugin.clear_graphics(window);
+ }
+
self.set_world(w.3, w.4, w.5);
self.physics.broad_phase = w.1;
self.physics.narrow_phase = w.2;
@@ -1363,19 +1299,9 @@ impl State for Testbed {
);
}
- #[cfg(feature = "fluids")]
- {
- if let Some(fluids) = &self.fluids {
- let radius = fluids.world.particle_radius();
-
- for (handle, fluid) in fluids.world.fluids().iter() {
- self.graphics.add_fluid(window, handle, fluid, radius);
- }
-
- for (handle, boundary) in fluids.world.boundaries().iter() {
- self.graphics.add_boundary(window, handle, boundary, radius);
- }
- }
+ for plugin in &mut self.plugins {
+ let graphics = &mut self.graphics;
+ plugin.init_graphics(window, &mut || graphics.next_color());
}
}
@@ -1410,7 +1336,7 @@ impl State for Testbed {
.contains(TestbedStateFlags::SUB_STEPPING)
!= self.state.flags.contains(TestbedStateFlags::SUB_STEPPING)
{
- self.integration_parameters.return_after_ccd_substep =
+ self.physics.integration_parameters.return_after_ccd_substep =
self.state.flags.contains(TestbedStateFlags::SUB_STEPPING);
}
@@ -1458,23 +1384,18 @@ impl State for Testbed {
self.handle_special_event(window, event);
}
- #[cfg(feature = "fluids")]
- let mut fluids_time = 0.0;
-
if self.state.running != RunMode::Stop {
for _ in 0..self.nsteps {
self.state.timestep_id += 1;
if self.state.selected_backend == RAPIER_BACKEND {
#[cfg(feature = "parallel")]
{
- let gravity = &self.gravity;
- let params = &self.integration_parameters;
let physics = &mut self.physics;
let event_handler = &self.event_handler;
self.state.thread_pool.install(|| {
physics.pipeline.step(
- gravity,
- params,
+ &physics.gravity,
+ &physics.integration_parameters,
&mut physics.broad_phase,
&mut physics.narrow_phase,
&mut physics.bodies,
@@ -1489,8 +1410,8 @@ impl State for Testbed {
#[cfg(not(feature = "parallel"))]
self.physics.pipeline.step(
- &self.gravity,
- &self.integration_parameters,
+ &self.physics.gravity,
+ &self.physics.integration_parameters,
&mut self.physics.broad_phase,
&mut self.physics.narrow_phase,
&mut self.physics.bodies,
@@ -1505,23 +1426,8 @@ impl State for Testbed {
.query_pipeline
.update(&self.physics.bodies, &self.physics.colliders);
- #[cfg(feature = "fluids")]
- {
- fluids_time = instant::now();
- if let Some(fluids) = &mut self.fluids {
- let dt = self.world.timestep();
- let gravity = &self.world.gravity;
- fluids.world.step_with_coupling(
- dt,
- gravity,
- &mut fluids.coupling.as_manager_mut(
- &self.physics.colliders,
- &mut self.physics.bodies,
- ),
- );
- }
-
- fluids_time = instant::now() - fluids_time;
+ for plugin in &mut self.plugins {
+ plugin.step(&mut self.physics)
}
}
@@ -1530,7 +1436,7 @@ impl State for Testbed {
if self.state.selected_backend == BOX2D_BACKEND {
self.box2d.as_mut().unwrap().step(
&mut self.physics.pipeline.counters,
- &self.integration_parameters,
+ &self.physics.integration_parameters,
);
self.box2d
.as_mut()
@@ -1547,7 +1453,7 @@ impl State for Testbed {
// println!("Step");
self.physx.as_mut().unwrap().step(
&mut self.physics.pipeline.counters,
- &self.integration_parameters,
+ &self.physics.integration_parameters,
);
self.physx
.as_mut()
@@ -1561,7 +1467,7 @@ impl State for Testbed {
if self.state.selected_backend == NPHYSICS_BACKEND {
self.nphysics.as_mut().unwrap().step(
&mut self.physics.pipeline.counters,
- &self.integration_parameters,
+ &self.physics.integration_parameters,
);
self.nphysics
.as_mut()
@@ -1580,20 +1486,8 @@ impl State for Testbed {
)
}
- #[cfg(feature = "fluids")]
- {
- if let Some(fluid_state) = &mut self.fluids {
- for f in &mut self.callbacks_fluids {
- f(
- window,
- &mut fluid_state.world,
- &mut fluid_state.coupling,
- &mut self.physics,
- &mut self.graphics,
- self.time,
- )
- }
- }
+ for plugin in &mut self.plugins {
+ plugin.run_callbacks(window, &mut self.physics, self.time)
}
self.events.poll_all();
@@ -1605,7 +1499,7 @@ impl State for Testbed {
// #[cfg(feature = "log")]
// debug!("{}", self.world.counters);
// }
- self.time += self.integration_parameters.dt();
+ self.time += self.physics.integration_parameters.dt();
}
}
@@ -1613,11 +1507,8 @@ impl State for Testbed {
self.graphics
.draw(&self.physics.bodies, &self.physics.colliders, window);
- #[cfg(feature = "fluids")]
- {
- if let Some(fluids) = &self.fluids {
- self.graphics.draw_fluids(&fluids.world)
- }
+ for plugin in &mut self.plugins {
+ plugin.draw();
}
if self.state.flags.contains(TestbedStateFlags::CONTACT_POINTS) {
@@ -1676,14 +1567,9 @@ CCD: {:.2}ms
counters.ccd.solver_time.time(),
);
- #[cfg(feature = "fluids")]
- {
- profile = format!(
- r#"{}
-Fluids: {:.2}ms
- "#,
- profile, fluids_time,
- )
+ for plugin in &self.plugins {
+ let plugin_profile = plugin.profiling_string();
+ profile = format!("{}\n{}", profile, plugin_profile,)
}
}