Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions web-ifc-three/src/IFCLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class IFCLoader extends Loader {
this.ifcManager = new IFCManager();
}

/**
* Loads an IFC file from a given URL.
* @param url URL of the IFC file or blob URL.
* @param onLoad Callback when the IFC model is loaded.
* @param onProgress Optional progress callback.
* @param onError Optional error callback.
*/
load(
url: any,
onLoad: (ifc: IFCModel) => void,
Expand All @@ -19,6 +26,29 @@ class IFCLoader extends Loader {
) {
const scope = this;

// Detect JSON files and provide a helpful error message.
// Users often try to load JSON files (produced by ifc-to-json) directly,
// but web-ifc-three only supports binary IFC files for geometry.
const urlString = typeof url === 'string' ? url : '';
if (urlString.endsWith('.json')) {
const error = new Error(
'Cannot load ".json" files directly with IFCLoader. ' +
'The IFCLoader is designed to load binary IFC files (.ifc) for geometry. ' +
'If you are trying to load a JSON file produced by "ifc-to-json", ' +
'please note that JSON files contain property/metadata only (not geometry) ' +
'and must be loaded alongside an IFC file using addModelJSONData(). ' +
'See the documentation for the correct workflow: ' +
'https://ifcjs.github.io/info/docs/Guide/web-ifc/Introduction'
);
if (onError) {
onError(error);
} else {
console.error(error);
}
scope.manager.itemError(url);
return;
}

const loader = new FileLoader(scope.manager);
this.onProgress = onProgress;
loader.setPath(scope.path);
Expand Down