From 541d2f3e65b20712b6021eb93249240c99a72d72 Mon Sep 17 00:00:00 2001 From: Koarare Date: Wed, 30 Nov 2022 22:45:58 +0900 Subject: [PATCH] Fix issue where bounding box size changes if the base avatar and outfit scale is different (#117) --- .../Editor/MeshRetargeter.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/MeshRetargeter.cs b/Packages/nadena.dev.modular-avatar/Editor/MeshRetargeter.cs index 0461a1c0..ae4de30d 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/MeshRetargeter.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/MeshRetargeter.cs @@ -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); } }