Skip to main content
Version: 3.x

Class: Cognite3DModel

@cognite/reveal.Cognite3DModel

Hierarchy​

  • Object3D

    ↳ Cognite3DModel

Implements​

Properties​

modelId​

• Readonly modelId: number

The CDF model ID of the model.

Implementation of​

CdfModelNodeCollectionDataProvider.modelId

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:57


revisionId​

• Readonly revisionId: number

The CDF revision ID of the model.

Implementation of​

CdfModelNodeCollectionDataProvider.revisionId

Defined in​

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


type​

• Readonly type: SupportedModelTypes = 'cad'

Implementation of​

CogniteModelBase.type

Overrides​

THREE.Object3D.type

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.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 @see {@link modelUnitToMetersFactor}.

Returns​

"" | WellKnownUnit

Defined in​

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


modelUnitToMetersFactor​

• get modelUnitToMetersFactor(): 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​

number

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.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/Cognite3DModel.ts:480


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/Cognite3DModel.ts:123

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/Cognite3DModel.ts:154


dispose​

▸ dispose(): void

Cleans up used resources.

Returns​

void

Implementation of​

CogniteModelBase.dispose

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:314


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/Cognite3DModel.ts:339


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/Cognite3DModel.ts:422


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/Cognite3DModel.ts:456


getCameraConfiguration​

▸ getCameraConfiguration(): 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​

CameraConfiguration

Implementation of​

CogniteModelBase.getCameraConfiguration

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:386


getDefaultNodeAppearance​

▸ getDefaultNodeAppearance(): NodeAppearance

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

Returns​

NodeAppearance

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:116


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.

Implementation of​

CogniteModelBase.getModelBoundingBox

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:370


getModelTransformation​

▸ getModelTransformation(out?): Matrix4

Gets transformation matrix of the model.

Parameters​

NameTypeDescription
out?Matrix4Preallocated THREE.Matrix4 (optional).

Returns​

Matrix4

Implementation of​

CogniteModelBase.getModelTransformation

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:402


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/Cognite3DModel.ts:323


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/Cognite3DModel.ts:473


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/Cognite3DModel.ts:500


mapBoxFromCdfToModelCoordinates​

▸ mapBoxFromCdfToModelCoordinates(box, out?): Box3

Maps from a 3D position in "CDF space" to coordinates in "ThreeJS model space". This is necessary because CDF has a right-handed Z-up coordinate system while ThreeJS uses a right-hand Y-up coordinate system. This function also accounts for transformation applied to the model.

Parameters​

NameTypeDescription
boxBox3The box in CDF model coordinates.
out?Box3Optional preallocated buffer for storing the result. May be same input as box.

Returns​

Box3

Transformed box.

Implementation of​

CdfModelNodeCollectionDataProvider.mapBoxFromCdfToModelCoordinates

Defined in​

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


mapBoxFromModelToCdfCoordinates​

▸ mapBoxFromModelToCdfCoordinates(box, out?): Box3

Maps from a 3D position in "ThreeJS model space" to coordinates in "CDF space". This is necessary because CDF has a right-handed Z-up coordinate system while ThreeJS uses a right-hand Y-up coordinate system. This function also accounts for transformation applied to the model.

Parameters​

NameTypeDescription
boxBox3The box in ThreeJS/model coordinates.
out?Box3Optional preallocated buffer for storing the result. May be same input as box.

Returns​

Box3

Transformed box.

Implementation of​

CdfModelNodeCollectionDataProvider.mapBoxFromModelToCdfCoordinates

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:284


mapFromCdfToModelCoordinates​

▸ mapFromCdfToModelCoordinates(p, out?): Vector3

Maps a position retrieved from the CDF API (e.g. 3D node information) to coordinates in "ThreeJS model space". This is necessary because CDF has a right-handed Z-up coordinate system while ThreeJS uses a right-hand Y-up coordinate system.

Parameters​

NameTypeDescription
pVector3The CDF coordinate to transform.
out?Vector3Optional preallocated buffer for storing the result. May be p.

Returns​

Vector3

Transformed position.

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:248


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/Cognite3DModel.ts:528


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/Cognite3DModel.ts:514


mapPositionFromModelToCdfCoordinates​

▸ mapPositionFromModelToCdfCoordinates(p, out?): Vector3

Maps from a 3D position in "ThreeJS model space" (e.g. a ray intersection coordinate) to coordinates in "CDF space". This is necessary because CDF has a right-handed Z-up coordinate system while ThreeJS uses a right-hand Y-up coordinate system. This function also accounts for transformation applied to the model.

Parameters​

NameTypeDescription
pVector3The ThreeJS coordinate to transform.
out?Vector3Optional preallocated buffer for storing the result. May be p.

Returns​

Vector3

Transformed position.

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:266


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/Cognite3DModel.ts:554


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 Cognite3DModel.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/Cognite3DModel.ts:542


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/Cognite3DModel.ts:186


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/Cognite3DModel.ts:225


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/Cognite3DModel.ts:234


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/Cognite3DModel.ts:108


setModelTransformation​

▸ setModelTransformation(matrix): void

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

Parameters​

NameTypeDescription
matrixMatrix4Transformation matrix.

Returns​

void

Implementation of​

CogniteModelBase.setModelTransformation

Defined in​

packages/cad-model/src/wrappers/Cognite3DModel.ts:394


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/Cognite3DModel.ts:200


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/Cognite3DModel.ts:211


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/Cognite3DModel.ts:172