Reference Source

Function

Static Public Summary
public

Creates box-shaped triangle mesh geometry arrays.

public

Creates box-shaped line segment geometry arrays.

public

Creates cylinder-shaped geometry arrays.

public

Creates grid-shaped geometry arrays..

public

Creates plane-shaped geometry arrays.

public

Creates sphere-shaped geometry arrays.

public

Creates torus-shaped geometry arrays.

public

Creates wireframe text-shaped geometry arrays.

public

convert2xkt(params: Object, stats: Object): Promise<number>

Converts model files into xeokit's native XKT format.

Supported source formats are: IFC, CityJSON, glTF, LAZ and LAS.

Only bundled in xeokit-convert.cjs.js.

Usage

const convert2xkt = require("@xeokit/xeokit-convert/dist/convert2xkt.cjs.js");
const fs = require('fs');

convert2xkt({
     sourceData: fs.readFileSync("rme_advanced_sample_project.ifc"),
     outputXKT: (xtkArrayBuffer) => {
         fs.writeFileSync("rme_advanced_sample_project.ifc.xkt", xtkArrayBuffer);
     }
 }).then(() => {
     console.log("Converted.");
 }, (errMsg) => {
     console.error("Conversion failed: " + errMsg)
 });
public

Parses a CityJSON model into an XKTModel.

public

Parses glTF into an XKTModel, supporting .glb and textures.

public

Parses glTF into an XKTModel, supporting .glb and textures.

public

Parses glTF into an XKTModel, supporting .glb and textures.

public

Parses glTF JSON into an XKTModel, without .glb and textures.

public

Parses IFC STEP file data into an XKTModel.

public

Parses LAS and LAZ point cloud data into an XKTModel.

public

Parses JSON metamodel into an XKTModel.

public

Parses PCD point cloud data into an XKTModel.

public

Parses PLY file data into an XKTModel.

public

Parses STL file data into an XKTModel.

public

writeXKTModelToArrayBuffer(xktModel: XKTModel, metaModelJSON: String, stats: Object, options: Object): ArrayBuffer

Writes an XKTModel to an ArrayBuffer.

Static Public

public buildBoxGeometry(cfg: *): Object source

Creates box-shaped triangle mesh geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a box-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const box = buildBoxGeometry({
    primitiveType: "triangles" // or "lines"
    center: [0,0,0],
    xSize: 1,  // Half-size on each axis
    ySize: 1,
    zSize: 1
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "boxGeometry",
     primitiveType: box.primitiveType,
     positions: box.positions,
     normals: box.normals,
     indices: box.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redBoxMesh",
     geometryId: "boxGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redBox",
     meshIds: ["redBoxMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.xSize Number
  • optional
  • default: 1.0

Half-size on the X-axis.

cfg.ySize Number
  • optional
  • default: 1.0

Half-size on the Y-axis.

cfg.zSize Number
  • optional
  • default: 1.0

Half-size on the Z-axis.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildBoxLinesGeometry(cfg: *): Object source

Creates box-shaped line segment geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a box-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const box = buildBoxLinesGeometry({
    center: [0,0,0],
    xSize: 1,  // Half-size on each axis
    ySize: 1,
    zSize: 1
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "boxGeometry",
     primitiveType: box.primitiveType, // "lines"
     positions: box.positions,
     normals: box.normals,
     indices: box.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redBoxMesh",
     geometryId: "boxGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redBox",
     meshIds: ["redBoxMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.xSize Number
  • optional
  • default: 1.0

Half-size on the X-axis.

cfg.ySize Number
  • optional
  • default: 1.0

Half-size on the Y-axis.

cfg.zSize Number
  • optional
  • default: 1.0

Half-size on the Z-axis.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildCylinderGeometry(cfg: *): Object source

Creates cylinder-shaped geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a cylinder-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const cylinder = buildCylinderGeometry({
     center: [0,0,0],
     radiusTop: 2.0,
     radiusBottom: 2.0,
     height: 5.0,
     radialSegments: 20,
     heightSegments: 1,
     openEnded: false
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "cylinderGeometry",
     primitiveType: cylinder.primitiveType,
     positions: cylinder.positions,
     normals: cylinder.normals,
     indices: cylinder.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redCylinderMesh",
     geometryId: "cylinderGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redCylinder",
     meshIds: ["redCylinderMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.radiusTop Number
  • optional
  • default: 1

Radius of top.

cfg.radiusBottom Number
  • optional
  • default: 1

Radius of bottom.

cfg.height Number
  • optional
  • default: 1

Height.

cfg.radialSegments Number
  • optional
  • default: 60

Number of horizontal segments.

cfg.heightSegments Number
  • optional
  • default: 1

Number of vertical segments.

cfg.openEnded Boolean
  • optional
  • default: false

Whether or not the cylinder has solid caps on the ends.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildGridGeometry(cfg: *): Object source

Creates grid-shaped geometry arrays..

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a grid-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const grid = buildGridGeometry({
     size: 1000,
     divisions: 500
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "gridGeometry",
     primitiveType: grid.primitiveType, // Will be "lines"
     positions: grid.positions,
     indices: grid.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redGridMesh",
     geometryId: "gridGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redGrid",
     meshIds: ["redGridMesh"]
});

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.size Number
  • optional
  • default: 1

Dimension on the X and Z-axis.

cfg.divisions Number
  • optional
  • default: 1

Number of divisions on X and Z axis..

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildPlaneGeometry(cfg: *): Object source

Creates plane-shaped geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a plane-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const plane = buildPlaneGeometry({
     center: [0,0,0],
     xSize: 2,
     zSize: 2,
     xSegments: 10,
     zSegments: 10
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "planeGeometry",
     primitiveType: plane.primitiveType, // Will be "triangles"
     positions: plane.positions,
     normals: plane.normals,
     indices: plane.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redPlaneMesh",
     geometryId: "planeGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redPlane",
     meshIds: ["redPlaneMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.xSize Number
  • optional
  • default: 1

Dimension on the X-axis.

cfg.zSize Number
  • optional
  • default: 1

Dimension on the Z-axis.

cfg.xSegments Number
  • optional
  • default: 1

Number of segments on the X-axis.

cfg.zSegments Number
  • optional
  • default: 1

Number of segments on the Z-axis.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildSphereGeometry(cfg: *): Object source

Creates sphere-shaped geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a sphere-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const sphere = buildSphereGeometry({
     center: [0,0,0],
     radius: 1.5,
     heightSegments: 60,
     widthSegments: 60
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "sphereGeometry",
     primitiveType: sphere.primitiveType, // Will be "triangles"
     positions: sphere.positions,
     normals: sphere.normals,
     indices: sphere.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redSphereMesh",
     geometryId: "sphereGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redSphere",
     meshIds: ["redSphereMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.radius Number
  • optional
  • default: 1

Radius.

cfg.heightSegments Number
  • optional
  • default: 24

Number of latitudinal bands.

cfg.widthSegments Number
  • optional
  • default: 18

Number of longitudinal bands.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildTorusGeometry(cfg: *): Object source

Creates torus-shaped geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a torus-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const torus = buildTorusGeometry({
     center: [0,0,0],
     radius: 1.0,
     tube: 0.5,
     radialSegments: 32,
     tubeSegments: 24,
     arc: Math.PI * 2.0
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "torusGeometry",
     primitiveType: torus.primitiveType, // Will be "triangles"
     positions: torus.positions,
     normals: torus.normals,
     indices: torus.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redTorusMesh",
     geometryId: "torusGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redTorus",
     meshIds: ["redTorusMesh"]
});

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.radius Number
  • optional
  • default: 1

The overall radius.

cfg.tube Number
  • optional
  • default: 0.3

The tube radius.

cfg.radialSegments Number
  • optional
  • default: 32

The number of radial segments.

cfg.tubeSegments Number
  • optional
  • default: 24

The number of tubular segments.

cfg.arc Number
  • optional
  • default: Math.PI*0.5

The length of the arc in radians, where Math.PI*2 is a closed torus.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public buildVectorTextGeometry(cfg: *): Object source

Creates wireframe text-shaped geometry arrays.

Usage

In the example below we'll create an XKTModel, then create an XKTMesh with a text-shaped XKTGeometry.

[Run this example]

const xktModel = new XKTModel();

const text = buildVectorTextGeometry({
     origin: [0,0,0],
     text: "On the other side of the screen, it all looked so easy"
});

const xktGeometry = xktModel.createGeometry({
     geometryId: "textGeometry",
     primitiveType: text.primitiveType, // Will be "lines"
     positions: text.positions,
     indices: text.indices
});

const xktMesh = xktModel.createMesh({
     meshId: "redTextMesh",
     geometryId: "textGeometry",
     position: [-4, -6, -4],
     scale: [1, 3, 1],
     rotation: [0, 0, 0],
     color: [1, 0, 0],
     opacity: 1
});

const xktEntity = xktModel.createEntity({
     entityId: "redText",
     meshIds: ["redTextMesh"]
 });

xktModel.finalize();

Params:

NameTypeAttributeDescription
cfg *
  • optional

Configs

cfg.center Number[]
  • optional

3D point indicating the center position.

cfg.origin Number[]
  • optional

3D point indicating the top left corner.

cfg.size Number
  • optional
  • default: 1

Size of each character.

cfg.text String
  • optional
  • default: ""

The text.

Return:

Object

Geometry arrays for XKTModel#createGeometry or XKTModel#createMesh.

public convert2xkt(params: Object, stats: Object): Promise<number> source

import {convert2xkt} from '@xeokit/xeokit-convert/src/convert2xkt.js'

Converts model files into xeokit's native XKT format.

Supported source formats are: IFC, CityJSON, glTF, LAZ and LAS.

Only bundled in xeokit-convert.cjs.js.

Usage

const convert2xkt = require("@xeokit/xeokit-convert/dist/convert2xkt.cjs.js");
const fs = require('fs');

convert2xkt({
     sourceData: fs.readFileSync("rme_advanced_sample_project.ifc"),
     outputXKT: (xtkArrayBuffer) => {
         fs.writeFileSync("rme_advanced_sample_project.ifc.xkt", xtkArrayBuffer);
     }
 }).then(() => {
     console.log("Converted.");
 }, (errMsg) => {
     console.error("Conversion failed: " + errMsg)
 });

Params:

NameTypeAttributeDescription
params Object

Conversion parameters.

params.WebIFC Object

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.

params.configs *
  • optional

Configurations.

params.source String
  • optional

Path to source file. Alternative to sourceData.

params.sourceData ArrayBuffer | JSON
  • optional

Source file data. Alternative to source.

params.sourceFormat String
  • optional

Format of source file/data. Always needed with sourceData, but not normally needed with source, because convert2xkt will determine the format automatically from the file extension of source.

params.metaModelDataStr String
  • optional

Source file data. Overrides metadata from metaModelSource, sourceData and source.

params.metaModelSource String
  • optional

Path to source metaModel file. Overrides metadata from sourceData and source. Overridden by metaModelData.

params.output String
  • optional

Path to destination XKT file. Directories on this path are automatically created if not existing.

params.outputXKTModel Function
  • optional

Callback to collect the XKTModel that is internally build by this method.

params.outputXKT Function
  • optional

Callback to collect XKT file data.

params.includeTypes String[]
  • optional

Option to only convert objects of these types.

params.excludeTypes String[]
  • optional

Option to never convert objects of these types.

stats Object
  • optional

Collects conversion statistics. Statistics are attached to this object if provided.

params.outputStats Function
  • optional

Callback to collect statistics.

params.rotateX Boolean
  • optional
  • default: false

Whether to rotate the model 90 degrees about the X axis to make the Y axis "up", if necessary. Applies to CityJSON and LAS/LAZ models.

params.reuseGeometries Boolean
  • optional
  • default: true

When true, will enable geometry reuse within the XKT. 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 when a model (eg. glTF) has 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).

params.includeTextures Boolean
  • optional
  • default: true

Whether to convert textures. Only works for glTF models.

params.includeNormals Boolean
  • optional
  • default: true

Whether to convert normals. When false, the parser will ignore geometry normals, and the modelwill 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 model.

params.minTileSize Number
  • optional
  • default: 200

Minimum RTC coordinate tile size. Set this to a value between 100 and 10000, depending on how far from the coordinate origin the model's vertex positions are; specify larger tile sizes when close to the origin, and smaller sizes when distant. This compensates for decreasing precision as floats get bigger.

params.log Function
  • optional

Logging callback.

Return:

Promise<number>

public parseCityJSONIntoXKTModel(params: Object): Promise source

import {parseCityJSONIntoXKTModel} from '@xeokit/xeokit-convert/src/parsers/parseCityJSONIntoXKTModel.js'

Parses a CityJSON model into an XKTModel.

CityJSON is a JSON-based encoding for a subset of the CityGML data model (version 2.0.0), which is an open standardised data model and exchange format to store digital 3D models of cities and landscapes. CityGML is an official standard of the Open Geospatial Consortium.

This converter function supports most of the CityJSON 1.0.2 Specification, with the following limitations:

  • Does not (yet) support CityJSON semantics for geometry primitives.
  • Does not (yet) support textured geometries.
  • Does not (yet) support geometry templates.
  • When the CityJSON file provides multiple themes for a geometry, then we parse only the first of the provided themes for that geometry.

Usage

In the example below we'll create an XKTModel, then load a CityJSON model into it.

utils.loadJSON("./models/cityjson/DenHaag.json", async (data) => {

    const xktModel = new XKTModel();

    parseCityJSONIntoXKTModel({
         data,
         xktModel,
         log: (msg) => { console.log(msg); }
    }).then(()=>{
       xktModel.finalize();
    },
    (msg) => {
        console.error(msg);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.data Object

CityJSON data.

params.xktModel XKTModel

XKTModel to parse into.

params.center boolean
  • optional
  • default: false

Set true to center the CityJSON vertex positions to [0,0,0]. This is applied before the transformation matrix, if specified.

params.transform Boolean
  • optional

4x4 transformation matrix to transform CityJSON vertex positions. Use this to rotate, translate and scale them if neccessary.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when CityJSON has been parsed.

public parseGLTFIntoXKTModel(params: Object): Promise source

Parses glTF into an XKTModel, supporting .glb and textures.

Usage

In the example below we'll create an XKTModel, then load a binary glTF model into it.

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);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing parameters.

params.data ArrayBuffer

The glTF.

params.baseUri String
  • optional

The base URI used to load this glTF, if any. For resolving relative uris to linked resources.

params.metaModelData Object
  • optional

Metamodel JSON. If this is provided, then parsing is able to ensure that the XKTObjects it creates will fit the metadata properly.

params.xktModel XKTModel

XKTModel to parse into.

params.includeTextures Boolean
  • optional
  • default: true

Whether to parse textures.

params.includeNormals Boolean
  • optional
  • default: 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.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when glTF has been parsed.

public parseGLTFIntoXKTModel(params: Object): Promise source

Parses glTF into an XKTModel, supporting .glb and textures.

Usage

In the example below we'll create an XKTModel, then load a binary glTF model into it.

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);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing parameters.

params.data ArrayBuffer

The glTF.

params.baseUri String
  • optional

The base URI used to load this glTF, if any. For resolving relative uris to linked resources.

params.metaModelData Object
  • optional

Metamodel JSON. If this is provided, then parsing is able to ensure that the XKTObjects it creates will fit the metadata properly.

params.xktModel XKTModel

XKTModel to parse into.

params.includeTextures Boolean
  • optional
  • default: true

Whether to parse textures.

params.includeNormals Boolean
  • optional
  • default: 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.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when glTF has been parsed.

public parseGLTFIntoXKTModel(params: Object): Promise source

Parses glTF into an XKTModel, supporting .glb and textures.

Usage

In the example below we'll create an XKTModel, then load a binary glTF model into it.

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);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing parameters.

params.data ArrayBuffer

The glTF.

params.baseUri String
  • optional

The base URI used to load this glTF, if any. For resolving relative uris to linked resources.

params.metaModelData Object
  • optional

Metamodel JSON. If this is provided, then parsing is able to ensure that the XKTObjects it creates will fit the metadata properly.

params.xktModel XKTModel

XKTModel to parse into.

params.includeTextures Boolean
  • optional
  • default: true

Whether to parse textures.

params.includeNormals Boolean
  • optional
  • default: 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.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when glTF has been parsed.

public parseGLTFJSONIntoXKTModel(params: Object): Promise source

import {parseGLTFJSONIntoXKTModel} from '@xeokit/xeokit-convert/src/parsers/parseGLTFJSONIntoXKTModel.js'

Parses glTF JSON into an XKTModel, without .glb and textures.

  • Lightweight JSON-based glTF parser which ignores textures
  • For texture and .glb support, see parseGLTFIntoXKTModel

Usage

In the example below we'll create an XKTModel, then load a glTF model into it.

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);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing parameters.

params.data Object

The glTF JSON.

params.metaModelData Object
  • optional

Metamodel JSON. If this is provided, then parsing is able to ensure that the XKTObjects it creates will fit the metadata properly.

params.xktModel XKTModel

XKTModel to parse into.

params.includeNormals Boolean
  • optional
  • default: 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.

params.reuseGeometries Boolean
  • optional
  • default: 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).

params.getAttachment function
  • optional

Callback through which to fetch attachments, if the glTF has them.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

public parseIFCIntoXKTModel(params: Object): Promise source

Parses IFC STEP file data into an XKTModel.

This function uses 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 XKTModel, then load an IFC model into it.

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);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.WebIFC Object

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.

params.data ArrayBuffer
  • optional

IFC file data.

params.xktModel XKTModel
  • optional

XKTModel to parse into.

params.autoNormals Boolean
  • optional
  • default: 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.

params.includeTypes String[]
  • optional

Option to only convert objects of these types.

params.excludeTypes String[]
  • optional

Option to never convert objects of these types.

params.wasmPath String

Path to web-ifc.wasm, required by this function.

params.stats Object
  • optional
  • default: {}

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when IFC has been parsed.

public parseLASIntoXKTModel(params: Object): Promise source

Parses LAS and LAZ point cloud data into an XKTModel.

This parser handles both the LASER file format (LAS) and its compressed version (LAZ), a public format for the interchange of 3-dimensional point cloud data data, developed for LIDAR mapping purposes.

Usage

In the example below we'll create an XKTModel, then load an LAZ point cloud model into it.

utils.loadArraybuffer("./models/laz/autzen.laz", async (data) => {

    const xktModel = new XKTModel();

    await parseLASIntoXKTModel({
         data,
         xktModel,
         rotateX: true,
         log: (msg) => { console.log(msg); }
    }).then(()=>{
       xktModel.finalize();
    },
    (msg) => {
        console.error(msg);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.data ArrayBuffer

LAS/LAZ file data.

params.xktModel XKTModel

XKTModel to parse into.

params.center boolean
  • optional
  • default: false

Set true to center the LAS point positions to [0,0,0]. This is applied before the transformation matrix, if specified.

params.transform Boolean
  • optional

4x4 transformation matrix to transform point positions. Use this to rotate, translate and scale them if neccessary.

params.colorDepth Number | String
  • optional
  • default: 8

Whether colors encoded using 8 or 16 bits. Can be set to 'auto'. LAS specification recommends 16 bits.

params.fp64 Boolean
  • optional
  • default: false

Configures if LASLoaderPlugin assumes that LAS positions are stored in 64-bit floats instead of 32-bit.

params.skip Number
  • optional
  • default: 1

Read one from every n points.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when LAS has been parsed.

public parseMetaModelIntoXKTModel(params: Object): Promise source

import {parseMetaModelIntoXKTModel} from '@xeokit/xeokit-convert/src/parsers/parseMetaModelIntoXKTModel.js'

Parses JSON metamodel into an XKTModel.

Params:

NameTypeAttributeDescription
params Object

Parsing parameters.

params.metaModelData JSON

Metamodel data.

params.excludeTypes String[]
  • optional

Types to exclude from parsing.

params.includeTypes String[]
  • optional

Types to include in parsing.

params.xktModel XKTModel

XKTModel to parse into.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when JSON has been parsed.

public parsePCDIntoXKTModel(params: Object): Promise source

Parses PCD point cloud data into an XKTModel.

Usage

In the example below we'll create an XKTModel, then load an LAZ point cloud model into it.

utils.loadArraybuffer(""./models/pcd/ism_test_cat.pcd"", async (data) => {

    const xktModel = new XKTModel();

    await parsePCDIntoXKTModel({
         data,
         xktModel,
         log: (msg) => { console.log(msg); }
    }).then(()=>{
       xktModel.finalize();
    },
    (msg) => {
        console.error(msg);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.data ArrayBuffer

PCD file data.

params.littleEndian Boolean
  • optional
  • default: true

Whether PCD binary data is Little-Endian or Big-Endian.

params.xktModel XKTModel

XKTModel to parse into.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when PCD has been parsed.

public async parsePLYIntoXKTModel(params: Object): Promise source

Parses PLY file data into an XKTModel.

Usage

In the example below we'll create an XKTModel, then load a PLY model into it.

utils.loadArraybuffer("./models/ply/test.ply", async (data) => {

    const xktModel = new XKTModel();

    parsePLYIntoXKTModel({data, xktModel}).then(()=>{
       xktModel.finalize();
    },
    (msg) => {
        console.error(msg);
    });
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.data ArrayBuffer

PLY file data.

params.xktModel XKTModel

XKTModel to parse into.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when PLY has been parsed.

public async parseSTLIntoXKTModel(params: Object): Promise source

Parses STL file data into an XKTModel.

  • Supports binary and ASCII STL formats.
  • Option to create a separate XKTEntity for each group of faces that share the same vertex colors.
  • Option to smooth face-aligned normals loaded from STL.
  • Option to reduce XKT file size by ignoring STL normals and relying on xeokit to auto-generate them.

Usage

In the example below we'll create an XKTModel, then load an STL model into it.

utils.loadArraybuffer("./models/stl/binary/spurGear.stl", async (data) => {

    const xktModel = new XKTModel();

    parseSTLIntoXKTModel({data, xktModel});

    xktModel.finalize();
});

Params:

NameTypeAttributeDescription
params Object

Parsing params.

params.data ArrayBuffer | String
  • optional

STL file data. Can be binary or string.

params.autoNormals Boolean
  • optional
  • default: false

When true, the parser will ignore the STL geometry normals, and the STL 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 STL. Overrides smoothNormals when true. This ignores the normals in the STL, and loads no normals from the STL into the XKTModel, resulting in the XKT file storing no normals for the STL model. The xeokit-sdk will then automatically generate the normals within its shaders. The disadvantages are that auto-normals may slow rendering down a little bit, and that the normals can only be face-aligned (and thus rendered using flat shading). The advantages, however, are a smaller XKT file size, and the ability to apply certain geometry optimizations during parsing, such as removing duplicated STL vertex positions, that are not possible when normals are loaded for the STL vertices.

params.smoothNormals Boolean
  • optional
  • default: true

When true, automatically converts face-oriented STL normals to vertex normals, for a smooth appearance. Ignored if autoNormals is true.

params.smoothNormalsAngleThreshold Number
  • optional
  • default: 20

This is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn.

params.splitMeshes Boolean
  • optional
  • default: true

When true, creates a separate XKTEntity for each group of faces that share the same vertex colors. Only works with binary STL (ie. when data is an ArrayBuffer).

params.xktModel XKTModel
  • optional

XKTModel to parse into.

params.stats Object
  • optional

Collects statistics.

params.log function
  • optional

Logging callback.

Return:

Promise

Resolves when STL has been parsed.

public writeXKTModelToArrayBuffer(xktModel: XKTModel, metaModelJSON: String, stats: Object, options: Object): ArrayBuffer source

Writes an XKTModel to an ArrayBuffer.

Params:

NameTypeAttributeDescription
xktModel XKTModel

The XKTModel.

metaModelJSON String

The metamodel JSON in a string.

stats Object
  • optional

Collects statistics.

options Object

Options for how the XKT is written.

options.zip Boolean
  • optional
  • default: true

ZIP the contents?

Return:

ArrayBuffer

The ArrayBuffer.