assimp/import/
structs.rs

1//! Argument structs for `Importer` post-processing configuration.
2
3use ffi::config::*;
4
5use math::Matrix4x4;
6
7/// Enumerates components of the Scene and Mesh data structures that can be excluded from the import
8/// using the `remove_component` step.
9///
10/// See `Importer::remove_component` for more details.
11#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum ComponentType {
13    Normals,
14    TangentsAndBitangents,
15    Colors,
16    TexCoords,
17    BoneWeights,
18    Animations,
19    Textures,
20    Lights,
21    Cameras,
22    Meshes,
23    Materials
24}
25
26#[derive(Clone, Copy, Debug, Eq, PartialEq)]
27pub enum UVTransformFlag {
28    Scaling,
29    Rotation,
30    Translation,
31    All
32}
33
34#[derive(Clone, Copy, Debug, Eq, PartialEq)]
35pub enum PrimitiveType {
36    Point,
37    Line,
38    Triangle,
39    Polygon
40}
41
42
43// Macro to simplify defining and structs and implementing Default trait
44// NOTE: pub keyword in field definition is to workaround rust issue #24189
45macro_rules! struct_with_defaults {
46    ($(#[$struct_attr:meta])* struct $i:ident {
47        $($(#[$field_attr:meta])* pub $n:ident: $t:ty = $v:expr),*
48    }) => (
49        $(#[$struct_attr])*
50        pub struct $i {
51            /// Whether to enable the step. Default: false
52            pub enable: bool,
53            $($(#[$field_attr])* pub $n: $t),*
54        }
55
56        impl Default for $i {
57            fn default() -> $i {
58                $i {
59                    enable: false,
60                    $($n: $v),*
61                }
62            }
63        }
64    )
65}
66
67struct_with_defaults! {
68    /// Arguments for `calc_tangent_space` post-process step.
69    struct CalcTangentSpace {
70        /// Maximum angle between two vertex tangents used for smoothing. Default: 45.0
71        pub max_smoothing_angle: f32 = 45.0,
72        /// Source UV channel for tangent space computation. Default: 0
73        pub texture_channel: i32 = 0
74    }
75}
76
77struct_with_defaults! {
78    /// Arguments for `remove_component` post-process step.
79    struct RemoveComponent {
80        /// Specify which components to remove. Default: none
81        pub components: Vec<ComponentType> = Vec::new()
82    }
83}
84
85struct_with_defaults! {
86    /// Arguments for `generate_normals` post-process step.
87    struct GenerateNormals {
88        /// Whether the generated normals are smoothed or not. Default: false
89        pub smooth: bool = false,
90        /// Maximum angle between two vertex normals used for smoothing. Default: 175.0
91        /// Only applies if `smooth` is `true`.
92        pub max_smoothing_angle: f32 = 175.0
93    }
94}
95
96struct_with_defaults! {
97    /// Arguments for `split_large_meshes` post-process step.
98    struct SplitLargeMeshes {
99        /// Maximum number of vertices per mesh. Default: 1000000
100        pub vertex_limit: i32 = AI_SLM_DEFAULT_MAX_VERTICES,
101        /// Maximum number of triangles per mesh. Default: 1000000
102        pub triangle_limit: i32 = AI_SLM_DEFAULT_MAX_TRIANGLES
103    }
104}
105
106struct_with_defaults! {
107    /// Arguments for `pre_transform_vertices` post-process step.
108    struct PreTransformVertices {
109        /// Whether to keep the existing scene hierarchy. Default: false
110        pub keep_hierarchy: bool = false,
111        /// Whether to normalize all vertices into the [-1, 1] range. Default: false
112        pub normalize: bool = false,
113        /// Whether to pre-transform all vertices using the matrix specified in the
114        /// `root_transformation` field. Default: false
115        pub add_root_transformation: bool = false,
116        /// Transformation matrix to use.
117        pub root_transformation: Matrix4x4 = Matrix4x4::new(1.0, 0.0, 0.0, 0.0,
118                                                            0.0, 1.0, 0.0, 0.0,
119                                                            0.0, 0.0, 1.0, 0.0,
120                                                            0.0, 0.0, 0.0, 1.0)
121    }
122}
123
124struct_with_defaults! {
125    /// Arguments for `limit_bone_weights` post-process step.
126    struct LimitBoneWeights {
127        /// Maximum number of bones that affect a single vertex. Default: 4
128        pub max_weights: i32 = AI_LMW_MAX_WEIGHTS
129    }
130}
131
132struct_with_defaults! {
133    /// Arguments for `improve_cache_locality` post-process step.
134    struct ImproveCacheLocality {
135        /// Set the size of the post-transform vertex cache. Default: 12
136        pub cache_size: i32 = PP_ICL_DEFAULT_PTCACHE_SIZE
137    }
138}
139
140struct_with_defaults! {
141    /// Arguments for `remove_redundant_materials` post-process step.
142    struct RemoveRedundantMaterials {
143        /// Space-delimited list of materials to keep. Identifiers containing whitespace must be
144        /// enclosed in single quotes. e.g. `material1 'material 2' material3`.
145        pub exclude_list: String = String::new()
146    }
147}
148
149struct_with_defaults! {
150    /// Arguments for `sort_by_primitive_type` post-process step.
151    struct SortByPrimitiveType {
152        /// List of primitive types to remove. Default: none
153        pub remove: Vec<PrimitiveType> = Vec::new()
154    }
155}
156
157struct_with_defaults! {
158    /// Arguments for `find_degenerates` post-process step.
159    struct FindDegenerates {
160        /// Whether to remove any found degenerates. Default: true
161        pub remove: bool = false
162    }
163}
164
165struct_with_defaults! {
166    /// Arguments for `find_invalid_data` post-process step.
167    struct FindInvalidData {
168        /// Specify the accuracy for considering animation values as invalid. Default: 0
169        pub accuracy: f32 = 0.0
170    }
171}
172
173struct_with_defaults! {
174    /// Arguments for `transform_uv_coords` post-process step.
175    struct TransformUVCoords {
176        /// Specify which UV transforms to evaluate. Default: all
177        pub flags: Vec<UVTransformFlag> = vec![UVTransformFlag::All]
178    }
179}
180
181struct_with_defaults! {
182    /// Arguments for `optimize_graph` post-process step.
183    struct OptimizeGraph {
184        /// Space-delimited list of nodes to keep. Identifiers containing whitespace must be
185        /// enclosed in single quotes. e.g. `node1 'node 2' node3`.
186        pub exclude_list: String = String::new()
187    }
188}
189
190struct_with_defaults! {
191    /// Arguments for `split_by_bone_count` post-process step.
192    struct SplitByBoneCount {
193        /// Maximum number of bones per mesh. Default: 60
194        pub max_bones: i32 = AI_SBBC_DEFAULT_MAX_BONES
195    }
196}
197
198struct_with_defaults! {
199    /// Arguments for `debone` post-process step.
200    struct Debone {
201        /// Threshold for considering bone necessary. Default: 1.0
202        pub threshold: f32 = AI_DEBONE_THRESHOLD,
203        /// Whether to require all bones to meet the threshold before removing any. Default: false
204        pub all_or_none: bool = false
205    }
206}