From f5cd805711f76596a77a71de9cba4717e0edd159 Mon Sep 17 00:00:00 2001 From: vpenades <5433822+vpenades@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:24:12 +0200 Subject: [PATCH] Khronos group has archived glTF-Sample-Models and replaced it by the new glTF-Sample-Assets --- .../Authoring/ExtensionsCreationTests.cs | 8 +- .../Schema2/LoadAndSave/LoadSampleTests.cs | 3 +- .../ExampleFiles.cs | 4 +- tests/SharpGLTF.NUnit/TestFiles.cs | 138 ++++++++++-------- .../Scenes/SceneBuilderTests.cs | 10 +- 5 files changed, 92 insertions(+), 71 deletions(-) diff --git a/tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs b/tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs index 104b8ae6..f167c2a5 100644 --- a/tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs +++ b/tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs @@ -47,7 +47,7 @@ public void CreateSceneWithSpecularGlossinessExtension() { TestContext.CurrentContext.AttachGltfValidatorLinks(); - var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF"); + var basePath = TestFiles.GetKhronosAssetDir( "SpecGlossVsMetalRough", "glTF"); // first, create a default material var material = new Materials.MaterialBuilder("material1") @@ -88,7 +88,7 @@ public void CreateSceneWithClearCoatExtension() { TestContext.CurrentContext.AttachGltfValidatorLinks(); - var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF"); + var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF"); // first, create a default material var material = new Materials.MaterialBuilder("material") @@ -127,7 +127,7 @@ public void CreateSceneWithTransmissionExtension() { TestContext.CurrentContext.AttachGltfValidatorLinks(); - var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF"); + var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF"); var material = new Materials.MaterialBuilder("material") .WithMetallicRoughnessShader() @@ -163,7 +163,7 @@ public void CreateSceneWithsSheenExtension() { TestContext.CurrentContext.AttachGltfValidatorLinks(); - var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF"); + var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF"); var material = new Materials.MaterialBuilder("material") .WithMetallicRoughnessShader() diff --git a/tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs b/tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs index 4a535346..3a123d55 100644 --- a/tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs +++ b/tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs @@ -267,8 +267,7 @@ public void LoadModelWithMorphTargets() [TestCase("RiggedFigure.glb")] [TestCase("RiggedSimple.glb")] [TestCase("BoxAnimated.glb")] - [TestCase("AnimatedMorphCube.glb")] - [TestCase("AnimatedMorphSphere.glb")] + [TestCase("AnimatedMorphCube.glb")] [TestCase("CesiumMan.glb")] //[TestCase("Monster.glb")] // temporarily removed from khronos repo [TestCase("BrainStem.glb")] diff --git a/tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs b/tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs index 58fc096b..1a09adbd 100644 --- a/tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs +++ b/tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs @@ -18,7 +18,7 @@ public ExampleFiles(string workingDirectory) _KhronosSchemaDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Schema"); _KhronosValidatorDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Validator"); - _KhronosSampleModelsDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Sample-Models"); + _KhronosSampleModelsDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Sample-Assets"); _BabylonJsMeshesDir = System.IO.Path.Combine(_WorkingDirectory, "BabylonJS-Assets"); _BabylonJsPlaygroundDir = System.IO.Path.Combine(_WorkingDirectory, "BabylonJS-PlaygroundScenes"); @@ -41,7 +41,7 @@ public void DownloadReferenceModels() DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF.git", _KhronosSchemaDir); DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Validator.git", _KhronosValidatorDir); - DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Models.git", _KhronosSampleModelsDir); + DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Assets.git", _KhronosSampleModelsDir); DownloadUtils.SyncronizeGitRepository("https://github.com/BabylonJS/Assets.git", _BabylonJsMeshesDir); // DownloadUtils.SyncronizeGitRepository("https://github.com/BabylonJS/MeshesLibrary.git", _BabylonJsMeshesDir); diff --git a/tests/SharpGLTF.NUnit/TestFiles.cs b/tests/SharpGLTF.NUnit/TestFiles.cs index c173f69a..dee76b4f 100644 --- a/tests/SharpGLTF.NUnit/TestFiles.cs +++ b/tests/SharpGLTF.NUnit/TestFiles.cs @@ -14,100 +14,119 @@ public static class TestFiles { #region lifecycle - private static void _EnsureInitialized() + private static System.IO.DirectoryInfo _DefDir(this System.IO.DirectoryInfo defDir, params string[] path) { - if (_TestFilesDir != null) return; + var finalPath = System.IO.Path.Combine(defDir.FullName, System.IO.Path.Combine(path)); + return new System.IO.DirectoryInfo(finalPath); + } - var wdir = TestContext.CurrentContext.WorkDirectory; + private static System.IO.FileInfo _DefFile(this System.IO.DirectoryInfo defDir, params string[] path) + { + var finalPath = System.IO.Path.Combine(defDir.FullName, System.IO.Path.Combine(path)); + return new System.IO.FileInfo(finalPath); + } + private static System.IO.DirectoryInfo _FindRepositoryRootDirectory() + { var examplesFound = false; - while (wdir.Length > 3) - { - _TestFilesDir = System.IO.Path.Combine(wdir, "TestFiles"); + var wdir = new System.IO.DirectoryInfo(TestContext.CurrentContext.TestDirectory); - if (wdir.ToUpperInvariant().EndsWith("TESTS") && System.IO.Directory.Exists(_TestFilesDir)) - { - examplesFound = true; - break; - } + while (wdir.FullName.Length > 3) + { + if (wdir._DefDir(".git").Exists) return wdir; - wdir = System.IO.Path.GetDirectoryName(wdir); + wdir = wdir.Parent; } - Assert.That(examplesFound, "TestFiles directory not found; please, run '1_DownloadTestFiles.cmd' before running the tests."); + Assert.That(examplesFound, "repository root directory not found."); - _AssetFilesDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(_TestFilesDir), "Assets"); + return wdir; } - private static string _UsingExternalFiles(params string[] subPath) + private static System.IO.DirectoryInfo _UsingExternalFiles(params string[] subPath) { - _EnsureInitialized(); + var r = _TestFilesDir1._DefDir(subPath); + if (r.Exists) return r; + r = _TestFilesDir2._DefDir(subPath); + if (r.Exists) return r; - return System.IO.Path.Combine(new string[] { _TestFilesDir }.Concat(subPath).ToArray()); + throw new System.IO.DirectoryNotFoundException(string.Join("/", subPath)); } - private static string _UsingInternalFiles(params string[] subPath) + private static System.IO.DirectoryInfo _UsingInternalFiles(params string[] subPath) { - _EnsureInitialized(); - - return System.IO.Path.Combine(new string[] { _AssetFilesDir }.Concat(subPath).ToArray()); + return _AssetFilesDir._DefDir(subPath); } #endregion #region data + private static Lazy _RepoRootDir = new Lazy(_FindRepositoryRootDirectory); + /// /// Path to Tests/Assets/ /// - private static string _AssetFilesDir; + private static System.IO.DirectoryInfo _AssetFilesDir => _RepoRootDir.Value._DefDir("tests", "Assets"); /// /// Path to Tests/TestFiles/ /// - private static string _TestFilesDir; + private static System.IO.DirectoryInfo _TestFilesDir1 => _RepoRootDir.Value._DefDir("tests", "TestFiles"); + + /// + /// Path to ..\..\SharpGLTF-TestFiles/ + /// + private static System.IO.DirectoryInfo _TestFilesDir2 => _RepoRootDir.Value._DefDir("..", "SharpGLTF-TestFiles"); - private static readonly string _SchemaDir = _UsingExternalFiles("glTF-Schema"); - private static readonly string _ValidationDir = _UsingExternalFiles("glTF-Validator"); - internal static readonly string _SampleModelsDir = _UsingExternalFiles("glTF-Sample-Models"); + + private static readonly System.IO.DirectoryInfo _SchemaDir = _UsingExternalFiles("glTF-Schema"); + private static readonly System.IO.DirectoryInfo _ValidationDir = _UsingExternalFiles("glTF-Validator"); + + internal static readonly System.IO.DirectoryInfo _KhronosSampleAssetsDir = _UsingExternalFiles("glTF-Sample-Assets"); - private static readonly string _BabylonJsMeshesDir = _UsingExternalFiles("BabylonJS-Assets"); - private static readonly string _GeneratedModelsDir = _UsingExternalFiles("GeneratedReferenceModels", "v_0_6_1"); + private static readonly System.IO.DirectoryInfo _BabylonJsMeshesDir = _UsingExternalFiles("BabylonJS-Assets"); + private static readonly System.IO.DirectoryInfo _GeneratedModelsDir = _UsingExternalFiles("GeneratedReferenceModels", "v_0_6_1"); #endregion #region properties - public static string KhronosSampleModelsDirectory => _SampleModelsDir; + internal static System.IO.DirectoryInfo KhronosSampleModelsDirectory => _KhronosSampleAssetsDir; #endregion #region API - + public static string GetKhronosAssetDir(params string[] path) + { + return _KhronosSampleAssetsDir._DefDir("Models")._DefDir(path).FullName; + } public static IReadOnlyList GetSchemaExtensionsModelsPaths() { - return GetModelPathsInDirectory(_SchemaDir, "extensions", "2.0"); + return _FindModelInDirectory(_SchemaDir._DefDir("extensions", "2.0")); } public static IEnumerable GetReferenceModelPaths(bool useNegative = false) { var dirPath = _GeneratedModelsDir; - if (dirPath.EndsWith(".zip")) dirPath = dirPath.Substring(0, dirPath.Length - 4); + if (dirPath.FullName.EndsWith(".zip")) + { + var p= dirPath.FullName.Substring(0, dirPath.FullName.Length - 4); + dirPath = new System.IO.DirectoryInfo(p); + } - var manifestsPath = System.IO.Path.Combine(dirPath, useNegative? "Negative" : "Positive"); + var manifestsPath = dirPath._DefDir(useNegative? "Negative" : "Positive"); - var manifests = System.IO.Directory.GetFiles(manifestsPath, "Manifest.json", System.IO.SearchOption.AllDirectories) + var manifests = manifestsPath.GetFiles("Manifest.json", System.IO.SearchOption.AllDirectories) .Skip(1) .ToArray(); foreach (var m in manifests) { - var d = System.IO.Path.GetDirectoryName(m); - - var content = System.IO.File.ReadAllText(m); + var content = System.IO.File.ReadAllText(m.FullName); var doc = Newtonsoft.Json.Linq.JObject.Parse(content); var models = doc.SelectToken("models"); @@ -118,11 +137,9 @@ public static IEnumerable GetReferenceModelPaths(bool useNegative = fals var loadable = !useNegative; - if (loadable) loadable = (Boolean)model.SelectToken("loadable"); - - mdlPath = System.IO.Path.Combine(d, mdlPath); + if (loadable) loadable = (Boolean)model.SelectToken("loadable"); - yield return mdlPath; + yield return m.Directory._DefFile(mdlPath).FullName; } } @@ -131,10 +148,10 @@ public static IEnumerable GetReferenceModelPaths(bool useNegative = fals public static IReadOnlyList GetSampleModelsPaths() { - var entries = KhronosSampleModel.Load(); + var entries = KhronosSampleModel.Load(_KhronosSampleAssetsDir._DefFile("Models", "model-index.json")); var files = entries - .SelectMany(item => item.GetPaths(_SampleModelsDir, "2.0")) + .SelectMany(item => item.GetPaths()) .ToList(); return files; @@ -175,7 +192,7 @@ public static IReadOnlyList GetKhronosValidationPaths() "invalid_image_mime_type.gltf", // actual images cannot be validated }; - var files = GetModelPathsInDirectory(_ValidationDir, "test") + var files = _FindModelInDirectory(_ValidationDir._DefDir("test")) .Where(item => skip.All(f=>!item.EndsWith(f))); return files @@ -197,7 +214,7 @@ public static IReadOnlyList GetBabylonJSModelsPaths() "\\meshes\\Tests\\BadDraco\\Box-draco.glb", // uses KHR_Draco compression }; - var files = GetModelPathsInDirectory(_BabylonJsMeshesDir); + var files = _FindModelInDirectory(_BabylonJsMeshesDir); return files .Where(item => !item.ToUpperInvariant().Contains("GLTF-DRACO")) @@ -209,12 +226,12 @@ public static IReadOnlyList GetBabylonJSModelsPaths() public static string GetPollyFileModelPath() { - return _UsingExternalFiles("glTF-Blender-Exporter", "polly", "project_polly.glb"); + return _UsingExternalFiles("glTF-Blender-Exporter", "polly")._DefFile("project_polly.glb").FullName; } public static string GetUniVRMModelPath() { - return _UsingExternalFiles("UniVRM", "AliciaSolid_vrm-0.51.vrm"); + return _UsingExternalFiles("UniVRM")._DefFile("AliciaSolid_vrm-0.51.vrm").FullName; } public static IEnumerable GetMeshIntancingModelPaths() @@ -224,14 +241,16 @@ public static IEnumerable GetMeshIntancingModelPaths() var meshInstPath = _UsingInternalFiles("gltf-GpuMeshInstancing"); - var fromLocal = System.IO.Directory.GetFiles(meshInstPath, "*.glb", System.IO.SearchOption.AllDirectories); + var fromLocal = meshInstPath + .GetFiles("*.glb", System.IO.SearchOption.AllDirectories) + .Select(item => item.FullName); return fromBabylon.Concat(fromLocal); } - private static IReadOnlyList GetModelPathsInDirectory(params string[] paths) + private static IReadOnlyList _FindModelInDirectory(System.IO.DirectoryInfo dinfo) { - var dirPath = System.IO.Path.Combine(paths); + var dirPath = dinfo.FullName; if (dirPath.EndsWith(".zip")) dirPath = dirPath.Substring(0, dirPath.Length-4); @@ -252,11 +271,14 @@ class KhronosSampleModel { #region loaders - public static KhronosSampleModel[] Load() - { - var path = System.IO.Path.Combine(TestFiles._SampleModelsDir, "2.0", "model-index.json"); - var text = System.IO.File.ReadAllText(path); - return Read(text); + public static KhronosSampleModel[] Load(System.IO.FileInfo finfo) + { + var text = System.IO.File.ReadAllText(finfo.FullName); + var result = Read(text); + + foreach (var item in result) { item._BaseDirectory = finfo.Directory; } + + return result; } public static KhronosSampleModel[] Read(string json) @@ -274,6 +296,8 @@ public static KhronosSampleModel[] Read(string json) #region data + private System.IO.DirectoryInfo _BaseDirectory; + public string Name { get; set; } public string Screenshot { get; set; } public Dictionary Variants { get; set; } = new Dictionary(); @@ -282,9 +306,9 @@ public static KhronosSampleModel[] Read(string json) #region API - public IEnumerable GetPaths(params string[] basePath) + public IEnumerable GetPaths() { - var rootPath = System.IO.Path.Combine(basePath); + var rootPath = _BaseDirectory.FullName; foreach(var variant in Variants) { diff --git a/tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs b/tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs index a6e3cbd9..b5e3fee8 100644 --- a/tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs +++ b/tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs @@ -572,13 +572,11 @@ public void CreateSharedNodeInstanceScene() } - [TestCase("AnimatedMorphCube.glb")] - [TestCase("AnimatedMorphSphere.glb")] + [TestCase("AnimatedMorphCube.glb")] [TestCase("Avocado.glb")] [TestCase("BoxAnimated.glb")] [TestCase("BrainStem.glb")] - [TestCase("CesiumMan.glb")] - [TestCase("GearboxAssy.glb")] + [TestCase("CesiumMan.glb")] [TestCase("OrientationTest.glb")] [TestCase("RiggedFigure.glb")] [TestCase("RiggedSimple.glb")] @@ -651,7 +649,7 @@ public void TestRoundTrip(string path) } - [TestCase("GearboxAssy.glb")] + [TestCase("Avocado.glb")] public void ExportMeshes(string path) { TestContext.CurrentContext.AttachGltfValidatorLinks(); @@ -664,7 +662,7 @@ public void ExportMeshes(string path) var srcModel = ModelRoot.Load(path, Validation.ValidationMode.TryFix); Assert.That(srcModel, Is.Not.Null); - srcModel.AttachToCurrentTest("GearBoxAssy.plotly"); + srcModel.AttachToCurrentTest("Avocado.plotly"); // convert it to a SceneBuilder so we can manipulate it: var srcScene = srcModel.DefaultScene.ToSceneBuilder();