diff --git a/cursebreaker-parser/src/main.rs b/cursebreaker-parser/src/main.rs index d45f931..6d6927b 100644 --- a/cursebreaker-parser/src/main.rs +++ b/cursebreaker-parser/src/main.rs @@ -52,15 +52,15 @@ fn main() -> Result<(), Box> { log::logger().flush(); scene.world - .query_all::<(&InteractableResource, &unity_parser::WorldTransform, &unity_parser::GameObject)>() - .for_each(|(resource, world_transform, object)| { + .query_all::<(&InteractableResource, &unity_parser::Transform, &unity_parser::GameObject)>() + .for_each(|(resource, transform, object)| { info!(" 📦 Resource: \"{}\"", object.name); info!(" • typeId: {}", resource.type_id); info!(" • maxHealth: {}", resource.max_health); // Extract world position from WorldTransform - let world_pos = world_transform.position(); - info!(" • World Position: ({:.2}, {:.2}, {:.2})", world_pos.x, world_pos.y, world_pos.z); + let world_pos = transform.local_position; + info!(" • Local Position: ({:.2}, {:.2}, {:.2})", world_pos.x, world_pos.y, world_pos.z); }); log::logger().flush(); diff --git a/unity-parser/src/post_processing/world_transform.rs b/unity-parser/src/post_processing/world_transform.rs index 33231dd..5829a98 100644 --- a/unity-parser/src/post_processing/world_transform.rs +++ b/unity-parser/src/post_processing/world_transform.rs @@ -92,7 +92,7 @@ pub fn compute_world_transforms(world: &mut World, entity_map: &HashMap(); for &entity in entity_map.values() { if let Some(transform) = transform_view.get(entity) { - if transform.parent().is_none() { + if transform.parent.is_none() { root_entities.push(entity); } } @@ -111,7 +111,7 @@ pub fn compute_world_transforms(world: &mut World, entity_map: &HashMap(); for &entity in entity_map.values() { if let Some(rect_transform) = rect_transform_view.get(entity) { - if rect_transform.transform.parent().is_none() { + if rect_transform.transform.parent.is_none() { rect_root_entities.push(entity); } } @@ -130,9 +130,9 @@ fn compute_world_transform_recursive(world: &mut World, entity: Entity, parent_m let transform_view = world.borrow::(); if let Some(transform) = transform_view.get(entity) { compute_local_matrix( - transform.local_position(), - transform.local_rotation(), - transform.local_scale(), + Some(&transform.local_position), + Some(&transform.local_rotation), + Some(&transform.local_scale), ) } else { // No transform component, skip this entity @@ -148,7 +148,7 @@ fn compute_world_transform_recursive(world: &mut World, entity: Entity, parent_m let transform_view = world.borrow::(); transform_view .get(entity) - .map(|t| t.children().to_vec()) + .map(|t| t.children.clone()) .unwrap_or_default() }; @@ -169,11 +169,11 @@ fn compute_rect_world_transform_recursive(world: &mut World, entity: Entity, par if let Some(rect_transform) = rect_transform_view.get(entity) { let transform = &rect_transform.transform; let local = compute_local_matrix( - transform.local_position(), - transform.local_rotation(), - transform.local_scale(), + Some(&transform.local_position), + Some(&transform.local_rotation), + Some(&transform.local_scale), ); - let children = transform.children().to_vec(); + let children = transform.children.clone(); (local, children) } else { // No rect transform component, skip this entity diff --git a/unity-parser/src/types/unity_types/mod.rs b/unity-parser/src/types/unity_types/mod.rs index 28da36e..1788d39 100644 --- a/unity-parser/src/types/unity_types/mod.rs +++ b/unity-parser/src/types/unity_types/mod.rs @@ -13,7 +13,6 @@ pub mod stripped_reference; pub mod transform; pub use box_collider::BoxCollider; -pub use capsule_collider::CapsuleCollider; pub use collider::Collider; pub use game_object::GameObject; pub use mesh_filter::MeshFilter; @@ -22,6 +21,5 @@ pub use prefab_instance::{ PrefabInstance, PrefabInstanceComponent, PrefabModification, PrefabResolver, }; pub use renderer::Renderer; -pub use sphere_collider::SphereCollider; pub use stripped_reference::StrippedReference; pub use transform::{RectTransform, Transform}; diff --git a/unity-parser/src/types/unity_types/transform.rs b/unity-parser/src/types/unity_types/transform.rs index f4aca27..cbb1c25 100644 --- a/unity-parser/src/types/unity_types/transform.rs +++ b/unity-parser/src/types/unity_types/transform.rs @@ -10,48 +10,11 @@ use sparsey::Entity; /// Transform determines the Position, Rotation, and Scale of each object in the scene. #[derive(Debug, Clone)] pub struct Transform { - local_position: Option, - local_rotation: Option, - local_scale: Option, - parent: Option, - children: Vec, -} - -impl Transform { - /// Get the local position - pub fn local_position(&self) -> Option<&Vector3> { - self.local_position.as_ref() - } - - /// Get the local rotation - pub fn local_rotation(&self) -> Option<&Quaternion> { - self.local_rotation.as_ref() - } - - /// Get the local scale - pub fn local_scale(&self) -> Option<&Vector3> { - self.local_scale.as_ref() - } - - /// Get the parent entity - pub fn parent(&self) -> Option { - self.parent - } - - /// Get the children entities - pub fn children(&self) -> &[Entity] { - &self.children - } - - /// Set the parent entity (used during hierarchy resolution) - pub fn set_parent(&mut self, parent: Option) { - self.parent = parent; - } - - /// Set the children entities (used during hierarchy resolution) - pub fn set_children(&mut self, children: Vec) { - self.children = children; - } + pub local_position: Vector3, + pub local_rotation: Quaternion, + pub local_scale: Vector3, + pub parent: Option, + pub children: Vec, } impl UnityComponent for Transform { @@ -98,7 +61,7 @@ impl UnityComponent for Transform { // Set parent (might be None if unresolved) let resolved_parent = parent_ref.and_then(|r| entity_map.get(&r.file_id).copied()); - transform.set_parent(resolved_parent); + transform.parent = resolved_parent; // Resolve any previously unresolved children let mut all_children = children_entities.clone(); @@ -110,15 +73,15 @@ impl UnityComponent for Transform { } } - transform.set_children(all_children); + transform.children = all_children; } })); } Some(Self { - local_position, - local_rotation, - local_scale, + local_position: local_position.unwrap_or_default(), + local_rotation: local_rotation.unwrap_or_default(), + local_scale: local_scale.unwrap_or_else(|| Vector3::new(1.0, 1.0, 1.0)), parent: None, children: Vec::new(), }) @@ -218,7 +181,7 @@ impl UnityComponent for RectTransform { // Set parent (might be None if unresolved) let resolved_parent = parent_ref.and_then(|r| entity_map.get(&r.file_id).copied()); - transform.set_parent(resolved_parent); + transform.parent = resolved_parent; // Resolve any previously unresolved children let mut all_children = children_entities.clone(); @@ -230,15 +193,15 @@ impl UnityComponent for RectTransform { } } - transform.set_children(all_children); + transform.children = all_children; } })); } let transform = Transform { - local_position, - local_rotation, - local_scale, + local_position: local_position.unwrap_or_default(), + local_rotation: local_rotation.unwrap_or_default(), + local_scale: local_scale.unwrap_or_else(|| Vector3::new(1.0, 1.0, 1.0)), parent: None, children: Vec::new(), };