|
1 | 1 | use anyhow::Result;
|
2 |
| -use bevy_asset::{AssetIoError, AssetLoader, AssetPath, LoadContext, LoadedAsset}; |
| 2 | +use bevy_asset::{AssetIoError, AssetLoader, AssetPath, Handle, LoadContext, LoadedAsset}; |
3 | 3 | use bevy_ecs::{bevy_utils::BoxedFuture, World, WorldBuilderSource};
|
4 | 4 | use bevy_math::Mat4;
|
5 | 5 | use bevy_pbr::prelude::{PbrBundle, StandardMaterial};
|
@@ -83,38 +83,7 @@ async fn load_gltf<'a, 'b>(
|
83 | 83 | let mut materials = vec![];
|
84 | 84 | let mut named_materials = HashMap::new();
|
85 | 85 | for material in gltf.materials() {
|
86 |
| - let material_label = material_label(&material); |
87 |
| - let pbr = material.pbr_metallic_roughness(); |
88 |
| - let mut dependencies = Vec::new(); |
89 |
| - let texture_handle = if let Some(info) = pbr.base_color_texture() { |
90 |
| - match info.texture().source().source() { |
91 |
| - gltf::image::Source::View { .. } => { |
92 |
| - let label = texture_label(&info.texture()); |
93 |
| - let path = AssetPath::new_ref(load_context.path(), Some(&label)); |
94 |
| - Some(load_context.get_handle(path)) |
95 |
| - } |
96 |
| - gltf::image::Source::Uri { uri, .. } => { |
97 |
| - let parent = load_context.path().parent().unwrap(); |
98 |
| - let image_path = parent.join(uri); |
99 |
| - let asset_path = AssetPath::new(image_path, None); |
100 |
| - let handle = load_context.get_handle(asset_path.clone()); |
101 |
| - dependencies.push(asset_path); |
102 |
| - Some(handle) |
103 |
| - } |
104 |
| - } |
105 |
| - } else { |
106 |
| - None |
107 |
| - }; |
108 |
| - let color = pbr.base_color_factor(); |
109 |
| - let handle = load_context.set_labeled_asset( |
110 |
| - &material_label, |
111 |
| - LoadedAsset::new(StandardMaterial { |
112 |
| - albedo: Color::rgba(color[0], color[1], color[2], color[3]), |
113 |
| - albedo_texture: texture_handle, |
114 |
| - ..Default::default() |
115 |
| - }) |
116 |
| - .with_dependencies(dependencies), |
117 |
| - ); |
| 86 | + let handle = load_material(&material, load_context); |
118 | 87 | if let Some(name) = material.name() {
|
119 | 88 | named_materials.insert(name.to_string(), handle.clone());
|
120 | 89 | }
|
@@ -252,10 +221,6 @@ async fn load_gltf<'a, 'b>(
|
252 | 221 | }
|
253 | 222 | }
|
254 | 223 |
|
255 |
| - for material in gltf.materials() { |
256 |
| - load_material(&material, load_context); |
257 |
| - } |
258 |
| - |
259 | 224 | let mut scenes = vec![];
|
260 | 225 | let mut named_scenes = HashMap::new();
|
261 | 226 | for scene in gltf.scenes() {
|
@@ -303,7 +268,7 @@ async fn load_gltf<'a, 'b>(
|
303 | 268 | Ok(())
|
304 | 269 | }
|
305 | 270 |
|
306 |
| -fn load_material(material: &Material, load_context: &mut LoadContext) { |
| 271 | +fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle<StandardMaterial> { |
307 | 272 | let material_label = material_label(&material);
|
308 | 273 | let pbr = material.pbr_metallic_roughness();
|
309 | 274 | let mut dependencies = Vec::new();
|
|
0 commit comments