aboutsummaryrefslogtreecommitdiff
path: root/src_testbed
diff options
context:
space:
mode:
authorrezural <rezural@protonmail.com>2021-07-08 11:04:06 +1000
committerSébastien Crozet <sebastien@crozet.re>2021-07-08 10:07:42 +0200
commit3b0d25646407e9b1d7e39dee1005d9a24e09ab66 (patch)
treec7f0fe2766bdada8db7e11e9d52b547f16f90ecc /src_testbed
parent53700db8603ee9ab7c2cb89d6d186ba47f7ae203 (diff)
downloadrapier-3b0d25646407e9b1d7e39dee1005d9a24e09ab66.tar.gz
rapier-3b0d25646407e9b1d7e39dee1005d9a24e09ab66.tar.bz2
rapier-3b0d25646407e9b1d7e39dee1005d9a24e09ab66.zip
make collider Option<> on EntityWithGraphics
Diffstat (limited to 'src_testbed')
-rw-r--r--src_testbed/graphics.rs28
-rw-r--r--src_testbed/objects/node.rs8
2 files changed, 23 insertions, 13 deletions
diff --git a/src_testbed/graphics.rs b/src_testbed/graphics.rs
index 0682f63..00d49f3 100644
--- a/src_testbed/graphics.rs
+++ b/src_testbed/graphics.rs
@@ -63,8 +63,10 @@ impl GraphicsManager {
let body = body.unwrap_or(RigidBodyHandle::invalid());
if let Some(sns) = self.b2sn.get_mut(&body) {
for sn in sns.iter_mut() {
- if sn.collider == collider {
- commands.entity(sn.entity).despawn();
+ if let Some(sn_c) = sn.collider {
+ if sn_c == collider {
+ commands.entity(sn.entity).despawn();
+ }
}
}
}
@@ -216,11 +218,11 @@ impl GraphicsManager {
for collider_handle in bodies[handle].colliders() {
let color = self.c2color.get(collider_handle).copied().unwrap_or(color);
let collider = &colliders[*collider_handle];
- self.do_add_shape(
+ self.add_shape(
commands,
meshes,
materials,
- *collider_handle,
+ Some(*collider_handle),
collider.shape(),
collider.is_sensor(),
collider.position(),
@@ -264,11 +266,11 @@ impl GraphicsManager {
let color = *self.b2color.get(&collider_parent).unwrap();
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());
- self.do_add_shape(
+ self.add_shape(
commands,
meshes,
materials,
- handle,
+ Some(handle),
collider.shape(),
collider.is_sensor(),
collider.position(),
@@ -279,12 +281,12 @@ impl GraphicsManager {
self.b2sn.insert(collider_parent, nodes);
}
- fn do_add_shape(
+ pub fn add_shape(
&mut self,
commands: &mut Commands,
meshes: &mut Assets<Mesh>,
materials: &mut Assets<StandardMaterial>,
- handle: ColliderHandle,
+ handle: Option<ColliderHandle>,
shape: &dyn Shape,
sensor: bool,
pos: &Isometry<f32>,
@@ -294,7 +296,7 @@ impl GraphicsManager {
) {
if let Some(compound) = shape.as_compound() {
for (shape_pos, shape) in compound.shapes() {
- self.do_add_shape(
+ self.add_shape(
commands,
meshes,
materials,
@@ -394,6 +396,14 @@ impl GraphicsManager {
pub fn nodes_mut(&mut self) -> impl Iterator<Item = &mut EntityWithGraphics> {
self.b2sn.values_mut().flat_map(|val| val.iter_mut())
}
+
+ pub fn prefab_meshes(&self) -> &HashMap<ShapeType, Handle<Mesh>> {
+ &self.prefab_meshes
+ }
+
+ pub fn prefab_meshes_mut(&mut self) -> &mut HashMap<ShapeType, Handle<Mesh>> {
+ &mut self.prefab_meshes
+ }
}
impl Default for GraphicsManager {
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs
index 47c9b41..9bbece2 100644
--- a/src_testbed/objects/node.rs
+++ b/src_testbed/objects/node.rs
@@ -23,7 +23,7 @@ pub struct EntityWithGraphics {
pub entity: Entity,
pub color: Point3<f32>,
pub base_color: Point3<f32>,
- pub collider: ColliderHandle,
+ pub collider: Option<ColliderHandle>,
pub delta: Isometry<f32>,
pub opacity: f32,
material: Handle<StandardMaterial>,
@@ -36,7 +36,7 @@ impl EntityWithGraphics {
materials: &mut Assets<StandardMaterial>,
prefab_meshs: &HashMap<ShapeType, Handle<Mesh>>,
shape: &dyn Shape,
- collider: ColliderHandle,
+ collider: Option<ColliderHandle>,
collider_pos: Isometry<f32>,
delta: Isometry<f32>,
color: Point3<f32>,
@@ -136,7 +136,7 @@ impl EntityWithGraphics {
}
pub fn update(&mut self, colliders: &ColliderSet, components: &mut Query<(&mut Transform,)>) {
- if let Some(co) = colliders.get(self.collider) {
+ if let Some(Some(co)) = self.collider.map(|c| colliders.get(c)) {
if let Ok(mut pos) = components.get_component_mut::<Transform>(self.entity) {
let co_pos = co.position() * self.delta;
pos.translation.x = co_pos.translation.vector.x;
@@ -159,7 +159,7 @@ impl EntityWithGraphics {
}
}
- pub fn object(&self) -> ColliderHandle {
+ pub fn object(&self) -> Option<ColliderHandle> {
self.collider
}