Don't setup highlighter if it already exists
This commit is contained in:
parent
0f9f02f46d
commit
c5c51b8504
45
bim.js
45
bim.js
@ -44,14 +44,16 @@ BIM.createScene = function (container) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @todo Serve web-ifc.wasm locally via AJAX
|
* @todo Serve web-ifc.wasm locally via AJAX
|
||||||
* @param {OBC.Components} components
|
|
||||||
* @param {ArrayBuffer} buffer The uploaded IFC file
|
* @param {ArrayBuffer} buffer The uploaded IFC file
|
||||||
|
* @param {string} name The filename to be used as the model's name
|
||||||
* @returns {OBC.FragmentsGroup} model
|
* @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);
|
const fragments = this.components.get(OBC.FragmentsManager);
|
||||||
// Clean memory before uploading new file
|
|
||||||
fragments.dispose();
|
|
||||||
|
|
||||||
const fragmentIfcLoader = this.components.get(OBC.IfcLoader);
|
const fragmentIfcLoader = this.components.get(OBC.IfcLoader);
|
||||||
// NOTE: loads web-ifc WASM from https://unpkg.com/web-ifc@0.0.53/
|
// 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;
|
fragmentIfcLoader.settings.webIfc.OPTIMIZE_PROFILES = true;
|
||||||
|
|
||||||
const model = await fragmentIfcLoader.load(buffer);
|
const model = await fragmentIfcLoader.load(buffer);
|
||||||
model.name = "Test";
|
model.name = name;
|
||||||
this.world.scene.three.add(model);
|
this.world.scene.three.add(model);
|
||||||
|
|
||||||
// Useful?
|
// Useful?
|
||||||
this.fragments = fragments;
|
this.fragments = fragments;
|
||||||
|
this.model = model;
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@ -92,22 +95,36 @@ BIM.setupHighligther = async function (model) {
|
|||||||
const indexer = this.components.get(OBC.IfcRelationsIndexer);
|
const indexer = this.components.get(OBC.IfcRelationsIndexer);
|
||||||
await indexer.process(model);
|
await indexer.process(model);
|
||||||
|
|
||||||
const highlighter = this.components.get(OBF.Highlighter);
|
let highlighter = null;
|
||||||
highlighter.setup({ world });
|
|
||||||
|
|
||||||
|
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) => {
|
highlighter.events.select.onHighlight.add(async (property) => {
|
||||||
const expressID = property[Object.keys(property)[0]].entries().next().value[0];
|
const expressID = property[Object.keys(property)[0]].entries().next().value[0];
|
||||||
let testProp = await model.getProperties(expressID);
|
let testProp = await model.getProperties(expressID);
|
||||||
|
|
||||||
// BAD just for testing
|
// BAD just for testing
|
||||||
const li = document.querySelector('#selected-prop');
|
if (testProp !== null) {
|
||||||
li.innerHTML = `
|
li.innerHTML = `
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>${testProp['Name'].name}</strong>: ${testProp['Name'].value}</span>
|
<li><strong>${testProp['Name'].name}</strong>: ${testProp['Name'].value}</span>
|
||||||
<li><strong>Tipo</strong>: ${testProp['PredefinedType'].value}</li>
|
<li><strong>Tipo</strong>: ${testProp['PredefinedType']? testProp['PredefinedType'].value : 'Nessuno'}</li>
|
||||||
</ul>
|
</ul>
|
||||||
`;
|
`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
highlighter.events.select.onClear.add(() => {
|
||||||
|
li.innerHTML = '';
|
||||||
|
});
|
||||||
|
|
||||||
|
this.highlighter = highlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default BIM;
|
export default BIM;
|
2
ui.js
2
ui.js
@ -22,7 +22,7 @@ UI.ifcLoader = function (btnId = 'load-ifc') {
|
|||||||
let model = null;
|
let model = null;
|
||||||
loadBtn.onchange = async function () {
|
loadBtn.onchange = async function () {
|
||||||
const files = this.files;
|
const files = this.files;
|
||||||
model = await BIM.loadIfc(new Uint8Array(await files[0].arrayBuffer()));
|
model = await BIM.loadIfc(new Uint8Array(await files[0].arrayBuffer()), files[0].name);
|
||||||
// Set a raycaster to select objects
|
// Set a raycaster to select objects
|
||||||
BIM.setupHighligther(model);
|
BIM.setupHighligther(model);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user