Skip to main content
Version: 4.x

Class: CogniteCadModel

@cognite/reveal.CogniteCadModel

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

Implements

Properties

modelId

Readonly modelId: number

The CDF model ID of the model.

Implementation of

CdfModelNodeCollectionDataProvider.modelId

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:75


revisionId

Readonly revisionId: number

The CDF revision ID of the model.

Implementation of

CdfModelNodeCollectionDataProvider.revisionId

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:79


type

Readonly type: SupportedModelTypes = 'cad'

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:26

Accessors

modelUnit

get modelUnit(): "" | WellKnownUnit

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 modelUnitToMetersFactor.

Returns

"" | WellKnownUnit

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:40


modelUnitToMetersFactor

get modelUnitToMetersFactor(): undefined | number

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

undefined | number

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:50


nodeCount

get nodeCount(): number

Returns the number of nodes in the model.

Returns

number

Implementation of

CdfModelNodeCollectionDataProvider.nodeCount

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:458


styledNodeCollections

get styledNodeCollections(): { appearance: NodeAppearance ; nodeCollection: NodeCollection }[]

Returns all currently registered node collections and associated appearance.

Returns

{ appearance: NodeAppearance ; nodeCollection: NodeCollection }[]

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:127


visible

get visible(): boolean

Returns the model visibility.

Returns

boolean

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:68

set visible(value): void

Sets the model visibility.

Example

model.visible = false

Parameters

NameType
valueboolean

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:61

Methods

assignStyledNodeCollection

assignStyledNodeCollection(nodeCollection, appearance): void

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.

Example

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

Parameters

NameTypeDescription
nodeCollectionNodeCollectionDynamic set of nodes to apply the provided appearance to.
appearanceNodeAppearanceAppearance to style the provided set with.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:158


dispose

dispose(): void

Cleans up used resources.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:247


getAncestorTreeIndices

getAncestorTreeIndices(treeIndex, generation): Promise<NumericRange>

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

Parameters

NameTypeDescription
treeIndexnumberTree index of node to find ancestor tree index range for.
generationnumberWhat "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.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:271


getBoundingBoxByNodeId

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

Fetches a bounding box from the CDF by the nodeId.

Example

const box = new THREE.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);

Parameters

NameTypeDescription
nodeIdnumber
box?Box3Optional. Used to write result to.

Returns

Promise<Box3>

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:399


getBoundingBoxByTreeIndex

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

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.

Example

const box = new THREE.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);

Parameters

NameTypeDescription
treeIndexnumberTree index of the node to find bounding box for.
box?Box3Optional preallocated container to hold the bounding box.

Returns

Promise<Box3>

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:434


getCameraConfiguration

getCameraConfiguration(): undefined | CameraConfiguration

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

undefined | CameraConfiguration

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:318


getCdfToDefaultModelTransformation

getCdfToDefaultModelTransformation(out?): Matrix4

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 setModelTransformation

Parameters

NameTypeDescription
out?Matrix4Preallocated THREE.Matrix4 (optional)

Returns

Matrix4

Implementation of

CdfModelNodeCollectionDataProvider.getCdfToDefaultModelTransformation

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:359


getDefaultNodeAppearance

getDefaultNodeAppearance(): NodeAppearance

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

Returns

NodeAppearance

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:120


getModelBoundingBox

getModelBoundingBox(outBbox?, restrictToMostGeometry?): Box3

Determines the full bounding box of the model.

Example

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

Parameters

NameTypeDescription
outBbox?Box3Optional. Used to write result to.
restrictToMostGeometry?booleanOptional. 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.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:302


getModelClippingPlanes

getModelClippingPlanes(): Plane[]

Get the clipping planes for this model.

Returns

Plane[]

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:349


getModelTransformation

getModelTransformation(out?): Matrix4

Gets transformation matrix that has previously been set with setModelTransformation.

Parameters

NameTypeDescription
out?Matrix4Preallocated THREE.Matrix4 (optional).

Returns

Matrix4

Implementation of

CdfModelNodeCollectionDataProvider.getModelTransformation

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:334


getSubtreeTreeIndices

getSubtreeTreeIndices(treeIndex): Promise<NumericRange>

Determines the range of tree indices for a given subtree.

Parameters

NameTypeDescription
treeIndexnumberIndex of the root of the subtree to get the index range for.

Returns

Promise<NumericRange>

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:255


iterateNodesByTreeIndex

iterateNodesByTreeIndex(action): Promise<void>

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).

Example

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

Parameters

NameTypeDescription
action(treeIndex: number) => voidFunction that will be called with a treeIndex argument.

Returns

Promise<void>

Promise that is resolved once the iteration is done.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:451


iterateSubtreeByTreeIndex

iterateSubtreeByTreeIndex(treeIndex, action): Promise<void>

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).

Example

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

Parameters

NameTypeDescription
treeIndexnumberTree index of the top parent of the subtree.
action(treeIndex: number) => voidFunction that will be called with a treeIndex argument.

Returns

Promise<void>

Promise that is resolved once the iteration is done.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:478


mapBoxFromCdfToModelCoordinates

mapBoxFromCdfToModelCoordinates(box, out?): Box3

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

Parameters

NameTypeDescription
boxBox3Box to compute transformation from
outBox3Optional pre-allocated box

Returns

Box3

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:378


mapNodeIdToTreeIndex

mapNodeIdToTreeIndex(nodeId): Promise<number>

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 mapNodeIdsToTreeIndices is recommended for better performance when mapping multiple IDs.

Throws

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

Parameters

NameTypeDescription
nodeIdnumberA Node ID to map to a tree index.

Returns

Promise<number>

TreeIndex of the provided node.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:506


mapNodeIdsToTreeIndices

mapNodeIdsToTreeIndices(nodeIds): Promise<number[]>

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.

Throws

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

Parameters

NameTypeDescription
nodeIdsnumber[]List of node IDs to map to tree indices.

Returns

Promise<number[]>

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

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:492


mapPointFromCdfToModelCoordinates

mapPointFromCdfToModelCoordinates(point, out?): Vector3

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

Parameters

NameTypeDescription
pointVector3Point to compute transformation from
outVector3Optional pre-allocated point

Returns

Vector3

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:368


mapTreeIndexToNodeId

mapTreeIndexToNodeId(treeIndex): Promise<number>

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

Throws

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

Parameters

NameTypeDescription
treeIndexnumberA tree index to map to a Node ID.

Returns

Promise<number>

TreeIndex of the provided node.

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:532


mapTreeIndicesToNodeIds

mapTreeIndicesToNodeIds(treeIndices): Promise<number[]>

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 iterateSubtreeByTreeIndex, and want to perform some operations on these nodes using the SDK.

Throws

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

Parameters

NameTypeDescription
treeIndicesnumber[]Tree indices to map to node IDs.

Returns

Promise<number[]>

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

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:520


removeAllStyledNodeCollections

removeAllStyledNodeCollections(): void

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

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:190


resetNodeTransform

resetNodeTransform(treeIndices): void

Resets the transformation for the nodes given.

Parameters

NameTypeDescription
treeIndicesNumericRangeTree indices of the nodes to reset transforms for.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:229


resetNodeTransformByTreeIndex

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

Remove override transform of the node by tree index.

Parameters

NameTypeDefault value
treeIndexnumberundefined
applyToChildrenbooleantrue

Returns

Promise<number>

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:238


setDefaultNodeAppearance

setDefaultNodeAppearance(appearance): void

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

Parameters

NameTypeDescription
appearanceNodeAppearanceDefault node appearance.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:112


setModelClippingPlanes

setModelClippingPlanes(clippingPlanes): void

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

Parameters

NameType
clippingPlanesPlane[]

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:342


setModelTransformation

setModelTransformation(matrix): void

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

Parameters

NameTypeDescription
matrixMatrix4Transformation matrix.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:326


setNodeTransform

setNodeTransform(treeIndices, transformMatrix): void

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

NameTypeDescription
treeIndicesNumericRangeTree indices of nodes to apply the transformation to.
transformMatrixMatrix4Transformation to apply.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:204


setNodeTransformByTreeIndex

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

Set override transform of the node by tree index.

Parameters

NameTypeDefault value
treeIndexnumberundefined
transformMatrix4undefined
applyToChildrenbooleantrue

Returns

Promise<number>

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:215


unassignStyledNodeCollection

unassignStyledNodeCollection(nodeCollection): void

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

Throws

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

Parameters

NameTypeDescription
nodeCollectionNodeCollectionNode collection previously added using assignStyledNodeCollection.

Returns

void

Defined in

packages/cad-model/src/wrappers/CogniteCadModel.ts:176