diff --git a/Sources/IO/Geometry/IFCImporter/example/controller.html b/Sources/IO/Geometry/IFCImporter/example/controller.html new file mode 100644 index 00000000000..d77bd53ba33 --- /dev/null +++ b/Sources/IO/Geometry/IFCImporter/example/controller.html @@ -0,0 +1,15 @@ + + + + + + + + +
+

Options

+
+ Merge geometries + + +
diff --git a/Sources/IO/Geometry/IFCImporter/example/index.js b/Sources/IO/Geometry/IFCImporter/example/index.js index 847ad237368..418e12418cf 100644 --- a/Sources/IO/Geometry/IFCImporter/example/index.js +++ b/Sources/IO/Geometry/IFCImporter/example/index.js @@ -6,18 +6,33 @@ import '@kitware/vtk.js/Rendering/Profiles/Geometry'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkResourceLoader from '@kitware/vtk.js/IO/Core/ResourceLoader'; import vtkIFCImporter from '@kitware/vtk.js/IO/Geometry/IFCImporter'; +import vtkURLExtract from '@kitware/vtk.js/Common/Core/URLExtract'; + +import controlPanel from './controller.html'; // ---------------------------------------------------------------------------- // Example code // ---------------------------------------------------------------------------- +const userParams = vtkURLExtract.extractURLParameters(); +const url = + userParams.fileURL || + 'https://raw.githubusercontent.com/ThatOpen/engine_web-ifc/refs/heads/main/tests/ifcfiles/public/duplex.ifc'; +const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance(); +fullScreenRenderer.addController(controlPanel); + +if (userParams.mergeGeometries === undefined) { + userParams.mergeGeometries = true; +} +const mergeGeometriesCheckbox = document.querySelector('#mergeGeometries'); +mergeGeometriesCheckbox.checked = Boolean(userParams.mergeGeometries); + const importer = vtkIFCImporter.newInstance({ - mergeGeometries: true, + mergeGeometries: mergeGeometriesCheckbox.checked, }); // ---------------------------------------------------------------------------- function update() { - const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance(); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow(); @@ -41,9 +56,9 @@ vtkResourceLoader vtkIFCImporter.setIFCAPI(window.WebIFC); // Trigger data download - importer - .setUrl( - 'https://raw.githubusercontent.com/ThatOpen/engine_web-ifc/refs/heads/main/tests/ifcfiles/public/duplex.ifc' - ) - .then(update); + importer.setUrl(url).then(update); }); + +mergeGeometriesCheckbox.addEventListener('change', (evt) => { + window.location = `?mergeGeometries=${evt.target.checked}`; +}); diff --git a/Sources/IO/Geometry/IFCImporter/index.js b/Sources/IO/Geometry/IFCImporter/index.js index b4969c198f0..4aadc02f534 100644 --- a/Sources/IO/Geometry/IFCImporter/index.js +++ b/Sources/IO/Geometry/IFCImporter/index.js @@ -14,6 +14,7 @@ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray'; import vtkAppendPolyData from 'vtk.js/Sources/Filters/General/AppendPolyData'; import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder'; +import { mat3 } from 'gl-matrix'; const { vtkErrorMacro } = macro; @@ -94,11 +95,16 @@ function vtkIFCImporter(publicAPI, model) { .buildFromRadian() .setMatrix(userMatrix); + const normalMatrix = vtkMatrixBuilder + .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]]; - transformMatrix.apply(point).apply(normal); + transformMatrix.apply(point); + normalMatrix.apply(normal); pointValues[i / 2] = point[0]; pointValues[i / 2 + 1] = point[1]; @@ -244,32 +250,32 @@ function vtkIFCImporter(publicAPI, model) { publicAPI.importActors = (renderer) => { if (model.mergeGeometries) { const opaqueMeshes = meshes.filter((mesh) => mesh.color.w === 1); - let apd = vtkAppendPolyData.newInstance(); + const oapd = vtkAppendPolyData.newInstance(); opaqueMeshes.forEach((mesh) => { const pd = createColoredPolyDataFromIFCMesh(mesh); - apd.addInputData(pd); + oapd.addInputData(pd); }); let mapper = vtkMapper.newInstance(); mapper.setColorModeToDirectScalars(); - mapper.setInputConnection(apd.getOutputPort()); + mapper.setInputConnection(oapd.getOutputPort()); let actor = vtkActor.newInstance(); actor.setMapper(mapper); renderer.addActor(actor); const transparentMeshes = meshes.filter((mesh) => mesh.color.w < 1); - apd = vtkAppendPolyData.newInstance(); + const tapd = vtkAppendPolyData.newInstance(); transparentMeshes.forEach((mesh) => { const pd = createColoredPolyDataFromIFCMesh(mesh); - apd.addInputData(pd); + tapd.addInputData(pd); }); mapper = vtkMapper.newInstance(); mapper.setColorModeToDirectScalars(); - mapper.setInputConnection(apd.getOutputPort()); + mapper.setInputConnection(tapd.getOutputPort()); actor = vtkActor.newInstance(); actor.setMapper(mapper);