From 4a4dbb447a5c5f761733a623b49c51faf6c60456 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 25 Nov 2022 20:26:30 +0900 Subject: [PATCH 1/9] initialRotations --- .../Components/Vrm10Instance/Vrm10Instance.cs | 9 ++- .../ControlRig/Vrm10ControlBone.cs | 21 ++++-- .../Vrm10Runtime/OpenXRHandTracking.cs | 65 +++++++++++++++++++ .../Vrm10Runtime/OpenXRHandTracking.cs.meta | 11 ++++ .../Components/Vrm10Runtime/Vrm10Runtime.cs | 4 +- .../Vrm10Runtime/Vrm10RuntimeControlRig.cs | 4 +- Assets/VRM10/Runtime/IO/Vrm10.cs | 15 ++++- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 7 +- .../VRM10_Samples/VRM10Viewer/VRM10Loaded.cs | 35 ++++++++++ 9 files changed, 154 insertions(+), 17 deletions(-) create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index 6c8afcc26..b2822cc0e 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System.Collections.Generic; +using UnityEngine; namespace UniVRM10 @@ -53,6 +54,7 @@ namespace UniVRM10 private UniHumanoid.Humanoid m_humanoid; private Vrm10Runtime m_runtime; private ControlRigGenerationOption m_controlRigGenerationOption = ControlRigGenerationOption.None; + private Dictionary m_initialRotations; /// /// VRM ファイルに記録された Humanoid ボーンに対応します。 @@ -79,15 +81,16 @@ namespace UniVRM10 { if (m_runtime == null) { - m_runtime = new Vrm10Runtime(this, m_controlRigGenerationOption); + m_runtime = new Vrm10Runtime(this, m_controlRigGenerationOption, m_initialRotations); } return m_runtime; } } - internal void InitializeAtRuntime(ControlRigGenerationOption controlRigGenerationOption) + internal void InitializeAtRuntime(ControlRigGenerationOption controlRigGenerationOption, Dictionary initialRotations = null) { m_controlRigGenerationOption = controlRigGenerationOption; + m_initialRotations = initialRotations; } void Start() diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 4364c7fd4..256b1b738 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(); - private Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType, Vrm10ControlBone parent) + private Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType, Vrm10ControlBone parent, Dictionary initialRotations) { if (boneType == HumanBodyBones.LastBone) { @@ -60,6 +60,13 @@ namespace UniVRM10 ControlTarget = controlTarget; // NOTE: bone name must be unique in the vrm instance. ControlBone = new GameObject($"{nameof(Vrm10ControlBone)}:{boneType.ToString()}").transform; + if (initialRotations != null) + { + if (initialRotations.TryGetValue(boneType, out var rotation)) + { + ControlBone.rotation = rotation; + } + } ControlBone.position = controlTarget.position; if (parent != null) @@ -86,32 +93,32 @@ namespace UniVRM10 } } - public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, out Dictionary boneMap) + public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, Dictionary initialRotations, out Dictionary boneMap) { - var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips, null); + var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips, null, initialRotations); boneMap = new Dictionary(); boneMap.Add(HumanBodyBones.Hips, hips); foreach (Transform child in humanoid.Hips) { - BuildRecursively(humanoid, child, hips, boneMap); + BuildRecursively(humanoid, child, hips, initialRotations, boneMap); } return hips; } - private static void BuildRecursively(UniHumanoid.Humanoid humanoid, Transform current, Vrm10ControlBone parent, Dictionary boneMap) + private static void BuildRecursively(UniHumanoid.Humanoid humanoid, Transform current, Vrm10ControlBone parent, Dictionary initialRotations, Dictionary boneMap) { if (humanoid.TryGetBoneForTransform(current, out var bone)) { - var newBone = new Vrm10ControlBone(current, bone, parent); + var newBone = new Vrm10ControlBone(current, bone, parent, initialRotations); parent = newBone; boneMap.Add(bone, newBone); } foreach (Transform child in current) { - BuildRecursively(humanoid, child, parent, boneMap); + BuildRecursively(humanoid, child, parent, initialRotations, boneMap); } } } diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs new file mode 100644 index 000000000..39c296209 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UniVRM10 +{ + /// + /// TPose のときに XR_EXT_hand_tracking の joint が向いている向きを定義する。 + /// + /// https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#_conventions_of_hand_joints + /// + /// Unityは左手系なので、X軸を反転させます。 + /// + public static class OpenXRHandTracking + { + public static Quaternion GetRotation(Vector3 up, Vector3 forward) + { + var xAxis = Vector3.Cross(up, forward).normalized; + var m = new Matrix4x4(xAxis, up, forward, new Vector4(0, 0, 0, 1)); + return m.rotation; + } + + public static Quaternion LeftHand = GetRotation(Vector3.up, Vector3.right); + public static Quaternion LeftThumb = GetRotation(Vector3.up, (Vector3.right + Vector3.forward).normalized); + public static Quaternion RightHand = GetRotation(Vector3.up, Vector3.left); + public static Quaternion RightThumb = GetRotation(Vector3.up, (Vector3.left + Vector3.forward).normalized); + + public static readonly Dictionary InitialRotations = new Dictionary() + { + // Left + // {HumanBodyBones.LeftHand, LeftHand}, + // {HumanBodyBones.LeftThumbProximal, LeftThumb}, + // {HumanBodyBones.LeftThumbIntermediate, LeftThumb}, + // {HumanBodyBones.LeftThumbDistal, LeftThumb}, + {HumanBodyBones.LeftIndexProximal, LeftHand}, + {HumanBodyBones.LeftIndexIntermediate, LeftHand}, + {HumanBodyBones.LeftIndexDistal, LeftHand}, + // {HumanBodyBones.LeftMiddleProximal, LeftHand}, + // {HumanBodyBones.LeftMiddleIntermediate, LeftHand}, + // {HumanBodyBones.LeftMiddleDistal, LeftHand}, + // {HumanBodyBones.LeftRingProximal, LeftHand}, + // {HumanBodyBones.LeftRingIntermediate, LeftHand}, + // {HumanBodyBones.LeftRingDistal, LeftHand}, + // {HumanBodyBones.LeftLittleProximal, LeftHand}, + // {HumanBodyBones.LeftLittleIntermediate, LeftHand}, + // {HumanBodyBones.LeftLittleDistal, LeftHand}, + // Right + // {HumanBodyBones.RightHand, RightHand}, + // {HumanBodyBones.RightThumbProximal, RightThumb}, + // {HumanBodyBones.RightThumbIntermediate, RightThumb}, + // {HumanBodyBones.RightThumbDistal, RightThumb}, + // {HumanBodyBones.RightIndexProximal, RightHand}, + // {HumanBodyBones.RightIndexIntermediate, RightHand}, + // {HumanBodyBones.RightIndexDistal, RightHand}, + // {HumanBodyBones.RightMiddleProximal, RightHand}, + // {HumanBodyBones.RightMiddleIntermediate, RightHand}, + // {HumanBodyBones.RightMiddleDistal, RightHand}, + // {HumanBodyBones.RightRingProximal, RightHand}, + // {HumanBodyBones.RightRingIntermediate, RightHand}, + // {HumanBodyBones.RightRingDistal, RightHand}, + // {HumanBodyBones.RightLittleProximal, RightHand}, + // {HumanBodyBones.RightLittleIntermediate, RightHand}, + // {HumanBodyBones.RightLittleDistal, RightHand}, + }; + } +} \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta new file mode 100644 index 000000000..bb500746b --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 45a6dbb978533164dafbcbf6f28e5117 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 49a0f602b..a31b74134 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -49,7 +49,7 @@ namespace UniVRM10 } } - public Vrm10Runtime(Vrm10Instance target, ControlRigGenerationOption controlRigGenerationOption) + public Vrm10Runtime(Vrm10Instance target, ControlRigGenerationOption controlRigGenerationOption, Dictionary initialRotations = null) { m_target = target; @@ -60,7 +60,7 @@ namespace UniVRM10 if (controlRigGenerationOption != ControlRigGenerationOption.None) { - ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform, controlRigGenerationOption); + ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform, controlRigGenerationOption, initialRotations); } Constraints = target.GetComponentsInChildren(); LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head, target.LookAtTargetType, target.Gaze); diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs index cb4f6f05d..0edb375eb 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs @@ -28,14 +28,14 @@ namespace UniVRM10 /// コンストラクタ。 /// humanoid は VRM T-Pose でなければならない。 /// - public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid, Transform vrmRoot, ControlRigGenerationOption option) + public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid, Transform vrmRoot, ControlRigGenerationOption option, Dictionary initialRotations) { if (option == ControlRigGenerationOption.None) return; _controlRigRoot = new GameObject("Runtime Control Rig").transform; _controlRigRoot.SetParent(vrmRoot); - _hipBone = Vrm10ControlBone.Build(humanoid, out _bones); + _hipBone = Vrm10ControlBone.Build(humanoid, initialRotations, out _bones); _hipBone.ControlBone.SetParent(_controlRigRoot); InitialHipsHeight = _hipBone.ControlTarget.position.y; diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index 721f64b8b..2d2bed77b 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using UniGLTF; @@ -38,6 +39,7 @@ namespace UniVRM10 string path, bool canLoadVrm0X = true, ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.Generate, + Dictionary initialRotations = null, bool showMeshes = true, IAwaitCaller awaitCaller = null, IMaterialDescriptorGenerator materialGenerator = null, @@ -56,6 +58,7 @@ namespace UniVRM10 System.IO.File.ReadAllBytes(path), canLoadVrm0X, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -82,6 +85,7 @@ namespace UniVRM10 byte[] bytes, bool canLoadVrm0X = true, ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.Generate, + Dictionary initialRotations = null, bool showMeshes = true, IAwaitCaller awaitCaller = null, IMaterialDescriptorGenerator materialGenerator = null, @@ -100,6 +104,7 @@ namespace UniVRM10 bytes, canLoadVrm0X, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -112,6 +117,7 @@ namespace UniVRM10 byte[] bytes, bool canLoadVrm0X, ControlRigGenerationOption controlRigGenerationOption, + Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -130,6 +136,7 @@ namespace UniVRM10 var instance = await TryLoadingAsVrm10Async( gltfData, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -155,6 +162,7 @@ namespace UniVRM10 var migratedInstance = await TryMigratingFromVrm0XAsync( gltfData, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -178,6 +186,7 @@ namespace UniVRM10 private static async Task TryLoadingAsVrm10Async( GltfData gltfData, ControlRigGenerationOption controlRigGenerationOption, + Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -203,6 +212,7 @@ namespace UniVRM10 vrm10Data, null, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -213,6 +223,7 @@ namespace UniVRM10 private static async Task TryMigratingFromVrm0XAsync( GltfData gltfData, ControlRigGenerationOption controlRigGenerationOption, + Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -240,6 +251,7 @@ namespace UniVRM10 migratedVrm10Data, migrationData, controlRigGenerationOption, + initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -257,6 +269,7 @@ namespace UniVRM10 Vrm10Data vrm10Data, MigrationData migrationData, ControlRigGenerationOption controlRigGenerationOption, + Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -274,7 +287,7 @@ namespace UniVRM10 throw new ArgumentNullException(nameof(vrm10Data)); } - using (var loader = new Vrm10Importer(vrm10Data, controlRigGenerationOption: controlRigGenerationOption, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(vrm10Data, controlRigGenerationOption: controlRigGenerationOption, initialRotations: initialRotations, materialGenerator: materialGenerator)) { // 1. Load meta information if callback was available. if (vrmMetaInformationCallback != null) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index fc5da977d..0e23ba5e8 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -19,6 +19,7 @@ namespace UniVRM10 /// VrmLib.Model の オブジェクトと UnityEngine.Object のマッピングを記録する private readonly ModelMap m_map = new ModelMap(); private readonly ControlRigGenerationOption m_controlRigGenerationOption; + private readonly Dictionary m_initialRotations; private VrmLib.Model m_model; private IReadOnlyDictionary m_externalMap; @@ -31,7 +32,8 @@ namespace UniVRM10 IReadOnlyDictionary externalObjectMap = null, ITextureDeserializer textureDeserializer = null, IMaterialDescriptorGenerator materialGenerator = null, - ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.None) + ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.None, + Dictionary initialRotations = null) : base(vrm.Data, externalObjectMap, textureDeserializer) { if (vrm == null) @@ -40,6 +42,7 @@ namespace UniVRM10 } m_vrm = vrm; m_controlRigGenerationOption = controlRigGenerationOption; + m_initialRotations = initialRotations; TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(Data); MaterialDescriptorGenerator = materialGenerator ?? new BuiltInVrm10MaterialDescriptorGenerator(); @@ -246,7 +249,7 @@ namespace UniVRM10 // VrmController var controller = Root.AddComponent(); - controller.InitializeAtRuntime(m_controlRigGenerationOption); + controller.InitializeAtRuntime(m_controlRigGenerationOption, m_initialRotations); controller.enabled = false; // vrm diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs index 05824727f..67e740685 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs @@ -159,6 +159,41 @@ namespace UniVRM10.VRM10Viewer } } + /// + /// from v0.104 + /// + /// + public void UpdateControlRigImplicit(UniHumanoid.Humanoid src) + { + var dst = m_controller.GetComponent(); + + foreach (HumanBodyBones bone in CachedEnum.GetValues()) + { + if (bone == HumanBodyBones.LastBone) + { + continue; + } + + var boneTransform = dst.GetBoneTransform(bone); + if (boneTransform == null) + { + continue; + } + + var bvhBone = src.GetBoneTransform(bone); + if (bvhBone != null) + { + // set normalized pose + boneTransform.localRotation = bvhBone.localRotation; + if (bone == HumanBodyBones.Hips) + { + // TODO: hips position scaling ? + boneTransform.localPosition = bvhBone.localPosition; + } + } + } + } + public void TPoseControlRig() { var controlRig = m_controller.Runtime.ControlRig; From a0d4621547a6c5a79c871505fa2de4cf6b6b1e21 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 25 Nov 2022 22:22:12 +0900 Subject: [PATCH 2/9] WIP OpenXRHandTracking --- .../ControlRig/Vrm10ControlBone.cs | 18 +++++- .../Vrm10Runtime/OpenXRHandTracking.cs | 58 +++++++++---------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 256b1b738..9fd07ca27 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -40,6 +40,7 @@ namespace UniVRM10 /// コントロールボーンの初期ローカル回転。 /// public Quaternion InitialControlBoneLocalRotation { get; } + Quaternion InitialControlBoneGlobalRotation; private readonly Quaternion _initialTargetLocalRotation; private readonly Quaternion _initialTargetGlobalRotation; @@ -77,16 +78,31 @@ namespace UniVRM10 InitialControlBoneLocalPosition = ControlBone.localPosition; InitialControlBoneLocalRotation = ControlBone.localRotation; + InitialControlBoneGlobalRotation = ControlBone.rotation; _initialTargetLocalRotation = controlTarget.localRotation; _initialTargetGlobalRotation = controlTarget.rotation; } + /// + /// 初期姿勢からの相対的な回転。 + /// + /// VRM-0.X では localRotation と同じである。 + /// + Quaternion ControlBoneRelativeRotationFromInitial + { + get + { + var axis = (ControlBone.parent != null ? ControlBone.parent.rotation : Quaternion.identity) * InitialControlBoneLocalRotation; + return InitialControlBoneLocalRotation * Quaternion.Inverse(InitialControlBoneGlobalRotation) * (Quaternion.Inverse(axis) * ControlBone.rotation) * InitialControlBoneGlobalRotation; + } + } + /// /// 親から再帰的にNormalized の ローカル回転を初期回転を加味して Target に適用する。 /// internal void ProcessRecursively() { - ControlTarget.localRotation = _initialTargetLocalRotation * Quaternion.Inverse(_initialTargetGlobalRotation) * ControlBone.localRotation * _initialTargetGlobalRotation; + ControlTarget.localRotation = _initialTargetLocalRotation * (Quaternion.Inverse(_initialTargetGlobalRotation) * ControlBoneRelativeRotationFromInitial * _initialTargetGlobalRotation); foreach (var child in _children) { child.ProcessRecursively(); diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs index 39c296209..9e622a739 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs @@ -27,39 +27,39 @@ namespace UniVRM10 public static readonly Dictionary InitialRotations = new Dictionary() { // Left - // {HumanBodyBones.LeftHand, LeftHand}, - // {HumanBodyBones.LeftThumbProximal, LeftThumb}, - // {HumanBodyBones.LeftThumbIntermediate, LeftThumb}, - // {HumanBodyBones.LeftThumbDistal, LeftThumb}, + {HumanBodyBones.LeftHand, LeftHand}, + {HumanBodyBones.LeftThumbProximal, LeftThumb}, + {HumanBodyBones.LeftThumbIntermediate, LeftThumb}, + {HumanBodyBones.LeftThumbDistal, LeftThumb}, {HumanBodyBones.LeftIndexProximal, LeftHand}, {HumanBodyBones.LeftIndexIntermediate, LeftHand}, {HumanBodyBones.LeftIndexDistal, LeftHand}, - // {HumanBodyBones.LeftMiddleProximal, LeftHand}, - // {HumanBodyBones.LeftMiddleIntermediate, LeftHand}, - // {HumanBodyBones.LeftMiddleDistal, LeftHand}, - // {HumanBodyBones.LeftRingProximal, LeftHand}, - // {HumanBodyBones.LeftRingIntermediate, LeftHand}, - // {HumanBodyBones.LeftRingDistal, LeftHand}, - // {HumanBodyBones.LeftLittleProximal, LeftHand}, - // {HumanBodyBones.LeftLittleIntermediate, LeftHand}, - // {HumanBodyBones.LeftLittleDistal, LeftHand}, + {HumanBodyBones.LeftMiddleProximal, LeftHand}, + {HumanBodyBones.LeftMiddleIntermediate, LeftHand}, + {HumanBodyBones.LeftMiddleDistal, LeftHand}, + {HumanBodyBones.LeftRingProximal, LeftHand}, + {HumanBodyBones.LeftRingIntermediate, LeftHand}, + {HumanBodyBones.LeftRingDistal, LeftHand}, + {HumanBodyBones.LeftLittleProximal, LeftHand}, + {HumanBodyBones.LeftLittleIntermediate, LeftHand}, + {HumanBodyBones.LeftLittleDistal, LeftHand}, // Right - // {HumanBodyBones.RightHand, RightHand}, - // {HumanBodyBones.RightThumbProximal, RightThumb}, - // {HumanBodyBones.RightThumbIntermediate, RightThumb}, - // {HumanBodyBones.RightThumbDistal, RightThumb}, - // {HumanBodyBones.RightIndexProximal, RightHand}, - // {HumanBodyBones.RightIndexIntermediate, RightHand}, - // {HumanBodyBones.RightIndexDistal, RightHand}, - // {HumanBodyBones.RightMiddleProximal, RightHand}, - // {HumanBodyBones.RightMiddleIntermediate, RightHand}, - // {HumanBodyBones.RightMiddleDistal, RightHand}, - // {HumanBodyBones.RightRingProximal, RightHand}, - // {HumanBodyBones.RightRingIntermediate, RightHand}, - // {HumanBodyBones.RightRingDistal, RightHand}, - // {HumanBodyBones.RightLittleProximal, RightHand}, - // {HumanBodyBones.RightLittleIntermediate, RightHand}, - // {HumanBodyBones.RightLittleDistal, RightHand}, + {HumanBodyBones.RightHand, RightHand}, + {HumanBodyBones.RightThumbProximal, RightThumb}, + {HumanBodyBones.RightThumbIntermediate, RightThumb}, + {HumanBodyBones.RightThumbDistal, RightThumb}, + {HumanBodyBones.RightIndexProximal, RightHand}, + {HumanBodyBones.RightIndexIntermediate, RightHand}, + {HumanBodyBones.RightIndexDistal, RightHand}, + {HumanBodyBones.RightMiddleProximal, RightHand}, + {HumanBodyBones.RightMiddleIntermediate, RightHand}, + {HumanBodyBones.RightMiddleDistal, RightHand}, + {HumanBodyBones.RightRingProximal, RightHand}, + {HumanBodyBones.RightRingIntermediate, RightHand}, + {HumanBodyBones.RightRingDistal, RightHand}, + {HumanBodyBones.RightLittleProximal, RightHand}, + {HumanBodyBones.RightLittleIntermediate, RightHand}, + {HumanBodyBones.RightLittleDistal, RightHand}, }; } } \ No newline at end of file From 18c4b2c904b1d6983b7890b285b5fb214b229617 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sun, 27 Nov 2022 23:07:08 +0900 Subject: [PATCH 3/9] NormalizedLocalRotation --- .../Vrm10Runtime/ControlRig/Vrm10ControlBone.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 9fd07ca27..b3ec8fafd 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -88,12 +88,12 @@ namespace UniVRM10 /// /// VRM-0.X では localRotation と同じである。 /// - Quaternion ControlBoneRelativeRotationFromInitial + Quaternion NormalizedLocalRotation { get { - var axis = (ControlBone.parent != null ? ControlBone.parent.rotation : Quaternion.identity) * InitialControlBoneLocalRotation; - return InitialControlBoneLocalRotation * Quaternion.Inverse(InitialControlBoneGlobalRotation) * (Quaternion.Inverse(axis) * ControlBone.rotation) * InitialControlBoneGlobalRotation; + var delta = Quaternion.Inverse(InitialControlBoneGlobalRotation) * ControlBone.localRotation * InitialControlBoneGlobalRotation; + return InitialControlBoneLocalRotation * delta; } } @@ -102,7 +102,7 @@ namespace UniVRM10 /// internal void ProcessRecursively() { - ControlTarget.localRotation = _initialTargetLocalRotation * (Quaternion.Inverse(_initialTargetGlobalRotation) * ControlBoneRelativeRotationFromInitial * _initialTargetGlobalRotation); + ControlTarget.localRotation = _initialTargetLocalRotation * (Quaternion.Inverse(_initialTargetGlobalRotation) * NormalizedLocalRotation * _initialTargetGlobalRotation); foreach (var child in _children) { child.ProcessRecursively(); From 7af375cf343b902bad52ec646f95bbee8be09eb7 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 15:39:10 +0900 Subject: [PATCH 4/9] =?UTF-8?q?Vrm10Importer=20=E3=81=AE=E5=BC=95=E3=81=8D?= =?UTF-8?q?=E6=95=B0=E3=82=92=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * controlRigGenerationOption を削除 * controlRigInitialRotations に一本化 * IReadOnlyDictionary を使う * XR_EXT_hand_tracking の親指のロールを修正 --- .../VrmScriptedImporterImpl.cs | 2 +- .../Components/Vrm10Instance/Vrm10Instance.cs | 18 ++++--- .../ControlRig/ControlRigGenerationOption.cs | 16 ------ .../ControlRigGenerationOption.cs.meta | 3 -- .../Vrm10Runtime/ControlRig/Rigs.meta | 8 +++ .../Rigs/ControlRigGenerationOption.cs | 50 +++++++++++++++++++ .../Rigs/ControlRigGenerationOption.cs.meta} | 2 +- .../ControlRig/Rigs/Vrm0XCompatibleRig.cs | 15 ++++++ .../Rigs/Vrm0XCompatibleRig.cs.meta | 11 ++++ .../Rigs/XR_EXT_hand_tracking.cs} | 34 ++++++++++--- .../Rigs/XR_EXT_hand_tracking.cs.meta | 11 ++++ .../ControlRig/Vrm10ControlBone.cs | 20 ++++---- .../Components/Vrm10Runtime/Vrm10Runtime.cs | 6 +-- .../Vrm10Runtime/Vrm10RuntimeControlRig.cs | 15 ++++-- Assets/VRM10/Runtime/IO/Vrm10.cs | 14 +----- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 14 +++--- Assets/VRM10/Tests.PlayMode/MaterialTests.cs | 2 +- Assets/VRM10/Tests/ApiSampleTests.cs | 2 +- Assets/VRM10/Tests/ExpressionTests.cs | 4 +- Assets/VRM10/Tests/LoadTests.cs | 2 +- 20 files changed, 171 insertions(+), 78 deletions(-) delete mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs delete mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs.meta create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs.meta create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs rename Assets/VRM10/Runtime/Components/Vrm10Runtime/{OpenXRHandTracking.cs.meta => ControlRig/Rigs/ControlRigGenerationOption.cs.meta} (83%) create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs.meta rename Assets/VRM10/Runtime/Components/Vrm10Runtime/{OpenXRHandTracking.cs => ControlRig/Rigs/XR_EXT_hand_tracking.cs} (61%) create mode 100644 Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs.meta diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs index a6a2705f9..305bcccfc 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs @@ -40,7 +40,7 @@ namespace UniVRM10 var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); - using (var loader = new Vrm10Importer(result, extractedObjects, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(result, controlRigInitialRotations: null, externalObjectMap: extractedObjects, materialGenerator: materialGenerator)) { // settings TextureImporters foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs index b2822cc0e..e3a888704 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Instance/Vrm10Instance.cs @@ -53,8 +53,15 @@ namespace UniVRM10 private UniHumanoid.Humanoid m_humanoid; private Vrm10Runtime m_runtime; - private ControlRigGenerationOption m_controlRigGenerationOption = ControlRigGenerationOption.None; - private Dictionary m_initialRotations; + + /// + /// ControlRig の生成オプション + /// + /// null: ControlRigGenerationOption.None + /// empty: ControlRigGenerationOption.Generate = Vrm0XCompatibleRig + /// other: ControlRigGenerationOption.Vrm0XCompatibleWithXR_EXT_hand_tracking など + /// + private IReadOnlyDictionary m_controlRigInitialRotations; /// /// VRM ファイルに記録された Humanoid ボーンに対応します。 @@ -81,16 +88,15 @@ namespace UniVRM10 { if (m_runtime == null) { - m_runtime = new Vrm10Runtime(this, m_controlRigGenerationOption, m_initialRotations); + m_runtime = new Vrm10Runtime(this, m_controlRigInitialRotations); } return m_runtime; } } - internal void InitializeAtRuntime(ControlRigGenerationOption controlRigGenerationOption, Dictionary initialRotations = null) + internal void InitializeAtRuntime(IReadOnlyDictionary controlRigInitialRotations) { - m_controlRigGenerationOption = controlRigGenerationOption; - m_initialRotations = initialRotations; + m_controlRigInitialRotations = controlRigInitialRotations; } void Start() diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs deleted file mode 100644 index 6ebb0e6e4..000000000 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace UniVRM10 -{ - public enum ControlRigGenerationOption - { - /// - /// コントロールリグを生成しません。 - /// - None, - - /// - /// 推奨されるオプションです。 - /// コントロールリグのボーン Transform を生成し、Root の Animator はコントロールリグのボーンを制御するようになります。 - /// - Generate, - } -} \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs.meta deleted file mode 100644 index f6e9a90c1..000000000 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/ControlRigGenerationOption.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9723f89e671a460188d12cbcceccaa4e -timeCreated: 1663314138 \ No newline at end of file diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs.meta new file mode 100644 index 000000000..990bb33f5 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ebc9416609f7b734f87e487dfa0ae076 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs new file mode 100644 index 000000000..eaae70332 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using UnityEngine; + +namespace UniVRM10 +{ + public enum ControlRigGenerationOption + { + /// + /// コントロールリグを生成しません。 + /// + None = 0, + + /// + /// 推奨されるオプションです。 + /// コントロールリグのボーン Transform を生成し、Root の Animator はコントロールリグのボーンを制御するようになります。 + /// + Generate = 1, + Vrm0XCompatibleRig = 1, + + /// + /// コントロールリグのボーン Transform を生成し、Root の Animator はコントロールリグのボーンを制御するようになります。 + /// 手と指に関して、XR_EXT_hand_tracking の初期回転を持ちます。 + /// https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_EXT_hand_tracking + /// + Vrm0XCompatibleWithXR_EXT_hand_tracking = 2, + } + + public static class ControlRigGenerationOptionExtensions + { + public static IReadOnlyDictionary ToInitialRotations(this ControlRigGenerationOption option) + { + switch (option) + { + case ControlRigGenerationOption.None: + return null; + + case ControlRigGenerationOption.Generate: + // case ControlRigGenerationOption.Vrm0XCompatibleRig: + return Vrm0XCompatibleRig.InitialRotations; + + case ControlRigGenerationOption.Vrm0XCompatibleWithXR_EXT_hand_tracking: + return XR_EXT_hand_tracking.InitialRotations; + + default: + throw new ArgumentException(); + } + } + } +} diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs.meta similarity index 83% rename from Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta rename to Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs.meta index bb500746b..f32b76551 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs.meta +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 45a6dbb978533164dafbcbf6f28e5117 +guid: 254b61afe523dd74b9579ff1e971bee7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs new file mode 100644 index 000000000..ddc033dc5 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace UniVRM10 +{ + public static class Vrm0XCompatibleRig + { + /// + /// 空の Dictionary を返します。 + /// HumanBodyBones に対応する Quaternion が無い場合は Quaternion.Identity を採用する仕様です。 + /// VRM-0.X では T-Pose のときにすべてのボーンが Quaternion.Identity です。 + /// + public static IReadOnlyDictionary InitialRotations => new Dictionary(); + } +} diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs.meta new file mode 100644 index 000000000..515a87b3b --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/Vrm0XCompatibleRig.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d1e0f212571bf3f41809f19c2d8f3211 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs similarity index 61% rename from Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs rename to Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs index 9e622a739..a563e59bd 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/OpenXRHandTracking.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs @@ -4,14 +4,23 @@ using UnityEngine; namespace UniVRM10 { /// - /// TPose のときに XR_EXT_hand_tracking の joint が向いている向きを定義する。 + /// XR_EXT_hand_tracking の joint を VRM-1.0 の TPose に当てはめたときの方向を定義します。 /// - /// https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#_conventions_of_hand_joints + /// * https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#_conventions_of_hand_joints + /// * https://github.com/vrm-c/vrm-specification/blob/master/specification/VRMC_vrm-1.0/tpose.ja.md /// - /// Unityは左手系なので、X軸を反転させます。 /// - public static class OpenXRHandTracking + public static class XR_EXT_hand_tracking { + /// + /// up vector と forward vector の外積により空間を算出して、回転を得ます。 + /// + /// OpenXR は右手系なのに対して Unityは左手系です。 + /// 結果として、X軸が反転することに注意してください。 + /// + /// + /// + /// public static Quaternion GetRotation(Vector3 up, Vector3 forward) { var xAxis = Vector3.Cross(up, forward).normalized; @@ -20,11 +29,22 @@ namespace UniVRM10 } public static Quaternion LeftHand = GetRotation(Vector3.up, Vector3.right); - public static Quaternion LeftThumb = GetRotation(Vector3.up, (Vector3.right + Vector3.forward).normalized); public static Quaternion RightHand = GetRotation(Vector3.up, Vector3.left); - public static Quaternion RightThumb = GetRotation(Vector3.up, (Vector3.left + Vector3.forward).normalized); - public static readonly Dictionary InitialRotations = new Dictionary() + /// + /// 親指は XZ 平面45度です。 + /// + public static Quaternion LeftThumb = GetRotation((Vector3.forward + Vector3.left).normalized, (Vector3.right + Vector3.forward).normalized); + + /// + /// 親指は XZ 平面45度です。 + /// + public static Quaternion RightThumb = GetRotation((Vector3.forward + Vector3.right).normalized, (Vector3.left + Vector3.forward).normalized); + + /// + /// VRM-1.0 の T-Pose の定義から各指はX軸と並行です。親指はXZ平面に45度です。 + /// + public static IReadOnlyDictionary InitialRotations => new Dictionary() { // Left {HumanBodyBones.LeftHand, LeftHand}, diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs.meta b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs.meta new file mode 100644 index 000000000..bd891171b --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/XR_EXT_hand_tracking.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 551eba367636e4b45b222ce636a6adcf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index b3ec8fafd..8ab12e5d1 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -46,7 +46,7 @@ namespace UniVRM10 private readonly Quaternion _initialTargetGlobalRotation; private readonly List _children = new List(); - private Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType, Vrm10ControlBone parent, Dictionary initialRotations) + private Vrm10ControlBone(Transform controlTarget, HumanBodyBones boneType, Vrm10ControlBone parent, IReadOnlyDictionary controlRigInitialRotations) { if (boneType == HumanBodyBones.LastBone) { @@ -61,9 +61,9 @@ namespace UniVRM10 ControlTarget = controlTarget; // NOTE: bone name must be unique in the vrm instance. ControlBone = new GameObject($"{nameof(Vrm10ControlBone)}:{boneType.ToString()}").transform; - if (initialRotations != null) + if (controlRigInitialRotations != null) { - if (initialRotations.TryGetValue(boneType, out var rotation)) + if (controlRigInitialRotations.TryGetValue(boneType, out var rotation)) { ControlBone.rotation = rotation; } @@ -86,7 +86,7 @@ namespace UniVRM10 /// /// 初期姿勢からの相対的な回転。 /// - /// VRM-0.X では localRotation と同じである。 + /// VRM-0.X 互換リグでは localRotation と同じ値を示す。 /// Quaternion NormalizedLocalRotation { @@ -109,32 +109,32 @@ namespace UniVRM10 } } - public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, Dictionary initialRotations, out Dictionary boneMap) + public static Vrm10ControlBone Build(UniHumanoid.Humanoid humanoid, IReadOnlyDictionary controlRigInitialRotations, out Dictionary boneMap) { - var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips, null, initialRotations); + var hips = new Vrm10ControlBone(humanoid.Hips, HumanBodyBones.Hips, null, controlRigInitialRotations); boneMap = new Dictionary(); boneMap.Add(HumanBodyBones.Hips, hips); foreach (Transform child in humanoid.Hips) { - BuildRecursively(humanoid, child, hips, initialRotations, boneMap); + BuildRecursively(humanoid, child, hips, controlRigInitialRotations, boneMap); } return hips; } - private static void BuildRecursively(UniHumanoid.Humanoid humanoid, Transform current, Vrm10ControlBone parent, Dictionary initialRotations, Dictionary boneMap) + private static void BuildRecursively(UniHumanoid.Humanoid humanoid, Transform current, Vrm10ControlBone parent, IReadOnlyDictionary controlRigInitialRotations, Dictionary boneMap) { if (humanoid.TryGetBoneForTransform(current, out var bone)) { - var newBone = new Vrm10ControlBone(current, bone, parent, initialRotations); + var newBone = new Vrm10ControlBone(current, bone, parent, controlRigInitialRotations); parent = newBone; boneMap.Add(bone, newBone); } foreach (Transform child in current) { - BuildRecursively(humanoid, child, parent, initialRotations, boneMap); + BuildRecursively(humanoid, child, parent, controlRigInitialRotations, boneMap); } } } diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index a31b74134..0265e65b7 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -49,7 +49,7 @@ namespace UniVRM10 } } - public Vrm10Runtime(Vrm10Instance target, ControlRigGenerationOption controlRigGenerationOption, Dictionary initialRotations = null) + public Vrm10Runtime(Vrm10Instance target, IReadOnlyDictionary controlRigInitialRotations) { m_target = target; @@ -58,9 +58,9 @@ namespace UniVRM10 throw new Exception(); } - if (controlRigGenerationOption != ControlRigGenerationOption.None) + if (controlRigInitialRotations != null) { - ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform, controlRigGenerationOption, initialRotations); + ControlRig = new Vrm10RuntimeControlRig(target.Humanoid, m_target.transform, controlRigInitialRotations); } Constraints = target.GetComponentsInChildren(); LookAt = new Vrm10RuntimeLookAt(target.Vrm.LookAt, target.Humanoid, m_head, target.LookAtTargetType, target.Gaze); diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs index 0edb375eb..681cf681d 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10RuntimeControlRig.cs @@ -25,17 +25,22 @@ namespace UniVRM10 public float InitialHipsHeight { get; } /// - /// コンストラクタ。 - /// humanoid は VRM T-Pose でなければならない。 + /// humanoid に対して ControlRig を生成します /// - public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid, Transform vrmRoot, ControlRigGenerationOption option, Dictionary initialRotations) + /// T-Pose である必要があります + /// + /// ControlRigの各ボーンの初期回転を表します + public Vrm10RuntimeControlRig(UniHumanoid.Humanoid humanoid, Transform vrmRoot, IReadOnlyDictionary controlRigInitialRotations) { - if (option == ControlRigGenerationOption.None) return; + if (controlRigInitialRotations == null) + { + throw new ArgumentNullException(); + } _controlRigRoot = new GameObject("Runtime Control Rig").transform; _controlRigRoot.SetParent(vrmRoot); - _hipBone = Vrm10ControlBone.Build(humanoid, initialRotations, out _bones); + _hipBone = Vrm10ControlBone.Build(humanoid, controlRigInitialRotations, out _bones); _hipBone.ControlBone.SetParent(_controlRigRoot); InitialHipsHeight = _hipBone.ControlTarget.position.y; diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index 2d2bed77b..5f5ef9448 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -39,7 +39,6 @@ namespace UniVRM10 string path, bool canLoadVrm0X = true, ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.Generate, - Dictionary initialRotations = null, bool showMeshes = true, IAwaitCaller awaitCaller = null, IMaterialDescriptorGenerator materialGenerator = null, @@ -58,7 +57,6 @@ namespace UniVRM10 System.IO.File.ReadAllBytes(path), canLoadVrm0X, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -85,7 +83,6 @@ namespace UniVRM10 byte[] bytes, bool canLoadVrm0X = true, ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.Generate, - Dictionary initialRotations = null, bool showMeshes = true, IAwaitCaller awaitCaller = null, IMaterialDescriptorGenerator materialGenerator = null, @@ -104,7 +101,6 @@ namespace UniVRM10 bytes, canLoadVrm0X, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -117,7 +113,6 @@ namespace UniVRM10 byte[] bytes, bool canLoadVrm0X, ControlRigGenerationOption controlRigGenerationOption, - Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -136,7 +131,6 @@ namespace UniVRM10 var instance = await TryLoadingAsVrm10Async( gltfData, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -162,7 +156,6 @@ namespace UniVRM10 var migratedInstance = await TryMigratingFromVrm0XAsync( gltfData, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -186,7 +179,6 @@ namespace UniVRM10 private static async Task TryLoadingAsVrm10Async( GltfData gltfData, ControlRigGenerationOption controlRigGenerationOption, - Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -212,7 +204,6 @@ namespace UniVRM10 vrm10Data, null, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -223,7 +214,6 @@ namespace UniVRM10 private static async Task TryMigratingFromVrm0XAsync( GltfData gltfData, ControlRigGenerationOption controlRigGenerationOption, - Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -251,7 +241,6 @@ namespace UniVRM10 migratedVrm10Data, migrationData, controlRigGenerationOption, - initialRotations, showMeshes, awaitCaller, materialGenerator, @@ -269,7 +258,6 @@ namespace UniVRM10 Vrm10Data vrm10Data, MigrationData migrationData, ControlRigGenerationOption controlRigGenerationOption, - Dictionary initialRotations, bool showMeshes, IAwaitCaller awaitCaller, IMaterialDescriptorGenerator materialGenerator, @@ -287,7 +275,7 @@ namespace UniVRM10 throw new ArgumentNullException(nameof(vrm10Data)); } - using (var loader = new Vrm10Importer(vrm10Data, controlRigGenerationOption: controlRigGenerationOption, initialRotations: initialRotations, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(vrm10Data, controlRigGenerationOption.ToInitialRotations(), materialGenerator: materialGenerator)) { // 1. Load meta information if callback was available. if (vrmMetaInformationCallback != null) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 0e23ba5e8..8d42eea33 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -18,8 +18,7 @@ namespace UniVRM10 private readonly Vrm10Data m_vrm; /// VrmLib.Model の オブジェクトと UnityEngine.Object のマッピングを記録する private readonly ModelMap m_map = new ModelMap(); - private readonly ControlRigGenerationOption m_controlRigGenerationOption; - private readonly Dictionary m_initialRotations; + private readonly IReadOnlyDictionary m_controlRigInitialRotations; private VrmLib.Model m_model; private IReadOnlyDictionary m_externalMap; @@ -29,11 +28,11 @@ namespace UniVRM10 public Vrm10Importer( Vrm10Data vrm, + IReadOnlyDictionary controlRigInitialRotations, IReadOnlyDictionary externalObjectMap = null, ITextureDeserializer textureDeserializer = null, - IMaterialDescriptorGenerator materialGenerator = null, - ControlRigGenerationOption controlRigGenerationOption = ControlRigGenerationOption.None, - Dictionary initialRotations = null) + IMaterialDescriptorGenerator materialGenerator = null + ) : base(vrm.Data, externalObjectMap, textureDeserializer) { if (vrm == null) @@ -41,8 +40,7 @@ namespace UniVRM10 throw new ArgumentNullException("vrm"); } m_vrm = vrm; - m_controlRigGenerationOption = controlRigGenerationOption; - m_initialRotations = initialRotations; + m_controlRigInitialRotations = controlRigInitialRotations; TextureDescriptorGenerator = new Vrm10TextureDescriptorGenerator(Data); MaterialDescriptorGenerator = materialGenerator ?? new BuiltInVrm10MaterialDescriptorGenerator(); @@ -249,7 +247,7 @@ namespace UniVRM10 // VrmController var controller = Root.AddComponent(); - controller.InitializeAtRuntime(m_controlRigGenerationOption, m_initialRotations); + controller.InitializeAtRuntime(m_controlRigInitialRotations); controller.enabled = false; // vrm diff --git a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs index 0dcc7b4ba..19f41039b 100644 --- a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs +++ b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs @@ -45,7 +45,7 @@ namespace UniVRM10.Test private (GameObject, IReadOnlyList) ToUnity(Vrm10Data data) { // Model => Unity - using (var loader = new Vrm10Importer(data)) + using (var loader = new Vrm10Importer(data, null)) { var loaded = loader.Load(); return (loaded.gameObject, loader.MaterialFactory.Materials); diff --git a/Assets/VRM10/Tests/ApiSampleTests.cs b/Assets/VRM10/Tests/ApiSampleTests.cs index f306c7990..a53b0dfdb 100644 --- a/Assets/VRM10/Tests/ApiSampleTests.cs +++ b/Assets/VRM10/Tests/ApiSampleTests.cs @@ -21,7 +21,7 @@ namespace UniVRM10.Test GameObject BuildGameObject(Vrm10Data data, bool showMesh) { - using (var loader = new Vrm10Importer(data)) + using (var loader = new Vrm10Importer(data, null)) { var loaded = loader.Load(); if (showMesh) diff --git a/Assets/VRM10/Tests/ExpressionTests.cs b/Assets/VRM10/Tests/ExpressionTests.cs index 8b8be849b..99e832566 100644 --- a/Assets/VRM10/Tests/ExpressionTests.cs +++ b/Assets/VRM10/Tests/ExpressionTests.cs @@ -32,7 +32,7 @@ namespace UniVRM10.Test controller.Vrm.Expression.Aa.MaterialColorBindings = src.ToArray(); // ok if no exception - var r = new Vrm10Runtime(controller, ControlRigGenerationOption.None); + var r = new Vrm10Runtime(controller, null); } [Test] @@ -56,7 +56,7 @@ namespace UniVRM10.Test controller.Vrm.Expression.Aa.MaterialUVBindings = src.ToArray(); // ok if no exception - var r = new Vrm10Runtime(controller, ControlRigGenerationOption.None); + var r = new Vrm10Runtime(controller, null); } } } diff --git a/Assets/VRM10/Tests/LoadTests.cs b/Assets/VRM10/Tests/LoadTests.cs index 652e5a146..ca2a4ac49 100644 --- a/Assets/VRM10/Tests/LoadTests.cs +++ b/Assets/VRM10/Tests/LoadTests.cs @@ -19,7 +19,7 @@ namespace UniVRM10.Test // empty thumbnail name vrm1Data.Data.GLTF.images[index].name = null; - using (var loader = new Vrm10Importer(vrm1Data)) + using (var loader = new Vrm10Importer(vrm1Data, null)) { loader.LoadAsync(new VRMShaders.ImmediateCaller()).Wait(); } From 60ecc165c8222d3303e08e5cc016042f33c730fc Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 17:03:45 +0900 Subject: [PATCH 5/9] internal --- .../ControlRig/Rigs/ControlRigGenerationOption.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs index eaae70332..b5a09268a 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Rigs/ControlRigGenerationOption.cs @@ -26,9 +26,9 @@ namespace UniVRM10 Vrm0XCompatibleWithXR_EXT_hand_tracking = 2, } - public static class ControlRigGenerationOptionExtensions + internal static class ControlRigGenerationOptionExtensions { - public static IReadOnlyDictionary ToInitialRotations(this ControlRigGenerationOption option) + internal static IReadOnlyDictionary ToInitialRotations(this ControlRigGenerationOption option) { switch (option) { From 02ea223822439639e94ff2982de281ca6937c695 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 17:06:31 +0900 Subject: [PATCH 6/9] controlRigInitialRotations = null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 順番 * null 引き数の省略 --- .../VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs | 2 +- Assets/VRM10/Runtime/IO/Vrm10.cs | 2 +- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 4 ++-- Assets/VRM10/Tests.PlayMode/MaterialTests.cs | 2 +- Assets/VRM10/Tests/LoadTests.cs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs index 305bcccfc..1bd6e9cf4 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterImpl.cs @@ -40,7 +40,7 @@ namespace UniVRM10 var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline); - using (var loader = new Vrm10Importer(result, controlRigInitialRotations: null, externalObjectMap: extractedObjects, materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(result, externalObjectMap: extractedObjects, materialGenerator: materialGenerator)) { // settings TextureImporters foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable()) diff --git a/Assets/VRM10/Runtime/IO/Vrm10.cs b/Assets/VRM10/Runtime/IO/Vrm10.cs index 5f5ef9448..c6b34fbe5 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10.cs @@ -275,7 +275,7 @@ namespace UniVRM10 throw new ArgumentNullException(nameof(vrm10Data)); } - using (var loader = new Vrm10Importer(vrm10Data, controlRigGenerationOption.ToInitialRotations(), materialGenerator: materialGenerator)) + using (var loader = new Vrm10Importer(vrm10Data, materialGenerator: materialGenerator, controlRigInitialRotations: controlRigGenerationOption.ToInitialRotations())) { // 1. Load meta information if callback was available. if (vrmMetaInformationCallback != null) diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 8d42eea33..5f86c25b2 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -28,10 +28,10 @@ namespace UniVRM10 public Vrm10Importer( Vrm10Data vrm, - IReadOnlyDictionary controlRigInitialRotations, IReadOnlyDictionary externalObjectMap = null, ITextureDeserializer textureDeserializer = null, - IMaterialDescriptorGenerator materialGenerator = null + IMaterialDescriptorGenerator materialGenerator = null, + IReadOnlyDictionary controlRigInitialRotations = null ) : base(vrm.Data, externalObjectMap, textureDeserializer) { diff --git a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs index 19f41039b..0dcc7b4ba 100644 --- a/Assets/VRM10/Tests.PlayMode/MaterialTests.cs +++ b/Assets/VRM10/Tests.PlayMode/MaterialTests.cs @@ -45,7 +45,7 @@ namespace UniVRM10.Test private (GameObject, IReadOnlyList) ToUnity(Vrm10Data data) { // Model => Unity - using (var loader = new Vrm10Importer(data, null)) + using (var loader = new Vrm10Importer(data)) { var loaded = loader.Load(); return (loaded.gameObject, loader.MaterialFactory.Materials); diff --git a/Assets/VRM10/Tests/LoadTests.cs b/Assets/VRM10/Tests/LoadTests.cs index ca2a4ac49..652e5a146 100644 --- a/Assets/VRM10/Tests/LoadTests.cs +++ b/Assets/VRM10/Tests/LoadTests.cs @@ -19,7 +19,7 @@ namespace UniVRM10.Test // empty thumbnail name vrm1Data.Data.GLTF.images[index].name = null; - using (var loader = new Vrm10Importer(vrm1Data, null)) + using (var loader = new Vrm10Importer(vrm1Data)) { loader.LoadAsync(new VRMShaders.ImmediateCaller()).Wait(); } From b24f06e1069b0c0a490e956c62ffaad95e64c865 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 17:07:16 +0900 Subject: [PATCH 7/9] comment --- Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs index 67e740685..861c2e783 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10Loaded.cs @@ -126,7 +126,6 @@ namespace UniVRM10.VRM10Viewer /// /// from v0.104 /// - /// public void UpdateControlRigImplicit(Animator src) { var dst = m_controller.GetComponent(); @@ -160,9 +159,8 @@ namespace UniVRM10.VRM10Viewer } /// - /// from v0.104 + /// from v0.108 /// - /// public void UpdateControlRigImplicit(UniHumanoid.Humanoid src) { var dst = m_controller.GetComponent(); From dd646cabb0cf1cee120239dfd7c10aa023957205 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 17:08:37 +0900 Subject: [PATCH 8/9] private readonly --- .../Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 8ab12e5d1..96f24fa87 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -40,8 +40,8 @@ namespace UniVRM10 /// コントロールボーンの初期ローカル回転。 /// public Quaternion InitialControlBoneLocalRotation { get; } - Quaternion InitialControlBoneGlobalRotation; + private readonly Quaternion _InitialControlBoneGlobalRotation; private readonly Quaternion _initialTargetLocalRotation; private readonly Quaternion _initialTargetGlobalRotation; private readonly List _children = new List(); @@ -78,7 +78,7 @@ namespace UniVRM10 InitialControlBoneLocalPosition = ControlBone.localPosition; InitialControlBoneLocalRotation = ControlBone.localRotation; - InitialControlBoneGlobalRotation = ControlBone.rotation; + _InitialControlBoneGlobalRotation = ControlBone.rotation; _initialTargetLocalRotation = controlTarget.localRotation; _initialTargetGlobalRotation = controlTarget.rotation; } @@ -92,7 +92,7 @@ namespace UniVRM10 { get { - var delta = Quaternion.Inverse(InitialControlBoneGlobalRotation) * ControlBone.localRotation * InitialControlBoneGlobalRotation; + var delta = Quaternion.Inverse(_InitialControlBoneGlobalRotation) * ControlBone.localRotation * _InitialControlBoneGlobalRotation; return InitialControlBoneLocalRotation * delta; } } From 5353ef14efdeb2a7e17f1508aad613ebcdcce538 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 28 Nov 2022 17:20:40 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=E5=B0=8F=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs index 96f24fa87..f2471e9d4 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/ControlRig/Vrm10ControlBone.cs @@ -41,7 +41,7 @@ namespace UniVRM10 /// public Quaternion InitialControlBoneLocalRotation { get; } - private readonly Quaternion _InitialControlBoneGlobalRotation; + private readonly Quaternion _initialControlBoneGlobalRotation; private readonly Quaternion _initialTargetLocalRotation; private readonly Quaternion _initialTargetGlobalRotation; private readonly List _children = new List(); @@ -78,7 +78,7 @@ namespace UniVRM10 InitialControlBoneLocalPosition = ControlBone.localPosition; InitialControlBoneLocalRotation = ControlBone.localRotation; - _InitialControlBoneGlobalRotation = ControlBone.rotation; + _initialControlBoneGlobalRotation = ControlBone.rotation; _initialTargetLocalRotation = controlTarget.localRotation; _initialTargetGlobalRotation = controlTarget.rotation; } @@ -92,7 +92,7 @@ namespace UniVRM10 { get { - var delta = Quaternion.Inverse(_InitialControlBoneGlobalRotation) * ControlBone.localRotation * _InitialControlBoneGlobalRotation; + var delta = Quaternion.Inverse(_initialControlBoneGlobalRotation) * ControlBone.localRotation * _initialControlBoneGlobalRotation; return InitialControlBoneLocalRotation * delta; } }