diff --git a/bim.js b/bim.js index 3ea7428..fb431cf 100644 --- a/bim.js +++ b/bim.js @@ -44,14 +44,16 @@ BIM.createScene = function (container) { } /** * @todo Serve web-ifc.wasm locally via AJAX - * @param {OBC.Components} components * @param {ArrayBuffer} buffer The uploaded IFC file + * @param {string} name The filename to be used as the model's name * @returns {OBC.FragmentsGroup} model */ -BIM.loadIfc = async function (buffer) { +BIM.loadIfc = async function (buffer, name) { + if (this.fragments) { + this.fragments.dispose(); + } + const fragments = this.components.get(OBC.FragmentsManager); - // Clean memory before uploading new file - fragments.dispose(); const fragmentIfcLoader = this.components.get(OBC.IfcLoader); // NOTE: loads web-ifc WASM from https://unpkg.com/web-ifc@0.0.53/ @@ -75,11 +77,12 @@ BIM.loadIfc = async function (buffer) { fragmentIfcLoader.settings.webIfc.OPTIMIZE_PROFILES = true; const model = await fragmentIfcLoader.load(buffer); - model.name = "Test"; + model.name = name; this.world.scene.three.add(model); // Useful? this.fragments = fragments; + this.model = model; return model; } @@ -92,22 +95,36 @@ BIM.setupHighligther = async function (model) { const indexer = this.components.get(OBC.IfcRelationsIndexer); await indexer.process(model); - const highlighter = this.components.get(OBF.Highlighter); - highlighter.setup({ world }); + let highlighter = null; + if (!this.highlighter) { + highlighter = this.components.get(OBF.Highlighter); + highlighter.setup({ world }); + } else { + highlighter = this.highlighter; + } + + const li = document.querySelector('#selected-prop'); highlighter.events.select.onHighlight.add(async (property) => { const expressID = property[Object.keys(property)[0]].entries().next().value[0]; let testProp = await model.getProperties(expressID); // BAD just for testing - const li = document.querySelector('#selected-prop'); - li.innerHTML = ` -