Skip to content

Commit 7d26158

Browse files
authored
feat: improve debug bone rendering (#99)
A couple of small changes to make the debug rendering of bones clearer, especially for the collider editor: * Child bones are highlighted with half transparency. * The radius of bone debug views is now dependent on the length of the bone (20% of length). This makes small bones such as fingers easier to see.
1 parent de67cf8 commit 7d26158

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

crates/bevy_animation_graph/src/core/context/deferred_gizmos.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::core::{
77
space_conversion::SpaceConversionContext,
88
};
99
use bevy::{
10-
color::LinearRgba,
10+
color::{Alpha, LinearRgba},
1111
gizmos::gizmos::Gizmos,
1212
math::{Isometry3d, Quat, Vec3},
1313
platform::collections::HashMap,
@@ -120,15 +120,15 @@ fn bone_gizmo(gizmos: &mut Gizmos, start: Vec3, end: Vec3, color: LinearRgba) {
120120
}
121121

122122
const BONE_CENTER_RATIO: f32 = 0.3;
123-
const BONE_RADIUS: f32 = 0.05;
123+
let bone_radius = 0.2 * end.distance(start);
124124

125125
let start_to_end = end - start;
126126
let third_way = start + start_to_end * BONE_CENTER_RATIO;
127127
let (oba, obb) = start_to_end.normalize().any_orthonormal_pair();
128-
let a = third_way + oba * BONE_RADIUS;
129-
let b = third_way + obb * BONE_RADIUS;
130-
let c = third_way - oba * BONE_RADIUS;
131-
let d = third_way - obb * BONE_RADIUS;
128+
let a = third_way + oba * bone_radius;
129+
let b = third_way + obb * bone_radius;
130+
let c = third_way - oba * bone_radius;
131+
let d = third_way - obb * bone_radius;
132132
gizmos.line(start, a, color);
133133
gizmos.line(start, b, color);
134134
gizmos.line(start, c, color);
@@ -167,6 +167,9 @@ impl DeferredGizmosContext<'_> {
167167
let Some(parent_id) = skeleton.parent(&bone_id) else {
168168
return;
169169
};
170+
171+
let children = skeleton.children(bone_id);
172+
170173
let global_bone_transform = self
171174
.space_conversion
172175
.global_transform_of_bone(pose, skeleton, bone_id);
@@ -178,6 +181,17 @@ impl DeferredGizmosContext<'_> {
178181
global_bone_transform.translation,
179182
color,
180183
));
184+
185+
for child_bone_id in children {
186+
let child_bone_transform =
187+
self.space_conversion
188+
.global_transform_of_bone(pose, skeleton, child_bone_id);
189+
self.gizmos.queue(DeferredGizmoCommand::Bone(
190+
global_bone_transform.translation,
191+
child_bone_transform.translation,
192+
color.with_alpha(0.5 * color.alpha),
193+
));
194+
}
181195
}
182196

183197
pub fn relative_custom_gizmo(

0 commit comments

Comments
 (0)