aboutsummaryrefslogtreecommitdiff
path: root/src_testbed/objects/node.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-01-09 17:25:17 +0100
committerSébastien Crozet <developer@crozet.re>2022-01-09 20:41:41 +0100
commita0d197e6919dda61ac2957e93ac72234fd6850e4 (patch)
treeb6459c5a9e26d6729f1d2955ac3ffde0e0ee9c79 /src_testbed/objects/node.rs
parent6627f7193b3a110915b05839c7fb6d592ad24fd2 (diff)
downloadrapier-a0d197e6919dda61ac2957e93ac72234fd6850e4.tar.gz
rapier-a0d197e6919dda61ac2957e93ac72234fd6850e4.tar.bz2
rapier-a0d197e6919dda61ac2957e93ac72234fd6850e4.zip
Update the testbed to use bevy 0.6
Diffstat (limited to 'src_testbed/objects/node.rs')
-rw-r--r--src_testbed/objects/node.rs59
1 files changed, 45 insertions, 14 deletions
diff --git a/src_testbed/objects/node.rs b/src_testbed/objects/node.rs
index aea11d8..1310415 100644
--- a/src_testbed/objects/node.rs
+++ b/src_testbed/objects/node.rs
@@ -5,15 +5,17 @@ use bevy::render::mesh::{Indices, VertexAttributeValues};
use na::{point, Point3, Vector3};
use std::collections::HashMap;
-use bevy::render::pipeline::PrimitiveTopology;
-use bevy::render::wireframe::Wireframe;
+use bevy::pbr::wireframe::Wireframe;
+use bevy::render::render_resource::PrimitiveTopology;
use rapier::geometry::{ColliderHandle, ColliderSet, Shape, ShapeType};
#[cfg(feature = "dim3")]
use rapier::geometry::{Cone, Cylinder};
use rapier::math::Isometry;
+use crate::graphics::BevyMaterial;
#[cfg(feature = "dim2")]
use {
+ bevy::sprite::MaterialMesh2dBundle,
na::{Point2, Vector2},
rapier::geometry::{Ball, Cuboid},
};
@@ -26,14 +28,14 @@ pub struct EntityWithGraphics {
pub collider: Option<ColliderHandle>,
pub delta: Isometry<f32>,
pub opacity: f32,
- material: Handle<StandardMaterial>,
+ material: Handle<BevyMaterial>,
}
impl EntityWithGraphics {
pub fn spawn(
commands: &mut Commands,
meshes: &mut Assets<Mesh>,
- materials: &mut Assets<StandardMaterial>,
+ materials: &mut Assets<BevyMaterial>,
prefab_meshs: &HashMap<ShapeType, Handle<Mesh>>,
shape: &dyn Shape,
collider: Option<ColliderHandle>,
@@ -74,9 +76,15 @@ impl EntityWithGraphics {
transform.rotation = Quat::from_rotation_z(shape_pos.rotation.angle());
}
+ #[cfg(feature = "dim2")]
+ let material = ColorMaterial {
+ color: bevy_color,
+ texture: None,
+ };
+ #[cfg(feature = "dim3")]
let material = StandardMaterial {
metallic: 0.5,
- roughness: 0.5,
+ perceptual_roughness: 0.5,
double_sided: true, // TODO: this doesn't do anything?
..StandardMaterial::from(bevy_color)
};
@@ -84,7 +92,15 @@ impl EntityWithGraphics {
let material_weak_handle = material_handle.clone_weak();
if let Some(mesh) = mesh {
- let pbr = PbrBundle {
+ #[cfg(feature = "dim2")]
+ let bundle = MaterialMesh2dBundle {
+ mesh: mesh.into(),
+ material: material_handle,
+ transform,
+ ..Default::default()
+ };
+ #[cfg(feature = "dim3")]
+ let bundle = PbrBundle {
mesh,
material: material_handle,
transform,
@@ -92,7 +108,7 @@ impl EntityWithGraphics {
};
let mut entity_commands = commands.entity(entity);
- entity_commands.insert_bundle(pbr);
+ entity_commands.insert_bundle(bundle);
if sensor {
entity_commands.insert(Wireframe);
@@ -115,23 +131,38 @@ impl EntityWithGraphics {
commands.entity(self.entity).despawn();
}
- pub fn select(&mut self, materials: &mut Assets<StandardMaterial>) {
+ pub fn select(&mut self, materials: &mut Assets<BevyMaterial>) {
// 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::rgba(self.color.x, self.color.y, self.color.z, self.opacity);
+ #[cfg(feature = "dim2")]
+ {
+ material.color =
+ Color::rgba(self.color.x, self.color.y, self.color.z, self.opacity);
+ }
+ #[cfg(feature = "dim3")]
+ {
+ material.base_color =
+ Color::rgba(self.color.x, self.color.y, self.color.z, self.opacity);
+ }
}
}
- pub fn unselect(&mut self, materials: &mut Assets<StandardMaterial>) {
+ pub fn unselect(&mut self, materials: &mut Assets<BevyMaterial>) {
self.set_color(materials, self.base_color);
}
- pub fn set_color(&mut self, materials: &mut Assets<StandardMaterial>, color: Point3<f32>) {
+ pub fn set_color(&mut self, materials: &mut Assets<BevyMaterial>, color: Point3<f32>) {
if let Some(material) = materials.get_mut(&self.material) {
- material.base_color = Color::rgba(color.x, color.y, color.z, self.opacity);
+ #[cfg(feature = "dim2")]
+ {
+ material.color = Color::rgba(color.x, color.y, color.z, self.opacity);
+ }
+ #[cfg(feature = "dim3")]
+ {
+ material.base_color = Color::rgba(color.x, color.y, color.z, self.opacity);
+ }
}
self.color = color;
self.base_color = color;
@@ -336,7 +367,7 @@ fn collider_mesh_scale(co_shape: &dyn Shape) -> Vec3 {
#[cfg(feature = "dim3")]
ShapeType::Cuboid => {
let c = co_shape.as_cuboid().unwrap();
- Vec3::from_slice_unaligned(c.half_extents.as_slice())
+ Vec3::from_slice(c.half_extents.as_slice())
}
#[cfg(feature = "dim3")]
ShapeType::Cylinder => {