From addc8dfbace7364f0b07f5cb02c0405050cc1ff0 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Wed, 27 Oct 2021 10:05:04 +0200 Subject: [PATCH] Remove o3dv test files without nodes. --- test/testfiles/o3dv/cube.o3dv | 12 -- test/testfiles/o3dv/cylinder.o3dv | 11 -- test/testfiles/o3dv/cylinder_types.o3dv | 45 ------- test/testfiles/o3dv/materials.o3dv | 70 ---------- test/testfiles/o3dv/solids.o3dv | 54 -------- test/testfiles/o3dv/sphere.o3dv | 10 -- test/testfiles/o3dv/sphere_types.o3dv | 41 ------ test/testfiles/o3dv/transformation.o3dv | 74 ----------- test/testfiles/o3dv/translateandrotate.o3dv | 2 +- test/tests/importero3dv_test.js | 137 ++++---------------- test/tests/model_test.js | 33 +---- test/utils/testutils.js | 27 +++- 12 files changed, 56 insertions(+), 460 deletions(-) delete mode 100644 test/testfiles/o3dv/cube.o3dv delete mode 100644 test/testfiles/o3dv/cylinder.o3dv delete mode 100644 test/testfiles/o3dv/cylinder_types.o3dv delete mode 100644 test/testfiles/o3dv/materials.o3dv delete mode 100644 test/testfiles/o3dv/solids.o3dv delete mode 100644 test/testfiles/o3dv/sphere.o3dv delete mode 100644 test/testfiles/o3dv/sphere_types.o3dv delete mode 100644 test/testfiles/o3dv/transformation.o3dv diff --git a/test/testfiles/o3dv/cube.o3dv b/test/testfiles/o3dv/cube.o3dv deleted file mode 100644 index 5394032..0000000 --- a/test/testfiles/o3dv/cube.o3dv +++ /dev/null @@ -1,12 +0,0 @@ -{ - "meshes" : [ - { - "type" : "cuboid", - "parameters" : { - "size_x" : 1.0, - "size_y" : 1.0, - "size_z" : 1.0 - } - } - ] -} diff --git a/test/testfiles/o3dv/cylinder.o3dv b/test/testfiles/o3dv/cylinder.o3dv deleted file mode 100644 index 6177cd1..0000000 --- a/test/testfiles/o3dv/cylinder.o3dv +++ /dev/null @@ -1,11 +0,0 @@ -{ - "meshes" : [ - { - "type" : "cylinder", - "parameters" : { - "radius" : 0.5, - "height" : 1.0 - } - } - ] -} diff --git a/test/testfiles/o3dv/cylinder_types.o3dv b/test/testfiles/o3dv/cylinder_types.o3dv deleted file mode 100644 index 2e9af7f..0000000 --- a/test/testfiles/o3dv/cylinder_types.o3dv +++ /dev/null @@ -1,45 +0,0 @@ -{ - "meshes" : [ - { - "type" : "cylinder", - "parameters" : { - "radius" : 0.5, - "height" : 1.0 - } - }, - { - "type" : "cylinder", - "parameters" : { - "radius" : 0.8, - "height" : 1.2 - }, - "transformation" : { - "translation" : [2.0, 0.0, 0.0] - } - }, - { - "type" : "cylinder", - "parameters" : { - "radius" : 0.5, - "height" : 1.0, - "smooth" : false, - "segments" : 5 - }, - "transformation" : { - "translation" : [2.0, 2.0, 0.0] - } - }, - { - "type" : "cylinder", - "parameters" : { - "radius" : 0.5, - "height" : 1.0, - "smooth" : false, - "segments" : 10 - }, - "transformation" : { - "translation" : [0.0, 2.0, 0.0] - } - } - ] -} diff --git a/test/testfiles/o3dv/materials.o3dv b/test/testfiles/o3dv/materials.o3dv deleted file mode 100644 index fe03fa2..0000000 --- a/test/testfiles/o3dv/materials.o3dv +++ /dev/null @@ -1,70 +0,0 @@ -{ - "materials" : [ - { - "name" : "Material 1", - "color" : [200, 0, 0], - "metalness" : 1.0, - "roughness" : 0.0 - }, - { - "name" : "Material 2", - "color" : [0, 200, 0], - "metalness" : 1.0, - "roughness" : 0.25 - }, - { - "name" : "Material 3", - "color" : [0, 0, 200], - "metalness" : 1.0, - "roughness" : 0.5 - }, - { - "name" : "Material 4", - "color" : [200, 200, 0], - "metalness" : 1.0, - "roughness" : 0.75 - } - ], - "meshes" : [ - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - }, - "transformation" : { - "translation" : [0.0, 0.0, 0.0] - }, - "material" : 0 - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - }, - "transformation" : { - "translation" : [1.5, 0.0, 0.0] - }, - "material" : 1 - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - }, - "transformation" : { - "translation" : [3.0, 0.0, 0.0] - }, - "material" : 2 - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - }, - "transformation" : { - "translation" : [4.5, 0.0, 0.0] - }, - "material" : 3 - } - ] -} diff --git a/test/testfiles/o3dv/solids.o3dv b/test/testfiles/o3dv/solids.o3dv deleted file mode 100644 index 54d778b..0000000 --- a/test/testfiles/o3dv/solids.o3dv +++ /dev/null @@ -1,54 +0,0 @@ -{ - "meshes" : [ - { - "type" : "platonic", - "parameters" : { - "solid_type" : "tetrahedron", - "radius" : 1.0 - }, - "transformation" : { - "translation" : [0.0, 0.0, 0.0] - } - }, - { - "type" : "platonic", - "parameters" : { - "solid_type" : "hexahedron", - "radius" : 1.0 - }, - "transformation" : { - "translation" : [0.0, 0.0, 3.0] - } - }, - { - "type" : "platonic", - "parameters" : { - "solid_type" : "octahedron", - "radius" : 1.0 - }, - "transformation" : { - "translation" : [3.0, 0.0, 0.0] - } - }, - { - "type" : "platonic", - "parameters" : { - "solid_type" : "dodecahedron", - "radius" : 1.0 - }, - "transformation" : { - "translation" : [3.0, 0.0, 3.0] - } - }, - { - "type" : "platonic", - "parameters" : { - "solid_type" : "icosahedron", - "radius" : 1.0 - }, - "transformation" : { - "translation" : [6.0, 0.0, 1.5] - } - } - ] -} diff --git a/test/testfiles/o3dv/sphere.o3dv b/test/testfiles/o3dv/sphere.o3dv deleted file mode 100644 index a47f2bb..0000000 --- a/test/testfiles/o3dv/sphere.o3dv +++ /dev/null @@ -1,10 +0,0 @@ -{ - "meshes" : [ - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - } - } - ] -} diff --git a/test/testfiles/o3dv/sphere_types.o3dv b/test/testfiles/o3dv/sphere_types.o3dv deleted file mode 100644 index c7aaa17..0000000 --- a/test/testfiles/o3dv/sphere_types.o3dv +++ /dev/null @@ -1,41 +0,0 @@ -{ - "meshes" : [ - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5 - } - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.8 - }, - "transformation" : { - "translation" : [2.0, 0.0, 0.0] - } - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5, - "smooth" : false, - "segments" : 5 - }, - "transformation" : { - "translation" : [2.0, 2.0, 0.0] - } - }, - { - "type" : "sphere", - "parameters" : { - "radius" : 0.5, - "smooth" : false, - "segments" : 10 - }, - "transformation" : { - "translation" : [0.0, 2.0, 0.0] - } - } - ] -} diff --git a/test/testfiles/o3dv/transformation.o3dv b/test/testfiles/o3dv/transformation.o3dv deleted file mode 100644 index 051f477..0000000 --- a/test/testfiles/o3dv/transformation.o3dv +++ /dev/null @@ -1,74 +0,0 @@ -{ - "materials" : [ - { - "name" : "Material 1", - "color" : [200, 0, 0] - }, - { - "name" : "Material 2", - "color" : [0, 200, 0] - }, - { - "name" : "Material 3", - "color" : [0, 0, 200] - }, - { - "name" : "Material 4", - "color" : [200, 200, 0] - } - ], - "meshes" : [ - { - "name" : "Cube", - "material" : 0, - "type" : "cuboid", - "parameters" : { - "size_x" : 1.0, - "size_y" : 1.0, - "size_z" : 1.0 - } - }, - { - "name" : "Cube T", - "material" : 1, - "transformation" : { - "translation" : [2.0, 0.0, 0.0] - }, - "type" : "cuboid", - "parameters" : { - "size_x" : 1.0, - "size_y" : 1.0, - "size_z" : 1.0 - } - }, - { - "name" : "Cube TR", - "material" : 2, - "transformation" : { - "translation" : [4.0, 0.0, 0.0], - "rotation" : [0.0, 0.0, 0.3826834323650898, 0.9238795325112867] - }, - "type" : "cuboid", - "parameters" : { - "size_x" : 1.0, - "size_y" : 1.0, - "size_z" : 1.0 - } - }, - { - "name" : "Cube TRS", - "material" : 3, - "transformation" : { - "translation" : [6.0, 0.0, 0.0], - "rotation" : [0.0, 0.0, 0.3826834323650898, 0.9238795325112867], - "scale" : [1.5, 2.0, 2.5] - }, - "type" : "cuboid", - "parameters" : { - "size_x" : 1.0, - "size_y" : 1.0, - "size_z" : 1.0 - } - } - ] -} diff --git a/test/testfiles/o3dv/translateandrotate.o3dv b/test/testfiles/o3dv/translateandrotate.o3dv index cb605ae..6986134 100644 --- a/test/testfiles/o3dv/translateandrotate.o3dv +++ b/test/testfiles/o3dv/translateandrotate.o3dv @@ -16,7 +16,7 @@ }, "children" : [ { - "name" : "Translated", + "name" : "Translated and Rotated", "transformation" : { "translation" : [2.0, 0.0, 0.0] }, diff --git a/test/tests/importero3dv_test.js b/test/tests/importero3dv_test.js index 7c37a8b..f7a0939 100644 --- a/test/tests/importero3dv_test.js +++ b/test/tests/importero3dv_test.js @@ -3,94 +3,36 @@ var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); describe ('O3dv Importer', function () { - it ('cube.o3dv', function (done) { - testFiles.ImportO3dvFile ('cube.o3dv', function (model) { + it ('translateandrotate.o3dv', function (done) { + testFiles.ImportO3dvFile ('translateandrotate.o3dv', function (model) { assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ + assert.deepStrictEqual (testUtils.ModelNodesToTree (model), { + name : '', + childNodes : [ { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] - } - } - ] - }); - done (); - }); - }); - - it ('cylinder.o3dv', function (done) { - testFiles.ImportO3dvFile ('cylinder.o3dv', function (model) { - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ + name : 'Translated', + childNodes : [], + meshNames : ['Cube'] + }, { - name : '', - vertexCount : 50, - normalCount : 196, - uvCount : 0, - triangleCount : 96, - boundingBox : { - min : [-0.49605735065723894, -0.4990133642141358, 0], - max : [0.5, 0.4990133642141358, 1] - } + name : 'Rotated', + childNodes : [ + { + name : 'Translated and Rotated', + childNodes : [], + meshNames : ['Cube'] + } + ], + meshNames : [] } - ] - }); - done (); - }); - }); - - it ('sphere.o3dv', function (done) { - testFiles.ImportO3dvFile ('sphere.o3dv', function (model) { - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } ], - meshes : [ - { - name : '', - vertexCount : 382, - normalCount : 2280, - uvCount : 0, - triangleCount : 760, - boundingBox : { - min : [-0.5, -0.5, -0.5], - max : [0.5, 0.5, 0.5] - } - } - ] + meshNames : ['Cube'] }); - done (); - }); - }); - it ('transformation.o3dv', function (done) { - testFiles.ImportO3dvFile ('transformation.o3dv', function (model) { - assert (OV.CheckModel (model)); assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { name : '', materials : [ - { name : 'Material 1' }, - { name : 'Material 2' }, - { name : 'Material 3' }, - { name : 'Material 4' } + { name : 'Green' } ], meshes : [ { @@ -103,42 +45,13 @@ describe ('O3dv Importer', function () { min : [0, 0, 0], max : [1, 1, 1] } - }, - { - name : 'Cube T', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [2, 0, 0], - max : [3, 1, 1] - } - }, - { - name : 'Cube TR', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [3.2928932188134525, 0, 0], - max : [4.707106781186548, 1.414213562373095, 1] - } - }, - { - name : 'Cube TRS', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [4.585786437626905, 0, 0], - max : [7.060660171779821, 2.4748737341529163, 2.5] - } - } + } ] }); + assert.strictEqual (model.MeshInstanceCount (), 3); + let boundingBox = OV.GetBoundingBox (model); + assert (OV.CoordIsEqual3D (boundingBox.min, new OV.Coord3D (-1.0, 0.0, 0.0))); + assert (OV.CoordIsEqual3D (boundingBox.max, new OV.Coord3D (3.0, 3.0, 1.0))); done (); }); }); diff --git a/test/tests/model_test.js b/test/tests/model_test.js index d82300a..ea817a9 100644 --- a/test/tests/model_test.js +++ b/test/tests/model_test.js @@ -253,33 +253,10 @@ describe ('Color Conversion', function () { }); }); -function GetModelTree (model) -{ - function AddNodeToModelTree (model, node, modelTree) - { - modelTree.name = node.HasParent () ? node.GetName () : ''; - modelTree.childNodes = []; - for (const childNode of node.GetChildNodes ()) { - let childTree = {}; - AddNodeToModelTree (model, childNode, childTree); - modelTree.childNodes.push (childTree); - } - modelTree.meshNames = []; - for (const meshIndex of node.GetMeshIndices ()) { - modelTree.meshNames.push (model.GetMesh (meshIndex).GetName ()); - } - } - - let modelTree = {}; - let root = model.GetRootNode (); - AddNodeToModelTree (model, root, modelTree); - return modelTree; -} - describe ('Node Hierarchy', function () { it ('Enumerate hierarchy', function () { let model = testUtils.GetHierarchicalModelNoFinalization (); - let modelTree = GetModelTree (model); + let modelTree = testUtils.ModelNodesToTree (model); assert.deepStrictEqual (modelTree, { name : '', childNodes : [ @@ -312,7 +289,7 @@ describe ('Node Hierarchy', function () { it ('Remove mesh', function () { let model = testUtils.GetHierarchicalModelNoFinalization (); model.RemoveMesh (2); - let modelTree = GetModelTree (model); + let modelTree = testUtils.ModelNodesToTree (model); assert.deepStrictEqual (modelTree, { name : '', childNodes : [ @@ -347,7 +324,7 @@ describe ('Node Hierarchy', function () { let mesh = new OV.Mesh (); mesh.SetName ('Mesh 8'); model.AddMeshToIndex (mesh, 3); - let modelTree = GetModelTree (model); + let modelTree = testUtils.ModelNodesToTree (model); assert.deepStrictEqual (modelTree, { name : '', childNodes : [ @@ -379,7 +356,7 @@ describe ('Node Hierarchy', function () { it ('Enumerate mesh instances', function () { let model = testUtils.GetTranslatedRotatedCubesModel (); - let modelTree = GetModelTree (model); + let modelTree = testUtils.ModelNodesToTree (model); assert.deepStrictEqual (modelTree, { name : '', childNodes : [ @@ -426,7 +403,7 @@ describe ('Node Hierarchy', function () { it ('Enumerate transformed mesh instances', function () { let model = testUtils.GetTranslatedRotatedCubesModel (); - let modelTree = GetModelTree (model); + let modelTree = testUtils.ModelNodesToTree (model); assert.deepStrictEqual (modelTree, { name : '', childNodes : [ diff --git a/test/utils/testutils.js b/test/utils/testutils.js index 534f474..9fa3486 100644 --- a/test/utils/testutils.js +++ b/test/utils/testutils.js @@ -25,6 +25,29 @@ module.exports = return arrayBuffer }, + ModelNodesToTree : function (model) + { + function AddNodeToModelTree (model, node, modelTree) + { + modelTree.name = node.HasParent () ? node.GetName () : ''; + modelTree.childNodes = []; + for (const childNode of node.GetChildNodes ()) { + let childTree = {}; + AddNodeToModelTree (model, childNode, childTree); + modelTree.childNodes.push (childTree); + } + modelTree.meshNames = []; + for (const meshIndex of node.GetMeshIndices ()) { + modelTree.meshNames.push (model.GetMesh (meshIndex).GetName ()); + } + } + + let modelTree = {}; + let root = model.GetRootNode (); + AddNodeToModelTree (model, root, modelTree); + return modelTree; + }, + ModelToObject : function (model) { var obj = { @@ -137,7 +160,7 @@ module.exports = return obj; }, - GetTwoCubesConnectingInOneVertexModel () + GetTwoCubesConnectingInOneVertexModel : function () { let model = new OV.Model (); @@ -152,7 +175,7 @@ module.exports = return model; }, - GetTwoCubesConnectingInOneEdgeModel () + GetTwoCubesConnectingInOneEdgeModel : function () { let model = new OV.Model ();