Skip to content

Commit

Permalink
Merge pull request #699 from ousttrue/fix/fix_unittest
Browse files Browse the repository at this point in the history
Fix/fix unittest
  • Loading branch information
ousttrue authored Jan 27, 2021
2 parents 7ad06ad + c7354f9 commit cfec160
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override string ToString()

public glTFExtensionExport Add(string key, ArraySegment<byte> raw)
{
m_serialized.Add(key, raw);
m_serialized[key] = raw;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM10/Runtime/IO/Vrm10Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ public SpringBoneManager CreateVrmSpringBone(List<Node> nodes)
joint.GravityDir = gltfJoint.GravityDir.ToVector3();
joint.GravityPower = gltfJoint.GravityPower.Value;
joint.Stiffness = gltfJoint.Stiffness.Value;
joint.Exclude = gltfJoint.Exclude.Value;
joint.Exclude = gltfJoint.Exclude.GetValueOrDefault();
springBone.Joints.Add(joint);
}

Expand Down
12 changes: 10 additions & 2 deletions Assets/VRM10/Runtime/IO/VrmSpringBoneAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ public static VRMC_springBone ToGltf(this SpringBoneManager self, List<Node> nod
return null;
}

var springBone = new VRMC_springBone();
var springBone = new VRMC_springBone
{
Springs = new List<Spring>(),
};

//
// VRMC_node_collider
//
foreach (var nodeCollider in self.Springs.SelectMany(x => x.Colliders))
{
var index = nodes.IndexOfThrow(nodeCollider.Node);
var gltfCollider = new VRMC_node_collider();
var gltfCollider = new VRMC_node_collider
{
Shapes = new List<ColliderShape>(),
};
foreach (var y in nodeCollider.Colliders)
{
switch (y.ColliderType)
Expand Down Expand Up @@ -80,12 +86,14 @@ public static VRMC_springBone ToGltf(this SpringBoneManager self, List<Node> nod
{
Name = x.Comment,
Colliders = x.Colliders.Select(y => nodes.IndexOfThrow(y.Node)).ToArray(),
Joints = new List<SpringBoneJoint>(),
};

foreach (var y in x.Joints)
{
spring.Joints.Add(new SpringBoneJoint
{
Node = nodes.IndexOfThrow(y.Node),
HitRadius = y.HitRadius,
DragForce = y.DragForce,
GravityDir = y.GravityDir.ToFloat3(),
Expand Down
36 changes: 30 additions & 6 deletions Assets/VRM10/Tests.PlayMode/MaterialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UniVRM10.Test
{
public class MaterialTests
{
const string _vrmPath = "Tests/Models/Alicia_vrm-1.00/AliciaSolid_vrm-1.00.vrm";
const string _vrmPath = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";

string[] _mtooSrgbTextureProperties = {
VrmLib.MToon.Utils.PropMainTex,
Expand All @@ -33,6 +33,10 @@ private ModelAsset ToUnity(string path)
{
var fi = new FileInfo(_vrmPath);
var bytes = File.ReadAllBytes(fi.FullName);

// migrate to 1.0
bytes = Migration.Migrate(bytes);

return ToUnity(bytes);
}

Expand Down Expand Up @@ -170,11 +174,31 @@ public IEnumerator MtoonGltfColorToUnity()

var model = ToVrmModel(assets.Root);
var gltfMaterial = model.Materials.First(x => x.Name == key.Name) as VrmLib.MToonMaterial;
gltfMaterial.Definition.Color.LitColor = new LinearColor { RGBA = srclinerColor };
gltfMaterial.Definition.Color.ShadeColor = new LinearColor { RGBA = srclinerColor };
gltfMaterial.Definition.Outline.OutlineColor = new LinearColor { RGBA = srclinerColor };
gltfMaterial.Definition.Emission.EmissionColor = new LinearColor { RGBA = srclinerColor };
gltfMaterial.Definition.Rim.RimColor = new LinearColor { RGBA = srclinerColor };
if (gltfMaterial == null)
{
throw new NotImplementedException();
}

gltfMaterial.Definition = new VrmLib.MToon.MToonDefinition
{
Color = new VrmLib.MToon.ColorDefinition
{
LitColor = new LinearColor { RGBA = srclinerColor },
ShadeColor = new LinearColor { RGBA = srclinerColor },
},
Outline = new VrmLib.MToon.OutlineDefinition
{
OutlineColor = new LinearColor { RGBA = srclinerColor },
},
Emission = new VrmLib.MToon.EmissionDefinition
{
EmissionColor = new LinearColor { RGBA = srclinerColor },
},
Rim = new VrmLib.MToon.RimDefinition
{
RimColor = new LinearColor { RGBA = srclinerColor },
}
};

var bytes = model.ToGlb();

Expand Down
6 changes: 2 additions & 4 deletions Assets/VRM10/Tests.PlayMode/VRM10.Tests.PlayMode.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
]
"defineConstraints": []
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

Expand All @@ -9,15 +10,15 @@ public class ApiSampleTests
{
VrmLib.Model ReadModel(string path)
{
var bytes = File.ReadAllBytes(path);
var bytes = Migration.Migrate(File.ReadAllBytes(path));

if (!UniGLTF.Glb.TryParse(bytes, out UniGLTF.Glb glb, out Exception ex))
{
Debug.LogError($"fail to Glb.TryParse: {path} => {ex}");
return null;
}

var model = UniVRM10.VrmLoader.CreateVrmModel(path);
var model = UniVRM10.VrmLoader.CreateVrmModel(bytes, new FileInfo(path));
return model;
}

Expand All @@ -43,10 +44,10 @@ byte[] ToVrm10(VrmLib.Model model)
return bytes;
}

[UnityTest]
public bool Sample()
[Test]
public void Sample()
{
var path = "Tests/Models/Alicia_vrm-1.00/AliciaSolid_vrm-1.00.vrm";
var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";
Debug.Log($"load: {path}");

// import
Expand Down Expand Up @@ -74,8 +75,6 @@ public bool Sample()

var vrmBytes = ToVrm10(dstModel);
Debug.Log($"export {vrmBytes.Length} bytes");

return true;
}
}
}
File renamed without changes.

0 comments on commit cfec160

Please sign in to comment.