Stupid selection...

This commit is contained in:
Nicolò P 2024-06-03 17:42:08 +02:00
parent 44943e5972
commit 37012578b7
4 changed files with 34 additions and 8 deletions

19
bim.js
View File

@ -1,5 +1,6 @@
import * as THREE from 'three'; import * as THREE from 'three';
import * as OBC from 'openbim-components'; import * as OBC from 'openbim-components';
import * as OBF from '@thatopen/components-front';
import * as WEBIFC from 'web-ifc'; import * as WEBIFC from 'web-ifc';
/** /**
@ -33,6 +34,7 @@ BIM.init = function (container) {
*/ */
BIM.createScene = function (container) { BIM.createScene = function (container) {
this.init(container); this.init(container);
this.world.scene.setup(); this.world.scene.setup();
// Add a grid to the scene // Add a grid to the scene
const grids = this.components.get(OBC.Grids); const grids = this.components.get(OBC.Grids);
@ -44,6 +46,7 @@ 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 {OBC.Components} components
* @param {ArrayBuffer} buffer The uploaded IFC file * @param {ArrayBuffer} buffer The uploaded IFC file
* @returns {OBC.FragmentsGroup} model
*/ */
BIM.loadIfc = async function (buffer) { BIM.loadIfc = async function (buffer) {
const fragments = this.components.get(OBC.FragmentsManager); const fragments = this.components.get(OBC.FragmentsManager);
@ -81,4 +84,20 @@ BIM.loadIfc = async function (buffer) {
return model; return model;
} }
/**
* @param {OBC.FragmentsGroup} model The loaded IFC model
*/
BIM.setupHighligther = async function (model) {
const world = this.world;
const indexer = this.components.get(OBC.IfcRelationsIndexer);
await indexer.process(model);
const highlighter = this.components.get(OBF.Highlighter);
highlighter.setup({ world });
highlighter.events.select.onHighlight.add((property) => {
console.log(property);
});
}
export default BIM; export default BIM;

View File

@ -12,6 +12,7 @@
"@thatopen/fragments": "./vendor/@thatopen/fragments/dist/index.mjs", "@thatopen/fragments": "./vendor/@thatopen/fragments/dist/index.mjs",
"web-ifc": "./vendor/web-ifc/web-ifc-api.js", "web-ifc": "./vendor/web-ifc/web-ifc-api.js",
"openbim-components": "./vendor/@thatopen/components/dist/index.mjs", "openbim-components": "./vendor/@thatopen/components/dist/index.mjs",
"@thatopen/components-front": "./vendor/@thatopen/components-front/dist/index.js",
"lit": "./vendor/@lit-labs/ssr-dom-shim/index.js" "lit": "./vendor/@lit-labs/ssr-dom-shim/index.js"
} }
} }

View File

@ -4,5 +4,5 @@ import UI from './ui.js';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
UI.setScene(document.querySelector('#scene')); UI.setScene(document.querySelector('#scene'));
UI.ifcLoader(); const model = UI.ifcLoader();
}); });

8
ui.js
View File

@ -14,14 +14,20 @@ UI.setScene = function (container) {
BIM.createScene(container); BIM.createScene(container);
} }
/** /**
* Returns the loaded model
* @param {string} btnId The loading button's id * @param {string} btnId The loading button's id
*/ */
UI.ifcLoader = function (btnId = 'load-ifc') { UI.ifcLoader = function (btnId = 'load-ifc') {
const loadBtn = document.querySelector(`#${btnId}`); const loadBtn = document.querySelector(`#${btnId}`);
let model = null;
loadBtn.onchange = async function () { loadBtn.onchange = async function () {
const files = this.files; const files = this.files;
BIM.loadIfc(new Uint8Array(await files[0].arrayBuffer())); model = await BIM.loadIfc(new Uint8Array(await files[0].arrayBuffer()));
// Set a raycaster to select objects
BIM.setupHighligther(model);
} }
return model;
}; };
export default UI; export default UI;