From 211e51990019fc0e02c50ec0933df24ed6c74d40 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 11 Jul 2023 13:52:52 -0700 Subject: [PATCH 1/2] Add `GltfLoader::new`. In my application, I'm manually wrapping the built-in Bevy loaders with a wrapper loader that stores some metadata before calling into the inner Bevy loader. This worked for the glTF loader in Bevy 0.10, but in Bevy 0.11 it became impossible to do this because the glTF loader became unconstructible outside Bevy due to the new private fields within it. It's now in fact impossible to get a reference to a GltfLoader at all from outside Bevy, because the only way to construct a GltfLoader is to add the GltfPlugin to an App, and the GltfPlugin only hands out references to its GltfLoader to the asset server, which provides no public access to the loaders it manages. This commit fixes the problem by adding a public `new` method to allow manual construction of a glTF loader. --- crates/bevy_gltf/src/loader.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index ff6f96bd21b56..048c2f32660aa 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -74,6 +74,19 @@ pub struct GltfLoader { pub(crate) custom_vertex_attributes: HashMap, } +impl GltfLoader { + /// Creates a new glTF loader. + pub fn new( + supported_compressed_formats: CompressedImageFormats, + custom_vertex_attributes: HashMap, + ) -> Self { + GltfLoader { + supported_compressed_formats, + custom_vertex_attributes, + } + } +} + impl AssetLoader for GltfLoader { fn load<'a>( &'a self, From 9cf4a562240ab5d69105b6d0279ac7b743197a7c Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Thu, 13 Jul 2023 16:36:11 -0700 Subject: [PATCH 2/2] Public loader fields --- crates/bevy_gltf/src/loader.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index 048c2f32660aa..8861bd7e6726f 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -70,21 +70,8 @@ pub enum GltfError { /// Loads glTF files with all of their data as their corresponding bevy representations. pub struct GltfLoader { - pub(crate) supported_compressed_formats: CompressedImageFormats, - pub(crate) custom_vertex_attributes: HashMap, -} - -impl GltfLoader { - /// Creates a new glTF loader. - pub fn new( - supported_compressed_formats: CompressedImageFormats, - custom_vertex_attributes: HashMap, - ) -> Self { - GltfLoader { - supported_compressed_formats, - custom_vertex_attributes, - } - } + pub supported_compressed_formats: CompressedImageFormats, + pub custom_vertex_attributes: HashMap, } impl AssetLoader for GltfLoader {