Browse Source

Khronos group has archived glTF-Sample-Models and replaced it by the new glTF-Sample-Assets

vpenades 1 year ago
parent
commit
f5cd805711

+ 4 - 4
tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs

@@ -47,7 +47,7 @@ namespace SharpGLTF.Schema2.Authoring
         {            
             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 @@ namespace SharpGLTF.Schema2.Authoring
         {            
             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 @@ namespace SharpGLTF.Schema2.Authoring
         {            
             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 @@ namespace SharpGLTF.Schema2.Authoring
         {            
             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()

+ 1 - 2
tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs

@@ -267,8 +267,7 @@ namespace SharpGLTF.Schema2.LoadAndSave
         [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")]

+ 2 - 2
tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs

@@ -18,7 +18,7 @@ namespace SharpGLTF
 
             _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 @@ namespace SharpGLTF
 
             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);

+ 81 - 57
tests/SharpGLTF.NUnit/TestFiles.cs

@@ -14,100 +14,119 @@ namespace SharpGLTF
     {
         #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<System.IO.DirectoryInfo> _RepoRootDir = new Lazy<System.IO.DirectoryInfo>(_FindRepositoryRootDirectory);
+
         /// <summary>
         /// Path to Tests/Assets/
         /// </summary>
-        private static string _AssetFilesDir;
+        private static System.IO.DirectoryInfo _AssetFilesDir => _RepoRootDir.Value._DefDir("tests", "Assets");
 
         /// <summary>
         /// Path to Tests/TestFiles/
         /// </summary>
-        private static string _TestFilesDir;
+        private static System.IO.DirectoryInfo _TestFilesDir1 => _RepoRootDir.Value._DefDir("tests", "TestFiles");
+
+        /// <summary>
+        /// Path to ..\..\SharpGLTF-TestFiles/
+        /// </summary>
+        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<string> GetSchemaExtensionsModelsPaths()
         {
-            return GetModelPathsInDirectory(_SchemaDir, "extensions", "2.0");         
+            return _FindModelInDirectory(_SchemaDir._DefDir("extensions", "2.0"));         
         }
 
         public static IEnumerable<string> 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 @@ namespace SharpGLTF
 
                     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 @@ namespace SharpGLTF
 
         public static IReadOnlyList<string> 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 @@ namespace SharpGLTF
                 "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 @@ namespace SharpGLTF
                 "\\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 @@ namespace SharpGLTF
 
         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<string> GetMeshIntancingModelPaths()
@@ -224,14 +241,16 @@ namespace SharpGLTF
 
             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<string> GetModelPathsInDirectory(params string[] paths)
+        private static IReadOnlyList<string> _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 @@ namespace SharpGLTF
     {
         #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 @@ namespace SharpGLTF
 
         #region data
 
+        private System.IO.DirectoryInfo _BaseDirectory;
+
         public string Name { get; set; }
         public string Screenshot { get; set; }
         public Dictionary<string, string> Variants { get; set; } = new Dictionary<string, string>();
@@ -282,9 +306,9 @@ namespace SharpGLTF
 
         #region API
 
-        public IEnumerable<string> GetPaths(params string[] basePath)
+        public IEnumerable<string> GetPaths()
         {
-            var rootPath = System.IO.Path.Combine(basePath);
+            var rootPath = _BaseDirectory.FullName;
 
             foreach(var variant in Variants)
             {

+ 4 - 6
tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs

@@ -572,13 +572,11 @@ namespace SharpGLTF.Scenes
         }
         
 
-        [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 @@ namespace SharpGLTF.Scenes
         }
 
         
-        [TestCase("GearboxAssy.glb")]        
+        [TestCase("Avocado.glb")]        
         public void ExportMeshes(string path)
         {
             TestContext.CurrentContext.AttachGltfValidatorLinks();
@@ -664,7 +662,7 @@ namespace SharpGLTF.Scenes
             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();