Skip to main content

euv_core/game/engine3d/mesh/
struct.rs

1use super::*;
2
3/// Single 3D mesh vertex storing local position and unit surface normal.
4#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
5pub struct Vertex3D {
6    /// Local-space 3D position.
7    #[get(type(copy))]
8    pub(crate) position: Vec3,
9    /// Local-space unit surface normal.
10    #[get(type(copy))]
11    pub(crate) normal: Vec3,
12}
13
14/// Physically based metallic-roughness material parameters for 3D surfaces.
15#[derive(Clone, Copy, Data, Debug, PartialEq)]
16pub struct PbrMaterial {
17    /// Base linear albedo RGB color.
18    #[get(type(copy))]
19    pub(crate) base_color: Vec3,
20    /// Metallic factor in `[0.0, 1.0]` (`1.0` = conductor/mirror/chrome).
21    #[get(type(copy))]
22    pub(crate) metallic: f32,
23    /// Surface roughness in `[0.04, 1.0]` (`0.04` = mirror gloss, `1.0` = matte).
24    #[get(type(copy))]
25    pub(crate) roughness: f32,
26    /// Emissive HDR RGB glow (neon windows, headlights, streetlights).
27    #[get(type(copy))]
28    pub(crate) emissive: Vec3,
29    /// Reflectivity multiplier used for ray-traced reflection blending (`0.0..=1.0`).
30    #[get(type(copy))]
31    pub(crate) reflectivity: f32,
32    /// Optional procedural surface detail overlay evaluated during deferred shading.
33    #[get(type(copy))]
34    pub(crate) surface_detail: SurfaceDetailMode,
35}
36
37/// Ergonomic descriptor for constructing an axis-aligned box `Mesh3D`.
38#[derive(Clone, Data, Debug, PartialEq)]
39pub struct BoxMeshDesc {
40    /// Human-readable mesh name.
41    pub(crate) name: String,
42    /// Box extents `(width, height, depth)` along `(X, Y, Z)`.
43    #[get(type(copy))]
44    pub(crate) size: Vec3,
45    /// When `true`, base rests on `y = 0`; otherwise centered at the origin.
46    #[get(type(copy))]
47    pub(crate) ground_pivot: bool,
48    /// Surface PBR material.
49    #[get(type(copy))]
50    pub(crate) material: PbrMaterial,
51}
52
53/// Ergonomic descriptor for constructing a subdivided ground plane `Mesh3D`.
54#[derive(Clone, Data, Debug, PartialEq)]
55pub struct GroundPlaneDesc {
56    /// Human-readable mesh name.
57    pub(crate) name: String,
58    /// Plane width along X.
59    #[get(type(copy))]
60    pub(crate) width: f32,
61    /// Plane depth along Z.
62    #[get(type(copy))]
63    pub(crate) depth: f32,
64    /// Grid subdivisions per axis (clamped to `1..=16`).
65    #[get(type(copy))]
66    pub(crate) subdivisions: usize,
67    /// Surface PBR material.
68    #[get(type(copy))]
69    pub(crate) material: PbrMaterial,
70}
71
72/// Nanite-style virtualized geometry cluster storing tight bounds, normal cone, and triangle slice.
73#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
74pub struct Meshlet3D {
75    /// First triangle index inside `Mesh3D::indices`.
76    #[get(type(copy))]
77    pub(crate) first_tri: u32,
78    /// Number of triangles belonging to this meshlet cluster (`<= 64`).
79    #[get(type(copy))]
80    pub(crate) tri_count: u32,
81    /// Tight local-space bounding box enclosing all cluster vertices.
82    #[get(type(copy))]
83    pub(crate) bounds: Aabb3D,
84    /// Average outward normal cone axis for backface cluster culling.
85    #[get(type(copy))]
86    pub(crate) cone_axis: Vec3,
87    /// Minimum dot product between member face normals and `cone_axis`.
88    #[get(type(copy))]
89    pub(crate) cone_cutoff: f32,
90    /// Geometric screen-space error metric used for continuous LOD transitions.
91    #[get(type(copy))]
92    pub(crate) screen_error: f32,
93}
94
95/// Indexed triangle mesh with local AABB, Nanite-style meshlet clusters, and default PBR material.
96#[derive(Clone, Data, Debug, PartialEq)]
97pub struct Mesh3D {
98    /// Human-readable asset name.
99    pub(crate) name: String,
100    /// Contiguous vertex buffer.
101    pub(crate) vertices: Vec<Vertex3D>,
102    /// Triangle index triplets `[i0, i1, i2]`.
103    pub(crate) indices: Vec<[u32; 3]>,
104    /// Precomputed local-space bounding box.
105    #[get(type(copy))]
106    pub(crate) bounds: Aabb3D,
107    /// Default PBR surface material.
108    #[get(type(copy))]
109    pub(crate) material: PbrMaterial,
110    /// Partitioned Nanite-style meshlet clusters for hierarchical culling and LOD streaming.
111    pub(crate) meshlets: Vec<Meshlet3D>,
112    /// Whether this mesh is a closed outward-wound volume eligible for screen-space backface and normal-cone culling.
113    #[get(type(copy))]
114    pub(crate) is_closed: bool,
115}
116
117/// Multi-level Level-of-Detail (LOD) mesh chain (`LOD0` full detail through `LOD2` distant proxy).
118#[derive(Clone, Data, Debug, PartialEq)]
119pub struct MeshLodChain {
120    /// Ordered detail levels from highest (`[0]`) to lowest (`[len - 1]`).
121    pub(crate) levels: Vec<Mesh3D>,
122}
123
124/// Result returned by `ModelImporter3D` containing imported mesh LOD chains and telemetry.
125#[derive(Clone, Data, Debug, PartialEq)]
126pub struct ImportedModel3D {
127    /// Model name extracted from source or fallback label.
128    pub(crate) name: String,
129    /// Source interchange format.
130    #[get(type(copy))]
131    pub(crate) format: ModelFormat,
132    /// Imported mesh LOD chains.
133    pub(crate) meshes: Vec<MeshLodChain>,
134    /// Total imported `LOD0` vertices.
135    #[get(type(copy))]
136    pub(crate) total_vertices: usize,
137    /// Total imported `LOD0` triangles.
138    #[get(type(copy))]
139    pub(crate) total_triangles: usize,
140}
141
142/// Stateless 3D model importer supporting Wavefront `.obj` and glTF 2.0 `.gltf` JSON assets.
143#[derive(Clone, Copy, Debug, Default)]
144pub struct ModelImporter3D;