Attach IK rig to selected skeleton

This commit is contained in:
Danny McGee
2024-02-28 18:49:16 -05:00
parent 96f1f8ec39
commit 3f887d3f3e
5 changed files with 282 additions and 20 deletions
+40 -12
View File
@@ -5,7 +5,10 @@ use bevy::{
};
use space_editor::space_editor_ui::NotShowCamera;
use crate::MainCamera;
use crate::{
anim::ik::{IkRigCamera, IK_RIG_RENDER_LAYER},
MainCamera,
};
use super::GIZMO_RENDER_LAYER;
@@ -19,9 +22,13 @@ pub(super) fn spawn_gizmo_camera(
let ent = q_main_camera.single();
cmd.entity(ent).with_children(|cmd| {
// TODO: This doesn't really belong here, but the render pipeline seems
// to break if we don't spawn these cameras in the correct order.
// We should probably add a dedicated module/plugin for setting up
// the editor cameras.
cmd.spawn((
Name::new("Gizmo Camera"),
GizmoCamera,
Name::new("IK Rig Camera"),
IkRigCamera,
Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
@@ -34,6 +41,26 @@ pub(super) fn spawn_gizmo_camera(
},
..default()
},
RenderLayers::layer(IK_RIG_RENDER_LAYER),
Fxaa::default(),
NotShowCamera,
));
cmd.spawn((
Name::new("Gizmo Camera"),
GizmoCamera,
Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::None,
..default()
},
camera: Camera {
hdr: true,
order: 2,
..default()
},
..default()
},
RenderLayers::layer(GIZMO_RENDER_LAYER),
Fxaa::default(),
NotShowCamera,
@@ -41,17 +68,18 @@ pub(super) fn spawn_gizmo_camera(
});
}
pub(super) fn sync_gizmo_and_main_cameras(
q_main_camera: Query<&Camera, (With<MainCamera>, Without<GizmoCamera>)>,
mut q_gizmo_camera: Query<&mut Camera, (With<GizmoCamera>, Without<MainCamera>)>,
pub(super) fn sync_main_and_aux_cameras(
q_main_camera: Query<(Entity, &Camera), With<MainCamera>>,
mut q_other_cameras: Query<&mut Camera, Without<MainCamera>>,
q_children: Query<&Children>,
) {
let Ok(main_cam) = q_main_camera.get_single() else {
let Ok((main_cam_ent, main_cam)) = q_main_camera.get_single() else {
return;
};
let Ok(mut gizmo_cam) = q_gizmo_camera.get_single_mut() else {
return;
};
gizmo_cam.viewport = main_cam.viewport.clone();
for child in q_children.iter_descendants(main_cam_ent) {
if let Ok(mut cam) = q_other_cameras.get_mut(child) {
cam.viewport = main_cam.viewport.clone();
}
}
}
+3 -4
View File
@@ -6,12 +6,11 @@ use self::{
camera::{spawn_gizmo_camera, GizmoCamera},
combo::spawn_combo_translation_rotation_gizmo,
common::*,
material::GizmoMaterial,
resources::{init_resources, GizmoMats, GizmoMeshes},
rotation::{spawn_rotation_gizmo, update_ss_ring_rotation},
translation::spawn_translation_gizmo,
};
pub use common::TransformGizmo;
pub use self::{common::TransformGizmo, material::GizmoMaterial};
use super::{Selection, TransformMode, TransformType};
@@ -23,7 +22,7 @@ mod resources;
mod rotation;
mod translation;
const GIZMO_RENDER_LAYER: u8 = 1;
pub const GIZMO_RENDER_LAYER: u8 = 2;
/// (sin|cos)(pi / 4)
const CIRC_45: f32 = 0.70710677;
@@ -67,7 +66,7 @@ impl Plugin for GizmoPlugin {
);
//sync camera viewports
app.add_systems(Update, camera::sync_gizmo_and_main_cameras);
app.add_systems(Update, camera::sync_main_and_aux_cameras);
app.add_systems(
PostUpdate,