1#[macro_use]
20extern crate failure;
21#[macro_use]
22extern crate serde_derive;
23
24pub use self::combine_indices::CreateSingleIndexConfig;
25pub use self::export::*;
26pub use crate::bounding_box::BoundingBox;
27use crate::custom_property::CustomProperty;
28pub use crate::material::PrincipledBSDF;
29use crate::serde::serialize_hashmap_deterministic;
30pub use crate::vertex_attributes::{
31 BoneInfluence, MultiIndexedVertexAttributes, SingleIndexedVertexAttributes, Vertex,
32 VertexAttribute,
33};
34pub use material::{Channel, MaterialInput};
35use std::collections::HashMap;
36
37mod bone;
38mod bounding_box;
39mod combine_indices;
40mod custom_property;
41mod export;
42mod face_tangents;
43mod interleave;
44mod material;
45mod serde;
46mod triangulate;
47mod vertex_attributes;
48mod y_up;
49
50mod create_mesh;
51
52#[cfg(test)]
53mod test_utils;
54
55#[derive(Debug, Fail)]
57pub enum BlenderError {
58 #[fail(
61 display = "There was an issue while exporting meshes: Blender stderr output: {}",
62 _0
63 )]
64 Stderr(String),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
71#[serde(deny_unknown_fields)]
72pub struct BlenderMesh {
73 name: String,
74 armature_name: Option<String>,
75 bounding_box: BoundingBox,
76 #[serde(alias = "attribs")]
77 multi_indexed_vertex_attributes: MultiIndexedVertexAttributes,
78 #[serde(default, serialize_with = "serialize_hashmap_deterministic")]
79 materials: HashMap<String, PrincipledBSDF>,
80 #[serde(default, serialize_with = "serialize_hashmap_deterministic")]
81 custom_properties: HashMap<String, CustomProperty>,
82}
83
84impl BlenderMesh {
85 pub fn armature_name(&self) -> Option<&String> {
87 self.armature_name.as_ref()
88 }
89
90 pub fn set_armature_name(&mut self, armature_name: Option<String>) {
92 self.armature_name = armature_name;
93 }
94
95 pub fn materials(&self) -> &HashMap<String, PrincipledBSDF> {
97 &self.materials
98 }
99
100 pub fn materials_mut(&mut self) -> &mut HashMap<String, PrincipledBSDF> {
102 &mut self.materials
103 }
104
105 pub fn custom_properties(&self) -> &HashMap<String, CustomProperty> {
109 &self.custom_properties
110 }
111
112 pub fn bounding_box(&self) -> BoundingBox {
114 self.bounding_box
115 }
116
117 pub fn set_bounding_box(&mut self, bounding_box: BoundingBox) {
119 self.bounding_box = bounding_box;
120 }
121
122 pub fn name(&self) -> &String {
124 &self.name
125 }
126
127 pub fn set_name(&mut self, name: String) {
129 self.name = name;
130 }
131}
132
133#[cfg(test)]
144#[macro_export]
145#[cfg(test)]
146macro_rules! concat_vecs {
147 ( $( $vec:expr),* ) => {
148 {
149 let mut concatenated_vec = Vec::new();
150 $(
151 concatenated_vec.append(&mut $vec.clone());
152 )*
153 concatenated_vec
154 }
155 }
156}
157
158#[cfg(test)]
159fn indexed(
160 attribute: crate::vertex_attributes::VertexAttribute<f32>,
161) -> crate::vertex_attributes::IndexedAttribute {
162 crate::vertex_attributes::IndexedAttribute {
163 indices: vec![],
164 attribute,
165 }
166}