Merge pull request #1774 from Santarh/contolRig

Rename class names about FKRetarget into ControlRig
This commit is contained in:
ousttrue
2022-09-06 19:51:33 +09:00
committed by GitHub
8 changed files with 71 additions and 64 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2e8a3d812e744fb68c6469d96d57380d
timeCreated: 1662455048

View File

@@ -9,7 +9,7 @@ namespace UniVRM10
/// 同時に、元のヒエラルキーの初期回転を保持する。
/// Apply 関数で、再帰的に正規化済みのローカル回転から初期回転を加味したローカル回転を作って適用する。
/// </summary>
public class Vrm10BoneWithAxis
public class Vrm10ControlBone
{
public readonly HumanBodyBones Bone;
@@ -31,9 +31,9 @@ namespace UniVRM10
public readonly Quaternion ToLocal;
public List<Vrm10BoneWithAxis> Children = new List<Vrm10BoneWithAxis>();
public List<Vrm10ControlBone> Children = new List<Vrm10ControlBone>();
public Vrm10BoneWithAxis(Transform current, Quaternion parentInverse, HumanBodyBones bone)
public Vrm10ControlBone(Transform current, Quaternion parentInverse, HumanBodyBones bone)
{
if (bone == HumanBodyBones.LastBone)
{
@@ -53,9 +53,9 @@ namespace UniVRM10
ToLocal = current.rotation;
}
public static Vrm10BoneWithAxis Build(UniHumanoid.Humanoid humanoid, Dictionary<HumanBodyBones, Vrm10BoneWithAxis> boneMap)
public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, Dictionary<HumanBodyBones, Vrm10ControlBone> boneMap)
{
var hips = new Vrm10BoneWithAxis(humanoid.Hips, Quaternion.identity, HumanBodyBones.Hips);
var hips = new Vrm10ControlBone(humanoid.Hips, Quaternion.identity, HumanBodyBones.Hips);
boneMap.Add(HumanBodyBones.Hips, hips);
foreach (Transform child in humanoid.Hips)
@@ -66,7 +66,7 @@ namespace UniVRM10
return hips;
}
private static void Traverse(UniHumanoid.Humanoid humanoid, Transform current, Vrm10BoneWithAxis parent, Dictionary<HumanBodyBones, Vrm10BoneWithAxis> boneMap)
private static void Traverse(UniHumanoid.Humanoid humanoid, Transform current, Vrm10ControlBone parent, Dictionary<HumanBodyBones, Vrm10ControlBone> boneMap)
{
if (humanoid.TryGetBoneForTransform(current, out var bone))
{
@@ -76,7 +76,7 @@ namespace UniVRM10
// ワールド回転 parent^-1 * current からローカル回転を算出する。
var parentInverse = Quaternion.Inverse(parent.Target.rotation);
var newBone = new Vrm10BoneWithAxis(current, parentInverse, bone);
var newBone = new Vrm10ControlBone(current, parentInverse, bone);
newBone.Normalized.SetParent(parent.Normalized, true);
parent.Children.Add(newBone);
parent = newBone;

View File

@@ -1,39 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
namespace UniVRM10
{
public class Vrm10FkRetarget
{
Vrm10BoneWithAxis m_root;
Dictionary<HumanBodyBones, Vrm10BoneWithAxis> m_boneMap = new Dictionary<HumanBodyBones, Vrm10BoneWithAxis>();
public readonly float InitialHipsHeight;
public Vrm10FkRetarget(UniHumanoid.Humanoid humanoid)
{
m_root = Vrm10BoneWithAxis.Build(humanoid, m_boneMap);
InitialHipsHeight = m_root.Target.position.y;
Debug.Log($"InitialHipsHeight: {InitialHipsHeight}");
}
public void Apply()
{
m_root.Target.position = m_root.Normalized.position;
m_root.ApplyRecursive(Quaternion.identity);
}
public Transform GetBoneTransform(HumanBodyBones bone)
{
if (m_boneMap.TryGetValue(bone, out var value))
{
return value.Normalized;
}
else
{
return null;
}
}
}
}

View File

@@ -14,28 +14,17 @@ namespace UniVRM10
public class Vrm10Runtime : IDisposable
{
private readonly Vrm10Instance m_target;
Vrm10FkRetarget m_fkRetarget;
public Vrm10FkRetarget GetOrCreateFkRetarget()
{
if (m_fkRetarget == null)
{
m_fkRetarget = new Vrm10FkRetarget(m_target.Humanoid);
}
return m_fkRetarget;
}
private readonly IVrm10Constraint[] m_constraints;
private readonly Transform m_head;
private readonly FastSpringBoneService m_fastSpringBoneService;
private readonly IReadOnlyDictionary<Transform, TransformState> m_defaultTransformStates;
private Vrm10RuntimeControlRig m_controlRig;
private FastSpringBoneBuffer m_fastSpringBoneBuffer;
private Vrm10RuntimeExpression m_expression;
public Vrm10RuntimeExpression Expression => m_expression;
private Vrm10RuntimeLookAt m_lookat;
public Vrm10RuntimeExpression Expression => m_expression;
public Vrm10RuntimeLookAt LookAt => m_lookat;
public Vrm10Runtime(Vrm10Instance target)
@@ -92,6 +81,15 @@ namespace UniVRM10
m_fastSpringBoneService.BufferCombiner.Register(m_fastSpringBoneBuffer);
}
public Vrm10RuntimeControlRig GetOrCreateControlRig()
{
if (m_controlRig == null)
{
m_controlRig = new Vrm10RuntimeControlRig(m_target.Humanoid);
}
return m_controlRig;
}
private FastSpringBoneBuffer CreateFastSpringBoneBuffer(Vrm10InstanceSpringBone springBone)
{
return new FastSpringBoneBuffer(
@@ -163,9 +161,9 @@ namespace UniVRM10
/// </summary>
public void Process()
{
if (m_fkRetarget != null)
if (m_controlRig != null)
{
m_fkRetarget.Apply();
m_controlRig.Process();
}
//

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using UnityEngine;
namespace UniVRM10
{
/// <summary>
/// VRM 1.0 モデルインスタンスに対して、コントロールリグを生成します。
/// これは VRM 0.x のような、正規化されたボーン操作を提供します。
///
/// Create a control rig for the VRM 1.0 model instance.
/// This provides the normalized operation of bones, like VRM 0.x.
/// </summary>
public class Vrm10RuntimeControlRig
{
private readonly Vrm10ControlBone _rootBone;
private readonly Dictionary<HumanBodyBones, Vrm10ControlBone> _bones = new Dictionary<HumanBodyBones, Vrm10ControlBone>();
public readonly float InitialHipsHeight;
public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid)
{
_rootBone = Vrm10ControlBone.Build(humanoid, _bones);
InitialHipsHeight = _rootBone.Target.position.y;
Debug.Log($"InitialHipsHeight: {InitialHipsHeight}");
}
public void Process()
{
_rootBone.Target.position = _rootBone.Normalized.position;
_rootBone.ApplyRecursive(Quaternion.identity);
}
public Transform GetBoneTransform(HumanBodyBones bone)
{
if (_bones.TryGetValue(bone, out var value))
{
return value.Normalized;
}
else
{
return null;
}
}
}
}

View File

@@ -301,7 +301,7 @@ namespace UniVRM10.VRM10Viewer
public void UpdatePose(Animator pose)
{
var fkRetarget = m_controller.Runtime.GetOrCreateFkRetarget();
var fkRetarget = m_controller.Runtime.GetOrCreateControlRig();
foreach (HumanBodyBones bone in Enum.GetValues(typeof(HumanBodyBones)))
{
if (bone == HumanBodyBones.LastBone)
@@ -339,7 +339,7 @@ namespace UniVRM10.VRM10Viewer
}
}
}
fkRetarget.Apply();
fkRetarget.Process();
}
}
Loaded m_loaded;