ak_vis/render/
render_axis.rs

1use crate::components::FrameAxis;
2use crate::visuals::AxisVisual;
3use bevy::{
4    light::{NotShadowCaster, NotShadowReceiver},
5    prelude::*,
6};
7
8pub fn render_axis(
9    visuals: Vec<AxisVisual>,
10    commands: &mut Commands,
11    materials: &mut ResMut<Assets<StandardMaterial>>,
12    meshes: &mut ResMut<Assets<Mesh>>,
13) {
14    for visual in visuals {
15        let dir = visual.direction.normalize_or_zero();
16        let rot = if dir.length_squared() > 0.0 {
17            Quat::from_rotation_arc(Vec3::Y, dir)
18        } else {
19            Quat::IDENTITY
20        };
21
22        let cyl_mesh = Cylinder::new(0.1, visual.length);
23
24        commands.spawn((
25            Mesh3d(meshes.add(cyl_mesh)),
26            MeshMaterial3d(materials.add(visual.color)),
27            Transform::from_rotation(rot).with_translation(dir * (visual.length * 0.5)),
28            FrameAxis,
29            NotShadowCaster,
30            NotShadowReceiver,
31        ));
32    }
33}