@cesium/engine 23.0.0 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/Build/Workers/{chunk-QTOHIXGF.js → chunk-2N4KDHS3.js} +10 -10
  2. package/Build/Workers/{chunk-SQTRWKO2.js → chunk-44EMEGKW.js} +5 -5
  3. package/Build/Workers/{chunk-OHBM4YG4.js → chunk-4TIG36AW.js} +12 -12
  4. package/Build/Workers/{chunk-BNBD2YZK.js → chunk-5A2SW66E.js} +16 -16
  5. package/Build/Workers/{chunk-52K3GJKG.js → chunk-5GXYJQ2K.js} +3 -3
  6. package/Build/Workers/{chunk-NQCAZU7S.js → chunk-63SIWPLS.js} +13 -13
  7. package/Build/Workers/{chunk-UEEGWJJP.js → chunk-6MPGQEHA.js} +2 -2
  8. package/Build/Workers/{chunk-PQVNT5CJ.js → chunk-6RMS4S72.js} +6 -6
  9. package/Build/Workers/{chunk-HYTFXWMY.js → chunk-6WLHJFD3.js} +7 -7
  10. package/Build/Workers/{chunk-DT5SJBKA.js → chunk-72VYSVEW.js} +9 -9
  11. package/Build/Workers/{chunk-JUGY5AZN.js → chunk-7MDYBRYJ.js} +4 -4
  12. package/Build/Workers/{chunk-6SLGTBB2.js → chunk-7O5XJTVE.js} +5 -5
  13. package/Build/Workers/{chunk-4UNQX2MP.js → chunk-7QRFIKWQ.js} +2 -2
  14. package/Build/Workers/{chunk-GN5NEUDT.js → chunk-7TYLCBGK.js} +8 -8
  15. package/Build/Workers/{chunk-SGKTBHFQ.js → chunk-7X322WP2.js} +13 -13
  16. package/Build/Workers/{chunk-T43FXHNC.js → chunk-A47HVBC5.js} +7 -7
  17. package/Build/Workers/{chunk-FSDVXW7M.js → chunk-AF3MU2RL.js} +5 -5
  18. package/Build/Workers/{chunk-3B65YFXC.js → chunk-AJLTU6PF.js} +1 -1
  19. package/Build/Workers/{chunk-OQ3EAJNW.js → chunk-AMIHNSST.js} +2 -2
  20. package/Build/Workers/{chunk-N4AWE7TZ.js → chunk-B6SCUUFP.js} +10 -10
  21. package/Build/Workers/{chunk-OMXN7YF4.js → chunk-BJD6QGXZ.js} +12 -12
  22. package/Build/Workers/{chunk-APDKMX7W.js → chunk-C6P4IG5P.js} +6 -6
  23. package/Build/Workers/{chunk-QA24Q62E.js → chunk-D4EJ2NXG.js} +17 -17
  24. package/Build/Workers/{chunk-HYLEKKO5.js → chunk-DHKPFLSJ.js} +1 -1
  25. package/Build/Workers/{chunk-MQJG522T.js → chunk-DVB56LG7.js} +6 -6
  26. package/Build/Workers/{chunk-Y5AJSEEN.js → chunk-EDXL4W76.js} +2 -2
  27. package/Build/Workers/{chunk-QQX7S5QT.js → chunk-EV3VGO6Y.js} +17 -17
  28. package/Build/Workers/{chunk-IFA7VHHP.js → chunk-GOQBUCXH.js} +10 -10
  29. package/Build/Workers/{chunk-5A7YSAXT.js → chunk-GQUNK2XC.js} +14 -14
  30. package/Build/Workers/{chunk-36LBFITA.js → chunk-HKUES6UG.js} +12 -12
  31. package/Build/Workers/{chunk-OC6X22PG.js → chunk-HRHRYFHS.js} +9 -9
  32. package/Build/Workers/{chunk-L7RDJ4V7.js → chunk-HXJMS2ZI.js} +1 -1
  33. package/Build/Workers/{chunk-NAYRNPEP.js → chunk-ILMFADZA.js} +4 -4
  34. package/Build/Workers/{chunk-AA33B6PU.js → chunk-ISY4EZCA.js} +4 -4
  35. package/Build/Workers/{chunk-7KRN6JPQ.js → chunk-J6AW5YHS.js} +14 -14
  36. package/Build/Workers/{chunk-OQBPOKPZ.js → chunk-JCI63T3K.js} +6 -6
  37. package/Build/Workers/{chunk-2WI4HGJU.js → chunk-KLPGTXS3.js} +6 -6
  38. package/Build/Workers/{chunk-5R7SBUTW.js → chunk-LIB2H534.js} +10 -10
  39. package/Build/Workers/{chunk-IYVDOB5V.js → chunk-LXMCPFFS.js} +4 -4
  40. package/Build/Workers/{chunk-NUYLNQKV.js → chunk-MKM27KGV.js} +2 -2
  41. package/Build/Workers/{chunk-R7M4XNPP.js → chunk-N65BAKSH.js} +8 -8
  42. package/Build/Workers/{chunk-4LGFX2P5.js → chunk-NKT5K3K3.js} +11 -11
  43. package/Build/Workers/{chunk-NNHU33JK.js → chunk-NPF7SSHZ.js} +7 -7
  44. package/Build/Workers/{chunk-LDQWNMEC.js → chunk-PVV64VFW.js} +1 -1
  45. package/Build/Workers/{chunk-WKXDCVBO.js → chunk-Q3C6VQH6.js} +4 -4
  46. package/Build/Workers/{chunk-ARCFIOKA.js → chunk-RQNJD3O4.js} +12 -12
  47. package/Build/Workers/{chunk-G3YT7M7A.js → chunk-UIGVOKKI.js} +1 -1
  48. package/Build/Workers/{chunk-ZIW5FCIW.js → chunk-UQU4RXLT.js} +27 -19
  49. package/Build/Workers/{chunk-MT5M7RLZ.js → chunk-VLDEUTOP.js} +2 -2
  50. package/Build/Workers/{chunk-5JP5FG7U.js → chunk-VMVOUQ5J.js} +7 -7
  51. package/Build/Workers/{chunk-2GL2EUEE.js → chunk-XJRBB253.js} +11 -11
  52. package/Build/Workers/{chunk-ESD4IEOU.js → chunk-XY6HMDGI.js} +5 -5
  53. package/Build/Workers/{chunk-56OHFSLH.js → chunk-Y7HNNPNK.js} +10 -10
  54. package/Build/Workers/{chunk-6FVFM2KB.js → chunk-YAOZMOFL.js} +5 -5
  55. package/Build/Workers/{chunk-AP6XWET5.js → chunk-YJZGW74L.js} +8 -8
  56. package/Build/Workers/{chunk-KPYU6YZG.js → chunk-YQFTYQMZ.js} +1 -1
  57. package/Build/Workers/{chunk-5VKZVPO5.js → chunk-ZBZRTRJB.js} +10 -10
  58. package/Build/Workers/combineGeometry.js +24 -24
  59. package/Build/Workers/createBoxGeometry.js +18 -18
  60. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  61. package/Build/Workers/createCircleGeometry.js +26 -26
  62. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  63. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  64. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  65. package/Build/Workers/createCorridorGeometry.js +29 -29
  66. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  67. package/Build/Workers/createCylinderGeometry.js +20 -20
  68. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  69. package/Build/Workers/createEllipseGeometry.js +26 -26
  70. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  71. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  73. package/Build/Workers/createFrustumGeometry.js +18 -18
  74. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  75. package/Build/Workers/createGeometry.js +24 -24
  76. package/Build/Workers/createGroundPolylineGeometry.js +22 -22
  77. package/Build/Workers/createPlaneGeometry.js +16 -16
  78. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  79. package/Build/Workers/createPolygonGeometry.js +32 -32
  80. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  81. package/Build/Workers/createPolylineGeometry.js +25 -25
  82. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  83. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  84. package/Build/Workers/createRectangleGeometry.js +27 -27
  85. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  86. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  87. package/Build/Workers/createSphereGeometry.js +19 -19
  88. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  89. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  90. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  91. package/Build/Workers/createVectorTileGeometries.js +24 -24
  92. package/Build/Workers/createVectorTilePoints.js +13 -13
  93. package/Build/Workers/createVectorTilePolygons.js +22 -22
  94. package/Build/Workers/createVectorTilePolylines.js +14 -14
  95. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  96. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  97. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  98. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  99. package/Build/Workers/createWallGeometry.js +25 -25
  100. package/Build/Workers/createWallOutlineGeometry.js +24 -24
  101. package/Build/Workers/decodeDraco.js +10 -10
  102. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  103. package/Build/Workers/decodeI3S.js +12 -12
  104. package/Build/Workers/gaussianSplatSorter.js +4 -4
  105. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  106. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  107. package/Build/Workers/transcodeKTX2.js +6 -6
  108. package/Build/Workers/transferTypedArrayTest.js +1 -1
  109. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  110. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  111. package/Source/Core/BoundingSphere.js +1 -1
  112. package/Source/Core/Cartesian2.js +7 -5
  113. package/Source/Core/Cartesian3.js +8 -6
  114. package/Source/Core/Cartesian4.js +8 -6
  115. package/Source/Core/Color.js +5 -3
  116. package/Source/Core/DeveloperError.js +2 -1
  117. package/Source/Core/ITwinPlatform.js +1 -0
  118. package/Source/Core/Ion.js +1 -1
  119. package/Source/Core/S2Cell.js +2 -2
  120. package/Source/Core/TerrainMesh.js +10 -1
  121. package/Source/Core/TerrainPicker.js +1 -0
  122. package/Source/Core/WallGeometry.js +1 -1
  123. package/Source/Core/WallOutlineGeometry.js +1 -1
  124. package/Source/Core/assert.js +27 -0
  125. package/Source/Core/globalTypes.js +4 -0
  126. package/Source/DataSources/CzmlDataSource.js +9 -0
  127. package/Source/DataSources/PathGraphics.js +13 -0
  128. package/Source/DataSources/PathVisualizer.js +330 -18
  129. package/Source/DataSources/StaticGeometryColorBatch.js +7 -2
  130. package/Source/DataSources/StaticGeometryPerMaterialBatch.js +7 -2
  131. package/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js +3 -1
  132. package/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js +3 -1
  133. package/Source/Renderer/Context.js +1 -1
  134. package/Source/Renderer/RenderState.js +2 -2
  135. package/Source/Renderer/VertexArray.js +80 -0
  136. package/Source/Scene/ArcGisMapService.js +1 -1
  137. package/Source/Scene/BillboardCollection.js +65 -364
  138. package/Source/Scene/BufferPoint.js +148 -0
  139. package/Source/Scene/BufferPointCollection.js +135 -0
  140. package/Source/Scene/BufferPointMaterial.js +95 -0
  141. package/Source/Scene/BufferPolygon.js +516 -0
  142. package/Source/Scene/BufferPolygonCollection.js +368 -0
  143. package/Source/Scene/BufferPolygonMaterial.js +41 -0
  144. package/Source/Scene/BufferPolyline.js +185 -0
  145. package/Source/Scene/BufferPolylineCollection.js +136 -0
  146. package/Source/Scene/BufferPolylineMaterial.js +93 -0
  147. package/Source/Scene/BufferPrimitive.js +347 -0
  148. package/Source/Scene/BufferPrimitiveCollection.js +702 -0
  149. package/Source/Scene/BufferPrimitiveMaterial.js +140 -0
  150. package/Source/Scene/Cesium3DTileContent.js +5 -1
  151. package/Source/Scene/Cesium3DTileContentFactory.js +9 -0
  152. package/Source/Scene/Cesium3DTileStyle.js +22 -0
  153. package/Source/Scene/Cesium3DTileset.js +1 -0
  154. package/Source/Scene/ClippingPolygonCollection.js +270 -101
  155. package/Source/Scene/CubeMapPanorama.js +4 -4
  156. package/Source/Scene/GaussianSplat3DTileContent.js +40 -46
  157. package/Source/Scene/GaussianSplatPrimitive.js +413 -70
  158. package/Source/Scene/GetFeatureInfoFormat.js +3 -3
  159. package/Source/Scene/GltfLoader.js +227 -34
  160. package/Source/Scene/GltfSpzLoader.js +109 -0
  161. package/Source/Scene/ITwinData.js +1 -0
  162. package/Source/Scene/Label.js +32 -0
  163. package/Source/Scene/LabelCollection.js +14 -13
  164. package/Source/Scene/Material.js +2 -0
  165. package/Source/Scene/Megatexture.js +1 -0
  166. package/Source/Scene/MetadataClassProperty.js +24 -10
  167. package/Source/Scene/MetadataComponentType.js +115 -23
  168. package/Source/Scene/Model/CustomShaderPipelineStage.js +3 -1
  169. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +761 -263
  170. package/Source/Scene/Model/MaterialPipelineStage.js +147 -0
  171. package/Source/Scene/Model/MetadataPipelineStage.js +3 -3
  172. package/Source/Scene/Model/ModelDrawCommand.js +6 -0
  173. package/Source/Scene/Model/ModelReader.js +1 -1
  174. package/Source/Scene/Model/ModelUtility.js +3 -1
  175. package/Source/Scene/Model/createVectorTileBuffersFromModelComponents.js +330 -0
  176. package/Source/Scene/ModelComponents.js +1632 -1542
  177. package/Source/Scene/PickedMetadataInfo.js +1 -0
  178. package/Source/Scene/ScreenSpaceCameraController.js +13 -0
  179. package/Source/Scene/SkyBox.js +17 -8
  180. package/Source/Scene/TileBoundingRegion.js +1 -1
  181. package/Source/Scene/TileBoundingS2Cell.js +1 -1
  182. package/Source/Scene/TileBoundingSphere.js +1 -1
  183. package/Source/Scene/TweenCollection.js +7 -0
  184. package/Source/Scene/VectorGltf3DTileContent.js +382 -0
  185. package/Source/Scene/VertexAttributeSemantic.js +14 -0
  186. package/Source/Scene/WebMapServiceImageryProvider.js +2 -2
  187. package/Source/Scene/WebMapTileServiceImageryProvider.js +366 -131
  188. package/Source/Scene/parseStructuralMetadata.js +97 -37
  189. package/Source/Scene/renderBufferPointCollection.js +334 -0
  190. package/Source/Scene/renderBufferPolygonCollection.js +386 -0
  191. package/Source/Scene/renderBufferPolylineCollection.js +529 -0
  192. package/Source/Shaders/BillboardCollectionFS.glsl +2 -77
  193. package/Source/Shaders/BillboardCollectionFS.js +2 -77
  194. package/Source/Shaders/BillboardCollectionVS.glsl +2 -60
  195. package/Source/Shaders/BillboardCollectionVS.js +2 -60
  196. package/Source/Shaders/BufferPointMaterialFS.glsl +27 -0
  197. package/Source/Shaders/BufferPointMaterialFS.js +29 -0
  198. package/Source/Shaders/BufferPointMaterialVS.glsl +48 -0
  199. package/Source/Shaders/BufferPointMaterialVS.js +50 -0
  200. package/Source/Shaders/BufferPolygonMaterialFS.glsl +13 -0
  201. package/Source/Shaders/BufferPolygonMaterialFS.js +15 -0
  202. package/Source/Shaders/BufferPolygonMaterialVS.glsl +30 -0
  203. package/Source/Shaders/BufferPolygonMaterialVS.js +32 -0
  204. package/Source/Shaders/BufferPolylineMaterialFS.glsl +13 -0
  205. package/Source/Shaders/BufferPolylineMaterialFS.js +15 -0
  206. package/Source/Shaders/BufferPolylineMaterialVS.glsl +49 -0
  207. package/Source/Shaders/BufferPolylineMaterialVS.js +51 -0
  208. package/Source/Shaders/Model/EdgeVisibilityStageFS.glsl +34 -48
  209. package/Source/Shaders/Model/EdgeVisibilityStageFS.js +34 -49
  210. package/Source/Shaders/Model/EdgeVisibilityStageVS.glsl +98 -0
  211. package/Source/Shaders/Model/EdgeVisibilityStageVS.js +100 -0
  212. package/Source/Shaders/Model/ModelFS.glsl +15 -0
  213. package/Source/Shaders/Model/ModelFS.js +15 -0
  214. package/Source/Shaders/Model/ModelVS.glsl +8 -0
  215. package/Source/Shaders/Model/ModelVS.js +8 -0
  216. package/Source/Shaders/PolygonSignedDistanceFS.glsl +64 -33
  217. package/Source/Shaders/PolygonSignedDistanceFS.js +64 -33
  218. package/Source/Shaders/PrimitiveGaussianSplatVS.glsl +9 -2
  219. package/Source/Shaders/PrimitiveGaussianSplatVS.js +9 -2
  220. package/Source/Shaders/Voxels/VoxelFS.glsl +1 -1
  221. package/Source/Shaders/Voxels/VoxelFS.js +1 -1
  222. package/Source/Workers/decodeDraco.js +3 -0
  223. package/Source/Workers/decodeI3S.js +5 -2
  224. package/index.d.ts +1007 -111
  225. package/index.js +368 -343
  226. package/package.json +2 -2
@@ -149,9 +149,9 @@ function createTextureForPropertyTable(
149
149
 
150
150
  const numFeatures = propertyTable.count;
151
151
 
152
- let gpuCompatiblePropertyBufferViews;
152
+ let gpuCompatiblePropertyInfo;
153
153
  try {
154
- gpuCompatiblePropertyBufferViews = collectGpuCompatiblePropertyBufferViews(
154
+ gpuCompatiblePropertyInfo = collectGpuCompatiblePropertyInfo(
155
155
  properties,
156
156
  bufferViews,
157
157
  classDefinition,
@@ -164,7 +164,7 @@ function createTextureForPropertyTable(
164
164
  return undefined;
165
165
  }
166
166
 
167
- const numGpuCompatibleProperties = gpuCompatiblePropertyBufferViews.length;
167
+ const numGpuCompatibleProperties = gpuCompatiblePropertyInfo.length;
168
168
 
169
169
  if (numGpuCompatibleProperties === 0) {
170
170
  return undefined;
@@ -183,7 +183,7 @@ function createTextureForPropertyTable(
183
183
  }
184
184
 
185
185
  const packedBufferView = packPropertyTablePropertiesIntoRGBA8(
186
- gpuCompatiblePropertyBufferViews,
186
+ gpuCompatiblePropertyInfo,
187
187
  numFeatures,
188
188
  );
189
189
 
@@ -209,13 +209,13 @@ function createTextureForPropertyTable(
209
209
  });
210
210
  }
211
211
 
212
- function collectGpuCompatiblePropertyBufferViews(
212
+ function collectGpuCompatiblePropertyInfo(
213
213
  properties,
214
214
  bufferViews,
215
215
  classDefinition,
216
216
  numFeatures,
217
217
  ) {
218
- const bufferViewsForThisTable = [];
218
+ const propertyInfos = [];
219
219
  const classProperties = classDefinition.properties;
220
220
 
221
221
  // It's possible for a primitive in a tileset to only use a subset of the class properties defined in the schema.
@@ -234,7 +234,7 @@ function collectGpuCompatiblePropertyBufferViews(
234
234
  : createNoDataBufferView(classProperty, numFeatures);
235
235
 
236
236
  const bufferViewLength = bufferView.length;
237
- const bytesPerElement = classProperty.bytesPerElement();
237
+ const bytesPerElement = classProperty.cpuBytesPerElement();
238
238
  const numBufferElements = bufferViewLength / bytesPerElement;
239
239
  if (numBufferElements !== numFeatures) {
240
240
  throw new RuntimeError(
@@ -242,13 +242,13 @@ function collectGpuCompatiblePropertyBufferViews(
242
242
  );
243
243
  }
244
244
 
245
- bufferViewsForThisTable.push({
245
+ propertyInfos.push({
246
246
  view: bufferView,
247
- bytesPerElement: bytesPerElement,
247
+ classProperty: classProperty,
248
248
  });
249
249
  }
250
250
 
251
- return bufferViewsForThisTable;
251
+ return propertyInfos;
252
252
  }
253
253
 
254
254
  /**
@@ -287,18 +287,25 @@ function createNoDataBufferView(classProperty, numFeatures) {
287
287
  noData = [noData];
288
288
  }
289
289
 
290
- const bytesPerElement = classProperty.bytesPerElement();
290
+ const bytesPerElement = classProperty.cpuBytesPerElement();
291
+ const bytesPerComponent = MetadataComponentType.getSizeInBytes(
292
+ classProperty.valueType,
293
+ );
291
294
  const buffer = new ArrayBuffer(bytesPerElement * numFeatures);
292
295
  const view = new DataView(buffer);
293
- const setter = MetadataComponentType.getDataViewSetter(
296
+ const accessors = MetadataComponentType.getDataViewAccessors(
294
297
  view,
295
- classProperty.componentType,
298
+ classProperty.valueType,
296
299
  );
297
300
 
298
301
  for (let i = 0; i < numFeatures; i++) {
299
302
  for (let j = 0; j < metadataArrayLength; j++) {
300
303
  for (let k = 0; k < metadataComponentCount; k++) {
301
- setter(bytesPerElement * i + j + k, noData[j][k]);
304
+ const componentIdx = j * metadataComponentCount + k;
305
+ accessors.set(
306
+ bytesPerElement * i + componentIdx * bytesPerComponent,
307
+ noData[j][k],
308
+ );
302
309
  }
303
310
  }
304
311
  }
@@ -308,39 +315,92 @@ function createNoDataBufferView(classProperty, numFeatures) {
308
315
 
309
316
  // Make one big buffer view to load into the texture
310
317
  // Since each texel is always 4 bytes (RGBA8 format), elements less than 4 bytes need to be padded (respecting little-endian order).
311
- function packPropertyTablePropertiesIntoRGBA8(
312
- bufferViewsForThisTable,
313
- numFeatures,
314
- ) {
315
- const numGpuCompatibleProperties = bufferViewsForThisTable.length;
318
+ // Exception: single-component 64-bit types can be downcast to 32-bit for GPU compatibility (with potential loss of precision / range).
319
+ function packPropertyTablePropertiesIntoRGBA8(propertyInfos, numFeatures) {
320
+ const numGpuCompatibleProperties = propertyInfos.length;
316
321
  const packedBufferView = new Uint8Array(
317
322
  numGpuCompatibleProperties * numFeatures * NUM_CHANNELS,
318
323
  );
324
+ const packedDataView = new DataView(
325
+ packedBufferView.buffer,
326
+ packedBufferView.byteOffset,
327
+ packedBufferView.byteLength,
328
+ );
319
329
 
320
- for (let i = 0, offset = 0; i < bufferViewsForThisTable.length; i++) {
321
- const bufferView = bufferViewsForThisTable[i].view;
322
- const bytesPerElement = bufferViewsForThisTable[i].bytesPerElement;
323
- const numElements = bufferView.length / bytesPerElement;
330
+ for (
331
+ let propertyIndex = 0;
332
+ propertyIndex < numGpuCompatibleProperties;
333
+ propertyIndex++
334
+ ) {
335
+ const propertyInfo = propertyInfos[propertyIndex];
336
+ const classProperty = propertyInfo.classProperty;
337
+ const rowOffset = propertyIndex * numFeatures * NUM_CHANNELS;
338
+ const sourceType = classProperty.valueType;
339
+ const packedType = MetadataComponentType.gpuComponentType(sourceType);
340
+
341
+ // E.g. When the source component type is INT64, we first downcast each element to INT32 before packing into the GPU buffer.
342
+ if (sourceType !== packedType) {
343
+ downcastAndPackProperty(propertyInfo, packedDataView, rowOffset);
344
+ continue;
345
+ }
324
346
 
325
- for (let j = 0; j < numElements; j++) {
326
- const sourceOffset = j * bytesPerElement;
327
- const destOffset = offset + j * NUM_CHANNELS;
347
+ packProperty(propertyInfo, packedBufferView, rowOffset);
348
+ }
328
349
 
329
- packedBufferView.set(
330
- bufferView.subarray(sourceOffset, sourceOffset + bytesPerElement),
331
- destOffset,
332
- );
350
+ return packedBufferView;
351
+ }
333
352
 
334
- // Pad remaining channels with 0
335
- for (let k = bytesPerElement; k < NUM_CHANNELS; k++) {
336
- packedBufferView[destOffset + k] = 0;
337
- }
338
- }
353
+ function packProperty(propertyInfo, packedBufferView, rowOffset) {
354
+ const bufferView = propertyInfo.view;
355
+ const bytesPerElement = propertyInfo.classProperty.cpuBytesPerElement();
356
+ const numElements = bufferView.length / bytesPerElement;
357
+
358
+ for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
359
+ const sourceOffset = elementIndex * bytesPerElement;
360
+ const destinationOffset = rowOffset + elementIndex * NUM_CHANNELS;
339
361
 
340
- offset += numElements * NUM_CHANNELS;
362
+ packedBufferView.set(
363
+ bufferView.subarray(sourceOffset, sourceOffset + bytesPerElement),
364
+ destinationOffset,
365
+ );
341
366
  }
367
+ }
342
368
 
343
- return packedBufferView;
369
+ // This is the slow path - rather than doing a straight copy, we need to interpret and downcast each element before packing it into the GPU buffer.
370
+ // Note: this function does not handle properties with multiple components per element (or arrays). While not complete, this is OK because
371
+ // multi-component properties with 64-bit types - even when downcast to 32 bits - cannot fit into a single RGBA8 texel.
372
+ function downcastAndPackProperty(propertyInfo, packedDataView, rowOffset) {
373
+ const classProperty = propertyInfo.classProperty;
374
+ const bufferView = propertyInfo.view;
375
+ const sourceType = classProperty.valueType;
376
+ const packedType = MetadataComponentType.gpuComponentType(sourceType);
377
+
378
+ const bytesPerElement = classProperty.cpuBytesPerElement();
379
+ const numElements = bufferView.length / bytesPerElement;
380
+
381
+ const sourceDataView = new DataView(
382
+ bufferView.buffer,
383
+ bufferView.byteOffset,
384
+ bufferView.byteLength,
385
+ );
386
+ const sourceAccessors = MetadataComponentType.getDataViewAccessors(
387
+ sourceDataView,
388
+ sourceType,
389
+ );
390
+ const packedAccessors = MetadataComponentType.getDataViewAccessors(
391
+ packedDataView,
392
+ packedType,
393
+ );
394
+
395
+ const downcastFunction = MetadataComponentType.downcastFunction(sourceType);
396
+
397
+ for (let elementIndex = 0; elementIndex < numElements; elementIndex++) {
398
+ const sourceElementOffset = elementIndex * bytesPerElement;
399
+ const destinationElementOffset = rowOffset + elementIndex * NUM_CHANNELS;
400
+
401
+ const value = sourceAccessors.get(sourceElementOffset);
402
+ packedAccessors.set(destinationElementOffset, downcastFunction(value));
403
+ }
344
404
  }
345
405
 
346
406
  export default parseStructuralMetadata;
@@ -0,0 +1,334 @@
1
+ // @ts-check
2
+
3
+ import defined from "../Core/defined.js";
4
+ import Cartesian3 from "../Core/Cartesian3.js";
5
+ import Color from "../Core/Color.js";
6
+ import BufferPoint from "./BufferPoint.js";
7
+ import Buffer from "../Renderer/Buffer.js";
8
+ import BufferUsage from "../Renderer/BufferUsage.js";
9
+ import VertexArray from "../Renderer/VertexArray.js";
10
+ import ComponentDatatype from "../Core/ComponentDatatype.js";
11
+ import RenderState from "../Renderer/RenderState.js";
12
+ import BlendingState from "./BlendingState.js";
13
+ import ShaderSource from "../Renderer/ShaderSource.js";
14
+ import ShaderProgram from "../Renderer/ShaderProgram.js";
15
+ import DrawCommand from "../Renderer/DrawCommand.js";
16
+ import Pass from "../Renderer/Pass.js";
17
+ import PrimitiveType from "../Core/PrimitiveType.js";
18
+ import BufferPointMaterialVS from "../Shaders/BufferPointMaterialVS.js";
19
+ import BufferPointMaterialFS from "../Shaders/BufferPointMaterialFS.js";
20
+ import EncodedCartesian3 from "../Core/EncodedCartesian3.js";
21
+ import AttributeCompression from "../Core/AttributeCompression.js";
22
+ import Matrix4 from "../Core/Matrix4.js";
23
+ import BoundingSphere from "../Core/BoundingSphere.js";
24
+ import BufferPointMaterial from "./BufferPointMaterial.js";
25
+
26
+ /** @import FrameState from "./FrameState.js"; */
27
+ /** @import BufferPointCollection from "./BufferPointCollection.js"; */
28
+ /** @import {Destroyable, TypedArray} from "../Core/globalTypes.js"; */
29
+
30
+ /**
31
+ * TODO(PR#13211): Need 'keyof' syntax to avoid duplicating attribute names.
32
+ * @typedef {'positionHigh' | 'positionLow' | 'pickColor' | 'showSizeAndColor' | 'outlineWidthAndOutlineColor'} BufferPointAttribute
33
+ * @ignore
34
+ */
35
+
36
+ /**
37
+ * @type {Record<BufferPointAttribute, number>}
38
+ * @ignore
39
+ */
40
+ const BufferPointAttributeLocations = {
41
+ positionHigh: 0,
42
+ positionLow: 1,
43
+ pickColor: 2,
44
+ showSizeAndColor: 3,
45
+ outlineWidthAndOutlineColor: 4,
46
+ };
47
+
48
+ /**
49
+ * @typedef {object} BufferPointRenderContext
50
+ * @property {VertexArray} [vertexArray]
51
+ * @property {Record<BufferPointAttribute, TypedArray>} [attributeArrays]
52
+ * @property {RenderState} [renderState]
53
+ * @property {ShaderProgram} [shaderProgram]
54
+ * @property {DrawCommand} [command]
55
+ * @property {Destroyable[]} [pickIds] Unordered list of collection PickIds.
56
+ * @property {Function} destroy
57
+ * @ignore
58
+ */
59
+
60
+ // Scratch variables.
61
+ const point = new BufferPoint();
62
+ const material = new BufferPointMaterial();
63
+ const pickColor = new Color();
64
+ const cartesian = new Cartesian3();
65
+ const encodedCartesian = new EncodedCartesian3();
66
+
67
+ /**
68
+ * @param {BufferPointCollection} collection
69
+ * @param {FrameState} frameState
70
+ * @param {BufferPointRenderContext} [renderContext]
71
+ * @returns {BufferPointRenderContext}
72
+ * @ignore
73
+ */
74
+ function renderBufferPointCollection(collection, frameState, renderContext) {
75
+ const context = frameState.context;
76
+ renderContext = renderContext || { destroy: destroyRenderContext };
77
+
78
+ if (!defined(renderContext.attributeArrays)) {
79
+ const featureCountMax = collection.primitiveCountMax;
80
+
81
+ renderContext.attributeArrays = {
82
+ positionHigh: new Float32Array(featureCountMax * 3),
83
+ positionLow: new Float32Array(featureCountMax * 3),
84
+ pickColor: new Uint8Array(featureCountMax * 4),
85
+ showSizeAndColor: new Float32Array(featureCountMax * 3),
86
+ outlineWidthAndOutlineColor: new Float32Array(featureCountMax * 2),
87
+ };
88
+ }
89
+
90
+ if (!defined(renderContext.pickIds)) {
91
+ renderContext.pickIds = [];
92
+ }
93
+
94
+ if (collection._dirtyCount > 0) {
95
+ const { attributeArrays, pickIds } = renderContext;
96
+
97
+ const positionHighArray = attributeArrays.positionHigh;
98
+ const positionLowArray = attributeArrays.positionLow;
99
+ const pickColorArray = attributeArrays.pickColor;
100
+ const showSizeAndColorArray = attributeArrays.showSizeAndColor;
101
+ const outlineWidthAndOutlineColorArray =
102
+ attributeArrays.outlineWidthAndOutlineColor;
103
+
104
+ const { _dirtyOffset, _dirtyCount } = collection;
105
+
106
+ for (let i = _dirtyOffset, il = _dirtyOffset + _dirtyCount; i < il; i++) {
107
+ collection.get(i, point);
108
+
109
+ if (!point._dirty) {
110
+ continue;
111
+ }
112
+
113
+ if (collection._allowPicking && point._pickId === 0) {
114
+ const pickId = context.createPickId({
115
+ collection,
116
+ index: i,
117
+ get primitive() {
118
+ // Cannot reuse primitives; scene.drillPick() appends to a list.
119
+ return collection.get(this.index, new BufferPoint());
120
+ },
121
+ });
122
+ point._pickId = pickId.key;
123
+ pickIds.push(pickId);
124
+ }
125
+
126
+ point.getPosition(cartesian);
127
+ EncodedCartesian3.fromCartesian(cartesian, encodedCartesian);
128
+ point.getMaterial(material);
129
+ Color.fromRgba(point._pickId, pickColor);
130
+
131
+ positionHighArray[i * 3] = encodedCartesian.high.x;
132
+ positionHighArray[i * 3 + 1] = encodedCartesian.high.y;
133
+ positionHighArray[i * 3 + 2] = encodedCartesian.high.z;
134
+
135
+ positionLowArray[i * 3] = encodedCartesian.low.x;
136
+ positionLowArray[i * 3 + 1] = encodedCartesian.low.y;
137
+ positionLowArray[i * 3 + 2] = encodedCartesian.low.z;
138
+
139
+ pickColorArray[i * 4] = Color.floatToByte(pickColor.red);
140
+ pickColorArray[i * 4 + 1] = Color.floatToByte(pickColor.green);
141
+ pickColorArray[i * 4 + 2] = Color.floatToByte(pickColor.blue);
142
+ pickColorArray[i * 4 + 3] = Color.floatToByte(pickColor.alpha);
143
+
144
+ showSizeAndColorArray[i * 3] = point.show ? 1 : 0;
145
+ showSizeAndColorArray[i * 3 + 1] = material.size;
146
+ showSizeAndColorArray[i * 3 + 2] = AttributeCompression.encodeRGB8(
147
+ material.color,
148
+ );
149
+
150
+ outlineWidthAndOutlineColorArray[i * 2] = material.outlineWidth;
151
+ outlineWidthAndOutlineColorArray[i * 2 + 1] =
152
+ AttributeCompression.encodeRGB8(material.outlineColor);
153
+
154
+ point._dirty = false;
155
+ }
156
+ }
157
+
158
+ if (!defined(renderContext.vertexArray)) {
159
+ const { attributeArrays } = renderContext;
160
+
161
+ renderContext.vertexArray = new VertexArray({
162
+ context,
163
+ attributes: [
164
+ {
165
+ index: BufferPointAttributeLocations.positionHigh,
166
+ componentDatatype: ComponentDatatype.FLOAT,
167
+ componentsPerAttribute: 3,
168
+ vertexBuffer: Buffer.createVertexBuffer({
169
+ typedArray: attributeArrays.positionHigh,
170
+ context,
171
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
172
+ usage: BufferUsage.STATIC_DRAW,
173
+ }),
174
+ },
175
+ {
176
+ index: BufferPointAttributeLocations.positionLow,
177
+ componentDatatype: ComponentDatatype.FLOAT,
178
+ componentsPerAttribute: 3,
179
+ vertexBuffer: Buffer.createVertexBuffer({
180
+ typedArray: attributeArrays.positionLow,
181
+ context,
182
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
183
+ usage: BufferUsage.STATIC_DRAW,
184
+ }),
185
+ },
186
+ {
187
+ index: BufferPointAttributeLocations.pickColor,
188
+ componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
189
+ componentsPerAttribute: 4,
190
+ vertexBuffer: Buffer.createVertexBuffer({
191
+ typedArray: attributeArrays.pickColor,
192
+ context,
193
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
194
+ usage: BufferUsage.STATIC_DRAW,
195
+ }),
196
+ },
197
+ {
198
+ index: BufferPointAttributeLocations.showSizeAndColor,
199
+ componentDatatype: ComponentDatatype.FLOAT,
200
+ componentsPerAttribute: 3,
201
+ vertexBuffer: Buffer.createVertexBuffer({
202
+ typedArray: attributeArrays.showSizeAndColor,
203
+ context,
204
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
205
+ usage: BufferUsage.STATIC_DRAW,
206
+ }),
207
+ },
208
+ {
209
+ index: BufferPointAttributeLocations.outlineWidthAndOutlineColor,
210
+ componentDatatype: ComponentDatatype.FLOAT,
211
+ componentsPerAttribute: 2,
212
+ vertexBuffer: Buffer.createVertexBuffer({
213
+ typedArray: attributeArrays.outlineWidthAndOutlineColor,
214
+ context,
215
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
216
+ usage: BufferUsage.STATIC_DRAW,
217
+ }),
218
+ },
219
+ ],
220
+ });
221
+ } else if (collection._dirtyCount > 0) {
222
+ for (const key in BufferPointAttributeLocations) {
223
+ if (Object.hasOwn(BufferPointAttributeLocations, key)) {
224
+ const attribute = /** @type {BufferPointAttribute} */ (key);
225
+ renderContext.vertexArray.copyAttributeFromRange(
226
+ BufferPointAttributeLocations[attribute],
227
+ renderContext.attributeArrays[attribute],
228
+ collection._dirtyOffset,
229
+ collection._dirtyCount,
230
+ );
231
+ }
232
+ }
233
+ }
234
+
235
+ if (!defined(renderContext.renderState)) {
236
+ renderContext.renderState = RenderState.fromCache({
237
+ blending: BlendingState.ALPHA_BLEND,
238
+ depthTest: { enabled: true },
239
+ });
240
+ }
241
+
242
+ if (!defined(renderContext.shaderProgram)) {
243
+ renderContext.shaderProgram = ShaderProgram.fromCache({
244
+ context,
245
+ vertexShaderSource: new ShaderSource({
246
+ sources: [BufferPointMaterialVS],
247
+ }),
248
+ fragmentShaderSource: new ShaderSource({
249
+ sources: [BufferPointMaterialFS],
250
+ }),
251
+ attributeLocations: BufferPointAttributeLocations,
252
+ });
253
+ }
254
+
255
+ if (
256
+ !defined(renderContext.command) ||
257
+ isCommandDirty(collection, renderContext.command)
258
+ ) {
259
+ renderContext.command = new DrawCommand({
260
+ vertexArray: renderContext.vertexArray,
261
+ renderState: renderContext.renderState,
262
+ shaderProgram: renderContext.shaderProgram,
263
+ primitiveType: PrimitiveType.POINTS,
264
+ pass: Pass.OPAQUE,
265
+ pickId: "v_pickColor",
266
+ owner: collection,
267
+ count: collection.primitiveCount,
268
+ modelMatrix: collection.modelMatrix,
269
+ boundingVolume: collection.boundingVolumeWC,
270
+ debugShowBoundingVolume: collection.debugShowBoundingVolume,
271
+ });
272
+ }
273
+
274
+ frameState.commandList.push(renderContext.command);
275
+
276
+ collection._dirtyCount = 0;
277
+ collection._dirtyOffset = 0;
278
+
279
+ return renderContext;
280
+ }
281
+
282
+ /**
283
+ * Returns true if DrawCommand is out of date for the given collection.
284
+ * @param {BufferPointCollection} collection
285
+ * @param {DrawCommand} command
286
+ * @ignore
287
+ */
288
+ function isCommandDirty(collection, command) {
289
+ const isModelMatrixEqual = Matrix4.equals(
290
+ collection.modelMatrix,
291
+ command._modelMatrix,
292
+ );
293
+
294
+ const isBoundingVolumeEqual = BoundingSphere.equals(
295
+ collection.boundingVolumeWC,
296
+ command._boundingVolume,
297
+ );
298
+
299
+ return (
300
+ collection.primitiveCount !== command._count ||
301
+ collection.debugShowBoundingVolume !== command.debugShowBoundingVolume ||
302
+ !isModelMatrixEqual ||
303
+ !isBoundingVolumeEqual
304
+ );
305
+ }
306
+
307
+ /**
308
+ * Destroys render context resources. Deleting properties from the context
309
+ * object isn't necessary, as collection.destroy() will discard the object.
310
+ * @ignore
311
+ */
312
+ function destroyRenderContext() {
313
+ const context = /** @type {BufferPointRenderContext} */ (this);
314
+
315
+ if (defined(context.vertexArray)) {
316
+ context.vertexArray.destroy();
317
+ }
318
+
319
+ if (defined(context.shaderProgram)) {
320
+ context.shaderProgram.destroy();
321
+ }
322
+
323
+ if (defined(context.renderState)) {
324
+ RenderState.removeFromCache(context.renderState);
325
+ }
326
+
327
+ if (defined(context.pickIds)) {
328
+ for (const pickId of context.pickIds) {
329
+ pickId.destroy();
330
+ }
331
+ }
332
+ }
333
+
334
+ export default renderBufferPointCollection;