-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2461ac6
commit afcf0ed
Showing
1 changed file
with
29 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | ||
} | ||
}; | ||
}); | ||
}); |