diff options
| author | rezural <rezural@protonmail.com> | 2021-07-06 07:38:50 +1000 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2021-07-08 10:07:42 +0200 |
| commit | 53700db8603ee9ab7c2cb89d6d186ba47f7ae203 (patch) | |
| tree | 16459338c3af3fa3a76923c28117338633b7bf24 /src_testbed/objects/node.rs | |
| parent | 9f8d9769f83c2b77d4bff6641117155c99ffd0d4 (diff) | |
| download | rapier-53700db8603ee9ab7c2cb89d6d186ba47f7ae203.tar.gz rapier-53700db8603ee9ab7c2cb89d6d186ba47f7ae203.tar.bz2 rapier-53700db8603ee9ab7c2cb89d6d186ba47f7ae203.zip | |
add opacity to EntityWithGraphics
Diffstat (limited to 'src_testbed/objects/node.rs')
| -rw-r--r-- | src_testbed/objects/node.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs index 21dcc79..47c9b41 100644 --- a/src_testbed/objects/node.rs +++ b/src_testbed/objects/node.rs @@ -11,6 +11,7 @@ use rapier::geometry::{ColliderHandle, ColliderSet, Shape, ShapeType}; #[cfg(feature = "dim3")] use rapier::geometry::{Cone, Cylinder}; use rapier::math::Isometry; + #[cfg(feature = "dim2")] use { na::{Point2, Vector2}, @@ -24,6 +25,7 @@ pub struct EntityWithGraphics { pub base_color: Point3<f32>, pub collider: ColliderHandle, pub delta: Isometry<f32>, + pub opacity: f32, material: Handle<StandardMaterial>, } @@ -49,7 +51,8 @@ impl EntityWithGraphics { .or_else(|| generate_collider_mesh(shape).map(|m| meshes.add(m))) .expect("Could not build the collider's render mesh"); - let bevy_color = Color::rgb(color.x, color.y, color.z); + let opacity = 1.0; + let bevy_color = Color::rgba(color.x, color.y, color.z, opacity); let shape_pos = collider_pos * delta; let mut transform = Transform::from_scale(scale); transform.translation.x = shape_pos.translation.vector.x; @@ -101,6 +104,7 @@ impl EntityWithGraphics { collider, delta, material: material_weak_handle, + opacity, } } @@ -108,12 +112,14 @@ impl EntityWithGraphics { //FIXME: Should this be despawn_recursive? commands.entity(self.entity).despawn(); } + pub fn select(&mut self, materials: &mut Assets<StandardMaterial>) { // NOTE: we don't just call `self.set_color` because that would // overwrite self.base_color too. self.color = point![1.0, 0.0, 0.0]; if let Some(material) = materials.get_mut(&self.material) { - material.base_color = Color::rgb(self.color.x, self.color.y, self.color.z); + material.base_color = + Color::rgba(self.color.x, self.color.y, self.color.z, self.opacity); } } @@ -123,7 +129,7 @@ impl EntityWithGraphics { pub fn set_color(&mut self, materials: &mut Assets<StandardMaterial>, color: Point3<f32>) { if let Some(material) = materials.get_mut(&self.material) { - material.base_color = Color::rgb(color.x, color.y, color.z); + material.base_color = Color::rgba(color.x, color.y, color.z, self.opacity); } self.color = color; self.base_color = color; |
