Skip to content

Commit

Permalink
Merge pull request #451 from anatawa12/remove-mesh-with-blendshape-wi…
Browse files Browse the repository at this point in the history
…th-merge-skinned-mesh

fix: RemoveMeshByBlendShape on the SMR with MergeSkinnedMesh not working
  • Loading branch information
anatawa12 authored Sep 11, 2023
2 parents 71e80b6 + 7195056 commit 931a823
Show file tree
Hide file tree
Showing 3 changed files with 31 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
- MergeBone will break Normal and Tangent `#448`
- PhysBone for Animator Parameter disappears `#452`
- RemoveMeshByBlendShape on the SkinnedMeshRenderer with MergeSkinnedMesh not working `#451`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog].
- Crash with Unity 2022 `#423`
- [Due to bug in Unity Editor 2022.3 or later][unity-bug], Avatar Optimizer was not compatible with Unity 2022.
- Error if all vertices of some BlendShape is removed by RemoveMeshByBlendShape or RemoveMeshInBox `#440`
- RemoveMeshByBlendShape on the SkinnedMeshRenderer with MergeSkinnedMesh not working `#451`

[unity-bug]: https://issuetracker.unity3d.com/issues/crash-on-gettargetassemblybyscriptpath-when-a-po-file-in-the-packages-directory-is-not-under-an-assembly-definition

Expand Down
29 changes: 29 additions & 0 deletions Editor/Processors/TraceAndOptimize/AnimatorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ private void OtherMutateComponents(ModificationsContainer mod, OptimizerSession
updater.AddModificationAsNewLayer(prop, AnimationProperty.Variable());
break;
}
case RemoveMeshByBlendShape removeMesh:
{
var blendShapes = removeMesh.RemovingShapeKeys;
{
var updater = mod.ModifyObject(removeMesh.GetComponent<SkinnedMeshRenderer>());
foreach (var blendShape in blendShapes)
updater.AddModificationAsNewLayer($"blendShape.{blendShape}",
AnimationProperty.Variable());
}

DeriveMergeSkinnedMeshProperties(removeMesh.GetComponent<MergeSkinnedMesh>());

void DeriveMergeSkinnedMeshProperties(MergeSkinnedMesh mergeSkinnedMesh)
{
if (mergeSkinnedMesh == null) return;

foreach (var renderer in mergeSkinnedMesh.renderersSet.GetAsSet())
{
var updater = mod.ModifyObject(renderer);
foreach (var blendShape in blendShapes)
updater.AddModificationAsNewLayer($"blendShape.{blendShape}",
AnimationProperty.Variable());

DeriveMergeSkinnedMeshProperties(renderer.GetComponent<MergeSkinnedMesh>());
}
}

break;
}
default:
{
if (DynamicBone.TryCast(component, out var dynamicBone))
Expand Down

0 comments on commit 931a823

Please sign in to comment.