Fix testbed rendering of colliders without parent
This commit is contained in:
committed by
Sébastien Crozet
parent
7aa94e994f
commit
fe87e2d586
@@ -179,7 +179,7 @@ impl GraphicsManager {
|
|||||||
color
|
color
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(
|
pub fn add_body_colliders(
|
||||||
&mut self,
|
&mut self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
meshes: &mut Assets<Mesh>,
|
meshes: &mut Assets<Mesh>,
|
||||||
@@ -197,12 +197,12 @@ impl GraphicsManager {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| self.alloc_color(materials, handle, !body.is_dynamic()));
|
.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,
|
commands, meshes, materials, components, handle, bodies, colliders, color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_with_color(
|
pub fn add_body_colliders_with_color(
|
||||||
&mut self,
|
&mut self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
meshes: &mut Assets<Mesh>,
|
meshes: &mut Assets<Mesh>,
|
||||||
@@ -263,9 +263,16 @@ impl GraphicsManager {
|
|||||||
) {
|
) {
|
||||||
let collider = &colliders[handle];
|
let collider = &colliders[handle];
|
||||||
let collider_parent = collider.parent().unwrap_or(RigidBodyHandle::invalid());
|
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 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(
|
self.add_shape(
|
||||||
commands,
|
commands,
|
||||||
meshes,
|
meshes,
|
||||||
@@ -294,6 +301,7 @@ impl GraphicsManager {
|
|||||||
color: Point3<f32>,
|
color: Point3<f32>,
|
||||||
out: &mut Vec<EntityWithGraphics>,
|
out: &mut Vec<EntityWithGraphics>,
|
||||||
) {
|
) {
|
||||||
|
println!("Shape type: {:?}", shape.shape_type());
|
||||||
if let Some(compound) = shape.as_compound() {
|
if let Some(compound) = shape.as_compound() {
|
||||||
for (shape_pos, shape) in compound.shapes() {
|
for (shape_pos, shape) in compound.shapes() {
|
||||||
self.add_shape(
|
self.add_shape(
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ struct OtherBackends {
|
|||||||
struct Plugins(Vec<Box<dyn TestbedPlugin>>);
|
struct Plugins(Vec<Box<dyn TestbedPlugin>>);
|
||||||
|
|
||||||
pub struct TestbedGraphics<'a, 'b, 'c, 'd> {
|
pub struct TestbedGraphics<'a, 'b, 'c, 'd> {
|
||||||
manager: &'a mut GraphicsManager,
|
graphics: &'a mut GraphicsManager,
|
||||||
commands: &'a mut Commands<'d>,
|
commands: &'a mut Commands<'d>,
|
||||||
meshes: &'a mut Assets<Mesh>,
|
meshes: &'a mut Assets<Mesh>,
|
||||||
materials: &'a mut Assets<StandardMaterial>,
|
materials: &'a mut Assets<StandardMaterial>,
|
||||||
@@ -434,7 +434,7 @@ impl TestbedApp {
|
|||||||
|
|
||||||
impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
|
impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
|
||||||
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
||||||
self.manager
|
self.graphics
|
||||||
.set_body_color(&mut self.materials, body, color);
|
.set_body_color(&mut self.materials, body, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +444,7 @@ impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
|
|||||||
bodies: &RigidBodySet,
|
bodies: &RigidBodySet,
|
||||||
colliders: &ColliderSet,
|
colliders: &ColliderSet,
|
||||||
) {
|
) {
|
||||||
self.manager.add(
|
self.graphics.add_body_colliders(
|
||||||
&mut *self.commands,
|
&mut *self.commands,
|
||||||
&mut *self.meshes,
|
&mut *self.meshes,
|
||||||
&mut *self.materials,
|
&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) {
|
pub fn remove_collider(&mut self, handle: ColliderHandle, colliders: &ColliderSet) {
|
||||||
if let Some(parent_handle) = colliders.get(handle).map(|c| c.parent()) {
|
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)
|
.remove_collider_nodes(&mut *self.commands, parent_handle, handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_body(&mut self, handle: RigidBodyHandle) {
|
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) {
|
pub fn add_collider(&mut self, handle: ColliderHandle, colliders: &ColliderSet) {
|
||||||
self.manager.add_collider(
|
self.graphics.add_collider(
|
||||||
&mut *self.commands,
|
&mut *self.commands,
|
||||||
&mut *self.meshes,
|
&mut *self.meshes,
|
||||||
&mut *self.materials,
|
&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]) {
|
pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
||||||
if let Some(graphics) = &mut self.graphics {
|
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]) {
|
pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: [f32; 3]) {
|
||||||
if let Some(graphics) = &mut self.graphics {
|
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) {
|
pub fn set_body_wireframe(&mut self, body: RigidBodyHandle, wireframe_enabled: bool) {
|
||||||
if let Some(graphics) = &mut self.graphics {
|
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 selected_example = state.selected_example;
|
||||||
let manager = &mut *graphics;
|
let graphics = &mut *graphics;
|
||||||
let meshes = &mut *meshes;
|
let meshes = &mut *meshes;
|
||||||
|
|
||||||
let graphics_context = TestbedGraphics {
|
let graphics_context = TestbedGraphics {
|
||||||
pipelines: &mut *pipelines,
|
pipelines: &mut *pipelines,
|
||||||
shaders: &mut *shaders,
|
shaders: &mut *shaders,
|
||||||
manager: &mut *manager,
|
graphics: &mut *graphics,
|
||||||
commands: &mut commands,
|
commands: &mut commands,
|
||||||
meshes: &mut *meshes,
|
meshes: &mut *meshes,
|
||||||
materials: &mut *materials,
|
materials: &mut *materials,
|
||||||
@@ -1045,7 +1049,7 @@ fn update_testbed(
|
|||||||
.action_flags
|
.action_flags
|
||||||
.set(TestbedActionFlags::RESET_WORLD_GRAPHICS, false);
|
.set(TestbedActionFlags::RESET_WORLD_GRAPHICS, false);
|
||||||
for (handle, _) in harness.physics.bodies.iter() {
|
for (handle, _) in harness.physics.bodies.iter() {
|
||||||
graphics.add(
|
graphics.add_body_colliders(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
meshes,
|
meshes,
|
||||||
materials,
|
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 {
|
for plugin in &mut plugins.0 {
|
||||||
plugin.init_graphics(
|
plugin.init_graphics(
|
||||||
&mut graphics,
|
&mut graphics,
|
||||||
@@ -1109,7 +1123,7 @@ fn update_testbed(
|
|||||||
let mut testbed_graphics = TestbedGraphics {
|
let mut testbed_graphics = TestbedGraphics {
|
||||||
pipelines: &mut *pipelines,
|
pipelines: &mut *pipelines,
|
||||||
shaders: &mut *shaders,
|
shaders: &mut *shaders,
|
||||||
manager: &mut *graphics,
|
graphics: &mut *graphics,
|
||||||
commands: &mut commands,
|
commands: &mut commands,
|
||||||
meshes: &mut *meshes,
|
meshes: &mut *meshes,
|
||||||
materials: &mut *materials,
|
materials: &mut *materials,
|
||||||
|
|||||||
Reference in New Issue
Block a user