public void LoadModels() { foreach (var f in TestFiles.GetSampleModelsPaths()) { var root = GltfUtils.LoadModel(f); Assert.NotNull(root); } }
public void TestLoadLightsModel() { var f = TestFiles.GetSchemaExtensionsModelsPaths() .FirstOrDefault(item => item.EndsWith("lights.gltf")); var model = GltfUtils.LoadModel(f); Assert.NotNull(model); Assert.AreEqual(3, model.LogicalPunctualLights.Count); Assert.AreEqual(1, model.DefaultScene.VisualChildren.ElementAt(0).PunctualLight.LogicalIndex); Assert.AreEqual(0, model.DefaultScene.VisualChildren.ElementAt(1).PunctualLight.LogicalIndex); }
public void TestLoadUnlitModel() { var f = TestFiles.GetSampleModelsPaths() .FirstOrDefault(item => item.EndsWith(@"UnlitTest\glTF-Binary\UnlitTest.glb")); var model = GltfUtils.LoadModel(f); Assert.NotNull(model); Assert.IsTrue(model.LogicalMaterials[0].Unlit); // do a model roundtrip var modelBis = ModelRoot.ParseGLB(model.WriteGLB()); Assert.NotNull(modelBis); Assert.IsTrue(modelBis.LogicalMaterials[0].Unlit); }
public void TestLoadPolly() { TestContext.CurrentContext.AttachShowDirLink(); // load Polly model var model = GltfUtils.LoadModel(TestFiles.GetPollyFileModelPath()); Assert.NotNull(model); // Save as GLB, and also evaluate all triangles and save as Wavefront OBJ model.AttachToCurrentTest("polly_out.glb"); model.AttachToCurrentTest("polly_out.obj"); // hierarchically browse some elements of the model: var scene = model.DefaultScene; var pollyNode = scene.FindNode("Polly_Display"); var pollyPrimitive = pollyNode.Mesh.Primitives[0]; var pollyIndices = pollyPrimitive.GetIndices(); var pollyPositions = pollyPrimitive.GetVertices("POSITION").AsVector3Array(); var pollyNormals = pollyPrimitive.GetVertices("NORMAL").AsVector3Array(); for (int i = 0; i < pollyIndices.Count; i += 3) { var a = (int)pollyIndices[i + 0]; var b = (int)pollyIndices[i + 1]; var c = (int)pollyIndices[i + 2]; var ap = pollyPositions[a]; var bp = pollyPositions[b]; var cp = pollyPositions[c]; var an = pollyNormals[a]; var bn = pollyNormals[b]; var cn = pollyNormals[c]; TestContext.WriteLine($"Triangle {ap} {an} {bp} {bn} {cp} {cn}"); } }
public void TestLoadSampleModels(string section) { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLink(); foreach (var f in TestFiles.GetSampleModelsPaths()) { if (!f.Contains(section)) { continue; } var perf = System.Diagnostics.Stopwatch.StartNew(); var model = GltfUtils.LoadModel(f); Assert.NotNull(model); var perf_load = perf.ElapsedMilliseconds; // do a model clone and compare it _AssertAreEqual(model, model.DeepClone()); var perf_clone = perf.ElapsedMilliseconds; // check extensions used if (!model.ExtensionsUsed.Contains("EXT_lights_image_based")) { var detectedExtensions = model.RetrieveUsedExtensions().ToArray(); CollectionAssert.AreEquivalent(model.ExtensionsUsed, detectedExtensions); } // evaluate and save all the triangles to a Wavefront Object model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj")); var perf_wavefront = perf.ElapsedMilliseconds; model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb")); var perf_glb = perf.ElapsedMilliseconds; TestContext.Progress.WriteLine($"processed {f.ToShortDisplayPath()} - Load:{perf_load}ms Clone:{perf_clone}ms S.obj:{perf_wavefront}ms S.glb:{perf_glb}ms"); } }
public void TestLoadSpecialCaseModels(string filePath) { TestContext.CurrentContext.AttachShowDirLink(); TestContext.CurrentContext.AttachGltfValidatorLink(); var f = TestFiles.GetSampleModelsPaths() .FirstOrDefault(item => item.EndsWith(filePath)); var model = GltfUtils.LoadModel(f); Assert.NotNull(model); // evaluate and save all the triangles to a Wavefront Object model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj")); model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb")); model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".gltf")); // do a model roundtrip var bytes = model.WriteGLB(); var modelBis = ModelRoot.ParseGLB(bytes); // clone var cloned = model.DeepClone(); }