euv-core 0.56.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
use super::*;

/// Single C struct field definition decoded from a Blender `DNA1` SDNA schema table.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub(crate) struct BlendSdnaField {
    /// Clean identifier name stripped of pointer stars and array brackets (e.g., `"obmat"`).
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) clean_name: String,
    /// Raw C declarator from `DNA1` `NAME` table (e.g., `"*next"`, `"obmat[4][4]"`).
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) raw_name: String,
    /// C type name from `DNA1` `TYPE` table (e.g., `"float"`, `"ID"`, `"ListBase"`).
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) type_name: String,
    /// Starting byte offset of this field inside the owning SDNA struct.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) offset: usize,
    /// Total footprint in bytes of this field (including array dimensions).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) byte_size: usize,
    /// `true` when this field stores a pointer (`*`, `**`, or function pointer `(*fn)()`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) is_pointer: bool,
    /// Indirection depth (`0` = value, `1` = `*`, `2` = `**`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) pointer_depth: u8,
    /// Product of all array dimensions (`1` for scalar fields, `16` for `[4][4]`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) total_elements: usize,
    /// Byte size of a single element (`pointer_size_bytes` for pointers, `TLEN` otherwise).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) element_size: usize,
    /// Optional SDNA struct index when this field embeds another SDNA struct by value.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) sdna_struct_index: Option<usize>,
}

/// Complete C struct layout decoded from a Blender `DNA1` `STRC` entry.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub(crate) struct BlendSdnaStruct {
    /// Struct type name (e.g., `"Object"`, `"Mesh"`, `"bNode"`).
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) type_name: String,
    /// Declared byte length from `TLEN` (or computed sum of field sizes).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) byte_size: usize,
    /// Ordered field descriptors with exact byte offsets.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) fields: Vec<BlendSdnaField>,
    /// O(1) lookup from clean field name to index in `fields`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) field_by_name: HashMap<String, usize>,
}

/// Parsed Blender `DNA1` SDNA schema table mapping struct indices and field names to byte offsets.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct BlendSdnaTable {
    /// Pointer width in bytes (`4` or `8`) for the source `.blend` archive.
    #[get(type(copy))]
    pub(crate) pointer_size_bytes: u8,
    /// True when the source `.blend` archive encodes numbers in little-endian order.
    #[get(type(copy))]
    pub(crate) is_little_endian: bool,
    /// Total number of SDNA struct definitions indexed in this table.
    #[get(type(copy))]
    pub(crate) struct_count: usize,
    /// Raw field declarator names from `DNA1` `NAME`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) names: Vec<String>,
    /// Raw C type names from `DNA1` `TYPE`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) types: Vec<String>,
    /// Byte sizes per C type from `DNA1` `TLEN`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) type_lengths: Vec<u16>,
    /// Indexed SDNA struct layouts matching `BHead::sdna_nr`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) structs: Vec<BlendSdnaStruct>,
    /// O(1) lookup from struct type name to `sdna_nr` index in `structs`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) struct_by_name: HashMap<String, usize>,
}

/// Single parsed `BHead` / `LargeBHead8` block header and byte range inside a `.blend` stream.
#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
pub(crate) struct BlendFileBlock {
    /// Four-byte ASCII block code (`"OB\0\0"`, `"ME\0\0"`, `"DATA"`, `"DNA1"`, etc.).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) code: [u8; 4],
    /// High-level Blender ID block classification.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) kind: BlendBlockKind,
    /// Original memory address serialized by Blender for pointer resolution.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) old_address: u64,
    /// SDNA struct index (`sdna_nr`) describing the payload elements.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) sdna_index: u32,
    /// Array element count (`nr`) stored consecutively inside the payload.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) count: usize,
    /// Inclusive starting byte offset of the block payload inside the `.blend` buffer.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) payload_start: usize,
    /// Exclusive ending byte offset of the block payload inside the `.blend` buffer.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) payload_end: usize,
}

/// Indexed zero-copy view over an uncompressed `.blend` buffer with full SDNA schema and O(1) pointer resolution.
#[derive(Clone, Data, Debug)]
pub(crate) struct BlendArchiveView<'a> {
    /// Backing uncompressed `.blend` file byte slice.
    #[get(pub(crate), type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) data: &'a [u8],
    /// Parsed `.blend` header metadata (classic 4.x or Blender 5.x large header).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) header: BlendHeader,
    /// Full SDNA schema table parsed from the `DNA1` block.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) sdna: BlendSdnaTable,
    /// All scanned file blocks in stream order.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) blocks: Vec<BlendFileBlock>,
    /// O(1) map from `old_address` to block index inside `blocks`.
    #[get(pub(crate))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) address_to_block: HashMap<u64, usize>,
}

/// Zero-copy typed view over a single SDNA struct instance inside a `BlendArchiveView`.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct BlendStructView<'a> {
    /// Parent archive view providing SDNA metadata and pointer resolution.
    #[get(pub(crate), type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) archive: &'a BlendArchiveView<'a>,
    /// Index of this struct's definition inside `BlendSdnaTable::structs`.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    #[get_mut(skip)]
    pub(crate) struct_index: usize,
    /// Exact payload byte slice backing this struct instance.
    #[get(pub(crate), type(copy))]
    #[set(skip)]
    #[get_mut(skip)]
    pub(crate) bytes: &'a [u8],
}