From 2d8af0ec226c7abbb97ed9ca8562619dacd9707e Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 24 Sep 2023 16:20:25 +0900 Subject: [PATCH 1/2] fix: AvatarMask is not mapped --- Editor/ObjectMapping/AnimationObjectMapper.cs | 34 +++++++++++++++++++ Editor/Processors/ApplyObjectMapping.cs | 24 ++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Editor/ObjectMapping/AnimationObjectMapper.cs b/Editor/ObjectMapping/AnimationObjectMapper.cs index e3fd821b0..06c5b9c35 100644 --- a/Editor/ObjectMapping/AnimationObjectMapper.cs +++ b/Editor/ObjectMapping/AnimationObjectMapper.cs @@ -84,6 +84,40 @@ public MappedGameObjectInfo(ObjectMapping objectMapping, string newPath, } } + [CanBeNull] + public string MapPath(string srcPath, Type type) + { + var gameObjectInfo = GetGameObjectInfo(srcPath); + if (gameObjectInfo == null) return srcPath; + var (instanceId, componentInfo) = gameObjectInfo.GetComponentByType(type); + + if (componentInfo != null) + { + var component = EditorUtility.InstanceIDToObject(componentInfo.MergedInto) as Component; + // there's mapping about component. + // this means the component is merged or some prop has mapping + if (!component) return null; // this means removed. + + var newPath = Utils.RelativePath(_rootGameObject.transform, component.transform); + if (newPath == null) return null; // this means moved to out of the animator scope + + return newPath; + } + else + { + // The component is not merged & no prop mapping so process GameObject mapping + + if (type != typeof(GameObject)) + { + var component = EditorUtility.InstanceIDToObject(instanceId) as Component; + if (!component) return null; // this means removed + } + + if (gameObjectInfo.NewPath == null) return null; + return gameObjectInfo.NewPath; + } + } + public EditorCurveBinding MapBinding(EditorCurveBinding binding) { var gameObjectInfo = GetGameObjectInfo(binding.path); diff --git a/Editor/Processors/ApplyObjectMapping.cs b/Editor/Processors/ApplyObjectMapping.cs index 25f2edd5f..1816b47cd 100644 --- a/Editor/Processors/ApplyObjectMapping.cs +++ b/Editor/Processors/ApplyObjectMapping.cs @@ -167,7 +167,7 @@ private AnimatorControllerLayer MapAnimatorControllerLayer(AnimatorControllerLay new AnimatorControllerLayer { name = layer.name, - avatarMask = layer.avatarMask, + avatarMask = DeepClone(layer.avatarMask, CustomClone), blendingMode = layer.blendingMode, defaultWeight = layer.defaultWeight, syncedLayerIndex = layer.syncedLayerIndex, @@ -215,6 +215,27 @@ private Object CustomClone(Object o) return newClip; } + else if (o is AvatarMask mask) + { + var newMask = _session.AddToAsset(new AvatarMask()); + newMask.name = "rebased " + mask.name; + newMask.transformCount = mask.transformCount; + var dstI = 0; + for (var srcI = 0; srcI < mask.transformCount; srcI++) + { + var path = mask.GetTransformPath(srcI); + var newPath = _mapping.MapPath(path, typeof(Transform)); + if (newPath != null) + { + newMask.SetTransformPath(dstI, newPath); + newMask.SetTransformActive(dstI, mask.GetTransformActive(srcI)); + dstI++; + } + } + newMask.transformCount = dstI; + + return newMask; + } else { return null; @@ -239,6 +260,7 @@ private T DeepClone(T original, Func visitor) where T : Objec case AnimatorStateMachine _: case AnimatorTransitionBase _: case StateMachineBehaviour _: + case AvatarMask _: break; // We want to clone these types // Leave textures, materials, and script definitions alone From 72235cfc4ac454f7ebf1f9fa41262333d245a41c Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sun, 24 Sep 2023 16:34:27 +0900 Subject: [PATCH 2/2] docs(changelog): AvatarMask broken with many cases --- CHANGELOG-PRERELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index f75663c1f..213b0cf8e 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog]. ### Removed ### Fixed +- AvatarMask broken with many cases `#502` ### Security