Skip to content

Commit b0e72bb

Browse files
authored
Removed hardcoded values for DebugColor in various places (#774)
1 parent 4867586 commit b0e72bb

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

src/pipeline/debug_render_pipeline/debug_render_backend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::DebugColor;
12
use crate::dynamics::{
23
ImpulseJoint, ImpulseJointHandle, Multibody, MultibodyLink, RigidBody, RigidBodyHandle,
34
};
@@ -43,7 +44,7 @@ pub trait DebugRenderBackend {
4344
object: DebugRenderObject,
4445
a: Point<Real>,
4546
b: Point<Real>,
46-
color: [f32; 4],
47+
color: DebugColor,
4748
);
4849

4950
/// Draws a set of lines.
@@ -54,7 +55,7 @@ pub trait DebugRenderBackend {
5455
indices: &[[u32; 2]],
5556
transform: &Isometry<Real>,
5657
scale: &Vector<Real>,
57-
color: [f32; 4],
58+
color: DebugColor,
5859
) {
5960
for idx in indices {
6061
let a = transform * (Scale::from(*scale) * vertices[idx[0] as usize]);
@@ -70,7 +71,7 @@ pub trait DebugRenderBackend {
7071
vertices: &[Point<Real>],
7172
transform: &Isometry<Real>,
7273
scale: &Vector<Real>,
73-
color: [f32; 4],
74+
color: DebugColor,
7475
closed: bool,
7576
) {
7677
for vtx in vertices.windows(2) {

src/pipeline/debug_render_pipeline/debug_render_pipeline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{outlines, DebugRenderBackend};
1+
use super::{outlines, DebugColor, DebugRenderBackend};
22
use crate::dynamics::{
33
GenericJoint, ImpulseJointSet, MultibodyJointSet, RigidBodySet, RigidBodyType,
44
};
@@ -180,8 +180,8 @@ impl DebugRenderPipeline {
180180
let mut render_joint = |body1,
181181
body2,
182182
data: &GenericJoint,
183-
mut anchor_color: [f32; 4],
184-
mut separation_color: [f32; 4],
183+
mut anchor_color: DebugColor,
184+
mut separation_color: DebugColor,
185185
object| {
186186
if !backend.filter_object(object) {
187187
return;
@@ -363,7 +363,7 @@ impl DebugRenderPipeline {
363363
backend: &mut impl DebugRenderBackend,
364364
shape: &dyn Shape,
365365
pos: &Isometry<Real>,
366-
color: [f32; 4],
366+
color: DebugColor,
367367
) {
368368
match shape.as_typed_shape() {
369369
TypedShape::Ball(s) => {
@@ -471,7 +471,7 @@ impl DebugRenderPipeline {
471471
backend: &mut impl DebugRenderBackend,
472472
shape: &dyn Shape,
473473
pos: &Isometry<Real>,
474-
color: [f32; 4],
474+
color: DebugColor,
475475
) {
476476
match shape.as_typed_shape() {
477477
TypedShape::Ball(s) => {

src/pipeline/debug_render_pipeline/debug_render_style.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ pub struct DebugRenderStyle {
3535
/// If a rigid-body is sleeping, its attached entities will have their colors
3636
/// multiplied by this array. (For a joint, both attached rigid-bodies must be sleeping
3737
/// or non-dynamic for this multiplier to be applied).
38-
pub sleep_color_multiplier: [f32; 4],
38+
pub sleep_color_multiplier: DebugColor,
3939
/// If a rigid-body is disabled, its attached entities will have their colors
4040
/// multiplied by this array. (For a joint, both attached rigid-bodies must be disabled
4141
/// for this multiplier to be applied).
42-
pub disabled_color_multiplier: [f32; 4],
42+
pub disabled_color_multiplier: DebugColor,
4343
/// The length of the local coordinate axes rendered for a rigid-body.
4444
pub rigid_body_axes_length: Real,
4545
/// The color for the segments joining the two contact points.

src_testbed/debug_render.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy::gizmos::gizmos::Gizmos;
55
use bevy::prelude::*;
66
use rapier::math::{Point, Real};
77
use rapier::pipeline::{
8-
DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline,
8+
DebugColor, DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline,
99
};
1010

1111
#[derive(Resource)]
@@ -36,15 +36,27 @@ struct BevyLinesRenderBackend<'w, 's> {
3636

3737
impl<'w, 's> DebugRenderBackend for BevyLinesRenderBackend<'w, 's> {
3838
#[cfg(feature = "dim2")]
39-
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
39+
fn draw_line(
40+
&mut self,
41+
_: DebugRenderObject,
42+
a: Point<Real>,
43+
b: Point<Real>,
44+
color: DebugColor,
45+
) {
4046
self.gizmos.line(
4147
[a.x as f32, a.y as f32, 1.0e-8].into(),
4248
[b.x as f32, b.y as f32, 1.0e-8].into(),
4349
Color::hsla(color[0], color[1], color[2], color[3]),
4450
)
4551
}
4652
#[cfg(feature = "dim3")]
47-
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
53+
fn draw_line(
54+
&mut self,
55+
_: DebugRenderObject,
56+
a: Point<Real>,
57+
b: Point<Real>,
58+
color: DebugColor,
59+
) {
4860
self.gizmos.line(
4961
[a.x as f32, a.y as f32, a.z as f32].into(),
5062
[b.x as f32, b.y as f32, b.z as f32].into(),

0 commit comments

Comments
 (0)