Skip to content

Commit 597799a

Browse files
lynn-lumenmockersf
andauthored
Add tetrahedron gizmos (#12914)
# Objective - Adds tetrahedron gizmos, suggestion of #9400 ## Solution - Implement tetrahedron gizmos as a `gizmos.primitive_3d` ## Additional info Here is a short video of the default tetrahedron :) https://github.com/bevyengine/bevy/assets/62256001/a6f31b6f-78bc-4dc2-8f46-2ebd04ed8a0e --------- Co-authored-by: François Mockers <[email protected]>
1 parent 78c9225 commit 597799a

File tree

1 file changed

+30
-1
lines changed
  • crates/bevy_gizmos/src/primitives

1 file changed

+30
-1
lines changed

crates/bevy_gizmos/src/primitives/dim3.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::f32::consts::TAU;
66
use bevy_color::Color;
77
use bevy_math::primitives::{
88
BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d,
9-
Polyline3d, Primitive3d, Segment3d, Sphere, Torus,
9+
Polyline3d, Primitive3d, Segment3d, Sphere, Tetrahedron, Torus,
1010
};
1111
use bevy_math::{Dir3, Quat, Vec3};
1212

@@ -943,3 +943,32 @@ impl<T: GizmoConfigGroup> Drop for Torus3dBuilder<'_, '_, '_, T> {
943943
});
944944
}
945945
}
946+
947+
// tetrahedron
948+
949+
impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d<Tetrahedron> for Gizmos<'w, 's, T> {
950+
type Output<'a> = () where Self: 'a;
951+
952+
fn primitive_3d(
953+
&mut self,
954+
primitive: Tetrahedron,
955+
position: Vec3,
956+
rotation: Quat,
957+
color: impl Into<Color>,
958+
) -> Self::Output<'_> {
959+
if !self.enabled {
960+
return;
961+
}
962+
963+
let [a, b, c, d] = primitive
964+
.vertices
965+
.map(rotate_then_translate_3d(rotation, position));
966+
967+
let lines = [(a, b), (a, c), (a, d), (b, c), (b, d), (c, d)];
968+
969+
let color = color.into();
970+
for (a, b) in lines.into_iter() {
971+
self.line(a, b, color);
972+
}
973+
}
974+
}

0 commit comments

Comments
 (0)