Group brush CSG history edits
This commit is contained in:
1 parent
1b9fbebda1
commit
3f85d25cc7
3 files changed
+115
-11
No files matched your search
@@ -119,6 +119,14 @@ pub enum EditorCommand {
|
||||
old_brush: Option<BrushDesc>,
|
||||
new_brush: BrushDesc,
|
||||
},
|
||||
ApplyBrushCsg {
|
||||
primary: Entity,
|
||||
old_transform: Transform,
|
||||
new_transform: Transform,
|
||||
old_brush: Option<BrushDesc>,
|
||||
new_brush: BrushDesc,
|
||||
deleted: Vec<(EditorEntitySnapshot, Option<Entity>)>,
|
||||
},
|
||||
SetStaticMeshRenderer {
|
||||
entity: Entity,
|
||||
old: Option<StaticMeshRenderer>,
|
||||
@@ -185,6 +193,7 @@ impl EditorCommand {
|
||||
EditorCommand::SetPrimitive { .. } => "Set Primitive",
|
||||
EditorCommand::SetBrush { .. } => "Set Brush",
|
||||
EditorCommand::SetBrushTransform { .. } => "Clip Brush",
|
||||
EditorCommand::ApplyBrushCsg { .. } => "Brush CSG",
|
||||
EditorCommand::SetStaticMeshRenderer { .. } => "Set Static Mesh Renderer",
|
||||
EditorCommand::SetPostProcessVolume { .. } => "Set Post Process Volume",
|
||||
EditorCommand::SetTransformGroup { .. } => "Move Selection",
|
||||
|
||||
@@ -529,6 +529,52 @@ pub fn set_brush_transform_with_history(
|
||||
);
|
||||
}
|
||||
|
||||
pub fn apply_brush_csg_with_history(
|
||||
world: &mut World,
|
||||
primary: Entity,
|
||||
new_transform: Transform,
|
||||
new_brush: BrushDesc,
|
||||
delete_entities: &[Entity],
|
||||
) {
|
||||
if !is_level_object(world, primary) {
|
||||
return;
|
||||
}
|
||||
let old_transform = world.get::<Transform>(primary).copied().unwrap_or_default();
|
||||
let old_brush = world.get::<BrushDesc>(primary).cloned();
|
||||
let deleted: Vec<(EditorEntitySnapshot, Option<Entity>)> = delete_entities
|
||||
.iter()
|
||||
.copied()
|
||||
.filter_map(|entity| {
|
||||
snapshot_entity(world, entity).map(|snapshot| (snapshot, Some(entity)))
|
||||
})
|
||||
.collect();
|
||||
if old_transform == new_transform
|
||||
&& old_brush.as_ref() == Some(&new_brush)
|
||||
&& deleted.is_empty()
|
||||
{
|
||||
return;
|
||||
}
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(primary) {
|
||||
entity_mut.insert(new_transform);
|
||||
entity_mut.insert(new_brush.clone());
|
||||
}
|
||||
for (_, entity) in &deleted {
|
||||
despawn_entity(world, *entity);
|
||||
}
|
||||
push_history(
|
||||
world,
|
||||
EditorCommand::ApplyBrushCsg {
|
||||
primary,
|
||||
old_transform,
|
||||
new_transform,
|
||||
old_brush,
|
||||
new_brush,
|
||||
deleted,
|
||||
},
|
||||
);
|
||||
select_one(world, primary);
|
||||
}
|
||||
|
||||
pub fn set_static_mesh_renderer_with_history(
|
||||
world: &mut World,
|
||||
entity: Entity,
|
||||
@@ -875,6 +921,25 @@ fn undo_command(world: &mut World, command: &mut EditorCommand) {
|
||||
}
|
||||
apply_brush(world, *entity, old_brush);
|
||||
}
|
||||
EditorCommand::ApplyBrushCsg {
|
||||
primary,
|
||||
old_transform,
|
||||
old_brush,
|
||||
deleted,
|
||||
..
|
||||
} => {
|
||||
if let Some(mut transform) = world.get_mut::<Transform>(*primary) {
|
||||
*transform = *old_transform;
|
||||
}
|
||||
apply_brush(world, *primary, old_brush);
|
||||
let mut restored = vec![*primary];
|
||||
for (snapshot, entity) in deleted.iter_mut() {
|
||||
let spawned = spawn_snapshot(world, snapshot);
|
||||
*entity = Some(spawned);
|
||||
restored.push(spawned);
|
||||
}
|
||||
select_many(world, &restored);
|
||||
}
|
||||
EditorCommand::SetStaticMeshRenderer { entity, old, .. } => {
|
||||
apply_static_mesh_renderer(world, *entity, old);
|
||||
}
|
||||
@@ -1014,6 +1079,22 @@ fn redo_command(world: &mut World, command: &mut EditorCommand) {
|
||||
entity_mut.insert(new_brush.clone());
|
||||
}
|
||||
}
|
||||
EditorCommand::ApplyBrushCsg {
|
||||
primary,
|
||||
new_transform,
|
||||
new_brush,
|
||||
deleted,
|
||||
..
|
||||
} => {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(*primary) {
|
||||
entity_mut.insert(*new_transform);
|
||||
entity_mut.insert(new_brush.clone());
|
||||
}
|
||||
for (_, entity) in deleted.iter_mut() {
|
||||
despawn_entity(world, entity.take());
|
||||
}
|
||||
select_one(world, *primary);
|
||||
}
|
||||
EditorCommand::SetStaticMeshRenderer { entity, new, .. } => {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(*entity) {
|
||||
entity_mut.insert(new.clone());
|
||||
|
||||
Reference in new issue
Block a user