Start M0 editor workflow polish
This commit is contained in:
1 parent
3e053a81ab
commit
19c4d017dc
8 files changed
+236
-40
No files matched your search
@@ -637,9 +637,42 @@ pub fn set_transform_with_history(
|
||||
if transform_nearly_eq(&old, &new) {
|
||||
return;
|
||||
}
|
||||
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
|
||||
*transform = new;
|
||||
}
|
||||
push_history(world, EditorCommand::SetTransform { entity, old, new });
|
||||
}
|
||||
|
||||
pub fn set_transform_group_with_history(
|
||||
world: &mut World,
|
||||
changes: impl IntoIterator<Item = (Entity, Transform, Transform)>,
|
||||
) {
|
||||
let mut entities = Vec::new();
|
||||
let mut olds = Vec::new();
|
||||
let mut news = Vec::new();
|
||||
for (entity, old, new) in changes {
|
||||
if transform_nearly_eq(&old, &new) {
|
||||
continue;
|
||||
}
|
||||
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
|
||||
*transform = new;
|
||||
entities.push(entity);
|
||||
olds.push(old);
|
||||
news.push(new);
|
||||
}
|
||||
}
|
||||
if !entities.is_empty() {
|
||||
push_history(
|
||||
world,
|
||||
EditorCommand::SetTransformGroup {
|
||||
entities,
|
||||
olds,
|
||||
news,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_actor_kind_with_history(
|
||||
world: &mut World,
|
||||
entity: Entity,
|
||||
@@ -1219,7 +1252,7 @@ fn capture_gizmo_transform_edits(world: &mut World) {
|
||||
let start_group =
|
||||
active.map(|(entity, transform)| selected_transforms(world, &selection, entity, transform));
|
||||
|
||||
let finished_edit = {
|
||||
let (finished_edit, live_edit) = {
|
||||
let mut tracker = world.resource_mut::<TransformEditTracker>();
|
||||
if tracker.active.is_none() {
|
||||
if let (Some((entity, transform)), Some(group)) = (active, start_group) {
|
||||
@@ -1228,15 +1261,26 @@ fn capture_gizmo_transform_edits(world: &mut World) {
|
||||
}
|
||||
}
|
||||
match tracker.active.take() {
|
||||
Some((primary, old, group)) if active.is_none() => Some((primary, old, group)),
|
||||
Some((primary, old, group)) if active.is_none() => (Some((primary, old, group)), None),
|
||||
Some(state) if active.is_some() => {
|
||||
let live = Some(state.clone());
|
||||
tracker.active = Some(state);
|
||||
None
|
||||
(None, live)
|
||||
}
|
||||
_ => None,
|
||||
_ => (None, None),
|
||||
}
|
||||
};
|
||||
|
||||
if let Some((primary, old_primary, group)) = live_edit {
|
||||
let Some(new_primary) = world.get::<Transform>(primary).copied() else {
|
||||
return;
|
||||
};
|
||||
if group.len() > 1 {
|
||||
let changes = transform_group_changes(old_primary, new_primary, group);
|
||||
apply_transform_group(world, &changes);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((primary, old_primary, group)) = finished_edit {
|
||||
let Some(new_primary) = world.get::<Transform>(primary).copied() else {
|
||||
return;
|
||||
@@ -1245,34 +1289,36 @@ fn capture_gizmo_transform_edits(world: &mut World) {
|
||||
set_transform_with_history(world, primary, old_primary, new_primary);
|
||||
return;
|
||||
}
|
||||
let translation_delta = new_primary.translation - old_primary.translation;
|
||||
let rotation_delta = new_primary.rotation * old_primary.rotation.inverse();
|
||||
let scale_ratio = new_primary.scale / old_primary.scale;
|
||||
let mut entities = Vec::new();
|
||||
let mut olds = Vec::new();
|
||||
let mut news = Vec::new();
|
||||
for (entity, old) in group {
|
||||
let changes = transform_group_changes(old_primary, new_primary, group);
|
||||
set_transform_group_with_history(world, changes);
|
||||
}
|
||||
}
|
||||
|
||||
fn transform_group_changes(
|
||||
old_primary: Transform,
|
||||
new_primary: Transform,
|
||||
group: Vec<(Entity, Transform)>,
|
||||
) -> Vec<(Entity, Transform, Transform)> {
|
||||
let translation_delta = new_primary.translation - old_primary.translation;
|
||||
let rotation_delta = new_primary.rotation * old_primary.rotation.inverse();
|
||||
let scale_ratio = new_primary.scale / old_primary.scale;
|
||||
group
|
||||
.into_iter()
|
||||
.map(|(entity, old)| {
|
||||
let new = Transform {
|
||||
translation: old.translation + translation_delta,
|
||||
rotation: rotation_delta * old.rotation,
|
||||
scale: old.scale * scale_ratio,
|
||||
};
|
||||
if let Some(mut transform) = world.get_mut::<Transform>(entity) {
|
||||
*transform = new;
|
||||
}
|
||||
entities.push(entity);
|
||||
olds.push(old);
|
||||
news.push(new);
|
||||
}
|
||||
if !entities.is_empty() {
|
||||
push_history(
|
||||
world,
|
||||
EditorCommand::SetTransformGroup {
|
||||
entities,
|
||||
olds,
|
||||
news,
|
||||
},
|
||||
);
|
||||
(entity, old, new)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn apply_transform_group(world: &mut World, changes: &[(Entity, Transform, Transform)]) {
|
||||
for (entity, _, new) in changes {
|
||||
if let Some(mut transform) = world.get_mut::<Transform>(*entity) {
|
||||
*transform = *new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user