From 708cf77df15076c0abe14422813498fb0f9ce8e5 Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 4 Jan 2026 14:00:03 +0000 Subject: [PATCH] renderer --- .../src/types/unity_types/renderer.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 unity-parser/src/types/unity_types/renderer.rs diff --git a/unity-parser/src/types/unity_types/renderer.rs b/unity-parser/src/types/unity_types/renderer.rs new file mode 100644 index 0000000..481c964 --- /dev/null +++ b/unity-parser/src/types/unity_types/renderer.rs @@ -0,0 +1,56 @@ +//! Renderer component wrapper + +use crate::types::{yaml_helpers, ComponentContext, FileRef, UnityComponent}; +use smallvec::SmallVec; +use sparsey::Entity; + +/// A Renderer component +/// +/// Renderer is the base class for all rendering components (MeshRenderer, SkinnedMeshRenderer, etc.). +/// It holds references to materials that define how the mesh should be rendered. +#[derive(Debug, Clone)] +pub struct Renderer { + materials: SmallVec<[FileRef; 1]>, +} + +impl Renderer { + /// Get the materials references + pub fn materials(&self) -> &[FileRef] { + &self.materials + } + + /// Get mutable access to the materials references + pub fn materials_mut(&mut self) -> &mut SmallVec<[FileRef; 1]> { + &mut self.materials + } + + /// Set the materials references + pub fn set_materials(&mut self, materials: SmallVec<[FileRef; 1]>) { + self.materials = materials; + } + + /// Add a material reference + pub fn add_material(&mut self, material: FileRef) { + self.materials.push(material); + } +} + +impl UnityComponent for Renderer { + /// Parse a Renderer 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 materials = yaml_helpers::get_file_ref_array(yaml, "m_Materials") + .unwrap_or_default() + .into_iter() + .collect(); + + Some(Self { materials }) + } +} + +impl crate::types::EcsInsertable for Renderer { + fn insert_into_world(self, world: &mut sparsey::World, entity: Entity) { + world.insert(entity, (self,)); + } +}