@xeokit/xeokit-convert
Version:
JavaScript utilities to create .XKT files
53 lines (52 loc) • 2.32 kB
TypeScript
/**
* @desc Parses glTF into an {@link XKTModel}, supporting ````.glb```` and textures.
*
* * Supports ````.glb```` and textures
* * For a lightweight glTF JSON parser that ignores textures, see {@link parseGLTFJSONIntoXKTModel}.
*
* ## Usage
*
* In the example below we'll create an {@link XKTModel}, then load a binary glTF model into it.
*
* ````javascript
* utils.loadArraybuffer("../assets/models/gltf/HousePlan/glTF-Binary/HousePlan.glb", async (data) => {
*
* const xktModel = new XKTModel();
*
* parseGLTFIntoXKTModel({
* data,
* xktModel,
* log: (msg) => { console.log(msg); }
* }).then(()=>{
* xktModel.finalize();
* },
* (msg) => {
* console.error(msg);
* });
* });
* ````
*
* @param {Object} params Parsing parameters.
* @param {ArrayBuffer} params.data The glTF.
* @param {String} [params.baseUri] The base URI used to load this glTF, if any. For resolving relative uris to linked resources.
* @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.includeTextures=true] Whether to parse textures.
* @param {Boolean} [params.includeNormals=true] 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 non-PBR representation of the glTF.
* @param {Object} [params.stats] Collects statistics.
* @param {function} [params.log] Logging callback.
@returns {Promise} Resolves when glTF has been parsed.
*/
export function parseGLTFIntoXKTModel({ data, baseUri, xktModel, metaModelData, includeTextures, includeNormals, getAttachment, stats, log }: {
data: ArrayBuffer;
baseUri?: string | undefined;
metaModelData?: Object | undefined;
xktModel: XKTModel;
includeTextures?: boolean | undefined;
includeNormals?: boolean | undefined;
stats?: Object | undefined;
log?: Function | undefined;
}): Promise<any>;