Skip to content

Commit

Permalink
Removed hardcoded values for DebugColor in various places
Browse files Browse the repository at this point in the history
  • Loading branch information
legendofa committed Dec 14, 2024
1 parent cf77b5b commit df428dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/pipeline/debug_render_pipeline/debug_render_backend.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::DebugColor;
use crate::dynamics::{
ImpulseJoint, ImpulseJointHandle, Multibody, MultibodyLink, RigidBody, RigidBodyHandle,
};
Expand Down Expand Up @@ -43,7 +44,7 @@ pub trait DebugRenderBackend {
object: DebugRenderObject,
a: Point<Real>,
b: Point<Real>,
color: [f32; 4],
color: DebugColor,
);

/// Draws a set of lines.
Expand All @@ -54,7 +55,7 @@ pub trait DebugRenderBackend {
indices: &[[u32; 2]],
transform: &Isometry<Real>,
scale: &Vector<Real>,
color: [f32; 4],
color: DebugColor,
) {
for idx in indices {
let a = transform * (Scale::from(*scale) * vertices[idx[0] as usize]);
Expand All @@ -70,7 +71,7 @@ pub trait DebugRenderBackend {
vertices: &[Point<Real>],
transform: &Isometry<Real>,
scale: &Vector<Real>,
color: [f32; 4],
color: DebugColor,
closed: bool,
) {
for vtx in vertices.windows(2) {
Expand Down
12 changes: 7 additions & 5 deletions src/pipeline/debug_render_pipeline/debug_render_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{outlines, DebugRenderBackend};
use super::{outlines, DebugRenderBackend, DebugColor};
use crate::dynamics::{
GenericJoint, ImpulseJointSet, MultibodyJointSet, RigidBodySet, RigidBodyType,
};
Expand Down Expand Up @@ -180,8 +180,8 @@ impl DebugRenderPipeline {
let mut render_joint = |body1,
body2,
data: &GenericJoint,
mut anchor_color: [f32; 4],
mut separation_color: [f32; 4],
mut anchor_color: DebugColor,
mut separation_color: DebugColor,
object| {
if !backend.filter_object(object) {
return;
Expand Down Expand Up @@ -363,8 +363,10 @@ impl DebugRenderPipeline {
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
pos: &Isometry<Real>,
color: [f32; 4],
color: DebugColor,
) {


match shape.as_typed_shape() {
TypedShape::Ball(s) => {
let vtx = &self.instances[&TypeId::of::<Ball>()];
Expand Down Expand Up @@ -471,7 +473,7 @@ impl DebugRenderPipeline {
backend: &mut impl DebugRenderBackend,
shape: &dyn Shape,
pos: &Isometry<Real>,
color: [f32; 4],
color: DebugColor,
) {
match shape.as_typed_shape() {
TypedShape::Ball(s) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/debug_render_pipeline/debug_render_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub struct DebugRenderStyle {
/// If a rigid-body is sleeping, its attached entities will have their colors
/// multiplied by this array. (For a joint, both attached rigid-bodies must be sleeping
/// or non-dynamic for this multiplier to be applied).
pub sleep_color_multiplier: [f32; 4],
pub sleep_color_multiplier: DebugColor,
/// If a rigid-body is disabled, its attached entities will have their colors
/// multiplied by this array. (For a joint, both attached rigid-bodies must be disabled
/// for this multiplier to be applied).
pub disabled_color_multiplier: [f32; 4],
pub disabled_color_multiplier: DebugColor,
/// The length of the local coordinate axes rendered for a rigid-body.
pub rigid_body_axes_length: Real,
/// The color for the segments joining the two contact points.
Expand Down
6 changes: 3 additions & 3 deletions src_testbed/debug_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy::gizmos::gizmos::Gizmos;
use bevy::prelude::*;
use rapier::math::{Point, Real};
use rapier::pipeline::{
DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline,
DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline, DebugColor
};

#[derive(Resource)]
Expand Down Expand Up @@ -36,15 +36,15 @@ struct BevyLinesRenderBackend<'w, 's> {

impl<'w, 's> DebugRenderBackend for BevyLinesRenderBackend<'w, 's> {
#[cfg(feature = "dim2")]
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: DebugColor) {
self.gizmos.line(
[a.x as f32, a.y as f32, 1.0e-8].into(),
[b.x as f32, b.y as f32, 1.0e-8].into(),
Color::hsla(color[0], color[1], color[2], color[3]),
)
}
#[cfg(feature = "dim3")]
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: [f32; 4]) {
fn draw_line(&mut self, _: DebugRenderObject, a: Point<Real>, b: Point<Real>, color: DebugColor) {
self.gizmos.line(
[a.x as f32, a.y as f32, a.z as f32].into(),
[b.x as f32, b.y as f32, b.z as f32].into(),
Expand Down

0 comments on commit df428dc

Please sign in to comment.