diff --git a/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.bin b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.bin new file mode 100644 index 0000000..b8fcbda Binary files /dev/null and b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.bin differ diff --git a/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.gltf b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.gltf new file mode 100644 index 0000000..01f14a5 --- /dev/null +++ b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado.gltf @@ -0,0 +1,149 @@ +{ + "accessors": [ + { + "bufferView": 0, + "componentType": 5126, + "count": 406, + "type": "VEC2" + }, + { + "bufferView": 1, + "componentType": 5126, + "count": 406, + "type": "VEC3" + }, + { + "bufferView": 2, + "componentType": 5126, + "count": 406, + "type": "VEC4" + }, + { + "bufferView": 3, + "componentType": 5126, + "count": 406, + "type": "VEC3", + "max": [ + 0.02128091, + 0.06284806, + 0.0138090011 + ], + "min": [ + -0.02128091, + -4.773855E-05, + -0.013809 + ] + }, + { + "bufferView": 4, + "componentType": 5123, + "count": 2046, + "type": "SCALAR" + } + ], + "asset": { + "generator": "glTF Tools for Unity", + "version": "2.0" + }, + "bufferViews": [ + { + "buffer": 0, + "byteLength": 3248 + }, + { + "buffer": 0, + "byteOffset": 3248, + "byteLength": 4872 + }, + { + "buffer": 0, + "byteOffset": 8120, + "byteLength": 6496 + }, + { + "buffer": 0, + "byteOffset": 14616, + "byteLength": 4872 + }, + { + "buffer": 0, + "byteOffset": 19488, + "byteLength": 4092 + } + ], + "buffers": [ + { + "uri": "Avocado.bin", + "byteLength": 23580 + } + ], + "images": [ + { + "uri": "Avocado_baseColor.png" + }, + { + "uri": "Avocado_roughnessMetallic.png" + }, + { + "uri": "Avocado_normal.png" + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "TEXCOORD_0": 0, + "NORMAL": 1, + "TANGENT": 2, + "POSITION": 3 + }, + "indices": 4, + "material": 0 + } + ], + "name": "Avocado" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorTexture": { + "index": 0 + }, + "metallicRoughnessTexture": { + "index": 1 + } + }, + "normalTexture": { + "index": 2 + }, + "name": "2256_Avocado_d" + } + ], + "nodes": [ + { + "mesh": 0, + "name": "Avocado" + } + ], + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "textures": [ + { + "source": 0 + }, + { + "source": 1 + }, + { + "source": 2 + } + ] +} \ No newline at end of file diff --git a/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_baseColor.png b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_baseColor.png new file mode 100644 index 0000000..6f3a8b2 Binary files /dev/null and b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_baseColor.png differ diff --git a/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_normal.png b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_normal.png new file mode 100644 index 0000000..73f90d5 Binary files /dev/null and b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_normal.png differ diff --git a/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_roughnessMetallic.png b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_roughnessMetallic.png new file mode 100644 index 0000000..b83cff9 Binary files /dev/null and b/glTF-Toolkit.UWP.Test/Assets/Avocado/Avocado_roughnessMetallic.png differ diff --git a/glTF-Toolkit.UWP.Test/UWPTest.cs b/glTF-Toolkit.UWP.Test/UWPTest.cs index bb93459..9228c4a 100644 --- a/glTF-Toolkit.UWP.Test/UWPTest.cs +++ b/glTF-Toolkit.UWP.Test/UWPTest.cs @@ -2,8 +2,10 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; +using System.IO; using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; +using Windows.ApplicationModel; using Windows.Foundation; using Windows.Security.Cryptography; using Windows.Storage; @@ -74,9 +76,76 @@ public async Task GLBConvertToWindowsMR() StorageFolder outputFolder = await CreateTemporaryOutputFolderAsync("Out_" + glbBaseName); - var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(sourceGlbFile, outputFolder, 512, TexturePacking.OcclusionRoughnessMetallic); + var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(sourceGlbFile, outputFolder, 1, TexturePacking.OcclusionRoughnessMetallic); Assert.IsTrue(converted.Name == "WaterBottle_converted.glb"); + + var basicProperties = await converted.GetBasicPropertiesAsync(); + Assert.IsTrue(basicProperties.Size > 0); + } + + [TestMethod] + public async Task GLTFConvertToWindowsMR() + { + const string gltfFileName = "Avocado.gltf"; + + // Copy all the resources to a temp folder, and save a reference to the GLTF file + var folder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Avocado")); + StorageFile copiedGltfFile = null; + + foreach (var resource in await folder.GetFilesAsync()) + { + var copied = await resource.CopyAsync(ApplicationData.Current.TemporaryFolder, resource.Name, NameCollisionOption.ReplaceExisting); + + if (resource.Name == gltfFileName) + { + copiedGltfFile = copied; + } + } + + Assert.IsNotNull(copiedGltfFile); + + // Convert the file for Windows MR and pack it. + StorageFolder outputFolder = await CreateTemporaryOutputFolderAsync("Out_" + Path.GetFileNameWithoutExtension(gltfFileName)); + + var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(copiedGltfFile, outputFolder, 1, TexturePacking.OcclusionRoughnessMetallic); + + Assert.IsTrue(converted.Name == "Avocado.glb"); + + var basicProperties = await converted.GetBasicPropertiesAsync(); + Assert.IsTrue(basicProperties.Size > 0); + } + + [TestMethod] + public async Task GLTFConvertToWindowsMRFromLocalState() + { + const string gltfFileName = "Avocado.gltf"; + + // Copy all the resources to a temp folder, and save a reference to the GLTF file + var folder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Avocado")); + StorageFile copiedGltfFile = null; + + foreach (var resource in await folder.GetFilesAsync()) + { + var copied = await resource.CopyAsync(ApplicationData.Current.LocalFolder, resource.Name, NameCollisionOption.ReplaceExisting); + + if (resource.Name == gltfFileName) + { + copiedGltfFile = copied; + } + } + + Assert.IsNotNull(copiedGltfFile); + + // Convert the file for Windows MR and pack it. + StorageFolder outputFolder = await CreateTemporaryOutputFolderAsync("Out_" + Path.GetFileNameWithoutExtension(gltfFileName)); + + var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(copiedGltfFile, outputFolder, 1, TexturePacking.OcclusionRoughnessMetallic); + + Assert.IsTrue(converted.Name == "Avocado.glb"); + + var basicProperties = await converted.GetBasicPropertiesAsync(); + Assert.IsTrue(basicProperties.Size > 0); } } } diff --git a/glTF-Toolkit.UWP.Test/glTF-Toolkit.UWP.Test.csproj b/glTF-Toolkit.UWP.Test/glTF-Toolkit.UWP.Test.csproj index 40f809f..10d83e9 100644 --- a/glTF-Toolkit.UWP.Test/glTF-Toolkit.UWP.Test.csproj +++ b/glTF-Toolkit.UWP.Test/glTF-Toolkit.UWP.Test.csproj @@ -120,6 +120,9 @@ + + + @@ -150,6 +153,10 @@ ..\Built\Out\v141\$(Platform)\$(Configuration)\glTF-Toolkit.UWP\Microsoft.glTF.Toolkit.UWP.winmd + + + + 14.0