Fix sample hydration rendering regressions
This commit is contained in:
1 parent
06010c5922
commit
d52cc2e3b7
8 files changed
+193
-39
No files matched your search
@@ -40,16 +40,17 @@ use static_meshes::{
|
||||
};
|
||||
pub use terrain::HydratedTerrainChunk;
|
||||
use terrain::{cleanup_removed_terrain, hydrate_terrain};
|
||||
pub use visibility::initialize_level_object_visibility_hierarchy;
|
||||
use visibility::{
|
||||
ensure_level_object_visibility_hierarchy, init_editor_visibility_on_spawn,
|
||||
sync_editor_visibility, visibility_from_editor,
|
||||
sync_editor_visibility,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
authoring_component_active, AuthoringComponentStates, 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,
|
||||
authoring_component_active, AuthoringComponentStates, BrushDesc, ColliderDesc, 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.
|
||||
@@ -115,6 +116,8 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
world.insert_resource(StaticMeshArtifactCache::default());
|
||||
}
|
||||
|
||||
initialize_level_object_visibility_hierarchy(world);
|
||||
|
||||
let primitives: Vec<(Entity, Primitive)> = world
|
||||
.query_filtered::<(
|
||||
Entity,
|
||||
@@ -250,12 +253,6 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
}
|
||||
}
|
||||
|
||||
let visibility_targets: Vec<(Entity, EditorVisibility)> = world
|
||||
.query_filtered::<(Entity, &EditorVisibility), With<LevelObject>>()
|
||||
.iter(world)
|
||||
.map(|(entity, vis)| (entity, *vis))
|
||||
.collect();
|
||||
|
||||
let rendering = world
|
||||
.get_resource::<settings::ProjectSettings>()
|
||||
.map(|s| s.rendering.clone())
|
||||
@@ -348,25 +345,6 @@ pub fn flush_level_object_hydration(world: &mut World) {
|
||||
}
|
||||
|
||||
state.apply(world);
|
||||
|
||||
for (entity, editor) in visibility_targets {
|
||||
let visibility = visibility_from_editor(editor);
|
||||
if let Some(mut vis) = world.get_mut::<Visibility>(entity) {
|
||||
*vis = visibility;
|
||||
} else if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(visibility);
|
||||
}
|
||||
if world.get::<InheritedVisibility>(entity).is_none() {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(InheritedVisibility::default());
|
||||
}
|
||||
}
|
||||
if world.get::<ViewVisibility>(entity).is_none() {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert(ViewVisibility::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -3,6 +3,24 @@
|
||||
use crate::{EditorVisibility, LevelObject};
|
||||
use bevy::prelude::*;
|
||||
|
||||
/// Establishes the runtime visibility hierarchy synchronously for all authored actors.
|
||||
///
|
||||
/// Scene loading can occur between scheduled hydration sets, so callers that materialize a scene
|
||||
/// must run this before generated render children can be attached in the same frame.
|
||||
pub fn initialize_level_object_visibility_hierarchy(world: &mut World) {
|
||||
let targets: Vec<(Entity, EditorVisibility)> = world
|
||||
.query_filtered::<(Entity, Option<&EditorVisibility>), With<LevelObject>>()
|
||||
.iter(world)
|
||||
.map(|(entity, visibility)| (entity, visibility.copied().unwrap_or_default()))
|
||||
.collect();
|
||||
|
||||
for (entity, editor_visibility) in targets {
|
||||
if let Ok(mut entity_mut) = world.get_entity_mut(entity) {
|
||||
entity_mut.insert((editor_visibility, visibility_from_editor(editor_visibility)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::type_complexity,
|
||||
reason = "the query mirrors Bevy's three visibility hierarchy components"
|
||||
@@ -81,7 +99,9 @@ pub fn visibility_from_editor(editor: EditorVisibility) -> Visibility {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ensure_level_object_visibility_hierarchy;
|
||||
use super::{
|
||||
ensure_level_object_visibility_hierarchy, initialize_level_object_visibility_hierarchy,
|
||||
};
|
||||
use crate::{EditorVisibility, LevelObject};
|
||||
use bevy::prelude::*;
|
||||
|
||||
@@ -102,4 +122,34 @@ mod tests {
|
||||
assert!(world.get::<InheritedVisibility>(entity).is_some());
|
||||
assert!(world.get::<ViewVisibility>(entity).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn immediate_initializer_establishes_hierarchy_before_scheduled_hydration() {
|
||||
let mut world = World::new();
|
||||
let entity = world
|
||||
.spawn((LevelObject, EditorVisibility { visible: false }))
|
||||
.id();
|
||||
|
||||
initialize_level_object_visibility_hierarchy(&mut world);
|
||||
|
||||
assert_eq!(world.get::<Visibility>(entity), Some(&Visibility::Hidden));
|
||||
assert!(world.get::<InheritedVisibility>(entity).is_some());
|
||||
assert!(world.get::<ViewVisibility>(entity).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn immediate_initializer_migrates_missing_authored_visibility() {
|
||||
let mut world = World::new();
|
||||
let entity = world.spawn(LevelObject).id();
|
||||
|
||||
initialize_level_object_visibility_hierarchy(&mut world);
|
||||
|
||||
assert_eq!(
|
||||
world.get::<EditorVisibility>(entity),
|
||||
Some(&EditorVisibility::default())
|
||||
);
|
||||
assert_eq!(world.get::<Visibility>(entity), Some(&Visibility::Visible));
|
||||
assert!(world.get::<InheritedVisibility>(entity).is_some());
|
||||
assert!(world.get::<ViewVisibility>(entity).is_some());
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,10 @@ pub use actor::{infer_actor_kind, validate_actor, ActorValidationError};
|
||||
pub use animation::*;
|
||||
pub use components::*;
|
||||
pub use hydration::{
|
||||
cascade_config_from_rendering, flush_level_object_hydration, material_from_desc,
|
||||
strip_hydrated, strip_hydrated_entity, HydratedModelRoot, HydratedPrefabMember,
|
||||
HydratedPrefabReady, HydratedSkinnedMeshRoot, HydratedTerrainChunk, HydrationPlugin,
|
||||
PrefabHydrationBlocked,
|
||||
cascade_config_from_rendering, flush_level_object_hydration,
|
||||
initialize_level_object_visibility_hierarchy, material_from_desc, strip_hydrated,
|
||||
strip_hydrated_entity, HydratedModelRoot, HydratedPrefabMember, HydratedPrefabReady,
|
||||
HydratedSkinnedMeshRoot, HydratedTerrainChunk, HydrationPlugin, PrefabHydrationBlocked,
|
||||
};
|
||||
pub use material_asset::{
|
||||
load_resolved_material_from_path, MaterialAlphaMode, MaterialAsset, MaterialInstanceAsset,
|
||||
|
||||
Reference in new issue
Block a user