73 lines
2.5 KiB
Rust
73 lines
2.5 KiB
Rust
//! Scene Parser - Parses Unity scenes and extracts game objects
|
|
//!
|
|
//! This binary handles:
|
|
//! - Initializing the Unity project
|
|
//! - Parsing Unity scenes
|
|
//! - Extracting Interactable_Resource components
|
|
//! - Computing world transforms
|
|
|
|
use cursebreaker_parser::InteractableResource;
|
|
use unity_parser::UnityProject;
|
|
use std::path::Path;
|
|
use unity_parser::log::DedupLogger;
|
|
use log::{info, error, LevelFilter};
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let logger = DedupLogger::new();
|
|
log::set_boxed_logger(Box::new(logger))
|
|
.map(|()| log::set_max_level(LevelFilter::Trace))
|
|
.unwrap();
|
|
|
|
info!("🎮 Cursebreaker - Scene Parser");
|
|
|
|
// Initialize Unity project once - scans entire project for GUID mappings
|
|
let project_root = Path::new("/home/connor/repos/CBAssets");
|
|
info!("\n📦 Initializing Unity project from: {}", project_root.display());
|
|
|
|
let project = UnityProject::from_path(project_root)?;
|
|
|
|
// Now parse the scene using the pre-built GUID resolvers
|
|
let scene_path = "_GameAssets/Scenes/Tiles/10_3.unity";
|
|
info!("📁 Parsing scene: {}", scene_path);
|
|
|
|
log::logger().flush();
|
|
|
|
// Parse the scene using the project
|
|
match project.parse_scene(scene_path) {
|
|
Ok(mut scene) => {
|
|
info!("✅ Scene parsed successfully!");
|
|
info!(" Total entities: {}", scene.entity_map.len());
|
|
|
|
// Post-processing: Compute world transforms
|
|
info!("🔄 Computing world transforms...");
|
|
unity_parser::compute_world_transforms(&mut scene.world, &scene.entity_map);
|
|
info!(" ✓ World transforms computed");
|
|
|
|
// Find all entities that have Interactable_Resource
|
|
log::logger().flush();
|
|
|
|
scene.world
|
|
.query_all::<(&InteractableResource, &unity_parser::WorldTransform, &unity_parser::GameObject)>()
|
|
.for_each(|(resource, transform, object)| {
|
|
info!(" 📦 Resource: \"{}\"", object.name);
|
|
info!(" • typeId: {}", resource.type_id);
|
|
|
|
// Extract world position from WorldTransform
|
|
let world_pos = transform.position();
|
|
info!(" • Position: ({:.2}, {:.2}, {:.2})", world_pos.x, world_pos.y, world_pos.z);
|
|
log::logger().flush();
|
|
});
|
|
|
|
log::logger().flush();
|
|
}
|
|
Err(e) => {
|
|
error!("Parse error: {}", e);
|
|
return Err(Box::new(e));
|
|
}
|
|
}
|
|
|
|
log::logger().flush();
|
|
|
|
Ok(())
|
|
}
|