euv-core 0.46.1

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
use super::*;

/// 3D world-space transform (translation, yaw/pitch/roll Euler rotation, and non-uniform scale).
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct Transform3D {
    /// World-space translation `(x, y, z)`.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Horizontal Y-axis yaw rotation in radians.
    #[get(type(copy))]
    pub(crate) yaw_rad: f32,
    /// Vertical X-axis pitch rotation in radians.
    #[get(type(copy))]
    pub(crate) pitch_rad: f32,
    /// Longitudinal Z-axis roll rotation in radians.
    #[get(type(copy))]
    pub(crate) roll_rad: f32,
    /// Scale multiplier along `(x, y, z)`.
    #[get(type(copy))]
    pub(crate) scale: Vec3,
}

/// 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,
    /// 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 AABB for O(1) frustum culling and chunk streaming.
    #[get(type(copy))]
    pub(crate) world_bounds: Aabb3D,
    /// 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,
    /// 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,
}

/// 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,
}

/// Complete open-world 3D scene graph with mesh instancing library, chunk streaming, and BVH acceleration.
#[derive(Clone, Data, Debug)]
pub struct World3D {
    /// Shared LOD mesh asset library referenced by `SceneObject3D::mesh_id`.
    pub(crate) mesh_library: 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,
    /// Flat BVH built over static world-space ray-trace casters (rebuilt only on static geometry edits).
    pub(crate) bvh: Bvh3D,
    /// Separate flat BVH over moving/dynamic ray-trace casters supporting O(N) incremental bottom-up refits.
    pub(crate) dynamic_bvh: Bvh3D,
    /// 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,
    /// 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>,
    /// Total imported external 3D models (`.obj` / `.gltf`).
    #[get(type(copy))]
    pub(crate) imported_model_count: usize,
    /// Active 3D camera mode index (`0=Chase`, `1=Hood`, `2=Orbit`, `3=Aerial`, `4=FreeFly`, `5=CinematicDolly`).
    #[get(type(copy))]
    pub(crate) camera_mode: u8,
    /// Continuous orbit angle in radians used for `Orbit` and `CinematicDolly` modes.
    #[get(type(copy))]
    pub(crate) camera_orbit_rad: f32,
}