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