use super::{FromValue, gameobject::GameObject, pptr::PPtr}; use crate::object::Value; use anyhow::Result; use glam::{Quat, Vec3}; use serde::Serialize; #[derive(Debug, Serialize)] pub struct Transform { pub father: PPtr, pub children: Vec>, pub gameobject: PPtr, pub local_position: Vec3, pub local_rotation: Quat, pub local_scale: Vec3, } impl FromValue for Transform { fn from_value(v: Value) -> Result { let mut fields = v.as_class("Transform").unwrap(); Ok(Self { children: fields .remove("m_Children") .unwrap() .as_class("vector") .unwrap() .remove("Array") .unwrap() .as_array() .unwrap() .into_iter() .map(|e| PPtr::from_value(e).unwrap().cast()) .collect(), father: fields .remove("m_Father") .unwrap() .parse::() .unwrap() .cast(), gameobject: fields.remove("m_GameObject").unwrap().parse().unwrap(), local_position: fields.remove("m_LocalPosition").unwrap().parse().unwrap(), local_rotation: fields.remove("m_LocalRotation").unwrap().parse().unwrap(), local_scale: fields.remove("m_LocalScale").unwrap().parse().unwrap(), }) } }