mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-23 03:16:12 -05:00
AvatarDescription.AddAnimator to CreateAvatarForCopyHierarchy
This commit is contained in:
parent
26c7cb9256
commit
787dada27e
|
|
@ -273,12 +273,16 @@ namespace UniHumanoid
|
|||
}
|
||||
#endif
|
||||
|
||||
public static void AddAnimator(GameObject _src,
|
||||
public static Avatar CreateAvatarForCopyHierarchy(
|
||||
Animator src,
|
||||
GameObject dst,
|
||||
IDictionary<Transform, Transform> boneMap,
|
||||
Action<AvatarDescription> modAvatarDesc = null)
|
||||
{
|
||||
var src = _src.GetComponent<Animator>();
|
||||
if (src == null)
|
||||
{
|
||||
throw new ArgumentNullException("src");
|
||||
}
|
||||
|
||||
var srcHumanBones = CachedEnum.GetValues<HumanBodyBones>()
|
||||
.Where(x => x != HumanBodyBones.LastBone)
|
||||
|
|
@ -292,12 +296,6 @@ namespace UniHumanoid
|
|||
.ToDictionary(x => x.Key, x => boneMap[x.Value])
|
||||
;
|
||||
|
||||
var animator = dst.AddComponent<Animator>();
|
||||
if (animator == null)
|
||||
{
|
||||
animator = dst.AddComponent<Animator>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Animator>(), normalized, bMap, avatarDescription =>
|
||||
{
|
||||
var vrmHuman = go.GetComponent<VRMHumanoidDescription>();
|
||||
if (vrmHuman != null && vrmHuman.Description != null)
|
||||
|
|
@ -84,6 +86,8 @@ namespace VRM
|
|||
avatarDescription.hasTranslationDoF = vrmHuman.Description.hasTranslationDoF;
|
||||
}
|
||||
});
|
||||
var newAnimator = normalized.GetOrAddComponent<Animator>();
|
||||
newAnimator.avatar = newAvatar;
|
||||
|
||||
CopyVRMComponents(go, normalized, bMap);
|
||||
|
||||
|
|
|
|||
|
|
@ -133,7 +133,9 @@ namespace UniVRM10
|
|||
// TODO: update: constraint
|
||||
// TODO: update: firstPoint offset
|
||||
|
||||
AvatarDescription.AddAnimator(go, normalized, boneMap);
|
||||
var newAvatar = AvatarDescription.CreateAvatarForCopyHierarchy(go.GetComponent<Animator>(), normalized, boneMap);
|
||||
var newAnimator = normalized.GetOrAddComponent<Animator>();
|
||||
newAnimator.avatar = newAvatar;
|
||||
|
||||
// TODO: write back normalized transform to boneMap
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user