@xeokit/xeokit-convert
Version:
JavaScript utilities to create .XKT files
58 lines (57 loc) • 2.85 kB
TypeScript
/**
* @desc Parses glTF JSON into an {@link XKTModel}, without ````.glb```` and textures.
*
* * Lightweight JSON-based glTF parser which ignores textures
* * For texture and ````.glb```` support, see {@link parseGLTFIntoXKTModel}
*
* ## Usage
*
* In the example below we'll create an {@link XKTModel}, then load a glTF model into it.
*
* ````javascript
* utils.loadJSON("./models/gltf/duplex/scene.gltf", async (data) => {
*
* const xktModel = new XKTModel();
*
* parseGLTFJSONIntoXKTModel({
* data,
* xktModel,
* log: (msg) => { console.log(msg); }
* }).then(()=>{
* xktModel.finalize();
* },
* (msg) => {
* console.error(msg);
* });
* });
* ````
*
* @param {Object} params Parsing parameters.
* @param {Object} params.data The glTF JSON.
* @param {Object} [params.metaModelData] Metamodel JSON. If this is provided, then parsing is able to ensure that the XKTObjects it creates will fit the metadata properly.
* @param {XKTModel} params.xktModel XKTModel to parse into.
* @param {Boolean} [params.includeNormals=false] Whether to parse normals. When false, the parser will ignore the glTF
* geometry normals, and the glTF 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 glTF.
* @param {Boolean} [params.reuseGeometries=true] When true, the parser will enable geometry reuse within the XKTModel. When false,
* will automatically "expand" all reused geometries into duplicate copies. This has the drawback of increasing the XKT
* file size (~10-30% for typical models), but can make the model more responsive in the xeokit Viewer, especially if the model
* has excessive geometry reuse. An example of excessive geometry reuse would be if we have 4000 geometries that are
* shared amongst 2000 objects, ie. a large number of geometries with a low amount of reuse, which can present a
* pathological performance case for xeokit's underlying graphics APIs (WebGL, WebGPU etc).
* @param {function} [params.getAttachment] Callback through which to fetch attachments, if the glTF has them.
* @param {Object} [params.stats] Collects statistics.
* @param {function} [params.log] Logging callback.
* @returns {Promise}
*/
export function parseGLTFJSONIntoXKTModel({ data, xktModel, metaModelData, includeNormals, reuseGeometries, getAttachment, stats, log }: {
data: Object;
metaModelData?: Object | undefined;
xktModel: XKTModel;
includeNormals?: boolean | undefined;
reuseGeometries?: boolean | undefined;
getAttachment?: Function | undefined;
stats?: Object | undefined;
log?: Function | undefined;
}): Promise<any>;