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

+74 -4
View File
@@ -1,5 +1,6 @@
//! Generates runtime render/physics/light components from reflectable authoring data.
mod brushes;
mod lights;
mod materials;
mod models;
@@ -16,6 +17,7 @@ pub use strip::{strip_hydrated, strip_hydrated_entity};
use bevy::ecs::system::SystemState;
use bevy::prelude::*;
use brushes::{hydrate_brushes, spawn_brush_mesh, HydratedBrushMesh};
use lights::{hydrate_lights, reconcile_missing_runtime_lights};
use materials::hydrate_materials;
pub use materials::material_from_desc;
@@ -30,10 +32,10 @@ use static_meshes::{
use visibility::{init_editor_visibility_on_spawn, sync_editor_visibility};
use crate::{
inspector_component_active, ColliderDesc, EditorVisibility, InspectorOrder, LevelObject,
MaterialDesc, MaterialOverride, Primitive, StaticMeshRenderer, COMPONENT_COLLIDER_DESC,
COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC, COMPONENT_PRIMITIVE,
COMPONENT_STATIC_MESH_RENDERER,
inspector_component_active, BrushDesc, ColliderDesc, EditorVisibility, InspectorOrder,
LevelObject, MaterialDesc, MaterialOverride, Primitive, StaticMeshRenderer,
COMPONENT_BRUSH_DESC, COMPONENT_COLLIDER_DESC, COMPONENT_LIGHT_DESC, COMPONENT_MATERIAL_DESC,
COMPONENT_PRIMITIVE, COMPONENT_STATIC_MESH_RENDERER,
};
/// Registers hydration systems in deterministic order.
@@ -46,6 +48,7 @@ impl Plugin for HydrationPlugin {
Update,
(
hydrate_primitives,
hydrate_brushes,
hydrate_materials,
hydrate_lights,
reconcile_missing_runtime_lights,
@@ -83,6 +86,45 @@ pub fn flush_level_object_hydration(world: &mut World) {
.map(|(entity, desc, _)| (entity, desc.clone()))
.collect();
let brush_entities_for_cleanup: Vec<Entity> = world
.query_filtered::<(Entity, &BrushDesc), With<LevelObject>>()
.iter(world)
.map(|(entity, _)| entity)
.collect();
let brush_targets: Vec<(
Entity,
BrushDesc,
Option<MaterialDesc>,
Option<ColliderDesc>,
Option<InspectorOrder>,
)> = world
.query_filtered::<(
Entity,
&BrushDesc,
Option<&MaterialDesc>,
Option<&ColliderDesc>,
Option<&InspectorOrder>,
), With<LevelObject>>()
.iter(world)
.map(|(entity, brush, material, collider, order)| {
(
entity,
brush.clone(),
material
.filter(|_| inspector_component_active(order, COMPONENT_MATERIAL_DESC))
.cloned(),
collider
.filter(|_| inspector_component_active(order, COMPONENT_COLLIDER_DESC))
.cloned(),
order.cloned(),
)
})
.filter(|(_, _, _, _, order)| {
inspector_component_active(order.as_ref(), COMPONENT_BRUSH_DESC)
})
.collect();
let static_mesh_entities_for_cleanup: Vec<Entity> = world
.query_filtered::<(Entity, &StaticMeshRenderer), With<LevelObject>>()
.iter(world)
@@ -138,6 +180,17 @@ pub fn flush_level_object_hydration(world: &mut World) {
}
}
let mut generated_brush_meshes = Vec::new();
for entity in &brush_entities_for_cleanup {
if let Some(children) = world.get::<Children>(*entity) {
for child in children.iter() {
if world.get::<HydratedBrushMesh>(child).is_some() {
generated_brush_meshes.push(child);
}
}
}
}
let visibility_targets: Vec<(Entity, EditorVisibility)> = world
.query_filtered::<(Entity, &EditorVisibility), With<LevelObject>>()
.iter(world)
@@ -187,6 +240,23 @@ pub fn flush_level_object_hydration(world: &mut World) {
commands.entity(entity).insert(MeshMaterial3d(material));
}
for child in generated_brush_meshes {
commands.entity(child).despawn();
}
for (entity, brush, material, collider, _) in &brush_targets {
spawn_brush_mesh(
&mut commands,
&asset_server,
&mut meshes,
&mut materials,
*entity,
brush,
material.as_ref(),
collider.as_ref(),
);
}
for child in generated_static_mesh_parts {
commands.entity(child).despawn();
}