@cognite/reveal 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/core/cad.d.ts +4 -5
  2. package/core/index.d.ts +7 -7
  3. package/core/src/datamodels/base/SupportedModelTypes.d.ts +4 -4
  4. package/core/src/datamodels/base/index.d.ts +6 -6
  5. package/core/src/datamodels/base/types.d.ts +14 -14
  6. package/core/src/datamodels/cad/CadManager.d.ts +45 -43
  7. package/core/src/datamodels/cad/CadModelFactory.d.ts +7 -7
  8. package/core/src/datamodels/cad/CadModelSectorLoadStatistics.d.ts +38 -38
  9. package/core/src/datamodels/cad/createCadManager.d.ts +9 -10
  10. package/core/src/datamodels/cad/picking.d.ts +28 -28
  11. package/core/src/datamodels/cad/rendering/RenderAlreadyLoadedGeometryProvider.d.ts +10 -9
  12. package/core/src/datamodels/cad/sector/CadModelClipper.d.ts +10 -10
  13. package/core/src/datamodels/cad/styling/AssetNodeCollection.d.ts +39 -39
  14. package/core/src/datamodels/cad/styling/InvertedNodeCollection.d.ts +24 -24
  15. package/core/src/datamodels/cad/styling/NodeCollectionDeserializer.d.ts +26 -26
  16. package/core/src/datamodels/cad/styling/PopulateIndexSetFromPagedResponseHelper.d.ts +24 -24
  17. package/core/src/datamodels/cad/styling/PropertyFilterNodeCollection.d.ts +61 -61
  18. package/core/src/datamodels/cad/styling/SinglePropertyFilterNodeCollection.d.ts +60 -60
  19. package/core/src/datamodels/cad/styling/index.d.ts +8 -8
  20. package/core/src/datamodels/pointcloud/PointCloudFactory.d.ts +9 -9
  21. package/core/src/datamodels/pointcloud/PointCloudManager.d.ts +26 -25
  22. package/core/src/datamodels/pointcloud/PointCloudMetadata.d.ts +11 -11
  23. package/core/src/datamodels/pointcloud/PointCloudMetadataRepository.d.ts +13 -13
  24. package/core/src/datamodels/pointcloud/PointCloudNode.d.ts +62 -62
  25. package/core/src/datamodels/pointcloud/PotreeGroupWrapper.d.ts +39 -39
  26. package/core/src/datamodels/pointcloud/PotreeNodeWrapper.d.ts +38 -38
  27. package/core/src/datamodels/pointcloud/createPointCloudManager.d.ts +6 -8
  28. package/core/src/datamodels/pointcloud/index.d.ts +5 -0
  29. package/core/src/datamodels/pointcloud/picking.d.ts +29 -29
  30. package/core/src/datamodels/pointcloud/types.d.ts +114 -114
  31. package/core/src/index.d.ts +19 -19
  32. package/core/src/internals.d.ts +15 -0
  33. package/core/src/migration.d.ts +8 -8
  34. package/core/src/public/RevealManager.d.ts +64 -61
  35. package/core/src/public/createRevealManager.d.ts +23 -24
  36. package/core/src/public/migration/Cognite3DModel.d.ts +339 -323
  37. package/core/src/public/migration/Cognite3DViewer.d.ts +555 -545
  38. package/core/src/public/migration/CogniteModelBase.d.ts +17 -17
  39. package/core/src/public/migration/CognitePointCloudModel.d.ts +121 -121
  40. package/core/src/public/migration/NodeIdAndTreeIndexMaps.d.ts +4 -4
  41. package/core/src/public/migration/NotSupportedInMigrationWrapperError.d.ts +11 -11
  42. package/core/src/public/migration/RenderController.d.ts +4 -4
  43. package/core/src/public/migration/types.d.ts +266 -240
  44. package/core/src/public/types.d.ts +46 -45
  45. package/core/src/{public/migration → storage}/RevealManagerHelper.d.ts +58 -58
  46. package/core/src/utilities/BoundingBoxClipper.d.ts +23 -23
  47. package/core/src/utilities/Spinner.d.ts +27 -28
  48. package/core/src/utilities/ViewStateHelper.d.ts +33 -33
  49. package/core/src/utilities/callActionWithIndicesAsync.d.ts +4 -4
  50. package/core/src/utilities/index.d.ts +8 -8
  51. package/core/src/utilities/reflection.d.ts +7 -7
  52. package/core/src/utilities/worldToViewport.d.ts +30 -31
  53. package/core/utilities.d.ts +4 -4
  54. package/extensions/datasource.d.ts +9 -0
  55. package/extensions/datasource.js +33 -0
  56. package/extensions/datasource.map +1 -0
  57. package/index.d.ts +8 -8
  58. package/index.js +142 -130
  59. package/index.map +1 -1
  60. package/package.json +1 -1
  61. package/packages/cad-geometry-loaders/index.d.ts +14 -20
  62. package/packages/cad-geometry-loaders/src/CadLoadingHints.d.ts +11 -11
  63. package/packages/cad-geometry-loaders/src/CadModelSectorBudget.d.ts +26 -26
  64. package/packages/cad-geometry-loaders/src/CadModelUpdateHandler.d.ts +44 -44
  65. package/packages/cad-geometry-loaders/src/sector/CachedRepository.d.ts +25 -25
  66. package/packages/cad-geometry-loaders/src/sector/ModelStateHandler.d.ts +12 -12
  67. package/packages/cad-geometry-loaders/src/sector/Repository.d.ts +9 -9
  68. package/packages/cad-geometry-loaders/src/sector/SectorLoader.d.ts +28 -28
  69. package/packages/cad-geometry-loaders/src/sector/SimpleAndDetailedToSector3D.d.ts +20 -20
  70. package/packages/cad-geometry-loaders/src/sector/culling/ByVisibilityGpuSectorCuller.d.ts +53 -53
  71. package/packages/cad-geometry-loaders/src/sector/culling/OccludingGeometryProvider.d.ts +6 -6
  72. package/packages/cad-geometry-loaders/src/sector/culling/OrderSectorsByVisibilityCoverage.d.ts +107 -107
  73. package/packages/cad-geometry-loaders/src/sector/culling/SectorCuller.d.ts +33 -33
  74. package/packages/cad-geometry-loaders/src/sector/culling/TakenSectorTree.d.ts +24 -24
  75. package/packages/cad-geometry-loaders/src/sector/culling/types.d.ts +71 -71
  76. package/packages/cad-geometry-loaders/src/sector/rxSectorUtilities.d.ts +12 -12
  77. package/packages/cad-geometry-loaders/src/sector/sectorUtilities.d.ts +20 -19
  78. package/packages/cad-geometry-loaders/src/utilities/PromiseUtils.d.ts +18 -18
  79. package/packages/cad-geometry-loaders/src/utilities/arrays.d.ts +5 -5
  80. package/packages/cad-geometry-loaders/src/utilities/groupMeshesByNumber.d.ts +8 -8
  81. package/packages/cad-geometry-loaders/src/utilities/rxOperations.d.ts +5 -5
  82. package/packages/cad-geometry-loaders/src/utilities/types.d.ts +25 -48
  83. package/packages/cad-parsers/index.d.ts +21 -20
  84. package/packages/cad-parsers/src/cad/CadSectorParser.d.ts +15 -15
  85. package/packages/cad-parsers/src/cad/LevelOfDetail.d.ts +8 -8
  86. package/packages/{cad-geometry-loaders/src/material-manager/rendering → cad-parsers/src/cad}/filterInstanceMesh.d.ts +6 -6
  87. package/packages/cad-parsers/src/cad/filterPrimitives.d.ts +9 -9
  88. package/packages/cad-parsers/src/cad/primitiveGeometries.d.ts +31 -31
  89. package/packages/{cad-geometry-loaders/src/material-manager/rendering → cad-parsers/src/cad}/triangleMeshes.d.ts +6 -6
  90. package/packages/cad-parsers/src/cad/types.d.ts +56 -56
  91. package/packages/cad-parsers/src/metadata/CadMetadataParser.d.ts +7 -7
  92. package/packages/cad-parsers/src/metadata/CadModelMetadata.d.ts +44 -44
  93. package/packages/cad-parsers/src/metadata/CadModelMetadataRepository.d.ts +16 -16
  94. package/packages/cad-parsers/src/metadata/MetadataRepository.d.ts +7 -6
  95. package/packages/cad-parsers/src/metadata/parsers/CadMetadataParserV8.d.ts +51 -51
  96. package/packages/cad-parsers/src/metadata/types.d.ts +41 -41
  97. package/packages/{cad-geometry-loaders → cad-parsers}/src/sector/RootSectorNode.d.ts +12 -12
  98. package/packages/{cad-geometry-loaders → cad-parsers}/src/sector/SectorNode.d.ts +21 -21
  99. package/packages/cad-parsers/src/utilities/SectorScene.d.ts +21 -21
  100. package/packages/cad-parsers/src/utilities/SectorSceneFactory.d.ts +12 -12
  101. package/packages/cad-parsers/src/{cad → utilities}/computeBoundingBoxFromAttributes.d.ts +9 -9
  102. package/packages/{cad-geometry-loaders → cad-parsers}/src/utilities/float32BufferToMatrix.d.ts +12 -12
  103. package/packages/cad-parsers/src/utilities/types.d.ts +48 -48
  104. package/packages/cad-styling/index.d.ts +9 -9
  105. package/packages/cad-styling/src/CombineNodeCollectionBase.d.ts +31 -31
  106. package/packages/cad-styling/src/IntersectionNodeCollection.d.ts +15 -15
  107. package/packages/cad-styling/src/NodeAppearance.d.ts +62 -62
  108. package/packages/cad-styling/src/NodeAppearanceProvider.d.ts +29 -29
  109. package/packages/cad-styling/src/NodeCollectionBase.d.ts +47 -47
  110. package/packages/cad-styling/src/TreeIndexNodeCollection.d.ts +23 -23
  111. package/packages/cad-styling/src/UnionNodeCollection.d.ts +15 -15
  112. package/packages/camera-manager/index.d.ts +4 -4
  113. package/packages/camera-manager/src/ComboControls.d.ts +84 -83
  114. package/packages/camera-manager/src/Keyboard.d.ts +14 -14
  115. package/packages/data-source/index.d.ts +6 -0
  116. package/packages/data-source/src/CdfDataSource.d.ts +19 -0
  117. package/packages/data-source/src/DataSource.d.ts +26 -0
  118. package/packages/data-source/src/LocalDataSource.d.ts +15 -0
  119. package/packages/logger/index.d.ts +5 -5
  120. package/packages/logger/src/Log.d.ts +5 -5
  121. package/packages/metrics/index.d.ts +5 -0
  122. package/packages/metrics/src/MetricsLogger.d.ts +21 -0
  123. package/packages/metrics/src/types.d.ts +7 -0
  124. package/packages/modeldata-api/index.d.ts +13 -8
  125. package/packages/modeldata-api/src/{CdfModelDataClient.d.ts → CdfModelDataProvider.d.ts} +15 -17
  126. package/packages/modeldata-api/src/CdfModelIdentifier.d.ts +17 -0
  127. package/packages/modeldata-api/src/CdfModelMetadataProvider.d.ts +19 -36
  128. package/packages/modeldata-api/src/CdfModelOutputsProvider.d.ts +15 -0
  129. package/packages/modeldata-api/src/{LocalModelDataClient.d.ts → LocalModelDataProvider.d.ts} +9 -10
  130. package/packages/modeldata-api/src/LocalModelIdentifier.d.ts +14 -0
  131. package/packages/modeldata-api/src/LocalModelMetadataProvider.d.ts +14 -19
  132. package/packages/modeldata-api/src/Model3DOutputList.d.ts +17 -17
  133. package/packages/modeldata-api/src/ModelIdentifier.d.ts +12 -0
  134. package/packages/modeldata-api/src/ModelMetadataProvider.d.ts +17 -0
  135. package/packages/modeldata-api/src/applyDefaultModelTransformation.d.ts +6 -6
  136. package/packages/modeldata-api/src/types.d.ts +41 -55
  137. package/packages/modeldata-api/src/utilities.d.ts +7 -7
  138. package/packages/nodes-api/index.d.ts +6 -7
  139. package/packages/nodes-api/src/NodesApiClient.d.ts +52 -43
  140. package/packages/nodes-api/src/NodesCdfClient.d.ts +24 -19
  141. package/packages/nodes-api/src/NodesLocalClient.d.ts +30 -25
  142. package/packages/nodes-api/src/types.d.ts +10 -14
  143. package/packages/rendering/index.d.ts +17 -0
  144. package/packages/{cad-geometry-loaders/src/material-manager → rendering/src}/CadMaterialManager.d.ts +37 -37
  145. package/packages/{cad-geometry-loaders → rendering}/src/InstancedMeshManager.d.ts +20 -20
  146. package/packages/{cad-geometry-loaders → rendering}/src/cameraconfig.d.ts +12 -12
  147. package/packages/{cad-geometry-loaders/src/material-manager → rendering/src}/rendering/EffectRenderManager.d.ts +99 -83
  148. package/packages/{cad-geometry-loaders/src/material-manager/styling → rendering/src/rendering}/NodeAppearanceTextureBuilder.d.ts +51 -50
  149. package/packages/{cad-parsers/src/cad → rendering/src/rendering}/RenderMode.d.ts +15 -15
  150. package/packages/{cad-geometry-loaders/src/material-manager → rendering/src}/rendering/createSimpleGeometryMesh.d.ts +6 -6
  151. package/packages/{cad-parsers/src/cad → rendering/src/rendering}/matCapTextureData.d.ts +5 -5
  152. package/packages/{cad-parsers/src/cad → rendering/src/rendering}/materials.d.ts +23 -23
  153. package/packages/{cad-parsers/src/cad → rendering/src/rendering}/primitives.d.ts +12 -12
  154. package/packages/{cad-parsers/src/cad → rendering/src/rendering}/shaders.d.ts +101 -101
  155. package/packages/{cad-geometry-loaders/src/material-manager → rendering/src}/rendering/types.d.ts +76 -76
  156. package/packages/{cad-geometry-loaders/src → rendering/src/sector}/CadNode.d.ts +54 -54
  157. package/packages/{cad-geometry-loaders/src/material-manager/styling → rendering/src/transform}/NodeTransformProvider.d.ts +13 -13
  158. package/packages/{cad-geometry-loaders/src/material-manager/styling → rendering/src/transform}/NodeTransformTextureBuilder.d.ts +23 -23
  159. package/packages/{cad-geometry-loaders/src/material-manager/styling → rendering/src/transform}/TransformOverrideBuffer.d.ts +21 -21
  160. package/packages/rendering/src/utilities/types.d.ts +26 -0
  161. package/packages/tools/index.d.ts +15 -12
  162. package/packages/tools/src/AxisView/AxisViewTool.d.ts +32 -32
  163. package/packages/tools/src/AxisView/types.d.ts +98 -98
  164. package/packages/tools/src/Cognite3DViewerToolBase.d.ts +25 -25
  165. package/packages/tools/src/DebugCameraTool.d.ts +20 -20
  166. package/packages/tools/src/DebugLoadedSectorsTool.d.ts +23 -23
  167. package/packages/tools/src/ExplodedViewTool.d.ts +12 -12
  168. package/packages/tools/src/Geomap/Geomap.d.ts +14 -14
  169. package/packages/tools/src/Geomap/GeomapTool.d.ts +21 -21
  170. package/packages/tools/src/Geomap/MapConfig.d.ts +195 -195
  171. package/packages/tools/src/HtmlOverlay/BucketGrid2D.d.ts +28 -0
  172. package/packages/tools/src/HtmlOverlay/HtmlOverlayTool.d.ts +159 -0
  173. package/packages/tools/src/Timeline/Keyframe.d.ts +38 -0
  174. package/packages/tools/src/Timeline/TimelineTool.d.ts +79 -0
  175. package/packages/tools/src/Timeline/types.d.ts +13 -0
  176. package/packages/tools/src/types.d.ts +4 -4
  177. package/packages/utilities/index.d.ts +24 -24
  178. package/packages/utilities/src/CameraConfiguration.d.ts +10 -10
  179. package/packages/utilities/src/IndexSet.d.ts +1 -1
  180. package/packages/utilities/src/NumericRange.d.ts +21 -21
  181. package/packages/utilities/src/RandomColors.d.ts +34 -0
  182. package/packages/utilities/src/WebGLRendererStateHelper.d.ts +15 -15
  183. package/packages/utilities/src/assertNever.d.ts +7 -7
  184. package/packages/utilities/src/cache/MemoryRequestCache.d.ts +22 -22
  185. package/packages/utilities/src/cache/MostFrequentlyUsedCache.d.ts +19 -19
  186. package/packages/utilities/src/cache/RequestCache.d.ts +13 -13
  187. package/packages/utilities/src/datastructures/DynamicDefragmentedBuffer.d.ts +22 -22
  188. package/packages/utilities/src/determinePowerOfTwoDimensions.d.ts +11 -11
  189. package/packages/utilities/src/disposeAttributeArrayOnUpload.d.ts +17 -17
  190. package/packages/utilities/src/events/EventTrigger.d.ts +13 -13
  191. package/packages/utilities/src/events/clickOrTouchEventOffset.d.ts +13 -13
  192. package/packages/utilities/src/events/index.d.ts +5 -5
  193. package/packages/utilities/src/indexset/IndexSet.d.ts +26 -26
  194. package/packages/utilities/src/indexset/IntermediateIndexNode.d.ts +26 -26
  195. package/packages/utilities/src/indexset/LeafIndexNode.d.ts +16 -16
  196. package/packages/utilities/src/isMobileOrTablet.d.ts +4 -4
  197. package/packages/utilities/src/networking/isTheSameDomain.d.ts +11 -11
  198. package/packages/utilities/src/objectTraversal.d.ts +8 -8
  199. package/packages/utilities/src/packFloat.d.ts +6 -6
  200. package/packages/utilities/src/revealEnv.d.ts +10 -10
  201. package/packages/utilities/src/three/AutoDisposeGroup.d.ts +17 -17
  202. package/packages/utilities/src/three/BoundingBoxLOD.d.ts +27 -27
  203. package/packages/utilities/src/three/getBox3CornerPoints.d.ts +5 -5
  204. package/packages/utilities/src/transformCameraConfiguration.d.ts +6 -6
  205. package/packages/utilities/src/types.d.ts +10 -10
  206. package/packages/utilities/src/workers/WorkerPool.d.ts +14 -14
  207. package/tools.d.ts +7 -7
  208. package/tools.js +70 -123
  209. package/tools.map +1 -1
  210. package/packages/tools/src/HtmlOverlayTool.d.ts +0 -88
  211. package/packages/utilities/src/metrics.d.ts +0 -15
@@ -1,545 +1,555 @@
1
- /*!
2
- * Copyright 2021 Cognite AS
3
- */
4
- import * as THREE from 'three';
5
- import { AddModelOptions, Cognite3DViewerOptions, Intersection, CameraChangeDelegate, PointerEventDelegate, CadModelBudget, PointCloudBudget } from './types';
6
- import { CogniteModelBase } from './CogniteModelBase';
7
- import { Cognite3DModel } from './Cognite3DModel';
8
- import { CognitePointCloudModel } from './CognitePointCloudModel';
9
- import { DisposedDelegate, SceneRenderedDelegate } from '../types';
10
- import { SupportedModelTypes } from '../../datamodels/base';
11
- import { IntersectionFromPixelOptions } from '../..';
12
- import { ViewerState } from '../../utilities/ViewStateHelper';
13
- import ComboControls from '../../../../packages/camera-manager';
14
- /**
15
- * @example
16
- * ```js
17
- * const viewer = new Cognite3DViewer({
18
- * noBackground: true,
19
- * sdk: CogniteClient({...})
20
- * });
21
- * ```
22
- * @module @cognite/reveal
23
- */
24
- export declare class Cognite3DViewer {
25
- private readonly _viewStateHelper;
26
- private get canvas();
27
- /**
28
- * For now it just always returns true.
29
- * @see Https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#Browser_compatibility.
30
- */
31
- static isBrowserSupported(): true;
32
- /**
33
- * The DOM element the viewer will insert its rendering canvas into.
34
- * The DOM element can be specified in the options when the viewer is created.
35
- * If not specified, the DOM element will be created automatically.
36
- * The DOM element cannot be changed after the viewer has been created.
37
- */
38
- get domElement(): HTMLElement;
39
- /**
40
- * Returns the renderer used to produce images from 3D geometry.
41
- */
42
- get renderer(): THREE.WebGLRenderer;
43
- private readonly camera;
44
- private readonly scene;
45
- private readonly controls;
46
- private readonly sdkClient;
47
- private readonly _subscription;
48
- private readonly _revealManagerHelper;
49
- private readonly _domElement;
50
- private readonly _renderer;
51
- private readonly _boundAnimate;
52
- private readonly _events;
53
- private readonly _models;
54
- private readonly _extraObjects;
55
- private readonly _automaticNearFarPlane;
56
- private readonly _automaticControlsSensitivity;
57
- private isDisposed;
58
- private readonly renderController;
59
- private latestRequestId;
60
- private readonly clock;
61
- private _clippingNeedsUpdate;
62
- private readonly spinner;
63
- private get revealManager();
64
- /**
65
- * Reusable buffers used by functions in Cognite3dViewer to avoid allocations.
66
- */
67
- private readonly _updateNearAndFarPlaneBuffers;
68
- /**
69
- * Gets the current budget for downloading geometry for CAD models. Note that this
70
- * budget is shared between all added CAD models and not a per-model budget.
71
- */
72
- get cadBudget(): CadModelBudget;
73
- /**
74
- * Sets the current budget for downloading geometry for CAD models. Note that this
75
- * budget is shared between all added CAD models and not a per-model budget.
76
- */
77
- set cadBudget(budget: CadModelBudget);
78
- /**
79
- * Returns the point cloud budget. The budget is shared between all loaded
80
- * point cloud models.
81
- */
82
- get pointCloudBudget(): PointCloudBudget;
83
- /**
84
- * Sets the point cloud budget. The budget is shared between all loaded
85
- * point cloud models.
86
- */
87
- set pointCloudBudget(budget: PointCloudBudget);
88
- /**
89
- * Gets a list of models currently added to the viewer.
90
- */
91
- get models(): CogniteModelBase[];
92
- constructor(options: Cognite3DViewerOptions);
93
- /**
94
- * Returns reveal version installed.
95
- */
96
- getVersion(): string;
97
- /**
98
- * Dispose of WebGL resources. Can be used to free up memory when the viewer is no longer in use.
99
- * @see {@link https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects}
100
- * ```ts
101
- * // Viewer is no longer in use, free up memory
102
- * viewer.dispose();
103
- * ```.
104
- */
105
- dispose(): void;
106
- /**
107
- * Triggered when the viewer is disposed. Listeners should clean up any
108
- * resources held and remove the reference to the viewer.
109
- */
110
- on(event: 'disposed', callback: DisposedDelegate): void;
111
- /**
112
- * @example
113
- * ```js
114
- * const onClick = (event) => { console.log(event.offsetX, event.offsetY) };
115
- * viewer.on('click', onClick);
116
- * ```
117
- */
118
- on(event: 'click' | 'hover', callback: PointerEventDelegate): void;
119
- /**
120
- * @example
121
- * ```js
122
- * viewer.on('cameraChange', (position, target) => {
123
- * console.log('Camera changed: ', position, target);
124
- * });
125
- * ```
126
- */
127
- on(event: 'cameraChange', callback: CameraChangeDelegate): void;
128
- /**
129
- * Event that is triggered immediatly after the scene has been rendered.
130
- * @param event Metadata about the rendering frame.
131
- * @param callback Callback to trigger when the event occurs.
132
- */
133
- on(event: 'sceneRendered', callback: SceneRenderedDelegate): void;
134
- /**
135
- * @example
136
- * ```js
137
- * viewer.off('click', onClick);
138
- * ```
139
- */
140
- off(event: 'click' | 'hover', callback: PointerEventDelegate): void;
141
- off(event: 'cameraChange', callback: CameraChangeDelegate): void;
142
- off(event: 'sceneRendered', callback: SceneRenderedDelegate): void;
143
- off(event: 'disposed', callback: DisposedDelegate): void;
144
- /**
145
- * Gets the current viewer state which includes the camera pose as well as applied styling.
146
- * @returns JSON object containing viewer state.
147
- */
148
- getViewState(): ViewerState;
149
- /**
150
- * Restores camera settings from the state provided, and clears all current styled
151
- * node collections and applies the `state` object.
152
- * @param state Viewer state retrieved from {@link Cognite3DViewer.getViewState}.
153
- */
154
- setViewState(state: ViewerState): Promise<void>;
155
- /**
156
- * Add a new model to the viewer.
157
- * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
158
- * @param options
159
- * @example
160
- * ```js
161
- * const options = {
162
- * modelId: 'COGNITE_3D_MODEL_ID',
163
- * revisionId: 'COGNITE_3D_REVISION_ID',
164
- * };
165
- * viewer.addModel(options).then(model => {
166
- * viewer.fitCameraToModel(model, 0);
167
- * });
168
- * ```
169
- */
170
- addModel(options: AddModelOptions): Promise<Cognite3DModel | CognitePointCloudModel>;
171
- /**
172
- * Add a new CAD 3D model to the viewer.
173
- * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
174
- * @param options
175
- * @example
176
- * ```js
177
- * const options = {
178
- * modelId: 'COGNITE_3D_MODEL_ID',
179
- * revisionId: 'COGNITE_3D_REVISION_ID',
180
- * };
181
- * viewer.addCadModel(options).then(model => {
182
- * viewer.fitCameraToModel(model, 0);
183
- * });
184
- * ```
185
- */
186
- addCadModel(options: AddModelOptions): Promise<Cognite3DModel>;
187
- /**
188
- * Add a new pointcloud 3D model to the viewer.
189
- * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
190
- * @param options
191
- * @example
192
- * ```js
193
- * const options = {
194
- * modelId: 'COGNITE_3D_MODEL_ID',
195
- * revisionId: 'COGNITE_3D_REVISION_ID',
196
- * };
197
- * viewer.addPointCloudModel(options).then(model => {
198
- * viewer.fitCameraToModel(model, 0);
199
- * });
200
- * ```
201
- */
202
- addPointCloudModel(options: AddModelOptions): Promise<CognitePointCloudModel>;
203
- /**
204
- * Removes a model that was previously added using {@link Cognite3DViewer.addModel},
205
- * {@link Cognite3DViewer.addCadModel} or {@link Cognite3DViewer.addPointCloudModel}
206
- * .
207
- * @param model
208
- */
209
- removeModel(model: Cognite3DModel | CognitePointCloudModel): void;
210
- /**
211
- * Use to determine of which type the model is.
212
- *
213
- * @param modelId The model's id.
214
- * @param revisionId The model's revision id.
215
- *
216
- * @returns Empty string if type is not supported.
217
- * @example
218
- * ```typescript
219
- * const viewer = new Cognite3DViewer(...);
220
- * const type = await viewer.determineModelType(options.modelId, options.revisionId)
221
- * let model: Cognite3DModel | CognitePointCloudModel
222
- * switch (type) {
223
- * case 'cad':
224
- * model = await viewer.addCadModel(options);
225
- * break;
226
- * case 'pointcloud':
227
- * model = await viewer.addPointCloudModel(options);
228
- * break;
229
- * default:
230
- * throw new Error('Model is not supported');
231
- * }
232
- * viewer.fitCameraToModel(model);
233
- * ```
234
- */
235
- determineModelType(modelId: number, revisionId: number): Promise<SupportedModelTypes | ''>;
236
- /**
237
- * Add a THREE.Object3D to the viewer.
238
- * @param object
239
- * @example
240
- * ```js
241
- * const sphere = new THREE.Mesh(
242
- * new THREE.SphereBufferGeometry(),
243
- * new THREE.MeshBasicMaterial()
244
- * );
245
- * viewer.addObject3D(sphere);
246
- * ```
247
- */
248
- addObject3D(object: THREE.Object3D): void;
249
- /**
250
- * Remove a THREE.Object3D from the viewer.
251
- * @param object
252
- * @example
253
- * ```js
254
- * const sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(), new THREE.MeshBasicMaterial());
255
- * viewer.addObject3D(sphere);
256
- * viewer.removeObject3D(sphere);
257
- * ```
258
- */
259
- removeObject3D(object: THREE.Object3D): void;
260
- /**
261
- * Add an object that will be considered a UI object. It will be rendered in the last stage and with orthographic projection.
262
- * @param object
263
- * @param screenPos Screen space position of object (in pixels).
264
- * @param size Pixel width and height of the object.
265
- */
266
- addUiObject(object: THREE.Object3D, screenPos: THREE.Vector2, size: THREE.Vector2): void;
267
- /** Removes the UI object from the viewer.
268
- * @param object
269
- */
270
- removeUiObject(object: THREE.Object3D): void;
271
- /**
272
- * Sets the color used as the clear color of the renderer.
273
- * @param color
274
- */
275
- setBackgroundColor(color: THREE.Color): void;
276
- /**
277
- * Sets per-pixel clipping planes. Pixels behind any of the planes will be sliced away.
278
- * @param clippingPlanes The planes to use for clipping.
279
- * @example
280
- * ```js
281
- * // Hide pixels with values less than 0 in the x direction
282
- * const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), 0);
283
- * viewer.setClippingPlanes([plane]);
284
- * ```
285
- * ```js
286
- * // Hide pixels with values greater than 20 in the x direction
287
- * const plane = new THREE.Plane(new THREE.Vector3(-1, 0, 0), 20);
288
- * viewer.setClippingPlanes([plane]);
289
- * ```
290
- * ```js
291
- * // Hide pixels with values less than 0 in the x direction or greater than 0 in the y direction
292
- * const xPlane = new THREE.Plane(new THREE.Vector3(1, 0, 0), 0);
293
- * const yPlane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0);
294
- * viewer.setClippingPlanes([xPlane, yPlane]);
295
- * ```
296
- * ```js
297
- * // Hide pixels behind an arbitrary, non axis-aligned plane
298
- * const plane = new THREE.Plane(new THREE.Vector3(1.5, 20, -19), 20);
299
- * viewer.setClippingPlanes([plane]);
300
- * ```
301
- * ```js
302
- * // Disable clipping planes
303
- * viewer.setClippingPlanes([]);
304
- * ```
305
- */
306
- setClippingPlanes(clippingPlanes: THREE.Plane[]): void;
307
- /**
308
- * @param slicingPlanes
309
- * @deprecated Since version 2.1, will be removed in version 3.0. Use {@link setClippingPlanes}.
310
- */
311
- setSlicingPlanes(slicingPlanes: THREE.Plane[]): void;
312
- /**
313
- * Returns the current active clipping planes.
314
- * @version New in 2.1
315
- */
316
- getClippingPlanes(): THREE.Plane[];
317
- /**
318
- * @obvious
319
- * @returns The THREE.Camera used for rendering.
320
- */
321
- getCamera(): THREE.PerspectiveCamera;
322
- /**
323
- * @obvious
324
- * @returns The THREE.Scene used for rendering.
325
- */
326
- getScene(): THREE.Scene;
327
- /**
328
- * @obvious
329
- * @returns Camera's position in world space.
330
- */
331
- getCameraPosition(): THREE.Vector3;
332
- /**
333
- * @obvious
334
- * @returns Camera's target in world space.
335
- */
336
- getCameraTarget(): THREE.Vector3;
337
- /**
338
- * @obvious
339
- * @param position Position in world space.
340
- * @example
341
- * ```js
342
- * // store position, target
343
- * const position = viewer.getCameraPosition();
344
- * const target = viewer.getCameraTarget();
345
- * // restore position, target
346
- * viewer.setCameraPosition(position);
347
- * viewer.setCameraTarget(target);
348
- * ```
349
- */
350
- setCameraPosition(position: THREE.Vector3): void;
351
- /**
352
- * Set camera's target.
353
- * @public
354
- * @param target Target in world space.
355
- * @example
356
- * ```js
357
- * // store position, target
358
- * const position = viewer.getCameraPosition();
359
- * const target = viewer.getCameraTarget();
360
- * // restore position, target
361
- * viewer.setCameraPosition(position);
362
- * viewer.setCameraTarget(target);
363
- * ```
364
- */
365
- setCameraTarget(target: THREE.Vector3): void;
366
- /**
367
- * Gets the camera controller. See https://www.npmjs.com/package/@cognite/three-combo-controls
368
- * for documentation. Note that by default the `minDistance` setting of the controls will
369
- * be automatic. This can be disabled using {@link Cognite3DViewerOptions.automaticControlsSensitivity}.
370
- */
371
- get cameraControls(): ComboControls;
372
- /**
373
- * Gets whether camera controls through mouse, touch and keyboard are enabled.
374
- */
375
- get cameraControlsEnabled(): boolean;
376
- /**
377
- * Sets whether camera controls through mouse, touch and keyboard are enabled.
378
- * This can be useful to e.g. temporarily disable navigation when manipulating other
379
- * objects in the scene or when implementing a "cinematic" viewer.
380
- */
381
- set cameraControlsEnabled(enabled: boolean);
382
- /**
383
- * Attempts to load the camera settings from the settings stored for the
384
- * provided model. See {@link https://docs.cognite.com/api/v1/#operation/get3DRevision}
385
- * and {@link https://docs.cognite.com/api/v1/#operation/update3DRevisions} for
386
- * information on how this setting is retrieved and stored. This setting can
387
- * also be changed through the 3D models management interface in Cognite Fusion.
388
- * If no camera configuration is stored in CDF, {@link Cognite3DViewer.fitCameraToModel}
389
- * is used as a fallback.
390
- * @param model The model to load camera settings from.
391
- */
392
- loadCameraFromModel(model: CogniteModelBase): void;
393
- /**
394
- * Move camera to a place where the 3D model is visible.
395
- * It uses the bounding box of the 3D model and calls {@link Cognite3DViewer.fitCameraToBoundingBox}.
396
- * @param model The 3D model.
397
- * @param duration The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.
398
- * @example
399
- * ```js
400
- * // Fit camera to model
401
- * viewer.fitCameraToModel(model);
402
- * ```
403
- * ```js
404
- * // Fit camera to model over 500 milliseconds
405
- * viewer.fitCameraToModel(model, 500);
406
- * ```
407
- * ```js
408
- * // Fit camera to model instantly
409
- * viewer.fitCameraToModel(model, 0);
410
- * ```
411
- */
412
- fitCameraToModel(model: CogniteModelBase, duration?: number): void;
413
- /**
414
- * Move camera to a place where the content of a bounding box is visible to the camera.
415
- * @param box The bounding box in world space.
416
- * @param duration The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.
417
- * @param radiusFactor The ratio of the distance from camera to center of box and radius of the box.
418
- * @example
419
- * ```js
420
- * // Fit camera to bounding box over 500 milliseconds
421
- * viewer.fitCameraToBoundingBox(boundingBox, 500);
422
- * ```
423
- * ```js
424
- * // Fit camera to bounding box instantaneously
425
- * viewer.fitCameraToBoundingBox(boundingBox, 0);
426
- * ```
427
- * ```js
428
- * // Place the camera closer to the bounding box
429
- * viewer.fitCameraToBoundingBox(boundingBox, 500, 2);
430
- * ```
431
- */
432
- fitCameraToBoundingBox(box: THREE.Box3, duration?: number, radiusFactor?: number): void;
433
- /**
434
- * Typically used when you perform some changes and can't see them unless you move camera.
435
- */
436
- requestRedraw(): void;
437
- /**
438
- * Allows to move camera with WASM or arrows keys.
439
- */
440
- enableKeyboardNavigation(): void;
441
- /**
442
- * Disables camera movement by pressing WASM or arrows keys.
443
- */
444
- disableKeyboardNavigation(): void;
445
- /**
446
- * 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.
447
- * @see {@link https://www.w3schools.com/graphics/canvas_coordinates.asp https://www.w3schools.com/graphics/canvas_coordinates.asp}.
448
- * @param point World space coordinate.
449
- * @param normalize Optional. If true, coordinates are normalized into [0,1]. If false, the values are in the range [0, <canvas_size>).
450
- * @returns Returns 2D coordinates if the point is visible on screen, or `null` if object is outside screen.
451
- * @example
452
- * ```js
453
- * const boundingBoxCenter = new THREE.Vector3();
454
- * // Find center of bounding box in world space
455
- * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
456
- * // Screen coordinates of that point
457
- * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
458
- * ```
459
- * ```js
460
- * const boundingBoxCenter = new THREE.Vector3();
461
- * // Find center of bounding box in world space
462
- * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
463
- * // Screen coordinates of that point normalized in the range [0,1]
464
- * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter, true);
465
- * ```
466
- * ```js
467
- * const boundingBoxCenter = new THREE.Vector3();
468
- * // Find center of bounding box in world space
469
- * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
470
- * // Screen coordinates of that point
471
- * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
472
- * if (screenCoordinates == null) {
473
- * // Object not visible on screen
474
- * } else {
475
- * // Object is visible on screen
476
- * }
477
- * ```
478
- */
479
- worldToScreen(point: THREE.Vector3, normalize?: boolean): THREE.Vector2 | null;
480
- /**
481
- * Take screenshot from the current camera position.
482
- * @param width Width of the final image. Default is current canvas size.
483
- * @param height Height of the final image. Default is current canvas size.
484
- * @returns A {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URL} of the image ('image/png').
485
- * @example
486
- * ```js
487
- * // Take a screenshot with custom resolution
488
- * const url = await viewer.getScreenshot(1920, 1080);
489
- * ```
490
- * ```js
491
- * // Add a screenshot with resolution of the canvas to the page
492
- * const url = await viewer.getScreenshot();
493
- * const image = document.createElement('img');
494
- * image.src = url;
495
- * document.body.appendChild(url);
496
- * ```
497
- */
498
- getScreenshot(width?: number, height?: number): Promise<string>;
499
- /**
500
- * Raycasting model(s) for finding where the ray intersects with the model.
501
- * @param offsetX X coordinate in pixels (relative to the domElement).
502
- * @param offsetY Y coordinate in pixels (relative to the domElement).
503
- * @param options Options to control the behavior of the intersection operation. Optional (new in 1.3.0).
504
- * @returns A promise that if there was an intersection then return the intersection object - otherwise it
505
- * returns `null` if there were no intersections.
506
- * @see {@link https://en.wikipedia.org/wiki/Ray_casting}.
507
- *
508
- * @example For CAD model
509
- * ```js
510
- * const offsetX = 50 // pixels from the left
511
- * const offsetY = 100 // pixels from the top
512
- * const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
513
- * if (intersection) // it was a hit
514
- * console.log(
515
- * 'You hit model ', intersection.model,
516
- * ' at the node with tree index ', intersection.treeIndex,
517
- * ' at this exact point ', intersection.point
518
- * );
519
- * ```
520
- *
521
- * @example For point cloud
522
- * ```js
523
- * const offsetX = 50 // pixels from the left
524
- * const offsetY = 100 // pixels from the top
525
- * const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
526
- * if (intersection) // it was a hit
527
- * console.log(
528
- * 'You hit model ', intersection.model,
529
- * ' at the point index ', intersection.pointIndex,
530
- * ' at this exact point ', intersection.point
531
- * );
532
- * ```
533
- */
534
- getIntersectionFromPixel(offsetX: number, offsetY: number, options?: IntersectionFromPixelOptions): Promise<null | Intersection>;
535
- private getModels;
536
- /** @private */
537
- private moveCameraTo;
538
- /** @private */
539
- private animate;
540
- /** @private */
541
- private updateCameraNearAndFar;
542
- /** @private */
543
- private resizeIfNecessary;
544
- private startPointerEventListeners;
545
- }
1
+ /*!
2
+ * Copyright 2021 Cognite AS
3
+ */
4
+ import * as THREE from 'three';
5
+ import { AddModelOptions, Cognite3DViewerOptions, Intersection, CameraChangeDelegate, PointerEventDelegate, CadModelBudget, PointCloudBudget } from './types';
6
+ import { CogniteModelBase } from './CogniteModelBase';
7
+ import { Cognite3DModel } from './Cognite3DModel';
8
+ import { CognitePointCloudModel } from './CognitePointCloudModel';
9
+ import { DisposedDelegate, SceneRenderedDelegate } from '../types';
10
+ import { SupportedModelTypes } from '../../datamodels/base';
11
+ import { IntersectionFromPixelOptions } from '../..';
12
+ import { ViewerState } from '../../utilities/ViewStateHelper';
13
+ import ComboControls from '../../../../packages/camera-manager';
14
+ /**
15
+ * @example
16
+ * ```js
17
+ * const viewer = new Cognite3DViewer({
18
+ * noBackground: true,
19
+ * sdk: CogniteClient({...})
20
+ * });
21
+ * ```
22
+ * @module @cognite/reveal
23
+ */
24
+ export declare class Cognite3DViewer {
25
+ private get canvas();
26
+ /**
27
+ * For now it just always returns true.
28
+ * @see Https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#Browser_compatibility.
29
+ */
30
+ static isBrowserSupported(): true;
31
+ /**
32
+ * The DOM element the viewer will insert its rendering canvas into.
33
+ * The DOM element can be specified in the options when the viewer is created.
34
+ * If not specified, the DOM element will be created automatically.
35
+ * The DOM element cannot be changed after the viewer has been created.
36
+ */
37
+ get domElement(): HTMLElement;
38
+ /**
39
+ * Returns the renderer used to produce images from 3D geometry.
40
+ */
41
+ get renderer(): THREE.WebGLRenderer;
42
+ private readonly _cdfSdkClient;
43
+ private readonly _dataSource;
44
+ private readonly camera;
45
+ private readonly scene;
46
+ private readonly controls;
47
+ private readonly _subscription;
48
+ private readonly _revealManagerHelper;
49
+ private readonly _domElement;
50
+ private readonly _renderer;
51
+ private readonly _boundAnimate;
52
+ private readonly _events;
53
+ private readonly _models;
54
+ private readonly _extraObjects;
55
+ private readonly _automaticNearFarPlane;
56
+ private readonly _automaticControlsSensitivity;
57
+ private isDisposed;
58
+ private readonly renderController;
59
+ private latestRequestId;
60
+ private readonly clock;
61
+ private _clippingNeedsUpdate;
62
+ private readonly spinner;
63
+ private get revealManager();
64
+ /**
65
+ * Reusable buffers used by functions in Cognite3dViewer to avoid allocations.
66
+ */
67
+ private readonly _updateNearAndFarPlaneBuffers;
68
+ /**
69
+ * Gets the current budget for downloading geometry for CAD models. Note that this
70
+ * budget is shared between all added CAD models and not a per-model budget.
71
+ */
72
+ get cadBudget(): CadModelBudget;
73
+ /**
74
+ * Sets the current budget for downloading geometry for CAD models. Note that this
75
+ * budget is shared between all added CAD models and not a per-model budget.
76
+ */
77
+ set cadBudget(budget: CadModelBudget);
78
+ /**
79
+ * Returns the point cloud budget. The budget is shared between all loaded
80
+ * point cloud models.
81
+ */
82
+ get pointCloudBudget(): PointCloudBudget;
83
+ /**
84
+ * Sets the point cloud budget. The budget is shared between all loaded
85
+ * point cloud models.
86
+ */
87
+ set pointCloudBudget(budget: PointCloudBudget);
88
+ /**
89
+ * Gets a list of models currently added to the viewer.
90
+ */
91
+ get models(): CogniteModelBase[];
92
+ constructor(options: Cognite3DViewerOptions);
93
+ /**
94
+ * Returns reveal version installed.
95
+ */
96
+ getVersion(): string;
97
+ /**
98
+ * Sets the log level. Used for debugging.
99
+ * Defaults to 'none' (which is identical to 'silent').
100
+ * @param level
101
+ */
102
+ setLogLevel(level: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent' | 'none'): void;
103
+ /**
104
+ * Dispose of WebGL resources. Can be used to free up memory when the viewer is no longer in use.
105
+ * @see {@link https://threejs.org/docs/#manual/en/introduction/How-to-dispose-of-objects}
106
+ * ```ts
107
+ * // Viewer is no longer in use, free up memory
108
+ * viewer.dispose();
109
+ * ```.
110
+ */
111
+ dispose(): void;
112
+ /**
113
+ * Triggered when the viewer is disposed. Listeners should clean up any
114
+ * resources held and remove the reference to the viewer.
115
+ */
116
+ on(event: 'disposed', callback: DisposedDelegate): void;
117
+ /**
118
+ * @example
119
+ * ```js
120
+ * const onClick = (event) => { console.log(event.offsetX, event.offsetY) };
121
+ * viewer.on('click', onClick);
122
+ * ```
123
+ */
124
+ on(event: 'click' | 'hover', callback: PointerEventDelegate): void;
125
+ /**
126
+ * @example
127
+ * ```js
128
+ * viewer.on('cameraChange', (position, target) => {
129
+ * console.log('Camera changed: ', position, target);
130
+ * });
131
+ * ```
132
+ */
133
+ on(event: 'cameraChange', callback: CameraChangeDelegate): void;
134
+ /**
135
+ * Event that is triggered immediatly after the scene has been rendered.
136
+ * @param event Metadata about the rendering frame.
137
+ * @param callback Callback to trigger when the event occurs.
138
+ */
139
+ on(event: 'sceneRendered', callback: SceneRenderedDelegate): void;
140
+ /**
141
+ * @example
142
+ * ```js
143
+ * viewer.off('click', onClick);
144
+ * ```
145
+ */
146
+ off(event: 'click' | 'hover', callback: PointerEventDelegate): void;
147
+ off(event: 'cameraChange', callback: CameraChangeDelegate): void;
148
+ off(event: 'sceneRendered', callback: SceneRenderedDelegate): void;
149
+ off(event: 'disposed', callback: DisposedDelegate): void;
150
+ /**
151
+ * Gets the current viewer state which includes the camera pose as well as applied styling.
152
+ * @returns JSON object containing viewer state.
153
+ */
154
+ getViewState(): ViewerState;
155
+ /**
156
+ * Restores camera settings from the state provided, and clears all current styled
157
+ * node collections and applies the `state` object.
158
+ * @param state Viewer state retrieved from {@link Cognite3DViewer.getViewState}.
159
+ */
160
+ setViewState(state: ViewerState): Promise<void>;
161
+ /**
162
+ * Add a new model to the viewer.
163
+ * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
164
+ * @param options
165
+ * @example
166
+ * ```js
167
+ * const options = {
168
+ * modelId: 'COGNITE_3D_MODEL_ID',
169
+ * revisionId: 'COGNITE_3D_REVISION_ID',
170
+ * };
171
+ * viewer.addModel(options).then(model => {
172
+ * viewer.fitCameraToModel(model, 0);
173
+ * });
174
+ * ```
175
+ */
176
+ addModel(options: AddModelOptions): Promise<Cognite3DModel | CognitePointCloudModel>;
177
+ /**
178
+ * Add a new CAD 3D model to the viewer.
179
+ * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
180
+ * @param options
181
+ * @example
182
+ * ```js
183
+ * const options = {
184
+ * modelId: 'COGNITE_3D_MODEL_ID',
185
+ * revisionId: 'COGNITE_3D_REVISION_ID',
186
+ * };
187
+ * viewer.addCadModel(options).then(model => {
188
+ * viewer.fitCameraToModel(model, 0);
189
+ * });
190
+ * ```
191
+ */
192
+ addCadModel(options: AddModelOptions): Promise<Cognite3DModel>;
193
+ /**
194
+ * Add a new pointcloud 3D model to the viewer.
195
+ * Call {@link Cognite3DViewer.fitCameraToModel} to see the model after the model has loaded.
196
+ * @param options
197
+ * @example
198
+ * ```js
199
+ * const options = {
200
+ * modelId: 'COGNITE_3D_MODEL_ID',
201
+ * revisionId: 'COGNITE_3D_REVISION_ID',
202
+ * };
203
+ * viewer.addPointCloudModel(options).then(model => {
204
+ * viewer.fitCameraToModel(model, 0);
205
+ * });
206
+ * ```
207
+ */
208
+ addPointCloudModel(options: AddModelOptions): Promise<CognitePointCloudModel>;
209
+ /**
210
+ * Removes a model that was previously added using {@link Cognite3DViewer.addModel},
211
+ * {@link Cognite3DViewer.addCadModel} or {@link Cognite3DViewer.addPointCloudModel}
212
+ * .
213
+ * @param model
214
+ */
215
+ removeModel(model: Cognite3DModel | CognitePointCloudModel): void;
216
+ /**
217
+ * Use to determine of which type the model is.
218
+ *
219
+ * @param modelId The model's id.
220
+ * @param revisionId The model's revision id.
221
+ *
222
+ * @returns Empty string if type is not supported.
223
+ * @example
224
+ * ```typescript
225
+ * const viewer = new Cognite3DViewer(...);
226
+ * const type = await viewer.determineModelType(options.modelId, options.revisionId)
227
+ * let model: Cognite3DModel | CognitePointCloudModel
228
+ * switch (type) {
229
+ * case 'cad':
230
+ * model = await viewer.addCadModel(options);
231
+ * break;
232
+ * case 'pointcloud':
233
+ * model = await viewer.addPointCloudModel(options);
234
+ * break;
235
+ * default:
236
+ * throw new Error('Model is not supported');
237
+ * }
238
+ * viewer.fitCameraToModel(model);
239
+ * ```
240
+ */
241
+ determineModelType(modelId: number, revisionId: number): Promise<SupportedModelTypes | ''>;
242
+ /**
243
+ * Add a THREE.Object3D to the viewer.
244
+ * @param object
245
+ * @example
246
+ * ```js
247
+ * const sphere = new THREE.Mesh(
248
+ * new THREE.SphereBufferGeometry(),
249
+ * new THREE.MeshBasicMaterial()
250
+ * );
251
+ * viewer.addObject3D(sphere);
252
+ * ```
253
+ */
254
+ addObject3D(object: THREE.Object3D): void;
255
+ /**
256
+ * Remove a THREE.Object3D from the viewer.
257
+ * @param object
258
+ * @example
259
+ * ```js
260
+ * const sphere = new THREE.Mesh(new THREE.SphereBufferGeometry(), new THREE.MeshBasicMaterial());
261
+ * viewer.addObject3D(sphere);
262
+ * viewer.removeObject3D(sphere);
263
+ * ```
264
+ */
265
+ removeObject3D(object: THREE.Object3D): void;
266
+ /**
267
+ * Add an object that will be considered a UI object. It will be rendered in the last stage and with orthographic projection.
268
+ * @param object
269
+ * @param screenPos Screen space position of object (in pixels).
270
+ * @param size Pixel width and height of the object.
271
+ */
272
+ addUiObject(object: THREE.Object3D, screenPos: THREE.Vector2, size: THREE.Vector2): void;
273
+ /** Removes the UI object from the viewer.
274
+ * @param object
275
+ */
276
+ removeUiObject(object: THREE.Object3D): void;
277
+ /**
278
+ * Sets the color used as the clear color of the renderer.
279
+ * @param color
280
+ */
281
+ setBackgroundColor(color: THREE.Color): void;
282
+ /**
283
+ * Sets per-pixel clipping planes. Pixels behind any of the planes will be sliced away.
284
+ * @param clippingPlanes The planes to use for clipping.
285
+ * @example
286
+ * ```js
287
+ * // Hide pixels with values less than 0 in the x direction
288
+ * const plane = new THREE.Plane(new THREE.Vector3(1, 0, 0), 0);
289
+ * viewer.setClippingPlanes([plane]);
290
+ * ```
291
+ * ```js
292
+ * // Hide pixels with values greater than 20 in the x direction
293
+ * const plane = new THREE.Plane(new THREE.Vector3(-1, 0, 0), 20);
294
+ * viewer.setClippingPlanes([plane]);
295
+ * ```
296
+ * ```js
297
+ * // Hide pixels with values less than 0 in the x direction or greater than 0 in the y direction
298
+ * const xPlane = new THREE.Plane(new THREE.Vector3(1, 0, 0), 0);
299
+ * const yPlane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0);
300
+ * viewer.setClippingPlanes([xPlane, yPlane]);
301
+ * ```
302
+ * ```js
303
+ * // Hide pixels behind an arbitrary, non axis-aligned plane
304
+ * const plane = new THREE.Plane(new THREE.Vector3(1.5, 20, -19), 20);
305
+ * viewer.setClippingPlanes([plane]);
306
+ * ```
307
+ * ```js
308
+ * // Disable clipping planes
309
+ * viewer.setClippingPlanes([]);
310
+ * ```
311
+ */
312
+ setClippingPlanes(clippingPlanes: THREE.Plane[]): void;
313
+ /**
314
+ * @param slicingPlanes
315
+ * @deprecated Since version 2.1, will be removed in version 3.0. Use {@link setClippingPlanes}.
316
+ */
317
+ setSlicingPlanes(slicingPlanes: THREE.Plane[]): void;
318
+ /**
319
+ * Returns the current active clipping planes.
320
+ * @version New in 2.1
321
+ */
322
+ getClippingPlanes(): THREE.Plane[];
323
+ /**
324
+ * @obvious
325
+ * @returns The THREE.Camera used for rendering.
326
+ */
327
+ getCamera(): THREE.PerspectiveCamera;
328
+ /**
329
+ * @obvious
330
+ * @returns The THREE.Scene used for rendering.
331
+ */
332
+ getScene(): THREE.Scene;
333
+ /**
334
+ * @obvious
335
+ * @returns Camera's position in world space.
336
+ */
337
+ getCameraPosition(): THREE.Vector3;
338
+ /**
339
+ * @obvious
340
+ * @returns Camera's target in world space.
341
+ */
342
+ getCameraTarget(): THREE.Vector3;
343
+ /**
344
+ * @obvious
345
+ * @param position Position in world space.
346
+ * @example
347
+ * ```js
348
+ * // store position, target
349
+ * const position = viewer.getCameraPosition();
350
+ * const target = viewer.getCameraTarget();
351
+ * // restore position, target
352
+ * viewer.setCameraPosition(position);
353
+ * viewer.setCameraTarget(target);
354
+ * ```
355
+ */
356
+ setCameraPosition(position: THREE.Vector3): void;
357
+ /**
358
+ * Set camera's target.
359
+ * @public
360
+ * @param target Target in world space.
361
+ * @example
362
+ * ```js
363
+ * // store position, target
364
+ * const position = viewer.getCameraPosition();
365
+ * const target = viewer.getCameraTarget();
366
+ * // restore position, target
367
+ * viewer.setCameraPosition(position);
368
+ * viewer.setCameraTarget(target);
369
+ * ```
370
+ */
371
+ setCameraTarget(target: THREE.Vector3): void;
372
+ /**
373
+ * Gets the camera controller. See https://www.npmjs.com/package/@cognite/three-combo-controls
374
+ * for documentation. Note that by default the `minDistance` setting of the controls will
375
+ * be automatic. This can be disabled using {@link Cognite3DViewerOptions.automaticControlsSensitivity}.
376
+ */
377
+ get cameraControls(): ComboControls;
378
+ /**
379
+ * Gets whether camera controls through mouse, touch and keyboard are enabled.
380
+ */
381
+ get cameraControlsEnabled(): boolean;
382
+ /**
383
+ * Sets whether camera controls through mouse, touch and keyboard are enabled.
384
+ * This can be useful to e.g. temporarily disable navigation when manipulating other
385
+ * objects in the scene or when implementing a "cinematic" viewer.
386
+ */
387
+ set cameraControlsEnabled(enabled: boolean);
388
+ /**
389
+ * Attempts to load the camera settings from the settings stored for the
390
+ * provided model. See {@link https://docs.cognite.com/api/v1/#operation/get3DRevision}
391
+ * and {@link https://docs.cognite.com/api/v1/#operation/update3DRevisions} for
392
+ * information on how this setting is retrieved and stored. This setting can
393
+ * also be changed through the 3D models management interface in Cognite Fusion.
394
+ * If no camera configuration is stored in CDF, {@link Cognite3DViewer.fitCameraToModel}
395
+ * is used as a fallback.
396
+ * @param model The model to load camera settings from.
397
+ */
398
+ loadCameraFromModel(model: CogniteModelBase): void;
399
+ /**
400
+ * Move camera to a place where the 3D model is visible.
401
+ * It uses the bounding box of the 3D model and calls {@link Cognite3DViewer.fitCameraToBoundingBox}.
402
+ * @param model The 3D model.
403
+ * @param duration The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.
404
+ * @example
405
+ * ```js
406
+ * // Fit camera to model
407
+ * viewer.fitCameraToModel(model);
408
+ * ```
409
+ * ```js
410
+ * // Fit camera to model over 500 milliseconds
411
+ * viewer.fitCameraToModel(model, 500);
412
+ * ```
413
+ * ```js
414
+ * // Fit camera to model instantly
415
+ * viewer.fitCameraToModel(model, 0);
416
+ * ```
417
+ */
418
+ fitCameraToModel(model: CogniteModelBase, duration?: number): void;
419
+ /**
420
+ * Move camera to a place where the content of a bounding box is visible to the camera.
421
+ * @param box The bounding box in world space.
422
+ * @param duration The duration of the animation moving the camera. Set this to 0 (zero) to disable animation.
423
+ * @param radiusFactor The ratio of the distance from camera to center of box and radius of the box.
424
+ * @example
425
+ * ```js
426
+ * // Fit camera to bounding box over 500 milliseconds
427
+ * viewer.fitCameraToBoundingBox(boundingBox, 500);
428
+ * ```
429
+ * ```js
430
+ * // Fit camera to bounding box instantaneously
431
+ * viewer.fitCameraToBoundingBox(boundingBox, 0);
432
+ * ```
433
+ * ```js
434
+ * // Place the camera closer to the bounding box
435
+ * viewer.fitCameraToBoundingBox(boundingBox, 500, 2);
436
+ * ```
437
+ */
438
+ fitCameraToBoundingBox(box: THREE.Box3, duration?: number, radiusFactor?: number): void;
439
+ /**
440
+ * Typically used when you perform some changes and can't see them unless you move camera.
441
+ */
442
+ requestRedraw(): void;
443
+ /**
444
+ * Allows to move camera with WASM or arrows keys.
445
+ */
446
+ enableKeyboardNavigation(): void;
447
+ /**
448
+ * Disables camera movement by pressing WASM or arrows keys.
449
+ */
450
+ disableKeyboardNavigation(): void;
451
+ /**
452
+ * 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.
453
+ * @see {@link https://www.w3schools.com/graphics/canvas_coordinates.asp https://www.w3schools.com/graphics/canvas_coordinates.asp}.
454
+ * @param point World space coordinate.
455
+ * @param normalize Optional. If true, coordinates are normalized into [0,1]. If false, the values are in the range [0, <canvas_size>).
456
+ * @returns Returns 2D coordinates if the point is visible on screen, or `null` if object is outside screen.
457
+ * @example
458
+ * ```js
459
+ * const boundingBoxCenter = new THREE.Vector3();
460
+ * // Find center of bounding box in world space
461
+ * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
462
+ * // Screen coordinates of that point
463
+ * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
464
+ * ```
465
+ * ```js
466
+ * const boundingBoxCenter = new THREE.Vector3();
467
+ * // Find center of bounding box in world space
468
+ * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
469
+ * // Screen coordinates of that point normalized in the range [0,1]
470
+ * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter, true);
471
+ * ```
472
+ * ```js
473
+ * const boundingBoxCenter = new THREE.Vector3();
474
+ * // Find center of bounding box in world space
475
+ * model.getBoundingBox(nodeId).getCenter(boundingBoxCenter);
476
+ * // Screen coordinates of that point
477
+ * const screenCoordinates = viewer.worldToScreen(boundingBoxCenter);
478
+ * if (screenCoordinates == null) {
479
+ * // Object not visible on screen
480
+ * } else {
481
+ * // Object is visible on screen
482
+ * }
483
+ * ```
484
+ */
485
+ worldToScreen(point: THREE.Vector3, normalize?: boolean): THREE.Vector2 | null;
486
+ /**
487
+ * Take screenshot from the current camera position.
488
+ * @param width Width of the final image. Default is current canvas size.
489
+ * @param height Height of the final image. Default is current canvas size.
490
+ * @returns A {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URL} of the image ('image/png').
491
+ * @example
492
+ * ```js
493
+ * // Take a screenshot with custom resolution
494
+ * const url = await viewer.getScreenshot(1920, 1080);
495
+ * ```
496
+ * ```js
497
+ * // Add a screenshot with resolution of the canvas to the page
498
+ * const url = await viewer.getScreenshot();
499
+ * const image = document.createElement('img');
500
+ * image.src = url;
501
+ * document.body.appendChild(url);
502
+ * ```
503
+ */
504
+ getScreenshot(width?: number, height?: number): Promise<string>;
505
+ /**
506
+ * Raycasting model(s) for finding where the ray intersects with the model.
507
+ * @param offsetX X coordinate in pixels (relative to the domElement).
508
+ * @param offsetY Y coordinate in pixels (relative to the domElement).
509
+ * @param options Options to control the behavior of the intersection operation. Optional (new in 1.3.0).
510
+ * @returns A promise that if there was an intersection then return the intersection object - otherwise it
511
+ * returns `null` if there were no intersections.
512
+ * @see {@link https://en.wikipedia.org/wiki/Ray_casting}.
513
+ *
514
+ * @example For CAD model
515
+ * ```js
516
+ * const offsetX = 50 // pixels from the left
517
+ * const offsetY = 100 // pixels from the top
518
+ * const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
519
+ * if (intersection) // it was a hit
520
+ * console.log(
521
+ * 'You hit model ', intersection.model,
522
+ * ' at the node with tree index ', intersection.treeIndex,
523
+ * ' at this exact point ', intersection.point
524
+ * );
525
+ * ```
526
+ *
527
+ * @example For point cloud
528
+ * ```js
529
+ * const offsetX = 50 // pixels from the left
530
+ * const offsetY = 100 // pixels from the top
531
+ * const intersection = await viewer.getIntersectionFromPixel(offsetX, offsetY);
532
+ * if (intersection) // it was a hit
533
+ * console.log(
534
+ * 'You hit model ', intersection.model,
535
+ * ' at the point index ', intersection.pointIndex,
536
+ * ' at this exact point ', intersection.point
537
+ * );
538
+ * ```
539
+ */
540
+ getIntersectionFromPixel(offsetX: number, offsetY: number, options?: IntersectionFromPixelOptions): Promise<null | Intersection>;
541
+ private getModels;
542
+ /** @private */
543
+ private moveCameraTo;
544
+ /**
545
+ * Creates a helper for managing viewer state.
546
+ */
547
+ private createViewStateHelper;
548
+ /** @private */
549
+ private animate;
550
+ /** @private */
551
+ private updateCameraNearAndFar;
552
+ /** @private */
553
+ private resizeIfNecessary;
554
+ private readonly startPointerEventListeners;
555
+ }