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

+3
View File
@@ -455,6 +455,7 @@ pub fn snapshot_for_asset(asset: &EditorAsset, translation: Vec3) -> Option<Edit
name: Some(asset.label.clone()),
transform: Transform::from_translation(translation),
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
@@ -654,6 +655,7 @@ pub fn spawn_subasset_at(
name: Some(label.clone()),
transform: Transform::from_translation(translation + Vec3::Y * 0.1),
primitive: None,
brush: None,
static_mesh_renderer: Some(shared::StaticMeshRenderer::single(slot)),
material: None,
material_override: None,
@@ -723,6 +725,7 @@ fn apply_static_mesh_placement_mode(
}),
transform,
primitive: None,
brush: None,
static_mesh_renderer: Some(shared::StaticMeshRenderer::single(entry)),
material: None,
material_override: None,
+11 -4
View File
@@ -1,9 +1,9 @@
use bevy::prelude::*;
use shared::{
ActorId, ActorKind, ActorName, ColliderDesc, EditorVisibility, InspectorOrder, LightDesc,
MaterialDesc, MaterialOverride, ModelRef, ObjectiveMarker, PhysicsBody, PostProcessVolumeDesc,
PrefabInstance, PrefabRef, Primitive, RigidBodyDesc, StaticMeshRenderer, TeamSpawn,
TriggerVolume, WeaponSpawn,
ActorId, ActorKind, ActorName, BrushDesc, ColliderDesc, EditorVisibility, InspectorOrder,
LightDesc, MaterialDesc, MaterialOverride, ModelRef, ObjectiveMarker, PhysicsBody,
PostProcessVolumeDesc, PrefabInstance, PrefabRef, Primitive, RigidBodyDesc, StaticMeshRenderer,
TeamSpawn, TriggerVolume, WeaponSpawn,
};
#[derive(Debug, Clone)]
pub struct EditorEntitySnapshot {
@@ -13,6 +13,7 @@ pub struct EditorEntitySnapshot {
pub name: Option<String>,
pub transform: Transform,
pub primitive: Option<Primitive>,
pub brush: Option<BrushDesc>,
pub static_mesh_renderer: Option<StaticMeshRenderer>,
pub material: Option<MaterialDesc>,
pub material_override: Option<MaterialOverride>,
@@ -102,6 +103,11 @@ pub enum EditorCommand {
old: Option<Primitive>,
new: Primitive,
},
SetBrush {
entity: Entity,
old: Option<BrushDesc>,
new: BrushDesc,
},
SetStaticMeshRenderer {
entity: Entity,
old: Option<StaticMeshRenderer>,
@@ -165,6 +171,7 @@ impl EditorCommand {
EditorCommand::SetRigidBody { .. } => "Set Rigid Body",
EditorCommand::SetCollider { .. } => "Set Collider",
EditorCommand::SetPrimitive { .. } => "Set Primitive",
EditorCommand::SetBrush { .. } => "Set Brush",
EditorCommand::SetStaticMeshRenderer { .. } => "Set Static Mesh Renderer",
EditorCommand::SetPostProcessVolume { .. } => "Set Post Process Volume",
EditorCommand::SetTransformGroup { .. } => "Move Selection",
+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>();
}
+17 -1
View File
@@ -11,7 +11,7 @@ use scene::{document::SceneDocument, strip_schema_version, validate_level_text};
use serde::de::DeserializeSeed;
use shared::{
flush_level_object_hydration, infer_actor_kind, strip_hydrated_entity, validate_actor, ActorId,
ActorKind, ActorName, ActorValidationError, ColliderDesc, EditorVisibility,
ActorKind, ActorName, ActorValidationError, BrushDesc, ColliderDesc, EditorVisibility,
HierarchySiblingIndex, InspectorOrder, LevelObject, LightDesc, MaterialDesc, MaterialOverride,
ModelRef, ObjectiveMarker, PhysicsBody, PlayerSpawn, PostProcessVolumeDesc, PrefabInstance,
PrefabRef, Primitive, RigidBodyDesc, StaticMeshRenderer, TeamSpawn, TriggerVolume, WeaponSpawn,
@@ -389,6 +389,21 @@ fn format_actor_validation(err: ActorValidationError) -> String {
ActorValidationError::MissingTransform => {
"Save failed: level object missing Transform".into()
}
ActorValidationError::BrushMissingDesc => {
"Save failed: Brush actor requires BrushDesc".into()
}
ActorValidationError::BrushHasPrimitive => {
"Save failed: Brush actor cannot have Primitive".into()
}
ActorValidationError::BrushHasStaticMeshRenderer => {
"Save failed: Brush actor cannot have StaticMeshRenderer".into()
}
ActorValidationError::BrushHasLight => {
"Save failed: Brush actor cannot have LightDesc".into()
}
ActorValidationError::BrushHasModelRef => {
"Save failed: Brush actor cannot have ModelRef".into()
}
ActorValidationError::StaticMeshMissingPrimitive => {
"Save failed: StaticMesh actor requires Primitive or StaticMeshRenderer with a mesh slot"
.into()
@@ -462,6 +477,7 @@ fn save_entities(world: &mut World, path: &Path, entities: Vec<Entity>) -> Resul
.allow_component::<ActorKind>()
.allow_component::<InspectorOrder>()
.allow_component::<Primitive>()
.allow_component::<BrushDesc>()
.allow_component::<StaticMeshRenderer>()
.allow_component::<MaterialDesc>()
.allow_component::<MaterialOverride>()
+2 -1
View File
@@ -86,6 +86,7 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
match kind {
ActorKind::StaticMesh
| ActorKind::Brush
| ActorKind::ImportedModel
| ActorKind::Light
| ActorKind::Empty
@@ -110,7 +111,7 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
fn actor_icon(kind: ActorKind) -> egui_phosphor_icons::Icon {
match kind {
ActorKind::StaticMesh | ActorKind::ImportedModel => icons::CUBE,
ActorKind::StaticMesh | ActorKind::Brush | ActorKind::ImportedModel => icons::CUBE,
ActorKind::Light => icons::LIGHTBULB,
ActorKind::PrefabAnchor => icons::PACKAGE,
ActorKind::PlayerSpawn => icons::PERSON_SIMPLE_RUN,
+26 -2
View File
@@ -51,10 +51,31 @@ impl Default for EditorComponentRegistry {
description: "Renders one or more normalized imported mesh slots.",
search_terms: &["mesh", "renderer", "rendering", "model", "static"],
recommended: &[],
conflicts_with: &["shared::components::Primitive"],
conflicts_with: &[
"shared::components::Primitive",
"shared::components::BrushDesc",
],
hydration_effect:
"Hydrates into generated mesh children and material bindings.",
},
EditorComponentDescriptor {
type_name: "shared::components::BrushDesc",
display_name: "Brush",
category: EditorComponentCategory::Authoring,
addable: true,
removable: true,
reorderable: true,
hidden: false,
icon: icons::CUBE.as_str(),
description: "Creates authored convex brush geometry for blockout.",
search_terms: &["brush", "blockout", "convex", "csg", "geometry"],
recommended: &["shared::components::MaterialDesc"],
conflicts_with: &[
"shared::components::Primitive",
"shared::components::StaticMeshRenderer",
],
hydration_effect: "Hydrates into generated brush mesh children.",
},
EditorComponentDescriptor {
type_name: "shared::components::MaterialDesc",
display_name: "Authoring Material",
@@ -127,7 +148,10 @@ impl Default for EditorComponentRegistry {
description: "Creates an authored built-in primitive shape.",
search_terms: &["box", "sphere", "ramp", "primitive"],
recommended: &[],
conflicts_with: &["shared::components::StaticMeshRenderer"],
conflicts_with: &[
"shared::components::StaticMeshRenderer",
"shared::components::BrushDesc",
],
hydration_effect:
"Hydrates into generated primitive render and collision data.",
},
+3
View File
@@ -89,6 +89,7 @@ pub fn light_snapshot(name: &str, translation: Vec3) -> EditorEntitySnapshot {
name: Some(name.to_string()),
transform: Transform::from_translation(translation),
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
@@ -136,6 +137,7 @@ pub fn ensure_player_spawn_for_edit(world: &mut World) -> Entity {
name: Some("Player Start".to_string()),
transform,
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
@@ -223,6 +225,7 @@ pub fn create_scene_sun_override_from_project_settings(world: &mut World) -> Ent
name: Some("Scene Sun".to_string()),
transform,
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
+2 -1
View File
@@ -106,7 +106,7 @@ fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
.copied()
.map(|kind| match kind {
ActorKind::Empty => 0,
ActorKind::StaticMesh | ActorKind::ImportedModel => 1,
ActorKind::Brush | ActorKind::StaticMesh | ActorKind::ImportedModel => 1,
ActorKind::Light => 2,
ActorKind::PrefabAnchor => 3,
ActorKind::PlayerSpawn => 4,
@@ -336,6 +336,7 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
use egui_phosphor_icons::icons;
match kind {
ActorKind::Empty => icons::FOLDER.as_str(),
ActorKind::Brush => icons::CUBE.as_str(),
ActorKind::StaticMesh => icons::CUBE.as_str(),
ActorKind::ImportedModel => icons::CUBE_TRANSPARENT.as_str(),
ActorKind::Light => icons::LIGHTBULB.as_str(),
+103 -18
View File
@@ -7,25 +7,25 @@ use bevy::prelude::*;
use bevy_egui::egui;
use egui_phosphor_icons::{icons, Icon};
use shared::{
inspector_component_active, AuthoringLightKind, AuthoringRigidBody, ColliderDesc,
ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef, InspectorOrder, LevelObject,
LightDesc, MaterialDesc, MaterialParameter, MaterialParameterValue, MaterialShaderKind,
ObjectiveMarker, PhysicsBody, PlayerSpawn, PostProcessVolumeDesc, PrefabInstance, Primitive,
PrimitiveShape, ProjectSun, RigidBodyDesc, StaticMeshRenderer, StaticMeshRendererEntry,
TeamSpawn, TriggerVolume, WeaponSpawn, AUTHORING_DIRECTIONAL_LUX_MAX,
AUTHORING_POINT_SPOT_LUMENS_MAX, COMPONENT_COLLIDER_DESC, COMPONENT_LIGHT_DESC,
COMPONENT_MATERIAL_DESC, COMPONENT_OBJECTIVE_MARKER, COMPONENT_PHYSICS_BODY,
COMPONENT_PLAYER_SPAWN, COMPONENT_POST_PROCESS_VOLUME, COMPONENT_PREFAB_INSTANCE,
COMPONENT_PRIMITIVE, COMPONENT_PROJECT_SUN, COMPONENT_RIGID_BODY_DESC,
COMPONENT_STATIC_MESH_RENDERER, COMPONENT_TEAM_SPAWN, COMPONENT_TRIGGER_VOLUME,
COMPONENT_WEAPON_SPAWN,
inspector_component_active, AuthoringLightKind, AuthoringRigidBody, BrushDesc, BrushKind,
ColliderDesc, ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef,
InspectorOrder, LevelObject, LightDesc, MaterialDesc, MaterialParameter,
MaterialParameterValue, MaterialShaderKind, ObjectiveMarker, PhysicsBody, PlayerSpawn,
PostProcessVolumeDesc, PrefabInstance, Primitive, PrimitiveShape, ProjectSun, RigidBodyDesc,
StaticMeshRenderer, StaticMeshRendererEntry, TeamSpawn, TriggerVolume, WeaponSpawn,
AUTHORING_DIRECTIONAL_LUX_MAX, AUTHORING_POINT_SPOT_LUMENS_MAX, COMPONENT_BRUSH_DESC,
COMPONENT_COLLIDER_DESC, COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC,
COMPONENT_OBJECTIVE_MARKER, COMPONENT_PHYSICS_BODY, COMPONENT_PLAYER_SPAWN,
COMPONENT_POST_PROCESS_VOLUME, COMPONENT_PREFAB_INSTANCE, COMPONENT_PRIMITIVE,
COMPONENT_PROJECT_SUN, COMPONENT_RIGID_BODY_DESC, COMPONENT_STATIC_MESH_RENDERER,
COMPONENT_TEAM_SPAWN, COMPONENT_TRIGGER_VOLUME, COMPONENT_WEAPON_SPAWN,
};
use crate::history::{
material_eq, set_collider_with_history, set_inspector_order_with_history,
set_light_with_history, set_material_with_history, set_physics_with_history,
set_post_process_volume_with_history, set_primitive_with_history, set_rigid_body_with_history,
set_static_mesh_renderer_with_history, EditorEntitySnapshot,
material_eq, set_brush_with_history, set_collider_with_history,
set_inspector_order_with_history, set_light_with_history, set_material_with_history,
set_physics_with_history, set_post_process_volume_with_history, set_primitive_with_history,
set_rigid_body_with_history, set_static_mesh_renderer_with_history, EditorEntitySnapshot,
};
use crate::selection::SelectedEntity;
use crate::ui::theme::{
@@ -131,6 +131,7 @@ enum AddComponentShelfDirection {
#[derive(Debug, Clone)]
enum CopiedComponent {
Primitive(Primitive),
BrushDesc(BrushDesc),
StaticMeshRenderer(StaticMeshRenderer),
MaterialDesc(MaterialDesc),
LightDesc(LightDesc),
@@ -149,6 +150,7 @@ impl CopiedComponent {
fn type_name(&self) -> &'static str {
match self {
Self::Primitive(_) => COMPONENT_PRIMITIVE,
Self::BrushDesc(_) => COMPONENT_BRUSH_DESC,
Self::StaticMeshRenderer(_) => COMPONENT_STATIC_MESH_RENDERER,
Self::MaterialDesc(_) => COMPONENT_MATERIAL_DESC,
Self::LightDesc(_) => COMPONENT_LIGHT_DESC,
@@ -357,6 +359,9 @@ fn present_component_type_names(world: &World, entity: Entity) -> Vec<&'static s
if world.get::<Primitive>(entity).is_some() {
present.push(COMPONENT_PRIMITIVE);
}
if world.get::<BrushDesc>(entity).is_some() {
present.push(COMPONENT_BRUSH_DESC);
}
if world.get::<MaterialDesc>(entity).is_some() || world.get::<Primitive>(entity).is_some() {
present.push(COMPONENT_MATERIAL_DESC);
}
@@ -405,6 +410,10 @@ fn copy_component(world: &mut World, entity: Entity, type_name: &str) {
.get::<Primitive>(entity)
.cloned()
.map(CopiedComponent::Primitive),
COMPONENT_BRUSH_DESC => world
.get::<BrushDesc>(entity)
.cloned()
.map(CopiedComponent::BrushDesc),
COMPONENT_STATIC_MESH_RENDERER => world
.get::<StaticMeshRenderer>(entity)
.cloned()
@@ -468,6 +477,9 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
Some(CopiedComponent::Primitive(value)) if type_name == COMPONENT_PRIMITIVE => {
set_primitive_with_history(world, entity, value);
}
Some(CopiedComponent::BrushDesc(value)) if type_name == COMPONENT_BRUSH_DESC => {
set_brush_with_history(world, entity, value);
}
Some(CopiedComponent::StaticMeshRenderer(value))
if type_name == COMPONENT_STATIC_MESH_RENDERER =>
{
@@ -517,6 +529,7 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
fn reset_component(world: &mut World, entity: Entity, type_name: &str) {
match type_name {
COMPONENT_PRIMITIVE => set_primitive_with_history(world, entity, Primitive::default()),
COMPONENT_BRUSH_DESC => set_brush_with_history(world, entity, BrushDesc::default()),
COMPONENT_STATIC_MESH_RENDERER => {
set_static_mesh_renderer_with_history(world, entity, StaticMeshRenderer::default());
}
@@ -575,6 +588,10 @@ fn remove_registered_component(world: &mut World, entity: Entity, type_name: &st
entity_mut.remove::<Primitive>();
true
}
COMPONENT_BRUSH_DESC if before.brush.is_some() => {
entity_mut.remove::<BrushDesc>();
true
}
COMPONENT_STATIC_MESH_RENDERER if before.static_mesh_renderer.is_some() => {
entity_mut.remove::<StaticMeshRenderer>();
true
@@ -670,6 +687,7 @@ fn draw_authoring_component_by_type(
) {
match type_name {
COMPONENT_STATIC_MESH_RENDERER => static_mesh_renderer_ui(world, ui, entity),
COMPONENT_BRUSH_DESC => brush_editor_ui(world, ui, entity),
COMPONENT_PRIMITIVE => primitive_editor_ui(world, ui, entity),
COMPONENT_MATERIAL_DESC => material_editor_ui(world, ui, entity),
COMPONENT_LIGHT_DESC => light_editor_ui(world, ui, entity),
@@ -1090,6 +1108,7 @@ fn component_display_name(
fn component_present(world: &World, entity: Entity, type_name: &str) -> bool {
match type_name {
"shared::components::Primitive" => world.get::<Primitive>(entity).is_some(),
"shared::components::BrushDesc" => world.get::<BrushDesc>(entity).is_some(),
"shared::components::StaticMeshRenderer" => {
world.get::<StaticMeshRenderer>(entity).is_some()
}
@@ -1112,10 +1131,19 @@ fn component_present(world: &World, entity: Entity, type_name: &str) -> bool {
fn insert_registered_component(world: &mut World, entity: Entity, type_name: &str) {
match type_name {
"shared::components::Primitive" => insert_component(world, entity, |world, e| {
world.entity_mut(e).insert(Primitive::cuboid(Vec3::ONE));
world
.entity_mut(e)
.insert((shared::ActorKind::StaticMesh, Primitive::cuboid(Vec3::ONE)));
}),
"shared::components::BrushDesc" => insert_component(world, entity, |world, e| {
world
.entity_mut(e)
.insert((shared::ActorKind::Brush, BrushDesc::default()));
}),
"shared::components::StaticMeshRenderer" => insert_component(world, entity, |world, e| {
world.entity_mut(e).insert(StaticMeshRenderer::default());
world
.entity_mut(e)
.insert((shared::ActorKind::StaticMesh, StaticMeshRenderer::default()));
}),
"shared::components::MaterialDesc" => insert_component(world, entity, |world, e| {
world.entity_mut(e).insert(MaterialDesc::default());
@@ -1189,6 +1217,7 @@ fn diff_added(before: &EditorEntitySnapshot, after: &EditorEntitySnapshot) -> Ed
.primitive
.clone()
.filter(|_| before.primitive.is_none()),
brush: after.brush.clone().filter(|_| before.brush.is_none()),
static_mesh_renderer: after
.static_mesh_renderer
.clone()
@@ -2370,6 +2399,62 @@ pub fn material_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity)
}
}
fn brush_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
let Some(mut brush) = world.get::<BrushDesc>(entity).cloned() else {
return;
};
let original = brush.clone();
let mut changed = false;
let mut reset_cube = false;
let card = component_card_context(
world,
entity,
ComponentCardOptions::removable(COMPONENT_BRUSH_DESC, "Brush", icons::CUBE),
);
let card_response = component_card(ui, &card, |ui| {
property_row(ui, "Kind", |ui| {
egui::ComboBox::from_id_salt("brush_kind")
.selected_text(match brush.kind {
BrushKind::Additive => "Additive",
BrushKind::SubtractiveMarker => "Subtractive Marker",
})
.show_ui(ui, |ui| {
changed |= ui
.selectable_value(&mut brush.kind, BrushKind::Additive, "Additive")
.changed();
changed |= ui
.selectable_value(
&mut brush.kind,
BrushKind::SubtractiveMarker,
"Subtractive Marker",
)
.changed();
});
});
property_row(ui, "Faces", |ui| {
ui.label(format!("{}", brush.faces.len()));
});
property_row(ui, "Shadows", |ui| {
ui.horizontal_wrapped(|ui| {
changed |= ui.checkbox(&mut brush.cast_shadows, "Cast").changed();
changed |= ui.checkbox(&mut brush.receive_shadows, "Receive").changed();
});
});
if ui.button("Reset Cube Brush").clicked() {
reset_cube = true;
}
});
apply_component_card_response(world, entity, card_response);
if reset_cube {
brush = BrushDesc::default();
changed = true;
}
if changed && brush != original {
set_brush_with_history(world, entity, brush);
}
}
fn primitive_editor_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
let Some(mut primitive) = world.get::<Primitive>(entity).cloned() else {
return;
@@ -603,6 +603,10 @@ fn icon_for_actor_components(components: ActorIconComponents) -> ActorIconSpec {
};
match kind {
ActorKind::Brush => ActorIconSpec {
image: ActorIconImage::Mesh,
category: ActorIconCategory::Mesh,
},
ActorKind::StaticMesh => {
if components.has_primitive || components.has_static_mesh_renderer {
ActorIconSpec {
@@ -455,6 +455,7 @@ pub fn spawn_post_process_volume_at_camera(world: &mut World) {
name: Some("Post Process Volume".into()),
transform: Transform::from_translation(translation),
primitive: None,
brush: None,
static_mesh_renderer: None,
material: None,
material_override: None,
+56 -44
View File
@@ -1,3 +1,4 @@
use bevy::ecs::system::SystemParam;
use bevy::picking::mesh_picking::ray_cast::{MeshRayCast, MeshRayCastSettings, RayCastVisibility};
use bevy::picking::pointer::{PointerAction, PointerInput, PointerInteraction};
use bevy::prelude::*;
@@ -36,6 +37,15 @@ pub struct ViewportPickStack {
pub struct EditorSelectionPlugin;
#[derive(SystemParam)]
struct PickTargetQueries<'w, 's> {
level_objects: Query<'w, 's, Entity, (With<LevelObject>, Without<EditorOnly>)>,
proxies: Query<'w, 's, &'static EditorVisualizerProxy>,
icon_proxies: Query<'w, 's, &'static ActorIconProxy>,
parents: Query<'w, 's, &'static ChildOf>,
editor_only: Query<'w, 's, (), With<EditorOnly>>,
}
impl Plugin for EditorSelectionPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<SelectedEntity>()
@@ -88,9 +98,7 @@ fn handle_pick_events(
pointers: Query<&PointerInteraction>,
editor_cameras: Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
mut mesh_ray_cast: MeshRayCast,
level_objects: Query<Entity, (With<LevelObject>, Without<EditorOnly>)>,
proxies: Query<&EditorVisualizerProxy>,
icon_proxies: Query<&ActorIconProxy>,
pick_targets: PickTargetQueries,
keys: Res<ButtonInput<KeyCode>>,
buttons: Res<ButtonInput<MouseButton>>,
display: Res<ViewportDisplayMode>,
@@ -132,9 +140,7 @@ fn handle_pick_events(
&mut pick_stack,
&editor_cameras,
&mut mesh_ray_cast,
&level_objects,
&proxies,
&icon_proxies,
&pick_targets,
pointer_pos,
additive,
);
@@ -152,9 +158,11 @@ fn handle_pick_events(
let mut picked = None;
for interaction in &pointers {
if let Some(entity) = interaction.as_slice().iter().find_map(|(entity, _hit)| {
pick_target_for_entity(*entity, &level_objects, &proxies, &icon_proxies)
}) {
if let Some(entity) = interaction
.as_slice()
.iter()
.find_map(|(entity, _hit)| pick_target_for_entity(*entity, &pick_targets))
{
picked = Some(entity);
break;
}
@@ -167,9 +175,7 @@ fn handle_pick_events(
let hits = collect_viewport_pick_hits(
&editor_cameras,
&mut mesh_ray_cast,
&level_objects,
&proxies,
&icon_proxies,
&pick_targets,
ui_state.viewport_rect,
pointer_pos,
);
@@ -231,18 +237,14 @@ fn apply_viewport_pick(
pick_stack: &mut ViewportPickStack,
editor_cameras: &Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
mesh_ray_cast: &mut MeshRayCast,
level_objects: &Query<Entity, (With<LevelObject>, Without<EditorOnly>)>,
proxies: &Query<&EditorVisualizerProxy>,
icon_proxies: &Query<&ActorIconProxy>,
pick_targets: &PickTargetQueries,
pointer_pos: egui::Pos2,
additive: bool,
) {
let hits = collect_viewport_pick_hits(
editor_cameras,
mesh_ray_cast,
level_objects,
proxies,
icon_proxies,
pick_targets,
ui_state.viewport_rect,
pointer_pos,
);
@@ -277,9 +279,7 @@ fn apply_pick_result(
fn collect_viewport_pick_hits(
editor_cameras: &Query<(&Camera, &GlobalTransform), With<EditorCamera>>,
mesh_ray_cast: &mut MeshRayCast,
level_objects: &Query<Entity, (With<LevelObject>, Without<EditorOnly>)>,
proxies: &Query<&EditorVisualizerProxy>,
icon_proxies: &Query<&ActorIconProxy>,
pick_targets: &PickTargetQueries,
scene_rect: egui::Rect,
pointer_pos: egui::Pos2,
) -> Vec<Entity> {
@@ -298,15 +298,7 @@ fn collect_viewport_pick_hits(
let Some(ray) = scene_view_ray(camera, transform, pointer_pos, scene_rect) else {
return Vec::new();
};
let filter = |entity: Entity| {
level_objects.contains(entity)
|| proxies
.get(entity)
.is_ok_and(|proxy| level_objects.contains(proxy.target) || proxy.target != entity)
|| icon_proxies
.get(entity)
.is_ok_and(|proxy| level_objects.contains(proxy.target))
};
let filter = |entity: Entity| pick_target_for_entity(entity, pick_targets).is_some();
let settings = MeshRayCastSettings::default()
.with_visibility(RayCastVisibility::Any)
.with_filter(&filter)
@@ -317,13 +309,11 @@ fn collect_viewport_pick_hits(
let mut ordered = Vec::new();
for icon_priority in [true, false] {
for (entity, _) in hits {
let is_icon = icon_proxies.get(*entity).is_ok();
let is_icon = pick_targets.icon_proxies.get(*entity).is_ok();
if is_icon != icon_priority {
continue;
}
let Some(target) =
pick_target_for_entity(*entity, level_objects, proxies, icon_proxies)
else {
let Some(target) = pick_target_for_entity(*entity, pick_targets) else {
continue;
};
if seen.insert(target) {
@@ -334,19 +324,41 @@ fn collect_viewport_pick_hits(
ordered
}
fn pick_target_for_entity(
entity: Entity,
level_objects: &Query<Entity, (With<LevelObject>, Without<EditorOnly>)>,
proxies: &Query<&EditorVisualizerProxy>,
icon_proxies: &Query<&ActorIconProxy>,
) -> Option<Entity> {
if let Ok(proxy) = icon_proxies.get(entity) {
return level_objects.contains(proxy.target).then_some(proxy.target);
fn pick_target_for_entity(entity: Entity, pick_targets: &PickTargetQueries) -> Option<Entity> {
if let Ok(proxy) = pick_targets.icon_proxies.get(entity) {
return pick_targets
.level_objects
.contains(proxy.target)
.then_some(proxy.target);
}
if let Ok(proxy) = proxies.get(entity) {
if let Ok(proxy) = pick_targets.proxies.get(entity) {
return Some(proxy.target);
}
level_objects.contains(entity).then_some(entity)
if pick_targets.editor_only.contains(entity) {
return None;
}
if pick_targets.level_objects.contains(entity) {
return Some(entity);
}
let mut current = pick_targets
.parents
.get(entity)
.ok()
.map(|parent| parent.parent());
while let Some(parent) = current {
if pick_targets.editor_only.contains(parent) {
return None;
}
if pick_targets.level_objects.contains(parent) {
return Some(parent);
}
current = pick_targets
.parents
.get(parent)
.ok()
.map(|parent| parent.parent());
}
None
}
fn sync_gizmo_targets(