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:
andristarr 2024-02-19 17:49:32 +01:00 committed by GitHub
parent a475511f43
commit e50e848b58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,7 +8,7 @@ use bevy_core_pipeline::prelude::Camera3dBundle;
use bevy_ecs::entity::EntityHashMap;
use bevy_ecs::{entity::Entity, world::World};
use bevy_hierarchy::{BuildWorldChildren, WorldChildBuilder};
use bevy_log::{error, warn};
use bevy_log::{error, info_span, warn};
use bevy_math::{Mat4, Vec3};
use bevy_pbr::{
AlphaMode, DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle,
@ -46,6 +46,7 @@ use gltf::{
Material, Node, Primitive, Semantic,
};
use serde::{Deserialize, Serialize};
use std::io::Error;
use std::{
collections::VecDeque,
path::{Path, PathBuf},
@ -181,6 +182,15 @@ async fn load_gltf<'a, 'b, 'c>(
settings: &'b GltfLoaderSettings,
) -> Result<Gltf, GltfError> {
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 mut linear_textures = HashSet::default();
@ -376,7 +386,6 @@ async fn load_gltf<'a, 'b, 'c>(
}
materials.push(handle);
}
let mut meshes = vec![];
let mut named_meshes = HashMap::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()
{
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: {:?}",
err
);
}
}
});
}
let mesh = load_context.add_labeled_asset(primitive_label, mesh);