euv-core 0.57.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
use super::*;

/// Gimbal-lock-free 3D world-space transform backed by a unit Hamilton quaternion (`position`, `rotation`, `scale`).
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct Transform3D {
    /// World-space translation `(x, y, z)`.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Unit Hamilton quaternion orientation `(x, y, z, w)`.
    #[get(type(copy))]
    pub(crate) rotation: Quat,
    /// Scale multiplier along `(x, y, z)`.
    #[get(type(copy))]
    pub(crate) scale: Vec3,
}

/// Multi-camera scene registry entry supporting both Perspective and Orthographic Blender/glTF cameras.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct SceneCamera3D {
    /// Human-readable camera label.
    pub(crate) name: String,
    /// Optional owning node index inside `World3D::scene_graph`.
    #[get(type(copy))]
    pub(crate) node_id: Option<u32>,
    /// World-space camera eye position.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// World-space camera orientation quaternion (glTF camera looks along local `-Z`, up `+Y`).
    #[get(type(copy))]
    pub(crate) rotation: Quat,
    /// Perspective or orthographic projection parameters.
    #[get(type(copy))]
    pub(crate) projection: GltfCameraProjection,
}

/// Fluent descriptor for spawning a `SceneObject3D` into `World3D`.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct SpawnObjectDesc {
    /// Human-readable object label.
    pub(crate) name: String,
    /// Registered mesh identifier from `World3D::register_mesh`.
    #[get(type(copy))]
    pub(crate) mesh_id: usize,
    /// World-space TRS transform.
    #[get(type(copy))]
    pub(crate) transform: Transform3D,
    /// Surface PBR material.
    #[get(type(copy))]
    pub(crate) material: PbrMaterial,
    /// Whether this object casts ray-traced shadows and appears in BVH reflections.
    #[get(type(copy))]
    pub(crate) ray_trace_caster: bool,
    /// Whether this object participates in solid vehicle and camera collision detection.
    #[get(type(copy))]
    pub(crate) solid_collider: bool,
    /// Continuous spin speed in radians/sec.
    #[get(type(copy))]
    pub(crate) spin_speed: f32,
    /// Whether this object moves dynamically and belongs in the incrementally refitted dynamic BVH.
    #[get(type(copy))]
    pub(crate) is_dynamic: bool,
}

/// Fluent descriptor for importing a 3D `.obj` or `.gltf` model into `World3D`.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct ImportModelDesc {
    /// Source model interchange format.
    #[get(type(copy))]
    pub(crate) format: ModelFormat,
    /// Raw `.obj` or `.gltf` text content.
    pub(crate) source: String,
    /// World-space placement transform.
    #[get(type(copy))]
    pub(crate) transform: Transform3D,
    /// Fallback PBR material when source omits material definitions.
    #[get(type(copy))]
    pub(crate) fallback_material: PbrMaterial,
    /// Optional continuous Y-spin speed in radians/sec.
    #[get(type(copy))]
    pub(crate) spin_speed: f32,
}

/// Instanced 3D scene object placed inside an open-world chunk.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct SceneObject3D {
    /// Human-readable object label.
    pub(crate) name: String,
    /// Index into `World3D::mesh_library` enabling GPU instancing batching.
    #[get(type(copy))]
    pub(crate) mesh_id: usize,
    /// World-space TRS transform.
    #[get(type(copy))]
    pub(crate) transform: Transform3D,
    /// Material override (or default mesh material).
    #[get(type(copy))]
    pub(crate) material: PbrMaterial,
    /// Cached world-space axis-aligned bounding box for O(1) frustum culling and chunk streaming.
    #[get(type(copy))]
    pub(crate) world_bounds: AxisAlignedBox3D,
    /// Spatial open-world chunk coordinate `(chunk_x, chunk_z)`.
    #[get(type(copy))]
    pub(crate) chunk_coord: (i32, i32),
    /// Whether this object casts ray-traced shadows and appears in BVH reflections.
    #[get(type(copy))]
    pub(crate) ray_trace_caster: bool,
    /// Whether this object participates in solid vehicle and camera collision detection.
    #[get(type(copy))]
    pub(crate) solid_collider: bool,
    /// Continuous spin speed in radians/sec for animated hero models or props.
    #[get(type(copy))]
    pub(crate) spin_speed: f32,
    /// Whether this object belongs to the dynamic incrementally-refitted BVH rather than the static world BVH.
    #[get(type(copy))]
    pub(crate) is_dynamic: bool,
    /// Discontinuity counter incremented on teleports so snapshot interpolation snaps cleanly.
    #[get(type(copy))]
    pub(crate) teleport_epoch: u32,
    /// Optional owning hierarchical node index inside `World3D::scene_graph`.
    #[get(type(copy))]
    pub(crate) node_id: Option<u32>,
    /// Optional index into `World3D::principled_materials` for full Principled BSDF shading.
    #[get(type(copy))]
    pub(crate) principled_material_id: Option<u32>,
    /// Optional index into `World3D::skins` for armature LBS/DQS vertex deformation.
    #[get(type(copy))]
    pub(crate) skin_id: Option<u32>,
}

/// Primary sun/moon directional light and atmospheric sky parameters.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct DirectionalLight3D {
    /// Normalized direction pointing toward the sun.
    #[get(type(copy))]
    pub(crate) direction: Vec3,
    /// Linear HDR sun radiance color.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Ambient sky zenith color.
    #[get(type(copy))]
    pub(crate) sky_zenith: Vec3,
    /// Ambient sky horizon and volumetric fog color.
    #[get(type(copy))]
    pub(crate) sky_horizon: Vec3,
    /// Time of day in `[0.0, 24.0]` hours.
    #[get(type(copy))]
    pub(crate) time_of_day: f32,
}

/// Oriented bounding box in 3D space used for tight rotated collider narrow-phase tests.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct OrientedBox3D {
    /// Box center position in target coordinate space.
    #[get(type(copy))]
    pub(crate) center: Vec3,
    /// Orthonormal local X, Y, and Z basis axes.
    #[get(type(copy))]
    pub(crate) axes: [Vec3; 3],
    /// Positive half-extents along each local axis.
    #[get(type(copy))]
    pub(crate) half_extents: Vec3,
}

/// Real-mesh narrow-phase collision contact reported against a solid `SceneObject3D` triangle.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct MeshCollisionHit3D {
    /// Colliding obstacle index inside `World3D::objects`.
    #[get(type(copy))]
    pub(crate) object_index: usize,
    /// Unit world-space separation normal pointing toward the moving collider.
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Positive penetration depth along `normal` in meters.
    #[get(type(copy))]
    pub(crate) penetration: f32,
    /// World-space contact point on the colliding triangle surface.
    #[get(type(copy))]
    pub(crate) contact_point: Vec3,
}

/// Interactive raycast scene picking result returned by `World3D::pick_object_ray`.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct ScenePickHit3D {
    /// Picked object index inside `World3D::objects`.
    #[get(type(copy))]
    pub(crate) object_index: usize,
    /// Registered mesh identifier of the picked object.
    #[get(type(copy))]
    pub(crate) mesh_id: usize,
    /// Ray distance from the camera origin to the intersection point in meters.
    #[get(type(copy))]
    pub(crate) distance: f32,
    /// World-space intersection point on the picked object.
    #[get(type(copy))]
    pub(crate) world_position: Vec3,
    /// Outward world-space surface normal at the intersection point.
    #[get(type(copy))]
    pub(crate) world_normal: Vec3,
}

/// Object-space raytracing instance descriptor enabling exact interpolated dynamic shadows and reflections with zero BVH rebuilds per VSync.
#[derive(Clone, Copy, Debug)]
pub(crate) struct DynamicRayInstance {
    /// Owning scene object index in `World3D::objects`.
    pub(crate) obj_idx: usize,
    /// Registered mesh index referencing `World3D::mesh_local_bvhs`.
    pub(crate) mesh_id: usize,
    /// World-space axis-aligned bounding box for O(1) miss rejection before transforming rays into object space.
    pub(crate) world_bounds: AxisAlignedBox3D,
    /// Exact analytical inverse model matrix (`S^-1 * R^T * T^-1`) mapping world rays to local space.
    pub(crate) inv_model: Mat4,
    /// Inverse-transpose 3x3 normal basis mapping local hit normals back to world space.
    pub(crate) normal_basis: [Vec3; 3],
    /// Surface PBR material override for this instance.
    pub(crate) material: PbrMaterial,
}

/// Complete open-world 3D scene graph with mesh instancing library, chunk streaming, and BVH acceleration.
#[derive(Clone, Data, Debug)]
pub struct World3D {
    /// Shared copy-on-write LOD mesh asset library referenced by `SceneObject3D::mesh_id` (`O(1)` `Arc::clone` on world clone).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) mesh_library: Arc<Vec<MeshLodChain>>,
    /// All world objects partitioned into open-world chunks.
    pub(crate) objects: Vec<SceneObject3D>,
    /// Active 3D perspective camera.
    #[get(type(copy))]
    pub(crate) camera: Camera3D,
    /// Active directional sun/sky lighting.
    #[get(type(copy))]
    pub(crate) sun: DirectionalLight3D,
    /// Shared copy-on-write flat BVH built over static world-space ray-trace casters (`O(1)` `Arc::clone` on world clone, flat zero-indirection `&Bvh3D` during raytracing).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) bvh: Arc<Bvh3D>,
    /// Shared copy-on-write flat BVH over moving/dynamic ray-trace casters (`O(1)` `Arc::clone` on world clone, unique zero-alloc in-place refit via `Arc::make_mut`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) dynamic_bvh: Arc<Bvh3D>,
    /// Lazily constructed shared local-space BVH4/BVH8 cache indexed by `mesh_id` for zero-rebuild object-space dynamic raytracing.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) mesh_local_bvhs: Arc<Vec<Option<Bvh3D>>>,
    /// Active object-space dynamic raytracing instances updated via inverse interpolated `Mat4` without BVH rebuilds.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) dynamic_instances: Vec<DynamicRayInstance>,
    /// Dirty flag triggering static BVH rebuild when static casters are added or modified.
    #[get(type(copy))]
    pub(crate) bvh_dirty: bool,
    /// Dirty flag triggering dynamic BVH incremental refit or rebuild when moving casters update.
    #[get(type(copy))]
    pub(crate) dynamic_bvh_dirty: bool,
    /// Topology change flag forcing a fresh dynamic BVH SAH build rather than an in-place refit.
    #[get(type(copy))]
    pub(crate) dynamic_topology_dirty: bool,
    /// Total static BVH full rebuilds executed.
    #[get(type(copy))]
    pub(crate) static_bvh_rebuilds: u64,
    /// Total zero-allocation incremental dynamic BVH refits executed.
    #[get(type(copy))]
    pub(crate) dynamic_bvh_refits: u64,
    /// Total full dynamic BVH rebuilds executed (topology changes or SAH quality resets).
    #[get(type(copy))]
    pub(crate) dynamic_bvh_rebuilds: u64,
    /// Monotonic revision incremented only when 3D world transforms, camera, or lighting change (isolated from HUD dirtiness).
    #[get(type(copy))]
    pub(crate) world_revision: u64,
    /// Monotonic simulation step counter incremented once per `step_simulation` call for parity-invariant particle emission.
    #[get(type(copy))]
    pub(crate) sim_tick: u64,
    /// Reusable scratch buffer holding transformed dynamic caster triangles during incremental BVH refits.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) dynamic_tris_scratch: Vec<BvhTriangle>,
    /// Open-world chunk size in meters (`64.0m` per city block).
    #[get(type(copy))]
    pub(crate) chunk_size: f32,
    /// Index of the drivable player vehicle object if spawned.
    #[get(skip)]
    pub(crate) player_vehicle_index: Option<usize>,
    /// Active hero supercar bodywork archetype (`AventadorV12` or `ShelbyCobra`).
    #[get(type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) hero_vehicle_style: HeroVehicleStyle,
    /// Pre-registered `(mesh_id, signature_material)` handles indexed by `HeroVehicleStyle` for zero-allocation live car switching.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) hero_vehicle_meshes: [Option<(usize, PbrMaterial)>; 2],
    /// Pre-registered rotating wheel `(mesh_id, rim_material)` handles indexed by `HeroVehicleStyle` for zero-allocation live car switching.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) hero_wheel_meshes: [Option<(usize, PbrMaterial)>; 2],
    /// Pre-allocated dynamic wheel `SceneObject3D` indices `[FL, FR, RL, RR]` mounted on the player vehicle.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) player_wheel_objects: [Option<usize>; 4],
    /// Total imported external 3D models (`.obj` / `.gltf`).
    #[get(type(copy))]
    pub(crate) imported_model_count: usize,
    /// Active 3D camera mode index (`0=Chase..=10=CityAerialDroneOrbit`).
    #[get(type(copy))]
    pub(crate) camera_mode: u8,
    /// Last active car-mounted camera mode restored when cycling `K` back from city views.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) last_car_camera_mode: CameraMode3D,
    /// Continuous orbit angle in radians used for `Orbit`, `CinematicDolly`, and `CityAerialDroneOrbit` modes.
    #[get(type(copy))]
    pub(crate) camera_orbit_rad: f32,
    /// Dynamic world-space omnidirectional point lights binned by `LightClusterGrid3D`.
    pub(crate) point_lights: Vec<PointLight3D>,
    /// Dynamic world-space spotlights (vehicle headlights, streetlamps) binned by `LightClusterGrid3D`.
    pub(crate) spot_lights: Vec<SpotLight3D>,
    /// Zero-allocation 3D Niagara particle system for sparks, exhaust trails, and atmospheric effects.
    pub(crate) niagara: NiagaraSystem3D,
    /// Active atmospheric mood preset (`0=Sunset, 1=RainyNight, 2=Noon, 3=Midnight`).
    #[get(type(copy))]
    pub(crate) atmosphere_preset: u8,
    /// Active independent time-of-day preset cycled via the `T` shortcut.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) time_of_day_preset: TimeOfDayPreset3D,
    /// Active independent atmospheric weather preset cycled via the `Y` shortcut.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) weather_preset: WeatherPreset3D,
    /// Whether current weather produces wet reflective specular sheen on city asphalt.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) wet_asphalt: bool,
    /// Active volumetric fog density multiplier applied to GPU and software atmospheric depth fog.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) weather_fog_density: f32,
    /// Active ambient hemisphere lighting factor tuned jointly by time of day and weather.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) weather_ambient_strength: f32,
    /// Active exposure scale tuned jointly by time of day and weather.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) weather_exposure: f32,
    /// Pre-allocated object indices of the layered 3D volumetric exhaust flame cones (`4 pipes x 3 layers`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) exhaust_flame_objects: [Option<usize>; EXHAUST_TOTAL_FLAME_OBJECTS],
    /// Per-object visibility mask for volumetric exhaust flame cones (`true` while actively emitting flame).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) exhaust_flame_visible: [bool; EXHAUST_TOTAL_FLAME_OBJECTS],
    /// Dedicated dynamic point light index illuminating the rear diffuser and asphalt during boost and backfire.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) exhaust_light_index: Option<usize>,
    /// Scene object index of the primary city road ground mesh for live wet/dry asphalt material tuning.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) road_ground_object_index: Option<usize>,
    /// Dynamic rigid-body autonomous NPC vehicles supporting boulevard cruising, off-road plaza free-roaming, and momentum-transfer impacts.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) traffic_vehicles: Vec<NpcVehicle3D>,
    /// Persistent player chassis dynamics state (velocity, slip angle, drift, nitro boost, suspension pitch/roll, camera feedback).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) player_physics: PlayerVehiclePhysics3D,
    /// Monotonic simulation clock in seconds driving continuous animated ocean waves, caustics, and shoreline foam.
    #[get(type(copy))]
    pub(crate) world_time_secs: f32,
    /// Hierarchical Blender/glTF scene graph with topological propagation and 64-bit Collections visibility.
    pub(crate) scene_graph: SceneGraph3D,
    /// Full 1:1 Blender Principled BSDF materials referenced by `SceneObject3D::principled_material_id`.
    pub(crate) principled_materials: Vec<PrincipledMaterial3D>,
    /// Mipmapped 2D texture pool referenced by `PrincipledMaterial3D` slots.
    pub(crate) textures: Vec<Texture2D3D>,
    /// Active armature skins evaluated against `scene_graph` joint world matrices.
    pub(crate) skins: Vec<Skin3D>,
    /// Multi-layer glTF/NLA animation mixer ticking directly into `scene_graph`.
    pub(crate) animation_mixer: AnimationMixer3D,
    /// Optional precomputed SH9 + octahedral specular + BRDF LUT IBL environment.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) environment_ibl: Option<EnvironmentIbl3D>,
    /// Physically based rectangular and disk Blender area lights.
    pub(crate) area_lights: Vec<AreaLight3D>,
    /// Imported and user-registered multi-camera list supporting Perspective and Orthographic projections.
    pub(crate) scene_cameras: Vec<SceneCamera3D>,
    /// Optional active camera index inside `scene_cameras` (`None` uses primary `camera`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) active_scene_camera: Option<usize>,
    /// Mapping from `scene_graph` node index to spawned `World3D::objects` index for O(1) transform synchronization.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) node_object_map: Vec<Option<usize>>,
    /// Reusable pre-allocated skinning and shape-key scratch arena for zero steady-state heap allocations.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) skin_scratch: SkinPaletteScratch3D,
    /// Per-object deformed mesh cache aligned with `objects` holding live morphed and skinned vertices.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) deformed_meshes: Vec<Option<Mesh3D>>,
    /// Selects Blender AgX filmic view transform (`true`) or ACES Filmic (`false`) during CPU/GPU tonemapping.
    #[get(type(copy))]
    pub(crate) use_agx_tonemap: bool,
    /// Persistent flat scratch buffers eliminating per-frame `Vec<Vec<_>>` allocations and O(N*M) pose scans during GPU pass building.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) gpu_pass_scratch: World3dGpuPassScratch,
    /// Persistent quantized geometry cache, batcher scratch, and progressive mip upload watermark reused by `build_gpu_pbr_scene_pass_into`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) pbr_pass_scratch: World3dPbrPassScratch,
    /// Persistent living city ecosystem state driving live traffic lights, drifting cumulus clouds, `BoidsFlockSolver` flocking birds, river shimmer, and wind sway.
    pub(crate) city_ecosystem: CityEcosystemState3D,
}

/// Persistent flat scratch buffers reused by `World3D::build_gpu_scene_pass_into` for zero-allocation O(N) instanced batch building.
#[derive(Clone, Debug, Default)]
pub(crate) struct World3dGpuPassScratch {
    /// Generation-stamped dense lookup epochs indexed directly by `object_index` for O(1) dynamic pose lookup and O(1) clear.
    pub(crate) dynamic_pose_epochs: Vec<u32>,
    /// Interpolated dynamic transforms aligned 1:1 with `dynamic_pose_epochs`.
    pub(crate) dynamic_pose_transforms: Vec<Transform3D>,
    /// Monotonic epoch counter incremented per pass (`0` triggers full reset on wrap).
    pub(crate) current_epoch: u32,
    /// Per-mesh visible instance counts indexed by `mesh_id`.
    pub(crate) mesh_counts: Vec<u32>,
    /// Per-mesh scatter write cursors indexed by `mesh_id`.
    pub(crate) mesh_cursors: Vec<u32>,
    /// Flat single-allocation gather buffer holding visible `(mesh_id, instance)` pairs before O(N) counting-sort scatter.
    pub(crate) visible_scratch: Vec<(u32, GpuWorld3dInstance)>,
}

/// Per-LOD quantized index range and quantization bounds cached inside `World3dPbrPassScratch`.
#[derive(Clone, Copy, Debug, Default)]
pub(crate) struct CachedPbrLodRange {
    /// Starting index inside `GpuPbrMeshBuffer::indices`.
    pub(crate) index_start: u32,
    /// Number of triangle indices in this LOD level.
    pub(crate) index_count: u32,
    /// Local quantization AABB minimum `[min_x, min_y, min_z, 0.0]`.
    pub(crate) bounds_min: [f32; 4],
    /// Local quantization AABB extent `[ext_x, ext_y, ext_z, 0.0]`.
    pub(crate) bounds_extent: [f32; 4],
    /// Whether this LOD level contains morph target deltas.
    pub(crate) has_morphs: bool,
}

/// Persistent quantized mesh cache and reusable sorting scratch enabling zero-allocation `World3D::build_gpu_pbr_scene_pass_into`.
#[derive(Clone, Debug, Default)]
pub(crate) struct World3dPbrPassScratch {
    /// Cached `Arc`-shared 24-byte quantized geometry buffer rebuilt only when `mesh_library` changes.
    pub(crate) cached_mesh_buffer: Arc<GpuPbrMeshBuffer>,
    /// Structural fingerprint `(mesh_count, total_vertices, total_indices)` detecting mesh library mutations.
    pub(crate) cached_signature: (usize, usize, usize),
    /// Cached `LOD0..LOD3` index ranges and quantization bounds indexed by `mesh_id`.
    pub(crate) cached_lod_ranges: Vec<[CachedPbrLodRange; 4]>,
    /// Reusable 64-bit sort and hardware instancing coalescer arena.
    pub(crate) batcher: GpuPbrBatcherScratch3D,
    /// Lowest uploaded mipmap level (`0 = FullRes`, `u8::MAX = Unloaded`) per `World3D::textures` slot.
    pub(crate) uploaded_texture_min_mip: Vec<u8>,
}

/// Persistent zero-allocation player vehicle chassis dynamics state for `World3D`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub(crate) struct PlayerVehiclePhysics3D {
    /// World-space horizontal chassis velocity vector `(vx, 0.0, vz)` in meters per second.
    #[get(type(copy))]
    pub(crate) vel: Vec3,
    /// Active yaw angular velocity around the vertical Y axis in radians per second.
    #[get(type(copy))]
    pub(crate) yaw_rate: f32,
    /// Smoothly damped visual chassis lateral body roll angle in radians.
    #[get(type(copy))]
    pub(crate) body_roll_rad: f32,
    /// Smoothly damped visual chassis longitudinal pitch angle in radians (squat/dive).
    #[get(type(copy))]
    pub(crate) body_pitch_rad: f32,
    /// Whether Shift nitro boost is currently delivering extra thrust.
    #[get(type(copy))]
    pub(crate) boost_active: bool,
    /// Normalized turbo overdrive reserve gauge in `[0.0, 1.0]` staying smoothly high during continuous boost.
    #[get(type(copy))]
    pub(crate) boost_charge: f32,
    /// Smooth progressive turbocharger spool-up factor in `[0.0, 1.0]` driving continuous thrust and exhaust afterburner stretch.
    #[get(type(copy))]
    pub(crate) boost_spool: f32,
    /// Normalized engine RPM estimate in `[0.0, 1.0]` across the 6-speed gearbox.
    #[get(type(copy))]
    pub(crate) engine_rpm_norm: f32,
    /// Active sequential gearbox gear index (`1..=6`) for realistic upshift exhaust crackle detection.
    #[get(type(copy))]
    pub(crate) active_gear: u8,
    /// Previous tick throttle command used to detect crisp off-throttle lift-off backfires.
    #[get(type(copy))]
    pub(crate) prev_throttle: f32,
    /// Remaining duration in seconds of active off-throttle or upshift exhaust backfire flame pops.
    #[get(type(copy))]
    pub(crate) backfire_timer: f32,
    /// Whether Space handbrake powerslide drift is currently active.
    #[get(type(copy))]
    pub(crate) drift_active: bool,
    /// Signed lateral chassis slip angle `atan2(v_lateral, |v_forward|)` in radians.
    #[get(type(copy))]
    pub(crate) drift_slip_angle: f32,
    /// Accumulated continuous drift duration in seconds for exit-drift boost kick qualification.
    #[get(type(copy))]
    pub(crate) drift_duration: f32,
    /// Peak absolute slip angle reached during the active drift window in radians.
    #[get(type(copy))]
    pub(crate) drift_peak_slip: f32,
    /// Smoothly damped dynamic chase-camera vertical FOV boost in degrees.
    #[get(type(copy))]
    pub(crate) camera_fov_boost: f32,
    /// Smoothly decaying impact camera shake amplitude in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) camera_shake: f32,
    /// Cumulative wheel rolling angle in radians around the local X axle (negative forward, positive reverse).
    #[get(type(copy))]
    pub(crate) wheel_spin_rad: f32,
    /// Smoothly damped front-wheel physical steering yaw offset in `[-0.48, +0.48]` radians.
    #[get(type(copy))]
    pub(crate) front_steer_rad: f32,
}

/// Full dynamic rigid-body state for an autonomous NPC vehicle capable of boulevard cruising, off-road plaza free-roaming, and momentum-transfer impacts.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub(crate) struct NpcVehicle3D {
    /// Owning scene object index inside `World3D::objects`.
    #[get(type(copy))]
    pub(crate) object_index: usize,
    /// World-space horizontal rigid-body velocity `(vx, 0.0, vz)` in meters per second.
    #[get(type(copy))]
    pub(crate) vel: Vec3,
    /// Active angular spin rate around the vertical Y axis in radians per second.
    #[get(type(copy))]
    pub(crate) yaw_rate: f32,
    /// Simulated vehicle mass in kilograms for 2-body collision impulse resolution.
    #[get(type(copy))]
    pub(crate) mass: f32,
    /// Target cruising speed in meters per second when autonomous steering is active.
    #[get(type(copy))]
    pub(crate) cruise_speed: f32,
    /// Remaining collision knockback recovery time in seconds during which the vehicle slides/spins freely under tire friction.
    #[get(type(copy))]
    pub(crate) recovery_timer: f32,
    /// Whether this NPC freely roams open off-road plazas and city grounds rather than following the boulevard loop.
    #[get(type(copy))]
    pub(crate) free_roam_mode: bool,
    /// Current progress along the 962m boulevard centerline in meters for loop-cruising NPCs.
    #[get(type(copy))]
    pub(crate) loop_arc_s: f32,
    /// Target lateral offset on the boulevard in meters for undisturbed loop-cruising NPCs.
    #[get(type(copy))]
    pub(crate) loop_lane_u: f32,
    /// Travel direction along the boulevard loop (`+1.0` clockwise, `-1.0` counter-clockwise).
    #[get(type(copy))]
    pub(crate) loop_dir: f32,
    /// Active world-space navigation waypoint `(x, 0.0, z)` for free-roaming NPCs.
    #[get(type(copy))]
    pub(crate) nav_target: Vec3,
    /// Current waypoint index inside the assigned open-city route.
    #[get(type(copy))]
    pub(crate) waypoint_idx: usize,
    /// Open-city off-road route identifier (`0=InnerPlaza, 1=OuterWestPlaza, 2=CrossCourtyard`).
    #[get(type(copy))]
    pub(crate) route_id: u8,
    /// Accumulated stalled time in seconds while intending to move below `NPC_STUCK_SPEED_MPS`.
    #[get(type(copy))]
    pub(crate) stuck_timer: f32,
    /// Remaining duration in seconds of the active 3-point Ackermann reverse-and-turn unstick maneuver.
    #[get(type(copy))]
    pub(crate) unstick_timer: f32,
    /// Signed Ackermann reverse steering direction (`-1.0` or `+1.0`) steering away from the blocking wall normal.
    #[get(type(copy))]
    pub(crate) unstick_steer: f32,
    /// Verified obstacle-free escape heading in radians locked after scanning 8 candidate headings.
    #[get(type(copy))]
    pub(crate) escape_heading: f32,
    /// Remaining duration in seconds to hold `escape_heading` before resuming normal navigation.
    #[get(type(copy))]
    pub(crate) escape_timer: f32,
    /// Smoothly damped lateral avoidance offset in meters for reciprocal oncoming passing and overtaking.
    #[get(type(copy))]
    pub(crate) lane_avoid_offset: f32,
    /// Last horizontal wall contact normal X component used to bias reverse unstick away from obstacles.
    #[get(type(copy))]
    pub(crate) last_wall_normal_x: f32,
    /// Last horizontal wall contact normal Z component used to bias reverse unstick away from obstacles.
    #[get(type(copy))]
    pub(crate) last_wall_normal_z: f32,
    /// Cumulative wheel rolling angle in radians around the local X axle (negative forward, positive reverse).
    #[get(type(copy))]
    pub(crate) wheel_spin_rad: f32,
    /// Smoothly damped front-wheel physical steering yaw offset in `[-0.48, +0.48]` radians.
    #[get(type(copy))]
    pub(crate) front_steer_rad: f32,
    /// Pre-allocated dynamic wheel `SceneObject3D` indices `[FL, FR, RL, RR]` mounted on this NPC vehicle.
    #[get(type(copy))]
    pub(crate) wheel_object_indices: [Option<usize>; 4],
    /// Sculpted vehicle archetype controlling wheel hub layout and rolling tire radius.
    #[get(type(copy))]
    pub(crate) vehicle_kind: SculptedVehicleKind,
}

/// Per-substep CCD stepping context carrying substep duration, optional playable ground bounds, and vehicle half-extent margin.
#[derive(Clone, Copy, Debug)]
pub(crate) struct VehicleCcdStepCtx3D {
    /// Substep duration in seconds.
    pub(crate) sub_dt: f32,
    /// Optional playable horizontal `(min_x, max_x, min_z, max_z)` ground bounds.
    pub(crate) ground_limits: Option<(f32, f32, f32, f32)>,
    /// Vehicle horizontal boundary margin in meters.
    pub(crate) ground_margin: f32,
}

/// Process-wide cached Vice Boulevard city template bundling pre-built meshes, BVHs, and static GPU vertex buffers for near-zero `/game3d` entry latency.
#[derive(Clone, Debug)]
pub(crate) struct OpenWorldCityTemplate3D {
    /// Fully assembled open-world `World3D` with static and dynamic BVHs already constructed.
    pub(crate) world: World3D,
    /// Pre-baked static GPU vertex buffer shared across scene instances in O(1) via `Arc::clone`.
    pub(crate) gpu_mesh_buffer: Arc<GpuWorld3dMeshBuffer>,
    /// Per-mesh `(vertex_start, vertex_count)` table paired with `gpu_mesh_buffer`.
    pub(crate) gpu_mesh_ranges: Vec<(u32, u32)>,
}