Skip to content

Commit

Permalink
fix: animation broken with auto merge blendShape
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Nov 3, 2024
1 parent c2b6039 commit e9f237a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Editor/Processors/TraceAndOptimize/AutoMergeBlendShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ private static void DoAutoMerge(MeshInfo2 meshInfo2, BuildContext context)
// bulk remove to optimize removing blendshape process
var removeNames = new HashSet<string>();

var newNames = new Dictionary<string, string>();

var i = 0;
// there is thing to merge
foreach (var (key, names) in groups)
Expand Down Expand Up @@ -82,6 +84,12 @@ private static void DoAutoMerge(MeshInfo2 meshInfo2, BuildContext context)
// validation passed, merge
var newName = $"AAO_Merged_{string.Join("_", names)}_{i++}";

foreach (var name in names)
{
newNames.Add(name, newName);
context.RecordMoveProperty(meshInfo2.SourceRenderer, $"blendShape.{name}", $"blendShape.{newName}");
}

// process meshInfo2
meshInfo2.BlendShapes.Add((newName, key.defaultWeight));
removeNames.UnionWith(names);
Expand Down Expand Up @@ -131,8 +139,22 @@ private static void DoAutoMerge(MeshInfo2 meshInfo2, BuildContext context)
next_shape: ;
}

var prevNames = meshInfo2.BlendShapes.Select(x => x.name).ToList();

// remove merged blendShapes
meshInfo2.BlendShapes.RemoveAll(x => removeNames.Contains(x.name));

for (var index = 0; index < prevNames.Count; index++)
{
var name = prevNames[index];
var newName = newNames.GetValueOrDefault(name, name);
var newIndex = meshInfo2.BlendShapes.FindIndex(x => x.name == newName);
if (newIndex != -1)
{
context.RecordMoveProperty(meshInfo2.SourceRenderer,
VProp.BlendShapeIndex(index), VProp.BlendShapeIndex(newIndex));
}
}
}

readonly struct MergeKey : IEquatable<MergeKey>
Expand Down

0 comments on commit e9f237a

Please sign in to comment.