diff --git a/unity-parser/src/types/unity_types/mesh_filter.rs b/unity-parser/src/types/unity_types/mesh_filter.rs new file mode 100644 index 0000000..c066a47 --- /dev/null +++ b/unity-parser/src/types/unity_types/mesh_filter.rs @@ -0,0 +1,42 @@ +//! MeshFilter component wrapper + +use crate::types::{yaml_helpers, ComponentContext, FileRef, UnityComponent}; +use sparsey::Entity; + +/// A MeshFilter component +/// +/// MeshFilter holds a reference to a mesh asset that is used by the MeshRenderer. +/// It defines the geometry that will be rendered for a GameObject. +#[derive(Debug, Clone)] +pub struct MeshFilter { + mesh: Option, +} + +impl MeshFilter { + /// Get the mesh reference + pub fn mesh(&self) -> Option<&FileRef> { + self.mesh.as_ref() + } + + /// Set the mesh reference + pub fn set_mesh(&mut self, mesh: Option) { + self.mesh = mesh; + } +} + +impl UnityComponent for MeshFilter { + /// Parse a MeshFilter from YAML + /// + /// Note: Caller is responsible for ensuring this is called on the correct document type. + fn parse(yaml: &serde_yaml::Mapping, _ctx: &ComponentContext) -> Option { + let mesh = yaml_helpers::get_file_ref(yaml, "m_Mesh"); + + Some(Self { mesh }) + } +} + +impl crate::types::EcsInsertable for MeshFilter { + fn insert_into_world(self, world: &mut sparsey::World, entity: Entity) { + world.insert(entity, (self,)); + } +}