@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,607 @@
1
+ import AxisAlignedBoundingBox from "./AxisAlignedBoundingBox.js";
2
+ import Cartesian3 from "./Cartesian3.js";
3
+ import defined from "./defined.js";
4
+ import IntersectionTests from "./IntersectionTests.js";
5
+ import Matrix4 from "./Matrix4.js";
6
+ import Ray from "./Ray.js";
7
+ import TaskProcessor from "./TaskProcessor.js";
8
+ import Cartographic from "./Cartographic.js";
9
+ import SceneMode from "../Scene/SceneMode.js";
10
+ import Interval from "./Interval.js";
11
+ import Check from "./Check.js";
12
+ import DeveloperError from "./DeveloperError.js";
13
+
14
+ // Terrain picker can be 4 levels deep (0-3)
15
+ const MAXIMUM_TERRAIN_PICKER_LEVEL = 3;
16
+
17
+ /**
18
+ * Creates an object that handles arbitrary ray intersections with a terrain mesh using a spatial acceleration structure.
19
+ *
20
+ * @alias TerrainPicker
21
+ * @constructor
22
+ *
23
+ * @param {Float32Array} vertices The terrain mesh's vertex buffer.
24
+ * @param {Uint8Array|Uint16Array|Uint32Array} indices The terrain mesh's index buffer.
25
+ * @param {TerrainEncoding} encoding The terrain mesh's vertex encoding.
26
+ *
27
+ * @private
28
+ */
29
+ function TerrainPicker(vertices, indices, encoding) {
30
+ //>>includeStart('debug', pragmas.debug);
31
+ Check.defined("vertices", vertices);
32
+ Check.defined("indices", indices);
33
+ Check.defined("encoding", encoding);
34
+ //>>includeEnd('debug');
35
+
36
+ /**
37
+ * The terrain mesh's vertex buffer.
38
+ * @type {Float32Array}
39
+ */
40
+ this._vertices = vertices;
41
+ /**
42
+ * The terrain mesh's index buffer.
43
+ * @type {Uint32Array}
44
+ */
45
+ this._indices = indices;
46
+ /**
47
+ * The terrain mesh's vertex encoding.
48
+ * @type {TerrainEncoding}
49
+ */
50
+ this._encoding = encoding;
51
+ /**
52
+ * The inverse of the terrain mesh tile's transform from world space to local space.
53
+ * @type {Matrix4}
54
+ */
55
+ this._inverseTransform = new Matrix4(); // Compute as-needed on rebuild
56
+ /**
57
+ * Whether or not to reset this terrain mesh's picker on the next ray intersection.
58
+ * @type {Boolean}
59
+ */
60
+ this._needsRebuild = true;
61
+ /**
62
+ * The root node of the terrain picker's quadtree.
63
+ * @type {TerrainPickerNode}
64
+ */
65
+ this._rootNode = new TerrainPickerNode();
66
+ }
67
+
68
+ const incrementallyBuildTerrainPickerTaskProcessor = new TaskProcessor(
69
+ "incrementallyBuildTerrainPicker",
70
+ );
71
+
72
+ Object.defineProperties(TerrainPicker.prototype, {
73
+ /**
74
+ * Indicates whether the terrain picker needs to be rebuilt due to changes in the underlying terrain mesh's vertices or indices.
75
+ * @type {boolean}
76
+ */
77
+ needsRebuild: {
78
+ get: function () {
79
+ return this._needsRebuild;
80
+ },
81
+ set: function (value) {
82
+ this._needsRebuild = value;
83
+ },
84
+ },
85
+ });
86
+
87
+ /**
88
+ * A node in the terrain picker quadtree.
89
+ * @constructor
90
+ * @private
91
+ */
92
+ function TerrainPickerNode() {
93
+ /**
94
+ * The tree-space x-coordinate of this node.
95
+ * @type {Number}
96
+ */
97
+ this.x = 0;
98
+ /**
99
+ * The tree-space y-coordinate of this node.
100
+ * @type {Number}
101
+ */
102
+ this.y = 0;
103
+ /**
104
+ * The level of this node in the quadtree.
105
+ * @type {Number}
106
+ */
107
+ this.level = 0;
108
+ /**
109
+ * The axis-aligned bounding box of this node (in the tree's local space).
110
+ * @type {AxisAlignedBoundingBox}
111
+ */
112
+ this.aabb = createAABBForNode(this.x, this.y, this.level);
113
+ /**
114
+ * The indices of the triangles that intersect this node.
115
+ * @type {Uint32Array}
116
+ */
117
+ this.intersectingTriangles = new Uint32Array(0);
118
+ /**
119
+ * The child terrain picker nodes of this node.
120
+ * @type {TerrainPickerNode[]}
121
+ */
122
+ this.children = [];
123
+ /**
124
+ * Whether or not this node is currently building its children on a worker.
125
+ * @type {Boolean}
126
+ */
127
+ this.buildingChildren = false;
128
+ }
129
+
130
+ /**
131
+ * Adds a child node to this node.
132
+ *
133
+ * @param {number} childIdx The index of the child to add (0-3).
134
+ * @memberof TerrainPickerNode
135
+ */
136
+ TerrainPickerNode.prototype.addChild = function (childIdx) {
137
+ //>>includeStart('debug', pragmas.debug);
138
+ if (childIdx < 0 || childIdx > 3) {
139
+ throw new DeveloperError(
140
+ "TerrainPickerNode child index must be between 0 and 3, inclusive.",
141
+ );
142
+ }
143
+ //>>includeEnd('debug');
144
+
145
+ const childNode = new TerrainPickerNode();
146
+ // Use bitwise operations to get child x,y from child index and parent x,y
147
+ childNode.x = this.x * 2 + (childIdx & 1);
148
+ childNode.y = this.y * 2 + ((childIdx >> 1) & 1);
149
+ childNode.level = this.level + 1;
150
+ childNode.aabb = createAABBForNode(childNode.x, childNode.y, childNode.level);
151
+
152
+ this.children[childIdx] = childNode;
153
+ };
154
+
155
+ const scratchTransformedRay = new Ray();
156
+ const scratchTrianglePoints = [
157
+ new Cartesian3(),
158
+ new Cartesian3(),
159
+ new Cartesian3(),
160
+ ];
161
+
162
+ /**
163
+ * Determines the point on the mesh where the given ray intersects.
164
+ * @param {Ray} ray The ray to test.
165
+ * @param {Matrix4} tileTransform The terrain mesh tile's transform from local space to world space.
166
+ * @param {Boolean} cullBackFaces Whether to consider back-facing triangles as intersections.
167
+ * @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
168
+ * @param {MapProjection} projection The map projection.
169
+ * @returns {Cartesian3 | undefined} result The intersection point, or undefined if there is no intersection.
170
+ * @memberof TerrainPicker
171
+ * @private
172
+ */
173
+ TerrainPicker.prototype.rayIntersect = function (
174
+ ray,
175
+ tileTransform,
176
+ cullBackFaces,
177
+ mode,
178
+ projection,
179
+ ) {
180
+ // Lazily (re)create the terrain picker
181
+ if (this._needsRebuild) {
182
+ reset(this, tileTransform);
183
+ }
184
+
185
+ const invTransform = this._inverseTransform;
186
+
187
+ const transformedRay = scratchTransformedRay;
188
+
189
+ transformedRay.origin = Matrix4.multiplyByPoint(
190
+ invTransform,
191
+ ray.origin,
192
+ transformedRay.origin,
193
+ );
194
+ transformedRay.direction = Matrix4.multiplyByPointAsVector(
195
+ invTransform,
196
+ ray.direction,
197
+ transformedRay.direction,
198
+ );
199
+
200
+ const intersections = [];
201
+ getNodesIntersectingRay(this._rootNode, transformedRay, intersections);
202
+
203
+ return findClosestPointInClosestNode(
204
+ this,
205
+ intersections,
206
+ ray,
207
+ cullBackFaces,
208
+ mode,
209
+ projection,
210
+ );
211
+ };
212
+
213
+ /**
214
+ * Resets the terrain picker's quadtree structure to just the root node. Done whenever the underlying terrain mesh changes.
215
+ * @param terrainPicker The terrain picker to reset.
216
+ * @private
217
+ */
218
+ function reset(terrainPicker, tileTransform) {
219
+ // PERFORMANCE_IDEA: warm-start the terrain picker by building a level on a worker.
220
+ // This currently isn't feasible because you can only copy the vertex buffer to a worker (slow) or transfer ownership (can't do picking on main thread in meantime).
221
+ // SharedArrayBuffers could be used, but most environments do not support them.
222
+ Matrix4.inverse(tileTransform, terrainPicker._inverseTransform);
223
+
224
+ terrainPicker._needsRebuild = false;
225
+ const triangleCount = terrainPicker._indices.length / 3;
226
+ const intersectingTriangles = new Uint32Array(triangleCount);
227
+
228
+ for (let i = 0; i < triangleCount; ++i) {
229
+ intersectingTriangles[i] = i;
230
+ }
231
+
232
+ terrainPicker._rootNode.intersectingTriangles = intersectingTriangles;
233
+ terrainPicker._rootNode.children.length = 0;
234
+ }
235
+
236
+ const scratchAABBMin = new Cartesian3();
237
+ const scratchAABBMax = new Cartesian3();
238
+
239
+ /**
240
+ * Creates an axis-aligned bounding box for a quadtree node at the given tree-space coordinates and level.
241
+ * This AABB is in the tree's local space (where the root node of the tree is a unit cube in its own local space).
242
+ *
243
+ * @param {number} x The x coordinate of the node.
244
+ * @param {number} y The y coordinate of the node.
245
+ * @param {number} level The level of the node.
246
+ * @returns {AxisAlignedBoundingBox} The axis-aligned bounding box for the node.
247
+ */
248
+ function createAABBForNode(x, y, level) {
249
+ const sizeAtLevel = 1.0 / Math.pow(2, level);
250
+
251
+ const aabbMin = Cartesian3.fromElements(
252
+ x * sizeAtLevel - 0.5,
253
+ y * sizeAtLevel - 0.5,
254
+ -0.5,
255
+ scratchAABBMin,
256
+ );
257
+
258
+ const aabbMax = Cartesian3.fromElements(
259
+ (x + 1) * sizeAtLevel - 0.5,
260
+ (y + 1) * sizeAtLevel - 0.5,
261
+ 0.5,
262
+ scratchAABBMax,
263
+ );
264
+
265
+ return AxisAlignedBoundingBox.fromCorners(aabbMin, aabbMax);
266
+ }
267
+
268
+ /**
269
+ * Packs triangle vertex positions and index into provided buffers, for the worker to process.
270
+ * (The worker does tests to organize triangles into child nodes of the quadtree.)
271
+ * @param {Float32Array} trianglePositionsBuffer The buffer to pack triangle vertex positions into.
272
+ * @param {Uint32Array} triangleIndicesBuffer The buffer to pack triangle indices into.
273
+ * @param {Cartesian3[]} trianglePositions The triangle's vertex positions.
274
+ * @param {number} triangleIndex The triangle's index in the overall tile's index buffer.
275
+ * @param {number} bufferIndex The index to use to pack into the buffers.
276
+ * @private
277
+ */
278
+ function packTriangleBuffers(
279
+ trianglePositionsBuffer,
280
+ triangleIndicesBuffer,
281
+ trianglePositions,
282
+ triangleIndex,
283
+ bufferIndex,
284
+ ) {
285
+ Cartesian3.pack(
286
+ trianglePositions[0],
287
+ trianglePositionsBuffer,
288
+ 9 * bufferIndex,
289
+ );
290
+ Cartesian3.pack(
291
+ trianglePositions[1],
292
+ trianglePositionsBuffer,
293
+ 9 * bufferIndex + 3,
294
+ );
295
+ Cartesian3.pack(
296
+ trianglePositions[2],
297
+ trianglePositionsBuffer,
298
+ 9 * bufferIndex + 6,
299
+ );
300
+ triangleIndicesBuffer[bufferIndex] = triangleIndex;
301
+ }
302
+
303
+ /**
304
+ * @typedef {Object} IntersectingNode
305
+ * @property {TerrainPickerNode} node - The intersecting quadtree node.
306
+ * @property {Interval} interval - The interval along the ray where the intersection occurs.
307
+ * @private
308
+ */
309
+
310
+ const scratchInterval = new Interval();
311
+
312
+ /**
313
+ * Recursively gathers all nodes in the quadtree that intersect the ray.
314
+ *
315
+ * @param {TerrainPickerNode} currentNode The current node being tested.
316
+ * @param {Ray} ray The ray to test.
317
+ * @param {IntersectingNode[]} intersectingNodes The array to store intersecting nodes in.
318
+ * @private
319
+ */
320
+ function getNodesIntersectingRay(currentNode, ray, intersectingNodes) {
321
+ const interval = IntersectionTests.rayAxisAlignedBoundingBox(
322
+ ray,
323
+ currentNode.aabb,
324
+ scratchInterval,
325
+ );
326
+
327
+ if (!defined(interval)) {
328
+ return;
329
+ }
330
+
331
+ const isLeaf = !currentNode.children.length || currentNode.buildingChildren;
332
+ if (isLeaf) {
333
+ intersectingNodes.push({
334
+ node: currentNode,
335
+ interval: new Interval(interval.start, interval.stop),
336
+ });
337
+ return;
338
+ }
339
+
340
+ for (let i = 0; i < currentNode.children.length; i++) {
341
+ getNodesIntersectingRay(currentNode.children[i], ray, intersectingNodes);
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Finds the closest intersecting node along the ray, in world space, and the closest point in that node,
347
+ * by testing all triangles in the closest node against the ray.
348
+ *
349
+ * @param {TerrainPicker} terrainPicker The terrain picker.
350
+ * @param {IntersectingNode[]} intersections The nodes that intersect the ray, along with the intersection intervals along said ray.
351
+ * @param {Ray} ray The ray to test.
352
+ * @param {boolean} cullBackFaces Whether to cull back faces.
353
+ * @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
354
+ * @param {MapProjection} projection The map projection.
355
+ * @returns The closest point in world space, or undefined if no intersection.
356
+ * @private
357
+ */
358
+ function findClosestPointInClosestNode(
359
+ terrainPicker,
360
+ intersections,
361
+ ray,
362
+ cullBackFaces,
363
+ mode,
364
+ projection,
365
+ ) {
366
+ const sortedIntersections = intersections.sort(function (a, b) {
367
+ return a.interval.start - b.interval.start;
368
+ });
369
+
370
+ let minT = Number.MAX_VALUE;
371
+ for (let i = 0; i < sortedIntersections.length; i++) {
372
+ const intersection = sortedIntersections[i];
373
+ const intersectionResult = getClosestTriangleInNode(
374
+ terrainPicker,
375
+ ray,
376
+ intersection.node,
377
+ cullBackFaces,
378
+ mode,
379
+ projection,
380
+ );
381
+ minT = Math.min(intersectionResult, minT);
382
+ if (minT !== Number.MAX_VALUE) {
383
+ break;
384
+ }
385
+ }
386
+
387
+ if (minT !== Number.MAX_VALUE) {
388
+ return Ray.getPoint(ray, minT);
389
+ }
390
+
391
+ return undefined;
392
+ }
393
+
394
+ /**
395
+ * Test all triangles in the given node against the ray, returning the closest intersection t value along the ray.
396
+ * Additionally, collect the triangles' positions and indices along the way to launch worker process that uses them to build out child nodes.
397
+ *
398
+ * @param {TerrainPicker} terrainPicker The terrain picker.
399
+ * @param {Ray} ray The ray to test.
400
+ * @param {TerrainPickerNode} node The node to test.
401
+ * @param {boolean} cullBackFaces Whether to cull back faces.
402
+ * @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
403
+ * @param {MapProjection} projection The map projection.
404
+ * @returns {number} The closest intersection t value along the ray, or Number.MAX_VALUE if no intersection.
405
+ * @private
406
+ */
407
+ function getClosestTriangleInNode(
408
+ terrainPicker,
409
+ ray,
410
+ node,
411
+ cullBackFaces,
412
+ mode,
413
+ projection,
414
+ ) {
415
+ let result = Number.MAX_VALUE;
416
+ const encoding = terrainPicker._encoding;
417
+ const indices = terrainPicker._indices;
418
+ const vertices = terrainPicker._vertices;
419
+ const triangleCount = node.intersectingTriangles.length;
420
+ const isMaxLevel = node.level >= MAXIMUM_TERRAIN_PICKER_LEVEL;
421
+ const shouldBuildChildren = !isMaxLevel && !node.buildingChildren;
422
+
423
+ let trianglePositions;
424
+ let triangleIndices;
425
+ if (shouldBuildChildren) {
426
+ // If the tree can be built deeper, prepare buffers to store triangle data for child nodes
427
+ trianglePositions = new Float32Array(triangleCount * 9); // 3 vertices per triangle * 3 floats per vertex
428
+ triangleIndices = new Uint32Array(triangleCount);
429
+ }
430
+
431
+ for (let i = 0; i < triangleCount; i++) {
432
+ const triIndex = node.intersectingTriangles[i];
433
+ const v0 = getVertexPosition(
434
+ encoding,
435
+ mode,
436
+ projection,
437
+ vertices,
438
+ indices[3 * triIndex],
439
+ scratchTrianglePoints[0],
440
+ );
441
+ const v1 = getVertexPosition(
442
+ encoding,
443
+ mode,
444
+ projection,
445
+ vertices,
446
+ indices[3 * triIndex + 1],
447
+ scratchTrianglePoints[1],
448
+ );
449
+ const v2 = getVertexPosition(
450
+ encoding,
451
+ mode,
452
+ projection,
453
+ vertices,
454
+ indices[3 * triIndex + 2],
455
+ scratchTrianglePoints[2],
456
+ );
457
+
458
+ const triT = IntersectionTests.rayTriangleParametric(
459
+ ray,
460
+ v0,
461
+ v1,
462
+ v2,
463
+ cullBackFaces,
464
+ );
465
+
466
+ if (defined(triT) && triT < result && triT >= 0) {
467
+ result = triT;
468
+ }
469
+
470
+ if (shouldBuildChildren) {
471
+ packTriangleBuffers(
472
+ trianglePositions,
473
+ triangleIndices,
474
+ scratchTrianglePoints,
475
+ triIndex,
476
+ i,
477
+ );
478
+ }
479
+ }
480
+
481
+ if (shouldBuildChildren) {
482
+ for (let childIdx = 0; childIdx < 4; childIdx++) {
483
+ node.addChild(childIdx);
484
+ }
485
+
486
+ addTrianglesToChildrenNodes(
487
+ terrainPicker._inverseTransform,
488
+ node,
489
+ triangleIndices,
490
+ trianglePositions,
491
+ );
492
+ }
493
+
494
+ return result;
495
+ }
496
+
497
+ const scratchCartographic = new Cartographic();
498
+
499
+ /**
500
+ * Gets a vertex position from the buffer, taking into account the exaggeration and scene mode of the terrain.
501
+ *
502
+ * @param {TerrainEncoding} encoding The terrain encoding.
503
+ * @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
504
+ * @param {MapProjection} projection The map projection.
505
+ * @param {Float32Array} vertices The vertex buffer of the terrain mesh.
506
+ * @param {Number} index The index of the vertex to get.
507
+ * @param {Cartesian3} result The decoded, exaggerated, and possibly projected vertex position.
508
+ * @returns {Cartesian3} The result vertex position.
509
+ * @private
510
+ */
511
+ function getVertexPosition(
512
+ encoding,
513
+ mode,
514
+ projection,
515
+ vertices,
516
+ index,
517
+ result,
518
+ ) {
519
+ let position = encoding.getExaggeratedPosition(vertices, index, result);
520
+ if (mode === SceneMode.SCENE3D) {
521
+ return position;
522
+ }
523
+
524
+ const ellipsoid = projection.ellipsoid;
525
+ const positionCartographic = ellipsoid.cartesianToCartographic(
526
+ position,
527
+ scratchCartographic,
528
+ );
529
+ position = projection.project(positionCartographic, result);
530
+ // Swizzle because coordinate basis are different in 2D/Columbus View
531
+ position = Cartesian3.fromElements(
532
+ position.z,
533
+ position.x,
534
+ position.y,
535
+ result,
536
+ );
537
+
538
+ return position;
539
+ }
540
+
541
+ /**
542
+ * Adds triangles to the child nodes of the given node by launching a worker process to do AABB-triangle testing.
543
+ *
544
+ * @param {Matrix4} inverseTransform
545
+ * @param {TerrainNode} node
546
+ * @param {Uint32Array} triangleIndices
547
+ * @param {Float32Array} trianglePositions
548
+ * @returns {Promise<void>} A promise that resolves when the triangles have been added to the child nodes.
549
+ * @private
550
+ */
551
+ async function addTrianglesToChildrenNodes(
552
+ inverseTransform,
553
+ node,
554
+ triangleIndices,
555
+ trianglePositions,
556
+ ) {
557
+ node.buildingChildren = true;
558
+
559
+ // Prepare data to be sent to a worker
560
+ const inverseTransformPacked = new Float64Array(16);
561
+ Matrix4.pack(inverseTransform, inverseTransformPacked, 0);
562
+
563
+ const aabbArray = new Float64Array(6 * 4); // 6 elements per AABB, 4 children
564
+ for (let i = 0; i < 4; i++) {
565
+ Cartesian3.pack(node.children[i].aabb.minimum, aabbArray, i * 6);
566
+ Cartesian3.pack(node.children[i].aabb.maximum, aabbArray, i * 6 + 3);
567
+ }
568
+
569
+ const parameters = {
570
+ aabbs: aabbArray,
571
+ inverseTransform: inverseTransformPacked,
572
+ triangleIndices: triangleIndices,
573
+ trianglePositions: trianglePositions,
574
+ };
575
+
576
+ const transferableObjects = [
577
+ aabbArray.buffer,
578
+ inverseTransformPacked.buffer,
579
+ triangleIndices.buffer,
580
+ trianglePositions.buffer,
581
+ ];
582
+
583
+ const incrementallyBuildTerrainPickerPromise =
584
+ incrementallyBuildTerrainPickerTaskProcessor.scheduleTask(
585
+ parameters,
586
+ transferableObjects,
587
+ );
588
+
589
+ if (!defined(incrementallyBuildTerrainPickerPromise)) {
590
+ // Failed to schedule task, retry on next pick
591
+ node.buildingChildren = false;
592
+ return;
593
+ }
594
+
595
+ // After worker completes, it transfers back a buffer of intersecting triangles for each child node
596
+ // Assign these to the child nodes
597
+ const result = await incrementallyBuildTerrainPickerPromise;
598
+ result.intersectingTrianglesArrays.forEach((buffer, index) => {
599
+ node.children[index].intersectingTriangles = new Uint32Array(buffer);
600
+ });
601
+
602
+ // The node's triangles have been distributed to its children
603
+ node.intersectingTriangles = new Uint32Array(0);
604
+ node.buildingChildren = false;
605
+ }
606
+
607
+ export default TerrainPicker;