diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs index c3412d014..23a91c19b 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs +++ b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs @@ -273,12 +273,16 @@ namespace UniHumanoid } #endif - public static void AddAnimator(GameObject _src, + public static Avatar CreateAvatarForCopyHierarchy( + Animator src, GameObject dst, IDictionary boneMap, Action modAvatarDesc = null) { - var src = _src.GetComponent(); + if (src == null) + { + throw new ArgumentNullException("src"); + } var srcHumanBones = CachedEnum.GetValues() .Where(x => x != HumanBodyBones.LastBone) @@ -292,12 +296,6 @@ namespace UniHumanoid .ToDictionary(x => x.Key, x => boneMap[x.Value]) ; - var animator = dst.AddComponent(); - if (animator == null) - { - animator = dst.AddComponent(); - } - var avatarDescription = UniHumanoid.AvatarDescription.Create(); if (modAvatarDesc != null) { @@ -305,9 +303,8 @@ namespace UniHumanoid } avatarDescription.SetHumanBones(map); var avatar = avatarDescription.CreateAvatar(dst.transform); - - avatar.name = dst.name; - animator.avatar = avatar; + avatar.name = "created"; + return avatar; } } } \ No newline at end of file diff --git a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs index 56fcca10b..3f5dcf927 100644 --- a/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs +++ b/Assets/VRM/Runtime/SkinnedMeshUtility/VRMBoneNormalizer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using UniGLTF; using UniGLTF.MeshUtility; using UniGLTF.Utils; using UniHumanoid; @@ -69,7 +70,8 @@ namespace VRM var (normalized, bMap) = BoneNormalizer.Execute(go); // 新しいヒエラルキーからAvatarを作る - UniHumanoid.AvatarDescription.AddAnimator(go, normalized, bMap, avatarDescription => + var newAvatar = UniHumanoid.AvatarDescription.CreateAvatarForCopyHierarchy( + go.GetComponent(), normalized, bMap, avatarDescription => { var vrmHuman = go.GetComponent(); if (vrmHuman != null && vrmHuman.Description != null) @@ -84,6 +86,8 @@ namespace VRM avatarDescription.hasTranslationDoF = vrmHuman.Description.hasTranslationDoF; } }); + var newAnimator = normalized.GetOrAddComponent(); + newAnimator.avatar = newAvatar; CopyVRMComponents(go, normalized, bMap); diff --git a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs index da612bee9..883bfc674 100644 --- a/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs +++ b/Assets/VRM10/Runtime/MeshUtility/Vrm10MeshUtility.cs @@ -133,7 +133,9 @@ namespace UniVRM10 // TODO: update: constraint // TODO: update: firstPoint offset - AvatarDescription.AddAnimator(go, normalized, boneMap); + var newAvatar = AvatarDescription.CreateAvatarForCopyHierarchy(go.GetComponent(), normalized, boneMap); + var newAnimator = normalized.GetOrAddComponent(); + newAnimator.avatar = newAvatar; // TODO: write back normalized transform to boneMap }