1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use color::{Rgba,ToRgba};
use super::{Property, texture::TextureSampler, AlphaType};
use super::parameter::*;
use mutiny_derive::Material;
use derive_builder::Builder;


#[derive(Debug, Material, Builder, Clone)]
#[builder(build_fn(name = "_build", private))]
#[material(default)]
#[builder(default)]
#[builder(setter(into))]
pub struct BasicMaterial{
    #[builder(private)]
    #[builder(setter(name = "hidden_base_color"))]
    #[material(uniform="base_color")]
    pub base_color: Parameter<Option<Rgba<f32>>>,

    #[builder(private)]
    #[builder(setter(name = "hidden_texture"))]
    #[material(name="tex")]
    pub texture: Parameter<Option<TextureSampler>>,

    pub properties: Parameter<Vec<Property>>,
    pub alpha_type: Parameter<AlphaType>,

    #[material(not_data)]
    pub debug_texcoords: Parameter<bool>,

    #[material(not_data)]
    pub debug_normals: Parameter<bool>,

    #[material(not_data)]
    pub output_linear_colors: Parameter<bool>,
}

impl BasicMaterialBuilder{
    pub fn new() -> BasicMaterialBuilder{
        BasicMaterialBuilder::default()
    }

    pub fn base_color<C: ToRgba>(&mut self, color: &C) -> &mut BasicMaterialBuilder{
        let color: Rgba<f32> = color.to_rgba().to_standard();
        self.base_color = Some(Parameter::new(Some(color)));
        self
    }

    pub fn texture<T: Into<TextureSampler>>(&mut self, texture: T) -> &mut BasicMaterialBuilder{
        self.texture = Some(Parameter::new(Some(texture.into())));
        self
    }

    pub fn build(&mut self) -> BasicMaterial{
        self._build().unwrap()
    }
}