Skip to main content

euv_core/game/engine3d/world/
struct.rs

1use super::*;
2
3/// 3D world-space transform (translation, yaw/pitch/roll Euler rotation, and non-uniform scale).
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct Transform3D {
6    /// World-space translation `(x, y, z)`.
7    #[get(type(copy))]
8    pub(crate) position: Vec3,
9    /// Horizontal Y-axis yaw rotation in radians.
10    #[get(type(copy))]
11    pub(crate) yaw_rad: f32,
12    /// Vertical X-axis pitch rotation in radians.
13    #[get(type(copy))]
14    pub(crate) pitch_rad: f32,
15    /// Longitudinal Z-axis roll rotation in radians.
16    #[get(type(copy))]
17    pub(crate) roll_rad: f32,
18    /// Scale multiplier along `(x, y, z)`.
19    #[get(type(copy))]
20    pub(crate) scale: Vec3,
21}
22
23/// Fluent descriptor for spawning a `SceneObject3D` into `World3D`.
24#[derive(Clone, Data, Debug, PartialEq)]
25pub struct SpawnObjectDesc {
26    /// Human-readable object label.
27    pub(crate) name: String,
28    /// Registered mesh identifier from `World3D::register_mesh`.
29    #[get(type(copy))]
30    pub(crate) mesh_id: usize,
31    /// World-space TRS transform.
32    #[get(type(copy))]
33    pub(crate) transform: Transform3D,
34    /// Surface PBR material.
35    #[get(type(copy))]
36    pub(crate) material: PbrMaterial,
37    /// Whether this object casts ray-traced shadows and appears in BVH reflections.
38    #[get(type(copy))]
39    pub(crate) ray_trace_caster: bool,
40    /// Continuous spin speed in radians/sec.
41    #[get(type(copy))]
42    pub(crate) spin_speed: f32,
43    /// Whether this object moves dynamically and belongs in the incrementally refitted dynamic BVH.
44    #[get(type(copy))]
45    pub(crate) is_dynamic: bool,
46}
47
48/// Fluent descriptor for importing a 3D `.obj` or `.gltf` model into `World3D`.
49#[derive(Clone, Data, Debug, PartialEq)]
50pub struct ImportModelDesc {
51    /// Source model interchange format.
52    #[get(type(copy))]
53    pub(crate) format: ModelFormat,
54    /// Raw `.obj` or `.gltf` text content.
55    pub(crate) source: String,
56    /// World-space placement transform.
57    #[get(type(copy))]
58    pub(crate) transform: Transform3D,
59    /// Fallback PBR material when source omits material definitions.
60    #[get(type(copy))]
61    pub(crate) fallback_material: PbrMaterial,
62    /// Optional continuous Y-spin speed in radians/sec.
63    #[get(type(copy))]
64    pub(crate) spin_speed: f32,
65}
66
67/// Instanced 3D scene object placed inside an open-world chunk.
68#[derive(Clone, Data, Debug, PartialEq)]
69pub struct SceneObject3D {
70    /// Human-readable object label.
71    pub(crate) name: String,
72    /// Index into `World3D::mesh_library` enabling GPU instancing batching.
73    #[get(type(copy))]
74    pub(crate) mesh_id: usize,
75    /// World-space TRS transform.
76    #[get(type(copy))]
77    pub(crate) transform: Transform3D,
78    /// Material override (or default mesh material).
79    #[get(type(copy))]
80    pub(crate) material: PbrMaterial,
81    /// Cached world-space AABB for O(1) frustum culling and chunk streaming.
82    #[get(type(copy))]
83    pub(crate) world_bounds: Aabb3D,
84    /// Spatial open-world chunk coordinate `(chunk_x, chunk_z)`.
85    #[get(type(copy))]
86    pub(crate) chunk_coord: (i32, i32),
87    /// Whether this object casts ray-traced shadows and appears in BVH reflections.
88    #[get(type(copy))]
89    pub(crate) ray_trace_caster: bool,
90    /// Continuous spin speed in radians/sec for animated hero models or props.
91    #[get(type(copy))]
92    pub(crate) spin_speed: f32,
93    /// Whether this object belongs to the dynamic incrementally-refitted BVH rather than the static world BVH.
94    #[get(type(copy))]
95    pub(crate) is_dynamic: bool,
96    /// Discontinuity counter incremented on teleports so snapshot interpolation snaps cleanly.
97    #[get(type(copy))]
98    pub(crate) teleport_epoch: u32,
99}
100
101/// Primary sun/moon directional light and atmospheric sky parameters.
102#[derive(Clone, Copy, Data, Debug, PartialEq)]
103pub struct DirectionalLight3D {
104    /// Normalized direction pointing toward the sun.
105    #[get(type(copy))]
106    pub(crate) direction: Vec3,
107    /// Linear HDR sun radiance color.
108    #[get(type(copy))]
109    pub(crate) color: Vec3,
110    /// Ambient sky zenith color.
111    #[get(type(copy))]
112    pub(crate) sky_zenith: Vec3,
113    /// Ambient sky horizon and volumetric fog color.
114    #[get(type(copy))]
115    pub(crate) sky_horizon: Vec3,
116    /// Time of day in `[0.0, 24.0]` hours.
117    #[get(type(copy))]
118    pub(crate) time_of_day: f32,
119}
120
121/// Complete open-world 3D scene graph with mesh instancing library, chunk streaming, and BVH acceleration.
122#[derive(Clone, Data, Debug)]
123pub struct World3D {
124    /// Shared LOD mesh asset library referenced by `SceneObject3D::mesh_id`.
125    pub(crate) mesh_library: Vec<MeshLodChain>,
126    /// All world objects partitioned into open-world chunks.
127    pub(crate) objects: Vec<SceneObject3D>,
128    /// Active 3D perspective camera.
129    #[get(type(copy))]
130    pub(crate) camera: Camera3D,
131    /// Active directional sun/sky lighting.
132    #[get(type(copy))]
133    pub(crate) sun: DirectionalLight3D,
134    /// Flat BVH built over static world-space ray-trace casters (rebuilt only on static geometry edits).
135    pub(crate) bvh: Bvh3D,
136    /// Separate flat BVH over moving/dynamic ray-trace casters supporting O(N) incremental bottom-up refits.
137    pub(crate) dynamic_bvh: Bvh3D,
138    /// Dirty flag triggering static BVH rebuild when static casters are added or modified.
139    #[get(type(copy))]
140    pub(crate) bvh_dirty: bool,
141    /// Dirty flag triggering dynamic BVH incremental refit or rebuild when moving casters update.
142    #[get(type(copy))]
143    pub(crate) dynamic_bvh_dirty: bool,
144    /// Topology change flag forcing a fresh dynamic BVH SAH build rather than an in-place refit.
145    #[get(type(copy))]
146    pub(crate) dynamic_topology_dirty: bool,
147    /// Total static BVH full rebuilds executed.
148    #[get(type(copy))]
149    pub(crate) static_bvh_rebuilds: u64,
150    /// Total zero-allocation incremental dynamic BVH refits executed.
151    #[get(type(copy))]
152    pub(crate) dynamic_bvh_refits: u64,
153    /// Total full dynamic BVH rebuilds executed (topology changes or SAH quality resets).
154    #[get(type(copy))]
155    pub(crate) dynamic_bvh_rebuilds: u64,
156    /// Monotonic revision incremented only when 3D world transforms, camera, or lighting change (isolated from HUD dirtiness).
157    #[get(type(copy))]
158    pub(crate) world_revision: u64,
159    /// Reusable scratch buffer holding transformed dynamic caster triangles during incremental BVH refits.
160    #[get(skip)]
161    #[get_mut(skip)]
162    #[set(skip)]
163    pub(crate) dynamic_tris_scratch: Vec<BvhTriangle>,
164    /// Open-world chunk size in meters (`64.0m` per city block).
165    #[get(type(copy))]
166    pub(crate) chunk_size: f32,
167    /// Index of the drivable player vehicle object if spawned.
168    #[get(skip)]
169    pub(crate) player_vehicle_index: Option<usize>,
170    /// Total imported external 3D models (`.obj` / `.gltf`).
171    #[get(type(copy))]
172    pub(crate) imported_model_count: usize,
173    /// Active 3D camera mode index (`0=Chase`, `1=Hood`, `2=Orbit`, `3=Aerial`, `4=FreeFly`, `5=CinematicDolly`).
174    #[get(type(copy))]
175    pub(crate) camera_mode: u8,
176    /// Continuous orbit angle in radians used for `Orbit` and `CinematicDolly` modes.
177    #[get(type(copy))]
178    pub(crate) camera_orbit_rad: f32,
179}