Add brush authoring schema
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-06-06 05:42:19 -04:00
1 parent cc6acb188d
commit 9f95ba3082
24 files changed
+891 -78

No files matched your search

+48 -1
View File
@@ -1,6 +1,6 @@
use bevy::prelude::*;
use shared::{
infer_actor_kind, ActorId, ActorKind, ActorName, ColliderDesc, EditorVisibility,
infer_actor_kind, ActorId, ActorKind, ActorName, BrushDesc, ColliderDesc, EditorVisibility,
HierarchySiblingIndex, InspectorOrder, LevelObject, LightDesc, MaterialDesc, MaterialOverride,
ModelRef, ObjectiveMarker, PhysicsBody, PlayerSpawn, PostProcessVolumeDesc, PrefabInstance,
PrefabRef, Primitive, RigidBodyDesc, StaticMeshRenderer, TeamSpawn, TriggerVolume, WeaponSpawn,
@@ -127,6 +127,7 @@ pub fn snapshot_entity(world: &World, entity: Entity) -> Option<EditorEntitySnap
.map(|name| name.as_str().to_string()),
transform: entity_ref.get::<Transform>().copied().unwrap_or_default(),
primitive: entity_ref.get::<Primitive>().cloned(),
brush: entity_ref.get::<BrushDesc>().cloned(),
static_mesh_renderer: entity_ref.get::<StaticMeshRenderer>().cloned(),
material: entity_ref.get::<MaterialDesc>().cloned(),
material_override: entity_ref.get::<MaterialOverride>().cloned(),
@@ -185,6 +186,9 @@ fn spawn_snapshot_with_parent(
if let Some(primitive) = &snapshot.primitive {
entity_mut.insert(primitive.clone());
}
if let Some(brush) = &snapshot.brush {
entity_mut.insert(brush.clone());
}
if let Some(renderer) = &snapshot.static_mesh_renderer {
entity_mut.insert(renderer.clone());
}
@@ -453,6 +457,20 @@ pub fn set_primitive_with_history(world: &mut World, entity: Entity, new: Primit
push_history(world, EditorCommand::SetPrimitive { entity, old, new });
}
pub fn set_brush_with_history(world: &mut World, entity: Entity, new: BrushDesc) {
if !is_level_object(world, entity) {
return;
}
let old = world.get::<BrushDesc>(entity).cloned();
if old.as_ref() == Some(&new) {
return;
}
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
entity_mut.insert(new.clone());
}
push_history(world, EditorCommand::SetBrush { entity, old, new });
}
pub fn set_static_mesh_renderer_with_history(
world: &mut World,
entity: Entity,
@@ -558,6 +576,7 @@ pub fn group_selection_with_history(world: &mut World, entities: &[Entity]) {
name: Some("Group".to_string()),
transform: Transform::default(),
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
@@ -600,6 +619,7 @@ pub fn create_empty_child_with_history(world: &mut World, parent: Entity) {
name: Some("Empty".to_string()),
transform: Transform::default(),
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
@@ -777,6 +797,9 @@ fn undo_command(world: &mut World, command: &mut EditorCommand) {
EditorCommand::SetPrimitive { entity, old, .. } => {
apply_primitive(world, *entity, old);
}
EditorCommand::SetBrush { entity, old, .. } => {
apply_brush(world, *entity, old);
}
EditorCommand::SetStaticMeshRenderer { entity, old, .. } => {
apply_static_mesh_renderer(world, *entity, old);
}
@@ -889,6 +912,11 @@ fn redo_command(world: &mut World, command: &mut EditorCommand) {
entity_mut.insert(new.clone());
}
}
EditorCommand::SetBrush { entity, new, .. } => {
if let Ok(mut entity_mut) = world.get_entity_mut(*entity) {
entity_mut.insert(new.clone());
}
}
EditorCommand::SetStaticMeshRenderer { entity, new, .. } => {
if let Ok(mut entity_mut) = world.get_entity_mut(*entity) {
entity_mut.insert(new.clone());
@@ -1045,6 +1073,19 @@ fn apply_primitive(world: &mut World, entity: Entity, primitive: &Option<Primiti
}
}
fn apply_brush(world: &mut World, entity: Entity, brush: &Option<BrushDesc>) {
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
match brush {
Some(value) => {
entity_mut.insert(value.clone());
}
None => {
entity_mut.remove::<BrushDesc>();
}
}
}
}
fn apply_static_mesh_renderer(
world: &mut World,
entity: Entity,
@@ -1098,6 +1139,9 @@ fn apply_authored_components(world: &mut World, entity: Entity, snapshot: &Edito
if let Some(v) = &snapshot.primitive {
entity_mut.insert(v.clone());
}
if let Some(v) = &snapshot.brush {
entity_mut.insert(v.clone());
}
if let Some(v) = &snapshot.static_mesh_renderer {
entity_mut.insert(v.clone());
}
@@ -1154,6 +1198,9 @@ fn remove_authored_components(world: &mut World, entity: Entity, snapshot: &Edit
if snapshot.primitive.is_some() {
entity_mut.remove::<Primitive>();
}
if snapshot.brush.is_some() {
entity_mut.remove::<BrushDesc>();
}
if snapshot.static_mesh_renderer.is_some() {
entity_mut.remove::<StaticMeshRenderer>();
}