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