XKTModel
A document model that represents the contents of an .XKT file.
- An XKTModel contains XKTTiles, which spatially subdivide the model into axis-aligned, box-shaped regions.
- Each XKTTile contains XKTEntitys, which represent the objects within its region.
- Each XKTEntity has XKTMeshs, which each have a XKTGeometry. Each XKTGeometry can be shared by multiple XKTMeshs.
- Import models into an XKTModel using parseGLTFJSONIntoXKTModel, parseIFCIntoXKTModel, parseCityJSONIntoXKTModel etc.
- Build an XKTModel programmatically using XKTModel#createGeometry, XKTModel#createMesh and XKTModel#createEntity.
- Serialize an XKTModel to an ArrayBuffer using writeXKTModelToArrayBuffer.
Usage
See main docs page for usage examples.
Constructor Summary
Public Constructor | ||
public |
constructor(cfg: *) Constructs a new XKTModel. |
Member Summary
Public Members | ||
public |
The axis-aligned 3D World-space boundary of this XKTModel. |
|
public |
The model author, if available. |
|
public |
The date the model was created, if available. |
|
public |
The application that created the model, if available. |
|
public |
|
|
public |
Map of XKTEntitys within this XKTModel, each mapped to XKTEntity#entityId. |
|
public |
XKTEntitys within this XKTModel. |
|
public |
Indicates if this XKTModel has been finalized. |
|
public |
geometries: {Number: XKTGeometry} Map of XKTGeometrys within this XKTModel, each mapped to XKTGeometry#geometryId. |
|
public |
List of XKTGeometrys within this XKTModel, in the order they were created. |
|
public |
Map of XKTMeshs within this XKTModel, each mapped to XKTMesh#meshId. |
|
public |
List of XKTMeshs within this XKTModel, in the order they were created. |
|
public |
metaObjects: {String: XKTMetaObject} Map of XKTMetaObjects within this XKTModel, each mapped to XKTMetaObject#metaObjectId. |
|
public |
XKTMetaObjects within this XKTModel. |
|
public |
Minimum diagonal size of the boundary of an XKTTile. |
|
public |
modelAABB: * Optional overall AABB that contains all the XKTEntitys we'll create in this model, if previously known. This is the AABB of a complete set of input files that are provided as a split-model set for conversion. This is used to help the XKTTile.aabbs within split models align neatly with each other, as we build them with a k-d tree in XKTModel#finalize. Without this, the AABBs of the different parts tend to misalign slightly, resulting in excess number of XKTTiles, which degrades memory and rendering performance when the XKT is viewer in the xeokit Viewer. |
|
public |
The model's ID, if available. Will be "default" by default. |
|
public |
The project ID, if available. |
|
public |
propertySets: {String: XKTPropertySet} Map of XKTPropertySets within this XKTModel, each mapped to XKTPropertySet#propertySetId. |
|
public |
XKTPropertySets within this XKTModel. |
|
public |
The positions of all shared XKTGeometrys are de-quantized using this singular de-quantization matrix. |
|
public |
The revision ID, if available. |
|
public |
The model schema version, if available. |
|
public |
textureSets: {Number: XKTTextureSet} Map of XKTTextureSets within this XKTModel, each mapped to XKTTextureSet#textureSetId. |
|
public |
List of XKTTextureSets within this XKTModel, in the order they were created. |
|
public |
textures: {Number: XKTTexture} Map of XKTTextures within this XKTModel, each mapped to XKTTexture#textureId. |
|
public |
List of XKTTextures within this XKTModel, in the order they were created. |
|
public |
XKTTiles within this XKTModel. |
|
public |
The XKT format version. |
Method Summary
Public Methods | ||
public |
Creates a default XKTMetaObject for each XKTEntity that does not already have one. |
|
public |
createEntity(params: *): XKTEntity Creates an XKTEntity within this XKTModel. |
|
public |
createGeometry(params: *): XKTGeometry Creates an XKTGeometry within this XKTModel. |
|
public |
createMesh(params: *): XKTMesh Creates an XKTMesh within this XKTModel. |
|
public |
createMetaObject(params: *): XKTMetaObject Creates an XKTMetaObject within this XKTModel. |
|
public |
createPropertySet(params: *): XKTPropertySet Creates an XKTPropertySet within this XKTModel. |
|
public |
createTexture(params: *): XKTTexture Creates an XKTTexture within this XKTModel. |
|
public |
createTextureSet(params: *): XKTTextureSet Creates an XKTTextureSet within this XKTModel. |
|
public |
async finalize() Finalizes this XKTModel. |
Public Constructors
Public Members
public aabb: Float64Array source
The axis-aligned 3D World-space boundary of this XKTModel.
Created by XKTModel#finalize.
public author: String source
The model author, if available.
Will be an empty string by default.
Properties:
Name | Type | Attribute | Description |
author | * |
public createdAt: String source
The date the model was created, if available.
Will be an empty string by default.
Properties:
Name | Type | Attribute | Description |
createdAt | * |
public creatingApplication: String source
The application that created the model, if available.
Will be an empty string by default.
Properties:
Name | Type | Attribute | Description |
creatingApplication | * |
public entities: {String: XKTEntity} source
Map of XKTEntitys within this XKTModel, each mapped to XKTEntity#entityId.
Created by XKTModel#createEntity.
public entitiesList: XKTEntity[] source
XKTEntitys within this XKTModel.
Each XKTEntity holds its position in this list in XKTEntity#entityIndex.
Created by XKTModel#finalize.
public finalized: boolean source
Indicates if this XKTModel has been finalized.
Set true
by XKTModel#finalize.
public geometries: {Number: XKTGeometry} source
Map of XKTGeometrys within this XKTModel, each mapped to XKTGeometry#geometryId.
Created by XKTModel#createGeometry.
public geometriesList: XKTGeometry[] source
List of XKTGeometrys within this XKTModel, in the order they were created.
Each XKTGeometry holds its position in this list in XKTGeometry#geometryIndex.
Created by XKTModel#finalize.
public meshes: {Number: XKTMesh} source
Map of XKTMeshs within this XKTModel, each mapped to XKTMesh#meshId.
Created by XKTModel#createMesh.
public meshesList: XKTMesh[] source
List of XKTMeshs within this XKTModel, in the order they were created.
Each XKTMesh holds its position in this list in XKTMesh#meshIndex.
Created by XKTModel#finalize.
public metaObjects: {String: XKTMetaObject} source
Map of XKTMetaObjects within this XKTModel, each mapped to XKTMetaObject#metaObjectId.
Created by XKTModel#createMetaObject.
public metaObjectsList: XKTMetaObject[] source
XKTMetaObjects within this XKTModel.
Each XKTMetaObject holds its position in this list in XKTMetaObject#metaObjectIndex.
Created by XKTModel#finalize.
public modelAABB: * source
Optional overall AABB that contains all the XKTEntitys we'll create in this model, if previously known.
This is the AABB of a complete set of input files that are provided as a split-model set for conversion.
This is used to help the XKTTile.aabbs within split models align neatly with each other, as we build them with a k-d tree in XKTModel#finalize. Without this, the AABBs of the different parts tend to misalign slightly, resulting in excess number of XKTTiles, which degrades memory and rendering performance when the XKT is viewer in the xeokit Viewer.
public propertySets: {String: XKTPropertySet} source
Map of XKTPropertySets within this XKTModel, each mapped to XKTPropertySet#propertySetId.
Created by XKTModel#createPropertySet.
public propertySetsList: XKTPropertySet[] source
XKTPropertySets within this XKTModel.
Each XKTPropertySet holds its position in this list in XKTPropertySet#propertySetIndex.
Created by XKTModel#finalize.
public reusedGeometriesDecodeMatrix: Float32Array source
The positions of all shared XKTGeometrys are de-quantized using this singular de-quantization matrix.
This de-quantization matrix is generated from the collective Local-space boundary of the positions of all shared XKTGeometrys.
public schema: String source
The model schema version, if available.
In the case of IFC, this could be "IFC2x3" or "IFC4", for example.
Will be an empty string by default.
Properties:
Name | Type | Attribute | Description |
schema | * |
public textureSets: {Number: XKTTextureSet} source
Map of XKTTextureSets within this XKTModel, each mapped to XKTTextureSet#textureSetId.
Created by XKTModel#createTextureSet.
public textureSetsList: XKTTextureSet[] source
List of XKTTextureSets within this XKTModel, in the order they were created.
Each XKTTextureSet holds its position in this list in XKTTextureSet#textureSetIndex.
Created by XKTModel#finalize.
public textures: {Number: XKTTexture} source
Map of XKTTextures within this XKTModel, each mapped to XKTTexture#textureId.
Created by XKTModel#createTexture.
public texturesList: XKTTexture[] source
List of XKTTextures within this XKTModel, in the order they were created.
Each XKTTexture holds its position in this list in XKTTexture#textureIndex.
Created by XKTModel#finalize.
Public Methods
public createDefaultMetaObjects() source
Creates a default XKTMetaObject for each XKTEntity that does not already have one.
public createEntity(params: *): XKTEntity source
Creates an XKTEntity within this XKTModel.
Registers the new XKTEntity in XKTModel#entities and XKTModel#entitiesList.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
public createGeometry(params: *): XKTGeometry source
Creates an XKTGeometry within this XKTModel.
Registers the new XKTGeometry in XKTModel#geometries and XKTModel#geometriesList.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.geometryId | Number | Unique ID for the XKTGeometry. |
|
params.primitiveType | String | The type of XKTGeometry: "triangles", "lines" or "points". |
|
params.positions | Float64Array | Floating-point Local-space vertex positions for the XKTGeometry. Required for all primitive types. |
|
params.normals | Number[] |
|
Floating-point vertex normals for the XKTGeometry. Only used with triangles primitives. Ignored for points and lines. |
params.colors | Number[] |
|
Floating-point RGBA vertex colors for the XKTGeometry. Required for points primitives. Ignored for lines and triangles. |
params.colorsCompressed | Number[] |
|
Integer RGBA vertex colors for the XKTGeometry. Required for points primitives. Ignored for lines and triangles. |
params.uvs | Number[] |
|
Floating-point vertex UV coordinates for the XKTGeometry. Alias for |
params.uv | Number[] |
|
Floating-point vertex UV coordinates for the XKTGeometry. Alias for |
params.colorsCompressed | Number[] |
|
Integer RGBA vertex colors for the XKTGeometry. Required for points primitives. Ignored for lines and triangles. |
params.indices | Uint32Array |
|
Indices for the XKTGeometry. Required for triangles and lines primitives. Ignored for points. |
params.edgeThreshold | Number |
|
public createMesh(params: *): XKTMesh source
Creates an XKTMesh within this XKTModel.
An XKTMesh can be owned by one XKTEntity, which can own multiple XKTMeshes.
Registers the new XKTMesh in XKTModel#meshes and XKTModel#meshesList.
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.meshId | Number | Unique ID for the XKTMesh. |
|
params.geometryId | Number | ID of an existing XKTGeometry in XKTModel#geometries. |
|
params.textureSetId | Number |
|
Unique ID of an XKTTextureSet in XKTModel#textureSets. |
params.color | Float32Array | RGB color for the XKTMesh, with each color component in range [0..1]. |
|
params.metallic | Number |
|
How metallic the XKTMesh is, in range [0..1]. A value of |
params.roughness | Number |
|
How rough the XKTMesh is, in range [0..1]. A value of |
params.opacity | Number | Opacity factor for the XKTMesh, in range [0..1]. |
|
params.matrix | Float64Array |
|
Modeling matrix for the XKTMesh. Overrides |
params.position | Number[] |
|
Position of the XKTMesh. Overridden by the |
params.scale | Number[] |
|
Scale of the XKTMesh. Overridden by the |
params.rotation | Number[] |
|
Rotation of the XKTMesh as Euler angles given in degrees, for each of the X, Y and Z axis. Overridden by the |
public createMetaObject(params: *): XKTMetaObject source
Creates an XKTMetaObject within this XKTModel.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.metaObjectId | String | Unique ID for the XKTMetaObject. |
|
params.propertySetIds | String | ID of one or more property sets that contains additional metadata about this XKTMetaObject. The property sets could be stored externally (ie not managed at all by the XKT file), or could be XKTPropertySets within XKTModel#propertySets. |
|
params.metaObjectType | String |
|
A meta type for the XKTMetaObject. Can be anything, but is usually an IFC type, such as "IfcSite" or "IfcWall". |
params.metaObjectName | String |
|
Human-readable name for the XKTMetaObject. Defaults to the |
params.parentMetaObjectId | String |
|
ID of the parent XKTMetaObject, if any. Defaults to the |
public createPropertySet(params: *): XKTPropertySet source
Creates an XKTPropertySet within this XKTModel.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.propertySetId | String | Unique ID for the XKTPropertySet. |
|
params.propertySetType | String |
|
A meta type for the XKTPropertySet. |
params.propertySetName | String |
|
Human-readable name for the XKTPropertySet. Defaults to the |
params.properties | String[] | Properties for the XKTPropertySet. |
public createTexture(params: *): XKTTexture source
Creates an XKTTexture within this XKTModel.
Registers the new XKTTexture in XKTModel#textures and XKTModel#texturesList.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.textureId | Number | Unique ID for the XKTTexture. |
|
params.src | String |
|
Source of an image file for the texture. |
params.imageData | Buffer |
|
Image data for the texture. |
params.mediaType | Number |
|
Media type (ie. MIME type) of |
params.width | Number |
|
Texture width, used with |
params.height | Number |
|
Texture height, used with |
params.compressed | Boolean |
|
Whether to compress the texture. |
params.minFilter | Number |
|
How the texture is sampled when a texel covers less than one pixel. Supported values are LinearMipmapLinearFilter, LinearMipMapNearestFilter, NearestMipMapNearestFilter, NearestMipMapLinearFilter and LinearMipMapLinearFilter. Ignored for compressed textures. |
params.magFilter | Number |
|
How the texture is sampled when a texel covers more than one pixel. Supported values are LinearFilter and NearestFilter. Ignored for compressed textures. |
params.wrapS | Number |
|
Wrap parameter for texture coordinate S. Supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Ignored for compressed textures. |
params.wrapT | Number |
|
Wrap parameter for texture coordinate T. Supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Ignored for compressed textures. {@param {Number} [params.wrapR=RepeatWrapping] Wrap parameter for texture coordinate R. Supported values are ClampToEdgeWrapping, MirroredRepeatWrapping and RepeatWrapping. Ignored for compressed textures. |
public createTextureSet(params: *): XKTTextureSet source
Creates an XKTTextureSet within this XKTModel.
Registers the new XKTTextureSet in XKTModel#textureSets and XKTModel#.textureSetsList.
Logs error and does nothing if this XKTModel has been finalized (see XKTModel#finalized).
Params:
Name | Type | Attribute | Description |
params | * | Method parameters. |
|
params.textureSetId | Number | Unique ID for the XKTTextureSet. |
|
params.colorTextureId | * |
|
ID of RGBA base color XKTTexture, with color in RGB and alpha in A. |
params.metallicRoughnessTextureId | * |
|
ID of RGBA metal-roughness XKTTexture, with the metallic factor in R, and roughness factor in G. |
params.normalsTextureId | * |
|
ID of RGBA normal XKTTexture, with normal map vectors in RGB. |
params.emissiveTextureId | * |
|
ID of RGBA emissive XKTTexture, with emissive color in RGB. |
params.occlusionTextureId | * |
|
ID of RGBA occlusion XKTTexture, with occlusion factor in R. |
public async finalize() source
Finalizes this XKTModel.
After finalizing, we may then serialize the model to an array buffer using writeXKTModelToArrayBuffer.
Logs error and does nothing if this XKTModel has already been finalized.
Internally, this method:
- for each XKTEntity that doesn't already have a XKTMetaObject, creates one with XKTMetaObject#metaObjectType set to "default"
- sets each XKTEntity's XKTEntity#hasReusedGeometries true if it shares its XKTGeometrys with other XKTEntitys,
- creates each XKTEntity's XKTEntity#aabb,
- creates XKTTiles in XKTModel#tilesList, and
- sets XKTModel#finalized
true
.