Skip to content

Commit

Permalink
Khronos group has archived glTF-Sample-Models and replaced it by the …
Browse files Browse the repository at this point in the history
…new glTF-Sample-Assets
  • Loading branch information
vpenades committed Aug 12, 2024
1 parent 0344b8f commit f5cd805
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
138 changes: 81 additions & 57 deletions tests/SharpGLTF.NUnit/TestFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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");
Expand All @@ -118,11 +137,9 @@ public static IEnumerable<string> 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;
}
}

Expand All @@ -131,10 +148,10 @@ public static IEnumerable<string> GetReferenceModelPaths(bool useNegative = fals

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;
Expand Down Expand Up @@ -175,7 +192,7 @@ public static IReadOnlyList<string> 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
Expand All @@ -197,7 +214,7 @@ public static IReadOnlyList<string> 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"))
Expand All @@ -209,12 +226,12 @@ public static IReadOnlyList<string> 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<string> GetMeshIntancingModelPaths()
Expand All @@ -224,14 +241,16 @@ public static IEnumerable<string> 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<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);

Expand All @@ -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)
Expand All @@ -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<string, string> Variants { get; set; } = new Dictionary<string, string>();
Expand All @@ -282,9 +306,9 @@ public static KhronosSampleModel[] Read(string json)

#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)
{
Expand Down
10 changes: 4 additions & 6 deletions tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -651,7 +649,7 @@ public void TestRoundTrip(string path)
}


[TestCase("GearboxAssy.glb")]
[TestCase("Avocado.glb")]
public void ExportMeshes(string path)
{
TestContext.CurrentContext.AttachGltfValidatorLinks();
Expand All @@ -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();
Expand Down

0 comments on commit f5cd805

Please sign in to comment.