We're going to copy most of the code from ifc-file-reader.js into our main.js file. Please note that this example is somewhat outdated. E.g. It doesn't use a scene picker.
export function readIfcFile() {
const input = document.querySelector('input[type="file"]');
if (!input) return;
input.addEventListener(
'change',
(e) => {
readFile(input);
},
false
);
}
function readFile(input) {
const reader = new FileReader();
reader.onload = () => {
const loaded = loadIfc(reader.result);
scene.add(loaded.MainObject);
};
reader.readAsText(input.files[0]);
}
readIfcFile();
var element = document.getElementById('loading');
element.parentNode.removeChild(element);
export function readIfcFile() {
const input = document.querySelector('input[type="file"]');
input.addEventListener(
'change',
(e) => {
readFile(input);
},
false
);
}
function readFile(input) {
// TODO
}
readIfcFile();
document.getElementById('c').style.display = 'none';
toggleLoader();
Note that readFile(input) has been changed. We will start with an empty function and add in the FileReader.
example/web-worker/main.js
function readFile(input) {
const reader = new FileReader();
reader.onload = () => {
// DO STUFF HERE
};
};
reader.readAsText(input.files[0]);
}
Til' this point, everything should be pretty easy. Now - let's start implementing the Web Worker.
example/web-worker/main.js
function readFile(input) {
const reader = new FileReader();
reader.onload = () => {
const ifcWorker = new Worker('worker/worker.js');
};
reader.readAsText(input.files[0]);
}
Creating a new worker is super easy. Use this for more detailed instruction.