@@ -99,229 +99,3 @@ impl<T: Iterator<Item = (&'static [u8], Property)>> From<T> for PropertyStore {
99
99
props
100
100
}
101
101
}
102
-
103
- #[ cfg( test) ]
104
- mod test {
105
- use std:: path:: Path ;
106
-
107
- use crate :: node:: Node ;
108
- use crate :: scene:: { PostProcess , PostProcessSteps , Scene } ;
109
- use crate :: sys:: {
110
- AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION , AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES ,
111
- AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS , AI_CONFIG_IMPORT_FBX_READ_WEIGHTS ,
112
- AI_CONFIG_PP_OG_EXCLUDE_LIST , AI_CONFIG_PP_PTV_ADD_ROOT_TRANSFORMATION ,
113
- AI_CONFIG_PP_PTV_ROOT_TRANSFORMATION ,
114
- } ;
115
- use crate :: { utils, RussimpError , Russult } ;
116
-
117
- use super :: { Property , PropertyStore } ;
118
-
119
- fn load_scene_with_props (
120
- model : & str ,
121
- flags : Option < PostProcessSteps > ,
122
- props : & PropertyStore ,
123
- from_buffer : bool ,
124
- ) -> Russult < Scene > {
125
- let model = utils:: get_model ( model) ;
126
- let flags = flags. unwrap_or ( vec ! [ ] ) ;
127
- if from_buffer {
128
- let model_path = Path :: new ( model. as_str ( ) ) ;
129
- let buffer = std:: fs:: read ( model. as_str ( ) )
130
- . map_err ( |_| RussimpError :: Import ( String :: from ( "Failed to read file" ) ) ) ?;
131
- let file_name = model_path
132
- . file_name ( )
133
- . and_then ( |n| n. to_str ( ) )
134
- . unwrap_or ( "" ) ;
135
- Scene :: from_buffer_with_props ( buffer. as_slice ( ) , flags, file_name, props)
136
- } else {
137
- Scene :: from_file_with_props ( model. as_str ( ) , flags, props)
138
- }
139
- }
140
-
141
- #[ test]
142
- fn import_fbx_without_preserving_pivots ( ) {
143
- fn traverse_check_fbx_node ( node : & Node ) -> bool {
144
- if node. name . ends_with ( "_$AssimpFbx$_RotationPivot" )
145
- || node. name . ends_with ( "_$AssimpFbx$_RotationOffset" )
146
- || node. name . ends_with ( "_$AssimpFbx$_PreRotation" )
147
- || node. name . ends_with ( "_$AssimpFbx$_PostRotation" )
148
- || node. name . ends_with ( "_$AssimpFbx$_ScalingPivot" )
149
- || node. name . ends_with ( "_$AssimpFbx$_ScalingOffset" )
150
- || node. name . ends_with ( "_$AssimpFbx$_Translation" )
151
- || node. name . ends_with ( "_$AssimpFbx$_Scaling" )
152
- || node. name . ends_with ( "_$AssimpFbx$_Rotation" )
153
- {
154
- return false ;
155
- }
156
- for child in node. children . borrow ( ) . iter ( ) {
157
- if !traverse_check_fbx_node ( & * child) {
158
- return false ;
159
- }
160
- }
161
- true
162
- }
163
-
164
- let props: PropertyStore = [ (
165
- AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS as & [ u8 ] ,
166
- Property :: Integer ( 0 ) ,
167
- ) ]
168
- . into_iter ( )
169
- . into ( ) ;
170
- let scene = load_scene_with_props ( "models/FBX/y_bot_run.fbx" , None , & props, false ) . unwrap ( ) ;
171
-
172
- // NOTE: A scene with collapsed FBX transforms should not contain
173
- // nodes with names like "<OriginalName>_$AssimpFbx$_<TransformName>"
174
- // https://github.com/assimp/assimp/blob/master/code/AssetLib/FBX/FBXImportSettings.h#L141
175
- if let Some ( root) = scene. root {
176
- assert ! ( traverse_check_fbx_node( & root) ) ;
177
- }
178
- }
179
-
180
- #[ test]
181
- fn import_fbx_without_weights ( ) {
182
- let props: PropertyStore = [ (
183
- AI_CONFIG_IMPORT_FBX_READ_WEIGHTS as & [ u8 ] ,
184
- Property :: Integer ( 0 ) ,
185
- ) ]
186
- . into_iter ( )
187
- . into ( ) ;
188
- let scene = load_scene_with_props ( "models/FBX/y_bot_run.fbx" , None , & props, true ) . unwrap ( ) ;
189
- assert_eq ! ( scene. meshes. len( ) , 2 ) ;
190
- for mesh in & scene. meshes {
191
- for bone in & mesh. bones {
192
- assert_eq ! ( bone. weights. len( ) , 0 ) ;
193
- }
194
- }
195
- }
196
-
197
- #[ test]
198
- fn import_collada_with_ignore_up_direction ( ) {
199
- let props: PropertyStore = [ (
200
- AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION as & [ u8 ] ,
201
- Property :: Integer ( 1 ) ,
202
- ) ]
203
- . into_iter ( )
204
- . into ( ) ;
205
- let scene =
206
- load_scene_with_props ( "models/COLLADA/blender_cube.dae" , None , & props, false ) . unwrap ( ) ;
207
-
208
- // NOTE: Ignoring the COLLADA file's UP direction should yield
209
- // an identity matrix as the root node transformation, meaning
210
- // we are now using blender coordinate system (+Z up instead of +Y up)
211
- if let Some ( root) = scene. root {
212
- let is_identity = root. transformation . a1 == 1.0
213
- && root. transformation . a2 == 0.0
214
- && root. transformation . a3 == 0.0
215
- && root. transformation . a4 == 0.0
216
- && root. transformation . b1 == 0.0
217
- && root. transformation . b2 == 1.0
218
- && root. transformation . b3 == 0.0
219
- && root. transformation . b4 == 0.0
220
- && root. transformation . c1 == 0.0
221
- && root. transformation . c2 == 0.0
222
- && root. transformation . c3 == 1.0
223
- && root. transformation . c4 == 0.0
224
- && root. transformation . d1 == 0.0
225
- && root. transformation . d2 == 0.0
226
- && root. transformation . d3 == 0.0
227
- && root. transformation . d4 == 1.0 ;
228
- assert ! ( is_identity) ;
229
- }
230
- }
231
-
232
- #[ test]
233
- fn import_collada_with_use_collada_names ( ) {
234
- let props: PropertyStore = [ (
235
- AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES as & [ u8 ] ,
236
- Property :: Integer ( 1 ) ,
237
- ) ]
238
- . into_iter ( )
239
- . into ( ) ;
240
- let scene =
241
- load_scene_with_props ( "models/COLLADA/blender_cube.dae" , None , & props, true ) . unwrap ( ) ;
242
-
243
- // NOTE: Importing a COLLADA file with this option enabled
244
- // should yield the real mesh names like: "Cube.001"
245
- // instead of "Cube_001-mesh" as the importer should use
246
- // the geometry's `name` property instead of `id`
247
- assert_eq ! ( scene. meshes. len( ) , 1 ) ;
248
- assert_eq ! ( scene. meshes[ 0 ] . name, "Cube.001" ) ;
249
- }
250
-
251
- #[ test]
252
- fn import_pp_ptv_root_transformation ( ) {
253
- let props: PropertyStore = [
254
- (
255
- AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION ,
256
- Property :: Integer ( 1 ) ,
257
- ) ,
258
- (
259
- AI_CONFIG_PP_PTV_ADD_ROOT_TRANSFORMATION ,
260
- Property :: Integer ( 1 ) ,
261
- ) ,
262
- (
263
- AI_CONFIG_PP_PTV_ROOT_TRANSFORMATION ,
264
- Property :: Matrix ( [
265
- [ 1.0 , 0.0 , 0.0 , 0.0 ] ,
266
- [ 0.0 , 0.0 , -1.0 , 0.0 ] ,
267
- [ 0.0 , 1.0 , 0.0 , 0.0 ] ,
268
- [ 0.0 , 0.0 , 0.0 , 1.0 ] ,
269
- ] ) ,
270
- ) ,
271
- ]
272
- . into_iter ( )
273
- . into ( ) ;
274
- let scene = load_scene_with_props (
275
- "models/COLLADA/blender_plane.dae" ,
276
- Some ( vec ! [ PostProcess :: PreTransformVertices ] ) ,
277
- & props,
278
- false ,
279
- )
280
- . unwrap ( ) ;
281
-
282
- // NOTE: The exported blender plane's normal is facing +Z (ignoring COLLADA up direction)
283
- // If we pre-transform its vertices with the above matrix,
284
- // its normal should be aligned with the Y axis,
285
- // i.e. all the Y coordinates of its vertices should be equal to 0
286
- assert_eq ! ( scene. meshes. len( ) , 1 ) ;
287
- for vertex in & scene. meshes [ 0 ] . vertices {
288
- assert_eq ! ( vertex. y, 0.0 ) ;
289
- }
290
- }
291
-
292
- #[ test]
293
- fn import_pp_og_exclude_list ( ) {
294
- fn traverse_find_bone_end ( node : & Node ) -> bool {
295
- if node. name . as_str ( ) == "Bone_end" {
296
- return true ;
297
- }
298
- for child in node. children . borrow ( ) . iter ( ) {
299
- if traverse_find_bone_end ( & * child) {
300
- return true ;
301
- }
302
- }
303
- return false ;
304
- }
305
-
306
- let props: PropertyStore = [ (
307
- AI_CONFIG_PP_OG_EXCLUDE_LIST as & [ u8 ] ,
308
- Property :: String ( "Bone_end" ) ,
309
- ) ]
310
- . into_iter ( )
311
- . into ( ) ;
312
- let scene = load_scene_with_props (
313
- "models/FBX/cube_armature.fbx" ,
314
- Some ( vec ! [ PostProcess :: OptimizeGraph ] ) ,
315
- & props,
316
- true ,
317
- )
318
- . unwrap ( ) ;
319
-
320
- // NOTE: Exported FBX file contains a cube with a single bone.
321
- // The bone's end is also exported and is technically unused,
322
- // but setting this option should preserve it in the hierarchy.
323
- if let Some ( root) = & scene. root {
324
- assert ! ( traverse_find_bone_end( & * root) ) ;
325
- }
326
- }
327
- }
0 commit comments