Create the ControlRig at a child of the VRM instance root.

This commit is contained in:
Masataka SUMI
2022-09-07 16:36:29 +09:00
parent 6b41e34071
commit f06d4bdd35
2 changed files with 27 additions and 14 deletions

View File

@@ -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<IVrm10Constraint>();
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();
}
/// <summary>
/// この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();
}
}
}

View File

@@ -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.
/// </summary>
public sealed class Vrm10RuntimeControlRig
public sealed class Vrm10RuntimeControlRig : IDisposable
{
private readonly Vrm10ControlBone _rootBone;
private readonly Transform _controlRigRoot;
private readonly Vrm10ControlBone _hipBone;
private readonly Dictionary<HumanBodyBones, Vrm10ControlBone> _bones;
public float InitialHipsHeight { get; }
@@ -21,16 +23,26 @@ namespace UniVRM10
/// コンストラクタ。
/// humanoid は VRM T-Pose でなければならない。
/// </summary>
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)