import { Matrix4, Plane, Box3, Vector3 } from 'three'; import { CogniteInternalId } from '@cognite/sdk'; import { SupportedModelTypes } from '../../../model-base'; import { CameraConfiguration, NumericRange } from '../../../utilities'; import { NodeAppearance, NodeCollection, CdfModelNodeCollectionDataProvider } from '../../../cad-styling'; import { WellKnownUnit } from '../types'; /** * Represents a single 3D CAD model loaded from CDF. * @noInheritDoc * @module @cognite/reveal */ export declare class CogniteCadModel implements CdfModelNodeCollectionDataProvider { readonly type: SupportedModelTypes; /** * 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 {@link CogniteCadModel.modelUnitToMetersFactor}. */ get modelUnit(): WellKnownUnit | ''; /** * 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. */ get modelUnitToMetersFactor(): number | undefined; /** * Sets the model visibility. * @example * ```js * model.visible = false * ``` */ set visible(value: boolean); /** * Returns the model visibility. */ get visible(): boolean; /** * The CDF model ID of the model. */ readonly modelId: number; /** * The CDF revision ID of the model. */ readonly revisionId: number; private readonly cadModel; private readonly nodesApiClient; private readonly nodeIdAndTreeIndexMaps; private _styledNodeCollections; private readonly customSectorBounds; /** * Sets the default appearance for nodes that are not styled using * {@link CogniteCadModel.assignStyledNodeCollection}. Updating the default style can be an * expensive operation, so use with care. * * @param appearance Default node appearance. */ setDefaultNodeAppearance(appearance: NodeAppearance): void; /** * Gets the default appearance for nodes that are not styled using * {@link CogniteCadModel.assignStyledNodeCollection}. */ getDefaultNodeAppearance(): NodeAppearance; /** * Returns all currently registered node collections and associated appearance. */ get styledNodeCollections(): { nodeCollection: NodeCollection; appearance: NodeAppearance; }[]; /** * 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 {@link 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. * * @param nodeCollection Dynamic set of nodes to apply the provided appearance to. * @param appearance Appearance to style the provided set with. * @param importance 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. * @example * ```js * model.setDefaultNodeAppearance({ rendererGhosted: true }); * const visibleNodes = new TreeIndexNodeCollection(someTreeIndices); * model.assignStyledNodeCollection(visibleSet, { rendererGhosted: false }); * ``` */ assignStyledNodeCollection(nodeCollection: NodeCollection, appearance: NodeAppearance, importance?: number): void; /** * Removes styling for previously added styled collection, resetting the style to the default (or * the style imposed by other styled collections). * @param nodeCollection Node collection previously added using {@link CogniteCadModel.assignStyledNodeCollection}. * @throws Error if node collection isn't assigned to the model. */ unassignStyledNodeCollection(nodeCollection: NodeCollection): void; /** * Removes all styled collections, resetting the appearance of all nodes to the * default appearance. */ removeAllStyledNodeCollections(): void; /** * 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. * * @param treeIndices Tree indices of nodes whose sectors should be locked. */ lockTreeIndices(treeIndices: number[]): void; /** * Removes the lock for the given tree indices. Sectors that were only * locked because of these tree indices will become eligible for eviction. * * @param treeIndices Tree indices to unlock. */ unlockTreeIndices(treeIndices: number[]): void; /** * Removes all tree-index-based sector locks on this model. */ unlockAllTreeIndices(): 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. * @param treeIndices Tree indices of nodes to apply the transformation to. * @param transformMatrix Transformation to apply. * @param boundingBox Optional bounding box for the nodes before any transformation is applied. If given, it is assumed that all the nodes' geometry fit inside. * @param space Space to apply the transformation in. Defaults to 'world'. */ setNodeTransform(treeIndices: NumericRange, transformMatrix: Matrix4, boundingBox?: Box3, space?: 'model' | 'world'): void; /** * Set override transform of the node by tree index. * @param treeIndex * @param transform * @param applyToChildren * @param space */ setNodeTransformByTreeIndex(treeIndex: number, transform: Matrix4, applyToChildren?: boolean, space?: 'model' | 'world'): Promise; /** * Resets the transformation for the nodes given. * @param treeIndices Tree indices of the nodes to reset transforms for. */ resetNodeTransform(treeIndices: NumericRange): void; /** * Remove override transform of the node by tree index. * @param treeIndex * @param applyToChildren */ resetNodeTransformByTreeIndex(treeIndex: number, applyToChildren?: boolean): Promise; /** * Cleans up used resources. */ dispose(): void; /** * Determines the range of tree indices for a given subtree. * @param treeIndex Index of the root of the subtree to get the index range for. */ getSubtreeTreeIndices(treeIndex: number): Promise; /** * Determines the tree index range of a subtree of an ancestor of the provided * node defined by a tree index. * * @param treeIndex Tree index of node to find ancestor tree index range for. * @param generation 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 Tree index range of the subtree spanned by the ancestor at the * "generation" specified, or the root. */ getAncestorTreeIndices(treeIndex: number, generation: number): Promise; /** * Determines the full bounding box of the model. * @param outBoundingBox Optional. Used to write result to. * @param restrictToMostGeometry 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 Model bounding box. * * @example * ```js * const boundingBox = new Box3() * model.getModelBoundingBox(boundingBox); * // boundingBox now has the bounding box * ``` * ```js * // the following code does the same * const boundingBox = model.getModelBoundingBox(); * ``` */ getModelBoundingBox(outBoundingBox?: Box3, restrictToMostGeometry?: boolean): Box3; /** * 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. */ getCameraConfiguration(): CameraConfiguration | undefined; /** * Sets transformation matrix of the model. This overrides the current transformation. * @param matrix Transformation matrix. */ setModelTransformation(matrix: Matrix4): void; /** * Gets transformation matrix that has previously been set with {@link CogniteCadModel.setModelTransformation}. * @param out Preallocated `Matrix4` (optional). */ getModelTransformation(out?: Matrix4): Matrix4; /** * Sets the clipping planes for this model. They will be combined with the * global clipping planes. */ setModelClippingPlanes(clippingPlanes: Plane[]): void; /** * Get the clipping planes for this model. */ getModelClippingPlanes(): Plane[]; /** * 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 {@link CogniteCadModel.setModelTransformation} * @param out Preallocated `Matrix4` (optional) */ getCdfToDefaultModelTransformation(out?: Matrix4): Matrix4; /** * Map point from CDF to model space, taking the model's custom transformation into account * @param point Point to compute transformation from * @param out Optional pre-allocated point */ mapPointFromCdfToModelCoordinates(point: Vector3, out?: Vector3): Vector3; /** * Map bounding box from CDF to model space, taking the model's custom transformation into account * @param box Box to compute transformation from * @param out Optional pre-allocated box */ mapBoxFromCdfToModelCoordinates(box: Box3, out?: Box3): Box3; /** * Fetches a bounding box from the CDF by the nodeId. * @param nodeId * @param box Optional. Used to write result to. * @example * ```js * const box = new Box3() * const nodeId = 100500; * await model.getBoundingBoxByNodeId(nodeId, box); * // box now has the bounding box *``` * ```js * // the following code does the same * const box = await model.getBoundingBoxByNodeId(nodeId); * ``` */ getBoundingBoxByNodeId(nodeId: number, box?: Box3): Promise; /** * Fetches a bounding box from the CDF by a list of nodeIds. * @param nodeIds * @example * ```js * const box = await model.getBoundingBoxByNodeIds([158239, 192837]); * ``` */ getBoundingBoxesByNodeIds(nodeIds: number[]): Promise; /** * 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. * @param treeIndex Tree index of the node to find bounding box for. * @param box Optional preallocated container to hold the bounding box. * @example * ```js * const box = new Box3() * const treeIndex = 42; * await model.getBoundingBoxByTreeIndex(treeIndex, box); * // box now has the bounding box *``` * ```js * // the following code does the same * const box = await model.getBoundingBoxByTreeIndex(treeIndex); * ``` */ getBoundingBoxByTreeIndex(treeIndex: number, box?: Box3): Promise; /** * 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). * @param action Function that will be called with a treeIndex argument. * @returns Promise that is resolved once the iteration is done. * @example * ```js * const logIndex = (treeIndex) => console.log(treeIndex); * await model.iterateNodesByTreeIndex(logIndex); // 0, 1, 2, ... * ``` */ iterateNodesByTreeIndex(action: (treeIndex: number) => void): Promise; /** * Returns the number of nodes in the model. */ get nodeCount(): number; /** * 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). * @param treeIndex Tree index of the top parent of the subtree. * @param action Function that will be called with a treeIndex argument. * @returns Promise that is resolved once the iteration is done. * @example * ```js * // make a subtree to be gray * await model.iterateNodesByTreeIndex(treeIndex => { * model.setNodeColorByTreeIndex(treeIndex, 127, 127, 127); * }); * ``` */ iterateSubtreeByTreeIndex(treeIndex: number, action: (treeIndex: number) => void): Promise; /** * 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. * * @param nodeIds List of node IDs to map to tree indices. * @returns 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. */ mapNodeIdsToTreeIndices(nodeIds: CogniteInternalId[]): Promise; /** * 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 * {@link CogniteCadModel.mapNodeIdsToTreeIndices} is recommended for better performance when * mapping multiple IDs. * * @param nodeId A Node ID to map to a tree index. * @returns TreeIndex of the provided node. * @throws If an invalid/non-existant node ID is provided the function throws an error. */ mapNodeIdToTreeIndex(nodeId: CogniteInternalId): Promise; /** * 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 * {@link CogniteCadModel.iterateSubtreeByTreeIndex}, and want to perform * some operations on these nodes using the SDK. * * @param treeIndices Tree indices to map to node IDs. * @returns 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. */ mapTreeIndicesToNodeIds(treeIndices: number[]): Promise; /** * Maps a single tree index to node ID for use with the API. If you have multiple * tree indices to map, {@link CogniteCadModel.mapNodeIdsToTreeIndices} is recommended for better * performance. * @param treeIndex A tree index to map to a Node ID. * @returns TreeIndex of the provided node. * @throws If an invalid/non-existent node ID is provided the function throws an error. */ mapTreeIndexToNodeId(treeIndex: number): Promise; /** @private */ private determineTreeIndices; }