Skip to main content
Version: Next

Class: Cognite3DViewer<DataSourceT>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:122

Type Parameters​

DataSourceT​

DataSourceT extends DataSourceType = ClassicDataSourceType

Constructors​

Constructor​

new Cognite3DViewer<DataSourceT>(options): Cognite3DViewer<DataSourceT>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:263

Parameters​

options​

Cognite3DViewerOptions

Returns​

Cognite3DViewer<DataSourceT>

Accessors​

cadBudget​

Get Signature​

get cadBudget(): CadModelBudget

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:217

Gets the current budget for downloading geometry for CAD models. Note that this budget is shared between all added CAD models and not a per-model budget.

Returns​

CadModelBudget

Set Signature​

set cadBudget(budget): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:227

Sets the current budget for downloading geometry for CAD models. Note that this budget is shared between all added CAD models and not a per-model budget.

Parameters​
budget​

CadModelBudget

Returns​

void


cameraManager​

Get Signature​

get cameraManager(): CameraManager

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:680

Returns​

CameraManager


canvas​

Get Signature​

get canvas(): HTMLCanvasElement

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:130

Returns the rendering canvas, the DOM element where the renderer draws its output.

Returns​

HTMLCanvasElement


domElement​

Get Signature​

get domElement(): HTMLElement

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:140

The DOM element the viewer will insert its rendering canvas into. The DOM element can be specified in the options when the viewer is created. If not specified, the DOM element will be created automatically. The DOM element cannot be changed after the viewer has been created.

Returns​

HTMLElement


models​

Get Signature​

get models(): CogniteModel<DataSourceT>[]

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:252

Gets a list of models currently added to the viewer.

Returns​

CogniteModel<DataSourceT>[]


pointCloudBudget​

Get Signature​

get pointCloudBudget(): PointCloudBudget

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:237

Returns the point cloud budget. The budget is shared between all loaded point cloud models.

Returns​

PointCloudBudget

Set Signature​

set pointCloudBudget(budget): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:245

Sets the point cloud budget. The budget is shared between all loaded point cloud models.

Parameters​
budget​

PointCloudBudget

Returns​

void


renderParameters​

Get Signature​

get renderParameters(): RenderParameters

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:147

Returns parameters of WebGLRenderer used by the viewer.

Returns​

RenderParameters

Methods​

add360ImageSet()​

Call Signature​

add360ImageSet(datasource, dataModelIdentifier): Promise<Image360Collection<DataSourceT & ClassicDataSourceType>>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:864

Adds a set of 360 images to the scene from the /datamodels API in Cognite Data Fusion.

Parameters​
datasource​

"datamodels"

The data data source which holds the references to the 360 image sets.

dataModelIdentifier​

Image360DataModelIdentifier

The search parameters to apply when querying Cognite Datamodels that contains the 360 images.

Returns​

Promise<Image360Collection<DataSourceT & ClassicDataSourceType>>

Call Signature​

add360ImageSet(datasource, eventFilter, add360ImageOptions?): Promise<Image360Collection<DataSourceT & ClassicDataSourceType>>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:879

Adds a set of 360 images to the scene from the /events API in Cognite Data Fusion.

Parameters​
datasource​

"events"

The CDF data source which holds the references to the 360 image sets.

eventFilter​

The metadata filter to apply when querying events that contains the 360 images.

add360ImageOptions?​

AddImage360Options

Options for behaviours when adding 360 images.

Returns​

Promise<Image360Collection<DataSourceT & ClassicDataSourceType>>

Example​
const eventFilter = { site_id: "12345" };
await viewer.add360ImageSet('events', eventFilter);

addCadModel()​

addCadModel<T>(options): Promise<CogniteCadModel>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:780

Add a new CAD 3D model to the viewer. Call Cognite3DViewer.fitCameraToModel to see the model after the model has loaded.

Type Parameters​

T​

T extends DataSourceType

Parameters​

options​

AddModelOptions<T>

Returns​

Promise<CogniteCadModel>

Example​

const options = {
modelId: 'COGNITE_3D_MODEL_ID',
revisionId: 'COGNITE_3D_REVISION_ID',
};
viewer.addCadModel(options).then(model => {
viewer.fitCameraToModel(model, 0);
});

addCustomObject()​

addCustomObject(customObject): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1134

Beta

Add a CustomObject to the viewer.

Parameters​

customObject​

ICustomObject

Returns​

void

Example​

const sphere = new Mesh(
new SphereGeometry(),
new MeshBasicMaterial()
);
const customObject = CustomObject(sphere);
customObject.isPartOfBoundingBox = false;
viewer.addCustomObject(customObject);

addModel()​

addModel(options): Promise<CogniteModel<DataSourceT>>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:733

Add a new model to the viewer. Call Cognite3DViewer.fitCameraToModel to see the model after the model has loaded.

Parameters​

options​

AddModelOptions<DataSourceT>

Returns​

Promise<CogniteModel<DataSourceT>>

Example​

const options = {
modelId: 'COGNITE_3D_MODEL_ID',
revisionId: 'COGNITE_3D_REVISION_ID',
};
viewer.addModel(options).then(model => {
viewer.fitCameraToModel(model, 0);
});

addObject3D()​

addObject3D(object): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1108

Add a Object3D to the viewer.

Parameters​

object​

Object3D

Returns​

void

Example​

const sphere = new Mesh(
new SphereGeometry(),
new MeshBasicMaterial()
);
viewer.addObject3D(sphere);

addPointCloudModel()​

addPointCloudModel(options): Promise<CognitePointCloudModel<DataSourceT>>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:827

Add a new pointcloud 3D model to the viewer. Call Cognite3DViewer.fitCameraToModel to see the model after the model has loaded.

Parameters​

options​

AddModelOptions<DataSourceT>

Returns​

Promise<CognitePointCloudModel<DataSourceT>>

Example​

const options = {
modelId: 'COGNITE_3D_MODEL_ID',
revisionId: 'COGNITE_3D_REVISION_ID',
};
viewer.addPointCloudModel(options).then(model => {
viewer.fitCameraToModel(model, 0);
});

canDoImage360Action()​

canDoImage360Action(action): boolean

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:981

Beta

Check if a 360 image action can be done.

Parameters​

action​

Image360Action

The action to check if can be done.

Returns​

boolean


createCustomObjectIntersectInput()​

createCustomObjectIntersectInput(pixelCoords): CustomObjectIntersectInput

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1632

Beta

Creates and initialize a CustomObjectIntersectInput to be used by CustomObject.intersectIfCloser method.

Parameters​

pixelCoords​

Vector2

A Vector2 containing pixel coordinates relative to the 3D viewer.

Returns​

CustomObjectIntersectInput

A CustomObjectIntersectInput ready to use.


determineModelType()​

determineModelType(modelId, revisionId): Promise<"" | SupportedModelTypes>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1066

Use to determine of which type the model is.

Parameters​

modelId​

number

The model's id.

revisionId​

number

The model's revision id.

Returns​

Promise<"" | SupportedModelTypes>

Empty string if type is not supported.

Example​

const viewer = new Cognite3DViewer(...);
const type = await viewer.determineModelType(options.modelId, options.revisionId)
let model: CogniteModel
switch (type) {
case 'cad':
model = await viewer.addCadModel(options);
break;
case 'pointcloud':
model = await viewer.addPointCloudModel(options);
break;
default:
throw new Error('Model is not supported');
}
viewer.fitCameraToModel(model);

dispose()​

dispose(): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:463

Dispose of WebGL resources. Can be used to free up memory when the viewer is no longer in use.

Returns​

void

See​

https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects

// Viewer is no longer in use, free up memory
viewer.dispose();

enter360Image()​

enter360Image(image360, revision?): Promise<void>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:956

Enter visualization of a 360 image.

Parameters​

image360​

Image360<DataSourceT>

The 360 image to enter.

revision?​

Image360Revision<DataSourceT>

The image revision to use. If not provided the newest revision will be shown.

Returns​

Promise<void>


exit360Image()​

exit360Image(): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:969

Exit visualization of the 360 image.

Returns​

void


findBestNext360ImageEntity()​

findBestNext360ImageEntity(clickedWorldPosition): Image360WithCollection<DataSourceT> | undefined

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1820

Finds the best next 360 image station to navigate to from the currently entered station, given the world-space position the user clicked.

Returning the station that is most directly "on the way" to where the user clicked.

Parameters​

clickedWorldPosition​

Vector3

World-space position of the user's click (e.g. from a point cloud intersection).

Returns​

Image360WithCollection<DataSourceT> | undefined

The best matching Image360 Entity and its collection, or undefined if not inside a 360 image or no candidates qualify.


fitCameraToBoundingBox()​

fitCameraToBoundingBox(boundingBox, duration?, radiusFactor?): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1410

Move camera to a place where the content of a bounding box is visible to the camera.

Parameters​

boundingBox​

Box3

The bounding box in world space.

duration?​

number

The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.

radiusFactor?​

number = 2

The ratio of the distance from camera to center of box and radius of the box.

Returns​

void

Example​

// Fit camera to bounding box over 500 milliseconds
viewer.fitCameraToBoundingBox(boundingBox, 500);
// Fit camera to bounding box instantaneously
viewer.fitCameraToBoundingBox(boundingBox, 0);
// Place the camera closer to the bounding box
viewer.fitCameraToBoundingBox(boundingBox, 500, 2);

fitCameraToModel()​

fitCameraToModel(model, duration?): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1353

Move camera to a place where the 3D model is visible. It uses the bounding box of the 3D model and calls Cognite3DViewer.fitCameraToBoundingBox.

Parameters​

model​

CogniteModel<DataSourceT>

The 3D model.

duration?​

number

The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.

Returns​

void

Example​

// Fit camera to model
viewer.fitCameraToModel(model);
// Fit camera to model over 500 milliseconds
viewer.fitCameraToModel(model, 500);
// Fit camera to model instantly
viewer.fitCameraToModel(model, 0);

fitCameraToModels()​

fitCameraToModels(models?, duration?, restrictToMostGeometry?): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1368

Move camera to a place where a set of 3D models are visible.

Parameters​

models?​

CogniteModel<DataSourceT>[]

Optional 3D models to focus the camera on. If no models are provided the camera will fit to all models.

duration?​

number

The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.

restrictToMostGeometry?​

boolean = false

If true, attempt to remove junk geometry from the boundingBox to allow setting a good camera position.

Returns​

void


fitCameraToVisualSceneBoundingBox()​

fitCameraToVisualSceneBoundingBox(duration?): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1386

Move camera to a place where a all objects in the scene are visible.

Parameters​

duration?​

number

The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.

Returns​

void


get360AnnotationIntersectionFromPixel()​

get360AnnotationIntersectionFromPixel(offsetX, offsetY): Promise<Image360AnnotationIntersection<DataSourceT> | null>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1804

Check for intersections with 360 annotations through the given pixel. Similar to Cognite3DViewer.getIntersectionFromPixel, but checks 360 image annotations instead of models.

Parameters​

offsetX​

number

offsetY​

number

Returns​

Promise<Image360AnnotationIntersection<DataSourceT> | null>


get360ImageCollections()​

get360ImageCollections(): Image360Collection<DataSourceT>[]

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:918

Returns a list of added 360 image collections.

Returns​

Image360Collection<DataSourceT>[]


getActive360ImageInfo()​

getActive360ImageInfo(): Image360WithCollection<DataSourceT> | undefined

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:925

Returns the currently entered 360 image.

Returns​

Image360WithCollection<DataSourceT> | undefined


getAnyIntersectionFromPixel()​

getAnyIntersectionFromPixel(pixelCoords, options?): Promise<AnyIntersection<DataSourceT> | undefined>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1696

Beta

Raycasting model(s) for finding where the ray intersects with all models, including custom objects.

Parameters​

pixelCoords​

Vector2

Pixel coordinate in pixels (relative to the domElement).

options?​
forceWindowedPick?​

boolean

Skip point-cloud full-frame pick caching for this call.

predicate?​

(customObject) => boolean

Check whether a CustomObject should be intersected.

stopOnHitting360Icon?​

boolean

Returns​

Promise<AnyIntersection<DataSourceT> | undefined>

A promise that if there was an intersection then return the intersection object - otherwise it returns null if there were no intersections.


getClippingPlanes()​

getClippingPlanes(): Plane[]

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1257

Returns the current active global clipping planes.

Returns​

Plane[]

Deprecated​

Use Cognite3DViewer.getGlobalClippingPlanes instead.


getGlobalClippingPlanes()​

getGlobalClippingPlanes(): Plane[]

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1264

Returns the current active global clipping planes.

Returns​

Plane[]


getIntersectionFromPixel()​

getIntersectionFromPixel(offsetX, offsetY): Promise<Intersection<DataSourceT> | null>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1673

Raycasting model(s) for finding where the ray intersects with the model.

Parameters​

offsetX​

number

X coordinate in pixels (relative to the domElement).

offsetY​

number

Y coordinate in pixels (relative to the domElement).

Returns​

Promise<Intersection<DataSourceT> | null>

A promise that if there was an intersection then return the intersection object - otherwise it returns null if there were no intersections.

See​

https://en.wikipedia.org/wiki/Ray_casting For more details on Ray casting.

Examples​

For CAD model

const offsetX = 50 // pixels from the left
const offsetY = 100 // pixels from the top
const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
if (intersection) // it was a hit
console.log(
'You hit model ', intersection.model,
' at the node with tree index ', intersection.treeIndex,
' at this exact point ', intersection.point
);

For point cloud

const offsetX = 50 // pixels from the left
const offsetY = 100 // pixels from the top
const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
if (intersection) // it was a hit
console.log(
'You hit model ', intersection.model,
' at the point index ', intersection.pointIndex,
' at this exact point ', intersection.point
);

getNormalizedPixelCoordinates()​

getNormalizedPixelCoordinates(pixelCoords): Vector2

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1613

Converts a pixel coordinate to normalized device coordinate (in range [-1, 1]).

Parameters​

pixelCoords​

Vector2

A Vector2 containing pixel coordinates relative to the 3D viewer.

Returns​

Vector2

A Vector2 containing the normalized device coordinate (in range [-1, 1]).


getPixelCoordinatesFromEvent()​

getPixelCoordinatesFromEvent(event): Vector2

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1622

Determines clicked or touched pixel coordinate as offset.

Parameters​

event​

PointerEvent | WheelEvent

An PointerEvent or WheelEvent.

Returns​

Vector2

A Vector2 containing pixel coordinates relative to the 3D viewer.


getResolutionOptions()​

getResolutionOptions(): ResolutionOptions

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:411

Get resolution options that are set on the viewer. This includes settings for max resolution and limiting resolution when moving the camera.

Returns​

ResolutionOptions

Options Options that are applied.


getSceneBoundingBox()​

getSceneBoundingBox(): Box3

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1272

Beta

Returns the union of all bounding boxes in reveal, including custom objects.

Returns​

Box3


getScreenshot()​

getScreenshot(width?, height?, includeUI?): Promise<string>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1507

Take a screenshot from the current camera position. When drawing UI, only the viewer DOM element and its children will be included in the image. The DOM is scaled to fit any provided resolution, and as a result some elements can be positioned incorrectly in regards to the 3D render.

html2canvas is used to draw UI and this has some limitations on what CSS properties it is able to render. See the html2canvas documentation for details.

Parameters​

width?​

number = ...

Width of the final image. Default is current canvas size.

height?​

number = ...

Height of the final image. Default is current canvas size.

includeUI?​

boolean = true

If false the screenshot will include only the rendered 3D. Default is true.

Returns​

Promise<string>

A Data URL of the image ('image/png').

Example​

// Take a screenshot with custom resolution
const url = await viewer.getScreenshot(1920, 1080);
// Add a screenshot with resolution of the canvas to the page
const url = await viewer.getScreenshot();
const image = document.createElement('img');
image.src = url;
document.body.appendChild(image);

getVersion()​

getVersion(): string

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:436

Returns reveal version installed.

Returns​

string


getViewState()​

getViewState(): ViewerState

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:697

Gets the current viewer state which includes the camera pose as well as applied styling.

Returns​

ViewerState

JSON object containing viewer state.


getVisualSceneBoundingBox()​

getVisualSceneBoundingBox(): Box3

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1281

Beta

Get the union of bounding box of all visual objects in the Cognite3DViewer.

Returns​

Box3

The visual bounding box of the Cognite3DViewer.


image360Action()​

image360Action(action): Promise<void>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:993

Beta

Do a 360 image action.

Parameters​

action​

Image360Action

The action to do.

Returns​

Promise<void>


loadCameraFromModel()​

loadCameraFromModel(model): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1325

Attempts to load the camera settings from the settings stored for the provided model. See https://docs.cognite.com/api/v1/#operation/get3DRevision and https://docs.cognite.com/api/v1/#operation/update3DRevisions for information on how this setting is retrieved and stored. This setting can also be changed through the 3D models management interface in Cognite Fusion. If no camera configuration is stored in CDF, Cognite3DViewer.fitCameraToModel is used as a fallback.

Parameters​

model​

CogniteModel<DataSourceT>

The model to load camera settings from.

Returns​

void


off()​

Remove event listener from the viewer. Call Cognite3DViewer.on to add event listener.

Param​

event

Param​

callback

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:599

Parameters​
event​

"click" | "hover"

callback​

PointerEventDelegate

Returns​

void

Example​
viewer.off('click', onClick);

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:606

Parameters​
event​

"cameraChange"

callback​

CameraChangeDelegate

Returns​

void

Example​
viewer.off('cameraChange', onCameraChange);

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:613

Parameters​
event​

"cameraStop"

callback​

CameraStopDelegate

Returns​

void

Example​
viewer.off('cameraStop', onCameraStop);

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:617

Unsubscribe the 'beforeSceneRendered'-event previously subscribed with Cognite3DViewer.on.

Parameters​
event​

"beforeSceneRendered"

callback​

BeforeSceneRenderedDelegate

Returns​

void

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:624

Parameters​
event​

"sceneRendered"

callback​

SceneRenderedDelegate

Returns​

void

Example​
viewer.off('sceneRendered', updateStats);

Call Signature​

off(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:631

Parameters​
event​

"disposed"

callback​

DisposedDelegate

Returns​

void

Example​
viewer.off('disposed', clearAll);

on()​

Add event listener to the viewer. Call Cognite3DViewer.off to remove an event listener.

Param​

event

Param​

callback

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:506

Triggered when the viewer is disposed. Listeners should clean up any resources held and remove the reference to the viewer.

Parameters​
event​

"disposed"

callback​

DisposedDelegate

Returns​

void

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:515

Parameters​
event​

"click" | "hover"

callback​

PointerEventDelegate

Returns​

void

Example​
const onClick = (event) => { console.log(event.offsetX, event.offsetY) };
viewer.on('click', onClick);

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:524

Parameters​
event​

"cameraChange"

callback​

CameraChangeDelegate

Returns​

void

Example​
viewer.on('cameraChange', (position, target) => {
console.log('Camera changed: ', position, target);
});

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:533

Parameters​
event​

"cameraStop"

callback​

CameraStopDelegate

Returns​

void

Example​
viewer.on('cameraStop', () => {
console.log('Camera stopped');
});

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:539

Event that is triggered immediately before the scene is rendered.

Parameters​
event​

"beforeSceneRendered"

Metadata about the rendering frame.

callback​

BeforeSceneRenderedDelegate

Callback to trigger when event occurs.

Returns​

void

Call Signature​

on(event, callback): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:545

Event that is triggered immediately after the scene has been rendered.

Parameters​
event​

"sceneRendered"

Metadata about the rendering frame.

callback​

SceneRenderedDelegate

Callback to trigger when the event occurs.

Returns​

void


onClick360Images()​

onClick360Images(event): Promise<boolean>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1749

Beta

Event function to click on 360 images.

Parameters​

event​

PointerEvent

The event type.

Returns​

Promise<boolean>

True if the event was handled, false otherwise.


onHover360Images()​

onHover360Images(event): boolean

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1765

Beta

Event function to move the mouse.

Parameters​

event​

PointerEvent

The event type.

Returns​

boolean

True if the event was handled, false otherwise.


remove360Images()​

remove360Images(...image360Entities): Promise<void>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:934

Remove a set of 360 images.

Parameters​

image360Entities​

...Image360<DataSourceT>[]

Returns​

Promise<void>

Deprecated​


remove360ImageSet()​

remove360ImageSet(imageCollection): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:947

Removes a previously added 360 image collection from the viewer.

Parameters​

imageCollection​

Image360Collection<DataSourceT>

Collection to remove.

Returns​

void


removeCustomObject()​

removeCustomObject(customObject): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1177

Beta

Remove a CustomObject from the viewer.

Parameters​

customObject​

ICustomObject

Returns​

void

Example​

const sphere = new Mesh(new SphereGeometry(), new MeshBasicMaterial());
const customObject = CustomObject(sphere);
viewer.addCustomObject(sphere);
viewer.removeCustomObject(sphere);

removeModel()​

removeModel(model): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1006

Removes a model that was previously added using Cognite3DViewer.addModel, Cognite3DViewer.addCadModel or Cognite3DViewer.addPointCloudModel .

Parameters​

model​

CogniteModel<DataSourceT>

Returns​

void


removeObject3D()​

removeObject3D(object): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1156

Remove a Object3D from the viewer.

Parameters​

object​

Object3D

Returns​

void

Example​

const sphere = new Mesh(new SphereGeometry(), new MeshBasicMaterial());
viewer.addObject3D(sphere);
viewer.removeObject3D(sphere);

requestRedraw()​

requestRedraw(): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1420

Typically used when you perform some changes and can't see them unless you move camera.

Returns​

void


setBackgroundColor()​

setBackgroundColor(backgroundColor): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1194

Sets the color used as the clear color of the renderer.

Parameters​

backgroundColor​
alpha?​

number

color?​

Color

Returns​

void


setCameraManager()​

setCameraManager(cameraManager): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:688

Sets the active camera manager instance for current Cognite3Dviewer.

Parameters​

cameraManager​

CameraManager

Camera manager instance.

Returns​

void


setClippingPlanes()​

setClippingPlanes(clippingPlanes): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1249

Sets per-pixel clipping planes. Pixels behind any of the planes will be sliced away.

Parameters​

clippingPlanes​

Plane[]

Returns​

void

Deprecated​

Use Cognite3DViewer.setGlobalClippingPlanes instead.


setGlobalClippingPlanes()​

setGlobalClippingPlanes(clippingPlanes): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1239

Sets per-pixel clipping planes. Pixels behind any of the planes will be sliced away.

Parameters​

clippingPlanes​

Plane[]

The planes to use for clipping.

Returns​

void

Example​

// Hide pixels with values less than 0 in the x direction
const plane = new Plane(new Vector3(1, 0, 0), 0);
viewer.setGlobalClippingPlanes([plane]);
// Hide pixels with values greater than 20 in the x direction
const plane = new Plane(new Vector3(-1, 0, 0), 20);
viewer.setGlobalClippingPlanes([plane]);
// Hide pixels with values less than 0 in the x direction or greater than 0 in the y direction
const xPlane = new Plane(new Vector3(1, 0, 0), 0);
const yPlane = new Plane(new Vector3(0, -1, 0), 0);
viewer.setGlobalClippingPlanes([xPlane, yPlane]);
// Hide pixels behind an arbitrary, non axis-aligned plane
const plane = new Plane(new Vector3(1.5, 20, -19), 20);
viewer.setGlobalClippingPlanes([plane]);
// Disable clipping planes
viewer.setGlobalClippingPlanes([]);

setLogLevel()​

setLogLevel(level): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:445

Sets the log level. Used for debugging. Defaults to 'none' (which is identical to 'silent').

Parameters​

level​

"error" | "warn" | "none" | "debug" | "trace" | "info" | "silent"

Returns​

void


setResolutionOptions()​

setResolutionOptions(options): void

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:423

Set options to control resolution of the viewer. This includes settings for max resolution and limiting resolution when moving the camera.

Parameters​

options​

ResolutionOptions

Options to apply.

Returns​

void


setViewState()​

setViewState(state): Promise<void>

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:707

Restores camera settings from the state provided, and clears all current styled node collections and applies the state object.

Parameters​

state​

ViewerState

Viewer state retrieved from Cognite3DViewer.getViewState.

Returns​

Promise<void>


worldToScreen()​

worldToScreen(point, normalize?): Vector2 | null

Defined in: packages/api/src/public/migration/Cognite3DViewer.ts:1458

Convert a point in world space to its coordinates in the canvas. This can be used to place HTML objects near 3D objects on top of the 3D viewer.

Parameters​

point​

Vector3

World space coordinate.

normalize?​

boolean

Optional. If true, coordinates are normalized into [0,1]. If false, the values are in the range [0, <canvas_size>).

Returns​

Vector2 | null

Returns 2D coordinates if the point is visible on screen, or null if object is outside screen.

See​

https://www.w3schools.com/graphics/canvas_coordinates.asp For details on HTML Canvas Coordinates.

Example​

const boundingBoxCenter = new Vector3();
// Find center of bounding box in world space
model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
// Screen coordinates of that point
const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
const boundingBoxCenter = new Vector3();
// Find center of bounding box in world space
model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
// Screen coordinates of that point normalized in the range [0,1]
const screenCoordinates = viewer.worldToScreen(boundingBoxCenter, true);
const boundingBoxCenter = new Vector3();
// Find center of bounding box in world space
model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
// Screen coordinates of that point
const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
if (screenCoordinates == null) {
// Object not visible on screen
} else {
// Object is visible on screen
}