fix: non-unit scale armatures result in incorrect constraint behavior (#421)

This commit is contained in:
bd_ 2023-09-08 18:44:09 +09:00 committed by GitHub
parent b155202714
commit 75fe74da53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -403,6 +403,34 @@ namespace nadena.dev.modular_avatar.core.editor
}
}
if (mergedSrcBone == newParent
&& (
Vector3.SqrMagnitude(mergedSrcBone.transform.localScale - src.transform.localScale) > 0.00001f
|| Quaternion.Angle(mergedSrcBone.transform.localRotation, src.transform.localRotation) > 0.00001f
|| Vector3.SqrMagnitude(mergedSrcBone.transform.localPosition - src.transform.localPosition) > 0.00001f
)
&& src.GetComponent<IConstraint>() != null
)
{
// Constraints are sensitive to changes in local reference frames in some cases. In this case we'll
// inject a dummy object in between in order to retain the local parent scale of the retargeted bone.
var objName = src.gameObject.name + "$ConstraintRef " + Guid.NewGuid();
var constraintScaleRef = new GameObject(objName);
constraintScaleRef.transform.SetParent(src.transform.parent);
constraintScaleRef.transform.localPosition = Vector3.zero;
constraintScaleRef.transform.localRotation = Quaternion.identity;
constraintScaleRef.transform.localScale = Vector3.one;
constraintScaleRef.transform.SetParent(newParent.transform, true);
mergedSrcBone = constraintScaleRef;
BoneDatabase.AddMergedBone(mergedSrcBone.transform);
BoneDatabase.RetainMergedBone(mergedSrcBone.transform);
PathMappings.MarkTransformLookthrough(mergedSrcBone);
thisPassAdded.Add(mergedSrcBone.transform);
}
src.transform.SetParent(mergedSrcBone.transform, true);
if (config.mangleNames)
{