@@ -2,16 +2,12 @@ mod extensions;
22mod gltf_ext;
33
44use alloc:: sync:: Arc ;
5- use std:: {
6- io:: Error ,
7- path:: { Path , PathBuf } ,
8- sync:: Mutex ,
9- } ;
5+ use std:: { io:: Error , sync:: Mutex } ;
106
117#[ cfg( feature = "bevy_animation" ) ]
128use bevy_animation:: { prelude:: * , AnimatedBy , AnimationTargetId } ;
139use bevy_asset:: {
14- io:: Reader , AssetLoadError , AssetLoader , Handle , LoadContext , ParseAssetPathError ,
10+ io:: Reader , AssetLoadError , AssetLoader , AssetPath , Handle , LoadContext , ParseAssetPathError ,
1511 ReadAssetBytesError , RenderAssetUsages ,
1612} ;
1713use bevy_camera:: {
@@ -113,6 +109,9 @@ pub enum GltfError {
113109 /// Error when loading a texture. Might be due to a disabled image file format feature.
114110 #[ error( "You may need to add the feature for the file format: {0}" ) ]
115111 ImageError ( #[ from] TextureError ) ,
112+ /// The image URI was unable to be resolved wrt the asset path.
113+ #[ error( "invalid image uri: {0}. asset path error={1}" ) ]
114+ InvalidImageUri ( String , ParseAssetPathError ) ,
116115 /// Failed to read bytes from an asset path.
117116 #[ error( "failed to read bytes from an asset path: {0}" ) ]
118117 ReadAssetBytesError ( #[ from] ReadAssetBytesError ) ,
@@ -598,12 +597,11 @@ impl GltfLoader {
598597 let mut _texture_handles = Vec :: new ( ) ;
599598 if gltf. textures ( ) . len ( ) == 1 || cfg ! ( target_arch = "wasm32" ) {
600599 for texture in gltf. textures ( ) {
601- let parent_path = load_context. path ( ) . parent ( ) . unwrap ( ) ;
602600 let image = load_image (
603601 texture,
604602 & buffer_data,
605603 & linear_textures,
606- parent_path ,
604+ load_context . asset_path ( ) ,
607605 loader. supported_compressed_formats ,
608606 default_sampler,
609607 settings,
@@ -616,15 +614,15 @@ impl GltfLoader {
616614 IoTaskPool :: get ( )
617615 . scope ( |scope| {
618616 gltf. textures ( ) . for_each ( |gltf_texture| {
619- let parent_path = load_context. path ( ) . parent ( ) . unwrap ( ) ;
617+ let asset_path = load_context. asset_path ( ) . clone ( ) ;
620618 let linear_textures = & linear_textures;
621619 let buffer_data = & buffer_data;
622620 scope. spawn ( async move {
623621 load_image (
624622 gltf_texture,
625623 buffer_data,
626624 linear_textures,
627- parent_path ,
625+ & asset_path ,
628626 loader. supported_compressed_formats ,
629627 default_sampler,
630628 settings,
@@ -1082,7 +1080,7 @@ async fn load_image<'a, 'b>(
10821080 gltf_texture : gltf:: Texture < ' a > ,
10831081 buffer_data : & [ Vec < u8 > ] ,
10841082 linear_textures : & HashSet < usize > ,
1085- parent_path : & ' b Path ,
1083+ gltf_path : & ' b AssetPath < ' b > ,
10861084 supported_compressed_formats : CompressedImageFormats ,
10871085 default_sampler : & ImageSamplerDescriptor ,
10881086 settings : & GltfLoaderSettings ,
@@ -1132,7 +1130,9 @@ async fn load_image<'a, 'b>(
11321130 label : GltfAssetLabel :: Texture ( gltf_texture. index ( ) ) ,
11331131 } )
11341132 } else {
1135- let image_path = parent_path. join ( uri) ;
1133+ let image_path = gltf_path
1134+ . resolve_embed ( uri)
1135+ . map_err ( |err| GltfError :: InvalidImageUri ( uri. to_owned ( ) , err) ) ?;
11361136 Ok ( ImageOrPath :: Path {
11371137 path : image_path,
11381138 is_srgb,
@@ -1808,7 +1808,7 @@ enum ImageOrPath {
18081808 label : GltfAssetLabel ,
18091809 } ,
18101810 Path {
1811- path : PathBuf ,
1811+ path : AssetPath < ' static > ,
18121812 is_srgb : bool ,
18131813 sampler_descriptor : ImageSamplerDescriptor ,
18141814 } ,
0 commit comments