From 8a3c98e658c8f3355221622776385e46c139078d Mon Sep 17 00:00:00 2001 From: kovacsv Date: Mon, 23 Oct 2023 20:27:21 +0200 Subject: [PATCH] The obj file format specifies continuous lines and not line segments. --- source/engine/import/importerobj.js | 2 +- source/engine/model/line.js | 2 +- source/engine/threejs/threeconverter.js | 8 ++++++-- test/testfiles/obj/cube_with_edges.obj | 9 ++++++--- test/testfiles/obj/lines.obj | 2 +- test/testfiles/obj/lines_colors.obj | 2 +- test/testfiles/obj/lines_in_meshes.obj | 2 +- test/testfiles/obj/lines_in_meshes_2.obj | 2 +- test/tests/importerobj_test.js | 8 ++++---- 9 files changed, 22 insertions(+), 15 deletions(-) diff --git a/source/engine/import/importerobj.js b/source/engine/import/importerobj.js index b26dae9..839a6b4 100644 --- a/source/engine/import/importerobj.js +++ b/source/engine/import/importerobj.js @@ -220,7 +220,7 @@ export class ImporterObj extends ImporterBase )); return true; } else if (keyword === 'l') { - if (parameters.length < 2 || parameters.length % 2 !== 0) { + if (parameters.length < 2) { return true; } this.ProcessLineCommand (parameters); diff --git a/source/engine/model/line.js b/source/engine/model/line.js index f8860b3..28fec18 100644 --- a/source/engine/model/line.js +++ b/source/engine/model/line.js @@ -27,7 +27,7 @@ export class Line if (this.vertices === null) { return 0; } - return parseInt (this.vertices.length / 2, 10); + return this.vertices.length - 1; } Clone () diff --git a/source/engine/threejs/threeconverter.js b/source/engine/threejs/threeconverter.js index 7e93343..0c6f84f 100644 --- a/source/engine/threejs/threeconverter.js +++ b/source/engine/threejs/threeconverter.js @@ -445,12 +445,16 @@ export function ConvertModelToThreeObject (model, conversionParams, conversionOu for (let i = 0; i < lineIndices.length; i++) { let line = mesh.GetLine (lineIndices[i]); let lineVertices = line.GetVertices (); - for (let vertexIndex of lineVertices) { + for (let i = 0; i < lineVertices.length; i++) { + let vertexIndex = lineVertices[i]; let vertex = mesh.GetVertex (vertexIndex); vertices.push (vertex.x, vertex.y, vertex.z); + if (i > 0 && i < lineVertices.length - 1) { + vertices.push (vertex.x, vertex.y, vertex.z); + } } meshMaterialHandler.ProcessItem (segmentCount, line.mat); - segmentCount += lineVertices.length / 2; + segmentCount += line.SegmentCount (); } meshMaterialHandler.Finalize (segmentCount); diff --git a/test/testfiles/obj/cube_with_edges.obj b/test/testfiles/obj/cube_with_edges.obj index b930c5f..4057ee8 100644 --- a/test/testfiles/obj/cube_with_edges.obj +++ b/test/testfiles/obj/cube_with_edges.obj @@ -29,12 +29,15 @@ f 1/1/6 4/2/6 3/3/6 2/4/6 f 2/1/1 3/2/1 7/3/1 6/4/1 f 4/1/2 1/2/2 5/3/2 8/4/2 f 5/1/5 6/2/5 7/3/5 8/4/5 -l 1 4 2 3 6 7 5 8 +l 1 4 +l 2 3 +l 6 7 +l 5 8 usemtl Red f 3/1/3 4/2/3 8/3/3 7/4/3 -l 1 2 2 6 6 5 5 1 +l 1 2 6 5 1 usemtl Blue f 1/1/4 2/2/4 6/3/4 5/4/4 -l 3 4 4 8 8 7 7 3 +l 3 4 8 7 3 diff --git a/test/testfiles/obj/lines.obj b/test/testfiles/obj/lines.obj index 58f2e8b..2bc3c89 100644 --- a/test/testfiles/obj/lines.obj +++ b/test/testfiles/obj/lines.obj @@ -8,4 +8,4 @@ v 1.0 1.0 1.0 v 0.0 1.0 1.0 l 1 2 l 3 4 -l 5 6 6 7 7 8 8 5 +l 5 6 7 8 5 diff --git a/test/testfiles/obj/lines_colors.obj b/test/testfiles/obj/lines_colors.obj index 9e55285..3c6e84b 100644 --- a/test/testfiles/obj/lines_colors.obj +++ b/test/testfiles/obj/lines_colors.obj @@ -12,7 +12,7 @@ usemtl Red l 1 2 l 3 4 usemtl Green -l 5 6 6 7 7 8 8 5 +l 5 6 7 8 5 usemtl Blue l 1 5 diff --git a/test/testfiles/obj/lines_in_meshes.obj b/test/testfiles/obj/lines_in_meshes.obj index 2f52e8a..59f4b24 100644 --- a/test/testfiles/obj/lines_in_meshes.obj +++ b/test/testfiles/obj/lines_in_meshes.obj @@ -10,4 +10,4 @@ g Mesh01 l 1 2 l 3 4 g Mesh02 -l 5 6 6 7 7 8 8 5 +l 5 6 7 8 5 diff --git a/test/testfiles/obj/lines_in_meshes_2.obj b/test/testfiles/obj/lines_in_meshes_2.obj index 0f3cb25..725e472 100644 --- a/test/testfiles/obj/lines_in_meshes_2.obj +++ b/test/testfiles/obj/lines_in_meshes_2.obj @@ -13,4 +13,4 @@ v 1.0 1.0 1.0 v 0.0 1.0 1.0 g Mesh02 -l 5 6 6 7 7 8 8 5 +l 5 6 7 8 5 diff --git a/test/tests/importerobj_test.js b/test/tests/importerobj_test.js index bd372b5..24ddaa8 100644 --- a/test/tests/importerobj_test.js +++ b/test/tests/importerobj_test.js @@ -668,7 +668,7 @@ describe ('Obj Importer', function () { mat : 0 }, { - vertices : [0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1], + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1], mat : 0 } ], @@ -707,7 +707,7 @@ describe ('Obj Importer', function () { name : 'Mesh02', lines : [ { - vertices : [0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1], + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1], mat : 0 } ], @@ -746,7 +746,7 @@ describe ('Obj Importer', function () { name : 'Mesh02', lines : [ { - vertices : [0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1], + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1], mat : 0 } ], @@ -781,7 +781,7 @@ describe ('Obj Importer', function () { mat : 0 }, { - vertices : [0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1], + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1], mat : 1 }, {