diff --git a/source/import/importero3dv.js b/source/import/importero3dv.js index ae2acc5..31f039f 100644 --- a/source/import/importero3dv.js +++ b/source/import/importero3dv.js @@ -42,7 +42,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase } } if (content.root !== undefined) { - this.ImportNode (content.root, this.model.GetRootNode ()); + this.ImportNode (content, content.root, this.model.GetRootNode ()); } this.ImportProperties (this.model, content); onFinish (); @@ -73,11 +73,6 @@ OV.ImporterO3dv = class extends OV.ImporterBase genParams.SetMaterial (meshContent.material); } - if (meshContent.transformation !== undefined) { - let meshTransformation = this.GetTransformation (meshContent.transformation); - genParams.SetTransformation (meshTransformation); - } - let parameters = meshContent.parameters; if (parameters === undefined) { return; @@ -116,7 +111,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase } } - ImportNode (nodeContent, node) + ImportNode (content, nodeContent, node) { if (nodeContent.name !== undefined) { node.SetName (nodeContent.name); @@ -125,16 +120,24 @@ OV.ImporterO3dv = class extends OV.ImporterBase const nodeTransformation = this.GetTransformation (nodeContent.transformation); node.SetTransformation (nodeTransformation); } - if (nodeContent.meshes !== undefined) { - for (const meshIndex of nodeContent.meshes) { - node.AddMeshIndex (meshIndex); - } - } if (nodeContent.children !== undefined) { for (const child of nodeContent.children) { let childNode = new OV.Node (); node.AddChildNode (childNode); - this.ImportNode (child, childNode); + this.ImportNode (content, child, childNode); + } + } + if (nodeContent.meshes !== undefined) { + for (const meshIndex of nodeContent.meshes) { + let meshNode = new OV.Node (); + meshNode.SetType (OV.NodeType.MeshNode); + let meshContent = content.meshes[meshIndex]; + if (meshContent.transformation !== undefined) { + let meshTransformation = this.GetTransformation (meshContent.transformation); + meshNode.SetTransformation (meshTransformation); + } + meshNode.AddMeshIndex (meshIndex); + node.AddChildNode (meshNode); } } } diff --git a/source/model/generator.js b/source/model/generator.js index 5b9349e..5247a16 100644 --- a/source/model/generator.js +++ b/source/model/generator.js @@ -4,7 +4,6 @@ OV.GeneratorParams = class { this.name = null; this.material = null; - this.transformation = null; } SetName (name) @@ -18,23 +17,6 @@ OV.GeneratorParams = class this.material = material; return this; } - - SetTransformationTRS (translation, rotation, scale) - { - const matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale); - return this.SetTransformationMatrix (matrix); - } - - SetTransformationMatrix (matrix) - { - return this.SetTransformation (new OV.Transformation (matrix)); - } - - SetTransformation (transformation) - { - this.transformation = transformation; - return this; - } }; OV.Generator = class @@ -57,9 +39,6 @@ OV.Generator = class AddVertex (x, y, z) { let coord = new OV.Coord3D (x, y, z); - if (this.params.transformation !== null) { - coord = this.params.transformation.TransformCoord3D (coord); - } return this.mesh.AddVertex (coord); } diff --git a/test/tests/generator_test.js b/test/tests/generator_test.js index 186ed43..acb1be6 100644 --- a/test/tests/generator_test.js +++ b/test/tests/generator_test.js @@ -16,18 +16,6 @@ describe ('Generator', function () { } }); - it ('Cuboid with Transformation', function () { - const params = new OV.GeneratorParams ().SetTransformationTRS ( - new OV.Coord3D (1.0, 0.0, 0.0), - new OV.Quaternion (0.0, 0.0, 0.0, 1.0), - new OV.Coord3D (1.0, 1.0, 1.0) - ); - const cuboid = OV.GenerateCuboid (params, 1.0, 1.0, 1.0); - const bounds = OV.GetBoundingBox (cuboid); - assert (OV.CoordIsEqual3D (bounds.min, new OV.Coord3D (1.0, 0.0, 0.0))); - assert (OV.CoordIsEqual3D (bounds.max, new OV.Coord3D (2.0, 1.0, 1.0))); - }); - it ('Cylinder with Default Parameters', function () { const cylinder = OV.GenerateCylinder (null, 0.5, 1.0, 25, false); assert (OV.IsSolid (cylinder)); diff --git a/test/tests/importero3dv_test.js b/test/tests/importero3dv_test.js index e0eb213..22fd015 100644 --- a/test/tests/importero3dv_test.js +++ b/test/tests/importero3dv_test.js @@ -11,22 +11,39 @@ describe ('O3dv Importer', function () { childNodes : [ { name : 'Translated', - childNodes : [], - meshNames : ['Cube'] + childNodes : [ + { + name : '', + childNodes : [], + meshNames : ['Cube'] + } + ], + meshNames : [] }, { name : 'Rotated', childNodes : [ { name : 'Translated and Rotated', - childNodes : [], - meshNames : ['Cube'] + childNodes : [ + { + name : '', + childNodes : [], + meshNames : ['Cube'] + } + ], + meshNames : [] } ], meshNames : [] + }, + { + name : '', + childNodes : [], + meshNames : ['Cube'] } ], - meshNames : ['Cube'] + meshNames : [] }); assert.strictEqual (model.MeshInstanceCount (), 3); @@ -46,17 +63,45 @@ describe ('O3dv Importer', function () { childNodes : [ { name : 'Tetrahedral', - childNodes : [], - meshNames : ['Tetrahedron'] + childNodes : [ + { + name : '', + childNodes : [], + meshNames : ['Tetrahedron'] + } + ], + meshNames : [] }, { name : 'Octahedral', - childNodes : [], - meshNames : ['Hexahedron', 'Octahedron'] + childNodes : [ + { + name : '', + childNodes : [], + meshNames : ['Hexahedron'] + }, + { + name : '', + childNodes : [], + meshNames : ['Octahedron'] + } + ], + meshNames : [] }, { name : 'Icosahedral', - childNodes : [], - meshNames : ['Dodecahedron', 'Icosahedron'] + childNodes : [ + { + name : '', + childNodes : [], + meshNames : ['Dodecahedron'] + }, + { + name : '', + childNodes : [], + meshNames : ['Icosahedron'] + } + ], + meshNames : [] } ], meshNames : [] diff --git a/test/utils/testutils.js b/test/utils/testutils.js index cdabca8..a513633 100644 --- a/test/utils/testutils.js +++ b/test/utils/testutils.js @@ -165,8 +165,9 @@ module.exports = let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); model.AddMeshToRootNode (cube1); + let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); let matrix = new OV.Matrix ().CreateTranslation (1.0, 1.0, 1.0); - let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0); + OV.TransformMesh (cube2, new OV.Transformation (matrix)); model.AddMeshToRootNode (cube2); OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); @@ -180,8 +181,9 @@ module.exports = let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); model.AddMeshToRootNode (cube1); + let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 1.0); - let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0); + OV.TransformMesh (cube2, new OV.Transformation (matrix)) model.AddMeshToRootNode (cube2); OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); @@ -195,8 +197,9 @@ module.exports = let cube1 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); model.AddMeshToRootNode (cube1); + let cube2 = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 0.0); - let cube2 = OV.GenerateCuboid (new OV.GeneratorParams ().SetTransformationMatrix (matrix), 1.0, 1.0, 1.0); + OV.TransformMesh (cube2, new OV.Transformation (matrix)); model.AddMeshToRootNode (cube2); OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) });