fix: MA MergeArmature forget to retaining the root bone. (#1355)

* fix: forget to retaining the root bone

* chore: fix test

---------

Co-authored-by: bd_ <bd_@nadena.dev>
This commit is contained in:
Reina_Sakiria 2024-11-25 09:41:20 +09:00 committed by GitHub
parent 5c084a8b8a
commit fd59c3e910
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2022 bd_ * Copyright (c) 2022 bd_
@ -117,6 +117,24 @@ namespace nadena.dev.modular_avatar.core.editor
RetainBoneReferences(c as Component); RetainBoneReferences(c as Component);
} }
foreach (var smr in avatarGameObject.transform.GetComponentsInChildren<SkinnedMeshRenderer>(true))
{
// If the root bone has been offset, or has a different sign for its scale, we need to retain it.
// see https://github.com/bdunderscore/modular-avatar/pull/1355
// (we avoid retaining otherwise to avoid excess bone transforms)
if (smr.rootBone == null || smr.rootBone.parent == null) continue;
var root = smr.rootBone;
var parent = root.parent;
if ((parent.position - root.position).sqrMagnitude > 0.000001f
|| Vector3.Dot(parent.localScale.normalized, root.localScale.normalized) < 0.9999f)
{
BoneDatabase.RetainMergedBone(smr.rootBone);
}
}
new RetargetMeshes().OnPreprocessAvatar(avatarGameObject, BoneDatabase, PathMappings); new RetargetMeshes().OnPreprocessAvatar(avatarGameObject, BoneDatabase, PathMappings);
} }