Skip to content

Commit f5cd805

Browse files
committed
Khronos group has archived glTF-Sample-Models and replaced it by the new glTF-Sample-Assets
1 parent 0344b8f commit f5cd805

File tree

5 files changed

+92
-71
lines changed

5 files changed

+92
-71
lines changed

tests/SharpGLTF.Core.Tests/Schema2/Authoring/ExtensionsCreationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void CreateSceneWithSpecularGlossinessExtension()
4747
{
4848
TestContext.CurrentContext.AttachGltfValidatorLinks();
4949

50-
var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF");
50+
var basePath = TestFiles.GetKhronosAssetDir( "SpecGlossVsMetalRough", "glTF");
5151

5252
// first, create a default material
5353
var material = new Materials.MaterialBuilder("material1")
@@ -88,7 +88,7 @@ public void CreateSceneWithClearCoatExtension()
8888
{
8989
TestContext.CurrentContext.AttachGltfValidatorLinks();
9090

91-
var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF");
91+
var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF");
9292

9393
// first, create a default material
9494
var material = new Materials.MaterialBuilder("material")
@@ -127,7 +127,7 @@ public void CreateSceneWithTransmissionExtension()
127127
{
128128
TestContext.CurrentContext.AttachGltfValidatorLinks();
129129

130-
var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF");
130+
var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF");
131131

132132
var material = new Materials.MaterialBuilder("material")
133133
.WithMetallicRoughnessShader()
@@ -163,7 +163,7 @@ public void CreateSceneWithsSheenExtension()
163163
{
164164
TestContext.CurrentContext.AttachGltfValidatorLinks();
165165

166-
var basePath = System.IO.Path.Combine(TestFiles.KhronosSampleModelsDirectory, "2.0", "SpecGlossVsMetalRough", "glTF");
166+
var basePath = TestFiles.GetKhronosAssetDir("SpecGlossVsMetalRough", "glTF");
167167

168168
var material = new Materials.MaterialBuilder("material")
169169
.WithMetallicRoughnessShader()

tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/LoadSampleTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ public void LoadModelWithMorphTargets()
267267
[TestCase("RiggedFigure.glb")]
268268
[TestCase("RiggedSimple.glb")]
269269
[TestCase("BoxAnimated.glb")]
270-
[TestCase("AnimatedMorphCube.glb")]
271-
[TestCase("AnimatedMorphSphere.glb")]
270+
[TestCase("AnimatedMorphCube.glb")]
272271
[TestCase("CesiumMan.glb")]
273272
//[TestCase("Monster.glb")] // temporarily removed from khronos repo
274273
[TestCase("BrainStem.glb")]

tests/SharpGLTF.DownloadTestFiles/ExampleFiles.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ExampleFiles(string workingDirectory)
1818

1919
_KhronosSchemaDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Schema");
2020
_KhronosValidatorDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Validator");
21-
_KhronosSampleModelsDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Sample-Models");
21+
_KhronosSampleModelsDir = System.IO.Path.Combine(_WorkingDirectory, "glTF-Sample-Assets");
2222

2323
_BabylonJsMeshesDir = System.IO.Path.Combine(_WorkingDirectory, "BabylonJS-Assets");
2424
_BabylonJsPlaygroundDir = System.IO.Path.Combine(_WorkingDirectory, "BabylonJS-PlaygroundScenes");
@@ -41,7 +41,7 @@ public void DownloadReferenceModels()
4141

4242
DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF.git", _KhronosSchemaDir);
4343
DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Validator.git", _KhronosValidatorDir);
44-
DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Models.git", _KhronosSampleModelsDir);
44+
DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Assets.git", _KhronosSampleModelsDir);
4545

4646
DownloadUtils.SyncronizeGitRepository("https://github.com/BabylonJS/Assets.git", _BabylonJsMeshesDir);
4747
// DownloadUtils.SyncronizeGitRepository("https://github.com/BabylonJS/MeshesLibrary.git", _BabylonJsMeshesDir);

tests/SharpGLTF.NUnit/TestFiles.cs

Lines changed: 81 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,119 @@ public static class TestFiles
1414
{
1515
#region lifecycle
1616

17-
private static void _EnsureInitialized()
17+
private static System.IO.DirectoryInfo _DefDir(this System.IO.DirectoryInfo defDir, params string[] path)
1818
{
19-
if (_TestFilesDir != null) return;
19+
var finalPath = System.IO.Path.Combine(defDir.FullName, System.IO.Path.Combine(path));
20+
return new System.IO.DirectoryInfo(finalPath);
21+
}
2022

21-
var wdir = TestContext.CurrentContext.WorkDirectory;
23+
private static System.IO.FileInfo _DefFile(this System.IO.DirectoryInfo defDir, params string[] path)
24+
{
25+
var finalPath = System.IO.Path.Combine(defDir.FullName, System.IO.Path.Combine(path));
26+
return new System.IO.FileInfo(finalPath);
27+
}
2228

29+
private static System.IO.DirectoryInfo _FindRepositoryRootDirectory()
30+
{
2331
var examplesFound = false;
2432

25-
while (wdir.Length > 3)
26-
{
27-
_TestFilesDir = System.IO.Path.Combine(wdir, "TestFiles");
33+
var wdir = new System.IO.DirectoryInfo(TestContext.CurrentContext.TestDirectory);
2834

29-
if (wdir.ToUpperInvariant().EndsWith("TESTS") && System.IO.Directory.Exists(_TestFilesDir))
30-
{
31-
examplesFound = true;
32-
break;
33-
}
35+
while (wdir.FullName.Length > 3)
36+
{
37+
if (wdir._DefDir(".git").Exists) return wdir;
3438

35-
wdir = System.IO.Path.GetDirectoryName(wdir);
39+
wdir = wdir.Parent;
3640
}
3741

38-
Assert.That(examplesFound, "TestFiles directory not found; please, run '1_DownloadTestFiles.cmd' before running the tests.");
42+
Assert.That(examplesFound, "repository root directory not found.");
3943

40-
_AssetFilesDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(_TestFilesDir), "Assets");
44+
return wdir;
4145
}
4246

43-
private static string _UsingExternalFiles(params string[] subPath)
47+
private static System.IO.DirectoryInfo _UsingExternalFiles(params string[] subPath)
4448
{
45-
_EnsureInitialized();
49+
var r = _TestFilesDir1._DefDir(subPath);
50+
if (r.Exists) return r;
51+
r = _TestFilesDir2._DefDir(subPath);
52+
if (r.Exists) return r;
4653

47-
return System.IO.Path.Combine(new string[] { _TestFilesDir }.Concat(subPath).ToArray());
54+
throw new System.IO.DirectoryNotFoundException(string.Join("/", subPath));
4855
}
4956

50-
private static string _UsingInternalFiles(params string[] subPath)
57+
private static System.IO.DirectoryInfo _UsingInternalFiles(params string[] subPath)
5158
{
52-
_EnsureInitialized();
53-
54-
return System.IO.Path.Combine(new string[] { _AssetFilesDir }.Concat(subPath).ToArray());
59+
return _AssetFilesDir._DefDir(subPath);
5560
}
5661

5762
#endregion
5863

5964
#region data
6065

66+
private static Lazy<System.IO.DirectoryInfo> _RepoRootDir = new Lazy<System.IO.DirectoryInfo>(_FindRepositoryRootDirectory);
67+
6168
/// <summary>
6269
/// Path to Tests/Assets/
6370
/// </summary>
64-
private static string _AssetFilesDir;
71+
private static System.IO.DirectoryInfo _AssetFilesDir => _RepoRootDir.Value._DefDir("tests", "Assets");
6572

6673
/// <summary>
6774
/// Path to Tests/TestFiles/
6875
/// </summary>
69-
private static string _TestFilesDir;
76+
private static System.IO.DirectoryInfo _TestFilesDir1 => _RepoRootDir.Value._DefDir("tests", "TestFiles");
77+
78+
/// <summary>
79+
/// Path to ..\..\SharpGLTF-TestFiles/
80+
/// </summary>
81+
private static System.IO.DirectoryInfo _TestFilesDir2 => _RepoRootDir.Value._DefDir("..", "SharpGLTF-TestFiles");
7082

71-
private static readonly string _SchemaDir = _UsingExternalFiles("glTF-Schema");
72-
private static readonly string _ValidationDir = _UsingExternalFiles("glTF-Validator");
73-
internal static readonly string _SampleModelsDir = _UsingExternalFiles("glTF-Sample-Models");
83+
84+
private static readonly System.IO.DirectoryInfo _SchemaDir = _UsingExternalFiles("glTF-Schema");
85+
private static readonly System.IO.DirectoryInfo _ValidationDir = _UsingExternalFiles("glTF-Validator");
86+
87+
internal static readonly System.IO.DirectoryInfo _KhronosSampleAssetsDir = _UsingExternalFiles("glTF-Sample-Assets");
7488

75-
private static readonly string _BabylonJsMeshesDir = _UsingExternalFiles("BabylonJS-Assets");
76-
private static readonly string _GeneratedModelsDir = _UsingExternalFiles("GeneratedReferenceModels", "v_0_6_1");
89+
private static readonly System.IO.DirectoryInfo _BabylonJsMeshesDir = _UsingExternalFiles("BabylonJS-Assets");
90+
private static readonly System.IO.DirectoryInfo _GeneratedModelsDir = _UsingExternalFiles("GeneratedReferenceModels", "v_0_6_1");
7791

7892
#endregion
7993

8094
#region properties
8195

82-
public static string KhronosSampleModelsDirectory => _SampleModelsDir;
96+
internal static System.IO.DirectoryInfo KhronosSampleModelsDirectory => _KhronosSampleAssetsDir;
8397

8498
#endregion
8599

86100
#region API
87101

88-
102+
public static string GetKhronosAssetDir(params string[] path)
103+
{
104+
return _KhronosSampleAssetsDir._DefDir("Models")._DefDir(path).FullName;
105+
}
89106

90107
public static IReadOnlyList<string> GetSchemaExtensionsModelsPaths()
91108
{
92-
return GetModelPathsInDirectory(_SchemaDir, "extensions", "2.0");
109+
return _FindModelInDirectory(_SchemaDir._DefDir("extensions", "2.0"));
93110
}
94111

95112
public static IEnumerable<string> GetReferenceModelPaths(bool useNegative = false)
96113
{
97114
var dirPath = _GeneratedModelsDir;
98-
if (dirPath.EndsWith(".zip")) dirPath = dirPath.Substring(0, dirPath.Length - 4);
115+
if (dirPath.FullName.EndsWith(".zip"))
116+
{
117+
var p= dirPath.FullName.Substring(0, dirPath.FullName.Length - 4);
118+
dirPath = new System.IO.DirectoryInfo(p);
119+
}
99120

100-
var manifestsPath = System.IO.Path.Combine(dirPath, useNegative? "Negative" : "Positive");
121+
var manifestsPath = dirPath._DefDir(useNegative? "Negative" : "Positive");
101122

102-
var manifests = System.IO.Directory.GetFiles(manifestsPath, "Manifest.json", System.IO.SearchOption.AllDirectories)
123+
var manifests = manifestsPath.GetFiles("Manifest.json", System.IO.SearchOption.AllDirectories)
103124
.Skip(1)
104125
.ToArray();
105126

106127
foreach (var m in manifests)
107128
{
108-
var d = System.IO.Path.GetDirectoryName(m);
109-
110-
var content = System.IO.File.ReadAllText(m);
129+
var content = System.IO.File.ReadAllText(m.FullName);
111130
var doc = Newtonsoft.Json.Linq.JObject.Parse(content);
112131

113132
var models = doc.SelectToken("models");
@@ -118,11 +137,9 @@ public static IEnumerable<string> GetReferenceModelPaths(bool useNegative = fals
118137

119138
var loadable = !useNegative;
120139

121-
if (loadable) loadable = (Boolean)model.SelectToken("loadable");
122-
123-
mdlPath = System.IO.Path.Combine(d, mdlPath);
140+
if (loadable) loadable = (Boolean)model.SelectToken("loadable");
124141

125-
yield return mdlPath;
142+
yield return m.Directory._DefFile(mdlPath).FullName;
126143
}
127144
}
128145

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

132149
public static IReadOnlyList<string> GetSampleModelsPaths()
133150
{
134-
var entries = KhronosSampleModel.Load();
151+
var entries = KhronosSampleModel.Load(_KhronosSampleAssetsDir._DefFile("Models", "model-index.json"));
135152

136153
var files = entries
137-
.SelectMany(item => item.GetPaths(_SampleModelsDir, "2.0"))
154+
.SelectMany(item => item.GetPaths())
138155
.ToList();
139156

140157
return files;
@@ -175,7 +192,7 @@ public static IReadOnlyList<string> GetKhronosValidationPaths()
175192
"invalid_image_mime_type.gltf", // actual images cannot be validated
176193
};
177194

178-
var files = GetModelPathsInDirectory(_ValidationDir, "test")
195+
var files = _FindModelInDirectory(_ValidationDir._DefDir("test"))
179196
.Where(item => skip.All(f=>!item.EndsWith(f)));
180197

181198
return files
@@ -197,7 +214,7 @@ public static IReadOnlyList<string> GetBabylonJSModelsPaths()
197214
"\\meshes\\Tests\\BadDraco\\Box-draco.glb", // uses KHR_Draco compression
198215
};
199216

200-
var files = GetModelPathsInDirectory(_BabylonJsMeshesDir);
217+
var files = _FindModelInDirectory(_BabylonJsMeshesDir);
201218

202219
return files
203220
.Where(item => !item.ToUpperInvariant().Contains("GLTF-DRACO"))
@@ -209,12 +226,12 @@ public static IReadOnlyList<string> GetBabylonJSModelsPaths()
209226

210227
public static string GetPollyFileModelPath()
211228
{
212-
return _UsingExternalFiles("glTF-Blender-Exporter", "polly", "project_polly.glb");
229+
return _UsingExternalFiles("glTF-Blender-Exporter", "polly")._DefFile("project_polly.glb").FullName;
213230
}
214231

215232
public static string GetUniVRMModelPath()
216233
{
217-
return _UsingExternalFiles("UniVRM", "AliciaSolid_vrm-0.51.vrm");
234+
return _UsingExternalFiles("UniVRM")._DefFile("AliciaSolid_vrm-0.51.vrm").FullName;
218235
}
219236

220237
public static IEnumerable<string> GetMeshIntancingModelPaths()
@@ -224,14 +241,16 @@ public static IEnumerable<string> GetMeshIntancingModelPaths()
224241

225242
var meshInstPath = _UsingInternalFiles("gltf-GpuMeshInstancing");
226243

227-
var fromLocal = System.IO.Directory.GetFiles(meshInstPath, "*.glb", System.IO.SearchOption.AllDirectories);
244+
var fromLocal = meshInstPath
245+
.GetFiles("*.glb", System.IO.SearchOption.AllDirectories)
246+
.Select(item => item.FullName);
228247

229248
return fromBabylon.Concat(fromLocal);
230249
}
231250

232-
private static IReadOnlyList<string> GetModelPathsInDirectory(params string[] paths)
251+
private static IReadOnlyList<string> _FindModelInDirectory(System.IO.DirectoryInfo dinfo)
233252
{
234-
var dirPath = System.IO.Path.Combine(paths);
253+
var dirPath = dinfo.FullName;
235254

236255
if (dirPath.EndsWith(".zip")) dirPath = dirPath.Substring(0, dirPath.Length-4);
237256

@@ -252,11 +271,14 @@ class KhronosSampleModel
252271
{
253272
#region loaders
254273

255-
public static KhronosSampleModel[] Load()
256-
{
257-
var path = System.IO.Path.Combine(TestFiles._SampleModelsDir, "2.0", "model-index.json");
258-
var text = System.IO.File.ReadAllText(path);
259-
return Read(text);
274+
public static KhronosSampleModel[] Load(System.IO.FileInfo finfo)
275+
{
276+
var text = System.IO.File.ReadAllText(finfo.FullName);
277+
var result = Read(text);
278+
279+
foreach (var item in result) { item._BaseDirectory = finfo.Directory; }
280+
281+
return result;
260282
}
261283

262284
public static KhronosSampleModel[] Read(string json)
@@ -274,6 +296,8 @@ public static KhronosSampleModel[] Read(string json)
274296

275297
#region data
276298

299+
private System.IO.DirectoryInfo _BaseDirectory;
300+
277301
public string Name { get; set; }
278302
public string Screenshot { get; set; }
279303
public Dictionary<string, string> Variants { get; set; } = new Dictionary<string, string>();
@@ -282,9 +306,9 @@ public static KhronosSampleModel[] Read(string json)
282306

283307
#region API
284308

285-
public IEnumerable<string> GetPaths(params string[] basePath)
309+
public IEnumerable<string> GetPaths()
286310
{
287-
var rootPath = System.IO.Path.Combine(basePath);
311+
var rootPath = _BaseDirectory.FullName;
288312

289313
foreach(var variant in Variants)
290314
{

tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,11 @@ public void CreateSharedNodeInstanceScene()
572572
}
573573

574574

575-
[TestCase("AnimatedMorphCube.glb")]
576-
[TestCase("AnimatedMorphSphere.glb")]
575+
[TestCase("AnimatedMorphCube.glb")]
577576
[TestCase("Avocado.glb")]
578577
[TestCase("BoxAnimated.glb")]
579578
[TestCase("BrainStem.glb")]
580-
[TestCase("CesiumMan.glb")]
581-
[TestCase("GearboxAssy.glb")]
579+
[TestCase("CesiumMan.glb")]
582580
[TestCase("OrientationTest.glb")]
583581
[TestCase("RiggedFigure.glb")]
584582
[TestCase("RiggedSimple.glb")]
@@ -651,7 +649,7 @@ public void TestRoundTrip(string path)
651649
}
652650

653651

654-
[TestCase("GearboxAssy.glb")]
652+
[TestCase("Avocado.glb")]
655653
public void ExportMeshes(string path)
656654
{
657655
TestContext.CurrentContext.AttachGltfValidatorLinks();
@@ -664,7 +662,7 @@ public void ExportMeshes(string path)
664662
var srcModel = ModelRoot.Load(path, Validation.ValidationMode.TryFix);
665663
Assert.That(srcModel, Is.Not.Null);
666664

667-
srcModel.AttachToCurrentTest("GearBoxAssy.plotly");
665+
srcModel.AttachToCurrentTest("Avocado.plotly");
668666

669667
// convert it to a SceneBuilder so we can manipulate it:
670668
var srcScene = srcModel.DefaultScene.ToSceneBuilder();

0 commit comments

Comments
 (0)