From 59b88c3f6ee039f658b05f02610d6e8025119ae4 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Wed, 21 Sep 2022 17:34:31 +0900 Subject: [PATCH] Fix a bug of incorrect pose set when EnforceTPose called --- .../Vrm10Runtime/ControlRig/Vrm10ControlBone.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 36828b9fb..4364c7fd4 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -45,7 +45,7 @@ namespace UniVRM10 private readonly Quaternion _initialTargetGlobalRotation; private readonly List _children = new List(); - internal Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType) + private Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType, Vrm10ControlBone parent) { if (boneType == HumanBodyBones.LastBone) { @@ -61,6 +61,13 @@ namespace UniVRM10 // NOTE: bone name must be unique in the vrm instance. ControlBone = new GameObject($"{nameof(Vrm10ControlBone)}:{boneType.ToString()}").transform; ControlBone.position = controlTarget.position; + + if (parent != null) + { + ControlBone.SetParent(parent.ControlBone, true); + parent._children.Add(this); + } + InitialControlBoneLocalPosition = ControlBone.localPosition; InitialControlBoneLocalRotation = ControlBone.localRotation; _initialTargetLocalRotation = controlTarget.localRotation; @@ -81,7 +88,7 @@ namespace UniVRM10 public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, out Dictionary boneMap) { - var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips); + var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips, null); boneMap = new Dictionary(); boneMap.Add(HumanBodyBones.Hips, hips); @@ -97,9 +104,7 @@ namespace UniVRM10 { if (humanoid.TryGetBoneForTransform(current, out var bone)) { - var newBone = new Vrm10ControlBone(current, bone); - newBone.ControlBone.SetParent(parent.ControlBone, true); - parent._children.Add(newBone); + var newBone = new Vrm10ControlBone(current, bone, parent); parent = newBone; boneMap.Add(bone, newBone); }