Skip to main content

wisp/scene/
mesh.rs

1//! `Mesh` — textured quad with 3D perspective rotation around the Y axis.
2//!
3//! M0.19 ships a fixed mesh shape (unit quad) with a perspective shader that
4//! takes `rotation_y` (radians) and `perspective_strength` (focal-length-ish).
5//! Generic per-Mesh custom WGSL is a v1+ chunk if/when we need it.
6
7use crate::color::Color;
8use crate::scene::container::Container;
9use crate::texture::Texture;
10
11/// Textured quad with 3D perspective rotation around the Y axis.
12#[derive(Debug, Clone)]
13pub struct Mesh {
14    /// Transform / visibility container.
15    pub container: Container,
16    /// Texture sampled across the quad.
17    pub texture: Texture,
18    /// Multiplicative tint applied to the sampled texel.
19    pub tint: Color,
20    /// Rotation angle around the Y (vertical) axis, in radians.
21    pub rotation_y: f32,
22    /// Perspective strength: 0.0 = orthographic, 1.0 = strong foreshortening.
23    pub perspective_strength: f32,
24}
25
26impl Mesh {
27    /// Construct a Mesh from a texture, with no rotation and mild perspective.
28    #[must_use]
29    pub fn from_texture(texture: Texture) -> Self {
30        Self {
31            container: Container::default(),
32            texture,
33            tint: Color::WHITE,
34            rotation_y: 0.0,
35            perspective_strength: 0.4,
36        }
37    }
38
39    /// Builder: set the Y-axis rotation.
40    #[must_use]
41    pub fn with_rotation_y(mut self, radians: f32) -> Self {
42        self.rotation_y = radians;
43        self
44    }
45
46    /// Builder: set the perspective strength (0.0–1.0 typical).
47    #[must_use]
48    pub fn with_perspective(mut self, strength: f32) -> Self {
49        self.perspective_strength = strength;
50        self
51    }
52}