pub struct MaterialLibrary {
pub materials: Vec<PbrMaterial>,
pub name_map: HashMap<String, usize>,
/* private fields */
}Expand description
A collection of named PBR materials.
Fields§
§materials: Vec<PbrMaterial>All materials, indexed by their position.
name_map: HashMap<String, usize>Name-to-index mapping.
Implementations§
Source§impl MaterialLibrary
impl MaterialLibrary
pub fn new() -> Self
Sourcepub fn with_presets() -> Self
pub fn with_presets() -> Self
Create a library pre-populated with all preset materials.
Sourcepub fn add(&mut self, name: impl Into<String>, material: PbrMaterial) -> usize
pub fn add(&mut self, name: impl Into<String>, material: PbrMaterial) -> usize
Add a material to the library. Returns its index.
Sourcepub fn get(&self, name: &str) -> Option<&PbrMaterial>
pub fn get(&self, name: &str) -> Option<&PbrMaterial>
Get a material by name.
Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut PbrMaterial>
pub fn get_mut(&mut self, name: &str) -> Option<&mut PbrMaterial>
Get a material by name (mutable).
Sourcepub fn get_by_index(&self, index: usize) -> Option<&PbrMaterial>
pub fn get_by_index(&self, index: usize) -> Option<&PbrMaterial>
Get a material by index.
Sourcepub fn get_by_index_mut(&mut self, index: usize) -> Option<&mut PbrMaterial>
pub fn get_by_index_mut(&mut self, index: usize) -> Option<&mut PbrMaterial>
Get a material by index (mutable).
Sourcepub fn remove(&mut self, name: &str) -> Option<PbrMaterial>
pub fn remove(&mut self, name: &str) -> Option<PbrMaterial>
Remove a material by name.
Sourcepub fn resolve_instance(
&self,
instance: &MaterialInstance,
) -> Option<PbrMaterial>
pub fn resolve_instance( &self, instance: &MaterialInstance, ) -> Option<PbrMaterial>
Resolve a material instance against this library.
Trait Implementations§
Source§impl Debug for MaterialLibrary
impl Debug for MaterialLibrary
Auto Trait Implementations§
impl Freeze for MaterialLibrary
impl RefUnwindSafe for MaterialLibrary
impl Send for MaterialLibrary
impl Sync for MaterialLibrary
impl Unpin for MaterialLibrary
impl UnsafeUnpin for MaterialLibrary
impl UnwindSafe for MaterialLibrary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.