@cognite/reveal 2.0.0-beta.3 → 2.1.2

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