1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
5pub struct Material {
6 pub name: String,
7 pub base_color: [f32; 4],
9 pub metallic: f32,
10 pub roughness: f32,
11 pub emissive: [f32; 3],
13 #[serde(default)]
14 pub double_sided: bool,
15 #[serde(default)]
17 pub albedo_texture_id: Option<String>,
18 #[serde(default)]
20 pub normal_texture_id: Option<String>,
21}
22
23impl Default for Material {
24 fn default() -> Self {
25 Self {
26 name: "default".into(),
27 base_color: [0.8, 0.8, 0.8, 1.0],
28 metallic: 0.0,
29 roughness: 0.6,
30 emissive: [0.0, 0.0, 0.0],
31 double_sided: false,
32 albedo_texture_id: None,
33 normal_texture_id: None,
34 }
35 }
36}
37
38impl Material {
39 pub fn colored(name: &str, rgba: [f32; 4]) -> Self {
40 Self {
41 name: name.into(),
42 base_color: rgba,
43 ..Default::default()
44 }
45 }
46}