@@ -16,8 +16,17 @@ fn main() {
16
16
. add_systems ( OnEnter ( Scene :: Gltf ) , gltf:: setup)
17
17
. add_systems ( OnEnter ( Scene :: Animation ) , animation:: setup)
18
18
. add_systems ( OnEnter ( Scene :: Gizmos ) , gizmos:: setup)
19
+ . add_systems (
20
+ OnEnter ( Scene :: GltfCoordinateConversion ) ,
21
+ gltf_coordinate_conversion:: setup,
22
+ )
19
23
. add_systems ( Update , switch_scene)
20
- . add_systems ( Update , gizmos:: draw_gizmos. run_if ( in_state ( Scene :: Gizmos ) ) ) ;
24
+ . add_systems ( Update , gizmos:: draw_gizmos. run_if ( in_state ( Scene :: Gizmos ) ) )
25
+ . add_systems (
26
+ Update ,
27
+ gltf_coordinate_conversion:: draw_gizmos
28
+ . run_if ( in_state ( Scene :: GltfCoordinateConversion ) ) ,
29
+ ) ;
21
30
22
31
#[ cfg( feature = "bevy_ci_testing" ) ]
23
32
app. add_systems ( Update , helpers:: switch_scene_in_ci :: < Scene > ) ;
@@ -33,6 +42,7 @@ enum Scene {
33
42
Gltf ,
34
43
Animation ,
35
44
Gizmos ,
45
+ GltfCoordinateConversion ,
36
46
}
37
47
38
48
impl Next for Scene {
@@ -42,7 +52,8 @@ impl Next for Scene {
42
52
Scene :: Bloom => Scene :: Gltf ,
43
53
Scene :: Gltf => Scene :: Animation ,
44
54
Scene :: Animation => Scene :: Gizmos ,
45
- Scene :: Gizmos => Scene :: Light ,
55
+ Scene :: Gizmos => Scene :: GltfCoordinateConversion ,
56
+ Scene :: GltfCoordinateConversion => Scene :: Light ,
46
57
}
47
58
}
48
59
}
@@ -340,3 +351,78 @@ mod gizmos {
340
351
}
341
352
}
342
353
}
354
+
355
+ mod gltf_coordinate_conversion {
356
+ use bevy:: {
357
+ color:: palettes:: basic:: * , gltf:: GltfLoaderSettings , prelude:: * , scene:: SceneInstanceReady ,
358
+ } ;
359
+
360
+ const CURRENT_SCENE : super :: Scene = super :: Scene :: GltfCoordinateConversion ;
361
+
362
+ pub fn setup ( mut commands : Commands , asset_server : Res < AssetServer > ) {
363
+ commands. spawn ( (
364
+ Camera3d :: default ( ) ,
365
+ Transform :: from_xyz ( -4.0 , 4.0 , -5.0 ) . looking_at ( Vec3 :: ZERO , Vec3 :: Y ) ,
366
+ DespawnOnExitState ( CURRENT_SCENE ) ,
367
+ ) ) ;
368
+
369
+ commands. spawn ( (
370
+ DirectionalLight {
371
+ color : BLUE . into ( ) ,
372
+ ..default ( )
373
+ } ,
374
+ Transform :: IDENTITY . looking_to ( Dir3 :: Z , Dir3 :: Y ) ,
375
+ DespawnOnExitState ( CURRENT_SCENE ) ,
376
+ ) ) ;
377
+
378
+ commands. spawn ( (
379
+ DirectionalLight {
380
+ color : RED . into ( ) ,
381
+ ..default ( )
382
+ } ,
383
+ Transform :: IDENTITY . looking_to ( Dir3 :: X , Dir3 :: Y ) ,
384
+ DespawnOnExitState ( CURRENT_SCENE ) ,
385
+ ) ) ;
386
+
387
+ commands. spawn ( (
388
+ DirectionalLight {
389
+ color : GREEN . into ( ) ,
390
+ ..default ( )
391
+ } ,
392
+ Transform :: IDENTITY . looking_to ( Dir3 :: NEG_Y , Dir3 :: X ) ,
393
+ DespawnOnExitState ( CURRENT_SCENE ) ,
394
+ ) ) ;
395
+
396
+ commands
397
+ . spawn ( (
398
+ SceneRoot ( asset_server. load_with_settings (
399
+ GltfAssetLabel :: Scene ( 0 ) . from_asset ( "models/Faces/faces.glb" ) ,
400
+ |s : & mut GltfLoaderSettings | {
401
+ s. use_model_forward_direction = Some ( true ) ;
402
+ } ,
403
+ ) ) ,
404
+ DespawnOnExitState ( CURRENT_SCENE ) ,
405
+ ) )
406
+ . observe ( show_aabbs) ;
407
+ }
408
+
409
+ pub fn show_aabbs (
410
+ trigger : On < SceneInstanceReady > ,
411
+ mut commands : Commands ,
412
+ children : Query < & Children > ,
413
+ meshes : Query < ( ) , With < Mesh3d > > ,
414
+ ) {
415
+ for child in children
416
+ . iter_descendants ( trigger. target ( ) )
417
+ . filter ( |& e| meshes. contains ( e) )
418
+ {
419
+ commands. entity ( child) . insert ( ShowAabbGizmo {
420
+ color : Some ( BLACK . into ( ) ) ,
421
+ } ) ;
422
+ }
423
+ }
424
+
425
+ pub fn draw_gizmos ( mut gizmos : Gizmos ) {
426
+ gizmos. axes ( Transform :: IDENTITY , 1.0 ) ;
427
+ }
428
+ }
0 commit comments