Skip to main content

euv_core/game/engine3d/blend/
struct.rs

1use super::*;
2
3/// Parsed `.blend` header metadata supporting both classic 12-byte (2.x-4.x) and Blender 5.0+ 17-byte large headers.
4#[derive(Clone, Copy, Data, Debug, Eq, PartialEq)]
5pub struct BlendHeader {
6    /// Major Blender version (e.g., `4` or `5`).
7    #[get(type(copy))]
8    pub(crate) version_major: u16,
9    /// Minor Blender version (e.g., `2` for `4.2`, `1` for `5.1`).
10    #[get(type(copy))]
11    pub(crate) version_minor: u16,
12    /// Pointer width in bytes (`4` for 32-bit, `8` for 64-bit).
13    #[get(type(copy))]
14    pub(crate) pointer_size_bytes: u8,
15    /// `true` for little-endian (`'v'`), `false` for big-endian (`'V'`).
16    #[get(type(copy))]
17    pub(crate) is_little_endian: bool,
18    /// `true` when using Blender 5.0+ extended large header & 32-byte `LargeBHead8`.
19    #[get(type(copy))]
20    pub(crate) is_large_header_v5: bool,
21    /// Byte length of the header before the first `BHead` block (`12` or `17`).
22    #[get(type(copy))]
23    pub(crate) header_size_bytes: usize,
24    /// File-format revision (`0` for classic 2.x-4.x, `>= 1` for Blender 5.0+).
25    #[get(type(copy))]
26    pub(crate) format_version: u16,
27}
28
29/// Summary of one `BHead` data block scanned inside a `.blend` file.
30#[derive(Clone, Data, Debug, Eq, PartialEq)]
31pub struct BlendBlockSummary {
32    /// Four-byte ASCII block code trimmed of trailing NULs (e.g., `"OB"`, `"ME"`, `"DNA1"`).
33    pub(crate) code: String,
34    /// Classified Blender ID block kind.
35    #[get(type(copy))]
36    pub(crate) kind: BlendBlockKind,
37    /// Payload length in bytes following the block header.
38    #[get(type(copy))]
39    pub(crate) byte_length: u64,
40    /// SDNA struct index (`sdna_nr`).
41    #[get(type(copy))]
42    pub(crate) sdna_index: u32,
43    /// Array element count (`nr`).
44    #[get(type(copy))]
45    pub(crate) element_count: u64,
46}
47
48/// Parsed metadata from the `DNA1` SDNA schema table inside a `.blend` file.
49#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
50pub struct BlendDnaSchemaSummary {
51    /// Total field name entries in `NAME`.
52    #[get(type(copy))]
53    pub(crate) name_count: usize,
54    /// Total C type entries in `TYPE`/`TLEN`.
55    #[get(type(copy))]
56    pub(crate) type_count: usize,
57    /// Total struct definitions in `STRC`.
58    #[get(type(copy))]
59    pub(crate) struct_count: usize,
60    /// Resolved byte offset of `ID.name` inside Blender `ID` blocks, if present in SDNA.
61    #[get(type(copy))]
62    pub(crate) id_name_offset: Option<usize>,
63    /// Resolved byte buffer length of `ID.name` (typically `66` in 4.x or `258` in 5.x).
64    #[get(type(copy))]
65    pub(crate) id_name_max_len: Option<usize>,
66}
67
68/// Complete inspection report extracted from a `.blend` file with zero external Blender process required.
69#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
70pub struct BlendInspectionReport {
71    /// Major Blender version number (e.g., `4` or `5`).
72    #[get(type(copy))]
73    pub(crate) blender_version_major: u16,
74    /// Minor Blender version number (e.g., `2` for `4.2`, `1` for `5.1`).
75    #[get(type(copy))]
76    pub(crate) blender_version_minor: u16,
77    /// Formatted Blender version string (e.g., `"4.2"` or `"5.1"`).
78    pub(crate) version_string: String,
79    /// Pointer width in bytes (`4` or `8`).
80    #[get(type(copy))]
81    pub(crate) pointer_size_bytes: u8,
82    /// `true` when encoded in little-endian byte order.
83    #[get(type(copy))]
84    pub(crate) is_little_endian: bool,
85    /// `true` when the file uses the Blender 5.0+ extended large header format.
86    #[get(type(copy))]
87    pub(crate) is_large_header_v5: bool,
88    /// Detected container compression (`None`, `Gzip`, or `Zstd`).
89    #[get(type(copy))]
90    pub(crate) compression: BlendCompression,
91    /// Total number of `BHead` blocks scanned.
92    #[get(type(copy))]
93    pub(crate) block_count: usize,
94    /// Number of SDNA struct definitions parsed from `DNA1`.
95    #[get(type(copy))]
96    pub(crate) dna_struct_count: usize,
97    /// Number of SDNA type entries parsed from `DNA1`.
98    #[get(type(copy))]
99    pub(crate) dna_type_count: usize,
100    /// Number of SDNA field name entries parsed from `DNA1`.
101    #[get(type(copy))]
102    pub(crate) dna_name_count: usize,
103    /// Discovered Blender Scene names (`SC`).
104    pub(crate) scenes: Vec<String>,
105    /// Discovered Blender Collection names (`GR`).
106    pub(crate) collections: Vec<String>,
107    /// Discovered Blender Object names (`OB`).
108    pub(crate) objects: Vec<String>,
109    /// Discovered Blender Mesh names (`ME`).
110    pub(crate) meshes: Vec<String>,
111    /// Discovered Blender Material names (`MA`).
112    pub(crate) materials: Vec<String>,
113    /// Discovered Blender Camera names (`CA`).
114    pub(crate) cameras: Vec<String>,
115    /// Discovered Blender Light names (`LA`).
116    pub(crate) lights: Vec<String>,
117    /// Discovered Blender Armature names (`AR`).
118    pub(crate) armatures: Vec<String>,
119    /// Discovered Blender Animation Action names (`AC`).
120    pub(crate) actions: Vec<String>,
121    /// Discovered Blender Image names (`IM`).
122    pub(crate) images: Vec<String>,
123    /// Discovered Blender NodeTree names (`NT`).
124    pub(crate) node_trees: Vec<String>,
125    /// Non-fatal structural warnings encountered during inspection.
126    pub(crate) warnings: Vec<String>,
127}
128
129/// Stateless pure-Rust `.blend` 4.x/5.x binary header, block, and SDNA inspector.
130#[derive(Clone, Copy, Debug, Default)]
131pub struct BlendInspector;