fix: improve handling of scale correction when root bone is null (#425)

This commit is contained in:
bd_ 2023-09-08 20:32:03 +09:00 committed by GitHub
parent f9c19c6d67
commit eecac2350e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -237,7 +237,7 @@ namespace nadena.dev.modular_avatar.core.editor
{
// Sometimes meshes have no root bone set. This is usually not ideal, but let's make sure we don't
// choke on the scale computation below.
scaleBone = renderer.bones[0];
scaleBone = renderer.transform;
}
renderer.bones = newBones;
@ -248,10 +248,13 @@ namespace nadena.dev.modular_avatar.core.editor
}
var newRootBone = BoneDatabase.GetRetargetedBone(rootBone, true);
var newScaleBone = BoneDatabase.GetRetargetedBone(scaleBone, true);
if (newRootBone == null)
{
newRootBone = renderer.transform;
}
var oldLossyScale = scaleBone.transform.lossyScale;
var newLossyScale = newScaleBone.transform.lossyScale;
var newLossyScale = newRootBone.transform.lossyScale;
var bounds = renderer.localBounds;
bounds.extents = new Vector3(
@ -259,10 +262,8 @@ namespace nadena.dev.modular_avatar.core.editor
bounds.extents.y * oldLossyScale.y / newLossyScale.y,
bounds.extents.z * oldLossyScale.z / newLossyScale.z
);
bounds.center = new Vector3(
bounds.center.x * oldLossyScale.x / newLossyScale.x,
bounds.center.y * oldLossyScale.y / newLossyScale.y,
bounds.center.z * oldLossyScale.z / newLossyScale.z
bounds.center = newRootBone.transform.InverseTransformPoint(
scaleBone.transform.TransformPoint(bounds.center)
);
renderer.localBounds = bounds;