aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src_testbed/graphics.rs18
-rw-r--r--src_testbed/testbed.rs40
2 files changed, 40 insertions, 18 deletions
diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs
index 00d49f3..197e77f 100644
--- a/src_testbed/graphics.rs
+++ b/src_testbed/graphics.rs
@@ -179,7 +179,7 @@ impl GraphicsManager {
color
}
- pub fn add(
+ pub fn add_body_colliders(
&mut self,
commands: &mut Commands,
meshes: &mut Assets<Mesh>,
@@ -197,12 +197,12 @@ impl GraphicsManager {
.cloned()
.unwrap_or_else(|| self.alloc_color(materials, handle, !body.is_dynamic()));
- let _ = self.add_with_color(
+ let _ = self.add_body_colliders_with_color(
commands, meshes, materials, components, handle, bodies, colliders, color,
);
}
- pub fn add_with_color(
+ pub fn add_body_colliders_with_color(
&mut self,
commands: &mut Commands,
meshes: &mut Assets<Mesh>,
@@ -263,9 +263,16 @@ impl GraphicsManager {
) {
let collider = &colliders[handle];
let collider_parent = collider.parent().unwrap_or(RigidBodyHandle::invalid());
- let color = *self.b2color.get(&collider_parent).unwrap();
+ let color = self
+ .b2color
+ .get(&collider_parent)
+ .copied()
+ .unwrap_or(self.ground_color);
let color = self.c2color.get(&handle).copied().unwrap_or(color);
- let mut nodes = std::mem::replace(self.b2sn.get_mut(&collider_parent).unwrap(), Vec::new());
+ let mut nodes = std::mem::replace(
+ self.b2sn.entry(collider_parent).or_insert(vec![]),
+ Vec::new(),
+ );
self.add_shape(
commands,
meshes,
@@ -294,6 +301,7 @@ impl GraphicsManager {
color: Point3<f32>,
out: &mut Vec<EntityWithGraphics>,
) {
+ println!("Shape type: {:?}", shape.shape_type());
if let Some(compound) = shape.as_compound() {
for (shape_pos, shape) in compound.shapes() {
self.add_shape(
diff --git a/src_testbed/testbed.rs b/src_testbed/testbed.rs
index e26125b..706a40a 100644
--- a/src_testbed/testbed.rs
+++ b/src_testbed/testbed.rs
@@ -133,7 +133,7 @@ struct OtherBackends {
struct Plugins(Vec<Box<dyn TestbedPlugin>>);
pub struct TestbedGraphics<'a, 'b, 'c, 'd> {
- manager: &'a mut GraphicsManager,
+ graphics: &'a mut GraphicsManager,
commands: &'a mut Commands<'d>,
meshes: &'a mut Assets<Mesh>,
materials: &'a mut Assets<StandardMaterial>,
@@ -434,7 +434,7 @@ impl TestbedApp {
impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
- self.manager
+ self.graphics
.set_body_color(&mut self.materials, body, color);
}
@@ -444,7 +444,7 @@ impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
bodies: &RigidBodySet,
colliders: &ColliderSet,
) {
- self.manager.add(
+ self.graphics.add_body_colliders(
&mut *self.commands,
&mut *self.meshes,
&mut *self.materials,
@@ -457,17 +457,17 @@ impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
pub fn remove_collider(&mut self, handle: ColliderHandle, colliders: &ColliderSet) {
if let Some(parent_handle) = colliders.get(handle).map(|c| c.parent()) {
- self.manager
+ self.graphics
.remove_collider_nodes(&mut *self.commands, parent_handle, handle)
}
}
pub fn remove_body(&mut self, handle: RigidBodyHandle) {
- self.manager.remove_body_nodes(&mut *self.commands, handle)
+ self.graphics.remove_body_nodes(&mut *self.commands, handle)
}
pub fn add_collider(&mut self, handle: ColliderHandle, colliders: &ColliderSet) {
- self.manager.add_collider(
+ self.graphics.add_collider(
&mut *self.commands,
&mut *self.meshes,
&mut *self.materials,
@@ -594,19 +594,23 @@ impl<'a, 'b, 'c, 'd> Testbed<'a, 'b, 'c, 'd> {
pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
if let Some(graphics) = &mut self.graphics {
- graphics.manager.set_initial_body_color(body, color);
+ graphics.graphics.set_initial_body_color(body, color);
}
}
pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: [f32; 3]) {
if let Some(graphics) = &mut self.graphics {
- graphics.manager.set_initial_collider_color(collider, color);
+ graphics
+ .graphics
+ .set_initial_collider_color(collider, color);
}
}
pub fn set_body_wireframe(&mut self, body: RigidBodyHandle, wireframe_enabled: bool) {
if let Some(graphics) = &mut self.graphics {
- graphics.manager.set_body_wireframe(body, wireframe_enabled);
+ graphics
+ .graphics
+ .set_body_wireframe(body, wireframe_enabled);
}
}
@@ -964,13 +968,13 @@ fn update_testbed(
}
let selected_example = state.selected_example;
- let manager = &mut *graphics;
+ let graphics = &mut *graphics;
let meshes = &mut *meshes;
let graphics_context = TestbedGraphics {
pipelines: &mut *pipelines,
shaders: &mut *shaders,
- manager: &mut *manager,
+ graphics: &mut *graphics,
commands: &mut commands,
meshes: &mut *meshes,
materials: &mut *materials,
@@ -1045,7 +1049,7 @@ fn update_testbed(
.action_flags
.set(TestbedActionFlags::RESET_WORLD_GRAPHICS, false);
for (handle, _) in harness.physics.bodies.iter() {
- graphics.add(
+ graphics.add_body_colliders(
&mut commands,
meshes,
materials,
@@ -1056,6 +1060,16 @@ fn update_testbed(
);
}
+ for (handle, _) in harness.physics.colliders.iter() {
+ graphics.add_collider(
+ &mut commands,
+ meshes,
+ materials,
+ handle,
+ &harness.physics.colliders,
+ );
+ }
+
for plugin in &mut plugins.0 {
plugin.init_graphics(
&mut graphics,
@@ -1109,7 +1123,7 @@ fn update_testbed(
let mut testbed_graphics = TestbedGraphics {
pipelines: &mut *pipelines,
shaders: &mut *shaders,
- manager: &mut *graphics,
+ graphics: &mut *graphics,
commands: &mut commands,
meshes: &mut *meshes,
materials: &mut *materials,