Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomolamanna authored Feb 13, 2025
1 parent 2461ac6 commit afcf0ed
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { Color } from 'https://cdn.skypack.dev/[email protected]';
import { IfcViewerAPI } from 'https://cdn.skypack.dev/[email protected]';
document.addEventListener("DOMContentLoaded", async function() {
const viewer = new IfcViewerAPI({ container: document.body, backgroundColor: new THREE.Color(0xffffff) });

const container = document.getElementById('viewer-container');
const viewer = new IfcViewerAPI({ container, backgroundColor: new Color(0xffffff) });
viewer.IFC.setWasmPath("https://unpkg.com/[email protected]/");

viewer.axes.setAxes();
viewer.grid.setGrid();
// Controlli della telecamera
await viewer.IFC.applyWebIfcConfig();
await viewer.IFC.setupThreeScene();

const input = document.getElementById('file-input');
input.addEventListener('change', async (changed) => {
const file = changed.target.files[0];
const ifcURL = URL.createObjectURL(file);
await viewer.IFC.loadIfcUrl(ifcURL);
// Selezione del file IFC
document.getElementById('ifc-file').addEventListener('change', async (event) => {
const file = event.target.files[0];
if (!file) return;

document.getElementById("status").innerText = `Caricamento di ${file.name} in corso...`;

const reader = new FileReader();
reader.readAsArrayBuffer(file);

reader.onload = async (e) => {
try {
const data = e.target.result;
const model = await viewer.IFC.loadIfc(new Uint8Array(data));
console.log("Modello IFC caricato:", model);
document.getElementById("status").innerText = `Caricamento completato: ${file.name}`;
} catch (error) {
console.error("Errore nel caricamento IFC:", error);
alert("Errore nel caricamento del file IFC.");
document.getElementById("status").innerText = "Errore nel caricamento del file.";
}
};
});
});

0 comments on commit afcf0ed

Please sign in to comment.