@@ -28,10 +28,7 @@ mod atmosphere;
2828mod cluster;
2929mod components;
3030pub mod contact_shadows;
31- use bevy_gltf:: {
32- extensions:: { GltfExtensionHandler , GltfExtensionHandlers } ,
33- GltfAssetLabel ,
34- } ;
31+ mod gltf;
3532use bevy_render:: sync_component:: SyncComponent ;
3633pub use contact_shadows:: {
3734 ContactShadows , ContactShadowsBuffer , ContactShadowsPlugin , ContactShadowsUniform ,
@@ -60,8 +57,6 @@ mod volumetric_fog;
6057use bevy_color:: { Color , LinearRgba } ;
6158
6259pub use atmosphere:: * ;
63- use bevy_asset:: LoadContext ;
64- use bevy_gltf:: { gltf, GltfMaterial } ;
6560use bevy_light:: { AmbientLight , DirectionalLight , PointLight , ShadowFilteringMethod , SpotLight } ;
6661use bevy_shader:: { load_shader_library, ShaderRef } ;
6762pub use cluster:: * ;
@@ -230,22 +225,7 @@ impl Plugin for PbrPlugin {
230225 . add_plugins ( ( ScatteringMediumPlugin , AtmospherePlugin ) ) ;
231226
232227 if self . gltf_render_enabled {
233- #[ cfg( target_family = "wasm" ) ]
234- bevy_tasks:: block_on ( async {
235- app. world_mut ( )
236- . resource_mut :: < GltfExtensionHandlers > ( )
237- . 0
238- . write ( )
239- . await
240- . push ( Box :: new ( GltfExtensionHandlerPbr ) )
241- } ) ;
242-
243- #[ cfg( not( target_family = "wasm" ) ) ]
244- app. world_mut ( )
245- . resource_mut :: < GltfExtensionHandlers > ( )
246- . 0
247- . write_blocking ( )
248- . push ( Box :: new ( GltfExtensionHandlerPbr ) ) ;
228+ gltf:: add_gltf ( app) ;
249229 }
250230
251231 if self . add_default_deferred_lighting_plugin {
@@ -385,120 +365,6 @@ pub fn stbn_placeholder() -> Image {
385365 }
386366}
387367
388- fn standard_material_from_gltf_material ( material : & GltfMaterial ) -> StandardMaterial {
389- StandardMaterial {
390- base_color : material. base_color ,
391- base_color_channel : material. base_color_channel . clone ( ) ,
392- base_color_texture : material. base_color_texture . clone ( ) ,
393- emissive : material. emissive ,
394- emissive_channel : material. emissive_channel . clone ( ) ,
395- emissive_texture : material. emissive_texture . clone ( ) ,
396- perceptual_roughness : material. perceptual_roughness ,
397- metallic : material. metallic ,
398- metallic_roughness_channel : material. metallic_roughness_channel . clone ( ) ,
399- metallic_roughness_texture : material. metallic_roughness_texture . clone ( ) ,
400- reflectance : material. reflectance ,
401- specular_tint : material. specular_tint ,
402- specular_transmission : material. specular_transmission ,
403- #[ cfg( feature = "pbr_transmission_textures" ) ]
404- specular_transmission_channel : material. specular_transmission_channel . clone ( ) ,
405- #[ cfg( feature = "pbr_transmission_textures" ) ]
406- specular_transmission_texture : material. specular_transmission_texture . clone ( ) ,
407- thickness : material. thickness ,
408- #[ cfg( feature = "pbr_transmission_textures" ) ]
409- thickness_channel : material. thickness_channel . clone ( ) ,
410- #[ cfg( feature = "pbr_transmission_textures" ) ]
411- thickness_texture : material. thickness_texture . clone ( ) ,
412- ior : material. ior ,
413- attenuation_distance : material. attenuation_distance ,
414- attenuation_color : material. attenuation_color ,
415- normal_map_channel : material. normal_map_channel . clone ( ) ,
416- normal_map_texture : material. normal_map_texture . clone ( ) ,
417- occlusion_channel : material. occlusion_channel . clone ( ) ,
418- occlusion_texture : material. occlusion_texture . clone ( ) ,
419- #[ cfg( feature = "pbr_specular_textures" ) ]
420- specular_channel : material. specular_channel . clone ( ) ,
421- #[ cfg( feature = "pbr_specular_textures" ) ]
422- specular_texture : material. specular_texture . clone ( ) ,
423- #[ cfg( feature = "pbr_specular_textures" ) ]
424- specular_tint_channel : material. specular_tint_channel . clone ( ) ,
425- #[ cfg( feature = "pbr_specular_textures" ) ]
426- specular_tint_texture : material. specular_tint_texture . clone ( ) ,
427- clearcoat : material. clearcoat ,
428- clearcoat_perceptual_roughness : material. clearcoat_perceptual_roughness ,
429- #[ cfg( feature = "pbr_multi_layer_material_textures" ) ]
430- clearcoat_roughness_channel : material. clearcoat_roughness_channel . clone ( ) ,
431- #[ cfg( feature = "pbr_multi_layer_material_textures" ) ]
432- clearcoat_roughness_texture : material. clearcoat_roughness_texture . clone ( ) ,
433- #[ cfg( feature = "pbr_multi_layer_material_textures" ) ]
434- clearcoat_normal_channel : material. clearcoat_normal_channel . clone ( ) ,
435- #[ cfg( feature = "pbr_multi_layer_material_textures" ) ]
436- clearcoat_normal_texture : material. clearcoat_normal_texture . clone ( ) ,
437- anisotropy_strength : material. anisotropy_strength ,
438- anisotropy_rotation : material. anisotropy_rotation ,
439- #[ cfg( feature = "pbr_anisotropy_texture" ) ]
440- anisotropy_channel : material. anisotropy_channel . clone ( ) ,
441- #[ cfg( feature = "pbr_anisotropy_texture" ) ]
442- anisotropy_texture : material. anisotropy_texture . clone ( ) ,
443- double_sided : material. double_sided ,
444- cull_mode : material. cull_mode ,
445- unlit : material. unlit ,
446- alpha_mode : material. alpha_mode ,
447- uv_transform : material. uv_transform ,
448- ..Default :: default ( )
449- }
450- }
451-
452- #[ derive( Default , Clone ) ]
453- struct GltfExtensionHandlerPbr ;
454-
455- impl GltfExtensionHandler for GltfExtensionHandlerPbr {
456- fn dyn_clone ( & self ) -> Box < dyn GltfExtensionHandler > {
457- Box :: new ( ( * self ) . clone ( ) )
458- }
459- fn on_root ( & mut self , load_context : & mut LoadContext < ' _ > , _gltf : & gltf:: Gltf ) {
460- // create the `StandardMaterial` for the glTF `DefaultMaterial` so
461- // it can be accessed when meshes don't have materials.
462- let std_label = format ! ( "{}#std" , GltfAssetLabel :: DefaultMaterial ) ;
463-
464- load_context. add_labeled_asset (
465- std_label,
466- standard_material_from_gltf_material ( & GltfMaterial :: default ( ) ) ,
467- ) ;
468- }
469-
470- fn on_material (
471- & mut self ,
472- load_context : & mut LoadContext < ' _ > ,
473- _gltf_material : & gltf:: Material ,
474- _material : Handle < GltfMaterial > ,
475- material_asset : & GltfMaterial ,
476- material_label : & str ,
477- ) {
478- let std_label = format ! ( "{}#std" , material_label) ;
479-
480- load_context. add_labeled_asset (
481- std_label,
482- standard_material_from_gltf_material ( material_asset) ,
483- ) ;
484- }
485-
486- fn on_spawn_mesh_and_material (
487- & mut self ,
488- load_context : & mut LoadContext < ' _ > ,
489- _primitive : & gltf:: Primitive ,
490- _mesh : & gltf:: Mesh ,
491- _material : & gltf:: Material ,
492- entity : & mut EntityWorldMut ,
493- material_label : & str ,
494- ) {
495- let std_label = format ! ( "{}#std" , material_label) ;
496- let handle = load_context. get_label_handle :: < StandardMaterial > ( std_label) ;
497-
498- entity. insert ( MeshMaterial3d ( handle) ) ;
499- }
500- }
501-
502368impl SyncComponent < PbrPlugin > for DirectionalLight {
503369 type Out = Self ;
504370}
0 commit comments