Skip to content

Commit

Permalink
fix: mesh is broken if all weighted bones are none
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Aug 7, 2024
1 parent f457738 commit 0033e1c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Internal/MeshInfo2/MeshInfo2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,22 @@ public void Optimize()

private void RemoveUnusedBones()
{
if (Bones.Count == 0) return;
var hasValidBone = Bones.Any(x => x.Transform != null);

// GC Bones
var usedBones = new HashSet<Bone>();
foreach (var meshInfo2Vertex in Vertices)
foreach (var (bone, _) in meshInfo2Vertex.BoneWeights)
usedBones.Add(bone);
Bones.RemoveAll(x => !usedBones.Contains(x));

if (hasValidBone && Bones.All(x => x.Transform == null))
{
// if all transform is null, the renderer will render nothing.
// so we have to some bone to render.
if (RootBone) Bones.Add(new Bone(Matrix4x4.identity, RootBone));
}
}

/// <returns>true if we flattened multi pass rendering</returns>
Expand Down

0 comments on commit 0033e1c

Please sign in to comment.