Fix issue where bounding box size changes if the base avatar and outfit scale is different (#117)

This commit is contained in:
Koarare 2022-11-30 22:45:58 +09:00 committed by GitHub
parent 74861c5fff
commit 541d2f3e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -200,7 +200,26 @@ namespace nadena.dev.modular_avatar.core.editor
dst.bindposes = newBindPoses;
renderer.bones = newBones;
renderer.sharedMesh = dst;
renderer.rootBone = BoneDatabase.GetRetargetedBone(renderer.rootBone, true);
var newRootBone = BoneDatabase.GetRetargetedBone(renderer.rootBone, true);
var oldLossyScale = renderer.rootBone.transform.lossyScale;
var newLossyScale = newRootBone.transform.lossyScale;
var bounds = renderer.localBounds;
bounds.extents = new Vector3(
bounds.extents.x * oldLossyScale.x / newLossyScale.x,
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
);
renderer.localBounds = bounds;
renderer.rootBone = newRootBone;
renderer.probeAnchor = BoneDatabase.GetRetargetedBone(renderer.probeAnchor, true);
}
}