Skip to content

Commit

Permalink
Merge pull request #1138 from anatawa12/fix-breaks-if-all-used-bones-…
Browse files Browse the repository at this point in the history
…are-none

fix: mesh is broken if all weighted bones are none
  • Loading branch information
anatawa12 authored Aug 7, 2024
2 parents f457738 + 8868752 commit 5126cc2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-PRERELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog].
### Fixed
- Some Humanoid Bones might be removed `#1137`
- Repeated `AddPathDependency` is broken.
- Render is broken if all weighted bone is none and some other non-weight bone is not none `#1138`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog].
### Fixed
- Some Humanoid Bones might be removed `#1137`
- Repeated `AddPathDependency` is broken.
- Render is broken if all weighted bone is none and some other non-weight bone is not none `#1138`

### Security

Expand Down
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 5126cc2

Please sign in to comment.