Gltf loader now shows which file is missing pre baked tangents (#11854)
# Objective - Gltf loader now shows which file is missing pre baked tangents - Fixes #11831 ## Solution - The file name is shown in the error message - What changed as a result of this PR? ### Changed: - Gltf loader now shows which file is missing pre baked tangents - If this PR is a breaking change (relative to the last release of Bevy), describe how a user might need to migrate their code to support these changes - Simply adding new functionality is not a breaking change. - Fixing behavior that was definitely a bug, rather than a questionable design choice is not a breaking change.
This commit is contained in:
		
							parent
							
								
									a475511f43
								
							
						
					
					
						commit
						e50e848b58
					
				| @ -8,7 +8,7 @@ use bevy_core_pipeline::prelude::Camera3dBundle; | |||||||
| use bevy_ecs::entity::EntityHashMap; | use bevy_ecs::entity::EntityHashMap; | ||||||
| use bevy_ecs::{entity::Entity, world::World}; | use bevy_ecs::{entity::Entity, world::World}; | ||||||
| use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder}; | use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder}; | ||||||
| use bevy_log::{error, warn}; | use bevy_log::{error, info_span, warn}; | ||||||
| use bevy_math::{Mat4, Vec3}; | use bevy_math::{Mat4, Vec3}; | ||||||
| use bevy_pbr::{ | use bevy_pbr::{ | ||||||
|     AlphaMode, DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle, |     AlphaMode, DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle, | ||||||
| @ -46,6 +46,7 @@ use gltf::{ | |||||||
|     Material, Node, Primitive, Semantic, |     Material, Node, Primitive, Semantic, | ||||||
| }; | }; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
|  | use std::io::Error; | ||||||
| use std::{ | use std::{ | ||||||
|     collections::VecDeque, |     collections::VecDeque, | ||||||
|     path::{Path, PathBuf}, |     path::{Path, PathBuf}, | ||||||
| @ -181,6 +182,15 @@ async fn load_gltf<'a, 'b, 'c>( | |||||||
|     settings: &'b GltfLoaderSettings, |     settings: &'b GltfLoaderSettings, | ||||||
| ) -> Result<Gltf, GltfError> { | ) -> Result<Gltf, GltfError> { | ||||||
|     let gltf = gltf::Gltf::from_slice(bytes)?; |     let gltf = gltf::Gltf::from_slice(bytes)?; | ||||||
|  |     let file_name = load_context | ||||||
|  |         .asset_path() | ||||||
|  |         .path() | ||||||
|  |         .to_str() | ||||||
|  |         .ok_or(GltfError::Gltf(gltf::Error::Io(Error::new( | ||||||
|  |             std::io::ErrorKind::InvalidInput, | ||||||
|  |             "Gltf file name invalid", | ||||||
|  |         ))))? | ||||||
|  |         .to_string(); | ||||||
|     let buffer_data = load_buffers(&gltf, load_context).await?; |     let buffer_data = load_buffers(&gltf, load_context).await?; | ||||||
| 
 | 
 | ||||||
|     let mut linear_textures = HashSet::default(); |     let mut linear_textures = HashSet::default(); | ||||||
| @ -376,7 +386,6 @@ async fn load_gltf<'a, 'b, 'c>( | |||||||
|         } |         } | ||||||
|         materials.push(handle); |         materials.push(handle); | ||||||
|     } |     } | ||||||
| 
 |  | ||||||
|     let mut meshes = vec![]; |     let mut meshes = vec![]; | ||||||
|     let mut named_meshes = HashMap::default(); |     let mut named_meshes = HashMap::default(); | ||||||
|     let mut meshes_on_skinned_nodes = HashSet::default(); |     let mut meshes_on_skinned_nodes = HashSet::default(); | ||||||
| @ -481,14 +490,19 @@ async fn load_gltf<'a, 'b, 'c>( | |||||||
|                 && primitive.material().normal_texture().is_some() |                 && primitive.material().normal_texture().is_some() | ||||||
|             { |             { | ||||||
|                 bevy_log::debug!( |                 bevy_log::debug!( | ||||||
|                     "Missing vertex tangents, computing them using the mikktspace algorithm" |                     "Missing vertex tangents for {}, computing them using the mikktspace algorithm. Consider using a tool such as Blender to pre-compute the tangents.", file_name | ||||||
|                 ); |                 ); | ||||||
|                 if let Err(err) = mesh.generate_tangents() { | 
 | ||||||
|                     warn!( |                 let generate_tangents_span = info_span!("generate_tangents", name = file_name); | ||||||
|  | 
 | ||||||
|  |                 generate_tangents_span.in_scope(|| { | ||||||
|  |                     if let Err(err) = mesh.generate_tangents() { | ||||||
|  |                         warn!( | ||||||
|                         "Failed to generate vertex tangents using the mikktspace algorithm: {:?}", |                         "Failed to generate vertex tangents using the mikktspace algorithm: {:?}", | ||||||
|                         err |                         err | ||||||
|                     ); |                     ); | ||||||
|                 } |                     } | ||||||
|  |                 }); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             let mesh = load_context.add_labeled_asset(primitive_label, mesh); |             let mesh = load_context.add_labeled_asset(primitive_label, mesh); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 andristarr
						andristarr