@cognite/3d-viewer
Advanced tools
Comparing version 5.2.0-beta.1 to 6.0.1
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
## [6.0.0] - 2019-07-29 | ||
### Added | ||
- IndexDB caching option | ||
- Ability to go through subtree of node and apply action | ||
### Changed | ||
- BREAKING CHANGE: Upgraded 3d viewer to use the latest v1 sdk! | ||
## [5.0.4] - 2019-05-07 | ||
@@ -5,0 +13,0 @@ ### Fixed |
@@ -1,22 +0,17 @@ | ||
import * as THREE from "three"; | ||
import * as THREE from 'three'; | ||
import { CogniteClient } from '@cognite/sdk'; | ||
export { THREE }; | ||
export class Cognite3DViewer { | ||
static isBrowserSupported(): boolean; | ||
domElement: HTMLElement; | ||
constructor(options?: Cognite3DViewerOptions); | ||
domElement: HTMLElement; | ||
static isBrowserSupported(): boolean; | ||
dispose(): void; | ||
on(type: "click", callback: (event: PointerEvent) => void): void; | ||
off(type: "click", callback: (event: PointerEvent) => void): void; | ||
on(type: 'click', callback: (event: PointerEvent) => void): void; | ||
off(type: 'click', callback: (event: PointerEvent) => void): void; | ||
on( | ||
type: "cameraChange", | ||
callback: (position: THREE.Vector3, target: THREE.Vector3) => void | ||
): void; | ||
off( | ||
type: "cameraChange", | ||
callback: (position: THREE.Vector3, target: THREE.Vector3) => void | ||
): void; | ||
on(type: 'cameraChange', callback: (position: THREE.Vector3, target: THREE.Vector3) => void): void; | ||
off(type: 'cameraChange', callback: (position: THREE.Vector3, target: THREE.Vector3) => void): void; | ||
@@ -35,7 +30,3 @@ addModel(options: AddModelOptions): Promise<Cognite3DModel>; | ||
fitCameraToModel(model: Cognite3DModel, duration?: number): void; | ||
fitCameraToBoundingBox( | ||
box: THREE.Box3, | ||
duration?: number, | ||
radiusFactor?: number | ||
): void; | ||
fitCameraToBoundingBox(box: THREE.Box3, duration?: number, radiusFactor?: number): void; | ||
@@ -48,7 +39,3 @@ enableKeyboardNavigation(): void; | ||
getScreenshot(width?: number, height?: number): Promise<string>; | ||
getIntersectionFromPixel( | ||
x: number, | ||
y: number, | ||
cognite3DModel?: Cognite3DModel | ||
): null | Intersection; | ||
getIntersectionFromPixel(x: number, y: number, cognite3DModel?: Cognite3DModel): null | Intersection; | ||
} | ||
@@ -63,2 +50,8 @@ | ||
iterateNodes(action: (nodeId: number, treeIndex?: number) => void): void; | ||
iterateSubtree( | ||
nodeId: number, | ||
action: (nodeId: number, treeIndex?: number) => void, | ||
treeIndex?: number, | ||
subtreeSize?: number | ||
): Promise<boolean>; | ||
@@ -98,3 +91,4 @@ getNodeColor(nodeId: number): Color; | ||
highlightColor?: THREE.Color; | ||
viewCube?: "topleft" | "topright" | "bottomleft" | "bottomright"; | ||
sdk: CogniteClient; | ||
viewCube?: 'topleft' | 'topright' | 'bottomleft' | 'bottomright'; | ||
enableCache: boolean; | ||
@@ -118,2 +112,3 @@ } | ||
revisionId: number; | ||
sdk: CogniteClient; | ||
localPath?: string; | ||
@@ -120,0 +115,0 @@ geometryFilter?: GeometryFilter; |
{ | ||
"name": "@cognite/3d-viewer", | ||
"version": "5.2.0-beta.1", | ||
"version": "6.0.1", | ||
"description": "JavaScript viewer to visualize 3D models on Cognite Data Fusion", | ||
@@ -59,3 +59,3 @@ "contributors": [ | ||
"@cognite/release-manager": "^0.1.78", | ||
"@cognite/sdk": "^1.7.6", | ||
"@cognite/sdk": "2.0.2", | ||
"@cognite/tslint-config-cognite-3d": "^1.0.3", | ||
@@ -104,3 +104,3 @@ "@types/three": "^0.93.28", | ||
"@babel/runtime": "^7.4.4", | ||
"@cognite/3d-web-parser": "^0.12.0", | ||
"@cognite/3d-web-parser": "^0.12.2", | ||
"@cognite/three-combo-controls": "^1.4.1", | ||
@@ -107,0 +107,0 @@ "@tweenjs/tween.js": "^17.2.0", |
345
README.md
@@ -6,12 +6,13 @@ # Cognite REVEAL 3D Web Viewer | ||
_Note: The component will by default send anonymous usage statistics. This is used to improve the 3D viewer. You can opt out from this in the Cognite3DViewer constructor._ | ||
## Table of Contents | ||
- [Install](#install) | ||
- [Cognite Data Fusion](#cognite-data-fusion) | ||
- [Usage](#usage) | ||
- [Sample code](#sample-code) | ||
- [Add progress listeners](#add-progress-listeners) | ||
- [Make the model clickable](#make-the-model-clickable) | ||
- [API Reference](#api-reference) | ||
- [Support](#support) | ||
- [Install](#install) | ||
- [Cognite Data Fusion](#cognite-data-fusion) | ||
- [Usage](#usage) | ||
- [Sample code](#sample-code) | ||
- [Add progress listeners](#add-progress-listeners) | ||
- [Make the model clickable](#make-the-model-clickable) | ||
- [API Reference](#api-reference) | ||
- [Support](#support) | ||
@@ -51,3 +52,3 @@ ## Prerequisites | ||
- [babel-polyfill](https://babeljs.io/docs/en/babel-polyfill) | ||
- [babel-polyfill](https://babeljs.io/docs/en/babel-polyfill) | ||
@@ -60,3 +61,3 @@ ### Sample code | ||
// The viewer will render to a canvas inside a wrapper container. | ||
// You can specify the wrapper by setting options.domElement and passing the options argument | ||
// You can specify the wrapper by setting options.domElement and passing the options argument | ||
// to the Cognite3DViewer constructor. If not set, it will create a div element for you. | ||
@@ -72,4 +73,4 @@ const viewer = new Cognite3DViewer(); | ||
const options = { | ||
modelId, // 3D model id | ||
revisionId, // The model's revision id | ||
modelId, // 3D model id | ||
revisionId, // The model's revision id | ||
}; | ||
@@ -86,3 +87,3 @@ viewer.addModel(options).then(function(model) { | ||
> ```css | ||
> { | ||
> { | ||
> width: 100vw; | ||
@@ -117,6 +118,6 @@ > height: 100vh; | ||
- **See: [getBoundingBox](#getboundingbox)** | ||
- **See: [getIntersectionFromPixel](#getintersectionfrompixel)** | ||
- **See: [fitCameraToBoundingBox](#fitcameratoboundingbox)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
- **See: [getBoundingBox](#getboundingbox)** | ||
- **See: [getIntersectionFromPixel](#getintersectionfrompixel)** | ||
- **See: [fitCameraToBoundingBox](#fitcameratoboundingbox)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
@@ -149,16 +150,16 @@ ```js | ||
```js | ||
const { target, position } = revision.camera; | ||
if (Array.isArray(target) && Array.isArray(position)) { | ||
// Create three.js objects | ||
const positionVector = new THREE.Vector3(...position); | ||
const targetVector = new THREE.Vector3(...target); | ||
// Apply transformation matrix | ||
positionVector.applyMatrix4(model.matrix); | ||
targetVector.applyMatrix4(model.matrix); | ||
// Set on viewer | ||
viewer.setCameraPosition(positionVector); | ||
viewer.setCameraTarget(targetVector); | ||
} else { | ||
viewer.fitCameraToModel(model, 0); | ||
} | ||
const { target, position } = revision.camera; | ||
if (Array.isArray(target) && Array.isArray(position)) { | ||
// Create three.js objects | ||
const positionVector = new THREE.Vector3(...position); | ||
const targetVector = new THREE.Vector3(...target); | ||
// Apply transformation matrix | ||
positionVector.applyMatrix4(model.matrix); | ||
targetVector.applyMatrix4(model.matrix); | ||
// Set on viewer | ||
viewer.setCameraPosition(positionVector); | ||
viewer.setCameraTarget(targetVector); | ||
} else { | ||
viewer.fitCameraToModel(model, 0); | ||
} | ||
``` | ||
@@ -172,39 +173,41 @@ | ||
- [Cognite3DViewer](#cognite3dviewer) | ||
- [Parameters](#parameters) | ||
- [Examples](#examples) | ||
- [dispose](#dispose) | ||
- [domElement](#domelement) | ||
- [isBrowserSupported](#isbrowsersupported) | ||
- [on](#on) | ||
- [off](#off) | ||
- [addModel](#addmodel) | ||
- [addObject3D](#addobject3d) | ||
- [removeObject3D](#removeobject3d) | ||
- [setSlicingPlanes](#setslicingplanes) | ||
- [getCameraPosition](#getcameraposition) | ||
- [getCameraTarget](#getcameratarget) | ||
- [setCameraPosition](#setcameraposition) | ||
- [setCameraTarget](#setcameratarget) | ||
- [fitCameraToBoundingBox](#fitcameratoboundingbox) | ||
- [disableKeyboardNavigation](#disablekeyboardnavigation) | ||
- [enableKeyboardNavigation](#enablekeyboardnavigation) | ||
- [fitCameraToModel](#fitcameratomodel) | ||
- [worldToScreen](#worldtoscreen) | ||
- [getIntersectionFromPixel](#getintersectionfrompixel) | ||
- [getScreenshot](#getscreenshot) | ||
- [Intersection](#intersection) | ||
- [Cognite3DModel](#cognite3dmodel) | ||
- [getSubtreeNodeIds](#getsubtreenodeids) | ||
- [getBoundingBox](#getboundingbox) | ||
- [getNodeColor](#getnodecolor) | ||
- [setNodeColor](#setnodecolor) | ||
- [resetNodeColor](#resetnodecolor) | ||
- [selectNode](#selectnode) | ||
- [deselectNode](#deselectnode) | ||
- [deselectAllNodes](#deselectallnodes) | ||
- [showNode](#shownode) | ||
- [showAllNodes](#showallnodes) | ||
- [hideAllNodes](#hideallnodes) | ||
- [hideNode](#hidenode) | ||
- [Cognite3DViewer](#cognite3dviewer) | ||
- [Parameters](#parameters) | ||
- [Examples](#examples) | ||
- [dispose](#dispose) | ||
- [domElement](#domelement) | ||
- [isBrowserSupported](#isbrowsersupported) | ||
- [on](#on) | ||
- [off](#off) | ||
- [addModel](#addmodel) | ||
- [addObject3D](#addobject3d) | ||
- [removeObject3D](#removeobject3d) | ||
- [setSlicingPlanes](#setslicingplanes) | ||
- [getCameraPosition](#getcameraposition) | ||
- [getCameraTarget](#getcameratarget) | ||
- [setCameraPosition](#setcameraposition) | ||
- [setCameraTarget](#setcameratarget) | ||
- [fitCameraToBoundingBox](#fitcameratoboundingbox) | ||
- [disableKeyboardNavigation](#disablekeyboardnavigation) | ||
- [enableKeyboardNavigation](#enablekeyboardnavigation) | ||
- [fitCameraToModel](#fitcameratomodel) | ||
- [worldToScreen](#worldtoscreen) | ||
- [getIntersectionFromPixel](#getintersectionfrompixel) | ||
- [getScreenshot](#getscreenshot) | ||
- [Intersection](#intersection) | ||
- [Cognite3DModel](#cognite3dmodel) | ||
- [getSubtreeNodeIds](#getsubtreenodeids) | ||
- [getBoundingBox](#getboundingbox) | ||
- [iterateNodes](#iterateNodes) | ||
- [iterateSubtree](#iterateSubtree) | ||
- [getNodeColor](#getnodecolor) | ||
- [setNodeColor](#setnodecolor) | ||
- [resetNodeColor](#resetnodecolor) | ||
- [selectNode](#selectnode) | ||
- [deselectNode](#deselectnode) | ||
- [deselectAllNodes](#deselectallnodes) | ||
- [showNode](#shownode) | ||
- [showAllNodes](#showallnodes) | ||
- [hideAllNodes](#hideallnodes) | ||
- [hideNode](#hidenode) | ||
@@ -217,8 +220,9 @@ ### Cognite3DViewer | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`) | ||
- `options.domElement` **[Element](https://developer.mozilla.org/docs/Web/API/Element)?** \-- An existing DOM element that we will render into. This corresponds to the domElement property below. | ||
- `options.noBackground` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** \-- Transparent background or not (optional, default `false`) | ||
- `options.logMetrics` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \-- Send anonymous usage statistics. (optional, default `true`) | ||
- `options.highlightColor` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \-- Highlight color of the selected objects (optional, default `THREE.Color(0,0,1)`) | ||
- `options.viewCube` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \-- If defined then show a view cube and snap location of the view cube to this value. One of: 'topleft', 'topright', 'bottomleft', 'bottomright'. | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`) | ||
- `options.domElement` **[Element](https://developer.mozilla.org/docs/Web/API/Element)?** \-- An existing DOM element that we will render into. This corresponds to the domElement property below. | ||
- `options.noBackground` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** \-- Transparent background or not (optional, default `false`) | ||
- `options.logMetrics` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \-- Send anonymous usage statistics. (optional, default `true`) | ||
- `options.highlightColor` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** \-- Highlight color of the selected objects (optional, default `THREE.Color(0,0,1)`) | ||
- `options.viewCube` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \-- If defined then show a view cube and snap location of the view cube to this value. One of: 'topleft', 'topright', 'bottomleft', 'bottomright'. | ||
#### Examples | ||
@@ -229,2 +233,3 @@ | ||
noBackground: true, | ||
sdk: <Instance of CogniteClient> | ||
}); | ||
@@ -235,3 +240,3 @@ ``` | ||
- **See: <https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects>** | ||
- **See: <https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects>** | ||
@@ -268,3 +273,3 @@ Dispose of WebGL resources. Can be used to free up memory when the viewer is no longer in use. | ||
- **See: [off](#off)** | ||
- **See: [off](#off)** | ||
@@ -276,4 +281,4 @@ Add event listener to the viewer | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \-- Event type ('click' or 'cameraChange') | ||
- `func` **function (event:PointerEvent)** \-- The callback function | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \-- Event type ('click' or 'cameraChange') | ||
- `func` **function (event:PointerEvent)** \-- The callback function | ||
@@ -295,3 +300,3 @@ ##### Examples | ||
- **See: [on](#on)** | ||
- **See: [on](#on)** | ||
@@ -303,4 +308,4 @@ Remove event listener from the viewer | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \-- Event type ('click' or 'cameraChange') | ||
- `func` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** \-- The callback function used in [on](#on) | ||
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \-- Event type ('click' or 'cameraChange') | ||
- `func` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** \-- The callback function used in [on](#on) | ||
@@ -319,8 +324,8 @@ ##### Examples | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`) | ||
- `options.modelId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The model's id | ||
- `options.revisionId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The model's revision id | ||
- `options.geometryFilter` { boundingBox?: **THREE.Box3** } \-- Filter out geometries. We currently only support bounding box filter, i.e. load only geometries inside the given bounding box. | ||
- `options.onProgress` **function (progress: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))?** \-- Callback for progress events | ||
- `options.onComplete` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** \-- Callback when the model is fully loaded | ||
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`) | ||
- `options.modelId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The model's id | ||
- `options.revisionId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The model's revision id | ||
- `options.geometryFilter` { boundingBox?: **THREE.Box3** } \-- Filter out geometries. We currently only support bounding box filter, i.e. load only geometries inside the given bounding box. | ||
- `options.onProgress` **function (progress: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))?** \-- Callback for progress events | ||
- `options.onComplete` **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)?** \-- Callback when the model is fully loaded | ||
@@ -332,4 +337,4 @@ ##### Examples | ||
const options = { | ||
modelId: 'COGNITE_3D_MODEL_ID', | ||
revisionId: 'COGNITE_3D_REVISION_ID', | ||
modelId: 'COGNITE_3D_MODEL_ID', | ||
revisionId: 'COGNITE_3D_REVISION_ID', | ||
}; | ||
@@ -349,5 +354,5 @@ viewer.addModel(options).then(model => { | ||
const options = { | ||
modelId: 'COGNITE_3D_MODEL_ID', | ||
revisionId: 'COGNITE_3D_REVISION_ID', | ||
geometryFilter: { boundingBox } | ||
modelId: 'COGNITE_3D_MODEL_ID', | ||
revisionId: 'COGNITE_3D_REVISION_ID', | ||
geometryFilter: { boundingBox }, | ||
}; | ||
@@ -363,3 +368,3 @@ | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cognite3DModel](#cognite3dmodel)>** | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Cognite3DModel](#cognite3dmodel)>** | ||
@@ -372,3 +377,3 @@ #### addObject3D | ||
- `object` **THREE.Object3D** \-- A three.js object | ||
- `object` **THREE.Object3D** \-- A three.js object | ||
@@ -378,3 +383,6 @@ ##### Examples | ||
```javascript | ||
const sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(), new THREE.MeshBasicMaterial()); | ||
const sphere = new THREE.Mesh( | ||
new THREE.SphereBufferGeometry(), | ||
new THREE.MeshBasicMaterial() | ||
); | ||
viewer.addObject3D(sphere); | ||
@@ -389,3 +397,3 @@ ``` | ||
- `object` **THREE.Object3D** \-- A three.js object | ||
- `object` **THREE.Object3D** \-- A three.js object | ||
@@ -395,3 +403,6 @@ ##### Examples | ||
```javascript | ||
const sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(), new THREE.MeshBasicMaterial()); | ||
const sphere = new THREE.Mesh( | ||
new THREE.SphereBufferGeometry(), | ||
new THREE.MeshBasicMaterial() | ||
); | ||
viewer.addObject3D(sphere); | ||
@@ -407,3 +418,3 @@ viewer.removeObject3D(sphere); | ||
- `slicingPlanes` **THREE.Plane[]** \-- The planes to use for slicing | ||
- `slicingPlanes` **THREE.Plane[]** \-- The planes to use for slicing | ||
@@ -472,3 +483,3 @@ ##### Examples | ||
- `position` **THREE.Vector3** \-- Position in world space | ||
- `position` **THREE.Vector3** \-- Position in world space | ||
@@ -492,3 +503,3 @@ ##### Examples | ||
- `target` **THREE.Vector3** \-- Target in world space | ||
- `target` **THREE.Vector3** \-- Target in world space | ||
@@ -507,10 +518,11 @@ ##### Examples | ||
#### fitCameraToBoundingBox | ||
- **See: [getBoundingBox](#getboundingbox)** | ||
Move camera to a place where the content of a bounding box is visible to the camera. | ||
- **See: [getBoundingBox](#getboundingbox)** | ||
Move camera to a place where the content of a bounding box is visible to the camera. | ||
##### Parameters | ||
- `box` **THREE.Box3** \-- The bounding box in world space | ||
- `duration` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The duration of the animation moving the camera. Set this to 0 (zero) to disable animation. | ||
- `radiusFactor` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The ratio of the distance from camera to center of box and radius of the box (optional, default `4`) | ||
- `box` **THREE.Box3** \-- The bounding box in world space | ||
- `duration` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The duration of the animation moving the camera. Set this to 0 (zero) to disable animation. | ||
- `radiusFactor` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- The ratio of the distance from camera to center of box and radius of the box (optional, default `4`) | ||
@@ -543,3 +555,3 @@ ##### Examples | ||
- **See: [enableKeyboardNavigation](#enablekeyboardnavigation)** | ||
- **See: [enableKeyboardNavigation](#enablekeyboardnavigation)** | ||
@@ -559,3 +571,3 @@ Disables camera navigation with the keyboard. | ||
- **See: [disableKeyboardNavigation](#disablekeyboardnavigation)** | ||
- **See: [disableKeyboardNavigation](#disablekeyboardnavigation)** | ||
@@ -596,8 +608,8 @@ Enables camera navigation with the keyboard. | ||
- `model` **[Cognite3DModel](#cognite3dmodel)** \-- The 3D model | ||
- `duration` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Same as for [fitCameraToBoundingBox](#fitcameratoboundingbox) | ||
- `model` **[Cognite3DModel](#cognite3dmodel)** \-- The 3D model | ||
- `duration` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Same as for [fitCameraToBoundingBox](#fitcameratoboundingbox) | ||
#### worldToScreen | ||
- **See: <https://www.w3schools.com/graphics/canvas_coordinates.asp>** | ||
- **See: <https://www.w3schools.com/graphics/canvas_coordinates.asp>** | ||
@@ -608,4 +620,4 @@ 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. | ||
- `point` **THREE.Vector3** \-- World space coordinate. | ||
- `normalize` **bool?** \-- Optional. If true, coordinates are normalized into [0,1]. If false, the values are in the range \[0, <canvas_size>). (optional, default `false`) | ||
- `point` **THREE.Vector3** \-- World space coordinate. | ||
- `normalize` **bool?** \-- Optional. If true, coordinates are normalized into [0,1]. If false, the values are in the range \[0, <canvas_size>). (optional, default `false`) | ||
@@ -654,5 +666,5 @@ ##### Examples | ||
- `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- X coordinate in pixels (relative to the domElement) | ||
- `y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- Y coordinate in pixels (relative to the domElement) | ||
- `cognite3DModel` **[Cognite3DModel](#cognite3dmodel)?** \-- If specified then only give results for this model | ||
- `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- X coordinate in pixels (relative to the domElement) | ||
- `y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- Y coordinate in pixels (relative to the domElement) | ||
- `cognite3DModel` **[Cognite3DModel](#cognite3dmodel)?** \-- If specified then only give results for this model | ||
@@ -663,4 +675,12 @@ ##### Examples | ||
const intersection = viewer.getIntersectionFromPixel(50, 100); // x = 50 pixels from the left, y = 100 pixels from the top | ||
if (intersection) // it was a hit | ||
console.log('You hit model ', intersection.model, ' at the node with id ', intersection.nodeId, ' at this exact point ', intersection.point); | ||
if (intersection) | ||
// it was a hit | ||
console.log( | ||
'You hit model ', | ||
intersection.model, | ||
' at the node with id ', | ||
intersection.nodeId, | ||
' at this exact point ', | ||
intersection.point | ||
); | ||
``` | ||
@@ -691,4 +711,4 @@ | ||
- `width` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Width of the final image. Default is current canvas size. | ||
- `height` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Height of the final image. Default is current canvas size. | ||
- `width` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Width of the final image. Default is current canvas size. | ||
- `height` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- Height of the final image. Default is current canvas size. | ||
@@ -703,5 +723,5 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** A [Blob URL](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL) to the image ('image/png') | ||
- `model` **[Cognite3DModel](#cognite3dmodel)** \-- The node id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The nodeId of the first intersected node | ||
- `point` **THREE.Vector3** \-- The 3D position of the intersection point in the world coordinate system | ||
- `model` **[Cognite3DModel](#cognite3dmodel)** \-- The node id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The nodeId of the first intersected node | ||
- `point` **THREE.Vector3** \-- The 3D position of the intersection point in the world coordinate system | ||
@@ -728,4 +748,4 @@ ### Cognite3DModel | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The ID of the root node | ||
- `subtreeSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- If you already know the subtreeSize, this will avoid an extra API call | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The ID of the root node | ||
- `subtreeSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** \-- If you already know the subtreeSize, this will avoid an extra API call | ||
@@ -740,4 +760,4 @@ Returns **\[[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)]** List of nodeIds in the subtree | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `box` **THREE.Box3?** \-- Optional target. Specify this to increase performance if the box can be reused. | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `box` **THREE.Box3?** \-- Optional target. Specify this to increase performance if the box can be reused. | ||
@@ -756,7 +776,42 @@ ##### Examples | ||
Returns **THREE.Box3** | ||
Returns **THREE.Box3** | ||
#### iterateNodes | ||
Go through the node tree and apply an action to each node that has a node ID. | ||
##### Examples | ||
```javascript | ||
const url = await model.iterateNodes(console.log); | ||
``` | ||
##### Parameters | ||
- `action` **Callback** \-- Callback function taking in a nodeId and treeId | ||
Returns **void** | ||
#### iterateSubtree | ||
Go through the subtree a node of the tree and apply an action to each subtree node that has a node ID. | ||
##### Examples | ||
```javascript | ||
const url = await viewer.iterateSubtree(1111111111, console.log); | ||
``` | ||
##### Parameters | ||
- `nodeId` **number** \-- The id of the node whose subtree will have action applied to | ||
- `action` **Callback** \-- Callback function taking in a nodeId and treeId | ||
- `treeIndex?` **number** \-- (Optional) The index within the tree for the given nodeId | ||
- `subtreeSiuze?` **number** \-- (Optional) The size of the subtree starting from nodeId | ||
Returns **Promise<boolean>** Whether a valid nodeId was given or not | ||
#### getNodeColor | ||
- **See: [setNodeColor](#setnodecolor)** | ||
- **See: [setNodeColor](#setnodecolor)** | ||
@@ -767,3 +822,3 @@ Return the color on a node. | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
@@ -774,3 +829,3 @@ Returns **{r: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), g: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), b: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}** (r, g, b in the range [0, 255]) | ||
- **See: [getNodeColor](#getnodecolor)** | ||
- **See: [getNodeColor](#getnodecolor)** | ||
@@ -781,6 +836,6 @@ Set the color on a node. | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `r` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The red color value (0-255) | ||
- `g` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The green color value (0-255) | ||
- `b` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The blue color value (0-255) | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `r` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The red color value (0-255) | ||
- `g` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The green color value (0-255) | ||
- `b` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The blue color value (0-255) | ||
@@ -793,8 +848,8 @@ #### resetNodeColor | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
#### selectNode | ||
- **See: [deselectNode](#deselectnode)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
- **See: [deselectNode](#deselectnode)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
@@ -805,8 +860,8 @@ Mark a node as selected. Only visible nodes can be selected. | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
#### deselectNode | ||
- **See: [selectNode](#selectnode)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
- **See: [selectNode](#selectnode)** | ||
- **See: [deselectAllNodes](#deselectallnodes)** | ||
@@ -817,3 +872,3 @@ Mark a node as deselected. | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
@@ -830,3 +885,3 @@ #### deselectAllNodes | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
@@ -843,3 +898,3 @@ #### showAllNodes | ||
- `ghost` **bool** \-- Hide with ghost effect (optional, default `false`) | ||
- `ghost` **bool** \-- Hide with ghost effect (optional, default `false`) | ||
@@ -852,4 +907,4 @@ #### hideNode | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `ghost` **bool** \-- Hide with ghost effect (optional, default `false`) | ||
- `nodeId` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** \-- The node's id | ||
- `ghost` **bool** \-- Hide with ghost effect (optional, default `false`) | ||
@@ -856,0 +911,0 @@ ## Support |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
214137
2
867
94
4