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: AxisAlignedBox3D,
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 axis-aligned bounding box, 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: AxisAlignedBox3D,
107 /// Default PBR surface material.
108 #[get(type(copy))]
109 pub(crate) material: PbrMaterial,
110 /// Optional per-part sub-materials indexed by `tri_materials[tri_idx] - 1` when non-zero.
111 pub(crate) sub_materials: Vec<PbrMaterial>,
112 /// Optional per-triangle material slot table (`0` uses the instance primary material, `k > 0` uses `sub_materials[k - 1]`).
113 pub(crate) tri_materials: Vec<u16>,
114 /// Partitioned Nanite-style meshlet clusters for hierarchical culling and LOD streaming.
115 pub(crate) meshlets: Vec<Meshlet3D>,
116 /// Whether this mesh is a closed outward-wound volume eligible for screen-space backface and normal-cone culling.
117 #[get(type(copy))]
118 pub(crate) is_closed: bool,
119}
120
121/// Multi-level Level-of-Detail (LOD) mesh chain (`LOD0` full detail through `LOD2` distant proxy).
122#[derive(Clone, Data, Debug, PartialEq)]
123pub struct MeshLodChain {
124 /// Ordered detail levels from highest (`[0]`) to lowest (`[len - 1]`).
125 pub(crate) levels: Vec<Mesh3D>,
126}
127
128/// Result returned by `ModelImporter3D` containing imported mesh LOD chains and telemetry.
129#[derive(Clone, Data, Debug, PartialEq)]
130pub struct ImportedModel3D {
131 /// Model name extracted from source or fallback label.
132 pub(crate) name: String,
133 /// Source interchange format.
134 #[get(type(copy))]
135 pub(crate) format: ModelFormat,
136 /// Imported mesh LOD chains.
137 pub(crate) meshes: Vec<MeshLodChain>,
138 /// Total imported `LOD0` vertices.
139 #[get(type(copy))]
140 pub(crate) total_vertices: usize,
141 /// Total imported `LOD0` triangles.
142 #[get(type(copy))]
143 pub(crate) total_triangles: usize,
144}
145
146/// Stateless 3D model importer supporting Wavefront `.obj` and glTF 2.0 `.gltf` JSON assets.
147#[derive(Clone, Copy, Debug, Default)]
148pub struct ModelImporter3D;