euv_core/game/engine3d/scene_graph/struct.rs
1use super::*;
2
3/// Blender `extras.euv` metadata attached to a `SceneNode3D` for physics, water buoyancy, and gameplay tags.
4#[derive(Clone, Data, Debug, PartialEq)]
5pub struct BlenderExtrasTags3D {
6 /// Physics collider classification.
7 #[get(type(copy))]
8 pub(crate) collider: SceneColliderShape3D,
9 /// Fluid buoyancy density ratio (`0.0` = disabled, `< 1.0` floats on water).
10 #[get(type(copy))]
11 pub(crate) buoyancy_density: f32,
12 /// Whether this node acts as a non-solid trigger volume.
13 #[get(type(copy))]
14 pub(crate) is_trigger: bool,
15 /// Whether this node casts directional or local shadows.
16 #[get(type(copy))]
17 pub(crate) cast_shadows: bool,
18 /// Raw custom JSON properties preserved verbatim from Blender `extras`.
19 pub(crate) custom_json: Option<String>,
20}
21
22/// Single named Blender Collection entry mapped to a visibility bit in `CollectionRegistry3D`.
23#[derive(Clone, Data, Debug, PartialEq)]
24pub struct CollectionEntry3D {
25 /// Human-readable Blender collection name.
26 pub(crate) name: String,
27 /// Assigned bit position (`0..64`).
28 #[get(type(copy))]
29 pub(crate) bit_index: u8,
30 /// Whether this collection is visible in the interactive viewport.
31 #[get(type(copy))]
32 pub(crate) visible_viewport: bool,
33 /// Whether this collection is enabled for final renders.
34 #[get(type(copy))]
35 pub(crate) visible_render: bool,
36}
37
38/// Registry mapping Blender Collections to a 64-bit visibility bitmask for O(1) culling checks.
39#[derive(Clone, Data, Debug, PartialEq)]
40pub struct CollectionRegistry3D {
41 /// Ordered collection descriptors (`len <= 64`).
42 pub(crate) entries: Vec<CollectionEntry3D>,
43 /// Precomputed bitmask of collections currently visible in viewport (`1 << bit_index`).
44 #[get(type(copy))]
45 pub(crate) active_mask: u64,
46}
47
48/// Hierarchical scene node storing local quaternion TRS, cached world matrices, collection bits, and component links.
49#[derive(Clone, Data, Debug, PartialEq)]
50pub struct SceneNode3D {
51 /// Human-readable node or Blender object name.
52 pub(crate) name: String,
53 /// Optional parent node index inside `SceneGraph3D::nodes`.
54 #[get(type(copy))]
55 pub(crate) parent: Option<u32>,
56 /// Topological tree depth (`0` = root).
57 #[get(type(copy))]
58 pub(crate) depth: u16,
59 /// Local translation relative to parent.
60 #[get(type(copy))]
61 pub(crate) local_translation: Vec3,
62 /// Local unit quaternion rotation relative to parent.
63 #[get(type(copy))]
64 pub(crate) local_rotation: Quat,
65 /// Local non-uniform scale relative to parent.
66 #[get(type(copy))]
67 pub(crate) local_scale: Vec3,
68 /// Cached current-frame local-to-world transformation matrix.
69 #[get(type(copy))]
70 pub(crate) world_matrix: Mat4,
71 /// Previous-frame local-to-world matrix for motion vectors and TSR reprojection.
72 #[get(type(copy))]
73 pub(crate) prev_world_matrix: Mat4,
74 /// Bitmask of Blender Collections containing this node (`bit 0` = root collection).
75 #[get(type(copy))]
76 pub(crate) collection_mask: u64,
77 /// Explicit per-node visibility toggle.
78 #[get(type(copy))]
79 pub(crate) visible: bool,
80 /// Optional mesh asset index attached to this node.
81 #[get(type(copy))]
82 pub(crate) mesh_id: Option<u32>,
83 /// Optional skeletal skin index attached to this node.
84 #[get(type(copy))]
85 pub(crate) skin_id: Option<u32>,
86 /// Optional camera index attached to this node.
87 #[get(type(copy))]
88 pub(crate) camera_id: Option<u32>,
89 /// Optional punctual/area light index attached to this node.
90 #[get(type(copy))]
91 pub(crate) light_id: Option<u32>,
92 /// First morph weight index inside `SceneGraph3D::morph_weights`.
93 #[get(type(copy))]
94 pub(crate) morph_weight_offset: u32,
95 /// Number of shape-key morph weights owned by this node.
96 #[get(type(copy))]
97 pub(crate) morph_weight_count: u16,
98 /// Imported Blender custom properties and gameplay tags.
99 pub(crate) extras: BlenderExtrasTags3D,
100}
101
102/// Flat depth-sorted 3D scene graph with zero-allocation dirty-bitset world-matrix propagation and Blender Collections.
103#[derive(Clone, Data, Debug, PartialEq)]
104pub struct SceneGraph3D {
105 /// Arena of all scene nodes indexed by node ID.
106 pub(crate) nodes: Vec<SceneNode3D>,
107 /// Depth-sorted topological traversal order guaranteeing parents precede children.
108 pub(crate) topo_order: Vec<u32>,
109 /// Bitset marking nodes whose local or inherited world transforms require recomputation.
110 pub(crate) dirty_words: Vec<u64>,
111 /// Flat contiguous shape-key morph target weight storage across all nodes.
112 pub(crate) morph_weights: Vec<f32>,
113 /// Registered Blender Collections and active visibility bitmask.
114 pub(crate) collections: CollectionRegistry3D,
115 /// Whether `topo_order` must be refreshed before propagation.
116 #[get(type(copy))]
117 pub(crate) topology_dirty: bool,
118 /// Monotonic revision incremented whenever transforms or hierarchy change.
119 #[get(type(copy))]
120 pub(crate) revision: u64,
121}