mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-12 23:48:59 +08:00
fix: improve handling of scale correction when root bone is null (#425)
This commit is contained in:
parent
f9c19c6d67
commit
eecac2350e
@ -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
|
// 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.
|
// choke on the scale computation below.
|
||||||
scaleBone = renderer.bones[0];
|
scaleBone = renderer.transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.bones = newBones;
|
renderer.bones = newBones;
|
||||||
@ -248,10 +248,13 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newRootBone = BoneDatabase.GetRetargetedBone(rootBone, true);
|
var newRootBone = BoneDatabase.GetRetargetedBone(rootBone, true);
|
||||||
var newScaleBone = BoneDatabase.GetRetargetedBone(scaleBone, true);
|
if (newRootBone == null)
|
||||||
|
{
|
||||||
|
newRootBone = renderer.transform;
|
||||||
|
}
|
||||||
|
|
||||||
var oldLossyScale = scaleBone.transform.lossyScale;
|
var oldLossyScale = scaleBone.transform.lossyScale;
|
||||||
var newLossyScale = newScaleBone.transform.lossyScale;
|
var newLossyScale = newRootBone.transform.lossyScale;
|
||||||
|
|
||||||
var bounds = renderer.localBounds;
|
var bounds = renderer.localBounds;
|
||||||
bounds.extents = new Vector3(
|
bounds.extents = new Vector3(
|
||||||
@ -259,10 +262,8 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
bounds.extents.y * oldLossyScale.y / newLossyScale.y,
|
bounds.extents.y * oldLossyScale.y / newLossyScale.y,
|
||||||
bounds.extents.z * oldLossyScale.z / newLossyScale.z
|
bounds.extents.z * oldLossyScale.z / newLossyScale.z
|
||||||
);
|
);
|
||||||
bounds.center = new Vector3(
|
bounds.center = newRootBone.transform.InverseTransformPoint(
|
||||||
bounds.center.x * oldLossyScale.x / newLossyScale.x,
|
scaleBone.transform.TransformPoint(bounds.center)
|
||||||
bounds.center.y * oldLossyScale.y / newLossyScale.y,
|
|
||||||
bounds.center.z * oldLossyScale.z / newLossyScale.z
|
|
||||||
);
|
);
|
||||||
renderer.localBounds = bounds;
|
renderer.localBounds = bounds;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user