rscad_core/material.rs
1//! PBR surface-finish material data.
2//!
3//! [`MaterialData`] carries the surface-finish half of a PBR material
4//! (metallic/roughness). Albedo intentionally stays in the separate `Color`
5//! wrapper so the existing color pipeline (SDF palette, vertex colors,
6//! OpenSCAD `color()`) keeps working unchanged; a material preset applies
7//! both. Fields all have serde defaults so the struct can grow (reflectance,
8//! emissive, alpha mode, texture references) without breaking saved scenes.
9
10/// Default metallic factor applied when no material is assigned.
11pub const DEFAULT_METALLIC: f64 = 0.3;
12/// Default perceptual roughness applied when no material is assigned.
13pub const DEFAULT_ROUGHNESS: f64 = 0.5;
14
15/// Surface-finish parameters for a PBR material, applied by the `Material`
16/// wrapper node.
17#[derive(Clone, Debug, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[cfg_attr(feature = "reflect", derive(bevy_reflect::Reflect))]
20pub struct MaterialData {
21 /// Metallic factor (0.0 dielectric – 1.0 metal).
22 #[cfg_attr(feature = "serde", serde(default = "default_metallic"))]
23 pub metallic: f64,
24 /// Perceptual roughness (0.0 mirror – 1.0 fully diffuse).
25 #[cfg_attr(feature = "serde", serde(default = "default_roughness"))]
26 pub roughness: f64,
27 /// Name of the preset this material was created from, if any. Cleared
28 /// when parameters are edited by hand.
29 #[cfg_attr(feature = "serde", serde(default))]
30 pub preset: Option<String>,
31}
32
33impl Default for MaterialData {
34 fn default() -> Self {
35 Self {
36 metallic: DEFAULT_METALLIC,
37 roughness: DEFAULT_ROUGHNESS,
38 preset: None,
39 }
40 }
41}
42
43#[cfg(feature = "serde")]
44fn default_metallic() -> f64 {
45 DEFAULT_METALLIC
46}
47
48#[cfg(feature = "serde")]
49fn default_roughness() -> f64 {
50 DEFAULT_ROUGHNESS
51}