@cesium/engine 21.0.1 → 22.1.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 (267) hide show
  1. package/Build/ThirdParty/Workers/zip-web-worker.js +10 -7
  2. package/Build/Workers/chunk-23T2IPHV.js +55 -0
  3. package/Build/Workers/{chunk-TGJQMEL4.js → chunk-2AM4E2WD.js} +2 -2
  4. package/Build/Workers/{chunk-4CORGH7N.js → chunk-2MWF4IES.js} +16 -14
  5. package/Build/Workers/{chunk-3RKX3UFI.js → chunk-2RCIRXNI.js} +1 -1
  6. package/Build/Workers/{chunk-LV3G32QE.js → chunk-3YTMGEXW.js} +5 -1424
  7. package/Build/Workers/{chunk-PJAA7QSC.js → chunk-4BHWJWS3.js} +6 -6
  8. package/Build/Workers/{chunk-FE565QHX.js → chunk-5JKH4AMT.js} +2 -2
  9. package/Build/Workers/{chunk-KZ7GDSAJ.js → chunk-6HKAPCSO.js} +1 -1
  10. package/Build/Workers/{chunk-VVALNLSH.js → chunk-A53R2F2L.js} +4 -4
  11. package/Build/Workers/{chunk-KVB73ECP.js → chunk-A6YFUGJO.js} +7 -7
  12. package/Build/Workers/{chunk-QNOIRRJK.js → chunk-AJYWXC6I.js} +4 -4
  13. package/Build/Workers/{chunk-UKA7OISV.js → chunk-AOIO5VUS.js} +282 -2284
  14. package/Build/Workers/{chunk-OBS5EMZ6.js → chunk-B7JRBTT6.js} +10 -10
  15. package/Build/Workers/{chunk-5YXA47QD.js → chunk-CHNDJRYA.js} +20 -18
  16. package/Build/Workers/{chunk-X3ZV3XNO.js → chunk-CJOV55CW.js} +20 -18
  17. package/Build/Workers/{chunk-W6I3LNPF.js → chunk-COGPE5Z2.js} +10 -8
  18. package/Build/Workers/{chunk-2QPH5QDK.js → chunk-CW7W27IZ.js} +14 -10
  19. package/Build/Workers/{chunk-MXOGBWMP.js → chunk-DICY26ID.js} +20 -16
  20. package/Build/Workers/{chunk-W6KMV4F5.js → chunk-DMEFNTUV.js} +69 -7
  21. package/Build/Workers/{chunk-T7HU6E7G.js → chunk-DQSJEOZY.js} +1 -1
  22. package/Build/Workers/{chunk-ASVODZNK.js → chunk-GDU4RZSZ.js} +16 -36
  23. package/Build/Workers/{chunk-MQPDOWGH.js → chunk-GKWOUMYA.js} +1 -1
  24. package/Build/Workers/{chunk-A2SP2EJZ.js → chunk-GTY4K4IA.js} +9 -7
  25. package/Build/Workers/{chunk-KEPPNSBL.js → chunk-H6Q7E4BQ.js} +8 -6
  26. package/Build/Workers/{chunk-JG3C3LPY.js → chunk-HHGOFZVQ.js} +7 -5
  27. package/Build/Workers/chunk-HXKUEOOD.js +352 -0
  28. package/Build/Workers/{chunk-UFSYRVC5.js → chunk-I4REFVXB.js} +4 -4
  29. package/Build/Workers/{chunk-LU7DLY2L.js → chunk-IL5F6WEE.js} +3 -3
  30. package/Build/Workers/{chunk-RVRN4KDB.js → chunk-JKXPC5HD.js} +2 -2
  31. package/Build/Workers/{chunk-CBPNIEGH.js → chunk-KKGD7HAW.js} +13 -11
  32. package/Build/Workers/{chunk-DTKSVIH5.js → chunk-KROSQJUA.js} +2 -2
  33. package/Build/Workers/{chunk-42EJCSIV.js → chunk-L4JLDVCM.js} +5 -5
  34. package/Build/Workers/{chunk-LPKJSIMD.js → chunk-LIYMRHGR.js} +15 -13
  35. package/Build/Workers/{chunk-J2XQVKVH.js → chunk-MKMZHRB3.js} +74 -35
  36. package/Build/Workers/{chunk-CSDYSXBI.js → chunk-MO25ZQ2I.js} +14 -12
  37. package/Build/Workers/{chunk-3YNW5K6O.js → chunk-O6RZEKHZ.js} +12 -12
  38. package/Build/Workers/{chunk-RR3NCT4R.js → chunk-OOCGX2OD.js} +4 -4
  39. package/Build/Workers/{chunk-XG54SG4O.js → chunk-OXFU5HNU.js} +13 -5
  40. package/Build/Workers/{chunk-P2UKEFCK.js → chunk-P5CGIJUY.js} +2 -2
  41. package/Build/Workers/{chunk-DBHL2UVG.js → chunk-QEANVUGT.js} +2 -2
  42. package/Build/Workers/{chunk-2SI7DEW5.js → chunk-QFBCIX7J.js} +8 -6
  43. package/Build/Workers/{chunk-DDXI6UYW.js → chunk-QUAH3XOT.js} +4 -4
  44. package/Build/Workers/{chunk-PZUZCAX3.js → chunk-RXZDTDIY.js} +13 -9
  45. package/Build/Workers/{chunk-YZ3RCE45.js → chunk-SPA2KPH3.js} +14 -12
  46. package/Build/Workers/chunk-TDSVSW5A.js +1460 -0
  47. package/Build/Workers/{chunk-G3CKZ34K.js → chunk-UG2DPFOL.js} +8 -6
  48. package/Build/Workers/{chunk-IKUOV6DO.js → chunk-URGEDZBS.js} +7 -7
  49. package/Build/Workers/{chunk-U2GR5FDL.js → chunk-V35NQOJC.js} +21 -11
  50. package/Build/Workers/chunk-W4XUEDU5.js +2058 -0
  51. package/Build/Workers/chunk-WB4TSSBQ.js +3514 -0
  52. package/Build/Workers/{chunk-EBDZDBJN.js → chunk-WTLYD4FE.js} +19 -15
  53. package/Build/Workers/{chunk-WQZL6CA2.js → chunk-Y4ALZ4SS.js} +9 -7
  54. package/Build/Workers/{chunk-DAJKOQW6.js → chunk-YF2NVO5B.js} +19 -13
  55. package/Build/Workers/{chunk-XJVRYJVZ.js → chunk-YSYSXSHF.js} +1 -1
  56. package/Build/Workers/{chunk-YNOVMSUX.js → chunk-YX562XOB.js} +15 -11
  57. package/Build/Workers/{chunk-J3KPR6DJ.js → chunk-YZWA5B4R.js} +15 -13
  58. package/Build/Workers/{chunk-NYYQZ3LH.js → chunk-Z6DFT4D3.js} +15 -11
  59. package/Build/Workers/combineGeometry.js +24 -21
  60. package/Build/Workers/createBoxGeometry.js +18 -15
  61. package/Build/Workers/createBoxOutlineGeometry.js +16 -13
  62. package/Build/Workers/createCircleGeometry.js +28 -24
  63. package/Build/Workers/createCircleOutlineGeometry.js +21 -17
  64. package/Build/Workers/createCoplanarPolygonGeometry.js +35 -31
  65. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +33 -29
  66. package/Build/Workers/createCorridorGeometry.js +32 -28
  67. package/Build/Workers/createCorridorOutlineGeometry.js +30 -26
  68. package/Build/Workers/createCylinderGeometry.js +20 -17
  69. package/Build/Workers/createCylinderOutlineGeometry.js +20 -16
  70. package/Build/Workers/createEllipseGeometry.js +28 -24
  71. package/Build/Workers/createEllipseOutlineGeometry.js +21 -17
  72. package/Build/Workers/createEllipsoidGeometry.js +19 -16
  73. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -15
  74. package/Build/Workers/createFrustumGeometry.js +18 -15
  75. package/Build/Workers/createFrustumOutlineGeometry.js +18 -15
  76. package/Build/Workers/createGeometry.js +28 -22
  77. package/Build/Workers/createGroundPolylineGeometry.js +25 -21
  78. package/Build/Workers/createPlaneGeometry.js +16 -13
  79. package/Build/Workers/createPlaneOutlineGeometry.js +15 -12
  80. package/Build/Workers/createPolygonGeometry.js +35 -31
  81. package/Build/Workers/createPolygonOutlineGeometry.js +32 -28
  82. package/Build/Workers/createPolylineGeometry.js +27 -23
  83. package/Build/Workers/createPolylineVolumeGeometry.js +33 -29
  84. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +29 -25
  85. package/Build/Workers/createRectangleGeometry.js +30 -26
  86. package/Build/Workers/createRectangleOutlineGeometry.js +23 -19
  87. package/Build/Workers/createSimplePolylineGeometry.js +25 -21
  88. package/Build/Workers/createSphereGeometry.js +19 -16
  89. package/Build/Workers/createSphereOutlineGeometry.js +18 -15
  90. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  91. package/Build/Workers/createVectorTileClampedPolylines.js +16 -13
  92. package/Build/Workers/createVectorTileGeometries.js +24 -21
  93. package/Build/Workers/createVectorTilePoints.js +15 -12
  94. package/Build/Workers/createVectorTilePolygons.js +24 -20
  95. package/Build/Workers/createVectorTilePolylines.js +16 -13
  96. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +91 -0
  97. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +28 -23
  98. package/Build/Workers/createVerticesFromHeightmap.js +28 -23
  99. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +26 -279
  100. package/Build/Workers/createWallGeometry.js +26 -22
  101. package/Build/Workers/createWallOutlineGeometry.js +25 -21
  102. package/Build/Workers/decodeDraco.js +10 -10
  103. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  104. package/Build/Workers/decodeI3S.js +13 -11
  105. package/Build/Workers/gaussianSplatSorter.js +4 -4
  106. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  107. package/Build/Workers/incrementallyBuildTerrainPicker.js +121 -0
  108. package/Build/Workers/transcodeKTX2.js +6 -6
  109. package/Build/Workers/transferTypedArrayTest.js +1 -1
  110. package/Build/Workers/upsampleQuantizedTerrainMesh.js +24 -20
  111. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +95 -0
  112. package/Source/Core/ArcGISTiledElevationTerrainProvider.js +2 -2
  113. package/Source/Core/AxisAlignedBoundingBox.js +36 -0
  114. package/Source/Core/Cesium3DTilesTerrainData.js +932 -0
  115. package/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js +1868 -0
  116. package/Source/Core/Cesium3DTilesTerrainProvider.js +1052 -0
  117. package/Source/Core/CesiumTerrainProvider.js +2 -2
  118. package/Source/Core/Color.js +23 -6
  119. package/Source/Core/EllipsoidalOccluder.js +2 -2
  120. package/Source/Core/FeatureDetection.js +0 -2
  121. package/Source/Core/GoogleEarthEnterpriseMetadata.js +1 -1
  122. package/Source/Core/GoogleEarthEnterpriseTerrainData.js +2 -1
  123. package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +1 -1
  124. package/Source/Core/HeightmapTerrainData.js +12 -22
  125. package/Source/Core/HilbertOrder.js +0 -6
  126. package/Source/Core/ITwinPlatform.js +6 -6
  127. package/Source/Core/IntersectionTests.js +80 -0
  128. package/Source/Core/Ion.js +1 -1
  129. package/Source/Core/IonResource.js +35 -27
  130. package/Source/Core/PixelFormat.js +2 -2
  131. package/Source/Core/QuantizedMeshTerrainData.js +24 -57
  132. package/Source/Core/Resource.js +15 -11
  133. package/Source/Core/S2Cell.js +6 -18
  134. package/Source/Core/TaskProcessor.js +1 -1
  135. package/Source/Core/TerrainData.js +2 -1
  136. package/Source/Core/TerrainEncoding.js +215 -38
  137. package/Source/Core/TerrainMesh.js +215 -8
  138. package/Source/Core/TerrainPicker.js +607 -0
  139. package/Source/Core/TerrainProvider.js +151 -0
  140. package/Source/Core/TexturePacker.js +27 -12
  141. package/Source/Core/Transforms.js +28 -19
  142. package/Source/Core/VRTheWorldTerrainProvider.js +2 -2
  143. package/Source/Core/binarySearch.js +1 -1
  144. package/Source/Core/createWorldBathymetryAsync.js +2 -2
  145. package/Source/Core/createWorldTerrainAsync.js +3 -3
  146. package/Source/Core/loadImageFromTypedArray.js +9 -3
  147. package/Source/Core/mergeSort.js +1 -1
  148. package/Source/DataSources/BillboardGraphics.js +1 -1
  149. package/Source/DataSources/BillboardVisualizer.js +7 -4
  150. package/Source/DataSources/PropertyArray.js +2 -2
  151. package/Source/Renderer/AutomaticUniforms.js +61 -0
  152. package/Source/Renderer/Buffer.js +32 -0
  153. package/Source/Renderer/BufferUsage.js +3 -1
  154. package/Source/Renderer/Context.js +98 -14
  155. package/Source/Renderer/Pass.js +10 -9
  156. package/Source/Renderer/Sync.js +104 -0
  157. package/Source/Renderer/TextureAtlas.js +67 -27
  158. package/Source/Renderer/UniformState.js +12 -0
  159. package/Source/Renderer/VertexArray.js +1 -1
  160. package/Source/Scene/ArcGisMapServerImageryProvider.js +1 -1
  161. package/Source/Scene/ArcGisMapService.js +1 -1
  162. package/Source/Scene/Azure2DImageryProvider.js +99 -13
  163. package/Source/Scene/BatchTable.js +2 -2
  164. package/Source/Scene/Billboard.js +75 -28
  165. package/Source/Scene/BillboardCollection.js +24 -15
  166. package/Source/Scene/BillboardTexture.js +56 -7
  167. package/Source/Scene/BingMapsImageryProvider.js +1 -1
  168. package/Source/Scene/BoundingVolumeSemantics.js +54 -62
  169. package/Source/Scene/Cesium3DTile.js +3 -3
  170. package/Source/Scene/Cesium3DTilesVoxelProvider.js +1 -1
  171. package/Source/Scene/Cesium3DTileset.js +1 -1
  172. package/Source/Scene/EdgeFramebuffer.js +245 -0
  173. package/Source/Scene/FrameState.js +12 -0
  174. package/Source/Scene/GaussianSplat3DTileContent.js +12 -16
  175. package/Source/Scene/GaussianSplatPrimitive.js +12 -8
  176. package/Source/Scene/GaussianSplatSorter.js +2 -2
  177. package/Source/Scene/Globe.js +4 -2
  178. package/Source/Scene/GlobeSurfaceTile.js +28 -70
  179. package/Source/Scene/GlobeSurfaceTileProvider.js +11 -0
  180. package/Source/Scene/GltfBufferViewLoader.js +18 -0
  181. package/Source/Scene/GltfLoader.js +46 -8
  182. package/Source/Scene/Google2DImageryProvider.js +48 -41
  183. package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +1 -1
  184. package/Source/Scene/I3SDataProvider.js +1 -1
  185. package/Source/Scene/I3SDecoder.js +3 -3
  186. package/Source/Scene/ITwinData.js +4 -4
  187. package/Source/Scene/ImageryLayer.js +1 -1
  188. package/Source/Scene/Implicit3DTileContent.js +18 -7
  189. package/Source/Scene/ImplicitSubtree.js +3 -3
  190. package/Source/Scene/ImplicitTileset.js +2 -2
  191. package/Source/Scene/IonImageryProvider.js +15 -84
  192. package/Source/Scene/IonImageryProviderFactory.js +194 -0
  193. package/Source/Scene/LabelCollection.js +54 -36
  194. package/Source/Scene/MetadataComponentType.js +5 -5
  195. package/Source/Scene/MetadataTableProperty.js +3 -9
  196. package/Source/Scene/Model/EdgeDetectionPipelineStage.js +42 -0
  197. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +800 -0
  198. package/Source/Scene/Model/MetadataPipelineStage.js +7 -7
  199. package/Source/Scene/Model/ModelDrawCommand.js +69 -0
  200. package/Source/Scene/Model/ModelImagery.js +4 -0
  201. package/Source/Scene/Model/ModelRuntimeNode.js +2 -2
  202. package/Source/Scene/Model/ModelRuntimePrimitive.js +13 -2
  203. package/Source/Scene/Model/ModelSceneGraph.js +15 -3
  204. package/Source/Scene/Model/ModelUtility.js +0 -1
  205. package/Source/Scene/Model/NodeRenderResources.js +1 -1
  206. package/Source/Scene/Model/PrimitiveRenderResources.js +1 -1
  207. package/Source/Scene/OIT.js +11 -1
  208. package/Source/Scene/PickFramebuffer.js +134 -50
  209. package/Source/Scene/Picking.js +195 -89
  210. package/Source/Scene/QuadtreePrimitive.js +34 -26
  211. package/Source/Scene/QuadtreeTile.js +66 -46
  212. package/Source/Scene/ResourceLoaderState.js +1 -1
  213. package/Source/Scene/Scene.js +160 -16
  214. package/Source/Scene/ScreenSpaceCameraController.js +1 -1
  215. package/Source/Scene/SensorVolumePortionToDisplay.js +6 -6
  216. package/Source/Scene/SingleTileImageryProvider.js +3 -3
  217. package/Source/Scene/Terrain.js +5 -5
  218. package/Source/Scene/TerrainFillMesh.js +1 -0
  219. package/Source/Scene/TileMapServiceImageryProvider.js +2 -2
  220. package/Source/Scene/UrlTemplateImageryProvider.js +1 -1
  221. package/Source/Scene/View.js +3 -0
  222. package/Source/Scene/VoxelPrimitive.js +196 -189
  223. package/Source/Scene/VoxelShape.js +2 -0
  224. package/Source/Scene/createWorldImageryAsync.js +1 -1
  225. package/Source/Shaders/BillboardCollectionFS.glsl +115 -62
  226. package/Source/Shaders/BillboardCollectionFS.js +115 -63
  227. package/Source/Shaders/BillboardCollectionVS.glsl +44 -37
  228. package/Source/Shaders/BillboardCollectionVS.js +45 -38
  229. package/Source/Shaders/Builtin/Constants/passCesium3DTile.glsl +1 -1
  230. package/Source/Shaders/Builtin/Constants/passCesium3DTile.js +1 -1
  231. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.glsl +1 -1
  232. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassification.js +1 -1
  233. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.glsl +1 -1
  234. package/Source/Shaders/Builtin/Constants/passCesium3DTileClassificationIgnoreShow.js +1 -1
  235. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdges.glsl +10 -0
  236. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdges.js +12 -0
  237. package/Source/Shaders/Builtin/Constants/passGaussianSplats.glsl +1 -1
  238. package/Source/Shaders/Builtin/Constants/passGaussianSplats.js +1 -1
  239. package/Source/Shaders/Builtin/Constants/passOpaque.glsl +1 -1
  240. package/Source/Shaders/Builtin/Constants/passOpaque.js +1 -1
  241. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  242. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  243. package/Source/Shaders/Builtin/Constants/passTranslucent.glsl +1 -1
  244. package/Source/Shaders/Builtin/Constants/passTranslucent.js +1 -1
  245. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +1 -1
  246. package/Source/Shaders/Builtin/Constants/passVoxels.js +1 -1
  247. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  248. package/Source/Shaders/GlobeVS.glsl +1 -1
  249. package/Source/Shaders/GlobeVS.js +1 -1
  250. package/Source/Shaders/Model/EdgeDetectionStageFS.glsl +58 -0
  251. package/Source/Shaders/Model/EdgeDetectionStageFS.js +60 -0
  252. package/Source/Shaders/Model/EdgeVisibilityStageFS.glsl +83 -0
  253. package/Source/Shaders/Model/EdgeVisibilityStageFS.js +85 -0
  254. package/Source/Shaders/Model/ModelFS.glsl +5 -0
  255. package/Source/Shaders/Model/ModelFS.js +5 -0
  256. package/Source/Shaders/Model/PrimitiveOutlineStageFS.glsl +0 -1
  257. package/Source/Shaders/Model/PrimitiveOutlineStageFS.js +0 -1
  258. package/Source/Shaders/ShadowVolumeAppearanceFS.glsl +7 -15
  259. package/Source/Shaders/ShadowVolumeAppearanceFS.js +7 -15
  260. package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
  261. package/Source/ThirdParty/zip-module.wasm +0 -0
  262. package/Source/Workers/createVerticesFromCesium3DTilesTerrain.js +46 -0
  263. package/Source/Workers/incrementallyBuildTerrainPicker.js +108 -0
  264. package/Source/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +55 -0
  265. package/index.d.ts +488 -31
  266. package/index.js +202 -190
  267. package/package.json +3 -2
@@ -0,0 +1,1052 @@
1
+ import BoundingSphere from "./BoundingSphere.js";
2
+ import Cesium3DTilesTerrainData from "./Cesium3DTilesTerrainData.js";
3
+ import CesiumMath from "./Math.js";
4
+ import Check from "./Check.js";
5
+ import Credit from "./Credit.js";
6
+ import defined from "./defined.js";
7
+ import DeveloperError from "./DeveloperError.js";
8
+ import DoubleEndedPriorityQueue from "./DoubleEndedPriorityQueue.js";
9
+ import Ellipsoid from "./Ellipsoid.js";
10
+ import Event from "./Event.js";
11
+ import Frozen from "./Frozen.js";
12
+ import GeographicTilingScheme from "./GeographicTilingScheme.js";
13
+ import ImplicitSubtree from "../Scene/ImplicitSubtree.js";
14
+ import ImplicitTileCoordinates from "../Scene/ImplicitTileCoordinates.js";
15
+ import IonResource from "./IonResource.js";
16
+ import ImplicitTileset from "../Scene/ImplicitTileset.js";
17
+ import loadImageFromTypedArray from "./loadImageFromTypedArray.js";
18
+ import MetadataSchema from "../Scene/MetadataSchema.js";
19
+ import MetadataSchemaLoader from "../Scene/MetadataSchemaLoader.js";
20
+ import MetadataSemantic from "../Scene/MetadataSemantic.js";
21
+ import OrientedBoundingBox from "./OrientedBoundingBox.js";
22
+ import parseGlb from "../Scene/GltfPipeline/parseGlb.js";
23
+ import Rectangle from "./Rectangle.js";
24
+ import Resource from "./Resource.js";
25
+ import ResourceCache from "../Scene/ResourceCache.js";
26
+ import RuntimeError from "./RuntimeError.js";
27
+ import TerrainProvider from "./TerrainProvider.js";
28
+
29
+ /**
30
+ * @typedef {object} Cesium3DTilesTerrainProvider.ConstructorOptions
31
+ *
32
+ * Initialization options for the Cesium3DTilesTerrainProvider constructor
33
+ *
34
+ * @property {boolean} [requestVertexNormals=false] Flag that indicates if the client should request additional lighting information from the server, in the form of per vertex normals if available.
35
+ * @property {boolean} [requestWaterMask=false] Flag that indicates if the client should request per tile water masks from the server, if available.
36
+ * @property {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
37
+ * @property {Credit|string} [credit] A credit for the data source, which is displayed on the canvas.
38
+ */
39
+
40
+ /**
41
+ * <div class="notice">
42
+ * To construct a Cesium3DTilesTerrainProvider, call {@link Cesium3DTilesTerrainProvider.fromIonAssetId} or {@link Cesium3DTilesTerrainProvider.fromUrl}. Do not call the constructor directly.
43
+ * </div>
44
+ *
45
+ * A {@link TerrainProvider} that accesses terrain data in a 3D Tiles format.
46
+ *
47
+ * @alias Cesium3DTilesTerrainProvider
48
+ * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
49
+ * @constructor
50
+ *
51
+ * @param {Cesium3DTilesTerrainProvider.ConstructorOptions}[options] An object describing initialization options
52
+ *
53
+ * @see TerrainProvider
54
+ * @see Cesium3DTilesTerrainProvider.fromUrl
55
+ * @see Cesium3DTilesTerrainProvider.fromIonAssetId
56
+ *
57
+ * // Create GTOPO30 with vertex normals
58
+ * try {
59
+ * const viewer = new Cesium.Viewer("cesiumContainer", {
60
+ * terrainProvider: await Cesium.Cesium3DTilesTerrainProvider.fromIonAssetId(2732686, {
61
+ * requestVertexNormals: true
62
+ * })
63
+ * });
64
+ * } catch (error) {
65
+ * console.log(error);
66
+ * }
67
+ */
68
+ function Cesium3DTilesTerrainProvider(options) {
69
+ options = options ?? Frozen.EMPTY_OBJECT;
70
+
71
+ let credit = options.credit;
72
+ if (typeof credit === "string") {
73
+ credit = new Credit(credit);
74
+ }
75
+ this._credit = credit;
76
+ this._tileCredits = undefined;
77
+ this._errorEvent = new Event();
78
+ this._ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84;
79
+
80
+ this._tilingScheme = new GeographicTilingScheme({
81
+ ellipsoid: this._ellipsoid,
82
+ });
83
+
84
+ this._subtreeCache = new ImplicitSubtreeCache({
85
+ provider: this,
86
+ });
87
+
88
+ /**
89
+ * @private
90
+ * @type {ImplicitTileset|undefined}
91
+ */
92
+ this._tileset0 = undefined;
93
+ /**
94
+ * @private
95
+ * @type {ImplicitTileset|undefined}
96
+ */
97
+ this._tileset1 = undefined;
98
+
99
+ this._resource = undefined;
100
+
101
+ /**
102
+ * Boolean flag that indicates if the client should request vertex normals from the server.
103
+ * @type {boolean}
104
+ * @default false
105
+ * @private
106
+ */
107
+ this._requestVertexNormals = options.requestVertexNormals ?? false;
108
+
109
+ /**
110
+ * Boolean flag that indicates if the client should request tile watermasks from the server.
111
+ * @type {boolean}
112
+ * @default false
113
+ * @private
114
+ */
115
+ this._requestWaterMask = options.requestWaterMask ?? false;
116
+ }
117
+
118
+ /**
119
+ * Creates a {@link TerrainProvider} that accesses terrain data in a Cesium 3D Tiles format.
120
+ *
121
+ * @param {Resource|string|Promise<Resource>|Promise<string>} url The URL of the Cesium terrain server.
122
+ * @param {Cesium3DTilesTerrainProvider.ConstructorOptions} [options] An object describing initialization options.
123
+ * @returns {Promise<Cesium3DTilesTerrainProvider>} A promise that resolves to the terrain provider.
124
+ *
125
+ * @example
126
+ * // Create terrain with normals.
127
+ * try {
128
+ * const viewer = new Cesium.Viewer("cesiumContainer", {
129
+ * terrainProvider: await Cesium.Cesium3DTilesTerrainProvider.fromUrl(
130
+ * Cesium.IonResource.fromAssetId(3956), {
131
+ * requestVertexNormals: true
132
+ * })
133
+ * });
134
+ * } catch (error) {
135
+ * console.log(error);
136
+ * }
137
+ */
138
+ Cesium3DTilesTerrainProvider.fromUrl = async function (url, options) {
139
+ //>>includeStart('debug', pragmas.debug);
140
+ Check.defined("url", url);
141
+ //>>includeEnd('debug');
142
+
143
+ options = options ?? Frozen.EMPTY_OBJECT;
144
+
145
+ url = await Promise.resolve(url);
146
+ const resource = Resource.createIfNeeded(url);
147
+
148
+ let tilesetJson;
149
+ try {
150
+ tilesetJson = await resource.fetchJson();
151
+ } catch (error) {
152
+ throw new RuntimeError("Could not load tileset JSON", error);
153
+ }
154
+
155
+ const provider = new Cesium3DTilesTerrainProvider(options);
156
+ // ion resources have a credits property we can use for additional attribution.
157
+ provider._tileCredits = resource.credits;
158
+ provider._resource = resource;
159
+
160
+ const childrenJson = tilesetJson["root"]["children"];
161
+ const child0Json = childrenJson[0];
162
+ const child1Json = childrenJson[1];
163
+
164
+ const metadataSchemaJson = tilesetJson["schema"];
165
+ const metadataSchema = MetadataSchema.fromJson(metadataSchemaJson);
166
+
167
+ provider._tileset0 = new ImplicitTileset(
168
+ resource,
169
+ child0Json,
170
+ metadataSchema,
171
+ );
172
+ provider._tileset1 = new ImplicitTileset(
173
+ resource,
174
+ child1Json,
175
+ metadataSchema,
176
+ );
177
+
178
+ return provider;
179
+ };
180
+
181
+ /**
182
+ * Creates a {@link TerrainProvider} from a Cesium ion asset ID that accesses terrain data in a Cesium 3D Tiles format
183
+ *
184
+ * @param {number} assetId The Cesium ion asset id.
185
+ * @param {CesiumTerrainProvider.ConstructorOptions} [options] An object describing initialization options.
186
+ * @returns {Promise<CesiumTerrainProvider>}
187
+ *
188
+ * @example
189
+ * // Create GTOPO30 with vertex normals
190
+ * try {
191
+ * const viewer = new Cesium.Viewer("cesiumContainer", {
192
+ * terrainProvider: await Cesium.Cesium3DTilesTerrainProvider.fromIonAssetId(2732686, {
193
+ * requestVertexNormals: true
194
+ * })
195
+ * });
196
+ * } catch (error) {
197
+ * console.log(error);
198
+ * }
199
+ *
200
+ * @exception {RuntimeError} layer.json does not specify a format
201
+ * @exception {RuntimeError} layer.json specifies an unknown format
202
+ * @exception {RuntimeError} layer.json specifies an unsupported quantized-mesh version
203
+ * @exception {RuntimeError} layer.json does not specify a tiles property, or specifies an empty array
204
+ * @exception {RuntimeError} layer.json does not specify any tile URL templates
205
+ */
206
+ Cesium3DTilesTerrainProvider.fromIonAssetId = async function (
207
+ assetId,
208
+ options,
209
+ ) {
210
+ //>>includeStart('debug', pragmas.debug);
211
+ Check.defined("assetId", assetId);
212
+ //>>includeEnd('debug');
213
+
214
+ const resource = await IonResource.fromAssetId(assetId);
215
+ return Cesium3DTilesTerrainProvider.fromUrl(resource, options);
216
+ };
217
+
218
+ const scratchPromises = new Array(3);
219
+
220
+ /**
221
+ * Requests the geometry for a given tile. This function should not be called before
222
+ * {@link Cesium3DTilesTerrainProvider#ready} returns true. The result must include terrain data and
223
+ * may optionally include a water mask and an indication of which child tiles are available.
224
+ *
225
+ * @param {number} x The X coordinate of the tile for which to request geometry.
226
+ * @param {number} y The Y coordinate of the tile for which to request geometry.
227
+ * @param {number} level The level of the tile for which to request geometry.
228
+ * @param {Request} [request] The request object. Intended for internal use only.
229
+ *
230
+ * @returns {Promise.<Cesium3DTilesTerrainData>|undefined} A promise for the requested geometry. If this method
231
+ * returns undefined instead of a promise, it is an indication that too many requests are already
232
+ * pending and the request will be retried later.
233
+ */
234
+ Cesium3DTilesTerrainProvider.prototype.requestTileGeometry = async function (
235
+ x,
236
+ y,
237
+ level,
238
+ request,
239
+ ) {
240
+ const rootId = getRootIdFromGeographic(level, x);
241
+ const implicitTileset = rootId === 0 ? this._tileset0 : this._tileset1;
242
+
243
+ const tileCoord = getImplicitTileCoordinatesFromGeographicCoordinates(
244
+ implicitTileset,
245
+ level,
246
+ x,
247
+ y,
248
+ );
249
+
250
+ const subtreeCoord = tileCoord.getSubtreeCoordinates();
251
+
252
+ const cache = this._subtreeCache;
253
+ let subtree = cache.find(rootId, subtreeCoord);
254
+
255
+ const requestWaterMask = this._requestWaterMask;
256
+ const that = this;
257
+
258
+ let subtreePromise;
259
+ if (subtree === undefined) {
260
+ const subtreeRelative =
261
+ implicitTileset.subtreeUriTemplate.getDerivedResource({
262
+ templateValues: subtreeCoord.getTemplateValues(),
263
+ });
264
+ const subtreeResource = implicitTileset.baseResource.getDerivedResource({
265
+ url: subtreeRelative.url,
266
+ });
267
+ subtreePromise = subtreeResource
268
+ .fetchArrayBuffer()
269
+ .then(async function (arrayBuffer) {
270
+ // Check if the subtree exists again in case multiple fetches for the same subtree went out at the same time. Don't want to double-add to the cache
271
+ subtree = cache.find(rootId, subtreeCoord);
272
+ if (subtree === undefined) {
273
+ const bufferU8 = new Uint8Array(arrayBuffer);
274
+ subtree = await ImplicitSubtree.fromSubtreeJson(
275
+ that._resource,
276
+ undefined,
277
+ bufferU8,
278
+ implicitTileset,
279
+ subtreeCoord,
280
+ );
281
+ cache.addSubtree(rootId, subtree);
282
+ }
283
+
284
+ return subtree;
285
+ });
286
+ } else {
287
+ subtreePromise = Promise.resolve(subtree);
288
+ }
289
+
290
+ // Note: only one content for terrain
291
+ const glbRelative = implicitTileset.contentUriTemplates[0].getDerivedResource(
292
+ {
293
+ templateValues: tileCoord.getTemplateValues(),
294
+ },
295
+ );
296
+ const glbResource = implicitTileset.baseResource.getDerivedResource({
297
+ url: glbRelative.url,
298
+ });
299
+
300
+ // Start fetching the glb right away -- possibly even before the subtree is loaded in some cases
301
+ const glbPromise = glbResource.fetchArrayBuffer();
302
+ if (glbPromise === undefined) {
303
+ return undefined;
304
+ }
305
+
306
+ const gltfPromise = glbPromise.then((glbBuffer) =>
307
+ parseGlb(new Uint8Array(glbBuffer)),
308
+ );
309
+
310
+ const promises = scratchPromises;
311
+ promises[0] = subtreePromise;
312
+ promises[1] = gltfPromise;
313
+ promises[2] = requestWaterMask
314
+ ? gltfPromise.then((gltf) => loadWaterMask(gltf, glbResource))
315
+ : undefined;
316
+
317
+ try {
318
+ const results = await Promise.all(promises);
319
+ const subtree = results[0];
320
+ const gltf = results[1];
321
+ const waterMask = results[2];
322
+
323
+ const metadataView = subtree.getTileMetadataView(tileCoord);
324
+
325
+ const minimumHeight = metadataView.getPropertyBySemantic(
326
+ MetadataSemantic.TILE_MINIMUM_HEIGHT,
327
+ );
328
+
329
+ const maximumHeight = metadataView.getPropertyBySemantic(
330
+ MetadataSemantic.TILE_MAXIMUM_HEIGHT,
331
+ );
332
+
333
+ const boundingSphereArray = metadataView.getPropertyBySemantic(
334
+ MetadataSemantic.TILE_BOUNDING_SPHERE,
335
+ );
336
+ const boundingSphere = BoundingSphere.unpack(
337
+ boundingSphereArray,
338
+ 0,
339
+ new BoundingSphere(),
340
+ );
341
+
342
+ const horizonOcclusionPoint = metadataView.getPropertyBySemantic(
343
+ MetadataSemantic.TILE_HORIZON_OCCLUSION_POINT,
344
+ );
345
+
346
+ const tilingScheme = that._tilingScheme;
347
+
348
+ // The tiling scheme uses geographic coords, not implicit coords
349
+ const rectangle = tilingScheme.tileXYToRectangle(
350
+ x,
351
+ y,
352
+ level,
353
+ new Rectangle(),
354
+ );
355
+
356
+ const ellipsoid = that._ellipsoid;
357
+
358
+ const orientedBoundingBox = OrientedBoundingBox.fromRectangle(
359
+ rectangle,
360
+ minimumHeight,
361
+ maximumHeight,
362
+ ellipsoid,
363
+ new OrientedBoundingBox(),
364
+ );
365
+
366
+ const skirtHeight = that.getLevelMaximumGeometricError(level) * 5.0;
367
+
368
+ const hasSW = isChildAvailable(implicitTileset, subtree, tileCoord, 0, 0);
369
+ const hasSE = isChildAvailable(implicitTileset, subtree, tileCoord, 1, 0);
370
+ const hasNW = isChildAvailable(implicitTileset, subtree, tileCoord, 0, 1);
371
+ const hasNE = isChildAvailable(implicitTileset, subtree, tileCoord, 1, 1);
372
+ const childTileMask =
373
+ (hasSW ? 1 : 0) | (hasSE ? 2 : 0) | (hasNW ? 4 : 0) | (hasNE ? 8 : 0);
374
+
375
+ const terrainData = new Cesium3DTilesTerrainData({
376
+ gltf: gltf,
377
+ minimumHeight: minimumHeight,
378
+ maximumHeight: maximumHeight,
379
+ boundingSphere: boundingSphere,
380
+ orientedBoundingBox: orientedBoundingBox,
381
+ horizonOcclusionPoint: horizonOcclusionPoint,
382
+ skirtHeight: skirtHeight,
383
+ requestVertexNormals: that._requestVertexNormals,
384
+ childTileMask: childTileMask,
385
+ credits: that._tileCredits,
386
+ waterMask: waterMask,
387
+ });
388
+
389
+ return Promise.resolve(terrainData);
390
+ } catch (err) {
391
+ console.log(
392
+ `Could not load subtree: ${rootId} ${subtreeCoord.level} ${subtreeCoord.x} ${subtreeCoord.y}: ${err}`,
393
+ );
394
+
395
+ console.log(
396
+ `Could not load tile: ${rootId} ${tileCoord.level} ${tileCoord.x} ${tileCoord.y}: ${err}`,
397
+ );
398
+ return undefined;
399
+ }
400
+ };
401
+
402
+ /**
403
+ * Determines whether data for a tile is available to be loaded.
404
+ *
405
+ * @param {number} x The X coordinate of the tile for which to request geometry.
406
+ * @param {number} y The Y coordinate of the tile for which to request geometry.
407
+ * @param {number} level The level of the tile for which to request geometry.
408
+ * @returns {boolean|undefined} Undefined if not supported or availability is unknown, otherwise true or false.
409
+ */
410
+ Cesium3DTilesTerrainProvider.prototype.getTileDataAvailable = function (
411
+ x,
412
+ y,
413
+ level,
414
+ ) {
415
+ const cache = this._subtreeCache;
416
+
417
+ const rootId = getRootIdFromGeographic(level, x);
418
+ const implicitTileset = rootId === 0 ? this._tileset0 : this._tileset1;
419
+ const tileCoord = getImplicitTileCoordinatesFromGeographicCoordinates(
420
+ implicitTileset,
421
+ level,
422
+ x,
423
+ y,
424
+ );
425
+
426
+ const subtreeCoord = tileCoord.getSubtreeCoordinates();
427
+ const subtree = cache.find(rootId, subtreeCoord);
428
+
429
+ // If the subtree is loaded, return the tile's availability
430
+ if (subtree !== undefined) {
431
+ const available = subtree.tileIsAvailableAtCoordinates(tileCoord);
432
+ return available;
433
+ }
434
+
435
+ if (subtreeCoord.isImplicitTilesetRoot()) {
436
+ if (tileCoord.isSubtreeRoot()) {
437
+ // The subtree's root tile is always available
438
+ return true;
439
+ }
440
+ // Don't know if the tile is available because its subtree hasn't been loaded yet
441
+ return undefined;
442
+ }
443
+
444
+ const parentSubtreeCoord = subtreeCoord.getParentSubtreeCoordinates();
445
+
446
+ // Check the parent subtree's child subtree availability to know if this subtree is available.
447
+ const parentSubtree = cache.find(rootId, parentSubtreeCoord);
448
+ if (parentSubtree !== undefined) {
449
+ const isChildSubtreeAvailable =
450
+ parentSubtree.childSubtreeIsAvailableAtCoordinates(subtreeCoord);
451
+
452
+ if (isChildSubtreeAvailable) {
453
+ return tileCoord.isSubtreeRoot()
454
+ ? true // The root tile of the subtree is always available
455
+ : undefined; // Don't know if the tile is available because the subtree hasn't been loaded yet
456
+ }
457
+ // Child subtree not available, so this tile isn't either
458
+ return false;
459
+ }
460
+
461
+ // The parent subtree isn't loaded either, so we don't even know if the child subtree is available
462
+ return undefined;
463
+ };
464
+
465
+ /**
466
+ * Gets the root ID from geographic tile coordinates.
467
+ * There are 2 root tiles in a geographic tiling scheme: one for each hemisphere.
468
+ * @private
469
+ * @param {number} level The level of the tile
470
+ * @param {number} x The x coordinate of the tile
471
+ * @returns {number} The root tile ID (0 or 1)
472
+ */
473
+ function getRootIdFromGeographic(level, x) {
474
+ //>>includeStart('debug', pragmas.debug);
475
+ Check.typeOf.number("level", level);
476
+ Check.typeOf.number("x", x);
477
+ //>>includeEnd('debug');
478
+
479
+ const numberOfYTilesAtLevel = 1 << level;
480
+ const rootId = (x / numberOfYTilesAtLevel) | 0;
481
+ return rootId;
482
+ }
483
+
484
+ /**
485
+ * Gets the implicit tile coordinates from geographic tile coordinates.
486
+ * @private
487
+ * @param {ImplicitTileset} implicitTileset
488
+ * @param {number} level The level of the tile
489
+ * @param {number} x The x coordinate of the tile
490
+ * @param {number} y The y coordinate of the tile
491
+ * @returns {ImplicitTileCoordinates} The implicit tile coordinates
492
+ */
493
+ function getImplicitTileCoordinatesFromGeographicCoordinates(
494
+ implicitTileset,
495
+ level,
496
+ x,
497
+ y,
498
+ ) {
499
+ //>>includeStart('debug', pragmas.debug);
500
+ Check.typeOf.object("implicitTileset", implicitTileset);
501
+ Check.typeOf.number("level", level);
502
+ Check.typeOf.number("x", x);
503
+ Check.typeOf.number("y", y);
504
+ //>>includeEnd('debug');
505
+
506
+ const numberOfYTilesAtLevel = 1 << level;
507
+ const implicitLevel = level;
508
+ const implicitX = x % numberOfYTilesAtLevel;
509
+ const implicitY = numberOfYTilesAtLevel - y - 1;
510
+ const { subdivisionScheme, subtreeLevels } = implicitTileset;
511
+
512
+ return new ImplicitTileCoordinates({
513
+ subdivisionScheme: subdivisionScheme,
514
+ subtreeLevels: subtreeLevels,
515
+ level: implicitLevel,
516
+ x: implicitX,
517
+ y: implicitY,
518
+ });
519
+ }
520
+
521
+ /**
522
+ * Loads the water mask image texture from the glTF.
523
+ * @private
524
+ * @param {Object.<string,*>} gltf The glTF JSON.
525
+ * @param {Resource} gltfResource The resource pointing to the glTF.
526
+ * @returns {Promise<HTMLImageElement|HTMLCanvasElement|ImageBitmap>|undefined} A promise that resolves to the loaded image. Returns undefined if <code>request.throttle</code> is true and the request does not have high enough priority.
527
+ */
528
+ async function loadWaterMask(gltf, gltfResource) {
529
+ const extension = gltf.extensions?.["EXT_structural_metadata"];
530
+ if (!defined(extension) || !defined(extension.propertyTextures)) {
531
+ return;
532
+ }
533
+
534
+ const schemaLoader = new MetadataSchemaLoader({
535
+ schema: extension.schema,
536
+ });
537
+
538
+ await schemaLoader.load();
539
+ const schema = schemaLoader.schema;
540
+
541
+ let metadataClass, waterMaskProperty;
542
+ if (defined(schema.classes)) {
543
+ for (const classId in schema.classes) {
544
+ if (schema.classes.hasOwnProperty(classId)) {
545
+ metadataClass = schema.classes[classId];
546
+ waterMaskProperty = metadataClass.propertiesBySemantic["WATERMASK"];
547
+ if (defined(waterMaskProperty)) {
548
+ break;
549
+ }
550
+ }
551
+ }
552
+ }
553
+
554
+ if (!defined(waterMaskProperty)) {
555
+ return;
556
+ }
557
+
558
+ const propertyTextureData = extension.propertyTextures.find(
559
+ (data) => data.class === metadataClass.id,
560
+ );
561
+ if (!defined(propertyTextureData)) {
562
+ throw new DeveloperError(
563
+ `Expected a propertyTexture with a class ${metadataClass.id}`,
564
+ );
565
+ }
566
+
567
+ const textureInfo = propertyTextureData.properties[waterMaskProperty.id];
568
+ const texture = gltf.textures[textureInfo.index];
569
+ const bufferViewId = gltf.images[texture.source]?.bufferView;
570
+
571
+ const bufferViewLoader = ResourceCache.getBufferViewLoader({
572
+ gltf: gltf,
573
+ bufferViewId: bufferViewId,
574
+ gltfResource: gltfResource,
575
+ baseResource: gltfResource,
576
+ });
577
+ await bufferViewLoader.load();
578
+
579
+ const image = await loadImageFromTypedArray({
580
+ uint8Array: new Uint8Array(bufferViewLoader.typedArray),
581
+ format: "image/png",
582
+ flipY: false,
583
+ skipColorSpaceConversion: true,
584
+ });
585
+
586
+ return image;
587
+ }
588
+
589
+ /**
590
+ * Checks whether a child tile at a given tile coordinate is available in the given subtree.
591
+ * @private
592
+ * @param {ImplicitTileset} implicitTileset The implicit tileset
593
+ * @param {ImplicitSubtree} subtree The subtree
594
+ * @param {ImplicitTileCoordinates} coord The tile coordinates of the parent tile
595
+ * @param {number} x The x coordinate of the child tile
596
+ * @param {number} y The y coordinate of the child tile
597
+ * @returns {boolean} <code>true</code> if the child tile is available. <code>false</code> otherwise.
598
+ */
599
+ function isChildAvailable(implicitTileset, subtree, coord, x, y) {
600
+ //>>includeStart('debug', pragmas.debug);
601
+ Check.typeOf.object("implicitTileset", implicitTileset);
602
+ Check.typeOf.object("subtree", subtree);
603
+ Check.typeOf.object("coord", coord);
604
+ Check.typeOf.number("x", x);
605
+ Check.typeOf.number("y", y);
606
+ //>>includeEnd('debug');
607
+
608
+ // For terrain it's required that the root tile of any available subtree is also available, so
609
+ // when the child tile belongs to a child subtree, we only need to check if the child subtree itself is available.
610
+ const isBottomOfSubtree = coord.isBottomOfSubtree();
611
+
612
+ const localLevel = 1;
613
+ const offset = getImplicitTileCoordinates(implicitTileset, localLevel, x, y);
614
+ const childCoord = coord.getDescendantCoordinates(offset);
615
+
616
+ const isAvailable = isBottomOfSubtree
617
+ ? subtree.childSubtreeIsAvailableAtCoordinates(childCoord)
618
+ : subtree.tileIsAvailableAtCoordinates(childCoord);
619
+
620
+ return isAvailable;
621
+ }
622
+
623
+ /**
624
+ * Gets the implicit tile coordinates from geographic tile coordinates.
625
+ * @private
626
+ * @param {ImplicitTileset} implicitTileset
627
+ * @param {number} level The level of the tile
628
+ * @param {number} x The x coordinate of the tile
629
+ * @param {number} y The y coordinate of the tile
630
+ * @returns {ImplicitTileCoordinates}
631
+ */
632
+ function getImplicitTileCoordinates(implicitTileset, level, x, y) {
633
+ //>>includeStart('debug', pragmas.debug);
634
+ Check.typeOf.object("implicitTileset", implicitTileset);
635
+ Check.typeOf.number("level", level);
636
+ Check.typeOf.number("x", x);
637
+ Check.typeOf.number("y", y);
638
+ //>>includeEnd('debug');
639
+
640
+ const { subdivisionScheme, subtreeLevels } = implicitTileset;
641
+
642
+ return new ImplicitTileCoordinates({
643
+ subdivisionScheme: subdivisionScheme,
644
+ subtreeLevels: subtreeLevels,
645
+ level: level,
646
+ x: x,
647
+ y: y,
648
+ });
649
+ }
650
+
651
+ /**
652
+ * Make sure we load availability data for a tile
653
+ *
654
+ * @param {number} _x The X coordinate of the tile for which to request geometry.
655
+ * @param {number} _y The Y coordinate of the tile for which to request geometry.
656
+ * @param {number} _level The level of the tile for which to request geometry.
657
+ * @returns {Promise<void>|undefined} Undefined if nothing need to be loaded or a Promise that resolves when all required tiles are loaded
658
+ */
659
+ Cesium3DTilesTerrainProvider.prototype.loadTileDataAvailability = function (
660
+ _x,
661
+ _y,
662
+ _level,
663
+ ) {
664
+ return undefined;
665
+ };
666
+
667
+ /**
668
+ * Get the maximum geometric error allowed in a tile at a given level.
669
+ *
670
+ * @param {number} level The tile level for which to get the maximum geometric error.
671
+ * @returns {number} The maximum geometric error.
672
+ */
673
+ Cesium3DTilesTerrainProvider.prototype.getLevelMaximumGeometricError =
674
+ function (level) {
675
+ const ellipsoid = this._ellipsoid;
676
+ const rootError =
677
+ TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(
678
+ ellipsoid,
679
+ 64,
680
+ 2,
681
+ );
682
+ return rootError / (1 << level);
683
+ };
684
+
685
+ Object.defineProperties(Cesium3DTilesTerrainProvider.prototype, {
686
+ /**
687
+ * Gets an event that is raised when the terrain provider encounters an asynchronous error. By subscribing
688
+ * to the event, you will be notified of the error and can potentially recover from it. Event listeners
689
+ * are passed an instance of {@link TileProviderError}.
690
+ * @memberof Cesium3DTilesTerrainProvider.prototype
691
+ * @type {Event}
692
+ */
693
+ errorEvent: {
694
+ get: function () {
695
+ return this._errorEvent;
696
+ },
697
+ },
698
+
699
+ /**
700
+ * Gets the credit to display when this terrain provider is active. Typically this is used to credit
701
+ * the source of the terrain.
702
+ * @memberof Cesium3DTilesTerrainProvider.prototype
703
+ * @type {Credit}
704
+ */
705
+ credit: {
706
+ get: function () {
707
+ return this._credit;
708
+ },
709
+ },
710
+
711
+ /**
712
+ * Gets the tiling scheme used by the provider.
713
+ * @memberof Cesium3DTilesTerrainProvider.prototype
714
+ * @type {TilingScheme}
715
+ */
716
+ tilingScheme: {
717
+ get: function () {
718
+ return this._tilingScheme;
719
+ },
720
+ },
721
+
722
+ /**
723
+ * Gets a value indicating whether or not the provider includes a water mask. The water mask
724
+ * indicates which areas of the globe are water rather than land, so they can be rendered
725
+ * as a reflective surface with animated waves.
726
+ * @memberof Cesium3DTilesTerrainProvider.prototype
727
+ * @type {boolean}
728
+ */
729
+ hasWaterMask: {
730
+ get: function () {
731
+ return this._requestWaterMask;
732
+ },
733
+ },
734
+
735
+ /**
736
+ * Gets a value indicating whether or not the requested tiles include vertex normals.
737
+ * @memberof Cesium3DTilesTerrainProvider.prototype
738
+ * @type {boolean}
739
+ */
740
+ hasVertexNormals: {
741
+ get: function () {
742
+ return this._requestVertexNormals;
743
+ },
744
+ },
745
+
746
+ /**
747
+ * Gets an object that can be used to determine availability of terrain from this provider, such as
748
+ * at points and in rectangles.
749
+ * @memberof Cesium3DTilesTerrainProvider.prototype
750
+ * @type {TileAvailability|undefined}
751
+ */
752
+ availability: {
753
+ get: function () {
754
+ return this._subtreeCache;
755
+ },
756
+ },
757
+ });
758
+
759
+ /**
760
+ * A node in the implicit subtree cache.
761
+ * @private
762
+ * @constructor
763
+ * @param {number} rootId The root tile ID (0 or 1)
764
+ * @param {ImplicitSubtree} subtree The subtree
765
+ * @param {number} stamp The timestamp used for priority ordering
766
+ */
767
+ function ImplicitSubtreeCacheNode(rootId, subtree, stamp) {
768
+ this.rootId = rootId;
769
+ this.subtree = subtree;
770
+ this.stamp = stamp;
771
+ }
772
+
773
+ /**
774
+ * A cache for implicit subtrees.
775
+ * @private
776
+ * @constructor
777
+ * @param {object} options Object with the following properties
778
+ * @param {Cesium3DTilesTerrainProvider} options.provider
779
+ * @param {number} [options.maximumSubtreeCount=0] The total number of subtrees this cache can store. If adding a new subtree would exceed this limit, the lowest priority subtrees will be removed until there is room, unless the subtree that is going to be removed is the parent of the new subtree, in which case it will not be removed and the new subtree will still be added, exceeding the memory limit.
780
+ */
781
+ function ImplicitSubtreeCache(options) {
782
+ this._maximumSubtreeCount = options.maximumSubtreeCount ?? 0;
783
+ this._subtreeRequestCounter = 0;
784
+
785
+ this._queue = new DoubleEndedPriorityQueue({
786
+ comparator: ImplicitSubtreeCache.comparator,
787
+ });
788
+
789
+ this._provider = options.provider;
790
+ }
791
+
792
+ /**
793
+ * @param {ImplicitSubtreeCacheNode} a
794
+ * @param {ImplicitSubtreeCacheNode} b
795
+ * @returns {number}
796
+ */
797
+ ImplicitSubtreeCache.comparator = function (a, b) {
798
+ const aCoord = a.subtree.implicitCoordinates;
799
+ const bCoord = b.subtree.implicitCoordinates;
800
+ if (aCoord.isAncestor(bCoord)) {
801
+ // Technically this shouldn't happen because the ancestor subtree was supposed to be added to the cache first.
802
+ return +1.0;
803
+ } else if (bCoord.isAncestor(aCoord)) {
804
+ return -1.0;
805
+ }
806
+ return a.stamp - b.stamp;
807
+ };
808
+
809
+ /**
810
+ * Adds a subtree to the cache.
811
+ * @param {number} rootId The root tile ID (0 or 1)
812
+ * @param {ImplicitSubtree} subtree The subtree
813
+ */
814
+ ImplicitSubtreeCache.prototype.addSubtree = function (rootId, subtree) {
815
+ const cacheNode = new ImplicitSubtreeCacheNode(
816
+ rootId,
817
+ subtree,
818
+ this._subtreeRequestCounter,
819
+ );
820
+ this._queue.insert(cacheNode);
821
+
822
+ this._subtreeRequestCounter++;
823
+
824
+ const subtreeCoord = subtree.implicitCoordinates;
825
+
826
+ // Make sure the parent subtree exists in the cache
827
+ if (subtreeCoord.level > 0) {
828
+ const parentCoord = subtreeCoord.getParentSubtreeCoordinates();
829
+ const parentNode = this.find(rootId, parentCoord);
830
+
831
+ //>>includeStart('debug', pragmas.debug)
832
+ if (parentNode === undefined) {
833
+ throw new DeveloperError("parent node needs to exist");
834
+ }
835
+ //>>includeEnd('debug');
836
+ }
837
+
838
+ if (this._maximumSubtreeCount > 0) {
839
+ while (this._queue.length > this._maximumSubtreeCount) {
840
+ const lowestPriorityNode = this._queue.getMinimum();
841
+ if (lowestPriorityNode === cacheNode) {
842
+ // Don't remove itself
843
+ break;
844
+ }
845
+
846
+ this._queue.removeMinimum();
847
+ }
848
+ }
849
+ };
850
+
851
+ /**
852
+ * Finds a subtree in the cache.
853
+ * @param {number} rootId The root tile ID (0 or 1)
854
+ * @param {ImplicitTileCoordinates} subtreeCoord The coordinates of the subtree
855
+ * @returns {ImplicitSubtree|undefined} The subtree if found; otherwise undefined.
856
+ */
857
+ ImplicitSubtreeCache.prototype.find = function (rootId, subtreeCoord) {
858
+ const queue = this._queue;
859
+ const array = queue.internalArray;
860
+ const { level, x, y } = subtreeCoord;
861
+
862
+ for (let i = 0; i < queue.length; i++) {
863
+ const other = array[i];
864
+ const otherRootId = other.rootId;
865
+ const otherCoord = other.subtree.implicitCoordinates;
866
+ if (
867
+ otherRootId === rootId &&
868
+ otherCoord.level === level &&
869
+ otherCoord.x === x &&
870
+ otherCoord.y === y
871
+ ) {
872
+ return other.subtree;
873
+ }
874
+ }
875
+ return undefined;
876
+ };
877
+
878
+ /**
879
+ * Determines the {@link ImplicitTileCoordinates} of the most detailed tile covering the position.
880
+ *
881
+ * @param {Cartographic} position The position for which to determine the maximum coordinates. The height component is ignored.
882
+ * @returns {ImplicitTileCoordinates|undefined} The coordinates of the most detailed tile covering the position.
883
+ * @throws {DeveloperError} If position is outside any tile according to the tiling scheme.
884
+ */
885
+
886
+ ImplicitSubtreeCache.prototype._computeMaximumImplicitTileCoordinatesAtPosition =
887
+ function (position) {
888
+ const { longitude, latitude } = position;
889
+ const provider = this._provider;
890
+ const rootId = longitude < 0.0 ? 0 : 1;
891
+ const implicitTileset =
892
+ rootId === 0 ? provider._tileset0 : provider._tileset1;
893
+ const subtreeLevels = implicitTileset.subtreeLevels;
894
+ const rootSubtreeCoord = getImplicitTileCoordinates(
895
+ implicitTileset,
896
+ 0,
897
+ 0,
898
+ 0,
899
+ );
900
+
901
+ let subtree = this.find(rootId, rootSubtreeCoord);
902
+ if (subtree === undefined) {
903
+ // Nothing has been loaded yet
904
+ return undefined;
905
+ }
906
+
907
+ let subtreeCoord = subtree.implicitCoordinates;
908
+ let subtreeX = subtreeCoord.x;
909
+ let subtreeY = subtreeCoord.y;
910
+ let subtreeLevel = subtreeCoord.level;
911
+
912
+ const globalMinimumLongitude = -CesiumMath.PI;
913
+ const globalMaximumLongitude = +CesiumMath.PI;
914
+ const rootLongitudeStart = CesiumMath.lerp(
915
+ globalMinimumLongitude,
916
+ globalMaximumLongitude,
917
+ rootId / 2.0,
918
+ );
919
+ const rootLongitudeEnd = CesiumMath.lerp(
920
+ globalMinimumLongitude,
921
+ globalMaximumLongitude,
922
+ (rootId + 1) / 2,
923
+ );
924
+ const rootLatitudeStart = -CesiumMath.PI * 0.5;
925
+ const rootLatitudeEnd = +CesiumMath.PI * 0.5;
926
+
927
+ let u = 0.0;
928
+ let v = 0.0;
929
+
930
+ // Find the deepest available subtree
931
+ let childSubtreeLoaded = true;
932
+ while (childSubtreeLoaded) {
933
+ const invDim = 1.0 / (1 << subtreeLevel);
934
+
935
+ const lonLength = (rootLongitudeEnd - rootLongitudeStart) * invDim;
936
+ const lonMin = rootLongitudeStart + subtreeX * lonLength;
937
+
938
+ const latLength = (rootLatitudeEnd - rootLatitudeStart) * invDim;
939
+ const latMin = rootLatitudeStart + subtreeY * latLength;
940
+
941
+ u = (longitude - lonMin) / lonLength;
942
+ v = (latitude - latMin) / latLength;
943
+
944
+ const childSubtreeCoord = computeDescendantCoordinatesAtUv(
945
+ implicitTileset,
946
+ subtreeCoord,
947
+ u,
948
+ v,
949
+ subtreeLevels,
950
+ );
951
+
952
+ if (subtree.childSubtreeIsAvailableAtCoordinates(childSubtreeCoord)) {
953
+ const childSubtree = this.find(rootId, childSubtreeCoord);
954
+ if (childSubtree !== undefined) {
955
+ subtree = childSubtree;
956
+ subtreeCoord = subtree.implicitCoordinates;
957
+ subtreeX = subtreeCoord.x;
958
+ subtreeY = subtreeCoord.y;
959
+ subtreeLevel = subtreeCoord.level;
960
+ } else {
961
+ // Child subtree is available but has not been loaded yet
962
+ // Since the root node of a subtree is always available, return the level of the child subtree
963
+ // sampleTerrainMostDetailed will keep calling this function until all available subtrees in the chain have been loaded
964
+ return childSubtreeCoord;
965
+ }
966
+ } else {
967
+ // Child subtree is not available
968
+ childSubtreeLoaded = false;
969
+ }
970
+ }
971
+
972
+ // Find the deepest level in the subtree
973
+ let deepestTileCoord;
974
+ for (let localLevel = 0; localLevel < subtreeLevels; localLevel++) {
975
+ const childCoord = computeDescendantCoordinatesAtUv(
976
+ implicitTileset,
977
+ subtreeCoord,
978
+ u,
979
+ v,
980
+ localLevel,
981
+ );
982
+
983
+ if (subtree.tileIsAvailableAtCoordinates(childCoord)) {
984
+ deepestTileCoord = childCoord;
985
+ } else {
986
+ break;
987
+ }
988
+ }
989
+
990
+ return deepestTileCoord;
991
+ };
992
+
993
+ /**
994
+ * Computes the descendant tile coordinates at a given (u,v) location within a subtree.
995
+ * @private
996
+ * @param {ImplicitTileset} implicitTileset
997
+ * @param {ImplicitTileCoordinates} subtreeCoord
998
+ * @param {number} u
999
+ * @param {number} v
1000
+ * @param {number} levelOffset
1001
+ * @returns {ImplicitTileCoordinates} The parent subtree coordinate
1002
+ */
1003
+ function computeDescendantCoordinatesAtUv(
1004
+ implicitTileset,
1005
+ subtreeCoord,
1006
+ u,
1007
+ v,
1008
+ levelOffset,
1009
+ ) {
1010
+ //>>includeStart('debug', pragmas.debug);
1011
+ Check.typeOf.object("implicitTileset", implicitTileset);
1012
+ Check.typeOf.object("subtreeCoord", subtreeCoord);
1013
+ Check.typeOf.number("u", u);
1014
+ Check.typeOf.number("v", v);
1015
+ Check.typeOf.number("levelOffset", levelOffset);
1016
+ //>>includeEnd('debug');
1017
+
1018
+ const dimension = 1 << levelOffset;
1019
+ const localX = CesiumMath.clamp((u * dimension) | 0, 0, dimension - 1);
1020
+ const localY = CesiumMath.clamp((v * dimension) | 0, 0, dimension - 1);
1021
+ const offset = getImplicitTileCoordinates(
1022
+ implicitTileset,
1023
+ levelOffset,
1024
+ localX,
1025
+ localY,
1026
+ );
1027
+ return subtreeCoord.getDescendantCoordinates(offset);
1028
+ }
1029
+
1030
+ // NOTE: ImplicitSubtreeCache implements just enough of the TileAvailability interface to support `sampleTerrain` and `sampleTerrainMostDetailed`.
1031
+ // Right now this just means implementing `computeMaximumLevelAtPosition`.
1032
+ // It's more difficult to implement the rest of the methods because doing everything in terms of ranges instead of bits is kind of awkward.
1033
+
1034
+ /**
1035
+ * Determines the level of the most detailed tile covering the position.
1036
+ *
1037
+ * @param {Cartographic} position The position for which to determine the maximum available level. The height component is ignored.
1038
+ * @returns {number} The level of the most detailed tile covering the position.
1039
+ * @throws {DeveloperError} If position is outside any tile according to the tiling scheme.
1040
+ */
1041
+ ImplicitSubtreeCache.prototype.computeMaximumLevelAtPosition = function (
1042
+ position,
1043
+ ) {
1044
+ const tileCoordinates =
1045
+ this._computeMaximumImplicitTileCoordinatesAtPosition(position);
1046
+ if (tileCoordinates === undefined) {
1047
+ return 0;
1048
+ }
1049
+ return tileCoordinates.level;
1050
+ };
1051
+
1052
+ export default Cesium3DTilesTerrainProvider;