@xeokit/xeokit-convert
Version:
JavaScript utilities to create .XKT files
68 lines (67 loc) • 2.9 kB
TypeScript
/**
* @desc Parses IFC STEP file data into an {@link XKTModel}.
*
* This function uses [web-ifc](https://github.com/tomvandig/web-ifc) to parse the IFC, which relies on a
* WASM file to do the parsing.
*
* Depending on how we use this function, we may need to provide it with a path to the directory where that WASM file is stored.
*
* This function is tested with web-ifc version 0.0.34.
*
* ## Usage
*
* In the example below we'll create an {@link XKTModel}, then load an IFC model into it.
*
* ````javascript
* import {XKTModel, parseIFCIntoXKTModel, writeXKTModelToArrayBuffer} from "xeokit-convert.es.js";
*
* import * as WebIFC from "web-ifc-api.js";
*
* utils.loadArraybuffer("rac_advanced_sample_project.ifc", async (data) => {
*
* const xktModel = new XKTModel();
*
* parseIFCIntoXKTModel({
* WebIFC,
* data,
* xktModel,
* wasmPath: "../dist/",
* autoNormals: true,
* log: (msg) => { console.log(msg); }
* }).then(()=>{
* xktModel.finalize();
* },
* (msg) => {
* console.error(msg);
* });
* });
* ````
*
* @param {Object} params Parsing params.
* @param {Object} params.WebIFC The WebIFC library. We pass this in as an external dependency, in order to give the
* caller the choice of whether to use the Browser or NodeJS version.
* @param {ArrayBuffer} [params.data] IFC file data.
* @param {XKTModel} [params.xktModel] XKTModel to parse into.
* @param {Boolean} [params.autoNormals=true] When true, the parser will ignore the IFC geometry normals, and the IFC
* data will rely on the xeokit ````Viewer```` to automatically generate them. This has the limitation that the
* normals will be face-aligned, and therefore the ````Viewer```` will only be able to render a flat-shaded representation
* of the IFC model. This is ````true```` by default, because IFC models tend to look acceptable with flat-shading,
* and we always want to minimize IFC model size wherever possible.
* @param {String[]} [params.includeTypes] Option to only convert objects of these types.
* @param {String[]} [params.excludeTypes] Option to never convert objects of these types.
* @param {String} params.wasmPath Path to ````web-ifc.wasm````, required by this function.
* @param {Object} [params.stats={}] Collects statistics.
* @param {function} [params.log] Logging callback.
* @returns {Promise} Resolves when IFC has been parsed.
*/
export function parseIFCIntoXKTModel({ WebIFC, data, xktModel, autoNormals, includeTypes, excludeTypes, wasmPath, stats, log }: {
WebIFC: Object;
data?: ArrayBuffer | undefined;
xktModel?: any;
autoNormals?: boolean | undefined;
includeTypes?: string[] | undefined;
excludeTypes?: string[] | undefined;
wasmPath: string;
stats?: Object | undefined;
log?: Function | undefined;
}): Promise<any>;