blend_rs/lib.rs
1//! [![github]](https://example.com) [![crates-io]](https://crates.io/crates/blend-rs) [![docs-rs]](https://docs.rs/blend-rs)
2//!
3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
6//!
7//! # blender-rs
8//!
9//! A Rust library to read Blender's .blend files without the hassle of byte parsing.
10//!
11//! **Note:** Due to the functioning of this library not all blender version are supported.
12//! The table about [Crate Features](#crate-features) lists the supported blender version.
13//!
14//! ## Example
15//! The example below illustrates how to extract the coordinates of each vertex of an object's mesh.
16//! ```rust
17//! use blend_rs::blend::{read, StructIter, PointerLike, NameLike};
18//! use blend_rs::blend::traverse::Named;
19//!
20//! use blend_rs::blender3_2::{Object, Mesh, MPoly, MVert, MLoop};
21//!
22//! pub struct Vertex {
23//! pub position: [f32; 3],
24//! }
25//!
26//! fn main() {
27//!
28//! let blend_data = std::fs::read("examples/example-3.2.blend")
29//! .expect("Blend file not found!");
30//!
31//! let reader = read(&blend_data)
32//! .expect("Failed to read blend data!");
33//!
34//! let plane: &Object = reader.iter::<Object>().unwrap()
35//! .find(|object| object.id.get_name() == "Plane")
36//! .unwrap();
37//!
38//! let mesh = reader.deref_single(&plane.data.as_instance_of::<Mesh>())
39//! .expect("Could not get mesh from object!");
40//!
41//! let mesh_polygons: StructIter<MPoly> = reader.deref(&mesh.mpoly)
42//! .expect("Could not get polygons from mesh!");
43//!
44//! let mesh_loops: Vec<&MLoop> = reader.deref(&mesh.mloop)
45//! .expect("Could not get loops from mesh!")
46//! .collect();
47//!
48//! let mesh_vertices: Vec<&MVert> = reader.deref(&mesh.mvert)
49//! .expect("Could not get vertices from mesh!")
50//! .collect();
51//!
52//! let vertices_per_polygon: Vec<Vec<Vertex>> = mesh_polygons
53//! .map(|polygon| {
54//! (polygon.loopstart..polygon.loopstart + polygon.totloop).into_iter()
55//! .map(|loop_index| {
56//! Vertex {
57//! position: mesh_vertices[mesh_loops[loop_index as usize].v as usize].co
58//! }
59//! })
60//! .collect()
61//! })
62//! .collect();
63//! }
64//! ```
65//!
66//! ## Crate Features
67//! Enable or disable features according to your needs and in order to optimize compile time.
68//!
69//! | Feature | Default | Description |
70//! | ----------------- |:--------:| ------------------------------------------------------------------ |
71//! | blender2_79 | ✗ | Generate and include code for blender 2.79 (64 Bit, little endian) |
72//! | blender2_80 | ✗ | Generate and include code for blender 2.80 (64 Bit, little endian) |
73//! | blender2_80x86 | ✗ | Generate and include code for blender 2.80 (32 Bit, little endian) |
74//! | blender2_93 | ✗ | Generate and include code for blender 2.93 (64 Bit, little endian) |
75//! | blender3_2 | ✔ | Generate and include code for blender 3.2 (64 Bit, little endian) |
76//! | blender3_3 | ✗ | Generate and include code for blender 3.3 (64 Bit, little endian) |
77//! | all | ✗ | Generate and include code for all above blender versions. |
78//!
79//! <sup>✔ enabled, ✗ disabled</sup>
80//!
81//! ## Details
82//!
83//! blend-rs depends heavily on code generated from the Blender DNA. The Blender DNA is a part of
84//! each `*.blend` file and contains a description for all structs, types and names within the file.
85//! Blender uses the DNA for forward- and backward compatibility. blend-rs uses the DNA to generate
86//! rust code.
87//!
88//! This library belongs to a set of three libraries which are all related to the topic of reading
89//! Blender's .blend files:
90//!
91//! <p style="text-align: center;">
92 #![doc=include_str!("../overview.svg")]
93//! </p>
94//!
95//! * [blend-inspect-rs](https://docs.rs/blend-inspect-rs):
96//! A Rust library to parse and analyse Blender's .blend files.
97//! * [blend-bindgen-rs](https://docs.rs/blend-bindgen-rs):
98//! A Rust library to generated Blender's data structures.
99//! * [blend-rs](https://docs.rs/blend-rs):
100//! A Rust library to read Blender's .blend files.
101//!
102//!
103extern crate core;
104
105pub mod blend;
106
107#[cfg(feature = "blender3_4")]
108include!(concat!(env!("OUT_DIR"), "/blender3_4.rs"));
109
110#[cfg(feature = "blender3_3")]
111include!(concat!(env!("OUT_DIR"), "/blender3_3.rs"));
112
113#[cfg(feature = "blender3_2")]
114include!(concat!(env!("OUT_DIR"), "/blender3_2.rs"));
115
116#[cfg(feature = "blender2_93")]
117include!(concat!(env!("OUT_DIR"), "/blender2_93.rs"));
118
119#[cfg(feature = "blender2_80")]
120include!(concat!(env!("OUT_DIR"), "/blender2_80.rs"));
121
122#[cfg(feature = "blender2_80x86")]
123include!(concat!(env!("OUT_DIR"), "/blender2_80x86.rs"));
124
125#[cfg(feature = "blender2_79")]
126include!(concat!(env!("OUT_DIR"), "/blender2_79.rs"));