selective parsing of scenes
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
//!
|
//!
|
||||||
//! This binary handles:
|
//! This binary handles:
|
||||||
//! - Initializing the Unity project
|
//! - Initializing the Unity project
|
||||||
//! - Parsing Unity scenes
|
//! - Parsing Unity scenes with type filtering
|
||||||
//! - Extracting Interactable_Resource components
|
//! - Extracting Interactable_Resource components only
|
||||||
//! - Computing world transforms
|
//! - Computing world transforms
|
||||||
|
|
||||||
use cursebreaker_parser::InteractableResource;
|
use cursebreaker_parser::InteractableResource;
|
||||||
use unity_parser::UnityProject;
|
use unity_parser::{UnityProject, TypeFilter};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use unity_parser::log::DedupLogger;
|
use unity_parser::log::DedupLogger;
|
||||||
use log::{info, error, LevelFilter};
|
use log::{info, error, LevelFilter};
|
||||||
@@ -29,14 +29,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let project = UnityProject::from_path(project_root)?;
|
let project = UnityProject::from_path(project_root)?;
|
||||||
|
|
||||||
// Now parse the scene using the pre-built GUID resolvers
|
// Create type filter to only parse GameObject, Transform, and InteractableResource MonoBehaviour
|
||||||
|
info!("🔍 Setting up type filter:");
|
||||||
|
info!(" • Unity types: GameObject, Transform");
|
||||||
|
info!(" • Custom MonoBehaviours: InteractableResource");
|
||||||
|
let type_filter = TypeFilter::new(
|
||||||
|
vec!["GameObject", "Transform", "PrefabInstance"],
|
||||||
|
vec!["InteractableResource"]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Now parse the scene using the pre-built GUID resolvers with filtering
|
||||||
let scene_path = "_GameAssets/Scenes/Tiles/10_3.unity";
|
let scene_path = "_GameAssets/Scenes/Tiles/10_3.unity";
|
||||||
info!("📁 Parsing scene: {}", scene_path);
|
info!("📁 Parsing scene: {}", scene_path);
|
||||||
|
|
||||||
log::logger().flush();
|
log::logger().flush();
|
||||||
|
|
||||||
// Parse the scene using the project
|
// Parse the scene using the project with type filtering
|
||||||
match project.parse_scene(scene_path) {
|
match project.parse_scene_filtered(scene_path, Some(&type_filter)) {
|
||||||
Ok(mut scene) => {
|
Ok(mut scene) => {
|
||||||
info!("✅ Scene parsed successfully!");
|
info!("✅ Scene parsed successfully!");
|
||||||
info!(" Total entities: {}", scene.entity_map.len());
|
info!(" Total entities: {}", scene.entity_map.len());
|
||||||
|
|||||||
@@ -144,9 +144,9 @@ pub fn build_world_from_documents(
|
|||||||
&mut world,
|
&mut world,
|
||||||
linking_ctx.borrow_mut().entity_map_mut(),
|
linking_ctx.borrow_mut().entity_map_mut(),
|
||||||
) {
|
) {
|
||||||
Ok(spawned) => {
|
Ok(_spawned) => {
|
||||||
info!("Spawned {} entities from prefab GUID: {}",
|
// info!("Spawned {} entities from prefab GUID: {}",
|
||||||
spawned.len(), component.prefab_ref.guid);
|
// spawned.len(), component.prefab_ref.guid);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Soft failure - warn but continue
|
// Soft failure - warn but continue
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ pub use error::{Error, Result};
|
|||||||
pub use model::{RawDocument, UnityAsset, UnityFile, UnityPrefab, UnityScene, UnityProject};
|
pub use model::{RawDocument, UnityAsset, UnityFile, UnityPrefab, UnityScene, UnityProject};
|
||||||
pub use parser::{
|
pub use parser::{
|
||||||
find_project_root, meta::MetaFile, parse_unity_file, parse_unity_file_filtered,
|
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 post_processing::{compute_world_transforms, WorldTransform};
|
||||||
pub use property::PropertyValue;
|
pub use property::PropertyValue;
|
||||||
|
|||||||
@@ -317,6 +317,35 @@ impl UnityProject {
|
|||||||
crate::parser::parse_scene_with_project(&path, self)
|
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
|
/// Parse a Unity prefab using the pre-built GUID resolvers
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|||||||
@@ -208,14 +208,29 @@ fn parse_scene(path: &Path, content: &str, type_filter: Option<&TypeFilter>) ->
|
|||||||
/// * `path` - Path to the scene file
|
/// * `path` - Path to the scene file
|
||||||
/// * `project` - Pre-initialized UnityProject with GUID resolvers
|
/// * `project` - Pre-initialized UnityProject with GUID resolvers
|
||||||
pub fn parse_scene_with_project(path: &Path, project: &UnityProject) -> Result<UnityScene> {
|
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
|
// Read the file
|
||||||
let content = std::fs::read_to_string(path)?;
|
let content = std::fs::read_to_string(path)?;
|
||||||
|
|
||||||
// Validate Unity header
|
// Validate Unity header
|
||||||
validate_unity_header(&content, path)?;
|
validate_unity_header(&content, path)?;
|
||||||
|
|
||||||
// Parse raw documents
|
// Parse raw documents with type filtering
|
||||||
let raw_documents = parse_raw_documents(&content, None)?;
|
let raw_documents = parse_raw_documents(&content, type_filter)?;
|
||||||
|
|
||||||
// Build ECS world from documents using project's resolvers
|
// Build ECS world from documents using project's resolvers
|
||||||
let (world, entity_map) = crate::ecs::build_world_from_documents(
|
let (world, entity_map) = crate::ecs::build_world_from_documents(
|
||||||
|
|||||||
Reference in New Issue
Block a user