Skip to main content

engvis_core/
material.rs

1/// Describes a PBR material
2#[derive(Debug, Clone)]
3pub struct PbrMaterial {
4    pub name: String,
5    pub albedo: [f32; 4],
6    pub metallic: f32,
7    pub roughness: f32,
8    pub emissive: [f32; 3],
9    pub normal_scale: f32,
10    pub alpha_cutoff: f32,
11
12    /// Texture indices (into a TextureCache)
13    pub albedo_texture: Option<usize>,
14    pub metallic_roughness_texture: Option<usize>,
15    pub normal_texture: Option<usize>,
16    pub emissive_texture: Option<usize>,
17}
18
19impl Default for PbrMaterial {
20    fn default() -> Self {
21        Self {
22            name: "Default".to_string(),
23            albedo: [0.8, 0.8, 0.8, 1.0],
24            metallic: 0.0,
25            roughness: 0.5,
26            emissive: [0.0, 0.0, 0.0],
27            normal_scale: 1.0,
28            alpha_cutoff: 0.5,
29            albedo_texture: None,
30            metallic_roughness_texture: None,
31            normal_texture: None,
32            emissive_texture: None,
33        }
34    }
35}
36
37/// Vertex (point) overlay rendering options
38#[derive(Debug, Clone, Copy)]
39pub struct VertexRenderOptions {
40    pub enabled: bool,
41    pub color: [f32; 3],
42    pub point_size: f32,
43}
44
45impl Default for VertexRenderOptions {
46    fn default() -> Self {
47        Self {
48            enabled: false,
49            color: [1.0, 0.85, 0.3],
50            point_size: 4.0,
51        }
52    }
53}
54
55/// Edge (line) overlay rendering options
56#[derive(Debug, Clone, Copy)]
57pub struct EdgeRenderOptions {
58    pub enabled: bool,
59    pub color: [f32; 3],
60    pub line_width: f32,
61}
62
63impl Default for EdgeRenderOptions {
64    fn default() -> Self {
65        Self {
66            enabled: true,
67            color: [0.2, 0.8, 1.0],
68            line_width: 5.0,
69        }
70    }
71}
72
73// ── RenderState ──────────────────────────────────────────────
74
75/// Aggregated rendering state that can be applied atomically.
76///
77/// Use `FrameCtx::set_render_state()` to update all rendering options in one call,
78/// or modulate individual fields directly via `frame.render_state.field`.
79///
80/// Clipping planes (near/far) are not part of this struct; use
81/// `FrameCtx::set_clip_planes()` to set them explicitly.
82#[derive(Debug, Clone, Copy)]
83pub struct RenderState {
84    /// Whether to render the surface (solid PBR mesh).
85    pub show_surface: bool,
86    /// Whether to render the ground/axis grid.
87    pub show_grid: bool,
88    /// Global surface opacity (0.0 = fully transparent, 1.0 = fully opaque).
89    pub opacity: f32,
90    /// Vertex (point) overlay options.
91    pub vertex_opts: VertexRenderOptions,
92    /// Edge (wireframe) overlay options.
93    pub edge_opts: EdgeRenderOptions,
94}
95
96impl Default for RenderState {
97    fn default() -> Self {
98        Self {
99            show_surface: true,
100            show_grid: true,
101            opacity: 1.0,
102            vertex_opts: VertexRenderOptions::default(),
103            edge_opts: EdgeRenderOptions::default(),
104        }
105    }
106}