From a13f82f6873472f4dfba2732535b431f0862c477 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Tue, 4 Jan 2022 19:49:13 +0100 Subject: [PATCH] Remove material parameter from mesh. --- source/model/generator.js | 6 +++--- source/model/mesh.js | 13 ------------- source/model/modelfinalization.js | 14 +------------- test/tests/generator_test.js | 5 ++++- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/source/model/generator.js b/source/model/generator.js index 91c19cc..ac36421 100644 --- a/source/model/generator.js +++ b/source/model/generator.js @@ -28,9 +28,6 @@ OV.Generator = class if (this.params.name !== null) { this.mesh.SetName (this.params.name); } - if (this.params.material !== null) { - this.mesh.SetMaterial (this.params.material); - } this.curve = null; } @@ -68,6 +65,9 @@ OV.Generator = class AddTriangle (v0, v1, v2) { let triangle = new OV.Triangle (v0, v1, v2); + if (this.params.material !== null) { + triangle.mat = this.params.material; + } if (this.curve !== null) { triangle.SetCurve (this.curve); } diff --git a/source/model/mesh.js b/source/model/mesh.js index f6d7ce7..739a14c 100644 --- a/source/model/mesh.js +++ b/source/model/mesh.js @@ -8,7 +8,6 @@ OV.Mesh = class extends OV.ModelObject3D this.normals = []; this.uvs = []; this.triangles = []; - this.mat = null; } VertexCount () @@ -111,16 +110,6 @@ OV.Mesh = class extends OV.ModelObject3D return this.triangles[index]; } - SetMaterial (mat) - { - this.mat = mat; - } - - GetMaterial () - { - return this.mat; - } - EnumerateVertices (onVertex) { for (const vertex of this.vertices) { @@ -176,8 +165,6 @@ OV.Mesh = class extends OV.ModelObject3D cloned.AddTriangle (triangle.Clone ()); } - cloned.SetMaterial (this.GetMaterial ()); - return cloned; } }; diff --git a/source/model/modelfinalization.js b/source/model/modelfinalization.js index 1cf2746..c3c8aaf 100644 --- a/source/model/modelfinalization.js +++ b/source/model/modelfinalization.js @@ -111,12 +111,7 @@ OV.ModelFinalizer = class this.FinalizeTriangle (mesh, triangle, meshStatus); if (triangle.mat === null) { - let meshMaterial = mesh.GetMaterial (); - if (meshMaterial !== null) { - triangle.mat = meshMaterial; - } else { - triangle.mat = this.GetDefaultMaterialIndex (model); - } + triangle.mat = this.GetDefaultMaterialIndex (model); } if (triangle.HasVertexColors ()) { @@ -340,13 +335,6 @@ OV.CheckModel = function (model) } } - let meshMaterial = mesh.GetMaterial (); - if (meshMaterial !== null) { - if (!IsCorrectIndex (meshMaterial, model.MaterialCount ())) { - return false; - } - } - return true; } diff --git a/test/tests/generator_test.js b/test/tests/generator_test.js index 7fc4773..acb1be6 100644 --- a/test/tests/generator_test.js +++ b/test/tests/generator_test.js @@ -10,7 +10,10 @@ describe ('Generator', function () { it ('Cuboid with Material', function () { const params = new OV.GeneratorParams ().SetMaterial (1); const cuboid = OV.GenerateCuboid (params, 1.0, 1.0, 1.0); - assert.strictEqual (cuboid.GetMaterial (), 1); + for (let i = 0; i < cuboid.TriangleCount (); i++) { + const triangle = cuboid.GetTriangle (i); + assert.strictEqual (triangle.mat, 1); + } }); it ('Cylinder with Default Parameters', function () {