Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Importerを修正 #882

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Assets/VRM10/Runtime/IO/RuntimeUnityBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
};
}
Expand All @@ -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
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -489,8 +489,8 @@ async Task LoadConstraintAsync(IAwaitCaller awaitCaller, VRM10Controller control
var a = constraint.Aim;
var aimConstraint = node.gameObject.AddComponent<VRM10AimConstraint>();
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);
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions Assets/VRM10/Tests/MigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,43 @@ public void Migrate_VrmTestModels()
}
}
}

/// <summary>
/// migration で x が反転することを確認
/// </summary>
[Test]
public void Migrate_SpringBoneTest()
{
//
// 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 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));
// 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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ヨシ!

}
}
}