From 154bc70037d42ef15d9a6c3288b8006027c2cb94 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Sat, 31 Oct 2020 14:42:14 +0100 Subject: Remove the Salva integration code from rapier + add a plugin system to the testbed. --- src_testbed/engine.rs | 121 ++------------------------------------------------ 1 file changed, 4 insertions(+), 117 deletions(-) (limited to 'src_testbed/engine.rs') 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>, - #[cfg(feature = "fluids")] - f2sn: HashMap, - #[cfg(feature = "fluids")] - boundary2sn: HashMap, b2color: HashMap>, c2color: HashMap>, b2wireframe: HashMap, - #[cfg(feature = "fluids")] - f2color: HashMap>, ground_color: Point3, camera: Camera, ground_handle: Option, - #[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) { - 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) { self.b2color.insert(b, color); @@ -234,6 +177,10 @@ impl GraphicsManager { } } + pub fn next_color(&mut self) -> Point3 { + Self::gen_color(&mut self.rand) + } + fn gen_color(rng: &mut Pcg32) -> Point3 { let mut color: Point3 = 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, - 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, - 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, - particle_radius: f32, - color: Point3, - ) { - 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) { - 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!( -- cgit