import * as THREE from 'three'; import * as OBC from 'openbim-components'; import * as WEBIFC from 'web-ifc'; /** * @namespace BIM */ const BIM = {}; /** * * @param {HTMLElement} container The scene container element * @returns {object} {components, world} */ BIM.init = function (container) { const components = new OBC.Components(); const worlds = components.get(OBC.Worlds); const world = worlds.create(); world.scene = new OBC.SimpleScene(components); world.renderer = new OBC.SimpleRenderer(components, container); world.camera = new OBC.SimpleCamera(components); // Starts the app and updates components at 60 fps components.init(); this.world = world; this.components = components; } /** * @param {HTMLElement} container The scene container element * @returns {OBC.Components} */ BIM.createScene = function (container) { this.init(container); this.world.scene.setup(); // Add a grid to the scene const grids = this.components.get(OBC.Grids); const grid = grids.create(this.world); // (zoom_level, position) this.world.camera.controls.setLookAt(15, 15, 15, 0, 0, 0); } /** * @todo Serve web-ifc.wasm locally via AJAX * @param {OBC.Components} components * @param {ArrayBuffer} buffer The uploaded IFC file */ BIM.loadIfc = async function (buffer) { 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/ //await fragmentIfcLoader.setup(); fragmentIfcLoader.settings.wasm = { path: "./vendor/web-ifc/", absolute: false }; // Excludes IFC categories from the fragment const excludedCats = [ WEBIFC.IFCTENDONANCHOR, WEBIFC.IFCREINFORCINGBAR, WEBIFC.IFCREINFORCINGELEMENT, ]; for (const cat of excludedCats) { fragmentIfcLoader.settings.excludedCategories.add(cat); } fragmentIfcLoader.settings.webIfc.COORDINATE_TO_ORIGIN = true; fragmentIfcLoader.settings.webIfc.OPTIMIZE_PROFILES = true; const model = await fragmentIfcLoader.load(buffer); model.name = "Test"; this.world.scene.three.add(model); // Useful? this.fragments = fragments; return model; } export default BIM;