mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-27 13:32:46 -05:00
Fix Vrm10 Tests
This commit is contained in:
parent
c4e3f53d5d
commit
eff55a9465
|
|
@ -7,49 +7,20 @@ namespace UniVRM10.Test
|
|||
{
|
||||
public class ApiSampleTests
|
||||
{
|
||||
VrmLib.Model ReadModel(string path)
|
||||
{
|
||||
var bytes = MigrationVrm.Migrate(File.ReadAllBytes(path));
|
||||
|
||||
var data = new GlbLowLevelParser(path, bytes).Parse();
|
||||
|
||||
var model = ModelReader.Read(data);
|
||||
return model;
|
||||
}
|
||||
|
||||
GameObject BuildGameObject(Vrm10Data data, bool showMesh)
|
||||
{
|
||||
using (var loader = new Vrm10Importer(data, null))
|
||||
{
|
||||
var loaded = loader.Load();
|
||||
if (showMesh)
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
}
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
return loaded.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sample()
|
||||
{
|
||||
var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";
|
||||
Debug.Log($"load: {path}");
|
||||
|
||||
using (var data = new GlbFileParser(path).Parse())
|
||||
using (var migrated = Vrm10Data.Migrate(data, out Vrm10Data result, out MigrationData migration))
|
||||
{
|
||||
Assert.NotNull(result);
|
||||
var instance = TestVrm10.LoadPathAsBuiltInRP(path, canLoadVrm0X: true);
|
||||
Assert.NotNull(instance);
|
||||
|
||||
var go = BuildGameObject(result, true);
|
||||
Debug.Log(go);
|
||||
var go = instance.gameObject;
|
||||
Debug.Log(go);
|
||||
|
||||
// export
|
||||
var vrmBytes = Vrm10Exporter.Export(go, textureSerializer: new EditorTextureSerializer());
|
||||
|
||||
Debug.Log($"export {vrmBytes.Length} bytes");
|
||||
}
|
||||
var vrmBytes = TestVrm10.ExportAsBuiltInRP(go);
|
||||
Debug.Log($"export {vrmBytes.Length} bytes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ namespace UniVRM10
|
|||
{
|
||||
try
|
||||
{
|
||||
Vrm10.LoadPathAsync(gltf.FullName, true, controlRigGenerationOption: ControlRigGenerationOption.None).Wait();
|
||||
TestVrm10.LoadPathAsBuiltInRP(gltf.FullName);
|
||||
}
|
||||
catch (UnNormalizedException)
|
||||
{
|
||||
|
|
@ -372,7 +372,7 @@ namespace UniVRM10
|
|||
new Color(2.0f, 2.0f, 2.0f, 1),
|
||||
};
|
||||
|
||||
var instance106 = Vrm10.LoadBytesAsync(model106, awaitCaller: new ImmediateCaller()).Result;
|
||||
var instance106 = TestVrm10.LoadBytesAsBuiltInRP(model106);
|
||||
var materials106 = instance106.GetComponent<RuntimeGltfInstance>().Materials;
|
||||
Assert.AreEqual(materialCount, materials106.Count);
|
||||
for (var idx = 0; idx < materialCount; ++idx)
|
||||
|
|
@ -384,7 +384,7 @@ namespace UniVRM10
|
|||
if (correctEmissions[idx].HasValue) AssertAreApproximatelyEqualColor(correctEmissions[idx].Value, material.GetColor(emissionName));
|
||||
}
|
||||
|
||||
var instance107 = Vrm10.LoadBytesAsync(model107, awaitCaller: new ImmediateCaller()).Result;
|
||||
var instance107 = TestVrm10.LoadBytesAsBuiltInRP(model107);
|
||||
var materials107 = instance107.GetComponent<RuntimeGltfInstance>().Materials;
|
||||
Assert.AreEqual(materialCount, materials107.Count);
|
||||
for (var idx = 0; idx < materialCount; ++idx)
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@ namespace UniVRM10
|
|||
|
||||
public static Vrm10Instance LoadAlicia()
|
||||
{
|
||||
var task = Vrm10.LoadPathAsync(AliciaPath, canLoadVrm0X: true);
|
||||
task.Wait();
|
||||
var instance = task.Result;
|
||||
|
||||
var instance = TestVrm10.LoadPathAsBuiltInRP(AliciaPath, canLoadVrm0X: true);
|
||||
return instance.GetComponent<Vrm10Instance>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
37
Assets/VRM10/Tests/TestVrm10.cs
Normal file
37
Assets/VRM10/Tests/TestVrm10.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class TestVrm10
|
||||
{
|
||||
public static Vrm10Instance LoadBytesAsBuiltInRP(byte[] bytes, bool canLoadVrm0X = true)
|
||||
{
|
||||
return Vrm10.LoadBytesAsync(
|
||||
bytes,
|
||||
canLoadVrm0X: canLoadVrm0X,
|
||||
awaitCaller: new ImmediateCaller(),
|
||||
materialGenerator: new BuiltInVrm10MaterialDescriptorGenerator()
|
||||
).Result;
|
||||
}
|
||||
|
||||
public static Vrm10Instance LoadPathAsBuiltInRP(string path, bool canLoadVrm0X = true)
|
||||
{
|
||||
return Vrm10.LoadPathAsync(
|
||||
path,
|
||||
canLoadVrm0X: canLoadVrm0X,
|
||||
awaitCaller: new ImmediateCaller(),
|
||||
materialGenerator: new BuiltInVrm10MaterialDescriptorGenerator()
|
||||
).Result;
|
||||
}
|
||||
|
||||
public static byte[] ExportAsBuiltInRP(GameObject gameObject)
|
||||
{
|
||||
return Vrm10Exporter.Export(
|
||||
gameObject,
|
||||
materialExporter: new BuiltInVrm10MaterialExporter(),
|
||||
textureSerializer: new EditorTextureSerializer()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/VRM10/Tests/TestVrm10.cs.meta
Normal file
3
Assets/VRM10/Tests/TestVrm10.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4c9e0897ac194db3b7a55132871e6d75
|
||||
timeCreated: 1722265007
|
||||
Loading…
Reference in New Issue
Block a user