euv_core/game/engine3d/gltf/struct.rs
1use super::*;
2
3/// Deferred child scene node descriptor emitted when splitting multi-primitive glTF meshes.
4#[derive(Clone, Debug)]
5pub(crate) struct GltfExtraPrimChild {
6 /// Owning parent scene node index.
7 pub(crate) parent_id: u32,
8 /// Generated primitive child node name.
9 pub(crate) child_name: String,
10 /// Assigned mesh primitive index inside `ImportedScene3D::meshes`.
11 pub(crate) prim_mesh_id: u32,
12 /// Optional inherited skeletal skin index.
13 pub(crate) skin_id: Option<u32>,
14 /// Inherited Blender collection bitmask.
15 pub(crate) collection_mask: u64,
16 /// Inherited Blender extras tags.
17 pub(crate) extras: BlenderExtrasTags3D,
18 /// Inherited initial morph target weights.
19 pub(crate) morph_weights: Vec<f32>,
20}
21
22/// In-memory URI resolver for `.gltf` buffers and images (ideal for WASM and deterministic tests).
23#[derive(Clone, Data, Debug, Default, PartialEq)]
24pub struct MemoryGltfResolver {
25 /// Map of relative buffer URI strings to raw binary bytes.
26 pub(crate) buffers: HashMap<String, Vec<u8>>,
27 /// Map of relative image URI strings to encoded PNG/JPEG/BMP bytes.
28 pub(crate) images: HashMap<String, Vec<u8>>,
29}
30
31/// Filesystem directory URI resolver with canonical path-traversal guards for native `.gltf` loading.
32#[derive(Clone, Data, Debug, Default, PartialEq)]
33pub struct DirectoryGltfResolver {
34 /// Base directory containing the `.gltf` document.
35 pub(crate) base_dir: PathBuf,
36}
37
38/// Imported Blender Armature / glTF 2.0 skin binding joint node indices to inverse bind matrices.
39#[derive(Clone, Data, Debug, Default, PartialEq)]
40pub struct ImportedSkin3D {
41 /// Human-readable armature or skin name.
42 pub(crate) name: String,
43 /// Ordered joint node indices into `ImportedScene3D::scene_graph`.
44 pub(crate) joints: Vec<u32>,
45 /// Optional skeleton root node index.
46 #[get(type(copy))]
47 pub(crate) skeleton_root: Option<u32>,
48 /// Column-major inverse bind matrices aligned 1:1 with `joints`.
49 pub(crate) inverse_bind_matrices: Vec<Mat4>,
50}
51
52/// Single keyframe timeline sampler belonging to an `ImportedAnimationClip3D`.
53#[derive(Clone, Data, Debug, Default, PartialEq)]
54pub struct ImportedAnimationSampler3D {
55 /// Monotonic keyframe timestamps in seconds.
56 pub(crate) timestamps: Vec<f32>,
57 /// Flattened keyframe values (and cubic-spline in/out tangents when `CubicSpline`).
58 pub(crate) values: Vec<f32>,
59 /// Scalar floats per keyframe value (`3` for T/S, `4` for R, `morph_count` for Weights).
60 #[get(type(copy))]
61 pub(crate) value_stride: usize,
62 /// Interpolation mode (`Step`, `Linear`, `CubicSpline`).
63 #[get(type(copy))]
64 pub(crate) interpolation: GltfInterpolationMode,
65}
66
67/// Channel binding an `ImportedAnimationSampler3D` to a scene node property.
68#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
69pub struct ImportedAnimationChannel3D {
70 /// Target node index in `ImportedScene3D::scene_graph`.
71 #[get(type(copy))]
72 pub(crate) target_node: u32,
73 /// Animated node property (`Translation`, `Rotation`, `Scale`, `MorphWeights`).
74 #[get(type(copy))]
75 pub(crate) path: GltfAnimationPath,
76 /// Index into `ImportedAnimationClip3D::samplers`.
77 #[get(type(copy))]
78 pub(crate) sampler_index: usize,
79}
80
81/// Complete animation clip imported from a Blender Action / glTF 2.0 animation.
82#[derive(Clone, Data, Debug, Default, PartialEq)]
83pub struct ImportedAnimationClip3D {
84 /// Action or clip name.
85 pub(crate) name: String,
86 /// Maximum timestamp across all samplers in seconds.
87 #[get(type(copy))]
88 pub(crate) duration_secs: f32,
89 /// Timeline samplers referenced by `channels`.
90 pub(crate) samplers: Vec<ImportedAnimationSampler3D>,
91 /// Node-property animation channels.
92 pub(crate) channels: Vec<ImportedAnimationChannel3D>,
93}
94
95/// Camera asset imported from a Blender Camera / glTF 2.0 camera entry.
96#[derive(Clone, Data, Debug, PartialEq)]
97pub struct ImportedCamera3D {
98 /// Camera label.
99 pub(crate) name: String,
100 /// Perspective or orthographic projection parameters.
101 #[get(type(copy))]
102 pub(crate) projection: GltfCameraProjection,
103}
104
105/// Light asset imported from `KHR_lights_punctual` or Blender area-light extras.
106#[derive(Clone, Data, Debug, PartialEq)]
107pub struct ImportedLight3D {
108 /// Light label.
109 pub(crate) name: String,
110 /// Linear RGB emission color.
111 #[get(type(copy))]
112 pub(crate) color: Vec3,
113 /// Luminous intensity (candela for point/spot, lux for directional).
114 #[get(type(copy))]
115 pub(crate) intensity: f32,
116 /// Emitter geometry and falloff parameters.
117 #[get(type(copy))]
118 pub(crate) kind: GltfLightKind,
119}
120
121/// Complete imported Blender/glTF 2.0 scene bundle with hierarchy, meshes, Principled BSDF materials, textures, rigs, animations, cameras, and lights.
122#[derive(Clone, Data, Debug, Default, PartialEq)]
123pub struct ImportedScene3D {
124 /// Scene or model name.
125 pub(crate) name: String,
126 /// Exporting tool generator string (e.g., `"Khronos glTF Blender I/O"`).
127 pub(crate) generator: String,
128 /// Hierarchical scene graph with Collections and propagated world matrices.
129 pub(crate) scene_graph: SceneGraph3D,
130 /// Flat mesh primitive list referenced by `SceneNode3D::mesh_id`.
131 pub(crate) meshes: Vec<Mesh3D>,
132 /// Principled BSDF material table referenced by `Mesh3D::material_index`.
133 pub(crate) materials: Vec<PrincipledMaterial3D>,
134 /// Decoded mipmapped texture pool referenced by `TextureSlot3D::texture_index`.
135 pub(crate) textures: Vec<Texture2D3D>,
136 /// Imported armature skins referenced by `SceneNode3D::skin_id`.
137 pub(crate) skins: Vec<ImportedSkin3D>,
138 /// Imported Blender Actions / glTF animation clips.
139 pub(crate) animations: Vec<ImportedAnimationClip3D>,
140 /// Imported cameras referenced by `SceneNode3D::camera_id`.
141 pub(crate) cameras: Vec<ImportedCamera3D>,
142 /// Imported punctual and area lights referenced by `SceneNode3D::light_id`.
143 pub(crate) lights: Vec<ImportedLight3D>,
144}
145
146/// Extracted `KHR_materials_anisotropy` and `KHR_materials_iridescence` PBR extension parameters for a glTF 2.0 material.
147#[derive(Clone, Data, Debug, Default, PartialEq)]
148pub struct GltfMaterialExtensionData {
149 /// Owning material name.
150 pub(crate) name: String,
151 /// `KHR_materials_anisotropy` strength in `[0.0, 1.0]`.
152 #[get(type(copy))]
153 pub(crate) anisotropy_strength: f32,
154 /// `KHR_materials_anisotropy` tangent rotation in radians.
155 #[get(type(copy))]
156 pub(crate) anisotropy_rotation: f32,
157 /// Optional `KHR_materials_anisotropy` tangent/strength texture slot.
158 #[get(type(copy))]
159 pub(crate) anisotropy_texture: Option<TextureSlot3D>,
160 /// `KHR_materials_iridescence` thin-film interference factor in `[0.0, 1.0]`.
161 #[get(type(copy))]
162 pub(crate) iridescence_factor: f32,
163 /// `KHR_materials_iridescence` thin-film index of refraction (default `1.3`).
164 #[get(type(copy))]
165 pub(crate) iridescence_ior: f32,
166 /// `KHR_materials_iridescence` minimum thin-film thickness in nanometers (default `100.0`).
167 #[get(type(copy))]
168 pub(crate) iridescence_thickness_min: f32,
169 /// `KHR_materials_iridescence` maximum thin-film thickness in nanometers (default `400.0`).
170 #[get(type(copy))]
171 pub(crate) iridescence_thickness_max: f32,
172 /// Optional `KHR_materials_iridescence` factor texture slot.
173 #[get(type(copy))]
174 pub(crate) iridescence_texture: Option<TextureSlot3D>,
175 /// Optional `KHR_materials_iridescence` thickness texture slot.
176 #[get(type(copy))]
177 pub(crate) iridescence_thickness_texture: Option<TextureSlot3D>,
178}