1use mod3d_base::ShortIndex;
3
4use crate::{Gl, ShaderMaterialBaseData, TextureId};
5
6#[derive(Debug)]
10pub struct Material {
11 base_data: ShaderMaterialBaseData,
13 textures: [(TextureId, ShortIndex); 8],
14}
15
16impl Material {
18 pub fn create<M, G: Gl>(
23 _context: &mut G,
24 _object: &mod3d_base::Object<M, G>,
25 material: &M,
26 ) -> Result<Self, ()>
27 where
28 M: mod3d_base::Material,
29 {
30 let base_data = ShaderMaterialBaseData::of_material(material);
31 let mut textures = [(TextureId::None, ShortIndex::none()); 8];
32 let mut i = 0;
33 for aspect in [
34 mod3d_base::MaterialAspect::Color,
35 mod3d_base::MaterialAspect::Normal,
36 mod3d_base::MaterialAspect::MetallicRoughness,
37 mod3d_base::MaterialAspect::Occlusion,
38 mod3d_base::MaterialAspect::Emission,
39 ] {
40 let ti = material.texture(aspect);
41 if ti.is_some() {
42 textures[i] = (TextureId::of_material_aspect(aspect), ti);
43 i += 1;
44 };
45 }
46 eprintln!("Textures {textures:?}");
47 Ok(Self {
48 base_data,
49 textures,
50 })
51 }
52 pub fn base_data(&self) -> &ShaderMaterialBaseData {
53 &self.base_data
54 }
55 pub fn textures(&self) -> &[(TextureId, ShortIndex)] {
56 &self.textures
57 }
58}
59
60impl std::fmt::Display for Material {
63 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
64 std::fmt::Debug::fmt(self, f)
65 }
66}
67
68impl mod3d_base::MaterialClient for Material {}