mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-26 08:38:10 +00:00
Rotation refactor
This commit is contained in:
@@ -7,7 +7,7 @@ use super::{
|
|||||||
on_gizmo_element_hover, on_gizmo_element_unhover,
|
on_gizmo_element_hover, on_gizmo_element_unhover,
|
||||||
rotation::{on_rotate, on_rotation_end, on_rotation_start, RotationWidget},
|
rotation::{on_rotate, on_rotation_end, on_rotation_start, RotationWidget},
|
||||||
translation::{on_translate, on_translation_end, on_translation_start, TranslationWidget},
|
translation::{on_translate, on_translation_end, on_translation_start, TranslationWidget},
|
||||||
GizmoMats, GizmoMeshes, TransformGizmoBundle, TransformGizmoRoot, GIZMO_RENDER_LAYER,
|
GizmoMats, GizmoMeshes, TransformGizmoBundle, GIZMO_RENDER_LAYER,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -20,10 +20,7 @@ pub(super) fn spawn_combo_translation_rotation_gizmo(
|
|||||||
meshes: &GizmoMeshes,
|
meshes: &GizmoMeshes,
|
||||||
mats: &GizmoMats,
|
mats: &GizmoMats,
|
||||||
) {
|
) {
|
||||||
cmd.spawn_empty()
|
cmd.spawn(TransformGizmoBundle::new(target, target_global_transform, space, normalizing_scale))
|
||||||
.insert(TransformGizmoRoot)
|
|
||||||
.with_children(|cmd| {
|
|
||||||
cmd.spawn(TransformGizmoBundle::new(target, target_global_transform, space, normalizing_scale))
|
|
||||||
.with_children(|cmd| {
|
.with_children(|cmd| {
|
||||||
use super::{ROT_X, ROT_Y, ROT_Z};
|
use super::{ROT_X, ROT_Y, ROT_Z};
|
||||||
|
|
||||||
@@ -162,5 +159,4 @@ pub(super) fn spawn_combo_translation_rotation_gizmo(
|
|||||||
On::<Pointer<DragEnd>>::target_commands_mut(on_translation_end),
|
On::<Pointer<DragEnd>>::target_commands_mut(on_translation_end),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ use crate::{
|
|||||||
math::{IsNonUniform, MatrixExtras, VecExtras},
|
math::{IsNonUniform, MatrixExtras, VecExtras},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub(super) struct TransformGizmoRoot;
|
|
||||||
|
|
||||||
#[derive(Component, Reflect)]
|
#[derive(Component, Reflect)]
|
||||||
pub(super) struct TransformGizmo {
|
pub(super) struct TransformGizmo {
|
||||||
pub(super) target : Entity,
|
pub(super) target : Entity,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::{
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
on_gizmo_element_hover, on_gizmo_element_unhover, GizmoMats, GizmoMeshes, InitialTransform,
|
on_gizmo_element_hover, on_gizmo_element_unhover, GizmoMats, GizmoMeshes, InitialTransform,
|
||||||
RebuildGizmo, TransformGizmo, TransformGizmoBundle, TransformGizmoRoot, GIZMO_RENDER_LAYER,
|
RebuildGizmo, TransformGizmo, TransformGizmoBundle, GIZMO_RENDER_LAYER,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
@@ -47,10 +47,7 @@ pub(super) fn spawn_rotation_gizmo(
|
|||||||
meshes: &GizmoMeshes,
|
meshes: &GizmoMeshes,
|
||||||
mats: &GizmoMats,
|
mats: &GizmoMats,
|
||||||
) {
|
) {
|
||||||
cmd.spawn_empty()
|
cmd.spawn((
|
||||||
.insert(TransformGizmoRoot)
|
|
||||||
.with_children(|cmd| {
|
|
||||||
cmd.spawn((
|
|
||||||
TransformGizmoBundle::new(target, target_global_transform, space, normalizing_scale),
|
TransformGizmoBundle::new(target, target_global_transform, space, normalizing_scale),
|
||||||
On::<Pointer<DragStart>>::run(on_rotation_start),
|
On::<Pointer<DragStart>>::run(on_rotation_start),
|
||||||
On::<Pointer<Drag>>::run(on_rotate),
|
On::<Pointer<Drag>>::run(on_rotate),
|
||||||
@@ -130,7 +127,6 @@ pub(super) fn spawn_rotation_gizmo(
|
|||||||
On::<Pointer<Out>>::run(on_gizmo_element_unhover),
|
On::<Pointer<Out>>::run(on_gizmo_element_unhover),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn update_ss_ring_rotation(
|
pub(super) fn update_ss_ring_rotation(
|
||||||
@@ -182,38 +178,51 @@ fn on_trackball_unhover(
|
|||||||
pub(super) fn on_rotation_start(
|
pub(super) fn on_rotation_start(
|
||||||
event: Listener<Pointer<DragStart>>,
|
event: Listener<Pointer<DragStart>>,
|
||||||
mut cmd: Commands,
|
mut cmd: Commands,
|
||||||
q_xform: Query<(Entity, &GlobalTransform), With<TransformGizmoRoot>>,
|
q_xform: Query<(Entity, &GlobalTransform)>,
|
||||||
|
q_gizmos: Query<&TransformGizmo>
|
||||||
) {
|
) {
|
||||||
info!("Rotation start");
|
info!("Rotation start");
|
||||||
|
|
||||||
if let Ok((ent, &world_xform)) = q_xform.get_single() {
|
let Ok(gizmo) = q_gizmos.get_single() else {
|
||||||
let hit_point = event.hit.position.unwrap();
|
error!("Rotation gizmo not found");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
cmd.entity(ent).insert((
|
let Ok((ent, world_xform)) = q_xform.get(gizmo.target) else {
|
||||||
InitialTransform(world_xform),
|
error!("Rotation gizmo target not found");
|
||||||
InitialHitPoint(hit_point),
|
return;
|
||||||
LastHitPoint(hit_point),
|
};
|
||||||
LastRotation {
|
|
||||||
axis: Vec3::ZERO,
|
let hit_point = event.hit.position.unwrap();
|
||||||
theta: 0.,
|
|
||||||
},
|
cmd.entity(ent).insert((
|
||||||
));
|
InitialTransform(world_xform.clone()),
|
||||||
}
|
InitialHitPoint(hit_point),
|
||||||
|
LastHitPoint(hit_point),
|
||||||
|
LastRotation {
|
||||||
|
axis: Vec3::ZERO,
|
||||||
|
theta: 0.,
|
||||||
|
},
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn on_rotation_end(
|
pub(super) fn on_rotation_end(
|
||||||
event: Listener<Pointer<DragEnd>>,
|
_: Listener<Pointer<DragEnd>>,
|
||||||
mut cmd: Commands,
|
mut cmd: Commands,
|
||||||
r_xform_mode: Res<TransformMode>,
|
r_xform_mode: Res<TransformMode>,
|
||||||
mut ev_rebuild_gizmo: EventWriter<RebuildGizmo>,
|
mut ev_rebuild_gizmo: EventWriter<RebuildGizmo>,
|
||||||
|
q_inited_components: Query<Entity, With<LastRotation>>
|
||||||
) {
|
) {
|
||||||
info!("Rotation end");
|
info!("Rotation end");
|
||||||
|
|
||||||
cmd.entity(event.target)
|
for ent in q_inited_components.iter() {
|
||||||
.remove::<InitialTransform>()
|
cmd.entity(ent)
|
||||||
.remove::<InitialHitPoint>()
|
.remove::<InitialTransform>()
|
||||||
.remove::<LastHitPoint>()
|
.remove::<InitialHitPoint>()
|
||||||
.remove::<LastRotation>();
|
.remove::<LastHitPoint>()
|
||||||
|
.remove::<LastRotation>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if matches!(r_xform_mode.space, TransformSpace::World) {
|
if matches!(r_xform_mode.space, TransformSpace::World) {
|
||||||
ev_rebuild_gizmo.send(RebuildGizmo);
|
ev_rebuild_gizmo.send(RebuildGizmo);
|
||||||
@@ -232,7 +241,6 @@ pub(super) fn on_rotate(
|
|||||||
&mut LastHitPoint,
|
&mut LastHitPoint,
|
||||||
&mut LastRotation,
|
&mut LastRotation,
|
||||||
),
|
),
|
||||||
With<TransformGizmoRoot>,
|
|
||||||
>,
|
>,
|
||||||
q_camera: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
|
q_camera: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
|
||||||
q_gizmo: Query<&GlobalTransform, (With<TransformGizmo>, Without<MainCamera>)>,
|
q_gizmo: Query<&GlobalTransform, (With<TransformGizmo>, Without<MainCamera>)>,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::{interaction::TransformSpace, MainCamera};
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
on_gizmo_element_hover, on_gizmo_element_unhover, GizmoMats, GizmoMeshes, InitialTransform,
|
on_gizmo_element_hover, on_gizmo_element_unhover, GizmoMats, GizmoMeshes, InitialTransform,
|
||||||
TransformGizmo, TransformGizmoBundle, TransformGizmoRoot, GIZMO_RENDER_LAYER,
|
TransformGizmo, TransformGizmoBundle, GIZMO_RENDER_LAYER,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
|||||||
Reference in New Issue
Block a user