diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 1138f08ee..5d96bb2e1 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -42,7 +42,7 @@ namespace UniVRM10 throw new Exception(); } - ControlRig = new Vrm10RuntimeControlRig(target.Humanoid); + ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform); Constraints = target.GetComponentsInChildren(); LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head, target.LookAtTargetType, target.Gaze); Expression = new Vrm10RuntimeExpression(target, LookAt, LookAt.EyeDirectionApplicable); @@ -69,6 +69,13 @@ namespace UniVRM10 } } + public void Dispose() + { + ControlRig.Dispose(); + m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer); + m_fastSpringBoneBuffer.Dispose(); + } + /// /// このVRMに紐づくSpringBone関連のバッファを再構築する /// ランタイム実行時にSpringBoneに対して変更を行いたいときは、このメソッドを明示的に呼ぶ必要がある @@ -169,11 +176,5 @@ namespace UniVRM10 // 4. Expression Expression.Process(); } - - public void Dispose() - { - m_fastSpringBoneService.BufferCombiner.Unregister(m_fastSpringBoneBuffer); - m_fastSpringBoneBuffer.Dispose(); - } } } \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs index 9adbeb807..d038a9cda 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -10,9 +11,10 @@ namespace UniVRM10 /// Create a control rig for the VRM 1.0 model instance. /// This provides the normalized operation of bones, like VRM 0.x. /// - public sealed class Vrm10RuntimeControlRig + public sealed class Vrm10RuntimeControlRig : IDisposable { - private readonly Vrm10ControlBone _rootBone; + private readonly Transform _controlRigRoot; + private readonly Vrm10ControlBone _hipBone; private readonly Dictionary _bones; public float InitialHipsHeight { get; } @@ -21,16 +23,26 @@ namespace UniVRM10 /// コンストラクタ。 /// humanoid は VRM T-Pose でなければならない。 /// - public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid) + public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid, Transform vrmRoot) { - _rootBone = Vrm10ControlBone.Build(humanoid, out _bones); - InitialHipsHeight = _rootBone.ControlTarget.position.y; + _controlRigRoot = new GameObject("Runtime Control Rig").transform; + _controlRigRoot.SetParent(vrmRoot); + + _hipBone = Vrm10ControlBone.Build(humanoid, out _bones); + _hipBone.ControlBone.SetParent(_controlRigRoot); + + InitialHipsHeight = _hipBone.ControlTarget.position.y; + } + + public void Dispose() + { + UnityEngine.Object.Destroy(_controlRigRoot); } internal void Process() { - _rootBone.ControlTarget.position = _rootBone.ControlBone.position; - _rootBone.ProcessRecursively(); + _hipBone.ControlTarget.position = _hipBone.ControlBone.position; + _hipBone.ProcessRecursively(); } public Transform GetBoneTransform(HumanBodyBones bone)