From f14186068c4bf21e7af6795062f992e164b8b2d3 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 19:11:50 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Migrate=5FSpringBoneTest=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=80=82=E6=AD=A3=E3=81=97=E3=81=8F=20migrat?= =?UTF-8?q?ion=20=E3=81=A7=E3=81=8D=E3=81=A6=E3=81=84=E3=82=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Tests/MigrationTests.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/VRM10/Tests/MigrationTests.cs b/Assets/VRM10/Tests/MigrationTests.cs index 2f5bded6fe..4e73823da9 100644 --- a/Assets/VRM10/Tests/MigrationTests.cs +++ b/Assets/VRM10/Tests/MigrationTests.cs @@ -213,5 +213,31 @@ public void Migrate_VrmTestModels() } } } + + /// + /// migration で x が反転することを確認 + /// + [Test] + public void Migrate_SpringBoneTest() + { + const float VALUE = -0.0359970331f; + var parser0 = new GltfParser(); + var bytes0 = File.ReadAllBytes(AliciaPath); + parser0.Parse(AliciaPath, bytes0); + var json0 = parser0.Json.ParseAsJson(); + var x = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][3]["colliders"][0]["offset"]["x"].GetSingle(); + Assert.AreEqual(VALUE, x); + + var bytes1 = MigrationVrm.Migrate(bytes0); + var parser1 = new GltfParser(); + parser1.Parse(AliciaPath, bytes1); + + Assert.True(UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(parser1.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone)); + var spring = springBone.Springs[0]; + var colliderNodeIndex = spring.Colliders[0]; + + Assert.True(UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(parser1.GLTF.nodes[colliderNodeIndex].extensions, out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider colliderGroup)); + Assert.AreEqual(-VALUE, colliderGroup.Shapes[0].Sphere.Offset[0]); + } } } From 1204d83ddc8a395bdfe27ed421e6c42244dc6eff Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 19:13:38 +0900 Subject: [PATCH 2/3] =?UTF-8?q?RuntimeUnityBuilder=20=E3=81=AE=20VRM?= =?UTF-8?q?=E9=83=A8=E5=88=86=E3=81=A7=E3=80=81=E5=BF=85=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E5=BA=A7=E6=A8=99=E5=A4=89=E6=8F=9B(x=E5=8F=8D=E8=BB=A2)?= =?UTF-8?q?=E3=81=8C=E7=84=A1=E3=81=8B=E3=81=A3=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mesh, Node は、VrmLib.Model を介して座標変換されている。 --- Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs index e86ee09bbf..6cceca31ec 100644 --- a/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs +++ b/Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs @@ -372,7 +372,7 @@ async Task LoadSpringBoneAsync(IAwaitCaller awaitCaller, VRM10Controller control var joint = new VRM10SpringJoint(Nodes[gltfJoint.Node.Value]); joint.m_jointRadius = gltfJoint.HitRadius.Value; joint.m_dragForce = gltfJoint.DragForce.Value; - joint.m_gravityDir = Vector3(gltfJoint.GravityDir); + joint.m_gravityDir = Vector3InvertX(gltfJoint.GravityDir); joint.m_gravityPower = gltfJoint.GravityPower.Value; joint.m_stiffnessForce = gltfJoint.Stiffness.Value; // joint.m_exclude = gltfJoint.Exclude.GetValueOrDefault(); @@ -398,7 +398,7 @@ async Task LoadSpringBoneAsync(IAwaitCaller awaitCaller, VRM10Controller control return new VRM10SpringBoneCollider { ColliderType = VRM10SpringBoneColliderTypes.Sphere, - Offset = Vector3(x.Sphere.Offset), + Offset = Vector3InvertX(x.Sphere.Offset), Radius = x.Sphere.Radius.Value, }; } @@ -407,9 +407,9 @@ async Task LoadSpringBoneAsync(IAwaitCaller awaitCaller, VRM10Controller control return new VRM10SpringBoneCollider { ColliderType = VRM10SpringBoneColliderTypes.Capsule, - Offset = Vector3(x.Capsule.Offset), + Offset = Vector3InvertX(x.Capsule.Offset), Radius = x.Capsule.Radius.Value, - Tail = Vector3(x.Capsule.Tail), + Tail = Vector3InvertX(x.Capsule.Tail), }; } else @@ -441,12 +441,12 @@ static AxisMask FreezeAxis(bool[] flags) return mask; } - static Vector3 Vector3(float[] f) + static Vector3 Vector3InvertX(float[] f) { var v = default(Vector3); if (f != null && f.Length == 3) { - v.x = f[0]; + v.x = -f[0]; v.y = f[1]; v.z = f[2]; } @@ -489,8 +489,8 @@ async Task LoadConstraintAsync(IAwaitCaller awaitCaller, VRM10Controller control var a = constraint.Aim; var aimConstraint = node.gameObject.AddComponent(); aimConstraint.Source = Nodes[a.Source.Value]; - aimConstraint.AimVector = Vector3(a.AimVector); - aimConstraint.UpVector = Vector3(a.UpVector); + aimConstraint.AimVector = Vector3InvertX(a.AimVector); + aimConstraint.UpVector = Vector3InvertX(a.UpVector); } } } From 14abb5ff6519acf889802c23b0ec5372837504df Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 16 Apr 2021 19:30:27 +0900 Subject: [PATCH 3/3] =?UTF-8?q?x=20=E3=81=A8=20y=20=E3=81=AE=E6=AF=94?= =?UTF-8?q?=E8=BC=83=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Tests/MigrationTests.cs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Assets/VRM10/Tests/MigrationTests.cs b/Assets/VRM10/Tests/MigrationTests.cs index 4e73823da9..1fcc93f4f6 100644 --- a/Assets/VRM10/Tests/MigrationTests.cs +++ b/Assets/VRM10/Tests/MigrationTests.cs @@ -220,24 +220,36 @@ public void Migrate_VrmTestModels() [Test] public void Migrate_SpringBoneTest() { - const float VALUE = -0.0359970331f; + // + // vrm0 のオリジナルの値 + // + var VALUE = new Vector3(-0.0359970331f, -0.0188314915f, 0.00566166639f); var parser0 = new GltfParser(); var bytes0 = File.ReadAllBytes(AliciaPath); parser0.Parse(AliciaPath, bytes0); var json0 = parser0.Json.ParseAsJson(); - var x = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][3]["colliders"][0]["offset"]["x"].GetSingle(); - Assert.AreEqual(VALUE, x); - + var colliderIndex = json0["extensions"]["VRM"]["secondaryAnimation"]["boneGroups"][0]["colliderGroups"][0].GetInt32(); + var x = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][colliderIndex]["colliders"][0]["offset"]["x"].GetSingle(); + var y = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][colliderIndex]["colliders"][0]["offset"]["y"].GetSingle(); + var z = json0["extensions"]["VRM"]["secondaryAnimation"]["colliderGroups"][colliderIndex]["colliders"][0]["offset"]["z"].GetSingle(); + Assert.AreEqual(VALUE.x, x); + Assert.AreEqual(VALUE.y, y); + Assert.AreEqual(VALUE.z, z); + + // + // vrm1 に migrate + // var bytes1 = MigrationVrm.Migrate(bytes0); var parser1 = new GltfParser(); parser1.Parse(AliciaPath, bytes1); - Assert.True(UniGLTF.Extensions.VRMC_springBone.GltfDeserializer.TryGet(parser1.GLTF.extensions, out UniGLTF.Extensions.VRMC_springBone.VRMC_springBone springBone)); var spring = springBone.Springs[0]; var colliderNodeIndex = spring.Colliders[0]; - Assert.True(UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(parser1.GLTF.nodes[colliderNodeIndex].extensions, out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider colliderGroup)); - Assert.AreEqual(-VALUE, colliderGroup.Shapes[0].Sphere.Offset[0]); + // x軸だけが反転する + Assert.AreEqual(-VALUE.x, colliderGroup.Shapes[0].Sphere.Offset[0]); + Assert.AreEqual(VALUE.y, colliderGroup.Shapes[0].Sphere.Offset[1]); + Assert.AreEqual(VALUE.z, colliderGroup.Shapes[0].Sphere.Offset[2]); } } }