selective parsing of scenes

This commit is contained in:
2026-01-11 03:03:39 +00:00
parent 44b9a67800
commit c7a31ce30e
5 changed files with 65 additions and 12 deletions

View File

@@ -144,9 +144,9 @@ pub fn build_world_from_documents(
&mut world,
linking_ctx.borrow_mut().entity_map_mut(),
) {
Ok(spawned) => {
info!("Spawned {} entities from prefab GUID: {}",
spawned.len(), component.prefab_ref.guid);
Ok(_spawned) => {
// info!("Spawned {} entities from prefab GUID: {}",
// spawned.len(), component.prefab_ref.guid);
}
Err(e) => {
// Soft failure - warn but continue

View File

@@ -42,7 +42,7 @@ pub use error::{Error, Result};
pub use model::{RawDocument, UnityAsset, UnityFile, UnityPrefab, UnityScene, UnityProject};
pub use parser::{
find_project_root, meta::MetaFile, parse_unity_file, parse_unity_file_filtered,
GuidResolver, PrefabGuidResolver,
parse_scene_with_project_filtered, GuidResolver, PrefabGuidResolver,
};
pub use post_processing::{compute_world_transforms, WorldTransform};
pub use property::PropertyValue;

View File

@@ -317,6 +317,35 @@ impl UnityProject {
crate::parser::parse_scene_with_project(&path, self)
}
/// Parse a Unity scene using the pre-built GUID resolvers with optional type filtering
///
/// # Arguments
///
/// * `path` - Path to the scene file (relative to project root or absolute)
/// * `type_filter` - Optional filter for Unity types and MonoBehaviour class names
///
/// # Example
///
/// ```no_run
/// # use unity_parser::{UnityProject, TypeFilter};
/// # let project = UnityProject::from_path("/home/user/repos/CBAssets")?;
/// let filter = TypeFilter::new(
/// vec!["GameObject", "Transform"],
/// vec!["InteractableResource"]
/// );
/// let scene = project.parse_scene_filtered("_GameAssets/Scenes/Tiles/10_3.unity", Some(&filter))?;
/// println!("Scene has {} entities", scene.entity_map.len());
/// # Ok::<(), unity_parser::Error>(())
/// ```
pub fn parse_scene_filtered(
&self,
path: impl AsRef<Path>,
type_filter: Option<&crate::types::TypeFilter>
) -> crate::Result<UnityScene> {
let path = self.resolve_path(path.as_ref());
crate::parser::parse_scene_with_project_filtered(&path, self, type_filter)
}
/// Parse a Unity prefab using the pre-built GUID resolvers
///
/// # Arguments

View File

@@ -208,14 +208,29 @@ fn parse_scene(path: &Path, content: &str, type_filter: Option<&TypeFilter>) ->
/// * `path` - Path to the scene file
/// * `project` - Pre-initialized UnityProject with GUID resolvers
pub fn parse_scene_with_project(path: &Path, project: &UnityProject) -> Result<UnityScene> {
parse_scene_with_project_filtered(path, project, None)
}
/// Parse a scene file using pre-built GUID resolvers from a UnityProject with optional type filtering
///
/// # Arguments
///
/// * `path` - Path to the scene file
/// * `project` - Pre-initialized UnityProject with GUID resolvers
/// * `type_filter` - Optional filter for Unity types and MonoBehaviour class names
pub fn parse_scene_with_project_filtered(
path: &Path,
project: &UnityProject,
type_filter: Option<&TypeFilter>
) -> Result<UnityScene> {
// Read the file
let content = std::fs::read_to_string(path)?;
// Validate Unity header
validate_unity_header(&content, path)?;
// Parse raw documents
let raw_documents = parse_raw_documents(&content, None)?;
// Parse raw documents with type filtering
let raw_documents = parse_raw_documents(&content, type_filter)?;
// Build ECS world from documents using project's resolvers
let (world, entity_map) = crate::ecs::build_world_from_documents(