euv_core/game/engine3d/mesh/struct.rs
1use super::*;
2
3/// Single 64-byte cache/GPU-aligned 3D mesh vertex storing position, normal, Lengyel tangent, dual UVs, and vertex color.
4#[repr(C, align(16))]
5#[derive(Clone, Copy, Data, Debug, PartialEq)]
6pub struct Vertex3D {
7 /// Local-space 3D position.
8 #[get(type(copy))]
9 pub(crate) position: Vec3,
10 /// Local-space unit surface normal.
11 #[get(type(copy))]
12 pub(crate) normal: Vec3,
13 /// Tangent vector `(tx, ty, tz, handedness_sign)` with `w` in `{-1.0, +1.0}`.
14 #[get(type(copy))]
15 pub(crate) tangent: [f32; 4],
16 /// Primary texture coordinate (`TEXCOORD_0`).
17 #[get(type(copy))]
18 pub(crate) uv0: [f32; 2],
19 /// Secondary texture coordinate (`TEXCOORD_1`).
20 #[get(type(copy))]
21 pub(crate) uv1: [f32; 2],
22 /// Packed UNORM8 vertex RGBA color (`COLOR_0`, defaults to opaque white `[255, 255, 255, 255]`).
23 #[get(type(copy))]
24 pub(crate) color0: [u8; 4],
25 /// Bit flags indicating populated attributes (`bit0=uv0`, `bit1=uv1`, `bit2=tangent`, `bit3=color0`).
26 #[get(type(copy))]
27 pub(crate) flags: u32,
28}
29
30/// Optional per-vertex skeletal skinning sidecar supporting up to 8 bone influences (`JOINTS_0/1`, `WEIGHTS_0/1`).
31#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
32pub struct MeshSkinInfluence3D {
33 /// Primary four influencing joint indices (`JOINTS_0`).
34 #[get(type(copy))]
35 pub(crate) joints_0: [u16; 4],
36 /// Primary four normalized weights (`WEIGHTS_0`).
37 #[get(type(copy))]
38 pub(crate) weights_0: [f32; 4],
39 /// Secondary four influencing joint indices (`JOINTS_1`).
40 #[get(type(copy))]
41 pub(crate) joints_1: [u16; 4],
42 /// Secondary four normalized weights (`WEIGHTS_1`).
43 #[get(type(copy))]
44 pub(crate) weights_1: [f32; 4],
45}
46
47/// Named Blender Shape Key / glTF morph target storing per-vertex displacement deltas.
48#[derive(Clone, Data, Debug, Default, PartialEq)]
49pub struct MorphTarget3D {
50 /// Human-readable Blender shape key name (e.g., `"BlinkLeft"`, `"Smile"`).
51 pub(crate) name: String,
52 /// Per-vertex local position deltas (`len == 0` or `len == vertices.len()`).
53 pub(crate) delta_positions: Vec<[f32; 3]>,
54 /// Per-vertex local normal deltas (`len == 0` or `len == vertices.len()`).
55 pub(crate) delta_normals: Vec<[f32; 3]>,
56 /// Per-vertex tangent XYZ deltas (`len == 0` or `len == vertices.len()`).
57 pub(crate) delta_tangents: Vec<[f32; 3]>,
58}
59
60/// Physically based metallic-roughness material parameters for 3D surfaces.
61#[derive(Clone, Copy, Data, Debug, PartialEq)]
62pub struct PbrMaterial {
63 /// Base linear albedo RGB color.
64 #[get(type(copy))]
65 pub(crate) base_color: Vec3,
66 /// Metallic factor in `[0.0, 1.0]` (`1.0` = conductor/mirror/chrome).
67 #[get(type(copy))]
68 pub(crate) metallic: f32,
69 /// Surface roughness in `[0.04, 1.0]` (`0.04` = mirror gloss, `1.0` = matte).
70 #[get(type(copy))]
71 pub(crate) roughness: f32,
72 /// Emissive HDR RGB glow (neon windows, headlights, streetlights).
73 #[get(type(copy))]
74 pub(crate) emissive: Vec3,
75 /// Reflectivity multiplier used for ray-traced reflection blending (`0.0..=1.0`).
76 #[get(type(copy))]
77 pub(crate) reflectivity: f32,
78 /// Optional procedural surface detail overlay evaluated during deferred shading.
79 #[get(type(copy))]
80 pub(crate) surface_detail: SurfaceDetailMode,
81}
82
83/// Ergonomic descriptor for constructing an axis-aligned box `Mesh3D`.
84#[derive(Clone, Data, Debug, PartialEq)]
85pub struct BoxMeshDesc {
86 /// Human-readable mesh name.
87 pub(crate) name: String,
88 /// Box extents `(width, height, depth)` along `(X, Y, Z)`.
89 #[get(type(copy))]
90 pub(crate) size: Vec3,
91 /// When `true`, base rests on `y = 0`; otherwise centered at the origin.
92 #[get(type(copy))]
93 pub(crate) ground_pivot: bool,
94 /// Surface PBR material.
95 #[get(type(copy))]
96 pub(crate) material: PbrMaterial,
97}
98
99/// Ergonomic descriptor for constructing a subdivided ground plane `Mesh3D`.
100#[derive(Clone, Data, Debug, PartialEq)]
101pub struct GroundPlaneDesc {
102 /// Human-readable mesh name.
103 pub(crate) name: String,
104 /// Plane width along X.
105 #[get(type(copy))]
106 pub(crate) width: f32,
107 /// Plane depth along Z.
108 #[get(type(copy))]
109 pub(crate) depth: f32,
110 /// Grid subdivisions per axis (clamped to `1..=16`).
111 #[get(type(copy))]
112 pub(crate) subdivisions: usize,
113 /// Surface PBR material.
114 #[get(type(copy))]
115 pub(crate) material: PbrMaterial,
116}
117
118/// Nanite-style virtualized geometry cluster storing tight bounds, normal cone, and triangle slice.
119#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
120pub struct Meshlet3D {
121 /// First triangle index inside `Mesh3D::indices`.
122 #[get(type(copy))]
123 pub(crate) first_tri: u32,
124 /// Number of triangles belonging to this meshlet cluster (`<= 64`).
125 #[get(type(copy))]
126 pub(crate) tri_count: u32,
127 /// Tight local-space bounding box enclosing all cluster vertices.
128 #[get(type(copy))]
129 pub(crate) bounds: AxisAlignedBox3D,
130 /// Average outward normal cone axis for backface cluster culling.
131 #[get(type(copy))]
132 pub(crate) cone_axis: Vec3,
133 /// Minimum dot product between member face normals and `cone_axis`.
134 #[get(type(copy))]
135 pub(crate) cone_cutoff: f32,
136 /// Geometric screen-space error metric used for continuous LOD transitions.
137 #[get(type(copy))]
138 pub(crate) screen_error: f32,
139}
140
141/// Indexed triangle mesh with local axis-aligned bounding box, Nanite-style meshlet clusters, and default PBR material.
142#[derive(Clone, Data, Debug, PartialEq)]
143pub struct Mesh3D {
144 /// Human-readable asset name.
145 pub(crate) name: String,
146 /// Contiguous vertex buffer.
147 pub(crate) vertices: Vec<Vertex3D>,
148 /// Triangle index triplets `[i0, i1, i2]`.
149 pub(crate) indices: Vec<[u32; 3]>,
150 /// Precomputed local-space bounding box.
151 #[get(type(copy))]
152 pub(crate) bounds: AxisAlignedBox3D,
153 /// Default PBR surface material.
154 #[get(type(copy))]
155 pub(crate) material: PbrMaterial,
156 /// Optional per-part sub-materials indexed by `tri_materials[tri_idx] - 1` when non-zero.
157 pub(crate) sub_materials: Vec<PbrMaterial>,
158 /// Optional per-triangle material slot table (`0` uses the instance primary material, `k > 0` uses `sub_materials[k - 1]`).
159 pub(crate) tri_materials: Vec<u16>,
160 /// Partitioned Nanite-style meshlet clusters for hierarchical culling and LOD streaming.
161 pub(crate) meshlets: Vec<Meshlet3D>,
162 /// Optional per-vertex skeletal skinning sidecar (empty for static meshes -> zero overhead).
163 pub(crate) skin_influences: Vec<MeshSkinInfluence3D>,
164 /// Optional Blender shape key / glTF morph target sidecars (empty when unmorphed).
165 pub(crate) morph_targets: Vec<MorphTarget3D>,
166 /// Optional index into the scene `PrincipledMaterial3D` table.
167 #[get(type(copy))]
168 pub(crate) material_index: Option<u32>,
169 /// Whether this mesh is a closed outward-wound volume eligible for screen-space backface and normal-cone culling.
170 #[get(type(copy))]
171 pub(crate) is_closed: bool,
172}
173
174/// Multi-level Level-of-Detail (LOD) mesh chain (`LOD0` full detail through `LOD2` distant proxy).
175#[derive(Clone, Data, Debug, PartialEq)]
176pub struct MeshLodChain {
177 /// Ordered detail levels from highest (`[0]`) to lowest (`[len - 1]`).
178 pub(crate) levels: Vec<Mesh3D>,
179}
180
181/// Result returned by `ModelImporter3D` containing imported mesh LOD chains and telemetry.
182#[derive(Clone, Data, Debug, PartialEq)]
183pub struct ImportedModel3D {
184 /// Model name extracted from source or fallback label.
185 pub(crate) name: String,
186 /// Source interchange format.
187 #[get(type(copy))]
188 pub(crate) format: ModelFormat,
189 /// Imported mesh LOD chains.
190 pub(crate) meshes: Vec<MeshLodChain>,
191 /// Total imported `LOD0` vertices.
192 #[get(type(copy))]
193 pub(crate) total_vertices: usize,
194 /// Total imported `LOD0` triangles.
195 #[get(type(copy))]
196 pub(crate) total_triangles: usize,
197}
198
199/// Stateless 3D model importer supporting Wavefront `.obj` and glTF 2.0 `.gltf` JSON assets.
200#[derive(Clone, Copy, Debug, Default)]
201pub struct ModelImporter3D;