From bfdfe42eea0d3e5bd88afa6e07ab3445dc64beec Mon Sep 17 00:00:00 2001 From: Adnane Belmadiaf Date: Mon, 24 Nov 2025 13:48:22 +0100 Subject: [PATCH] fix(IFCImporter): optimize IFC parsing --- Sources/IO/Geometry/IFCImporter/index.js | 72 +++++++++++++----------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/Sources/IO/Geometry/IFCImporter/index.js b/Sources/IO/Geometry/IFCImporter/index.js index 4aadc02f534..a3f2e68ebcd 100644 --- a/Sources/IO/Geometry/IFCImporter/index.js +++ b/Sources/IO/Geometry/IFCImporter/index.js @@ -45,14 +45,14 @@ function vtkIFCImporter(publicAPI, model) { const pointValues = new Float32Array(vertices.length / 2); const normalsArray = new Float32Array(vertices.length / 2); - for (let i = 0; i < vertices.length; i += 6) { - pointValues[i / 2] = vertices[i]; - pointValues[i / 2 + 1] = vertices[i + 1]; - pointValues[i / 2 + 2] = vertices[i + 2]; - - normalsArray[i / 2] = vertices[i + 3]; - normalsArray[i / 2 + 1] = vertices[i + 4]; - normalsArray[i / 2 + 2] = vertices[i + 5]; + for (let i = 0, p = 0; i < vertices.length; i += 6, p += 3) { + pointValues[p] = vertices[i]; + pointValues[p + 1] = vertices[i + 1]; + pointValues[p + 2] = vertices[i + 2]; + + normalsArray[p] = vertices[i + 3]; + normalsArray[p + 1] = vertices[i + 4]; + normalsArray[p + 2] = vertices[i + 5]; } const nCells = indices.length; @@ -99,40 +99,44 @@ function vtkIFCImporter(publicAPI, model) { .buildFromRadian() .multiply3x3(mat3.fromMat4(mat3.create(), userMatrix)); - for (let i = 0; i < vertices.length; i += 6) { - const point = [vertices[i], vertices[i + 1], vertices[i + 2]]; - const normal = [vertices[i + 3], vertices[i + 4], vertices[i + 5]]; + const point = [0, 0, 0]; + const normal = [0, 0, 0]; + for (let i = 0, p = 0; i < vertices.length; i += 6, p += 3) { + point[0] = vertices[i]; + point[1] = vertices[i + 1]; + point[2] = vertices[i + 2]; + normal[0] = vertices[i + 3]; + normal[1] = vertices[i + 4]; + normal[2] = vertices[i + 5]; transformMatrix.apply(point); normalMatrix.apply(normal); - pointValues[i / 2] = point[0]; - pointValues[i / 2 + 1] = point[1]; - pointValues[i / 2 + 2] = point[2]; + pointValues[p] = point[0]; + pointValues[p + 1] = point[1]; + pointValues[p + 2] = point[2]; - normalsArray[i / 2] = normal[0]; - normalsArray[i / 2 + 1] = normal[1]; - normalsArray[i / 2 + 2] = normal[2]; + normalsArray[p] = normal[0]; + normalsArray[p + 1] = normal[1]; + normalsArray[p + 2] = normal[2]; - const colorIndex = i / 2; - colorArray[colorIndex] = color.x; - colorArray[colorIndex + 1] = color.y; - colorArray[colorIndex + 2] = color.z; + colorArray[p] = color.x; + colorArray[p + 1] = color.y; + colorArray[p + 2] = color.z; } } else { - for (let i = 0; i < vertices.length; i += 6) { - pointValues[i / 2] = vertices[i]; - pointValues[i / 2 + 1] = vertices[i + 1]; - pointValues[i / 2 + 2] = vertices[i + 2]; - - normalsArray[i / 2] = vertices[i + 3]; - normalsArray[i / 2 + 1] = vertices[i + 4]; - normalsArray[i / 2 + 2] = vertices[i + 5]; - - const colorIndex = i / 2; - colorArray[colorIndex] = color.x; - colorArray[colorIndex + 1] = color.y; - colorArray[colorIndex + 2] = color.z; + for (let i = 0, p = 0; i < vertices.length; i += 6, p += 3) { + pointValues[p] = vertices[i]; + pointValues[p + 1] = vertices[i + 1]; + pointValues[p + 2] = vertices[i + 2]; + + normalsArray[p] = vertices[i + 3]; + normalsArray[p + 1] = vertices[i + 4]; + normalsArray[p + 2] = vertices[i + 5]; + + colorArray[p] = color.x; + colorArray[p + 1] = color.y; + colorArray[p + 2] = color.z; } }