From 597799a979c29e39575b5a06fc3b397fb159fb1a Mon Sep 17 00:00:00 2001 From: Lynn <62256001+solis-lumine-vorago@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:59:58 +0200 Subject: [PATCH] Add tetrahedron gizmos (#12914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 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 --- crates/bevy_gizmos/src/primitives/dim3.rs | 31 ++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/bevy_gizmos/src/primitives/dim3.rs b/crates/bevy_gizmos/src/primitives/dim3.rs index c34d9ba234..9f1f38890a 100644 --- a/crates/bevy_gizmos/src/primitives/dim3.rs +++ b/crates/bevy_gizmos/src/primitives/dim3.rs @@ -6,7 +6,7 @@ use std::f32::consts::TAU; use bevy_color::Color; use bevy_math::primitives::{ BoxedPolyline3d, Capsule3d, Cone, ConicalFrustum, Cuboid, Cylinder, Line3d, Plane3d, - Polyline3d, Primitive3d, Segment3d, Sphere, Torus, + Polyline3d, Primitive3d, Segment3d, Sphere, Tetrahedron, Torus, }; use bevy_math::{Dir3, Quat, Vec3}; @@ -943,3 +943,32 @@ impl Drop for Torus3dBuilder<'_, '_, '_, T> { }); } } + +// tetrahedron + +impl<'w, 's, T: GizmoConfigGroup> GizmoPrimitive3d for Gizmos<'w, 's, T> { + type Output<'a> = () where Self: 'a; + + fn primitive_3d( + &mut self, + primitive: Tetrahedron, + position: Vec3, + rotation: Quat, + color: impl Into, + ) -> Self::Output<'_> { + if !self.enabled { + return; + } + + let [a, b, c, d] = primitive + .vertices + .map(rotate_then_translate_3d(rotation, position)); + + let lines = [(a, b), (a, c), (a, d), (b, c), (b, d), (c, d)]; + + let color = color.into(); + for (a, b) in lines.into_iter() { + self.line(a, b, color); + } + } +}