Ship production navigation authoring workflow
This commit is contained in:
1 parent
0798aa5d57
commit
b4aa61e394
35 files changed
+3898
-602
No files matched your search
@@ -319,6 +319,7 @@ pub fn clear_level_objects(world: &mut World) {
|
||||
}
|
||||
|
||||
pub fn spawn_with_history(world: &mut World, mut snapshot: EditorEntitySnapshot) -> Entity {
|
||||
assign_missing_actor_ids(&mut snapshot);
|
||||
snapshot.hierarchy_sibling_index = next_sibling_index(world, None);
|
||||
let entity = spawn_snapshot(world, &snapshot);
|
||||
push_history(
|
||||
@@ -340,6 +341,9 @@ pub fn spawn_many_with_history(
|
||||
if snapshots.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
for snapshot in &mut snapshots {
|
||||
assign_missing_actor_ids(snapshot);
|
||||
}
|
||||
for (sibling_index, snapshot) in (next_sibling_index(world, None)..).zip(snapshots.iter_mut()) {
|
||||
snapshot.hierarchy_sibling_index = sibling_index;
|
||||
}
|
||||
@@ -421,12 +425,37 @@ pub fn duplicate_entities_with_history(world: &mut World, entities: &[Entity]) {
|
||||
}
|
||||
|
||||
fn assign_fresh_actor_ids(snapshot: &mut EditorEntitySnapshot) {
|
||||
snapshot.actor_id = Some(new_actor_id());
|
||||
let actor_id = new_actor_id();
|
||||
if let Some(bounds) = &mut snapshot.navigation_bounds {
|
||||
bounds.artifact_path = shared::navigation_artifact_path_for_actor(&actor_id.0);
|
||||
}
|
||||
snapshot.actor_id = Some(actor_id);
|
||||
for child in &mut snapshot.children {
|
||||
assign_fresh_actor_ids(child);
|
||||
}
|
||||
}
|
||||
|
||||
fn assign_missing_actor_ids(snapshot: &mut EditorEntitySnapshot) {
|
||||
let existing_actor_id = snapshot
|
||||
.actor_id
|
||||
.clone()
|
||||
.filter(|id| !id.0.trim().is_empty());
|
||||
let assigned_new_id = existing_actor_id.is_none();
|
||||
let actor_id = existing_actor_id.unwrap_or_else(new_actor_id);
|
||||
if let Some(bounds) = &mut snapshot.navigation_bounds {
|
||||
if assigned_new_id
|
||||
|| bounds.artifact_path == NavigationBounds::default().artifact_path
|
||||
|| shared::navigation_generated_artifact_path(&bounds.artifact_path).is_err()
|
||||
{
|
||||
bounds.artifact_path = shared::navigation_artifact_path_for_actor(&actor_id.0);
|
||||
}
|
||||
}
|
||||
snapshot.actor_id = Some(actor_id);
|
||||
for child in &mut snapshot.children {
|
||||
assign_missing_actor_ids(child);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rename_entity_with_history(world: &mut World, entity: Entity, new_name: String) {
|
||||
if !is_mutable_level_object(world, entity) {
|
||||
return;
|
||||
@@ -2825,8 +2854,10 @@ mod tests {
|
||||
#[test]
|
||||
fn snapshots_preserve_component_order_and_independent_active_state() {
|
||||
let mut world = World::new();
|
||||
let mut order = InspectorOrder::default();
|
||||
order.component_ids = vec![shared::AUTHORING_COMPONENT_LIGHT.to_string()];
|
||||
let order = InspectorOrder {
|
||||
component_ids: vec![shared::AUTHORING_COMPONENT_LIGHT.to_string()],
|
||||
..Default::default()
|
||||
};
|
||||
let mut states = AuthoringComponentStates::default();
|
||||
states.set_component_active(shared::COMPONENT_LIGHT_DESC, false);
|
||||
let entity = world
|
||||
@@ -3516,6 +3547,73 @@ mod tests {
|
||||
assert_eq!(unique.len(), ids.len(), "duplicated actors need fresh IDs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_navigation_bounds_gets_actor_owned_artifact_path() {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<EditorHistory>();
|
||||
world.init_resource::<SceneIo>();
|
||||
world.init_resource::<SelectedEntity>();
|
||||
let original_id = ActorId::new("navigation-bounds-original");
|
||||
let original_bounds = NavigationBounds::for_actor(&original_id.0);
|
||||
let original = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
ActorKind::Navigation,
|
||||
original_id,
|
||||
Transform::IDENTITY,
|
||||
original_bounds.clone(),
|
||||
))
|
||||
.id();
|
||||
|
||||
duplicate_entities_with_history(&mut world, &[original]);
|
||||
|
||||
let (duplicate_id, duplicate_bounds) = world
|
||||
.query::<(Entity, &ActorId, &NavigationBounds)>()
|
||||
.iter(&world)
|
||||
.find_map(|(entity, actor_id, bounds)| {
|
||||
(entity != original).then_some((actor_id.clone(), bounds.clone()))
|
||||
})
|
||||
.expect("duplicated navigation bounds should exist");
|
||||
assert_ne!(
|
||||
duplicate_bounds.artifact_path,
|
||||
original_bounds.artifact_path
|
||||
);
|
||||
assert_eq!(
|
||||
duplicate_bounds.artifact_path,
|
||||
shared::navigation_artifact_path_for_actor(&duplicate_id.0)
|
||||
);
|
||||
|
||||
apply_command_undo(&mut world);
|
||||
apply_command_redo(&mut world);
|
||||
let redone = world
|
||||
.query::<(&ActorId, &NavigationBounds)>()
|
||||
.iter(&world)
|
||||
.find(|(actor_id, _)| **actor_id == duplicate_id)
|
||||
.expect("redo should preserve the duplicate actor identity");
|
||||
assert_eq!(redone.1, &duplicate_bounds);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn existing_navigation_snapshot_keeps_deliberate_generated_path() {
|
||||
let mut world = World::new();
|
||||
let mut bounds = NavigationBounds::for_actor("bounds-existing");
|
||||
bounds.artifact_path = "assets/navigation/generated/custom-zone.nav.ron".into();
|
||||
let entity = world
|
||||
.spawn((
|
||||
LevelObject,
|
||||
ActorKind::Navigation,
|
||||
ActorId::new("bounds-existing"),
|
||||
Transform::IDENTITY,
|
||||
bounds.clone(),
|
||||
))
|
||||
.id();
|
||||
let mut snapshot = snapshot_entity(&world, entity).unwrap();
|
||||
|
||||
assign_missing_actor_ids(&mut snapshot);
|
||||
|
||||
assert_eq!(snapshot.navigation_bounds.as_ref(), Some(&bounds));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn linked_members_reject_direct_history_mutations() {
|
||||
let mut world = World::new();
|
||||
|
||||
@@ -88,6 +88,7 @@ pub struct SceneIo {
|
||||
pub events: VecDeque<SceneIoEvent>,
|
||||
pub tabs: Vec<SceneTab>,
|
||||
pub active_tab: usize,
|
||||
change_revision: u64,
|
||||
next_event_id: u64,
|
||||
next_tab_id: u64,
|
||||
}
|
||||
@@ -127,6 +128,7 @@ impl Default for SceneIo {
|
||||
recovery_snapshot: None,
|
||||
}],
|
||||
active_tab: 0,
|
||||
change_revision: 0,
|
||||
next_event_id: 1,
|
||||
next_tab_id: 2,
|
||||
}
|
||||
@@ -136,14 +138,20 @@ impl Default for SceneIo {
|
||||
impl SceneIo {
|
||||
pub fn mark_dirty(&mut self) {
|
||||
self.dirty = true;
|
||||
self.change_revision = self.change_revision.wrapping_add(1);
|
||||
self.sync_active_tab_metadata();
|
||||
}
|
||||
|
||||
pub fn mark_clean(&mut self) {
|
||||
self.dirty = false;
|
||||
self.change_revision = self.change_revision.wrapping_add(1);
|
||||
self.sync_active_tab_metadata();
|
||||
}
|
||||
|
||||
pub fn change_revision(&self) -> u64 {
|
||||
self.change_revision
|
||||
}
|
||||
|
||||
pub fn active_path_label(&self) -> String {
|
||||
self.active_path
|
||||
.as_ref()
|
||||
@@ -935,7 +943,7 @@ fn save_level(world: &mut World, path: &Path) -> Result<usize, String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_active_scene(world: &mut World) -> Result<String, String> {
|
||||
pub(crate) fn serialize_active_scene(world: &mut World) -> Result<String, String> {
|
||||
let entities = authored_scene_entities(world);
|
||||
if world
|
||||
.resource::<SceneIo>()
|
||||
@@ -1950,11 +1958,13 @@ mod tests {
|
||||
let mut io = SceneIo::default();
|
||||
assert_eq!(io.tabs.len(), 1);
|
||||
assert!(!io.tabs[0].dirty);
|
||||
let initial_revision = io.change_revision();
|
||||
|
||||
io.active_path = Some(PathBuf::from("assets/levels/arena.scn.ron"));
|
||||
io.mark_dirty();
|
||||
|
||||
assert!(io.has_unsaved_tabs());
|
||||
assert!(io.change_revision() > initial_revision);
|
||||
assert!(io.tabs[0].dirty);
|
||||
assert_eq!(
|
||||
io.tabs[0].path.as_deref(),
|
||||
|
||||
@@ -9,9 +9,9 @@ use egui_phosphor_icons::{icons, Icon};
|
||||
use shared::{
|
||||
authoring_component_active,
|
||||
brush_math::{validate_brush, BrushDiagnosticSeverity},
|
||||
infer_actor_kind, ActorKind, AnimationControllerDesc, AudioListenerDesc, AudioSourceDesc,
|
||||
AuthoringComponentStates, AuthoringLightKind, AuthoringRigidBody, BrushDesc, BrushKind,
|
||||
ColliderDesc, ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef,
|
||||
infer_actor_kind, ActorId, ActorKind, AnimationControllerDesc, AudioListenerDesc,
|
||||
AudioSourceDesc, AuthoringComponentStates, AuthoringLightKind, AuthoringRigidBody, BrushDesc,
|
||||
BrushKind, ColliderDesc, ColliderShapeDesc, ColorDesc, ComponentInstanceId, EditorAssetRef,
|
||||
InspectorOrder, LevelObject, LightDesc, MaterialDesc, MaterialParameter,
|
||||
MaterialParameterValue, MaterialRef, MaterialShaderKind, NavigationArea, NavigationBounds,
|
||||
NavigationLink, NavigationObstacle, ObjectiveMarker, PhysicsBody, PlayerSpawn,
|
||||
@@ -690,9 +690,13 @@ fn paste_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
Some(CopiedComponent::PrefabInstance(value)) if type_name == COMPONENT_PREFAB_INSTANCE => {
|
||||
insert_direct_component(world, entity, value);
|
||||
}
|
||||
Some(CopiedComponent::NavigationBounds(value))
|
||||
Some(CopiedComponent::NavigationBounds(mut value))
|
||||
if type_name == COMPONENT_NAVIGATION_BOUNDS =>
|
||||
{
|
||||
value.artifact_path = world
|
||||
.get::<NavigationBounds>(entity)
|
||||
.map(|bounds| bounds.artifact_path.clone())
|
||||
.unwrap_or_else(|| navigation_bounds_for_entity(world, entity).artifact_path);
|
||||
crate::history::set_navigation_with_history(
|
||||
world,
|
||||
entity,
|
||||
@@ -760,6 +764,19 @@ fn reset_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
} else if type_path == COMPONENT_NAVIGATION_BOUNDS {
|
||||
let bounds = reset_navigation_bounds_for_entity(world, entity);
|
||||
let _ = crate::history::reflected_component_transaction(
|
||||
world,
|
||||
entity,
|
||||
"Reset Component",
|
||||
component_id,
|
||||
type_path,
|
||||
move |world, entity| {
|
||||
world.entity_mut(entity).insert(bounds);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let _ = crate::history::reflected_component_transaction(
|
||||
world,
|
||||
@@ -809,7 +826,7 @@ fn reset_component(world: &mut World, entity: Entity, type_name: &str) {
|
||||
world,
|
||||
entity,
|
||||
crate::history::NavigationComponentState {
|
||||
bounds: Some(NavigationBounds::default()),
|
||||
bounds: Some(reset_navigation_bounds_for_entity(world, entity)),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -1609,6 +1626,19 @@ fn insert_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
} else if descriptor.type_name == COMPONENT_NAVIGATION_BOUNDS {
|
||||
let bounds = navigation_bounds_for_entity(world, entity);
|
||||
let _ = crate::history::reflected_component_transaction(
|
||||
world,
|
||||
entity,
|
||||
"Add Component",
|
||||
descriptor.id,
|
||||
descriptor.type_name,
|
||||
move |world, entity| {
|
||||
world.entity_mut(entity).insert(bounds);
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let _ = crate::history::reflected_component_transaction(
|
||||
world,
|
||||
@@ -1689,9 +1719,8 @@ fn insert_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
});
|
||||
}),
|
||||
COMPONENT_NAVIGATION_BOUNDS => insert_component(world, entity, |world, e| {
|
||||
world
|
||||
.entity_mut(e)
|
||||
.insert((ActorKind::Navigation, NavigationBounds::default()));
|
||||
let bounds = navigation_bounds_for_entity(world, e);
|
||||
world.entity_mut(e).insert((ActorKind::Navigation, bounds));
|
||||
}),
|
||||
COMPONENT_NAVIGATION_OBSTACLE => insert_component(world, entity, |world, e| {
|
||||
world
|
||||
@@ -1717,6 +1746,21 @@ fn insert_registered_component(world: &mut World, entity: Entity, type_name: &st
|
||||
}
|
||||
}
|
||||
|
||||
fn navigation_bounds_for_entity(world: &World, entity: Entity) -> NavigationBounds {
|
||||
world
|
||||
.get::<ActorId>(entity)
|
||||
.map(|actor_id| NavigationBounds::for_actor(&actor_id.0))
|
||||
.unwrap_or_else(|| NavigationBounds::for_actor(&uuid::Uuid::new_v4().to_string()))
|
||||
}
|
||||
|
||||
fn reset_navigation_bounds_for_entity(world: &World, entity: Entity) -> NavigationBounds {
|
||||
let mut bounds = navigation_bounds_for_entity(world, entity);
|
||||
if let Some(current) = world.get::<NavigationBounds>(entity) {
|
||||
bounds.artifact_path.clone_from(¤t.artifact_path);
|
||||
}
|
||||
bounds
|
||||
}
|
||||
|
||||
fn insert_component(world: &mut World, entity: Entity, insert: impl FnOnce(&mut World, Entity)) {
|
||||
let before = crate::history::snapshot_entity(world, entity);
|
||||
let old_kind = before.as_ref().map(|s| s.actor_kind);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -154,33 +154,45 @@ fn draw_navigation_visualizers(
|
||||
links: Query<(&NavigationLink, &GlobalTransform), With<LevelObject>>,
|
||||
) {
|
||||
for (value, global) in &bounds {
|
||||
let (_, rotation, center) = global.to_scale_rotation_translation();
|
||||
let half_extents = crate::ui::navigation_inspector::world_aabb_half_extents(
|
||||
global.affine(),
|
||||
value.half_extents,
|
||||
);
|
||||
let center = global.translation();
|
||||
draw_box(
|
||||
&mut gizmos,
|
||||
center,
|
||||
rotation,
|
||||
value.half_extents,
|
||||
Quat::IDENTITY,
|
||||
half_extents,
|
||||
Color::srgba(0.12, 0.82, 0.78, 0.72),
|
||||
);
|
||||
}
|
||||
for (value, global) in &obstacles {
|
||||
let (_, rotation, center) = global.to_scale_rotation_translation();
|
||||
let half_extents = crate::ui::navigation_inspector::world_aabb_half_extents(
|
||||
global.affine(),
|
||||
value.half_extents,
|
||||
);
|
||||
let center = global.translation();
|
||||
draw_box(
|
||||
&mut gizmos,
|
||||
center,
|
||||
rotation,
|
||||
value.half_extents,
|
||||
Quat::IDENTITY,
|
||||
half_extents,
|
||||
Color::srgba(1.0, 0.28, 0.22, 0.78),
|
||||
);
|
||||
}
|
||||
for (value, global) in &areas {
|
||||
let (_, rotation, center) = global.to_scale_rotation_translation();
|
||||
let half_extents = crate::ui::navigation_inspector::world_aabb_half_extents(
|
||||
global.affine(),
|
||||
value.half_extents,
|
||||
);
|
||||
let center = global.translation();
|
||||
let color = if value.walkable {
|
||||
Color::srgba(0.32, 0.72, 1.0, 0.62)
|
||||
} else {
|
||||
Color::srgba(1.0, 0.55, 0.18, 0.72)
|
||||
};
|
||||
draw_box(&mut gizmos, center, rotation, value.half_extents, color);
|
||||
draw_box(&mut gizmos, center, Quat::IDENTITY, half_extents, color);
|
||||
}
|
||||
for (value, global) in &links {
|
||||
let start = global.transform_point(value.start);
|
||||
|
||||
Reference in new issue
Block a user