Skip to main content
Version: Next

Class: CogniteCadModel

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:30

Provides metadata needed to get asset mappings for a CDF 3D model

Implements​

Properties​

modelId​

readonly modelId: number

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:80

The CDF model ID of the model.

Implementation of​

CdfModelNodeCollectionDataProvider.modelId


revisionId​

readonly revisionId: number

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:84

The CDF revision ID of the model.

Implementation of​

CdfModelNodeCollectionDataProvider.revisionId


type​

readonly type: SupportedModelTypes = 'cad'

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:31

Accessors​

modelUnit​

Get Signature​

get modelUnit(): "" | WellKnownUnit

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:45

Returns the unit the coordinates for the model is stored. Returns an empty string if no unit has been stored. Note that coordinates in Reveal always are converted to meters using CogniteCadModel.modelUnitToMetersFactor.

Returns​

"" | WellKnownUnit


modelUnitToMetersFactor​

Get Signature​

get modelUnitToMetersFactor(): number | undefined

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:55

Returns the conversion factor that converts from model coordinates to meters. Note that this can return undefined if the model has been stored in an unsupported unit.

Returns​

number | undefined


nodeCount​

Get Signature​

get nodeCount(): number

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:574

Returns the number of nodes in the model.

Returns​

number

Total count of nodes in the model

Implementation of​

CdfModelNodeCollectionDataProvider.nodeCount


styledNodeCollections​

Get Signature​

get styledNodeCollections(): object[]

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:148

Returns all currently registered node collections and associated appearance.

Returns​

object[]


visible​

Get Signature​

get visible(): boolean

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:73

Returns the model visibility.

Returns​

boolean

Set Signature​

set visible(value): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:66

Sets the model visibility.

Example​
model.visible = false
Parameters​
value​

boolean

Returns​

void

Methods​

assignStyledNodeCollection()​

assignStyledNodeCollection(nodeCollection, appearance, importance?): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:180

Customizes rendering style for a set of nodes, e.g. to highlight, hide or color code a set of 3D objects. This allows for custom look and feel of the 3D model which is useful to highlight certain parts or to color code the 3D model based on information (e.g. coloring the 3D model by construction status).

The NodeCollection can be updated dynamically and the rendered nodes will be updated automatically as the styling changes. The appearance of the style nodes cannot be changed.

When nodes are in several styled sets, the style is combined in the order the sets were added, i.e. styled sets added late can overwrite styled sets added early.

If the nodeCollection provided already has an assigned style, this style will be replaced with style provided.

Parameters​

nodeCollection​

NodeCollection

Dynamic set of nodes to apply the provided appearance to.

appearance​

NodeAppearance

Appearance to style the provided set with.

importance?​

number = 0

The importance of this style. Can be used to manually order the order of styles, this can avoid the order of adding styles affecting the outcome. Optional and defaults to 0.

Returns​

void

Example​

model.setDefaultNodeAppearance({ rendererGhosted: true });
const visibleNodes = new TreeIndexNodeCollection(someTreeIndices);
model.assignStyledNodeCollection(visibleSet, { rendererGhosted: false });

dispose()​

dispose(): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:350

Cleans up used resources.

Returns​

void


getAncestorTreeIndices()​

getAncestorTreeIndices(treeIndex, generation): Promise<NumericRange>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:374

Determines the tree index range of a subtree of an ancestor of the provided node defined by a tree index.

Parameters​

treeIndex​

number

Tree index of node to find ancestor tree index range for.

generation​

number

What "generation" to find. 0 is the node itself, 1 means parent, 2 means grandparent etc. If the node doesn't have as many ancestors, the root of the model is returned. This can be determined by checking that the range returned includes 0.

Returns​

Promise<NumericRange>

Tree index range of the subtree spanned by the ancestor at the "generation" specified, or the root.


getBoundingBoxByNodeId()​

getBoundingBoxByNodeId(nodeId, box?): Promise<Box3>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:504

Fetches a bounding box from the CDF by the nodeId.

Parameters​

nodeId​

number

box?​

Box3

Optional. Used to write result to.

Returns​

Promise<Box3>

Example​

const box = new Box3()
const nodeId = 100500;
await model.getBoundingBoxByNodeId(nodeId, box);
// box now has the bounding box
// the following code does the same
const box = await model.getBoundingBoxByNodeId(nodeId);

getBoundingBoxByTreeIndex()​

getBoundingBoxByTreeIndex(treeIndex, box?): Promise<Box3>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:550

Determine the bounding box of the node identified by the tree index provided. Note that this function uses the CDF API to look up the bounding box.

Parameters​

treeIndex​

number

Tree index of the node to find bounding box for.

box?​

Box3

Optional preallocated container to hold the bounding box.

Returns​

Promise<Box3>

Example​

const box = new Box3()
const treeIndex = 42;
await model.getBoundingBoxByTreeIndex(treeIndex, box);
// box now has the bounding box
// the following code does the same
const box = await model.getBoundingBoxByTreeIndex(treeIndex);

getBoundingBoxesByNodeIds()​

getBoundingBoxesByNodeIds(nodeIds): Promise<Box3[]>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:519

Fetches a bounding box from the CDF by a list of nodeIds.

Parameters​

nodeIds​

number[]

Returns​

Promise<Box3[]>

Example​

const box = await model.getBoundingBoxByNodeIds([158239, 192837]);

getCameraConfiguration()​

getCameraConfiguration(): CameraConfiguration | undefined

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:421

Retrieves the camera position and target stored for the model. Typically this is used to store a good starting position for a model. Returns undefined if there isn't any stored camera configuration for the model.

Returns​

CameraConfiguration | undefined


getCdfToDefaultModelTransformation()​

getCdfToDefaultModelTransformation(out?): Matrix4

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:464

Gets transformation from CDF space to ThreeJS space, which includes any additional "default" transformations assigned to this model. Does not include any custom transformations set by CogniteCadModel.setModelTransformation

Parameters​

out?​

Matrix4

Preallocated Matrix4 (optional)

Returns​

Matrix4

Implementation of​

CdfModelNodeCollectionDataProvider.getCdfToDefaultModelTransformation


getDefaultNodeAppearance()​

getDefaultNodeAppearance(): NodeAppearance

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:141

Gets the default appearance for nodes that are not styled using CogniteCadModel.assignStyledNodeCollection.

Returns​

NodeAppearance


getModelBoundingBox()​

getModelBoundingBox(outBoundingBox?, restrictToMostGeometry?): Box3

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:405

Determines the full bounding box of the model.

Parameters​

outBoundingBox?​

Box3

Optional. Used to write result to.

restrictToMostGeometry?​

boolean

Optional. When true, returned bounds are restricted to where most of the geometry is located. This is useful for models that have junk geometry located far from the "main" model. Added in version 1.3.0.

Returns​

Box3

Model bounding box.

Example​

const boundingBox = new Box3()
model.getModelBoundingBox(boundingBox);
// boundingBox now has the bounding box
// the following code does the same
const boundingBox = model.getModelBoundingBox();

getModelClippingPlanes()​

getModelClippingPlanes(): Plane[]

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:454

Get the clipping planes for this model.

Returns​

Plane[]


getModelTransformation()​

getModelTransformation(out?): Matrix4

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:439

Gets transformation matrix that has previously been set with CogniteCadModel.setModelTransformation.

Parameters​

out?​

Matrix4

Preallocated Matrix4 (optional).

Returns​

Matrix4

Implementation of​

CdfModelNodeCollectionDataProvider.getModelTransformation


getSubtreeTreeIndices()​

getSubtreeTreeIndices(treeIndex): Promise<NumericRange>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:358

Determines the range of tree indices for a given subtree.

Parameters​

treeIndex​

number

Index of the root of the subtree to get the index range for.

Returns​

Promise<NumericRange>


iterateNodesByTreeIndex()​

iterateNodesByTreeIndex(action): Promise<void>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:567

Iterates over all nodes in the model and applies the provided action to each node (identified by tree index). The passed action is applied incrementally to avoid main thread blocking, meaning that the changes can be partially applied until promise is resolved (iteration is done).

Parameters​

action​

(treeIndex) => void

Function that will be called with a treeIndex argument.

Returns​

Promise<void>

Promise that is resolved once the iteration is done.

Example​

const logIndex = (treeIndex) => console.log(treeIndex);
await model.iterateNodesByTreeIndex(logIndex); // 0, 1, 2, ...

iterateSubtreeByTreeIndex()​

iterateSubtreeByTreeIndex(treeIndex, action): Promise<void>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:594

Iterates over all nodes in a subtree of the model and applies the provided action to each node (identified by tree index). The provided node is included in the visited set. The passed action is applied incrementally to avoid main thread blocking, meaning that the changes can be partially applied until promise is resolved (iteration is done).

Parameters​

treeIndex​

number

Tree index of the top parent of the subtree.

action​

(treeIndex) => void

Function that will be called with a treeIndex argument.

Returns​

Promise<void>

Promise that is resolved once the iteration is done.

Example​

// make a subtree to be gray
await model.iterateNodesByTreeIndex(treeIndex => {
model.setNodeColorByTreeIndex(treeIndex, 127, 127, 127);
});

lockTreeIndices()​

lockTreeIndices(treeIndices): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:226

Locks the sectors containing the given tree indices so they are never evicted when the CAD budget is reduced. The lock is reactive: if a tree index's geometry is later discovered in a new sector (when that sector loads), the new sector is automatically locked as well.

Parameters​

treeIndices​

number[]

Tree indices of nodes whose sectors should be locked.

Returns​

void


mapBoxFromCdfToModelCoordinates()​

mapBoxFromCdfToModelCoordinates(box, out?): Box3

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:483

Map bounding box from CDF to model space, taking the model's custom transformation into account

Parameters​

box​

Box3

Box to compute transformation from

out?​

Box3 = ...

Optional pre-allocated box

Returns​

Box3


mapNodeIdsToTreeIndices()​

mapNodeIdsToTreeIndices(nodeIds): Promise<number[]>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:608

Maps a list of Node IDs to tree indices. This function is useful when you have a list of nodes, e.g. from Asset Mappings, that you want to highlight, hide, color etc in the viewer.

Parameters​

nodeIds​

number[]

List of node IDs to map to tree indices.

Returns​

Promise<number[]>

A list of tree indices corresponing to the elements in the input.

Throws​

If an invalid/non-existant node ID is provided the function throws an error.


mapNodeIdToTreeIndex()​

mapNodeIdToTreeIndex(nodeId): Promise<number>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:622

Maps a single node ID to tree index. This is useful when you e.g. have a node ID from an asset mapping and want to highlight the given asset using CogniteCadModel.mapNodeIdsToTreeIndices is recommended for better performance when mapping multiple IDs.

Parameters​

nodeId​

number

A Node ID to map to a tree index.

Returns​

Promise<number>

TreeIndex of the provided node.

Throws​

If an invalid/non-existant node ID is provided the function throws an error.


mapPointFromCdfToModelCoordinates()​

mapPointFromCdfToModelCoordinates(point, out?): Vector3

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:473

Map point from CDF to model space, taking the model's custom transformation into account

Parameters​

point​

Vector3

Point to compute transformation from

out?​

Vector3 = ...

Optional pre-allocated point

Returns​

Vector3


mapTreeIndexToNodeId()​

mapTreeIndexToNodeId(treeIndex): Promise<number>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:648

Maps a single tree index to node ID for use with the API. If you have multiple tree indices to map, CogniteCadModel.mapNodeIdsToTreeIndices is recommended for better performance.

Parameters​

treeIndex​

number

A tree index to map to a Node ID.

Returns​

Promise<number>

TreeIndex of the provided node.

Throws​

If an invalid/non-existent node ID is provided the function throws an error.


mapTreeIndicesToNodeIds()​

mapTreeIndicesToNodeIds(treeIndices): Promise<number[]>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:636

Maps a list of tree indices to node IDs for use with the Cognite SDK. This function is useful if you have a list of tree indices, e.g. from CogniteCadModel.iterateSubtreeByTreeIndex, and want to perform some operations on these nodes using the SDK.

Parameters​

treeIndices​

number[]

Tree indices to map to node IDs.

Returns​

Promise<number[]>

A list of node IDs corresponding to the elements of the input.

Throws​

If an invalid tree index is provided the function throws an error.


removeAllStyledNodeCollections()​

removeAllStyledNodeCollections(): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:213

Removes all styled collections, resetting the appearance of all nodes to the default appearance.

Returns​

void


resetNodeTransform()​

resetNodeTransform(treeIndices): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:328

Resets the transformation for the nodes given.

Parameters​

treeIndices​

NumericRange

Tree indices of the nodes to reset transforms for.

Returns​

void


resetNodeTransformByTreeIndex()​

resetNodeTransformByTreeIndex(treeIndex, applyToChildren?): Promise<number>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:341

Remove override transform of the node by tree index.

Parameters​

treeIndex​

number

applyToChildren?​

boolean = true

Returns​

Promise<number>


setDefaultNodeAppearance()​

setDefaultNodeAppearance(appearance): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:133

Sets the default appearance for nodes that are not styled using CogniteCadModel.assignStyledNodeCollection. Updating the default style can be an expensive operation, so use with care.

Parameters​

appearance​

NodeAppearance

Default node appearance.

Returns​

void


setModelClippingPlanes()​

setModelClippingPlanes(clippingPlanes): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:447

Sets the clipping planes for this model. They will be combined with the global clipping planes.

Parameters​

clippingPlanes​

Plane[]

Returns​

void


setModelTransformation()​

setModelTransformation(matrix): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:429

Sets transformation matrix of the model. This overrides the current transformation.

Parameters​

matrix​

Matrix4

Transformation matrix.

Returns​

void


setNodeTransform()​

setNodeTransform(treeIndices, transformMatrix, boundingBox?, space?): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:258

Apply a transformation matrix to the tree indices given, changing rotation, scale and/or position.

Note that setting multiple transformations for the same node isn't supported and might lead to undefined results.

Parameters​

treeIndices​

NumericRange

Tree indices of nodes to apply the transformation to.

transformMatrix​

Matrix4

Transformation to apply.

boundingBox?​

Box3

Optional bounding box for the nodes before any transformation is applied. If given, it is assumed that all the nodes' geometry fit inside.

space?​

"model" | "world"

Space to apply the transformation in. Defaults to 'world'.

Returns​

void


setNodeTransformByTreeIndex()​

setNodeTransformByTreeIndex(treeIndex, transform, applyToChildren?, space?): Promise<number>

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:312

Set override transform of the node by tree index.

Parameters​

treeIndex​

number

transform​

Matrix4

applyToChildren?​

boolean = true

space?​

"model" | "world"

Returns​

Promise<number>


unassignStyledNodeCollection()​

unassignStyledNodeCollection(nodeCollection): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:199

Removes styling for previously added styled collection, resetting the style to the default (or the style imposed by other styled collections).

Parameters​

nodeCollection​

NodeCollection

Node collection previously added using CogniteCadModel.assignStyledNodeCollection.

Returns​

void

Throws​

Error if node collection isn't assigned to the model.


unlockAllTreeIndices()​

unlockAllTreeIndices(): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:243

Removes all tree-index-based sector locks on this model.

Returns​

void


unlockTreeIndices()​

unlockTreeIndices(treeIndices): void

Defined in: packages/cad-model/src/wrappers/CogniteCadModel.ts:236

Removes the lock for the given tree indices. Sectors that were only locked because of these tree indices will become eligible for eviction.

Parameters​

treeIndices​

number[]

Tree indices to unlock.

Returns​

void