From cc304f3b90856993233b8dca4a6cb79eda0a0b24 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 1 Aug 2022 19:31:21 +0900 Subject: [PATCH 1/3] fix importer / exporter --- .../Constraint/Vrm10ConstraintUtil.cs | 18 ++++++++++++++++++ .../Constraint/Vrm10ConstraintUtil.cs.meta | 11 +++++++++++ Assets/VRM10/Runtime/IO/Vrm10Exporter.cs | 2 +- Assets/VRM10/Runtime/IO/Vrm10Importer.cs | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs create mode 100644 Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs.meta diff --git a/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs b/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs new file mode 100644 index 000000000..702f17d02 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs @@ -0,0 +1,18 @@ +namespace UniVRM10 +{ + public static class Vrm10ConstraintUtil + { + /// + /// 右手系と左手系を相互に変換する + /// + public static UniGLTF.Extensions.VRMC_node_constraint.AimAxis ReverseX(UniGLTF.Extensions.VRMC_node_constraint.AimAxis src) + { + switch (src) + { + case UniGLTF.Extensions.VRMC_node_constraint.AimAxis.PositiveX: return UniGLTF.Extensions.VRMC_node_constraint.AimAxis.NegativeX; + case UniGLTF.Extensions.VRMC_node_constraint.AimAxis.NegativeX: return UniGLTF.Extensions.VRMC_node_constraint.AimAxis.PositiveX; + default: return src; + } + } + } +} diff --git a/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs.meta b/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs.meta new file mode 100644 index 000000000..461a75070 --- /dev/null +++ b/Assets/VRM10/Runtime/Components/Constraint/Vrm10ConstraintUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2c7b76ebe42e9543ac52153ea9f2728 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs index af3dc02f4..bd20f8cb4 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Exporter.cs @@ -430,7 +430,7 @@ namespace UniVRM10 { Source = model.Nodes.IndexOf(converter.Nodes[aimConstraint.Source.gameObject]), Weight = aimConstraint.Weight, - AimAxis = aimConstraint.AimAxis, + AimAxis = Vrm10ConstraintUtil.ReverseX(aimConstraint.AimAxis), }; break; diff --git a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs index 1fab7d277..6aed057d5 100644 --- a/Assets/VRM10/Runtime/IO/Vrm10Importer.cs +++ b/Assets/VRM10/Runtime/IO/Vrm10Importer.cs @@ -701,7 +701,7 @@ namespace UniVRM10 var component = node.gameObject.AddComponent(); component.Source = Nodes[aim.Source.Value]; // required component.Weight = aim.Weight.GetValueOrDefault(1.0f); - component.AimAxis = aim.AimAxis; // required + component.AimAxis = Vrm10ConstraintUtil.ReverseX(aim.AimAxis); // required } else if (constraint.Rotation != null) { From 29df3f89da8d201647f1fc073d6074a9dc40caba Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 1 Aug 2022 20:38:43 +0900 Subject: [PATCH 2/3] aim gizmo --- .../Constraint/Vrm10AimConstraint.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs b/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs index 72d364c82..231640f0b 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs @@ -76,5 +76,31 @@ namespace UniVRM10 Weight ); } + + public void OnDrawGizmosSelected() + { + if (Source == null) + { + return; + } + + Gizmos.color = Color.magenta; + Gizmos.DrawLine(transform.position, Source.position); + Gizmos.DrawSphere(Source.position, 0.01f); + + Gizmos.matrix = transform.localToWorldMatrix; + var len = 0.1f; + switch (AimAxis) + { + case AimAxis.PositiveX: + Gizmos.color = Color.red; + Gizmos.DrawLine(Vector3.zero, Vector3.right * len); + break; + case AimAxis.NegativeX: + Gizmos.color = Color.red; + Gizmos.DrawLine(Vector3.zero, Vector3.left * len); + break; + } + } } } From ea9aa5afe6894cc749b9d92f5a651920297e0990 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 5 Aug 2022 16:07:20 +0900 Subject: [PATCH 3/3] =?UTF-8?q?world=20=E3=82=92=20local=20=E3=81=AB?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs b/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs index 231640f0b..15d489eae 100644 --- a/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs +++ b/Assets/VRM10/Runtime/Components/Constraint/Vrm10AimConstraint.cs @@ -70,7 +70,7 @@ namespace UniVRM10 var toVec = (Source.position - transform.position).normalized; var fromToQuat = Quaternion.FromToRotation(fromVec, toVec); - transform.rotation = Quaternion.SlerpUnclamped( + transform.localRotation = Quaternion.SlerpUnclamped( _dstRestLocalQuat, Quaternion.Inverse(dstParentWorldQuat) * fromToQuat * dstParentWorldQuat * _dstRestLocalQuat, Weight