mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-21 18:15:39 -05:00
Fix VRM0X Tests
This commit is contained in:
@@ -16,12 +16,17 @@ namespace VRM
|
||||
/// </summary>
|
||||
/// <param name="path">出力先</param>
|
||||
/// <param name="settings">エクスポート設定</param>
|
||||
public static byte[] Export(GameObject exportRoot, VRMMetaObject meta, VRMExportSettings settings)
|
||||
public static byte[] Export(
|
||||
GameObject exportRoot,
|
||||
VRMMetaObject meta,
|
||||
VRMExportSettings settings,
|
||||
IMaterialExporter materialExporter = null
|
||||
)
|
||||
{
|
||||
List<GameObject> destroy = new List<GameObject>();
|
||||
try
|
||||
{
|
||||
return Export(exportRoot, meta, settings, destroy);
|
||||
return Export(exportRoot, meta, settings, materialExporter, destroy);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -143,9 +148,12 @@ namespace VRM
|
||||
/// <param name="path"></param>
|
||||
/// <param name="settings"></param>
|
||||
/// <param name="destroy">作業が終わったらDestoryするべき一時オブジェクト</param>
|
||||
static byte[] Export(GameObject exportRoot, VRMMetaObject meta,
|
||||
VRMExportSettings settings,
|
||||
List<GameObject> destroy)
|
||||
private static byte[] Export(
|
||||
GameObject exportRoot,
|
||||
VRMMetaObject meta,
|
||||
VRMExportSettings settings,
|
||||
IMaterialExporter materialExporter,
|
||||
List<GameObject> destroy)
|
||||
{
|
||||
var target = exportRoot;
|
||||
|
||||
@@ -227,6 +235,7 @@ namespace VRM
|
||||
var gltfExportSettings = settings.GltfExportSettings;
|
||||
using (var exporter = new VRMExporter(data, gltfExportSettings,
|
||||
animationExporter: settings.KeepAnimation ? new EditorAnimationExporter() : null,
|
||||
materialExporter: materialExporter,
|
||||
textureSerializer: new EditorTextureSerializer()))
|
||||
{
|
||||
exporter.Prepare(target);
|
||||
|
||||
@@ -33,9 +33,11 @@ namespace VRM.Samples
|
||||
public void ImportExportTest()
|
||||
{
|
||||
var path = AliciaPath;
|
||||
using (var data = new GlbFileParser(path).Parse())
|
||||
using (var context = new VRMImporterContext(new VRMData(data)))
|
||||
using (var loaded = context.Load())
|
||||
using var data = new GlbFileParser(path).Parse();
|
||||
var vrmData = new VRMData(data);
|
||||
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
|
||||
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
|
||||
using var loaded = context.Load();
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
@@ -126,9 +128,11 @@ namespace VRM.Samples
|
||||
public void MeshCopyTest()
|
||||
{
|
||||
var path = AliciaPath;
|
||||
using (var data = new GlbFileParser(path).Parse())
|
||||
using (var context = new VRMImporterContext(new VRMData(data)))
|
||||
using (var loaded = context.Load())
|
||||
using var data = new GlbFileParser(path).Parse();
|
||||
var vrmData = new VRMData(data);
|
||||
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
|
||||
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
|
||||
using var loaded = context.Load();
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
loaded.EnableUpdateWhenOffscreen();
|
||||
@@ -147,8 +151,10 @@ namespace VRM.Samples
|
||||
// Aliciaを古いデシリアライザでロードする
|
||||
var path = AliciaPath;
|
||||
|
||||
using (var data = new GlbFileParser(path).Parse())
|
||||
using (var context = new VRMImporterContext(new VRMData(data)))
|
||||
using var data = new GlbFileParser(path).Parse();
|
||||
var vrmData = new VRMData(data);
|
||||
var materialGenerator = new BuiltInVrmMaterialDescriptorGenerator(vrmData.VrmExtension);
|
||||
using var context = new VRMImporterContext(vrmData, materialGenerator: materialGenerator);
|
||||
{
|
||||
var oldJson = context.GLTF.ToJson().ParseAsJson().ToString(" ");
|
||||
|
||||
|
||||
32
Assets/VRM/Tests/TestVrm0X.cs
Normal file
32
Assets/VRM/Tests/TestVrm0X.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UniGLTF;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
public static class TestVrm0X
|
||||
{
|
||||
public static RuntimeGltfInstance LoadBytesAsBuiltInRP(byte[] bytes)
|
||||
{
|
||||
return VrmUtility.LoadBytesAsync(
|
||||
"",
|
||||
bytes,
|
||||
awaitCaller: new ImmediateCaller(),
|
||||
materialGeneratorCallback: x => new BuiltInVrmMaterialDescriptorGenerator(x)
|
||||
).Result;
|
||||
}
|
||||
|
||||
public static RuntimeGltfInstance LoadPathAsBuiltInRP(string path)
|
||||
{
|
||||
return VrmUtility.LoadAsync(
|
||||
path,
|
||||
awaitCaller: new ImmediateCaller(),
|
||||
materialGeneratorCallback: x => new BuiltInVrmMaterialDescriptorGenerator(x)
|
||||
).Result;
|
||||
}
|
||||
|
||||
public static byte[] ExportAsBuiltInRP(GameObject gameObject, VRMExportSettings exportSettings)
|
||||
{
|
||||
return VRMEditorExporter.Export(gameObject, null, exportSettings, new BuiltInVrmMaterialExporter());
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/VRM/Tests/TestVrm0X.cs.meta
Normal file
3
Assets/VRM/Tests/TestVrm0X.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47b1209d83114ccbaa0bf02436b8eb04
|
||||
timeCreated: 1722265572
|
||||
@@ -21,11 +21,8 @@ namespace VRM
|
||||
[Test]
|
||||
public void VRMLookAtTest()
|
||||
{
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
using (data)
|
||||
using (var loader = new VRMImporterContext(new VRMData(data)))
|
||||
using (var loaded = loader.Load())
|
||||
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
|
||||
{
|
||||
loaded.ShowMeshes();
|
||||
|
||||
@@ -35,12 +32,12 @@ namespace VRM
|
||||
var lookAt = go.AddComponent<VRMLookAtBlendShapeApplyer>();
|
||||
var settings = (VRMExportSettings)ScriptableObject.CreateInstance<VRMExportSettings>();
|
||||
settings.PoseFreeze = true;
|
||||
bytes = VRMEditorExporter.Export(go, null, settings);
|
||||
}
|
||||
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
|
||||
}
|
||||
|
||||
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
|
||||
using (var loader2 = new VRMImporterContext(new VRMData(data2)))
|
||||
{
|
||||
using var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse();
|
||||
using var loader2 = new VRMImporterContext(new VRMData(data2));
|
||||
Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType);
|
||||
}
|
||||
}
|
||||
@@ -48,13 +45,10 @@ namespace VRM
|
||||
[Test]
|
||||
public void VRMLookAtCurveMapWithFreezeTest()
|
||||
{
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
byte[] bytes;
|
||||
CurveMapper horizontalInner = default;
|
||||
using (data)
|
||||
using (var loader = new VRMImporterContext(new VRMData(data)))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
|
||||
loaded.ShowMeshes();
|
||||
|
||||
var go = loaded.gameObject;
|
||||
@@ -63,13 +57,11 @@ namespace VRM
|
||||
horizontalInner = lookAt.HorizontalInner;
|
||||
var settings = ScriptableObject.CreateInstance<VRMExportSettings>();
|
||||
settings.PoseFreeze = true;
|
||||
bytes = VRMEditorExporter.Export(go, null, settings);
|
||||
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
|
||||
}
|
||||
|
||||
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
|
||||
using (var loader = new VRMImporterContext(new VRMData(data2)))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
using var loaded = TestVrm0X.LoadBytesAsBuiltInRP(bytes);
|
||||
loaded.ShowMeshes();
|
||||
|
||||
var lookAt = loaded.GetComponent<VRMLookAtBoneApplyer>();
|
||||
@@ -81,13 +73,10 @@ namespace VRM
|
||||
[Test]
|
||||
public void VRMLookAtCurveMapTest()
|
||||
{
|
||||
var data = new GlbFileParser(AliciaPath).Parse();
|
||||
byte[] bytes = default;
|
||||
byte[] bytes;
|
||||
CurveMapper horizontalInner = default;
|
||||
using (data)
|
||||
using (var loader = new VRMImporterContext(new VRMData(data)))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
using var loaded = TestVrm0X.LoadPathAsBuiltInRP(AliciaPath);
|
||||
loaded.ShowMeshes();
|
||||
|
||||
var go = loaded.gameObject;
|
||||
@@ -96,13 +85,11 @@ namespace VRM
|
||||
horizontalInner = lookAt.HorizontalInner;
|
||||
var settings = (VRMExportSettings)ScriptableObject.CreateInstance<VRMExportSettings>();
|
||||
settings.PoseFreeze = false;
|
||||
bytes = VRMEditorExporter.Export(go, null, settings);
|
||||
bytes = TestVrm0X.ExportAsBuiltInRP(go, settings);
|
||||
}
|
||||
|
||||
using (var data2 = new GlbLowLevelParser(AliciaPath, bytes).Parse())
|
||||
using (var loader = new VRMImporterContext(new VRMData(data2)))
|
||||
using (var loaded = loader.Load())
|
||||
{
|
||||
using var loaded = TestVrm0X.LoadBytesAsBuiltInRP(bytes);
|
||||
loaded.ShowMeshes();
|
||||
|
||||
var lookAt = loaded.GetComponent<VRMLookAtBoneApplyer>();
|
||||
|
||||
@@ -67,13 +67,21 @@ namespace VRM
|
||||
var path = AliciaPath;
|
||||
var loaded = Load(File.ReadAllBytes(path), path);
|
||||
|
||||
var exported = VRMExporter.Export(new UniGLTF.GltfExportSettings
|
||||
var exportSettings = new GltfExportSettings
|
||||
{
|
||||
DivideVertexBuffer = true, // test this
|
||||
ExportOnlyBlendShapePosition = true,
|
||||
ExportTangents = false,
|
||||
UseSparseAccessorForMorphTarget = true,
|
||||
}, loaded, new EditorTextureSerializer());
|
||||
};
|
||||
var exported = new ExportingGltfData();
|
||||
using var exporter = new VRMExporter(
|
||||
exported,
|
||||
exportSettings,
|
||||
textureSerializer: new EditorTextureSerializer(),
|
||||
materialExporter: new BuiltInVrmMaterialExporter());
|
||||
exporter.Prepare(loaded);
|
||||
exporter.Export();
|
||||
var bytes = exported.ToGlbBytes();
|
||||
var divided = Load(bytes, path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user