Przeglądaj źródła

Bumped version
Tests code cleanup

Vicente Penades 6 lat temu
rodzic
commit
2eb28154d9

+ 1 - 1
src/SharpGLTF.DOM/SharpGLTF.csproj

@@ -11,7 +11,7 @@
     <Description>SharpGLTF is a c# library for reading and writing glTF2 3D models</Description>
     <Copyright>Copyright (c) 2019 Vicente Penades</Copyright>
     <PackageTags>C# glTF 3D</PackageTags>
-    <Version>1.0.0-alpha0003</Version>
+    <Version>1.0.0-alpha0004</Version>
     <LangVersion>latest</LangVersion>
     <DebugSymbols>true</DebugSymbols>
     <PackageLicenseFile>LICENSE</PackageLicenseFile>

+ 9 - 10
tests/SharpGLTF.Tests/Geometry/CreateMeshTests.cs

@@ -56,24 +56,23 @@ namespace SharpGLTF.Geometry
 
             // Now we switch to the .Schema2 namespace and we create a new scene:
 
-            var root = Schema2.ModelRoot.CreateModel();                        
-            var scene = root.UseScene("default");
-            var node = scene.CreateNode("main scene");
+            var model = Schema2.ModelRoot.CreateModel();                        
+            var scene = model.UseScene("default");
+            var rnode = scene.CreateNode("main scene");
 
-            var material = root.CreateMaterial("DefaultMaterial")
+            var material = model.CreateMaterial("DefaultMaterial")
                 .WithDefault(new Vector4(1, 0, 0, 1));
             material.DoubleSided = true;            
 
-            node.Mesh = root.CreateMesh();
+            rnode.Mesh = model.CreateMesh();
 
             // this assigns the mesh we've created before to this schema mesh.
             // Notice that the schema buffers being created will be using the
             // memory allocated by (#1) and (#2)
-            srcMesh.AssignToSchema(node.Mesh);
-
-            root.MergeBuffers();
-            root.AttachToCurrentTest("Triangle.gltf");
-            root.AttachToCurrentTest("Triangle.glb");
+            srcMesh.AssignToSchema(rnode.Mesh);
+                        
+            model.AttachToCurrentTest("Triangle.gltf");
+            model.AttachToCurrentTest("Triangle.glb");
 
             TestContext.CurrentContext.AttachShowDirLink();
         }        

+ 5 - 10
tests/SharpGLTF.Tests/Schema2/Authoring/CreateModelTests.cs

@@ -60,14 +60,12 @@ namespace SharpGLTF.Schema2.Authoring
                 .CreateAccessor()
                 .WithIndexData(indicesView, 0, 3, IndexType.UNSIGNED_INT);
             
-            // create mehh primitive
+            // create mesh primitive
             var primitive = rmesh.CreatePrimitive();
             primitive.DrawPrimitiveType = PrimitiveType.TRIANGLES;
             primitive.SetVertexAccessor("POSITION", positionsAccessor);
             primitive.IndexAccessor = indicesAccessor;
-
-            // save result
-            model.MergeBuffers();
+            
             model.AttachToCurrentTest("result.glb");
             model.AttachToCurrentTest("result.gltf");
         }
@@ -134,9 +132,7 @@ namespace SharpGLTF.Schema2.Authoring
             primitive.Material
                 .FindChannel("BaseColor")
                 .SetTexture(0, model.CreateImage().WithExternalFile(imagePath) );
-
-            // save result            
-            model.MergeBuffers();
+            
             model.AttachToCurrentTest("result.glb");
             model.AttachToCurrentTest("result.gltf");            
         }
@@ -166,10 +162,9 @@ namespace SharpGLTF.Schema2.Authoring
 
             // fill our node with the mesh
             meshBuilder.CopyToNode(rnode, createMaterialForColor);
-
-            model.MergeBuffers();
+            
             model.AttachToCurrentTest("result.glb");
             model.AttachToCurrentTest("result.gltf");
-        }       
+        }
     }
 }

+ 9 - 10
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadModelTests.cs

@@ -75,10 +75,10 @@ namespace SharpGLTF.Schema2.LoadAndSave
 
             foreach (var f in TestFiles.GetSampleFilePaths())
             {
-                var root = GltfUtils.LoadModel(f);
-                Assert.NotNull(root);
+                var model = GltfUtils.LoadModel(f);
+                Assert.NotNull(model);
 
-                TestContext.CurrentContext.AttachToCurrentTestAsWavefrontObject(System.IO.Path.GetFileName(f), root);
+                model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
             }
         }
 
@@ -102,18 +102,17 @@ namespace SharpGLTF.Schema2.LoadAndSave
             TestContext.CurrentContext.AttachShowDirLink();
             
             // load Polly model
-            var polly = GltfUtils.LoadModel( TestFiles.GetPollyFilePath() );
+            var model = GltfUtils.LoadModel( TestFiles.GetPollyFilePath() );
 
-            Assert.NotNull(polly);            
+            Assert.NotNull(model);            
 
-            // Save as GLB, and also evaluate all triangles and save as Wavefront OBJ
-            polly.MergeBuffers();
-            polly.AttachToCurrentTest("polly_out.glb");
-            TestContext.CurrentContext.AttachToCurrentTestAsWavefrontObject("polly_out.obj", polly);
+            // 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 = polly.DefaultScene;
+            var scene = model.DefaultScene;
 
             var pollyNode = scene.FindNode("Polly_Display");            
 

+ 0 - 13
tests/SharpGLTF.Tests/Schema2/ModelDumpUtils.cs

@@ -11,19 +11,6 @@ namespace SharpGLTF.Schema2
     /// </summary>
     static class ModelDumpUtils
     {
-        public static void AttachToCurrentTestAsWavefrontObject(this NUnit.Framework.TestContext context, string fileName, ModelRoot model)
-        {
-            fileName = System.IO.Path.ChangeExtension(fileName, ".obj");
-
-            fileName = context.GetAttachmentPath(fileName, true);
-
-            var wavefront = model.ToWavefrontWriter().ToString();
-
-            System.IO.File.WriteAllText(fileName, wavefront);
-
-            NUnit.Framework.TestContext.AddTestAttachment(fileName);
-        }
-
         public static WavefrontWriter ToWavefrontWriter(this ModelRoot model)
         {
             var writer = new WavefrontWriter();

+ 10 - 1
tests/SharpGLTF.Tests/TestUtils.cs

@@ -41,18 +41,27 @@ namespace SharpGLTF
 
         public static void AttachToCurrentTest(this Schema2.ModelRoot model, string fileName)
         {
+            // find the output path for the current test
             fileName = NUnit.Framework.TestContext.CurrentContext.GetAttachmentPath(fileName, true);
             
             if (fileName.ToLower().EndsWith(".glb"))
             {
+                // ensure the model has just one buffer
                 model.MergeBuffers();
                 model.SaveGLB(fileName);
             }
-            else
+            else if (fileName.ToLower().EndsWith(".gltf"))
             {
                 model.SaveGLTF(fileName, Newtonsoft.Json.Formatting.Indented);
             }
+            else if (fileName.ToLower().EndsWith(".obj"))
+            {
+                // evaluate all triangles of the model
+                var wavefront = Schema2.ModelDumpUtils.ToWavefrontWriter(model).ToString();
+                System.IO.File.WriteAllText(fileName, wavefront);                
+            }
 
+            // Attach the saved file to the current test
             NUnit.Framework.TestContext.AddTestAttachment(fileName);
         }