enable clear_graphics and run_callbacks agin
update plugin signature to recieve bevy structs, add Arc<Mutex<>> around gfx_components, we we can get shared mutable access add prefab_meshes() access function Remove Arc<Mutex<>>
This commit is contained in:
committed by
Sébastien Crozet
parent
62d6b0651b
commit
7c249c873d
@@ -195,9 +195,9 @@ 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()));
|
||||||
|
|
||||||
self.add_with_color(
|
let _ = self.add_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_with_color(
|
||||||
@@ -210,8 +210,7 @@ impl GraphicsManager {
|
|||||||
bodies: &RigidBodySet,
|
bodies: &RigidBodySet,
|
||||||
colliders: &ColliderSet,
|
colliders: &ColliderSet,
|
||||||
color: Point3<f32>,
|
color: Point3<f32>,
|
||||||
) {
|
) -> Vec<EntityWithGraphics> {
|
||||||
// let body = bodies.get(handle).unwrap();
|
|
||||||
let mut new_nodes = Vec::new();
|
let mut new_nodes = Vec::new();
|
||||||
|
|
||||||
for collider_handle in bodies[handle].colliders() {
|
for collider_handle in bodies[handle].colliders() {
|
||||||
@@ -246,7 +245,10 @@ impl GraphicsManager {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
let nodes = self.b2sn.entry(handle).or_insert_with(Vec::new);
|
let nodes = self.b2sn.entry(handle).or_insert_with(Vec::new);
|
||||||
nodes.append(&mut new_nodes);
|
|
||||||
|
nodes.append(&mut new_nodes.clone());
|
||||||
|
|
||||||
|
new_nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_collider(
|
pub fn add_collider(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use {
|
|||||||
rapier::geometry::{Ball, Cuboid},
|
rapier::geometry::{Ball, Cuboid},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub struct EntityWithGraphics {
|
pub struct EntityWithGraphics {
|
||||||
pub entity: Entity,
|
pub entity: Entity,
|
||||||
pub color: Point3<f32>,
|
pub color: Point3<f32>,
|
||||||
|
|||||||
@@ -1,12 +1,32 @@
|
|||||||
use crate::harness::RunState;
|
use crate::harness::Harness;
|
||||||
use crate::physics::PhysicsState;
|
use crate::physics::PhysicsState;
|
||||||
|
use crate::GraphicsManager;
|
||||||
|
use bevy::prelude::{Assets, Commands, Mesh, Query, StandardMaterial, Transform};
|
||||||
use na::Point3;
|
use na::Point3;
|
||||||
|
|
||||||
pub trait TestbedPlugin {
|
pub trait TestbedPlugin {
|
||||||
fn init_graphics(&mut self, gen_color: &mut dyn FnMut() -> Point3<f32>);
|
fn init_graphics(
|
||||||
fn clear_graphics(&mut self);
|
&mut self,
|
||||||
fn run_callbacks(&mut self, physics: &mut PhysicsState, run_state: &RunState);
|
graphics: &mut GraphicsManager,
|
||||||
|
commands: &mut Commands,
|
||||||
|
meshes: &mut Assets<Mesh>,
|
||||||
|
materials: &mut Assets<StandardMaterial>,
|
||||||
|
components: &mut Query<(&mut Transform,)>,
|
||||||
|
harness: &mut Harness,
|
||||||
|
|
||||||
|
gen_color: &mut dyn FnMut() -> Point3<f32>,
|
||||||
|
);
|
||||||
|
fn clear_graphics(&mut self, graphics: &mut GraphicsManager, commands: &mut Commands);
|
||||||
|
fn run_callbacks(&mut self, harness: &mut Harness);
|
||||||
fn step(&mut self, physics: &mut PhysicsState);
|
fn step(&mut self, physics: &mut PhysicsState);
|
||||||
fn draw(&mut self);
|
fn draw(
|
||||||
|
&mut self,
|
||||||
|
graphics: &mut GraphicsManager,
|
||||||
|
commands: &mut Commands,
|
||||||
|
meshes: &mut Assets<Mesh>,
|
||||||
|
materials: &mut Assets<StandardMaterial>,
|
||||||
|
components: &mut Query<(&mut Transform,)>,
|
||||||
|
harness: &mut Harness,
|
||||||
|
);
|
||||||
fn profiling_string(&self) -> String;
|
fn profiling_string(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -942,6 +942,7 @@ fn update_testbed(
|
|||||||
let selected_example = state.selected_example;
|
let selected_example = state.selected_example;
|
||||||
let manager = &mut *graphics;
|
let manager = &mut *graphics;
|
||||||
let meshes = &mut *meshes;
|
let meshes = &mut *meshes;
|
||||||
|
|
||||||
let graphics_context = TestbedGraphics {
|
let graphics_context = TestbedGraphics {
|
||||||
manager: &mut *manager,
|
manager: &mut *manager,
|
||||||
commands: &mut commands,
|
commands: &mut commands,
|
||||||
@@ -950,6 +951,7 @@ fn update_testbed(
|
|||||||
components: &mut gfx_components,
|
components: &mut gfx_components,
|
||||||
camera: &mut cameras.iter_mut().next().unwrap().2,
|
camera: &mut cameras.iter_mut().next().unwrap().2,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut testbed = Testbed {
|
let mut testbed = Testbed {
|
||||||
graphics: Some(graphics_context),
|
graphics: Some(graphics_context),
|
||||||
state: &mut *state,
|
state: &mut *state,
|
||||||
@@ -997,9 +999,9 @@ fn update_testbed(
|
|||||||
if let Ok(w) = snapshot.restore() {
|
if let Ok(w) = snapshot.restore() {
|
||||||
clear(&mut commands, &mut state, &mut graphics, &mut plugins);
|
clear(&mut commands, &mut state, &mut graphics, &mut plugins);
|
||||||
|
|
||||||
// for plugin in &mut plugins {
|
for plugin in &mut plugins.0 {
|
||||||
// plugin.clear_graphics(window);
|
plugin.clear_graphics(&mut graphics, &mut commands);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// set_world(w.3, w.4, w.5);
|
// set_world(w.3, w.4, w.5);
|
||||||
harness.physics.broad_phase = w.1;
|
harness.physics.broad_phase = w.1;
|
||||||
@@ -1028,10 +1030,18 @@ fn update_testbed(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for plugin in &mut plugins {
|
for plugin in &mut plugins.0 {
|
||||||
// let graphics = &mut graphics;
|
let next_color = graphics.next_color();
|
||||||
// plugin.init_graphics(window, &mut || graphics.next_color());
|
plugin.init_graphics(
|
||||||
// }
|
&mut graphics,
|
||||||
|
&mut commands,
|
||||||
|
meshes,
|
||||||
|
materials,
|
||||||
|
&mut gfx_components,
|
||||||
|
&mut harness,
|
||||||
|
&mut || next_color,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if example_changed
|
if example_changed
|
||||||
@@ -1071,6 +1081,7 @@ fn update_testbed(
|
|||||||
for _ in 0..state.nsteps {
|
for _ in 0..state.nsteps {
|
||||||
if state.selected_backend == RAPIER_BACKEND {
|
if state.selected_backend == RAPIER_BACKEND {
|
||||||
let graphics = &mut graphics;
|
let graphics = &mut graphics;
|
||||||
|
|
||||||
let mut testbed_graphics = TestbedGraphics {
|
let mut testbed_graphics = TestbedGraphics {
|
||||||
manager: &mut *graphics,
|
manager: &mut *graphics,
|
||||||
commands: &mut commands,
|
commands: &mut commands,
|
||||||
@@ -1137,9 +1148,9 @@ fn update_testbed(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for plugin in &mut plugins.0 {
|
for plugin in &mut plugins.0 {
|
||||||
// plugin.run_callbacks(window, &mut harness.physics, &harness.state);
|
plugin.run_callbacks(&mut harness);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1157,15 +1168,25 @@ fn update_testbed(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let physics = &harness.physics;
|
graphics.draw(
|
||||||
graphics.draw(&physics.bodies, &physics.colliders, &mut gfx_components);
|
&harness.physics.bodies,
|
||||||
|
&harness.physics.colliders,
|
||||||
|
&mut gfx_components,
|
||||||
|
);
|
||||||
|
|
||||||
for plugin in &mut plugins.0 {
|
for plugin in &mut plugins.0 {
|
||||||
plugin.draw();
|
plugin.draw(
|
||||||
|
&mut graphics,
|
||||||
|
&mut commands,
|
||||||
|
meshes,
|
||||||
|
materials,
|
||||||
|
&mut gfx_components,
|
||||||
|
&mut harness,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.flags.contains(TestbedStateFlags::CONTACT_POINTS) {
|
if state.flags.contains(TestbedStateFlags::CONTACT_POINTS) {
|
||||||
draw_contacts(&physics.narrow_phase, &physics.colliders);
|
draw_contacts(&harness.physics.narrow_phase, &harness.physics.colliders);
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.running == RunMode::Step {
|
if state.running == RunMode::Step {
|
||||||
@@ -1177,14 +1198,14 @@ fn clear(
|
|||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
state: &mut TestbedState,
|
state: &mut TestbedState,
|
||||||
graphics: &mut GraphicsManager,
|
graphics: &mut GraphicsManager,
|
||||||
_plugins: &mut Plugins,
|
plugins: &mut Plugins,
|
||||||
) {
|
) {
|
||||||
state.can_grab_behind_ground = false;
|
state.can_grab_behind_ground = false;
|
||||||
graphics.clear(commands);
|
graphics.clear(commands);
|
||||||
|
|
||||||
// for plugin in plugins.0.drain(..) {
|
for mut plugin in plugins.0.drain(..) {
|
||||||
// plugin.clear_graphics();
|
plugin.clear_graphics(graphics, commands);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "dim2")]
|
#[cfg(feature = "dim2")]
|
||||||
|
|||||||
Reference in New Issue
Block a user