Skip to main content

euv_core/game/engine3d/asset/
struct.rs

1use super::*;
2
3/// Decoded 64-byte `.euv3d` package header metadata.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct Euv3dHeader {
6    /// Format version (`EUV3D_FORMAT_VERSION`).
7    #[get(type(copy))]
8    pub(crate) version: u32,
9    /// Bitmask describing optional pre-baked sections (`BVH4`, `Meshlets`, `LODs`).
10    #[get(type(copy))]
11    pub(crate) flags: u32,
12    /// Number of entries stored in the section directory.
13    #[get(type(copy))]
14    pub(crate) section_count: u32,
15    /// Byte offset of the section directory table (typically `64`).
16    #[get(type(copy))]
17    pub(crate) table_offset: u64,
18    /// CRC32 checksum computed over payload bytes `[64..total_bytes]`.
19    #[get(type(copy))]
20    pub(crate) content_crc32: u32,
21    /// Total file size in bytes.
22    #[get(type(copy))]
23    pub(crate) total_bytes: u64,
24    /// 64-bit FNV-1a content digest for deterministic asset cache keying.
25    #[get(type(copy))]
26    pub(crate) digest_fnv1a: u64,
27}
28
29/// Single 32-byte section directory entry inside an `.euv3d` package.
30#[derive(Clone, Copy, Data, Debug, Eq, Hash, PartialEq)]
31pub struct Euv3dSectionEntry {
32    /// Semantic payload type of this section.
33    #[get(type(copy))]
34    pub(crate) kind: Euv3dSectionKind,
35    /// 64-byte-aligned starting byte offset inside the `.euv3d` buffer.
36    #[get(type(copy))]
37    pub(crate) offset: u64,
38    /// Exact payload length in bytes (excluding trailing alignment padding).
39    #[get(type(copy))]
40    pub(crate) byte_length: u64,
41    /// Number of logical elements stored inside this section.
42    #[get(type(copy))]
43    pub(crate) element_count: u32,
44    /// Section-specific bit flags.
45    #[get(type(copy))]
46    pub(crate) flags: u32,
47}
48
49/// Configuration controlling Garland-Heckbert QEM LOD generation, spatial meshlets, and BVH4 baking.
50#[derive(Clone, Copy, Data, Debug, PartialEq)]
51pub struct Euv3dBakeConfig {
52    /// Target number of LOD levels (`1..=4`, default `4`).
53    #[get(type(copy))]
54    pub(crate) lod_levels: usize,
55    /// Whether to cluster triangles into spatially coherent vertex-cache-friendly meshlets.
56    #[get(type(copy))]
57    pub(crate) build_meshlets: bool,
58    /// Whether to pre-bake per-mesh SIMD BVH4 acceleration structures into the package.
59    #[get(type(copy))]
60    pub(crate) bake_bvh4: bool,
61    /// Whether to preserve/generate full texture mipmap chains before serializing.
62    #[get(type(copy))]
63    pub(crate) generate_mipmaps: bool,
64}
65
66/// Zero-copy validated view over a 64-byte-aligned `.euv3d` binary buffer.
67#[derive(Clone, Data, Debug)]
68pub struct Euv3dPackageView<'a> {
69    /// Borrowed backing `.euv3d` byte slice.
70    pub(crate) raw_bytes: &'a [u8],
71    /// Parsed and CRC-verified 64-byte file header.
72    #[get(type(copy))]
73    pub(crate) header: Euv3dHeader,
74    /// Validated 64-byte-aligned section directory entries.
75    pub(crate) sections: Vec<Euv3dSectionEntry>,
76}
77
78/// Decoded `.euv3d` asset bundle containing the full scene, QEM LOD chains, and zero-rebuild BVH4 trees.
79#[derive(Clone, Data, Debug, Default)]
80pub struct BakedAssetBundle3D {
81    /// Restored Blender/glTF scene with hierarchy, materials, textures, rigs, animations, cameras, and lights.
82    pub(crate) scene: ImportedScene3D,
83    /// Pre-baked Garland-Heckbert QEM LOD chains aligned 1:1 with `scene.meshes`.
84    pub(crate) lod_chains: Vec<MeshLodChain>,
85    /// Pre-baked local-space SIMD BVH4 acceleration trees aligned 1:1 with `scene.meshes` (zero SAH build on load).
86    pub(crate) local_bvhs: Vec<Bvh3D>,
87    /// Total number of sections stored in the source `.euv3d` archive.
88    #[get(type(copy))]
89    pub(crate) section_count: usize,
90    /// Total byte size of the source `.euv3d` archive.
91    #[get(type(copy))]
92    pub(crate) total_bytes: usize,
93    /// Deterministic 64-bit FNV-1a digest of the archive contents.
94    #[get(type(copy))]
95    pub(crate) digest_fnv1a: u64,
96}
97
98/// Compact 24-byte `#[repr(C)]` quantized 3D vertex for `.euv3d` v2 storage and direct hardware GPU PBR rendering.
99#[repr(C)]
100#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
101pub struct QuantizedVertex3D {
102    /// Quantized 16-bit local-space position normalized against mesh AABB `[x, y, z]`.
103    #[get(type(copy))]
104    pub(crate) pos_q16: [u16; 3],
105    /// Packed attribute flags, tangent handedness sign, and sub-material bits.
106    #[get(type(copy))]
107    pub(crate) pad_flags: u16,
108    /// Octahedral-encoded unit surface normal in `SNORM16` `[nx, ny]`.
109    #[get(type(copy))]
110    pub(crate) normal_oct: [i16; 2],
111    /// Octahedral-encoded unit tangent and sign payload in `SNORM16` `[tx, ty]`.
112    #[get(type(copy))]
113    pub(crate) tangent_oct_sign: [i16; 2],
114    /// Half-precision IEEE-754 `f16` primary texture coordinates `[u0, v0]`.
115    #[get(type(copy))]
116    pub(crate) uv0_f16: [u16; 2],
117    /// Linear vertex color packed as unsigned normalized `[r, g, b, a]`.
118    #[get(type(copy))]
119    pub(crate) color0_rgba8: [u8; 4],
120}
121
122/// Compact 16-byte `#[repr(C)]` quantized skeletal skinning vertex sidecar for `.euv3d` v2 and GPU skinning.
123#[repr(C)]
124#[derive(Clone, Copy, Data, Debug, Default, Eq, New, PartialEq)]
125pub struct QuantizedSkinVertex3D {
126    /// Four primary influencing joint indices (`JOINTS_0`).
127    #[get(type(copy))]
128    pub(crate) joints: [u16; 4],
129    /// Four normalized `UNORM8` bone weights (`WEIGHTS_0`).
130    #[get(type(copy))]
131    pub(crate) weights_u8: [u8; 4],
132    /// Optional offset into extended secondary joint/weight buffer (`0` when unused).
133    #[get(type(copy))]
134    pub(crate) extra_offset: u32,
135}
136
137/// Cache-line-aligned 64-byte `#[repr(C)]` `.euv3d` v2 meshlet cluster descriptor with bounding sphere and quantized normal cone.
138#[repr(C)]
139#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
140pub struct QuantizedMeshlet3D {
141    /// First triangle index inside the owning LOD index buffer.
142    #[get(type(copy))]
143    pub(crate) first_tri: u32,
144    /// Number of triangles in this cluster (`<= 64`).
145    #[get(type(copy))]
146    pub(crate) tri_count: u32,
147    /// Tight local-space bounding box minimum corner.
148    #[get(type(copy))]
149    pub(crate) bounds_min: [f32; 3],
150    /// Tight local-space bounding box maximum corner.
151    #[get(type(copy))]
152    pub(crate) bounds_max: [f32; 3],
153    /// Local-space bounding sphere center.
154    #[get(type(copy))]
155    pub(crate) sphere_center: [f32; 3],
156    /// Local-space bounding sphere radius.
157    #[get(type(copy))]
158    pub(crate) sphere_radius: f32,
159    /// Backface normal cone apex position in local space.
160    #[get(type(copy))]
161    pub(crate) cone_apex: [f32; 3],
162    /// Quantized unit normal cone axis (`SNORM8` in `-127..=127`).
163    #[get(type(copy))]
164    pub(crate) cone_axis_s8: [i8; 3],
165    /// Quantized normal cone cutoff (`SNORM8`, `127` disables culling).
166    #[get(type(copy))]
167    pub(crate) cone_cutoff_s8: i8,
168}
169
170/// Compact binary mip-tail directory entry parsed from an `.euv3d` v2 `TextureMipTails` section.
171#[derive(Clone, Copy, Data, Debug, Eq, New, PartialEq)]
172pub struct Euv3dMipTailEntry {
173    /// Width of the largest mip level stored in the tail (`<= 32`).
174    #[get(type(copy))]
175    pub(crate) width: u32,
176    /// Height of the largest mip level stored in the tail (`<= 32`).
177    #[get(type(copy))]
178    pub(crate) height: u32,
179    /// Texture color space (`Srgb`, `Linear`, or `NormalTangent`).
180    #[get(type(copy))]
181    pub(crate) color_space: TextureColorSpace,
182    /// Number of mip levels stored in the contiguous tail (`32x32..1x1`).
183    #[get(type(copy))]
184    pub(crate) mip_count: u8,
185    /// Starting byte offset of the first tail mip payload inside `TextureMipTails`.
186    #[get(type(copy))]
187    pub(crate) byte_offset: usize,
188}
189
190/// Stateless serializer and zero-copy loader for `.euv3d` 64-byte-aligned binary 3D asset packages.
191#[derive(Clone, Copy, Debug, Default)]
192pub struct Euv3dPackage {}
193
194/// Symmetric 4x4 error quadric matrix stored as 10 upper-triangular `f64` coefficients for QEM simplification.
195#[derive(Clone, Copy, Debug, Default)]
196pub(crate) struct QemMatrix {
197    /// Upper-triangular entries `[a00, a01, a02, a03, a11, a12, a13, a22, a23, a33]`.
198    pub(crate) coeffs: [f64; 10],
199}
200
201/// Candidate undirected edge collapse entry queued in the QEM binary min-heap.
202#[derive(Clone, Copy, Debug)]
203pub(crate) struct QemEdgeCandidate {
204    /// Quadric error cost `v^T Q v` (smaller collapses first).
205    pub(crate) cost: f64,
206    /// First vertex index.
207    pub(crate) vert_a: usize,
208    /// Second vertex index.
209    pub(crate) vert_b: usize,
210    /// Revision stamp of `vert_a` when queued (for lazy invalidation).
211    pub(crate) ver_a: u32,
212    /// Revision stamp of `vert_b` when queued (for lazy invalidation).
213    pub(crate) ver_b: u32,
214    /// Optimal contracted 3D position.
215    pub(crate) target_pos: [f64; 3],
216    /// Normalized interpolation factor in `[0.0, 1.0]` along `vert_a -> vert_b`.
217    pub(crate) interp_t: f32,
218}
219
220/// Serializable metadata record describing one baked LOD level inside the shared binary geometry buffers.
221#[derive(Clone, Debug, Deserialize, Serialize)]
222pub(crate) struct Euv3dLodRecord {
223    /// Starting vertex index inside the `Vertices` section.
224    pub(crate) first_vertex: u32,
225    /// Number of vertices in this LOD level.
226    pub(crate) vertex_count: u32,
227    /// Starting triangle index inside the `Indices` section.
228    pub(crate) first_tri: u32,
229    /// Number of triangles in this LOD level.
230    pub(crate) tri_count: u32,
231    /// Starting meshlet index inside the `Meshlets` section.
232    pub(crate) first_meshlet: u32,
233    /// Number of meshlets belonging to this LOD level.
234    pub(crate) meshlet_count: u32,
235    /// Local bounding box minimum corner.
236    pub(crate) bounds_min: [f32; 3],
237    /// Local bounding box maximum corner.
238    pub(crate) bounds_max: [f32; 3],
239}
240
241/// Serializable metadata record describing one morph target inside the `MorphDeltas` section.
242#[derive(Clone, Debug, Deserialize, Serialize)]
243pub(crate) struct Euv3dMorphRecord {
244    /// Shape key / morph target name.
245    pub(crate) name: String,
246    /// Starting `[f32; 3]` element index for position deltas.
247    pub(crate) first_pos: u32,
248    /// Count of position deltas.
249    pub(crate) pos_count: u32,
250    /// Starting `[f32; 3]` element index for normal deltas.
251    pub(crate) first_norm: u32,
252    /// Count of normal deltas.
253    pub(crate) norm_count: u32,
254    /// Starting `[f32; 3]` element index for tangent deltas.
255    pub(crate) first_tan: u32,
256    /// Count of tangent deltas.
257    pub(crate) tan_count: u32,
258}
259
260/// Serializable PBR material payload matching `PbrMaterial` for `.euv3d` legacy material slots.
261#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
262pub(crate) struct Euv3dLegacyPbrRecord {
263    /// Base linear albedo RGB.
264    pub(crate) base_color: [f32; 3],
265    /// Metallic factor.
266    pub(crate) metallic: f32,
267    /// Roughness factor.
268    pub(crate) roughness: f32,
269    /// Emissive HDR RGB.
270    pub(crate) emissive: [f32; 3],
271    /// Reflectivity factor.
272    pub(crate) reflectivity: f32,
273    /// Encoded `SurfaceDetailMode` discriminant.
274    pub(crate) surface_detail: u8,
275}
276
277/// Serializable mesh record storing LOD slices, material links, skin sidecar slice, and morph targets.
278#[derive(Clone, Debug, Deserialize, Serialize)]
279pub(crate) struct Euv3dMeshRecord {
280    /// Mesh asset name.
281    pub(crate) name: String,
282    /// Default fallback `PbrMaterial`.
283    pub(crate) material: Euv3dLegacyPbrRecord,
284    /// Sub-material table.
285    pub(crate) sub_materials: Vec<Euv3dLegacyPbrRecord>,
286    /// Per-triangle sub-material slot indices for `LOD0`.
287    pub(crate) tri_materials: Vec<u16>,
288    /// Optional index into the scene `PrincipledMaterial3D` table.
289    pub(crate) material_index: Option<u32>,
290    /// Whether this mesh is a closed solid volume.
291    pub(crate) is_closed: bool,
292    /// Ordered LOD level records (`LOD0` first).
293    pub(crate) lods: Vec<Euv3dLodRecord>,
294    /// Starting index inside `SkinInfluences` for `LOD0`.
295    pub(crate) first_skin: u32,
296    /// Number of `MeshSkinInfluence3D` records for `LOD0`.
297    pub(crate) skin_count: u32,
298    /// Morph targets belonging to `LOD0`.
299    pub(crate) morphs: Vec<Euv3dMorphRecord>,
300}
301
302/// Serializable metadata record describing one pre-baked local BVH4 tree inside the BVH sections.
303#[derive(Clone, Debug, Deserialize, Serialize)]
304pub(crate) struct Euv3dBvhRecord {
305    /// First `Bvh4Node` index inside `Bvh4Nodes`.
306    pub(crate) first_node: u32,
307    /// Number of `Bvh4Node` entries.
308    pub(crate) node_count: u32,
309    /// First `BvhTri4` packet index inside `BvhTri4Packets`.
310    pub(crate) first_packet: u32,
311    /// Number of `BvhTri4` packets.
312    pub(crate) packet_count: u32,
313    /// First `BvhTriangle` index inside `BvhTriangles`.
314    pub(crate) first_tri: u32,
315    /// Number of `BvhTriangle` records.
316    pub(crate) tri_count: u32,
317    /// Cached root bounding box minimum corner.
318    pub(crate) root_min: [f32; 3],
319    /// Cached root bounding box maximum corner.
320    pub(crate) root_max: [f32; 3],
321    /// Baseline SAH build cost.
322    pub(crate) build_sah_cost: f32,
323}
324
325/// Serializable `TextureSlot3D` record for `PrincipledMaterial3D`.
326#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
327pub(crate) struct Euv3dTextureSlotRecord {
328    /// Index into scene texture array.
329    pub(crate) texture_index: u32,
330    /// UV set index (`0` or `1`).
331    pub(crate) tex_coord: u8,
332    /// UV offset.
333    pub(crate) offset: [f32; 2],
334    /// UV rotation in radians.
335    pub(crate) rotation: f32,
336    /// UV scale.
337    pub(crate) uv_scale: [f32; 2],
338}
339
340/// Serializable `PrincipledMaterial3D` record preserving every Blender Principled BSDF and KHR extension parameter.
341#[derive(Clone, Debug, Deserialize, Serialize)]
342pub(crate) struct Euv3dMaterialRecord {
343    /// Material name.
344    pub(crate) name: String,
345    /// Base color RGBA.
346    pub(crate) base_color_factor: [f32; 4],
347    /// Metallic factor.
348    pub(crate) metallic_factor: f32,
349    /// Roughness factor.
350    pub(crate) roughness_factor: f32,
351    /// Normal map scale.
352    pub(crate) normal_scale: f32,
353    /// Occlusion strength.
354    pub(crate) occlusion_strength: f32,
355    /// Emissive factor RGB.
356    pub(crate) emissive_factor: [f32; 3],
357    /// Emissive strength multiplier.
358    pub(crate) emissive_strength: f32,
359    /// Index of refraction.
360    pub(crate) ior: f32,
361    /// Specular factor.
362    pub(crate) specular_factor: f32,
363    /// Specular color tint.
364    pub(crate) specular_color_factor: [f32; 3],
365    /// Clearcoat weight.
366    pub(crate) clearcoat_factor: f32,
367    /// Clearcoat roughness.
368    pub(crate) clearcoat_roughness_factor: f32,
369    /// Transmission weight.
370    pub(crate) transmission_factor: f32,
371    /// Volume thickness.
372    pub(crate) thickness_factor: f32,
373    /// Volume attenuation distance.
374    pub(crate) attenuation_distance: f32,
375    /// Volume attenuation color.
376    pub(crate) attenuation_color: [f32; 3],
377    /// Sheen color factor.
378    pub(crate) sheen_color_factor: [f32; 3],
379    /// Sheen roughness.
380    pub(crate) sheen_roughness_factor: f32,
381    /// Unlit flag.
382    pub(crate) unlit: bool,
383    /// Alpha mode discriminant (`0=Opaque`, `1=Mask`, `2=Blend`).
384    pub(crate) alpha_mode: u8,
385    /// Alpha cutoff threshold.
386    pub(crate) alpha_cutoff: f32,
387    /// Double-sided flag.
388    pub(crate) double_sided: bool,
389    /// Base color texture slot.
390    pub(crate) base_color_texture: Option<Euv3dTextureSlotRecord>,
391    /// Metallic-roughness texture slot.
392    pub(crate) metallic_roughness_texture: Option<Euv3dTextureSlotRecord>,
393    /// Normal map texture slot.
394    pub(crate) normal_texture: Option<Euv3dTextureSlotRecord>,
395    /// Occlusion texture slot.
396    pub(crate) occlusion_texture: Option<Euv3dTextureSlotRecord>,
397    /// Emissive texture slot.
398    pub(crate) emissive_texture: Option<Euv3dTextureSlotRecord>,
399    /// Specular factor texture slot.
400    pub(crate) specular_texture: Option<Euv3dTextureSlotRecord>,
401    /// Specular color texture slot.
402    pub(crate) specular_color_texture: Option<Euv3dTextureSlotRecord>,
403    /// Clearcoat texture slot.
404    pub(crate) clearcoat_texture: Option<Euv3dTextureSlotRecord>,
405    /// Clearcoat roughness texture slot.
406    pub(crate) clearcoat_roughness_texture: Option<Euv3dTextureSlotRecord>,
407    /// Clearcoat normal texture slot.
408    pub(crate) clearcoat_normal_texture: Option<Euv3dTextureSlotRecord>,
409    /// Transmission texture slot.
410    pub(crate) transmission_texture: Option<Euv3dTextureSlotRecord>,
411    /// Sheen color texture slot.
412    pub(crate) sheen_color_texture: Option<Euv3dTextureSlotRecord>,
413    /// Sheen roughness texture slot.
414    pub(crate) sheen_roughness_texture: Option<Euv3dTextureSlotRecord>,
415}
416
417/// Serializable texture mip level byte range inside `TexturesBlob`, `TextureMipTails`, or `TextureMipHigh`.
418#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
419pub(crate) struct Euv3dTexMipRecord {
420    /// Mip width in pixels.
421    pub(crate) width: u32,
422    /// Mip height in pixels.
423    pub(crate) height: u32,
424    /// Byte offset inside the backing texture section.
425    pub(crate) byte_offset: u64,
426    /// Byte length inside the backing texture section.
427    pub(crate) byte_length: u64,
428    /// `true` when stored inside the contiguous `.euv3d` v2 `TextureMipTails` section (`<= 32x32`).
429    #[serde(default)]
430    pub(crate) is_mip_tail: bool,
431}
432
433/// Serializable texture descriptor referencing RGBA8 mip slices inside `TexturesBlob`.
434#[derive(Clone, Debug, Deserialize, Serialize)]
435pub(crate) struct Euv3dTextureRecord {
436    /// Texture name.
437    pub(crate) name: String,
438    /// Color space (`0=Srgb`, `1=Linear`, `2=NormalTangent`).
439    pub(crate) color_space: u8,
440    /// Min filter (`0=Nearest`, `1=Linear`).
441    pub(crate) min_filter: u8,
442    /// Mag filter (`0=Nearest`, `1=Linear`).
443    pub(crate) mag_filter: u8,
444    /// Wrap S (`0=Repeat`, `1=MirroredRepeat`, `2=ClampToEdge`).
445    pub(crate) wrap_s: u8,
446    /// Wrap T (`0=Repeat`, `1=MirroredRepeat`, `2=ClampToEdge`).
447    pub(crate) wrap_t: u8,
448    /// Encoded mip levels.
449    pub(crate) mips: Vec<Euv3dTexMipRecord>,
450}
451
452/// Serializable scene node descriptor matching `SceneNode3D`.
453#[derive(Clone, Debug, Deserialize, Serialize)]
454pub(crate) struct Euv3dNodeRecord {
455    /// Node name.
456    pub(crate) name: String,
457    /// Parent index.
458    pub(crate) parent: Option<u32>,
459    /// Local translation.
460    pub(crate) translation: [f32; 3],
461    /// Local rotation quaternion `[x, y, z, w]`.
462    pub(crate) rotation: [f32; 4],
463    /// Local scale.
464    pub(crate) scale: [f32; 3],
465    /// Optional mesh reference.
466    pub(crate) mesh_id: Option<u32>,
467    /// Optional skin reference.
468    pub(crate) skin_id: Option<u32>,
469    /// Optional camera reference.
470    pub(crate) camera_id: Option<u32>,
471    /// Optional light reference.
472    pub(crate) light_id: Option<u32>,
473    /// Collection membership bitmask.
474    pub(crate) collection_mask: u64,
475    /// Node visibility flag.
476    pub(crate) visible: bool,
477    /// Initial morph weights.
478    pub(crate) morph_weights: Vec<f32>,
479    /// `extras.euv` collider kind (`0=None, 1=Box, 2=Sphere, 3=ConvexHull, 4=Mesh`).
480    pub(crate) collider_shape: u8,
481    /// Fluid buoyancy density ratio.
482    pub(crate) buoyancy_density: f32,
483    /// Trigger volume flag.
484    pub(crate) is_trigger: bool,
485    /// Cast shadow flag.
486    pub(crate) cast_shadows: bool,
487    /// Raw custom JSON payload.
488    pub(crate) custom_json: Option<String>,
489}
490
491/// Serializable collection entry matching `CollectionEntry3D`.
492#[derive(Clone, Debug, Deserialize, Serialize)]
493pub(crate) struct Euv3dCollectionRecord {
494    /// Collection name.
495    pub(crate) name: String,
496    /// Bit index (`0..64`).
497    pub(crate) bit_index: u8,
498    /// Viewport visibility flag.
499    pub(crate) visible_viewport: bool,
500    /// Render visibility flag.
501    pub(crate) visible_render: bool,
502}
503
504/// Serializable armature skin record matching `ImportedSkin3D`.
505#[derive(Clone, Debug, Deserialize, Serialize)]
506pub(crate) struct Euv3dSkinRecord {
507    /// Skin name.
508    pub(crate) name: String,
509    /// Joint node indices.
510    pub(crate) joints: Vec<u32>,
511    /// Optional skeleton root node index.
512    pub(crate) skeleton_root: Option<u32>,
513    /// Flattened column-major inverse bind matrices (`16` floats each).
514    pub(crate) inverse_bind_matrices: Vec<[f32; 16]>,
515}
516
517/// Serializable animation sampler record referencing `f32` ranges inside `AnimationsBlob`.
518#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
519pub(crate) struct Euv3dAnimSamplerRecord {
520    /// Starting `f32` element index for timestamps inside `AnimationsBlob`.
521    pub(crate) first_time: u32,
522    /// Count of keyframe timestamps.
523    pub(crate) time_count: u32,
524    /// Starting `f32` element index for values inside `AnimationsBlob`.
525    pub(crate) first_value: u32,
526    /// Count of flattened value floats.
527    pub(crate) value_count: u32,
528    /// Float stride per keyframe.
529    pub(crate) value_stride: u32,
530    /// Interpolation mode (`0=Step`, `1=Linear`, `2=CubicSpline`).
531    pub(crate) interpolation: u8,
532}
533
534/// Serializable animation channel record.
535#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
536pub(crate) struct Euv3dAnimChannelRecord {
537    /// Target node index.
538    pub(crate) target_node: u32,
539    /// Animated property (`0=Translation`, `1=Rotation`, `2=Scale`, `3=MorphWeights`).
540    pub(crate) path: u8,
541    /// Sampler index within the owning clip.
542    pub(crate) sampler_index: u32,
543}
544
545/// Serializable animation clip record.
546#[derive(Clone, Debug, Deserialize, Serialize)]
547pub(crate) struct Euv3dAnimClipRecord {
548    /// Clip name.
549    pub(crate) name: String,
550    /// Total duration in seconds.
551    pub(crate) duration_secs: f32,
552    /// Samplers belonging to this clip.
553    pub(crate) samplers: Vec<Euv3dAnimSamplerRecord>,
554    /// Channels belonging to this clip.
555    pub(crate) channels: Vec<Euv3dAnimChannelRecord>,
556}
557
558/// Serializable camera record matching `ImportedCamera3D`.
559#[derive(Clone, Debug, Deserialize, Serialize)]
560pub(crate) struct Euv3dCameraRecord {
561    /// Camera label.
562    pub(crate) name: String,
563    /// `true` for perspective, `false` for orthographic.
564    pub(crate) is_perspective: bool,
565    /// Vertical FOV (perspective) or X magnification (orthographic).
566    pub(crate) param_a: f32,
567    /// Aspect ratio (perspective, optional encoded via `> 0.0`) or Y magnification (orthographic).
568    pub(crate) param_b: f32,
569    /// Near clipping plane.
570    pub(crate) znear: f32,
571    /// Optional far clipping plane.
572    pub(crate) zfar: Option<f32>,
573}
574
575/// Serializable light record matching `ImportedLight3D`.
576#[derive(Clone, Debug, Deserialize, Serialize)]
577pub(crate) struct Euv3dLightRecord {
578    /// Light label.
579    pub(crate) name: String,
580    /// Linear RGB color.
581    pub(crate) color: [f32; 3],
582    /// Intensity scalar.
583    pub(crate) intensity: f32,
584    /// Kind tag (`0=Directional`, `1=Point`, `2=Spot`, `3=Area`).
585    pub(crate) kind: u8,
586    /// Optional attenuation range (Point/Spot).
587    pub(crate) range: Option<f32>,
588    /// Inner cone angle (Spot) or Width (Area).
589    pub(crate) param_a: f32,
590    /// Outer cone angle (Spot) or Height (Area).
591    pub(crate) param_b: f32,
592}
593
594/// Top-level JSON metadata structure stored in the `.euv3d` `SceneMetadataJson` section.
595#[derive(Clone, Debug, Deserialize, Serialize)]
596pub(crate) struct Euv3dSceneMetadata {
597    /// Scene name.
598    pub(crate) name: String,
599    /// Source generator string.
600    pub(crate) generator: String,
601    /// Scene collections.
602    pub(crate) collections: Vec<Euv3dCollectionRecord>,
603    /// Scene graph nodes.
604    pub(crate) nodes: Vec<Euv3dNodeRecord>,
605    /// Baked meshes and LOD chains.
606    pub(crate) meshes: Vec<Euv3dMeshRecord>,
607    /// Pre-baked local BVH4 tree records aligned with `meshes`.
608    pub(crate) bvhs: Vec<Euv3dBvhRecord>,
609    /// Principled BSDF materials.
610    pub(crate) materials: Vec<Euv3dMaterialRecord>,
611    /// Mipmapped textures.
612    pub(crate) textures: Vec<Euv3dTextureRecord>,
613    /// Armature skins.
614    pub(crate) skins: Vec<Euv3dSkinRecord>,
615    /// Animation clips.
616    pub(crate) animations: Vec<Euv3dAnimClipRecord>,
617    /// Cameras.
618    pub(crate) cameras: Vec<Euv3dCameraRecord>,
619    /// Punctual & area lights.
620    pub(crate) lights: Vec<Euv3dLightRecord>,
621}