webarchi/assets/ui.js
Nicolò P 96bb0388a8 Include IFC file name
TODO: move UI routines to Stimulus
2025-04-02 17:31:28 +02:00

38 lines
1.0 KiB
JavaScript

'use strict';
import BIM from './bim.js';
/**
* @todo Move to Stimulus?
* @namespace UI
*/
const UI = {};
/**
*
* @param {HTMLElement} container The scene container element
*/
UI.setScene = function (container) {
BIM.createScene(container);
}
/**
* Returns the loaded model
* @param {HTMLElement} container The container element
* @param {string} btnId The loading button's id
*/
UI.ifcLoader = function (container, btnId = 'load-ifc') {
const loadBtn = document.querySelector(`#${btnId}`);
const nameInput = document.querySelector('[data-form-target="building"]');
let model = null;
loadBtn.onchange = async function () {
const files = this.files;
model = await BIM.loadIfc(new Uint8Array(await files[0].arrayBuffer()), files[0].name);
// Set a raycaster to select objects
BIM.setupHighligther(model);
localStorage.setItem('loaded-ifc', files[0].name);
nameInput.value = files[0].name.replace('.ifc', '');
}
return model;
};
export default UI;