euv_core/game/engine3d/gltf/struct.rs
1use super::*;
2
3/// In-memory URI resolver for `.gltf` buffers and images (ideal for WASM and deterministic tests).
4#[derive(Clone, Data, Debug, Default, PartialEq)]
5pub struct MemoryGltfResolver {
6 /// Map of relative buffer URI strings to raw binary bytes.
7 pub(crate) buffers: HashMap<String, Vec<u8>>,
8 /// Map of relative image URI strings to encoded PNG/JPEG/BMP bytes.
9 pub(crate) images: HashMap<String, Vec<u8>>,
10}
11
12/// Filesystem directory URI resolver with canonical path-traversal guards for native `.gltf` loading.
13#[derive(Clone, Data, Debug, Default, PartialEq)]
14pub struct DirectoryGltfResolver {
15 /// Base directory containing the `.gltf` document.
16 pub(crate) base_dir: PathBuf,
17}
18
19/// Imported Blender Armature / glTF 2.0 skin binding joint node indices to inverse bind matrices.
20#[derive(Clone, Data, Debug, Default, PartialEq)]
21pub struct ImportedSkin3D {
22 /// Human-readable armature or skin name.
23 pub(crate) name: String,
24 /// Ordered joint node indices into `ImportedScene3D::scene_graph`.
25 pub(crate) joints: Vec<u32>,
26 /// Optional skeleton root node index.
27 #[get(type(copy))]
28 pub(crate) skeleton_root: Option<u32>,
29 /// Column-major inverse bind matrices aligned 1:1 with `joints`.
30 pub(crate) inverse_bind_matrices: Vec<Mat4>,
31}
32
33/// Single keyframe timeline sampler belonging to an `ImportedAnimationClip3D`.
34#[derive(Clone, Data, Debug, Default, PartialEq)]
35pub struct ImportedAnimationSampler3D {
36 /// Monotonic keyframe timestamps in seconds.
37 pub(crate) timestamps: Vec<f32>,
38 /// Flattened keyframe values (and cubic-spline in/out tangents when `CubicSpline`).
39 pub(crate) values: Vec<f32>,
40 /// Scalar floats per keyframe value (`3` for T/S, `4` for R, `morph_count` for Weights).
41 #[get(type(copy))]
42 pub(crate) value_stride: usize,
43 /// Interpolation mode (`Step`, `Linear`, `CubicSpline`).
44 #[get(type(copy))]
45 pub(crate) interpolation: GltfInterpolationMode,
46}
47
48/// Channel binding an `ImportedAnimationSampler3D` to a scene node property.
49#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
50pub struct ImportedAnimationChannel3D {
51 /// Target node index in `ImportedScene3D::scene_graph`.
52 #[get(type(copy))]
53 pub(crate) target_node: u32,
54 /// Animated node property (`Translation`, `Rotation`, `Scale`, `MorphWeights`).
55 #[get(type(copy))]
56 pub(crate) path: GltfAnimationPath,
57 /// Index into `ImportedAnimationClip3D::samplers`.
58 #[get(type(copy))]
59 pub(crate) sampler_index: usize,
60}
61
62/// Complete animation clip imported from a Blender Action / glTF 2.0 animation.
63#[derive(Clone, Data, Debug, Default, PartialEq)]
64pub struct ImportedAnimationClip3D {
65 /// Action or clip name.
66 pub(crate) name: String,
67 /// Maximum timestamp across all samplers in seconds.
68 #[get(type(copy))]
69 pub(crate) duration_secs: f32,
70 /// Timeline samplers referenced by `channels`.
71 pub(crate) samplers: Vec<ImportedAnimationSampler3D>,
72 /// Node-property animation channels.
73 pub(crate) channels: Vec<ImportedAnimationChannel3D>,
74}
75
76/// Camera asset imported from a Blender Camera / glTF 2.0 camera entry.
77#[derive(Clone, Data, Debug, PartialEq)]
78pub struct ImportedCamera3D {
79 /// Camera label.
80 pub(crate) name: String,
81 /// Perspective or orthographic projection parameters.
82 #[get(type(copy))]
83 pub(crate) projection: GltfCameraProjection,
84}
85
86/// Light asset imported from `KHR_lights_punctual` or Blender area-light extras.
87#[derive(Clone, Data, Debug, PartialEq)]
88pub struct ImportedLight3D {
89 /// Light label.
90 pub(crate) name: String,
91 /// Linear RGB emission color.
92 #[get(type(copy))]
93 pub(crate) color: Vec3,
94 /// Luminous intensity (candela for point/spot, lux for directional).
95 #[get(type(copy))]
96 pub(crate) intensity: f32,
97 /// Emitter geometry and falloff parameters.
98 #[get(type(copy))]
99 pub(crate) kind: GltfLightKind,
100}
101
102/// Complete imported Blender/glTF 2.0 scene bundle with hierarchy, meshes, Principled BSDF materials, textures, rigs, animations, cameras, and lights.
103#[derive(Clone, Data, Debug, Default, PartialEq)]
104pub struct ImportedScene3D {
105 /// Scene or model name.
106 pub(crate) name: String,
107 /// Exporting tool generator string (e.g., `"Khronos glTF Blender I/O"`).
108 pub(crate) generator: String,
109 /// Hierarchical scene graph with Collections and propagated world matrices.
110 pub(crate) scene_graph: SceneGraph3D,
111 /// Flat mesh primitive list referenced by `SceneNode3D::mesh_id`.
112 pub(crate) meshes: Vec<Mesh3D>,
113 /// Principled BSDF material table referenced by `Mesh3D::material_index`.
114 pub(crate) materials: Vec<PrincipledMaterial3D>,
115 /// Decoded mipmapped texture pool referenced by `TextureSlot3D::texture_index`.
116 pub(crate) textures: Vec<Texture2D3D>,
117 /// Imported armature skins referenced by `SceneNode3D::skin_id`.
118 pub(crate) skins: Vec<ImportedSkin3D>,
119 /// Imported Blender Actions / glTF animation clips.
120 pub(crate) animations: Vec<ImportedAnimationClip3D>,
121 /// Imported cameras referenced by `SceneNode3D::camera_id`.
122 pub(crate) cameras: Vec<ImportedCamera3D>,
123 /// Imported punctual and area lights referenced by `SceneNode3D::light_id`.
124 pub(crate) lights: Vec<ImportedLight3D>,
125}