79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
import * as THREE from 'three';
|
|
import * as OBC from 'openbim-components';
|
|
|
|
/**
|
|
* @namespace Actions
|
|
*/
|
|
const Actions = {};
|
|
|
|
/**
|
|
*
|
|
* @param {HTMLElement} container The scene container element
|
|
* @returns {object} {components, world}
|
|
*/
|
|
Actions.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();
|
|
|
|
return {components, world};
|
|
}
|
|
/**
|
|
* @param {OBC.Components} components
|
|
*/
|
|
Actions.loadIfc = function (components) {
|
|
const fragments = components.get(OBC.FragmentsManager);
|
|
|
|
console.log('Working...');
|
|
|
|
return fragments;
|
|
}
|
|
|
|
/**
|
|
* @param {HTMLElement} container The scene container element
|
|
* @returns {OBC.Components}
|
|
*/
|
|
Actions.createScene = function (container) {
|
|
const {components, world} = this.init(container);
|
|
|
|
world.scene.setup();
|
|
world.camera.controls.setLookAt(3, 3, 3, 0, 0, 0);
|
|
|
|
return components;
|
|
}
|
|
/**
|
|
* @namespace UI
|
|
*/
|
|
const UI = {};
|
|
|
|
/**
|
|
*
|
|
* @param {HTMLElement} container The scene container element
|
|
*/
|
|
UI.setScene = function (container) {
|
|
this.components = Actions.createScene(container);
|
|
}
|
|
/**
|
|
* @param {string} uiContainer The UI div's id
|
|
*/
|
|
UI.ifcLoader = function (uiContainer) {
|
|
const ui = document.querySelector(`#${uiContainer}`);
|
|
const loadBtn = document.createElement('button');
|
|
loadBtn.textContent = 'Apri IFC';
|
|
loadBtn.style = 'padding: 10px; cursor: pointer; position: absolute; top: 0; right: 4rem';
|
|
loadBtn.onclick = Actions.loadIfc(this.components);
|
|
|
|
ui.appendChild(loadBtn);
|
|
};
|
|
|
|
export default UI; |