Merge pull request #2391 from Santarh/testFix

Pass tests in URP project settings
This commit is contained in:
Masataka SUMI
2024-07-30 15:47:39 +09:00
committed by GitHub
33 changed files with 308 additions and 162 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 257f9efac603801459934018928760de
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: fc1ba24d4a4141d4d9e9ae0a0d3ecd0a
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: b5d17df8d14f2324692a7c69f24cf658
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

View File

@@ -3,7 +3,7 @@ guid: 0f7acf68f1798ae48a5505519abac457
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
@@ -24,6 +24,7 @@ TextureImporter:
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
@@ -62,6 +63,7 @@ TextureImporter:
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
@@ -99,6 +101,18 @@ TextureImporter:
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
@@ -112,6 +126,7 @@ TextureImporter:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0

View File

Before

Width:  |  Height:  |  Size: 560 B

After

Width:  |  Height:  |  Size: 560 B

View File

@@ -33,6 +33,8 @@ namespace UniGLTF
var tmp = AssetDatabase.LoadAssetAtPath<Mesh>(assetPath);
Assert.Null(tmp);
AssetDatabase.DeleteAsset(assetPath);
}
AssetDatabase.Refresh();

View File

@@ -1,13 +1,10 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public sealed class CopyTextureTests
{
private static string AssetPath = "Assets/VRMShaders/GLTF/IO/Tests";
private static readonly Color32 Black = new Color32(0, 0, 0, 255);
private static readonly Color32 Gray = new Color32(127, 127, 127, 255);
private static readonly Color32 White = new Color32(255, 255, 255, 255);
@@ -32,7 +29,7 @@ namespace UniGLTF
[Test]
public void CopyFromNonReadableSRgbPng()
{
var nonReadableTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var nonReadableTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
Assert.False(nonReadableTex.isReadable);
var copiedTex = TextureConverter.CopyTexture(nonReadableTex, ColorSpace.sRGB, true, null);
var pixels = copiedTex.GetPixels32(miplevel: 0);
@@ -46,7 +43,7 @@ namespace UniGLTF
[Test]
public void CopyFromNonReadableSRgbDds()
{
var compressedTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable_compressed.dds");
var compressedTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable_compressed.dds");
Assert.False(compressedTex.isReadable);
var copiedTex = TextureConverter.CopyTexture(compressedTex, ColorSpace.sRGB, true, null);
var pixels = copiedTex.GetPixels32(miplevel: 0);
@@ -60,7 +57,7 @@ namespace UniGLTF
[Test]
public void CopyAttributes()
{
var src = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var src = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
var dst = TextureConverter.CopyTexture(src, ColorSpace.sRGB, false, null);
Assert.AreEqual(src.name, dst.name);
Assert.AreEqual(src.anisoLevel, dst.anisoLevel);

View File

@@ -1,18 +1,16 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public sealed class EditorTextureSerializerTests
{
private static readonly string AssetPath = "Assets/UniGLTF/Tests/UniGLTF";
private static readonly string SrgbGrayImageName = "4x4_gray_import_as_srgb";
private static readonly string LinearGrayImageName = "4x4_gray_import_as_linear";
private static readonly string NormalMapGrayImageName = "4x4_gray_import_as_normal_map";
private static readonly Texture2D SrgbGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{SrgbGrayImageName}.png");
private static readonly Texture2D LinearGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{LinearGrayImageName}.png");
private static readonly Texture2D NormalMapGrayTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/{NormalMapGrayImageName}.png");
private static readonly Texture2D SrgbGrayTex = TestAssets.LoadAsset<Texture2D>($"{SrgbGrayImageName}.png");
private static readonly Texture2D LinearGrayTex = TestAssets.LoadAsset<Texture2D>($"{LinearGrayImageName}.png");
private static readonly Texture2D NormalMapGrayTex = TestAssets.LoadAsset<Texture2D>($"{NormalMapGrayImageName}.png");
private static readonly Color32 JustGray = new Color32(127, 127, 127, 255);
private static readonly Color32 SrgbGrayInSrgb = JustGray;
private static readonly Color32 SrgbGrayInLinear = ((Color)SrgbGrayInSrgb).linear;
@@ -113,23 +111,28 @@ namespace UniGLTF
{
// Prepare
var root = GameObject.CreatePrimitive(PrimitiveType.Cube);
var mat = new Material(Shader.Find("Standard"));
var mat = new Material(Shader.Find(BuiltInStandardMaterialExporter.TargetShaderName));
mat.SetTexture(propertyName, srcTex);
root.GetComponentOrThrow<MeshRenderer>().sharedMaterial = mat;
// Export glTF
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, new GltfExportSettings
{
InverseAxis = Axes.X,
ExportOnlyBlendShapePosition = false,
UseSparseAccessorForMorphTarget = false,
DivideVertexBuffer = false,
}, textureSerializer: new EditorTextureSerializer()))
{
exporter.Prepare(root);
exporter.Export();
}
using var exporter = new gltfExporter(
data,
new GltfExportSettings
{
InverseAxis = Axes.X,
ExportOnlyBlendShapePosition = false,
UseSparseAccessorForMorphTarget = false,
DivideVertexBuffer = false,
},
materialExporter: new BuiltInGltfMaterialExporter(),
textureSerializer: new EditorTextureSerializer()
);
exporter.Prepare(root);
exporter.Export();
var gltf = data.Gltf;
Assert.AreEqual(1, gltf.images.Count);
var exportedImage = gltf.images[0];

View File

@@ -0,0 +1,12 @@
namespace UniGLTF
{
public static class TestAssets
{
public static readonly string AssetPath = "Assets/UniGLTF/Tests/Objects";
public static T LoadAsset<T>(string filename) where T : UnityEngine.Object
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<T>($"{AssetPath}/{filename}");
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8519ebb2f0f84833a752bb564b59c47c
timeCreated: 1722263712

View File

@@ -0,0 +1,52 @@
using UnityEngine;
namespace UniGLTF
{
public static class TestGltf
{
public static RuntimeGltfInstance LoadBytesAsBuiltInRP(byte[] bytes)
{
return GltfUtility.LoadBytesAsync(
"",
bytes,
awaitCaller: new ImmediateCaller(),
materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()
).Result;
}
public static RuntimeGltfInstance LoadPathAsBuiltInRP(string path)
{
return GltfUtility.LoadAsync(
path,
awaitCaller: new ImmediateCaller(),
materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()
).Result;
}
public static ExportingGltfData ExportAsBuiltInRP(GameObject gameObject, GltfExportSettings exportSettings = null)
{
var data = new ExportingGltfData();
using var exporter = new gltfExporter(
data,
exportSettings ?? new GltfExportSettings(),
progress: new EditorProgress(),
animationExporter: new EditorAnimationExporter(),
materialExporter: new BuiltInGltfMaterialExporter(),
textureSerializer: new EditorTextureSerializer()
);
exporter.Prepare(gameObject);
exporter.Export();
return data;
}
public static GameObject CreatePrimitiveAsBuiltInRP(PrimitiveType primitiveType)
{
var go = GameObject.CreatePrimitive(primitiveType);
var shader = Shader.Find("Standard");
var material = new Material(shader);
go.GetComponent<Renderer>().sharedMaterial = material;
return go;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 11719ab072944cc2b7c0eaafa0cdff2e
timeCreated: 1722267047

View File

@@ -1,17 +1,14 @@
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace UniGLTF
{
public class TextureBytesTests
{
static string AssetPath = "Assets/VRMShaders/GLTF/IO/Tests";
[Test]
public void NonReadablePng()
{
var nonReadableTex = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable.png");
var nonReadableTex = TestAssets.LoadAsset<Texture2D>("4x4_non_readable.png");
Assert.False(nonReadableTex.isReadable);
var (bytes, mime) = new EditorTextureSerializer().ExportBytesWithMime(nonReadableTex, ColorSpace.sRGB);
Assert.NotNull(bytes);
@@ -20,7 +17,7 @@ namespace UniGLTF
[Test]
public void NonReadableDds()
{
var readonlyTexture = AssetDatabase.LoadAssetAtPath<Texture2D>($"{AssetPath}/4x4_non_readable_compressed.dds");
var readonlyTexture = TestAssets.LoadAsset<Texture2D>("4x4_non_readable_compressed.dds");
Assert.False(readonlyTexture.isReadable);
var (bytes, mime) = new EditorTextureSerializer().ExportBytesWithMime(readonlyTexture, ColorSpace.sRGB);
Assert.NotNull(bytes);

View File

@@ -100,18 +100,17 @@ namespace UniGLTF
// export
var data = new ExportingGltfData();
using var exporter = new gltfExporter(
data,
new GltfExportSettings(),
materialExporter: new BuiltInGltfMaterialExporter());
exporter.Prepare(go);
exporter.Export();
string json = null;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export();
// remove empty buffer
data.Gltf.buffers.Clear();
// remove empty buffer
data.Gltf.buffers.Clear();
json = data.Gltf.ToJson();
}
var json = data.Gltf.ToJson();
// parse
using (var parsed = GltfData.CreateFromExportForTest(data))
@@ -353,12 +352,7 @@ namespace UniGLTF
[Test]
public void GlTFToJsonTest()
{
var data = new ExportingGltfData();
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(CreateSimpleScene());
exporter.Export();
}
var data = TestGltf.ExportAsBuiltInRP(CreateSimpleScene());
var expected = data.Gltf.ToJson().ParseAsJson();
expected.AddKey(Utf8String.From("meshes"));
@@ -565,7 +559,7 @@ namespace UniGLTF
{
var shader = Shader.Find("Unlit/Color");
var cubeA = GameObject.CreatePrimitive(PrimitiveType.Cube);
var cubeA = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
{
cubeA.transform.SetParent(go.transform);
var material = new Material(shader);
@@ -586,16 +580,8 @@ namespace UniGLTF
}
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(go);
var gltf = data.Gltf;
var json = default(string);
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export();
json = gltf.ToJson();
}
Assert.AreEqual(2, gltf.meshes.Count);
@@ -658,22 +644,14 @@ namespace UniGLTF
try
{
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
var cube = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
cube.transform.SetParent(go.transform);
UnityEngine.Object.DestroyImmediate(cube.GetComponent<MeshRenderer>());
}
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(go);
var gltf = data.Gltf;
string json;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(go);
exporter.Export();
json = gltf.ToJson();
}
Assert.AreEqual(0, gltf.meshes.Count);
Assert.AreEqual(1, gltf.nodes.Count);
@@ -682,7 +660,7 @@ namespace UniGLTF
// import
using (var parsed = GltfData.CreateFromExportForTest(data))
{
using (var context = new ImporterContext(parsed))
using (var context = new ImporterContext(parsed, materialGenerator: new BuiltInGltfMaterialDescriptorGenerator()))
using (var loaded = context.Load())
{
Assert.AreEqual(1, loaded.transform.GetChildren().Count());
@@ -708,14 +686,14 @@ namespace UniGLTF
try
{
{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
var child = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// remove MeshFilter
Component.DestroyImmediate(child.GetComponent<MeshFilter>());
}
{
var child = GameObject.CreatePrimitive(PrimitiveType.Cube);
var child = TestGltf.CreatePrimitiveAsBuiltInRP(PrimitiveType.Cube);
child.transform.SetParent(root.transform);
// set null
child.GetComponent<MeshFilter>().sharedMesh = null;
@@ -727,16 +705,9 @@ namespace UniGLTF
Assert.True(vs.All(x => x.CanExport));
// export
var data = new ExportingGltfData();
var data = TestGltf.ExportAsBuiltInRP(root);
var gltf = data.Gltf;
string json;
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
{
exporter.Prepare(root);
exporter.Export();
json = gltf.ToJson();
}
var json = gltf.ToJson();
Assert.AreEqual(0, gltf.meshes.Count);
Assert.AreEqual(2, gltf.nodes.Count);

View File

@@ -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);

View File

@@ -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(" ");

View 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());
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 47b1209d83114ccbaa0bf02436b8eb04
timeCreated: 1722265572

View File

@@ -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>();

View File

@@ -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);

View File

@@ -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");
}
}
}

View File

@@ -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)

View File

@@ -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>();
}
}

View 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()
);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4c9e0897ac194db3b7a55132871e6d75
timeCreated: 1722265007