Build renderer and material component foundations
Add dedicated skinned rendering, pose restoration, shared Material and Material Instance slots, registry-driven components, Surface/Solari integration, transactional schema upgrades, navigation authoring, documentation, and evaluation evidence.
This commit is contained in:
1 parent
0553a85220
commit
0798aa5d57
169 files changed
+27098
-3469
No files matched your search
@@ -5,7 +5,7 @@ mod transform;
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::{ActorId, ActorKind, ActorName, HydratedPrefabMember, LevelObject};
|
||||
use shared::{infer_actor_kind, ActorId, ActorKind, ActorName, HydratedPrefabMember, LevelObject};
|
||||
|
||||
use crate::ext::extensibility::ActorInspectorSectionRegistry;
|
||||
use crate::ui::inspector;
|
||||
@@ -29,9 +29,8 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
|
||||
return;
|
||||
}
|
||||
|
||||
let kind = entity_ref
|
||||
.get::<ActorKind>()
|
||||
.copied()
|
||||
let kind = infer_actor_kind(entity_ref)
|
||||
.or_else(|| entity_ref.get::<ActorKind>().copied())
|
||||
.unwrap_or(ActorKind::Empty);
|
||||
|
||||
egui::Frame::new()
|
||||
@@ -111,6 +110,7 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
|
||||
|
||||
match kind {
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::ImportedModel
|
||||
| ActorKind::Light
|
||||
@@ -123,7 +123,8 @@ pub fn draw_actor_inspector(world: &mut World, ui: &mut egui::Ui, entity: Entity
|
||||
| ActorKind::TeamSpawn
|
||||
| ActorKind::Objective
|
||||
| ActorKind::AudioSource
|
||||
| ActorKind::AudioListener => {
|
||||
| ActorKind::AudioListener
|
||||
| ActorKind::Navigation => {
|
||||
inspector::authoring_inspector_ui(world, ui, entity);
|
||||
}
|
||||
}
|
||||
@@ -139,7 +140,10 @@ 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::Brush | ActorKind::ImportedModel => icons::CUBE,
|
||||
ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::Brush
|
||||
| ActorKind::ImportedModel => icons::CUBE,
|
||||
ActorKind::Light => icons::LIGHTBULB,
|
||||
ActorKind::PrefabAnchor => icons::PACKAGE,
|
||||
ActorKind::PlayerSpawn => icons::PERSON_SIMPLE_RUN,
|
||||
@@ -149,6 +153,7 @@ fn actor_icon(kind: ActorKind) -> egui_phosphor_icons::Icon {
|
||||
ActorKind::TeamSpawn | ActorKind::Objective => icons::FLAG,
|
||||
ActorKind::AudioSource => icons::SPEAKER_HIGH,
|
||||
ActorKind::AudioListener => icons::HEADPHONES,
|
||||
ActorKind::Navigation => icons::PATH,
|
||||
ActorKind::Empty => icons::CIRCLE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
use shared::{
|
||||
AnimationClipRecord, AnimationControllerDesc, AnimationManifest, AnimationSkeletonRecord,
|
||||
AnimationStateDesc, EditorAssetRef, ModelRef, COMPONENT_ANIMATION_CONTROLLER_DESC,
|
||||
AnimationStateDesc, EditorAssetRef, SkinnedMeshRenderer, COMPONENT_ANIMATION_CONTROLLER_DESC,
|
||||
};
|
||||
|
||||
use crate::assets::animation::load_animation_manifest;
|
||||
@@ -656,8 +656,8 @@ fn manifest_summary(ui: &mut egui::Ui, manifest: &Result<AnimationManifest, Stri
|
||||
|
||||
fn manifest_for_actor(world: &World, entity: Entity) -> Result<AnimationManifest, String> {
|
||||
let model = world
|
||||
.get::<ModelRef>(entity)
|
||||
.ok_or_else(|| "actor has no ModelRef".to_string())?;
|
||||
.get::<SkinnedMeshRenderer>(entity)
|
||||
.ok_or_else(|| "actor has no SkinnedMeshRenderer".to_string())?;
|
||||
let registry = world
|
||||
.get_resource::<AssetRegistry>()
|
||||
.ok_or_else(|| "asset registry is unavailable".to_string())?;
|
||||
@@ -878,6 +878,7 @@ mod tests {
|
||||
schema_version: 1,
|
||||
asset_id: "model-id".into(),
|
||||
label: "Robot".into(),
|
||||
default_animation_clip_id: None,
|
||||
source: AnimationManifestSource {
|
||||
path: "assets/models/robot.glb".into(),
|
||||
format: "glb".into(),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3,7 +3,7 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use shared::MaterialAsset;
|
||||
use shared::{MaterialAsset, MaterialInstanceAsset};
|
||||
|
||||
use crate::asset_db::ImportSettings;
|
||||
use crate::assets::{AssetSelection, ASSETS_ROOT, BUILTINS_FOLDER};
|
||||
@@ -48,6 +48,7 @@ pub struct AssetBrowserUiState {
|
||||
pub(crate) pending_delete: Option<AssetDeleteRequest>,
|
||||
pub(crate) import_draft: Option<ImportSettingsDraft>,
|
||||
pub(crate) material_draft: Option<MaterialAssetDraft>,
|
||||
pub(crate) material_instance_draft: Option<MaterialInstanceAssetDraft>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -71,6 +72,13 @@ pub(crate) struct MaterialAssetDraft {
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct MaterialInstanceAssetDraft {
|
||||
pub(crate) path: String,
|
||||
pub(crate) asset: MaterialInstanceAsset,
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for AssetBrowserUiState {
|
||||
fn default() -> Self {
|
||||
let mut expanded_folders = HashSet::new();
|
||||
@@ -89,6 +97,7 @@ impl Default for AssetBrowserUiState {
|
||||
pending_delete: None,
|
||||
import_draft: None,
|
||||
material_draft: None,
|
||||
material_instance_draft: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
//! Editor-visible component registry for actor inspector palettes.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use bevy::ecs::reflect::ReflectComponent;
|
||||
use bevy::prelude::*;
|
||||
use bevy::reflect::std_traits::ReflectDefault;
|
||||
use bevy::reflect::GetTypeRegistration;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -9,6 +15,7 @@ pub enum EditorComponentCategory {
|
||||
Rendering,
|
||||
Animation,
|
||||
Audio,
|
||||
Navigation,
|
||||
Physics,
|
||||
Gameplay,
|
||||
Volumes,
|
||||
@@ -17,6 +24,8 @@ pub enum EditorComponentCategory {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EditorComponentDescriptor {
|
||||
/// Stable editor/protocol identity. This must not be a Rust type path.
|
||||
pub id: &'static str,
|
||||
pub type_name: &'static str,
|
||||
pub display_name: &'static str,
|
||||
pub category: EditorComponentCategory,
|
||||
@@ -35,6 +44,266 @@ pub struct EditorComponentDescriptor {
|
||||
#[derive(Resource, Debug, Clone)]
|
||||
pub struct EditorComponentRegistry {
|
||||
pub descriptors: Vec<EditorComponentDescriptor>,
|
||||
inspectors: HashMap<&'static str, ComponentInspectorFn>,
|
||||
}
|
||||
|
||||
pub type ComponentInspectorFn = fn(&mut World, &mut egui::Ui, Entity);
|
||||
|
||||
impl EditorComponentRegistry {
|
||||
/// Registers a statically linked component extension.
|
||||
///
|
||||
/// Stable ids and reflected type paths are both unique. Returning an error
|
||||
/// here prevents a game/editor extension from silently shadowing a built-in.
|
||||
pub fn register(&mut self, descriptor: EditorComponentDescriptor) -> Result<(), String> {
|
||||
if self
|
||||
.descriptors
|
||||
.iter()
|
||||
.any(|existing| existing.id == descriptor.id)
|
||||
{
|
||||
return Err(format!(
|
||||
"duplicate authoring component id `{}`",
|
||||
descriptor.id
|
||||
));
|
||||
}
|
||||
if self
|
||||
.descriptors
|
||||
.iter()
|
||||
.any(|existing| existing.type_name == descriptor.type_name)
|
||||
{
|
||||
return Err(format!(
|
||||
"component type `{}` is already registered",
|
||||
descriptor.type_name
|
||||
));
|
||||
}
|
||||
self.descriptors.push(descriptor);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn register_with_inspector(
|
||||
&mut self,
|
||||
descriptor: EditorComponentDescriptor,
|
||||
inspector: ComponentInspectorFn,
|
||||
) -> Result<(), String> {
|
||||
let type_name = descriptor.type_name;
|
||||
self.register(descriptor)?;
|
||||
self.inspectors.insert(type_name, inspector);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn inspector(&self, type_name: &str) -> Option<ComponentInspectorFn> {
|
||||
self.inspectors.get(type_name).copied()
|
||||
}
|
||||
|
||||
/// Hard lifecycle requirements keyed by stable component IDs. Keeping this
|
||||
/// lookup in the registry removes requirement policy from inspector code.
|
||||
pub fn required_component_ids(
|
||||
&self,
|
||||
descriptor: &EditorComponentDescriptor,
|
||||
) -> &'static [&'static str] {
|
||||
match descriptor.id {
|
||||
shared::AUTHORING_COMPONENT_ANIMATION_CONTROLLER => {
|
||||
&[shared::AUTHORING_COMPONENT_SKINNED_MESH_RENDERER]
|
||||
}
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn present_dependents(
|
||||
&self,
|
||||
world: &World,
|
||||
entity: Entity,
|
||||
required_id: &str,
|
||||
) -> Vec<&EditorComponentDescriptor> {
|
||||
self.descriptors
|
||||
.iter()
|
||||
.filter(|descriptor| {
|
||||
self.required_component_ids(descriptor)
|
||||
.contains(&required_id)
|
||||
&& self.component_present(world, entity, descriptor.type_name)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn by_id(&self, id: &str) -> Option<&EditorComponentDescriptor> {
|
||||
self.descriptors
|
||||
.iter()
|
||||
.find(|descriptor| descriptor.id == id)
|
||||
}
|
||||
|
||||
pub fn by_type_name(&self, type_name: &str) -> Option<&EditorComponentDescriptor> {
|
||||
self.descriptors
|
||||
.iter()
|
||||
.find(|descriptor| descriptor.type_name == type_name)
|
||||
}
|
||||
|
||||
pub fn stable_id_for_type<'a>(&self, type_name: &'a str) -> &'a str {
|
||||
self.by_type_name(type_name)
|
||||
.map(|descriptor| descriptor.id)
|
||||
.unwrap_or(type_name)
|
||||
}
|
||||
|
||||
pub fn ensure_component_order(&self, order: &mut shared::InspectorOrder, present: &[&str]) {
|
||||
for type_name in present {
|
||||
let component_id = self.stable_id_for_type(type_name);
|
||||
if !order
|
||||
.component_ids
|
||||
.iter()
|
||||
.any(|existing| existing == component_id)
|
||||
{
|
||||
order.component_ids.push(component_id.to_string());
|
||||
}
|
||||
}
|
||||
order.component_type_names.clear();
|
||||
}
|
||||
|
||||
pub fn ordered_components<'a>(
|
||||
&self,
|
||||
order: &shared::InspectorOrder,
|
||||
present: &[&'a str],
|
||||
) -> Vec<&'a str> {
|
||||
let mut ordered = Vec::new();
|
||||
for component_id in &order.component_ids {
|
||||
if let Some(type_name) = present
|
||||
.iter()
|
||||
.find(|type_name| self.stable_id_for_type(type_name) == component_id)
|
||||
{
|
||||
ordered.push(*type_name);
|
||||
}
|
||||
}
|
||||
for legacy_type_name in &order.component_type_names {
|
||||
if let Some(type_name) = present
|
||||
.iter()
|
||||
.find(|type_name| **type_name == legacy_type_name)
|
||||
{
|
||||
if !ordered.contains(type_name) {
|
||||
ordered.push(*type_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
for type_name in present {
|
||||
if !ordered.contains(type_name) {
|
||||
ordered.push(*type_name);
|
||||
}
|
||||
}
|
||||
ordered
|
||||
}
|
||||
|
||||
pub fn move_component(
|
||||
&self,
|
||||
order: &mut shared::InspectorOrder,
|
||||
type_name: &str,
|
||||
offset: isize,
|
||||
present: &[&str],
|
||||
) -> bool {
|
||||
self.ensure_component_order(order, present);
|
||||
let component_id = self.stable_id_for_type(type_name);
|
||||
let Some(index) = order
|
||||
.component_ids
|
||||
.iter()
|
||||
.position(|existing| existing == component_id)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
let target =
|
||||
(index as isize + offset).clamp(0, order.component_ids.len() as isize - 1) as usize;
|
||||
if index == target {
|
||||
return false;
|
||||
}
|
||||
let item = order.component_ids.remove(index);
|
||||
order.component_ids.insert(target, item);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn component_present(&self, world: &World, entity: Entity, type_name: &str) -> bool {
|
||||
let Ok(entity_ref) = world.get_entity(entity) else {
|
||||
return false;
|
||||
};
|
||||
let Some(app_registry) = world.get_resource::<AppTypeRegistry>() else {
|
||||
return false;
|
||||
};
|
||||
let type_registry = app_registry.read();
|
||||
type_registry
|
||||
.get_with_type_path(type_name)
|
||||
.and_then(|registration| registration.data::<ReflectComponent>())
|
||||
.is_some_and(|component| component.contains(entity_ref))
|
||||
}
|
||||
|
||||
/// Validates registry metadata against Bevy reflection before the first
|
||||
/// inspector frame. This is also the contract test used by extensions.
|
||||
pub fn validate(&self, world: &World) -> Result<(), Vec<String>> {
|
||||
let Some(app_registry) = world.get_resource::<AppTypeRegistry>() else {
|
||||
return Err(vec!["AppTypeRegistry is unavailable".to_string()]);
|
||||
};
|
||||
let type_registry = app_registry.read();
|
||||
let mut errors = Vec::new();
|
||||
let mut ids = HashSet::new();
|
||||
let mut type_names = HashSet::new();
|
||||
for descriptor in &self.descriptors {
|
||||
if descriptor.id.trim().is_empty() {
|
||||
errors.push(format!(
|
||||
"{} has an empty stable id",
|
||||
descriptor.display_name
|
||||
));
|
||||
} else if !ids.insert(descriptor.id) {
|
||||
errors.push(format!("duplicate stable id `{}`", descriptor.id));
|
||||
}
|
||||
if !type_names.insert(descriptor.type_name) {
|
||||
errors.push(format!(
|
||||
"duplicate reflected type `{}`",
|
||||
descriptor.type_name
|
||||
));
|
||||
}
|
||||
match type_registry.get_with_type_path(descriptor.type_name) {
|
||||
Some(registration) if registration.data::<ReflectComponent>().is_none() => errors
|
||||
.push(format!(
|
||||
"`{}` is registered without ReflectComponent",
|
||||
descriptor.type_name
|
||||
)),
|
||||
None => errors.push(format!(
|
||||
"reflected component `{}` is not registered",
|
||||
descriptor.type_name
|
||||
)),
|
||||
Some(registration)
|
||||
if descriptor.addable && registration.data::<ReflectDefault>().is_none() =>
|
||||
{
|
||||
errors.push(format!(
|
||||
"addable component `{}` has no reflected Default",
|
||||
descriptor.type_name
|
||||
));
|
||||
}
|
||||
Some(_) => {}
|
||||
}
|
||||
for relation in descriptor
|
||||
.recommended
|
||||
.iter()
|
||||
.chain(descriptor.conflicts_with.iter())
|
||||
{
|
||||
if !self
|
||||
.descriptors
|
||||
.iter()
|
||||
.any(|candidate| candidate.type_name == *relation)
|
||||
{
|
||||
errors.push(format!(
|
||||
"{} references unregistered component `{relation}`",
|
||||
descriptor.id
|
||||
));
|
||||
}
|
||||
}
|
||||
for required_id in self.required_component_ids(descriptor) {
|
||||
if self.by_id(required_id).is_none() {
|
||||
errors.push(format!(
|
||||
"{} requires unknown stable component id `{required_id}`",
|
||||
descriptor.id
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if errors.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(errors)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EditorComponentRegistry {
|
||||
@@ -42,6 +311,7 @@ impl Default for EditorComponentRegistry {
|
||||
Self {
|
||||
descriptors: vec![
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_STATIC_MESH_RENDERER,
|
||||
type_name: "shared::components::StaticMeshRenderer",
|
||||
display_name: "Static Mesh Renderer",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
@@ -56,11 +326,35 @@ impl Default for EditorComponentRegistry {
|
||||
conflicts_with: &[
|
||||
"shared::components::Primitive",
|
||||
"shared::components::BrushDesc",
|
||||
"shared::animation::SkinnedMeshRenderer",
|
||||
],
|
||||
hydration_effect:
|
||||
"Hydrates into generated mesh children and material bindings.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_SKINNED_MESH_RENDERER,
|
||||
type_name: "shared::animation::SkinnedMeshRenderer",
|
||||
display_name: "Skinned Mesh Renderer",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
addable: false,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::PERSON_SIMPLE_RUN.as_str(),
|
||||
description:
|
||||
"Renders rigged geometry while preserving its imported joints and skin bindings.",
|
||||
search_terms: &["mesh", "renderer", "skinned", "skeletal", "rigged", "joints"],
|
||||
recommended: &["shared::animation::AnimationControllerDesc"],
|
||||
conflicts_with: &[
|
||||
"shared::components::Primitive",
|
||||
"shared::components::BrushDesc",
|
||||
"shared::components::StaticMeshRenderer",
|
||||
],
|
||||
hydration_effect:
|
||||
"Hydrates through a dedicated scene root containing Bevy skinned meshes and joints.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_BRUSH,
|
||||
type_name: "shared::components::BrushDesc",
|
||||
display_name: "Brush",
|
||||
category: EditorComponentCategory::Authoring,
|
||||
@@ -75,10 +369,12 @@ impl Default for EditorComponentRegistry {
|
||||
conflicts_with: &[
|
||||
"shared::components::Primitive",
|
||||
"shared::components::StaticMeshRenderer",
|
||||
"shared::animation::SkinnedMeshRenderer",
|
||||
],
|
||||
hydration_effect: "Hydrates into generated brush mesh children.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_MATERIAL,
|
||||
type_name: "shared::components::MaterialDesc",
|
||||
display_name: "Authoring Material",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
@@ -94,6 +390,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into Bevy material assets for renderable actors.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_RIGID_BODY,
|
||||
type_name: "shared::components::RigidBodyDesc",
|
||||
display_name: "Rigid Body",
|
||||
category: EditorComponentCategory::Physics,
|
||||
@@ -109,6 +406,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into runtime Avian rigid-body state.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_COLLIDER,
|
||||
type_name: "shared::components::ColliderDesc",
|
||||
display_name: "Collider",
|
||||
category: EditorComponentCategory::Physics,
|
||||
@@ -124,6 +422,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into runtime Avian collider state.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_LIGHT,
|
||||
type_name: "shared::components::LightDesc",
|
||||
display_name: "Light",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
@@ -139,6 +438,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into runtime Bevy light components.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_ANIMATION_CONTROLLER,
|
||||
type_name: "shared::animation::AnimationControllerDesc",
|
||||
display_name: "Animation Controller",
|
||||
category: EditorComponentCategory::Animation,
|
||||
@@ -149,12 +449,13 @@ impl Default for EditorComponentRegistry {
|
||||
icon: icons::FILM_SLATE.as_str(),
|
||||
description: "Authors named animation states for an imported model rig.",
|
||||
search_terms: &["animation", "controller", "state", "clip", "skeleton", "rig"],
|
||||
recommended: &[],
|
||||
recommended: &["shared::animation::SkinnedMeshRenderer"],
|
||||
conflicts_with: &[],
|
||||
hydration_effect:
|
||||
"Hydrates into a Bevy animation graph and player bound to the imported model.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_AUDIO_SOURCE,
|
||||
type_name: "shared::components::AudioSourceDesc",
|
||||
display_name: "Audio Source",
|
||||
category: EditorComponentCategory::Audio,
|
||||
@@ -171,6 +472,7 @@ impl Default for EditorComponentRegistry {
|
||||
"Hydrates into runtime Bevy audio voices with bus and attenuation control.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_AUDIO_LISTENER,
|
||||
type_name: "shared::components::AudioListenerDesc",
|
||||
display_name: "Audio Listener",
|
||||
category: EditorComponentCategory::Audio,
|
||||
@@ -187,6 +489,7 @@ impl Default for EditorComponentRegistry {
|
||||
"The highest-priority enabled listener becomes the runtime listener.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_PRIMITIVE,
|
||||
type_name: "shared::components::Primitive",
|
||||
display_name: "Primitive",
|
||||
category: EditorComponentCategory::Authoring,
|
||||
@@ -201,11 +504,13 @@ impl Default for EditorComponentRegistry {
|
||||
conflicts_with: &[
|
||||
"shared::components::StaticMeshRenderer",
|
||||
"shared::components::BrushDesc",
|
||||
"shared::animation::SkinnedMeshRenderer",
|
||||
],
|
||||
hydration_effect:
|
||||
"Hydrates into generated primitive render and collision data.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_PLAYER_SPAWN,
|
||||
type_name: "shared::components::PlayerSpawn",
|
||||
display_name: "Player Spawn",
|
||||
category: EditorComponentCategory::Gameplay,
|
||||
@@ -222,6 +527,7 @@ impl Default for EditorComponentRegistry {
|
||||
"Used by PIE/session startup; no saved runtime player is created.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_WEAPON_SPAWN,
|
||||
type_name: "shared::components::WeaponSpawn",
|
||||
display_name: "Weapon Spawn",
|
||||
category: EditorComponentCategory::Gameplay,
|
||||
@@ -237,6 +543,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into gameplay spawn metadata.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_TRIGGER_VOLUME,
|
||||
type_name: "shared::components::TriggerVolume",
|
||||
display_name: "Trigger Volume",
|
||||
category: EditorComponentCategory::Volumes,
|
||||
@@ -252,6 +559,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into gameplay trigger queries and visualizers.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_TEAM_SPAWN,
|
||||
type_name: "shared::components::TeamSpawn",
|
||||
display_name: "Team Spawn",
|
||||
category: EditorComponentCategory::Gameplay,
|
||||
@@ -267,6 +575,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into gameplay spawn metadata.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_OBJECTIVE,
|
||||
type_name: "shared::components::ObjectiveMarker",
|
||||
display_name: "Objective Marker",
|
||||
category: EditorComponentCategory::Gameplay,
|
||||
@@ -282,6 +591,7 @@ impl Default for EditorComponentRegistry {
|
||||
hydration_effect: "Hydrates into gameplay objective metadata.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_POST_PROCESS_VOLUME,
|
||||
type_name: "shared::components::PostProcessVolumeDesc",
|
||||
display_name: "Post-Process Volume",
|
||||
category: EditorComponentCategory::Volumes,
|
||||
@@ -298,6 +608,215 @@ impl Default for EditorComponentRegistry {
|
||||
"Affects active camera rendering when the camera is inside the volume.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_NAVIGATION_BOUNDS,
|
||||
type_name: "shared::navigation::NavigationBounds",
|
||||
display_name: "Navigation Bounds",
|
||||
category: EditorComponentCategory::Navigation,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::PATH.as_str(),
|
||||
description: "Defines the world region and agent profile for a navigation bake.",
|
||||
search_terms: &["navigation", "navmesh", "bounds", "agent", "bake"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[
|
||||
"shared::navigation::NavigationObstacle",
|
||||
"shared::navigation::NavigationArea",
|
||||
"shared::navigation::NavigationLink",
|
||||
],
|
||||
hydration_effect: "Feeds the generated navigation artifact; no render component is hydrated.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_NAVIGATION_OBSTACLE,
|
||||
type_name: "shared::navigation::NavigationObstacle",
|
||||
display_name: "Navigation Obstacle",
|
||||
category: EditorComponentCategory::Navigation,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::SELECTION_SLASH.as_str(),
|
||||
description: "Carves an axis-aligned blocked volume from overlapping bakes.",
|
||||
search_terms: &["navigation", "navmesh", "obstacle", "block", "carve"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[
|
||||
"shared::navigation::NavigationBounds",
|
||||
"shared::navigation::NavigationArea",
|
||||
"shared::navigation::NavigationLink",
|
||||
],
|
||||
hydration_effect: "Contributes a deterministic unwalkable volume during bake.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_NAVIGATION_AREA,
|
||||
type_name: "shared::navigation::NavigationArea",
|
||||
display_name: "Navigation Area",
|
||||
category: EditorComponentCategory::Navigation,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::POLYGON.as_str(),
|
||||
description: "Labels a walkable or blocked navigation area and traversal cost.",
|
||||
search_terms: &["navigation", "navmesh", "area", "cost", "walkable"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[
|
||||
"shared::navigation::NavigationBounds",
|
||||
"shared::navigation::NavigationObstacle",
|
||||
"shared::navigation::NavigationLink",
|
||||
],
|
||||
hydration_effect: "Stores area metadata and blocked-volume contribution in the bake artifact.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_NAVIGATION_LINK,
|
||||
type_name: "shared::navigation::NavigationLink",
|
||||
display_name: "Navigation Link",
|
||||
category: EditorComponentCategory::Navigation,
|
||||
addable: true,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::LINK.as_str(),
|
||||
description: "Connects otherwise isolated navigation regions with an explicit traversal.",
|
||||
search_terms: &["navigation", "navmesh", "link", "jump", "door", "ladder"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[
|
||||
"shared::navigation::NavigationBounds",
|
||||
"shared::navigation::NavigationObstacle",
|
||||
"shared::navigation::NavigationArea",
|
||||
],
|
||||
hydration_effect: "Adds a validated directed or bidirectional runtime path connection.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: shared::AUTHORING_COMPONENT_LEGACY_PHYSICS_BODY,
|
||||
type_name: "shared::components::PhysicsBody",
|
||||
display_name: "Legacy Physics Body",
|
||||
category: EditorComponentCategory::Physics,
|
||||
addable: false,
|
||||
removable: true,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::SPHERE.as_str(),
|
||||
description: "Legacy combined physics authoring retained for scene compatibility.",
|
||||
search_terms: &["legacy", "physics", "body"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Hydrates through the compatibility physics path.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "prefab.instance",
|
||||
type_name: "shared::components::PrefabInstance",
|
||||
display_name: "Prefab Instance",
|
||||
category: EditorComponentCategory::Authoring,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::PACKAGE.as_str(),
|
||||
description: "Stores a linked prefab instance and its overrides.",
|
||||
search_terms: &["prefab", "instance", "link"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Hydrates linked prefab members beneath this anchor.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "prefab.reference",
|
||||
type_name: "shared::components::PrefabRef",
|
||||
display_name: "Prefab Reference",
|
||||
category: EditorComponentCategory::Authoring,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::PACKAGE.as_str(),
|
||||
description: "Stable source reference owned by a prefab anchor.",
|
||||
search_terms: &["prefab", "reference"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Resolves the prefab source asset.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "render.imported_model",
|
||||
type_name: "shared::components::ModelRef",
|
||||
display_name: "Imported Model Reference",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::CUBE_TRANSPARENT.as_str(),
|
||||
description: "Legacy full-scene imported model reference.",
|
||||
search_terms: &["model", "imported", "scene"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Hydrates the referenced imported model scene.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "render.material_override_legacy",
|
||||
type_name: "shared::components::MaterialOverride",
|
||||
display_name: "Legacy Material Override",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::PALETTE.as_str(),
|
||||
description: "Legacy renderer material slot overrides retained for migration.",
|
||||
search_terms: &["material", "override", "legacy"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Applies compatibility material overrides.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "render.project_sun",
|
||||
type_name: "shared::components::ProjectSun",
|
||||
display_name: "Project Sun",
|
||||
category: EditorComponentCategory::Rendering,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: true,
|
||||
hidden: false,
|
||||
icon: icons::SUN.as_str(),
|
||||
description: "Marks the scene light that overrides the project sun.",
|
||||
search_terms: &["sun", "directional", "project"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Selects the authored directional project light.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "core.actor_kind",
|
||||
type_name: "shared::components::ActorKind",
|
||||
display_name: "Actor Kind Hint",
|
||||
category: EditorComponentCategory::Editor,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::TAG.as_str(),
|
||||
description: "Compatibility and presentation hint derived from primary components.",
|
||||
search_terms: &["actor", "kind", "hint"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "No runtime effect; validation uses component composition.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "editor.component_states",
|
||||
type_name: "shared::components::AuthoringComponentStates",
|
||||
display_name: "Authoring Component States",
|
||||
category: EditorComponentCategory::Editor,
|
||||
addable: false,
|
||||
removable: false,
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::TOGGLE_LEFT.as_str(),
|
||||
description: "Stores persisted component enable state independently of inspector layout.",
|
||||
search_terms: &["editor", "active", "enabled"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect: "Controls whether opted-in authoring components hydrate.",
|
||||
},
|
||||
EditorComponentDescriptor {
|
||||
id: "editor.inspector_order",
|
||||
type_name: "shared::components::InspectorOrder",
|
||||
display_name: "Inspector Order",
|
||||
category: EditorComponentCategory::Editor,
|
||||
@@ -306,14 +825,62 @@ impl Default for EditorComponentRegistry {
|
||||
reorderable: false,
|
||||
hidden: true,
|
||||
icon: icons::LIST_BULLETS.as_str(),
|
||||
description: "Stores editor-only component ordering and active-state metadata.",
|
||||
description: "Stores editor-only component card ordering.",
|
||||
search_terms: &["editor", "order"],
|
||||
recommended: &[],
|
||||
conflicts_with: &[],
|
||||
hydration_effect:
|
||||
"Controls editor presentation and authoring component active state.",
|
||||
hydration_effect: "Controls editor presentation only; runtime active state is stored separately.",
|
||||
},
|
||||
],
|
||||
inspectors: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers one statically linked game/editor component with reflection,
|
||||
/// lifecycle metadata, and its editor inspector in a single call.
|
||||
pub fn register_authoring_component<T>(
|
||||
app: &mut App,
|
||||
descriptor: EditorComponentDescriptor,
|
||||
inspector: ComponentInspectorFn,
|
||||
) -> Result<(), String>
|
||||
where
|
||||
T: Component + Reflect + GetTypeRegistration,
|
||||
{
|
||||
app.register_type::<T>();
|
||||
if !app.world().contains_resource::<EditorComponentRegistry>() {
|
||||
app.init_resource::<EditorComponentRegistry>();
|
||||
}
|
||||
app.world_mut()
|
||||
.resource_mut::<EditorComponentRegistry>()
|
||||
.register_with_inspector(descriptor, inspector)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn built_in_registry_is_unique_and_reflectable() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(shared::SharedTypesPlugin)
|
||||
.init_resource::<EditorComponentRegistry>();
|
||||
|
||||
app.world()
|
||||
.resource::<EditorComponentRegistry>()
|
||||
.validate(app.world())
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn static_extensions_cannot_shadow_stable_ids_or_types() {
|
||||
let mut registry = EditorComponentRegistry::default();
|
||||
let mut duplicate = registry.descriptors[0].clone();
|
||||
duplicate.type_name = "game::editor_ext::StaticFixture";
|
||||
assert!(registry.register(duplicate).is_err());
|
||||
|
||||
let mut duplicate = registry.descriptors[0].clone();
|
||||
duplicate.id = "game.static_fixture";
|
||||
assert!(registry.register(duplicate).is_err());
|
||||
}
|
||||
}
|
||||
@@ -91,6 +91,7 @@ pub fn light_snapshot(name: &str, translation: Vec3) -> EditorEntitySnapshot {
|
||||
primitive: None,
|
||||
brush: None,
|
||||
static_mesh_renderer: None,
|
||||
skinned_mesh_renderer: None,
|
||||
material: None,
|
||||
material_override: None,
|
||||
rigid_body: None,
|
||||
@@ -109,8 +110,18 @@ pub fn light_snapshot(name: &str, translation: Vec3) -> EditorEntitySnapshot {
|
||||
post_process_volume: None,
|
||||
team_spawn: None,
|
||||
objective: None,
|
||||
|
||||
navigation_bounds: None,
|
||||
|
||||
navigation_obstacle: None,
|
||||
|
||||
navigation_area: None,
|
||||
|
||||
navigation_link: None,
|
||||
hierarchy_sibling_index: 0,
|
||||
editor_visibility: shared::EditorVisibility::default(),
|
||||
inspector_order: None,
|
||||
component_states: None,
|
||||
children: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -142,6 +153,7 @@ pub fn ensure_player_spawn_for_edit(world: &mut World) -> Entity {
|
||||
primitive: None,
|
||||
brush: None,
|
||||
static_mesh_renderer: None,
|
||||
skinned_mesh_renderer: None,
|
||||
material: None,
|
||||
material_override: None,
|
||||
rigid_body: None,
|
||||
@@ -160,8 +172,18 @@ pub fn ensure_player_spawn_for_edit(world: &mut World) -> Entity {
|
||||
post_process_volume: None,
|
||||
team_spawn: None,
|
||||
objective: None,
|
||||
|
||||
navigation_bounds: None,
|
||||
|
||||
navigation_obstacle: None,
|
||||
|
||||
navigation_area: None,
|
||||
|
||||
navigation_link: None,
|
||||
hierarchy_sibling_index: 0,
|
||||
editor_visibility: shared::EditorVisibility::default(),
|
||||
inspector_order: None,
|
||||
component_states: None,
|
||||
children: Vec::new(),
|
||||
},
|
||||
)
|
||||
@@ -233,6 +255,7 @@ pub fn create_scene_sun_override_from_project_settings(world: &mut World) -> Ent
|
||||
primitive: None,
|
||||
brush: None,
|
||||
static_mesh_renderer: None,
|
||||
skinned_mesh_renderer: None,
|
||||
material: None,
|
||||
material_override: None,
|
||||
rigid_body: None,
|
||||
@@ -251,8 +274,18 @@ pub fn create_scene_sun_override_from_project_settings(world: &mut World) -> Ent
|
||||
post_process_volume: None,
|
||||
team_spawn: None,
|
||||
objective: None,
|
||||
|
||||
navigation_bounds: None,
|
||||
|
||||
navigation_obstacle: None,
|
||||
|
||||
navigation_area: None,
|
||||
|
||||
navigation_link: None,
|
||||
hierarchy_sibling_index: 0,
|
||||
editor_visibility: shared::EditorVisibility::default(),
|
||||
inspector_order: None,
|
||||
component_states: None,
|
||||
children: Vec::new(),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ use bevy::prelude::*;
|
||||
use shared::{
|
||||
ActorKind, AuthoringLightKind, EditorVisibility, HierarchySiblingIndex, HydratedPrefabMember,
|
||||
LevelObject, LightDesc, ModelRef, PhysicsBody, PlayerSpawn, PrefabInstance,
|
||||
SkinnedMeshRenderer,
|
||||
};
|
||||
|
||||
use super::helpers::{entity_name, is_level_object, HierarchyNodeKind};
|
||||
@@ -203,7 +204,10 @@ fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
|
||||
.copied()
|
||||
.map(|kind| match kind {
|
||||
ActorKind::Empty => 0,
|
||||
ActorKind::Brush | ActorKind::StaticMesh | ActorKind::ImportedModel => 1,
|
||||
ActorKind::Brush
|
||||
| ActorKind::StaticMesh
|
||||
| ActorKind::SkinnedMesh
|
||||
| ActorKind::ImportedModel => 1,
|
||||
ActorKind::Light => 2,
|
||||
ActorKind::AudioSource | ActorKind::AudioListener => 3,
|
||||
ActorKind::PrefabAnchor => 3,
|
||||
@@ -213,6 +217,7 @@ fn actor_kind_sort_key(world: &World, entity: Entity) -> u8 {
|
||||
ActorKind::PostProcessVolume => 6,
|
||||
ActorKind::TeamSpawn => 7,
|
||||
ActorKind::Objective => 8,
|
||||
ActorKind::Navigation => 6,
|
||||
})
|
||||
.unwrap_or(9)
|
||||
}
|
||||
@@ -464,6 +469,7 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
ActorKind::Empty => icons::FOLDER.as_str(),
|
||||
ActorKind::Brush => icons::CUBE.as_str(),
|
||||
ActorKind::StaticMesh => icons::CUBE.as_str(),
|
||||
ActorKind::SkinnedMesh => icons::PERSON_SIMPLE_RUN.as_str(),
|
||||
ActorKind::ImportedModel => icons::CUBE_TRANSPARENT.as_str(),
|
||||
ActorKind::Light => icons::LIGHTBULB.as_str(),
|
||||
ActorKind::AudioSource => icons::SPEAKER_HIGH.as_str(),
|
||||
@@ -475,6 +481,7 @@ pub fn actor_kind_icon(kind: ActorKind) -> &'static str {
|
||||
ActorKind::PostProcessVolume => icons::CAMERA.as_str(),
|
||||
ActorKind::TeamSpawn => icons::FLAG.as_str(),
|
||||
ActorKind::Objective => icons::TARGET.as_str(),
|
||||
ActorKind::Navigation => icons::PATH.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,6 +541,10 @@ pub fn entity_matches_filter(world: &World, entity: Entity, filter_lower: &str)
|
||||
.is_some()
|
||||
.then_some("spawn"),
|
||||
world.get::<ModelRef>(entity).is_some().then_some("model"),
|
||||
world
|
||||
.get::<SkinnedMeshRenderer>(entity)
|
||||
.is_some()
|
||||
.then_some("skinned model"),
|
||||
world
|
||||
.get::<PhysicsBody>(entity)
|
||||
.is_some()
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -158,6 +158,44 @@ pub fn top_menu_bar(
|
||||
crate::rendering_diagnostics::spawn_post_process_volume_at_camera(world);
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
ui.menu_button("Navigation", |ui| {
|
||||
use super::navigation_inspector::{
|
||||
spawn_navigation_actor, NavigationActorType,
|
||||
};
|
||||
for (label, actor_type) in [
|
||||
("Create Bounds", NavigationActorType::Bounds),
|
||||
("Create Obstacle", NavigationActorType::Obstacle),
|
||||
("Create Area", NavigationActorType::Area),
|
||||
("Create Link", NavigationActorType::Link),
|
||||
] {
|
||||
if menu_item(ui, label, None, true).clicked() {
|
||||
spawn_navigation_actor(world, actor_type);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
let selected_bounds =
|
||||
selected.as_slice().iter().copied().find(|entity| {
|
||||
world.get::<shared::NavigationBounds>(*entity).is_some()
|
||||
});
|
||||
if menu_item(ui, "Bake Selected Bounds", None, selected_bounds.is_some())
|
||||
.clicked()
|
||||
{
|
||||
if let Some(entity) = selected_bounds {
|
||||
super::navigation_inspector::bake_bounds(world, entity);
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
if menu_item(ui, "Test Selected Path", None, selected_bounds.is_some())
|
||||
.clicked()
|
||||
{
|
||||
if let Some(entity) = selected_bounds {
|
||||
super::navigation_inspector::query_preview(world, entity);
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ui.menu_button("Build", |ui| {
|
||||
|
||||
@@ -3,7 +3,7 @@ mod animation_inspector;
|
||||
mod asset_browser;
|
||||
mod audio_inspector;
|
||||
mod build;
|
||||
mod component_registry;
|
||||
pub mod component_registry;
|
||||
mod diagnostics;
|
||||
mod dock_tabs;
|
||||
mod fonts;
|
||||
@@ -14,6 +14,7 @@ pub mod hierarchy_state;
|
||||
pub(crate) mod inspector;
|
||||
mod layout;
|
||||
mod menu;
|
||||
pub(crate) mod navigation_inspector;
|
||||
mod play_controls;
|
||||
mod post_process_volume_ui;
|
||||
mod scene_tabs;
|
||||
@@ -294,6 +295,7 @@ impl Plugin for EditorUiPlugin {
|
||||
.init_resource::<inspector::InspectorClipboard>()
|
||||
.init_resource::<inspector::InspectorPanelState>()
|
||||
.init_resource::<animation_inspector::AnimationInspectorState>()
|
||||
.init_resource::<navigation_inspector::NavigationEditorState>()
|
||||
.init_resource::<ViewportUiState>()
|
||||
.init_resource::<LayoutSaveTimer>()
|
||||
.add_systems(
|
||||
@@ -301,6 +303,7 @@ impl Plugin for EditorUiPlugin {
|
||||
init_hierarchy_panel_from_prefs
|
||||
.after(crate::project_io::load_user_preferences_on_startup),
|
||||
)
|
||||
.add_systems(Startup, validate_editor_component_registry)
|
||||
.add_systems(
|
||||
Startup,
|
||||
apply_ui_state_from_prefs
|
||||
@@ -312,11 +315,25 @@ impl Plugin for EditorUiPlugin {
|
||||
(
|
||||
hierarchy_state::tick_hierarchy_prefs_save,
|
||||
build::tick_build_job,
|
||||
navigation_inspector::sync_navigation_state,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_editor_component_registry(world: &mut World) {
|
||||
let errors = world
|
||||
.resource::<component_registry::EditorComponentRegistry>()
|
||||
.validate(world)
|
||||
.err();
|
||||
if let Some(errors) = errors {
|
||||
panic!(
|
||||
"invalid authoring component registry:\n{}",
|
||||
errors.join("\n")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_ui_state_from_prefs(mut ui_state: ResMut<UiState>, prefs: Res<UserPreferences>) {
|
||||
*ui_state = UiState::from_prefs(&prefs);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,765 @@
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_egui::egui;
|
||||
use egui_phosphor_icons::icons;
|
||||
use scene::navigation::{
|
||||
aabb_overlaps, bake_navigation, geometry_overlaps_bounds, navigation_geometry_from_parts,
|
||||
navigation_source_fingerprint, point_in_aabb, read_navigation_artifact,
|
||||
write_navigation_artifact, NavigationAreaInput, NavigationBakeArtifact, NavigationBakeInput,
|
||||
NavigationLinkInput, NavigationVolumeInput,
|
||||
};
|
||||
use shared::{
|
||||
ActorId, BrushDesc, NavigationArea, NavigationBounds, NavigationLink, NavigationObstacle,
|
||||
Primitive, COMPONENT_NAVIGATION_AREA, COMPONENT_NAVIGATION_BOUNDS, COMPONENT_NAVIGATION_LINK,
|
||||
COMPONENT_NAVIGATION_OBSTACLE,
|
||||
};
|
||||
|
||||
use crate::history::{set_navigation_with_history, NavigationComponentState};
|
||||
use crate::project_io::ProjectWorkspace;
|
||||
use crate::scene_io::SceneIo;
|
||||
use crate::ui::inspector::{
|
||||
apply_component_card_response, component_card, component_card_context, property_row,
|
||||
ComponentCardOptions,
|
||||
};
|
||||
use crate::ui::theme::{ERROR, SUCCESS, TEXT_DIM, WARNING};
|
||||
use crate::viewport::{editor_spawn_ground_position, snap_translation, ViewportSettings};
|
||||
|
||||
#[derive(Resource, Debug, Clone)]
|
||||
pub struct NavigationEditorState {
|
||||
pub bounds_entity: Option<Entity>,
|
||||
pub artifact: Option<NavigationBakeArtifact>,
|
||||
pub preview_start: Vec3,
|
||||
pub preview_end: Vec3,
|
||||
pub preview_path: Vec<Vec3>,
|
||||
pub status: String,
|
||||
pub error: bool,
|
||||
pub show_mesh: bool,
|
||||
observed_fingerprint: Option<String>,
|
||||
auto_bake_attempt: Option<String>,
|
||||
debounce_elapsed: f32,
|
||||
}
|
||||
|
||||
impl Default for NavigationEditorState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bounds_entity: None,
|
||||
artifact: None,
|
||||
preview_start: Vec3::new(-4.0, 0.0, 0.0),
|
||||
preview_end: Vec3::new(4.0, 0.0, 0.0),
|
||||
preview_path: Vec::new(),
|
||||
status: "Not baked".into(),
|
||||
error: false,
|
||||
show_mesh: true,
|
||||
observed_fingerprint: None,
|
||||
auto_bake_attempt: None,
|
||||
debounce_elapsed: 0.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn navigation_bounds_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut bounds) = world.get::<NavigationBounds>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = bounds.clone();
|
||||
let mut preview_start = world.resource::<NavigationEditorState>().preview_start;
|
||||
let mut preview_end = world.resource::<NavigationEditorState>().preview_end;
|
||||
let mut show_mesh = world.resource::<NavigationEditorState>().show_mesh;
|
||||
let status = world.resource::<NavigationEditorState>().status.clone();
|
||||
let status_error = world.resource::<NavigationEditorState>().error;
|
||||
let current = build_input(world, entity, &bounds).ok();
|
||||
let stale = current.as_ref().is_some_and(|input| {
|
||||
world
|
||||
.resource::<NavigationEditorState>()
|
||||
.artifact
|
||||
.as_ref()
|
||||
.is_none_or(|artifact| artifact.is_stale_for(input))
|
||||
});
|
||||
let mut bake = false;
|
||||
let mut preview = false;
|
||||
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(
|
||||
COMPONENT_NAVIGATION_BOUNDS,
|
||||
"Navigation Bounds",
|
||||
icons::PATH,
|
||||
),
|
||||
);
|
||||
let response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Half extents", |ui| {
|
||||
vec3_editor(ui, &mut bounds.half_extents, 0.1)
|
||||
});
|
||||
property_row(ui, "Agent ID", |ui| {
|
||||
ui.text_edit_singleline(&mut bounds.agent.id)
|
||||
});
|
||||
property_row(ui, "Radius / height", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::DragValue::new(&mut bounds.agent.radius).speed(0.01));
|
||||
ui.add(egui::DragValue::new(&mut bounds.agent.height).speed(0.01))
|
||||
})
|
||||
.response
|
||||
});
|
||||
property_row(ui, "Climb / slope", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::DragValue::new(&mut bounds.agent.max_climb).speed(0.01));
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut bounds.agent.max_slope_deg)
|
||||
.speed(0.25)
|
||||
.suffix(" deg"),
|
||||
)
|
||||
})
|
||||
.response
|
||||
});
|
||||
property_row(ui, "Voxel detail", |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut bounds.agent.cell_size_fraction)
|
||||
.speed(0.1)
|
||||
.range(1.0..=12.0),
|
||||
);
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut bounds.agent.cell_height_fraction)
|
||||
.speed(0.1)
|
||||
.range(1.0..=24.0),
|
||||
)
|
||||
})
|
||||
.response
|
||||
});
|
||||
property_row(ui, "Artifact", |ui| {
|
||||
ui.text_edit_singleline(&mut bounds.artifact_path)
|
||||
});
|
||||
property_row(ui, "Auto bake", |ui| {
|
||||
ui.checkbox(&mut bounds.auto_bake, "Debounced")
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
ui.horizontal(|ui| {
|
||||
bake = ui
|
||||
.button(format!("{} Bake", icons::HAMMER.as_str()))
|
||||
.on_hover_text("Bake deterministic navigation artifact")
|
||||
.clicked();
|
||||
preview = ui
|
||||
.add_enabled(
|
||||
!stale,
|
||||
egui::Button::new(format!("{} Test Path", icons::PATH.as_str())),
|
||||
)
|
||||
.on_hover_text("Query the baked artifact using the game runtime API")
|
||||
.clicked();
|
||||
ui.checkbox(&mut show_mesh, "Overlay");
|
||||
});
|
||||
let status_color = if status_error {
|
||||
ERROR
|
||||
} else if stale {
|
||||
WARNING
|
||||
} else {
|
||||
SUCCESS
|
||||
};
|
||||
ui.colored_label(
|
||||
status_color,
|
||||
if stale {
|
||||
format!("Stale: {status}")
|
||||
} else {
|
||||
status.clone()
|
||||
},
|
||||
);
|
||||
|
||||
property_row(ui, "Path start", |ui| {
|
||||
vec3_editor(ui, &mut preview_start, 0.1)
|
||||
});
|
||||
property_row(ui, "Path end", |ui| vec3_editor(ui, &mut preview_end, 0.1));
|
||||
if let Some(input) = current.as_ref() {
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} obstacles {} areas {} links",
|
||||
input.obstacles.len(),
|
||||
input.areas.len(),
|
||||
input.links.len()
|
||||
))
|
||||
.small()
|
||||
.color(TEXT_DIM),
|
||||
);
|
||||
}
|
||||
});
|
||||
apply_component_card_response(world, entity, response);
|
||||
|
||||
if bounds != original {
|
||||
set_navigation_with_history(
|
||||
world,
|
||||
entity,
|
||||
NavigationComponentState {
|
||||
bounds: Some(bounds.clone()),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
{
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
state.preview_start = preview_start;
|
||||
state.preview_end = preview_end;
|
||||
state.show_mesh = show_mesh;
|
||||
}
|
||||
if bake {
|
||||
bake_bounds(world, entity);
|
||||
}
|
||||
if preview {
|
||||
query_preview(world, entity);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn navigation_obstacle_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut value) = world.get::<NavigationObstacle>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = value.clone();
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(
|
||||
COMPONENT_NAVIGATION_OBSTACLE,
|
||||
"Navigation Obstacle",
|
||||
icons::SELECTION_SLASH,
|
||||
),
|
||||
);
|
||||
let response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Half extents", |ui| {
|
||||
vec3_editor(ui, &mut value.half_extents, 0.05)
|
||||
});
|
||||
property_row(ui, "Runtime", |ui| {
|
||||
ui.checkbox(&mut value.dynamic, "Dynamic obstacle")
|
||||
});
|
||||
if value.dynamic {
|
||||
ui.colored_label(
|
||||
WARNING,
|
||||
"Dynamic carving is not baked in navigation v1; this volume remains a static bake input.",
|
||||
);
|
||||
}
|
||||
});
|
||||
apply_component_card_response(world, entity, response);
|
||||
if value != original {
|
||||
set_navigation_with_history(
|
||||
world,
|
||||
entity,
|
||||
NavigationComponentState {
|
||||
obstacle: Some(value),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn navigation_area_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut value) = world.get::<NavigationArea>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = value.clone();
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(
|
||||
COMPONENT_NAVIGATION_AREA,
|
||||
"Navigation Area",
|
||||
icons::POLYGON,
|
||||
),
|
||||
);
|
||||
let response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Area ID", |ui| ui.text_edit_singleline(&mut value.id));
|
||||
property_row(ui, "Half extents", |ui| {
|
||||
vec3_editor(ui, &mut value.half_extents, 0.05)
|
||||
});
|
||||
property_row(ui, "Cost", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut value.cost)
|
||||
.speed(0.05)
|
||||
.range(0.05..=100.0),
|
||||
)
|
||||
});
|
||||
property_row(ui, "Walkable", |ui| {
|
||||
ui.checkbox(&mut value.walkable, "Enabled")
|
||||
});
|
||||
});
|
||||
apply_component_card_response(world, entity, response);
|
||||
if value != original {
|
||||
set_navigation_with_history(
|
||||
world,
|
||||
entity,
|
||||
NavigationComponentState {
|
||||
area: Some(value),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn navigation_link_inspector_ui(world: &mut World, ui: &mut egui::Ui, entity: Entity) {
|
||||
let Some(mut value) = world.get::<NavigationLink>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let original = value.clone();
|
||||
let card = component_card_context(
|
||||
world,
|
||||
entity,
|
||||
ComponentCardOptions::removable(COMPONENT_NAVIGATION_LINK, "Navigation Link", icons::LINK),
|
||||
);
|
||||
let response = component_card(ui, &card, |ui| {
|
||||
property_row(ui, "Start", |ui| vec3_editor(ui, &mut value.start, 0.05));
|
||||
property_row(ui, "End", |ui| vec3_editor(ui, &mut value.end, 0.05));
|
||||
property_row(ui, "Direction", |ui| {
|
||||
ui.checkbox(&mut value.bidirectional, "Bidirectional")
|
||||
});
|
||||
property_row(ui, "Cost", |ui| {
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut value.cost)
|
||||
.speed(0.05)
|
||||
.range(0.05..=100.0),
|
||||
)
|
||||
});
|
||||
property_row(ui, "Enabled", |ui| {
|
||||
ui.checkbox(&mut value.enabled, "Active")
|
||||
});
|
||||
});
|
||||
apply_component_card_response(world, entity, response);
|
||||
if value != original {
|
||||
set_navigation_with_history(
|
||||
world,
|
||||
entity,
|
||||
NavigationComponentState {
|
||||
link: Some(value),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bake_bounds(world: &mut World, entity: Entity) {
|
||||
let Some(bounds) = world.get::<NavigationBounds>(entity).cloned() else {
|
||||
set_status(
|
||||
world,
|
||||
"Bake failed: selected actor has no Navigation Bounds",
|
||||
true,
|
||||
);
|
||||
return;
|
||||
};
|
||||
let input = match build_input(world, entity, &bounds) {
|
||||
Ok(input) => input,
|
||||
Err(error) => {
|
||||
set_status(world, format!("Bake failed: {error}"), true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let artifact = match bake_navigation(&input) {
|
||||
Ok(artifact) => artifact,
|
||||
Err(error) => {
|
||||
set_status(world, format!("Bake failed: {error}"), true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let path = match artifact_path(world, &bounds.artifact_path) {
|
||||
Ok(path) => path,
|
||||
Err(error) => {
|
||||
set_status(world, format!("Bake failed: {error}"), true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let Err(error) = write_navigation_artifact(&path, &artifact) {
|
||||
set_status(world, format!("Bake failed: {error}"), true);
|
||||
return;
|
||||
}
|
||||
let polygon_count: usize = artifact
|
||||
.mesh
|
||||
.layers
|
||||
.iter()
|
||||
.map(|layer| layer.polygons.len())
|
||||
.sum();
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
state.bounds_entity = Some(entity);
|
||||
state.artifact = Some(artifact);
|
||||
state.preview_path.clear();
|
||||
state.error = false;
|
||||
state.status = format!("Baked {polygon_count} polygons to {}", bounds.artifact_path);
|
||||
}
|
||||
|
||||
pub fn query_preview(world: &mut World, entity: Entity) {
|
||||
let (artifact, start, end) = {
|
||||
let state = world.resource::<NavigationEditorState>();
|
||||
(
|
||||
state.artifact.clone(),
|
||||
state.preview_start,
|
||||
state.preview_end,
|
||||
)
|
||||
};
|
||||
let Some(artifact) = artifact else {
|
||||
set_status(world, "Path test failed: bake navigation first", true);
|
||||
return;
|
||||
};
|
||||
let runtime = match game::navigation::NavigationRuntime::from_artifact(artifact) {
|
||||
Ok(runtime) => runtime,
|
||||
Err(error) => {
|
||||
set_status(world, format!("Path test failed: {error}"), true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match runtime.query(start, end) {
|
||||
Ok(path) => {
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
state.bounds_entity = Some(entity);
|
||||
state.preview_path = path.points;
|
||||
state.error = false;
|
||||
state.status = format!(
|
||||
"Path {:.2} m, {} waypoints{}",
|
||||
path.length,
|
||||
state.preview_path.len(),
|
||||
path.used_link_actor_id
|
||||
.as_deref()
|
||||
.map(|id| format!(", link {id}"))
|
||||
.unwrap_or_default()
|
||||
);
|
||||
}
|
||||
Err(error) => set_status(world, format!("Path test failed: {error}"), true),
|
||||
}
|
||||
}
|
||||
|
||||
fn build_input(
|
||||
world: &mut World,
|
||||
bounds_entity: Entity,
|
||||
bounds: &NavigationBounds,
|
||||
) -> Result<NavigationBakeInput, String> {
|
||||
let active_path = world
|
||||
.resource::<SceneIo>()
|
||||
.active_path
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.ok_or_else(|| "save the scene before baking navigation".to_string())?;
|
||||
let project_root = Path::new(&world.resource::<ProjectWorkspace>().root);
|
||||
let source_scene = active_path
|
||||
.strip_prefix(project_root)
|
||||
.unwrap_or(&active_path)
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/");
|
||||
let bounds_actor_id = actor_id(world, bounds_entity)?;
|
||||
let bounds_transform = world_transform(world, bounds_entity);
|
||||
let center = bounds_transform.translation.to_array();
|
||||
let half_extents = world_aabb_half_extents(bounds_transform, bounds.half_extents).to_array();
|
||||
|
||||
let mut obstacles = Vec::new();
|
||||
let mut obstacle_query = world.query::<(Entity, &NavigationObstacle)>();
|
||||
for (entity, obstacle) in obstacle_query.iter(world) {
|
||||
let value = NavigationVolumeInput {
|
||||
actor_id: actor_id(world, entity)?,
|
||||
center: world_position(world, entity).to_array(),
|
||||
half_extents: world_aabb_half_extents(
|
||||
world_transform(world, entity),
|
||||
obstacle.half_extents,
|
||||
)
|
||||
.to_array(),
|
||||
};
|
||||
if aabb_overlaps(center, half_extents, value.center, value.half_extents) {
|
||||
obstacles.push(value);
|
||||
}
|
||||
}
|
||||
obstacles.sort_by(|a, b| a.actor_id.cmp(&b.actor_id));
|
||||
|
||||
let mut areas = Vec::new();
|
||||
let mut area_query = world.query::<(Entity, &NavigationArea)>();
|
||||
for (entity, area) in area_query.iter(world) {
|
||||
let value = NavigationAreaInput {
|
||||
actor_id: actor_id(world, entity)?,
|
||||
id: area.id.clone(),
|
||||
center: world_position(world, entity).to_array(),
|
||||
half_extents: world_aabb_half_extents(
|
||||
world_transform(world, entity),
|
||||
area.half_extents,
|
||||
)
|
||||
.to_array(),
|
||||
cost: area.cost,
|
||||
walkable: area.walkable,
|
||||
};
|
||||
if aabb_overlaps(center, half_extents, value.center, value.half_extents) {
|
||||
areas.push(value);
|
||||
}
|
||||
}
|
||||
areas.sort_by(|a, b| a.actor_id.cmp(&b.actor_id));
|
||||
|
||||
let mut links = Vec::new();
|
||||
let mut link_query = world.query::<(Entity, &NavigationLink)>();
|
||||
for (entity, link) in link_query.iter(world) {
|
||||
let transform = world_transform(world, entity);
|
||||
let value = NavigationLinkInput {
|
||||
actor_id: actor_id(world, entity)?,
|
||||
start: transform.transform_point(link.start).to_array(),
|
||||
end: transform.transform_point(link.end).to_array(),
|
||||
bidirectional: link.bidirectional,
|
||||
cost: link.cost,
|
||||
enabled: link.enabled,
|
||||
};
|
||||
if point_in_aabb(value.start, center, half_extents)
|
||||
|| point_in_aabb(value.end, center, half_extents)
|
||||
{
|
||||
links.push(value);
|
||||
}
|
||||
}
|
||||
links.sort_by(|a, b| a.actor_id.cmp(&b.actor_id));
|
||||
|
||||
let mut geometry = Vec::new();
|
||||
let mut geometry_query = world.query::<(Entity, Option<&Primitive>, Option<&BrushDesc>)>();
|
||||
for (entity, primitive, brush) in geometry_query.iter(world) {
|
||||
if primitive.is_none() && brush.is_none() {
|
||||
continue;
|
||||
}
|
||||
let transform = world_transform(world, entity);
|
||||
let Some(value) = navigation_geometry_from_parts(
|
||||
actor_id(world, entity)?,
|
||||
transform.translation.to_array(),
|
||||
transform.rotation.to_array(),
|
||||
transform.scale.to_array(),
|
||||
primitive,
|
||||
brush,
|
||||
) else {
|
||||
continue;
|
||||
};
|
||||
if geometry_overlaps_bounds(&value, center, half_extents) {
|
||||
geometry.push(value);
|
||||
}
|
||||
}
|
||||
geometry.sort_by(|a, b| a.actor_id.cmp(&b.actor_id));
|
||||
|
||||
Ok(NavigationBakeInput {
|
||||
source_scene,
|
||||
bounds_actor_id,
|
||||
center,
|
||||
half_extents,
|
||||
agent: bounds.agent.clone(),
|
||||
geometry,
|
||||
obstacles,
|
||||
areas,
|
||||
links,
|
||||
})
|
||||
}
|
||||
|
||||
fn actor_id(world: &World, entity: Entity) -> Result<String, String> {
|
||||
world
|
||||
.get::<ActorId>(entity)
|
||||
.map(|id| id.0.clone())
|
||||
.filter(|id| !id.trim().is_empty())
|
||||
.ok_or_else(|| format!("navigation actor {entity:?} requires a stable ActorId"))
|
||||
}
|
||||
|
||||
fn world_transform(world: &World, entity: Entity) -> Transform {
|
||||
let mut chain = Vec::new();
|
||||
let mut current = entity;
|
||||
let mut visited = HashSet::new();
|
||||
while visited.insert(current) {
|
||||
chain.push(world.get::<Transform>(current).copied().unwrap_or_default());
|
||||
let Some(parent) = world.get::<ChildOf>(current).map(ChildOf::parent) else {
|
||||
break;
|
||||
};
|
||||
current = parent;
|
||||
}
|
||||
if world.get::<ChildOf>(current).is_some() {
|
||||
return Transform::default();
|
||||
}
|
||||
let mut chain = chain.into_iter().rev();
|
||||
let root = chain.next().unwrap_or_default();
|
||||
chain
|
||||
.fold(GlobalTransform::from(root), |global, local| {
|
||||
global.mul_transform(local)
|
||||
})
|
||||
.compute_transform()
|
||||
}
|
||||
|
||||
fn world_position(world: &World, entity: Entity) -> Vec3 {
|
||||
world_transform(world, entity).translation
|
||||
}
|
||||
|
||||
fn world_aabb_half_extents(transform: Transform, local_half_extents: Vec3) -> Vec3 {
|
||||
let half = transform.scale.abs() * local_half_extents;
|
||||
let x = transform.rotation * Vec3::X;
|
||||
let y = transform.rotation * Vec3::Y;
|
||||
let z = transform.rotation * Vec3::Z;
|
||||
x.abs() * half.x + y.abs() * half.y + z.abs() * half.z
|
||||
}
|
||||
|
||||
fn artifact_path(world: &World, authored: &str) -> Result<PathBuf, String> {
|
||||
let relative = Path::new(authored);
|
||||
if relative.is_absolute()
|
||||
|| relative
|
||||
.components()
|
||||
.any(|component| matches!(component, std::path::Component::ParentDir))
|
||||
{
|
||||
return Err("navigation artifact path must stay inside the project".into());
|
||||
}
|
||||
if !authored
|
||||
.replace('\\', "/")
|
||||
.starts_with("assets/navigation/generated/")
|
||||
{
|
||||
return Err("navigation artifacts must be under assets/navigation/generated/".into());
|
||||
}
|
||||
Ok(Path::new(&world.resource::<ProjectWorkspace>().root).join(relative))
|
||||
}
|
||||
|
||||
fn set_status(world: &mut World, message: impl Into<String>, error: bool) {
|
||||
let message = message.into();
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
state.status.clone_from(&message);
|
||||
state.error = error;
|
||||
if error {
|
||||
state.preview_path.clear();
|
||||
}
|
||||
world.resource_mut::<SceneIo>().set_status(message);
|
||||
}
|
||||
|
||||
fn vec3_editor(ui: &mut egui::Ui, value: &mut Vec3, speed: f64) -> egui::Response {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(egui::DragValue::new(&mut value.x).speed(speed));
|
||||
ui.add(egui::DragValue::new(&mut value.y).speed(speed));
|
||||
ui.add(egui::DragValue::new(&mut value.z).speed(speed))
|
||||
})
|
||||
.response
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum NavigationActorType {
|
||||
Bounds,
|
||||
Obstacle,
|
||||
Area,
|
||||
Link,
|
||||
}
|
||||
|
||||
pub fn spawn_navigation_actor(world: &mut World, actor_type: NavigationActorType) -> Entity {
|
||||
let rect = world.resource::<crate::ui::UiState>().viewport_rect;
|
||||
let settings = world.resource::<ViewportSettings>().clone();
|
||||
let translation = snap_translation(editor_spawn_ground_position(world, rect), &settings);
|
||||
let (name, bounds, obstacle, area, link) = match actor_type {
|
||||
NavigationActorType::Bounds => (
|
||||
"Navigation Bounds",
|
||||
Some(NavigationBounds::default()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
NavigationActorType::Obstacle => (
|
||||
"Navigation Obstacle",
|
||||
None,
|
||||
Some(NavigationObstacle::default()),
|
||||
None,
|
||||
None,
|
||||
),
|
||||
NavigationActorType::Area => (
|
||||
"Navigation Area",
|
||||
None,
|
||||
None,
|
||||
Some(NavigationArea::default()),
|
||||
None,
|
||||
),
|
||||
NavigationActorType::Link => (
|
||||
"Navigation Link",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(NavigationLink::default()),
|
||||
),
|
||||
};
|
||||
let mut snapshot =
|
||||
super::helpers::primitive_snapshot(name, shared::PrimitiveShape::Box, translation);
|
||||
snapshot.actor_kind = shared::ActorKind::Navigation;
|
||||
snapshot.primitive = None;
|
||||
snapshot.material = None;
|
||||
snapshot.physics = None;
|
||||
snapshot.collider = None;
|
||||
snapshot.rigid_body = None;
|
||||
snapshot.navigation_bounds = bounds;
|
||||
snapshot.navigation_obstacle = obstacle;
|
||||
snapshot.navigation_area = area;
|
||||
snapshot.navigation_link = link;
|
||||
crate::history::spawn_with_history(world, snapshot)
|
||||
}
|
||||
|
||||
pub fn sync_navigation_state(world: &mut World) {
|
||||
let selected = world.resource::<crate::selection::SelectedEntity>().0;
|
||||
let Some(entity) = selected.filter(|entity| world.get::<NavigationBounds>(*entity).is_some())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Some(bounds) = world.get::<NavigationBounds>(entity).cloned() else {
|
||||
return;
|
||||
};
|
||||
let input = match build_input(world, entity, &bounds) {
|
||||
Ok(input) => input,
|
||||
Err(_) => return,
|
||||
};
|
||||
let fingerprint = navigation_source_fingerprint(&input);
|
||||
let changed_bounds = world.resource::<NavigationEditorState>().bounds_entity != Some(entity);
|
||||
if changed_bounds {
|
||||
let loaded = artifact_path(world, &bounds.artifact_path)
|
||||
.ok()
|
||||
.and_then(|path| read_navigation_artifact(&path).ok());
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
state.bounds_entity = Some(entity);
|
||||
state.artifact = loaded;
|
||||
state.preview_path.clear();
|
||||
state.observed_fingerprint = None;
|
||||
state.auto_bake_attempt = None;
|
||||
state.debounce_elapsed = 0.0;
|
||||
}
|
||||
|
||||
let delta = world.resource::<Time>().delta_secs();
|
||||
let mut should_bake = false;
|
||||
{
|
||||
let mut state = world.resource_mut::<NavigationEditorState>();
|
||||
if state.observed_fingerprint.as_deref() != Some(&fingerprint) {
|
||||
state.observed_fingerprint = Some(fingerprint.clone());
|
||||
state.auto_bake_attempt = None;
|
||||
state.debounce_elapsed = 0.0;
|
||||
}
|
||||
let stale = state
|
||||
.artifact
|
||||
.as_ref()
|
||||
.is_none_or(|artifact| artifact.source_fingerprint != fingerprint);
|
||||
if stale {
|
||||
state.debounce_elapsed += delta;
|
||||
if !state.error {
|
||||
state.status = "Authored navigation changed; rebake required".into();
|
||||
}
|
||||
should_bake = bounds.auto_bake
|
||||
&& state.debounce_elapsed >= 0.75
|
||||
&& state.auto_bake_attempt.as_deref() != Some(&fingerprint);
|
||||
if should_bake {
|
||||
state.auto_bake_attempt = Some(fingerprint.clone());
|
||||
}
|
||||
} else if state.status == "Not baked"
|
||||
|| state.status == "Authored navigation changed; rebake required"
|
||||
{
|
||||
state.status = format!("Current: {}", bounds.artifact_path);
|
||||
state.error = false;
|
||||
}
|
||||
}
|
||||
if should_bake {
|
||||
bake_bounds(world, entity);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn world_transform_uses_current_authored_parent_chain() {
|
||||
let mut world = World::new();
|
||||
let parent = world.spawn(Transform::from_xyz(4.0, 0.0, 0.0)).id();
|
||||
let child = world
|
||||
.spawn((Transform::from_xyz(0.0, 0.0, 2.0), ChildOf(parent)))
|
||||
.id();
|
||||
|
||||
world
|
||||
.entity_mut(child)
|
||||
.insert(Transform::from_xyz(0.0, 0.0, 3.0));
|
||||
|
||||
assert_eq!(
|
||||
world_transform(&world, child).translation,
|
||||
Vec3::new(4.0, 0.0, 3.0)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,25 @@ fn left_toolbar(world: &mut World, ui: &mut egui::Ui) {
|
||||
if icon_button(ui, icons::PENCIL_SIMPLE_LINE, "Draw brush (B)").clicked() {
|
||||
start_draw_brush_tool(world);
|
||||
}
|
||||
let selected_navigation_bounds = world
|
||||
.resource::<crate::selection::SelectedEntity>()
|
||||
.0
|
||||
.filter(|entity| world.get::<shared::NavigationBounds>(*entity).is_some());
|
||||
let navigation_tip = if selected_navigation_bounds.is_some() {
|
||||
"Bake selected navigation bounds"
|
||||
} else {
|
||||
"Create navigation bounds"
|
||||
};
|
||||
if icon_button(ui, icons::PATH, navigation_tip).clicked() {
|
||||
if let Some(entity) = selected_navigation_bounds {
|
||||
super::navigation_inspector::bake_bounds(world, entity);
|
||||
} else {
|
||||
super::navigation_inspector::spawn_navigation_actor(
|
||||
world,
|
||||
super::navigation_inspector::NavigationActorType::Bounds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
toolbar_separator(ui);
|
||||
|
||||
|
||||
@@ -875,7 +875,7 @@ fn viewport_asset_drop_ui(
|
||||
.as_slice()
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|entity| world.get::<shared::ModelRef>(*entity).is_some())
|
||||
.find(|entity| world.get::<shared::SkinnedMeshRenderer>(*entity).is_some())
|
||||
{
|
||||
assign_animation_clip_operator(world, selection, entity);
|
||||
} else {
|
||||
@@ -1011,7 +1011,7 @@ fn asset_drag_descriptor(
|
||||
} if selected
|
||||
.as_slice()
|
||||
.iter()
|
||||
.any(|entity| world.get::<shared::ModelRef>(*entity).is_some()) =>
|
||||
.any(|entity| world.get::<shared::SkinnedMeshRenderer>(*entity).is_some()) =>
|
||||
{
|
||||
"Assign clip to animated actor"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user