mesh_tools/
builder_material.rs1use crate::builder::GltfBuilder;
2use crate::material;
3
4impl GltfBuilder {
5 pub fn add_material(&mut self, name: Option<String>,
7 base_color: Option<[f32; 4]>,
8 metallic_factor: Option<f32>,
9 roughness_factor: Option<f32>,
10 double_sided: Option<bool>) -> usize {
11 let mut builder = material::MaterialBuilder::new(name);
12
13 if let Some(color) = base_color {
14 builder = builder.with_base_color(color);
15 }
16
17 if let Some(metallic) = metallic_factor {
18 builder = builder.with_metallic_factor(metallic);
19 }
20
21 if let Some(roughness) = roughness_factor {
22 builder = builder.with_roughness_factor(roughness);
23 }
24
25 if let Some(double_sided) = double_sided {
26 builder = builder.with_double_sided(double_sided);
27 }
28
29 let material = builder.build();
30
31 if let Some(materials) = &mut self.gltf.materials {
32 let index = materials.len();
33 materials.push(material);
34 index
35 } else {
36 self.gltf.materials = Some(vec![material]);
37 0
38 }
39 }
40
41 pub fn create_basic_material(&mut self, name: Option<String>, color: [f32; 4]) -> usize {
43 let material = material::create_basic_material(name, color);
44
45 if let Some(materials) = &mut self.gltf.materials {
46 let index = materials.len();
47 materials.push(material);
48 index
49 } else {
50 self.gltf.materials = Some(vec![material]);
51 0
52 }
53 }
54
55 pub fn create_metallic_material(&mut self, name: Option<String>,
57 color: [f32; 4],
58 metallic: f32,
59 roughness: f32) -> usize {
60 let material = material::create_metallic_material(name, color, metallic, roughness);
61
62 if let Some(materials) = &mut self.gltf.materials {
63 let index = materials.len();
64 materials.push(material);
65 index
66 } else {
67 self.gltf.materials = Some(vec![material]);
68 0
69 }
70 }
71}