Skip to content

Commit

Permalink
only take up to the max number of joints (#9351)
Browse files Browse the repository at this point in the history
# Objective

- Meshes with a higher number of joints than `MAX_JOINTS` are crashing
- Fixes partly #9021 (doesn't crash anymore, but the mesh is not
correctly displayed)

## Solution

- Only take up to `MAX_JOINTS` joints when extending the buffer
  • Loading branch information
mockersf authored Aug 28, 2023
1 parent b8238b2 commit cd3fdbf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy_log::warn;
use bevy_math::{Mat4, Vec3};
use bevy_pbr::{
AlphaMode, DirectionalLight, DirectionalLightBundle, PbrBundle, PointLight, PointLightBundle,
SpotLight, SpotLightBundle, StandardMaterial,
SpotLight, SpotLightBundle, StandardMaterial, MAX_JOINTS,
};
use bevy_render::{
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
Expand Down Expand Up @@ -489,6 +489,7 @@ async fn load_gltf<'a, 'b>(
}
}

let mut warned_about_max_joints = HashSet::new();
for (&entity, &skin_index) in &entity_to_skin_index_map {
let mut entity = world.entity_mut(entity);
let skin = gltf.skins().nth(skin_index).unwrap();
Expand All @@ -497,6 +498,16 @@ async fn load_gltf<'a, 'b>(
.map(|node| node_index_to_entity_map[&node.index()])
.collect();

if joint_entities.len() > MAX_JOINTS && warned_about_max_joints.insert(skin_index) {
warn!(
"The glTF skin {:?} has {} joints, but the maximum supported is {}",
skin.name()
.map(|name| name.to_string())
.unwrap_or_else(|| skin.index().to_string()),
joint_entities.len(),
MAX_JOINTS
);
}
entity.insert(SkinnedMesh {
inverse_bindposes: skinned_mesh_inverse_bindposes[skin_index].clone(),
joints: joint_entities,
Expand Down

0 comments on commit cd3fdbf

Please sign in to comment.