renderer
This commit is contained in:
56
unity-parser/src/types/unity_types/renderer.rs
Normal file
56
unity-parser/src/types/unity_types/renderer.rs
Normal file
@@ -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<Self> {
|
||||||
|
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,));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user