mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-11 23:19:00 +08:00
feat: support using cloth's Humanoid Rig on merge_armature.adjust_names
This commit is contained in:
parent
97d8261557
commit
b470421f02
@ -116,7 +116,50 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
var avatarRoot = RuntimeUtil.FindAvatarTransformInParents(target.mergeTarget.Get(target).transform);
|
||||
var avatarAnimator = avatarRoot != null ? avatarRoot.GetComponent<Animator>() : null;
|
||||
HeuristicBoneMapper.RenameBonesByHeuristic(target, avatarAnimator: avatarAnimator);
|
||||
|
||||
// Search Outfit Root Animator
|
||||
var outfitRoot = ((ModularAvatarMergeArmature)serializedObject.targetObject).transform;
|
||||
Animator outfitAnimator = null;
|
||||
while (outfitRoot != null)
|
||||
{
|
||||
if (outfitRoot == avatarRoot)
|
||||
{
|
||||
outfitAnimator = null;
|
||||
break;
|
||||
}
|
||||
outfitAnimator = outfitRoot.GetComponent<Animator>();
|
||||
if (outfitAnimator != null && outfitAnimator.isHuman) break;
|
||||
outfitAnimator = null;
|
||||
outfitRoot = outfitRoot.parent;
|
||||
}
|
||||
|
||||
if (outfitAnimator != null)
|
||||
{
|
||||
var hipsCheck = outfitAnimator.GetBoneTransform(HumanBodyBones.Hips);
|
||||
if (hipsCheck != null && hipsCheck.parent == outfitRoot.transform)
|
||||
{
|
||||
// Sometimes broken rigs can have the hips as a direct child of the root, instead of having
|
||||
// an intermediate Armature object. We do not currently support this kind of rig, and so we'll
|
||||
// assume the outfit's humanoid rig is broken and move on to heuristic matching.
|
||||
outfitAnimator = null;
|
||||
} else if (hipsCheck == null) {
|
||||
outfitAnimator = null;
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<Transform, HumanBodyBones> humanoidBones = null;
|
||||
if (outfitAnimator != null)
|
||||
{
|
||||
humanoidBones = new Dictionary<Transform, HumanBodyBones>();
|
||||
foreach (HumanBodyBones boneIndex in Enum.GetValues(typeof(HumanBodyBones)))
|
||||
{
|
||||
var bone = boneIndex != HumanBodyBones.LastBone ? outfitAnimator.GetBoneTransform(boneIndex) : null;
|
||||
if (bone == null) continue;
|
||||
humanoidBones[bone] = boneIndex;
|
||||
}
|
||||
}
|
||||
|
||||
HeuristicBoneMapper.RenameBonesByHeuristic(target, humanoidBones: humanoidBones, avatarAnimator: avatarAnimator);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user