@cesium/engine 23.0.1 → 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-G6MJ3ZW3.js → chunk-2N4KDHS3.js} +10 -10
  2. package/Build/Workers/{chunk-C6HHBKT5.js → chunk-44EMEGKW.js} +5 -5
  3. package/Build/Workers/{chunk-TNXOPEIG.js → chunk-4TIG36AW.js} +12 -12
  4. package/Build/Workers/{chunk-PQTSXJBJ.js → chunk-5A2SW66E.js} +16 -16
  5. package/Build/Workers/{chunk-TXYQNXNW.js → chunk-5GXYJQ2K.js} +3 -3
  6. package/Build/Workers/{chunk-O67UP5YO.js → chunk-63SIWPLS.js} +13 -13
  7. package/Build/Workers/{chunk-CVAAIRNP.js → chunk-6MPGQEHA.js} +2 -2
  8. package/Build/Workers/{chunk-LHFC4R7Z.js → chunk-6RMS4S72.js} +6 -6
  9. package/Build/Workers/{chunk-77DJBHMI.js → chunk-6WLHJFD3.js} +7 -7
  10. package/Build/Workers/{chunk-HXEPZWJN.js → chunk-72VYSVEW.js} +9 -9
  11. package/Build/Workers/{chunk-VPWYHFQA.js → chunk-7MDYBRYJ.js} +4 -4
  12. package/Build/Workers/{chunk-XPMXRJDD.js → chunk-7O5XJTVE.js} +5 -5
  13. package/Build/Workers/{chunk-UEWYSOFD.js → chunk-7QRFIKWQ.js} +2 -2
  14. package/Build/Workers/{chunk-3UQ2YMPP.js → chunk-7TYLCBGK.js} +8 -8
  15. package/Build/Workers/{chunk-GLCPE2BJ.js → chunk-7X322WP2.js} +13 -13
  16. package/Build/Workers/{chunk-2OBWHTIC.js → chunk-A47HVBC5.js} +7 -7
  17. package/Build/Workers/{chunk-CID5SY7L.js → chunk-AF3MU2RL.js} +5 -5
  18. package/Build/Workers/{chunk-BTP3634E.js → chunk-AJLTU6PF.js} +1 -1
  19. package/Build/Workers/{chunk-YSJRB2UZ.js → chunk-AMIHNSST.js} +2 -2
  20. package/Build/Workers/{chunk-QPXGGVHC.js → chunk-B6SCUUFP.js} +10 -10
  21. package/Build/Workers/{chunk-QNABVTTP.js → chunk-BJD6QGXZ.js} +12 -12
  22. package/Build/Workers/{chunk-RZX6LOG6.js → chunk-C6P4IG5P.js} +6 -6
  23. package/Build/Workers/{chunk-4JJQRZYL.js → chunk-D4EJ2NXG.js} +17 -17
  24. package/Build/Workers/{chunk-K7UTK4OM.js → chunk-DHKPFLSJ.js} +1 -1
  25. package/Build/Workers/{chunk-S53HSRT6.js → chunk-DVB56LG7.js} +6 -6
  26. package/Build/Workers/{chunk-PBECJOWF.js → chunk-EDXL4W76.js} +2 -2
  27. package/Build/Workers/{chunk-ALTCIHRH.js → chunk-EV3VGO6Y.js} +17 -17
  28. package/Build/Workers/{chunk-UOQB7XQI.js → chunk-GOQBUCXH.js} +10 -10
  29. package/Build/Workers/{chunk-TMCTZ5E3.js → chunk-GQUNK2XC.js} +14 -14
  30. package/Build/Workers/{chunk-PAFMAR7A.js → chunk-HKUES6UG.js} +12 -12
  31. package/Build/Workers/{chunk-6U5QMZU3.js → chunk-HRHRYFHS.js} +9 -9
  32. package/Build/Workers/{chunk-PUO7BYDY.js → chunk-HXJMS2ZI.js} +1 -1
  33. package/Build/Workers/{chunk-FXSRA5UG.js → chunk-ILMFADZA.js} +4 -4
  34. package/Build/Workers/{chunk-U4SWB6TI.js → chunk-ISY4EZCA.js} +4 -4
  35. package/Build/Workers/{chunk-PGZ3B6CB.js → chunk-J6AW5YHS.js} +14 -14
  36. package/Build/Workers/{chunk-VX774SWE.js → chunk-JCI63T3K.js} +6 -6
  37. package/Build/Workers/{chunk-54O3AGOA.js → chunk-KLPGTXS3.js} +6 -6
  38. package/Build/Workers/{chunk-CNLXMOPM.js → chunk-LIB2H534.js} +10 -10
  39. package/Build/Workers/{chunk-H3TVRJLY.js → chunk-LXMCPFFS.js} +4 -4
  40. package/Build/Workers/{chunk-DNMASBMH.js → chunk-MKM27KGV.js} +2 -2
  41. package/Build/Workers/{chunk-66OWUDO7.js → chunk-N65BAKSH.js} +8 -8
  42. package/Build/Workers/{chunk-ZEMJQKHD.js → chunk-NKT5K3K3.js} +11 -11
  43. package/Build/Workers/{chunk-EIC3VAOZ.js → chunk-NPF7SSHZ.js} +7 -7
  44. package/Build/Workers/{chunk-YDR5LX5Z.js → chunk-PVV64VFW.js} +1 -1
  45. package/Build/Workers/{chunk-FKU77FNM.js → chunk-Q3C6VQH6.js} +4 -4
  46. package/Build/Workers/{chunk-CYOPNGPX.js → chunk-RQNJD3O4.js} +12 -12
  47. package/Build/Workers/{chunk-IJ3SUMK3.js → chunk-UIGVOKKI.js} +1 -1
  48. package/Build/Workers/{chunk-TFPG3ZKW.js → chunk-UQU4RXLT.js} +27 -19
  49. package/Build/Workers/{chunk-N6HRZLS6.js → chunk-VLDEUTOP.js} +2 -2
  50. package/Build/Workers/{chunk-MNSNOONX.js → chunk-VMVOUQ5J.js} +7 -7
  51. package/Build/Workers/{chunk-OZYB3AOR.js → chunk-XJRBB253.js} +11 -11
  52. package/Build/Workers/{chunk-B2VA6IEL.js → chunk-XY6HMDGI.js} +5 -5
  53. package/Build/Workers/{chunk-2M7DKGLW.js → chunk-Y7HNNPNK.js} +10 -10
  54. package/Build/Workers/{chunk-CJ7ZDY77.js → chunk-YAOZMOFL.js} +5 -5
  55. package/Build/Workers/{chunk-FCJQO4NC.js → chunk-YJZGW74L.js} +8 -8
  56. package/Build/Workers/{chunk-JUKGMJX7.js → chunk-YQFTYQMZ.js} +1 -1
  57. package/Build/Workers/{chunk-HNDE73JK.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 +215 -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 +394 -369
  226. package/package.json +2 -2
@@ -0,0 +1,702 @@
1
+ // @ts-check
2
+
3
+ import BoundingSphere from "../Core/BoundingSphere.js";
4
+ import Cartesian3 from "../Core/Cartesian3.js";
5
+ import DeveloperError from "../Core/DeveloperError.js";
6
+ import Frozen from "../Core/Frozen.js";
7
+ import Matrix4 from "../Core/Matrix4.js";
8
+ import assert from "../Core/assert.js";
9
+ import ComponentDatatype from "../Core/ComponentDatatype.js";
10
+ import defined from "../Core/defined.js";
11
+ import Check from "../Core/Check.js";
12
+
13
+ /** @import { Destroyable, TypedArray, TypedArrayConstructor } from "../Core/globalTypes.js"; */
14
+ /** @import BufferPrimitive from "./BufferPrimitive.js"; */
15
+ /** @import BufferPrimitiveMaterial from "./BufferPrimitiveMaterial.js"; */
16
+
17
+ /**
18
+ * @typedef {object} BufferPrimitiveOptions
19
+ * @property {boolean} [show=true]
20
+ * @property {BufferPrimitiveMaterial} [material]
21
+ * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
22
+ */
23
+
24
+ /**
25
+ * Collection of primitives held in ArrayBuffer storage for performance and memory optimization.
26
+ *
27
+ * <p>To get the full performance benefit of using a BufferPrimitiveCollection containing "N" primitives,
28
+ * be careful to avoid allocating "N" instances of any related JavaScript object. {@link BufferPrimitive},
29
+ * {@link Color}, {@link Cartesian3}, and other objects can all be reused when working with large collections,
30
+ * using the {@link https://en.wikipedia.org/wiki/Flyweight_pattern|flyweight pattern}.</p>
31
+ *
32
+ * @abstract
33
+ * @template T extends BufferPrimitive
34
+ * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
35
+ *
36
+ * @see BufferPrimitive
37
+ * @see BufferPrimitiveMaterial
38
+ * @see BufferPointCollection
39
+ * @see BufferPolylineCollection
40
+ * @see BufferPolygonCollection
41
+ */
42
+ class BufferPrimitiveCollection {
43
+ /**
44
+ * Default capacity of buffers on new collections. A quantity of elements:
45
+ * number of vertices in the vertex buffer, primitives in the primitive
46
+ * buffer, etc. This value is arbitrary, and collections cannot be resized,
47
+ * so specific per-buffer capacities should be provided in the collection
48
+ * constructor when available.
49
+ *
50
+ * @type {number}
51
+ * @readonly
52
+ * @static
53
+ */
54
+ static DEFAULT_CAPACITY = 1024;
55
+
56
+ /** @ignore */
57
+ static Error = {
58
+ ERR_RESIZE: "BufferPrimitive range cannot be resized after initialization.",
59
+ ERR_CAPACITY: "BufferPrimitiveCollection capacity exceeded.",
60
+ ERR_MULTIPLE_OF_FOUR:
61
+ "BufferPrimitive byte length must be a multiple of 4.",
62
+ ERR_OUT_OF_RANGE: "BufferPrimitive buffer access out of range.",
63
+ };
64
+
65
+ /**
66
+ * Resources managed by the collection's renderer. Collections may have multiple renderer
67
+ * implementations, so the collection should be ignorant of the renderer's implementation
68
+ * and context data. A collection only has one renderer active at a time.
69
+ *
70
+ * @type {Destroyable|null}
71
+ * @ignore
72
+ */
73
+ _renderContext = null;
74
+
75
+ /**
76
+ * @param {object} options
77
+ * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] Transforms geometry from model to world coordinates.
78
+ * @param {number} [options.primitiveCountMax=BufferPrimitiveCollection.DEFAULT_CAPACITY]
79
+ * @param {number} [options.vertexCountMax=BufferPrimitiveCollection.DEFAULT_CAPACITY]
80
+ * @param {boolean} [options.show=true]
81
+ * @param {ComponentDatatype} [options.positionDatatype=ComponentDatatype.DOUBLE]
82
+ * @param {boolean} [options.allowPicking=false] When <code>true</code>, primitives are pickable with {@link Scene#pick}. When <code>false</code>, memory and initialization cost are lower.
83
+ * @param {boolean} [options.debugShowBoundingVolume=false]
84
+ */
85
+ constructor(options = Frozen.EMPTY_OBJECT) {
86
+ /**
87
+ * Determines if primitives in this collection will be shown.
88
+ * @type {boolean}
89
+ * @default true
90
+ */
91
+ this.show = options.show ?? true;
92
+
93
+ /**
94
+ * Transforms geometry from model to world coordinates.
95
+ * @type {Matrix4}
96
+ * @default Matrix4.IDENTITY
97
+ */
98
+ this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY);
99
+
100
+ /**
101
+ * Local bounding volume for all primitives in the collection, including both
102
+ * shown and hidden primitives.
103
+ * @type {BoundingSphere}
104
+ */
105
+ this.boundingVolume = new BoundingSphere();
106
+
107
+ /**
108
+ * World bounding volume for all primitives in the collection, including both
109
+ * shown and hidden primitives.
110
+ * @type {BoundingSphere}
111
+ */
112
+ this.boundingVolumeWC = new BoundingSphere();
113
+
114
+ /**
115
+ * When <code>true</code>, primitives are pickable with {@link Scene#pick}.
116
+ * When <code>false</code>, memory and initialization cost are lower.
117
+ * @type {boolean}
118
+ * @readonly
119
+ * @ignore
120
+ * @default false
121
+ */
122
+ this._allowPicking = options.allowPicking ?? false;
123
+
124
+ /**
125
+ * This property is for debugging only; it is not for production use nor is it optimized.
126
+ * <p>
127
+ * Draws the bounding sphere for each draw command in the primitive.
128
+ * </p>
129
+ *
130
+ * @type {boolean}
131
+ * @default false
132
+ */
133
+ this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false;
134
+
135
+ /**
136
+ * @type {number}
137
+ * @protected
138
+ * @ignore
139
+ */
140
+ this._primitiveCount = 0;
141
+
142
+ /**
143
+ * @type {number}
144
+ * @protected
145
+ * @ignore
146
+ */
147
+ this._primitiveCountMax =
148
+ options.primitiveCountMax ?? BufferPrimitiveCollection.DEFAULT_CAPACITY;
149
+
150
+ /**
151
+ * @type {DataView<ArrayBuffer>}
152
+ * @ignore
153
+ */
154
+ this._primitiveView = null;
155
+
156
+ /**
157
+ * @type {number}
158
+ * @ignore
159
+ */
160
+ this._positionCount = 0;
161
+
162
+ /**
163
+ * @type {number}
164
+ * @protected
165
+ * @ignore
166
+ */
167
+ this._positionCountMax =
168
+ options.vertexCountMax ?? BufferPrimitiveCollection.DEFAULT_CAPACITY;
169
+
170
+ /**
171
+ * @type {TypedArray}
172
+ * @ignore
173
+ */
174
+ this._positionView = null;
175
+
176
+ /**
177
+ * @type {DataView<ArrayBuffer>}
178
+ * @ignore
179
+ */
180
+ this._materialView = null;
181
+
182
+ // Potentially-dirty primitives are tracked as a contiguous range, with
183
+ // 'clean' primitives potentially within the range. Individual primitive
184
+ // 'dirty' flags are source-of-truth.
185
+
186
+ /**
187
+ * @type {number}
188
+ * @ignore
189
+ */
190
+ this._dirtyOffset = 0;
191
+
192
+ /**
193
+ * @type {number}
194
+ * @ignore
195
+ */
196
+ this._dirtyCount = 0;
197
+
198
+ /**
199
+ * @type {boolean}
200
+ * @ignore
201
+ */
202
+ this._dirtyBoundingVolume = false;
203
+
204
+ this._allocatePrimitiveBuffer();
205
+ this._allocatePositionBuffer(
206
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
207
+ options.positionDatatype ?? ComponentDatatype.DOUBLE,
208
+ );
209
+ this._allocateMaterialBuffer();
210
+ }
211
+
212
+ /**
213
+ * Accessing `this.constructor` can cause JSDoc builds to fail, so use this
214
+ * protected getter function instead.
215
+ * @protected
216
+ * @return {*}
217
+ * @ignore
218
+ */
219
+ _getCollectionClass() {
220
+ DeveloperError.throwInstantiationError();
221
+ }
222
+
223
+ /**
224
+ * @protected
225
+ * @return {*}
226
+ * @ignore
227
+ */
228
+ _getPrimitiveClass() {
229
+ DeveloperError.throwInstantiationError();
230
+ }
231
+
232
+ /**
233
+ * @return {*}
234
+ * @ignore
235
+ */
236
+ _getMaterialClass() {
237
+ DeveloperError.throwInstantiationError();
238
+ }
239
+
240
+ /////////////////////////////////////////////////////////////////////////////
241
+ // COLLECTION LIFECYCLE
242
+
243
+ /**
244
+ * @private
245
+ * @ignore
246
+ */
247
+ _allocatePrimitiveBuffer() {
248
+ const layout = this._getPrimitiveClass().Layout;
249
+
250
+ //>>includeStart('debug', pragmas.debug);
251
+ const { ERR_MULTIPLE_OF_FOUR } = BufferPrimitiveCollection.Error;
252
+ assert(layout.__BYTE_LENGTH % 4 === 0, ERR_MULTIPLE_OF_FOUR);
253
+ //>>includeEnd('debug');
254
+
255
+ this._primitiveView = new DataView(
256
+ new ArrayBuffer(this._primitiveCountMax * layout.__BYTE_LENGTH),
257
+ );
258
+ }
259
+
260
+ /**
261
+ * @param {ComponentDatatype} datatype
262
+ * @private
263
+ * @ignore
264
+ */
265
+ _allocatePositionBuffer(datatype) {
266
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
267
+ this._positionView = ComponentDatatype.createTypedArray(
268
+ datatype,
269
+ this._positionCountMax * 3,
270
+ );
271
+ }
272
+
273
+ /**
274
+ * @private
275
+ * @ignore
276
+ */
277
+ _allocateMaterialBuffer() {
278
+ const MaterialClass = this._getMaterialClass();
279
+ this._materialView = new DataView(
280
+ new ArrayBuffer(this._primitiveCountMax * MaterialClass.packedLength),
281
+ );
282
+ }
283
+
284
+ /**
285
+ * Returns true if this object was destroyed; otherwise, false.
286
+ *
287
+ * @returns {boolean} True if this object was destroyed; otherwise, false.
288
+ */
289
+ isDestroyed() {
290
+ return false;
291
+ }
292
+
293
+ /** Destroys collection and its GPU resources. */
294
+ destroy() {
295
+ if (defined(this._renderContext)) {
296
+ this._renderContext.destroy();
297
+ this._renderContext = undefined;
298
+ this._dirtyOffset = 0;
299
+ this._dirtyCount = this.primitiveCount;
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Sorts primitives of the collection.
305
+ *
306
+ * Because sorting changes the indices (but not the feature IDs) of primitives
307
+ * in the collection, the function also returns an array mapping from previous
308
+ * index to new index. When sorting repeatedly, the array can be reused and
309
+ * passed as the 'result' argument for each call.
310
+ *
311
+ * @param {Function} sortFn
312
+ * @param {Uint32Array} result
313
+ * @returns {Uint32Array} Mapping from previous index to new index.
314
+ */
315
+ sort(sortFn, result = new Uint32Array(this.primitiveCount)) {
316
+ const PrimitiveClass = this._getPrimitiveClass();
317
+ const CollectionClass = this._getCollectionClass();
318
+
319
+ const { primitiveCount } = this;
320
+
321
+ const a = new PrimitiveClass();
322
+ const b = new PrimitiveClass();
323
+
324
+ // Mapping from NEW index to PREVIOUS index.
325
+ const dstSrcMap = new Uint32Array(primitiveCount);
326
+ for (let i = 0; i < primitiveCount; i++) {
327
+ dstSrcMap[i] = i;
328
+ }
329
+ dstSrcMap.sort((indexA, indexB) =>
330
+ sortFn(this.get(indexA, a), this.get(indexB, b)),
331
+ );
332
+
333
+ // Mapping from PREVIOUS index to NEW index.
334
+ for (let i = 0; i < primitiveCount; i++) {
335
+ result[dstSrcMap[i]] = i;
336
+ }
337
+
338
+ // Copy primitives to temporary collection, in sort order.
339
+ const tmp = CollectionClass._cloneEmpty(this);
340
+ for (let i = 0; i < primitiveCount; i++) {
341
+ const src = this.get(dstSrcMap[i], a);
342
+ const dst = tmp.add({}, b);
343
+ PrimitiveClass.clone(src, dst);
344
+ }
345
+
346
+ // Assign buffers from temporary collection onto this one.
347
+ CollectionClass._replaceBuffers(tmp, this);
348
+ this._dirtyOffset = 0;
349
+ this._dirtyCount = primitiveCount;
350
+
351
+ return result;
352
+ }
353
+
354
+ /**
355
+ * Duplicates the contents of this collection into the result collection.
356
+ * Result collection is not resized, and must contain enough space for all
357
+ * primitives in the source collection. Existing primitives in the result
358
+ * collection will be overwritten.
359
+ *
360
+ * <p>Useful when allocating more space for a collection that has reached its
361
+ * capacity, and efficiently transferring features to the new collection.</p>
362
+ *
363
+ * @example
364
+ * const result = new BufferPrimitiveCollection({ ... }); // allocate larger 'result' collection
365
+ * BufferPrimitiveCollection.clone(collection, result); // copy primitives from 'collection' into 'result'
366
+ *
367
+ * @param {BufferPrimitiveCollection<T>} collection
368
+ * @param {BufferPrimitiveCollection<T>} result
369
+ * @template T extends BufferPrimitive
370
+ */
371
+ static clone(collection, result) {
372
+ //>>includeStart('debug', pragmas.debug);
373
+ const { ERR_CAPACITY } = BufferPrimitiveCollection.Error;
374
+ assert(collection.primitiveCount <= result.primitiveCountMax, ERR_CAPACITY);
375
+ assert(collection.vertexCount <= result.vertexCountMax, ERR_CAPACITY);
376
+ //>>includeEnd('debug');
377
+
378
+ const layout = collection._getPrimitiveClass().Layout;
379
+ const MaterialClass = collection._getMaterialClass();
380
+ const PrimitiveClass = collection._getPrimitiveClass();
381
+
382
+ this._copySubDataView(
383
+ collection._primitiveView,
384
+ result._primitiveView,
385
+ collection.primitiveCount * layout.__BYTE_LENGTH,
386
+ );
387
+
388
+ this._copySubArray(
389
+ collection._positionView,
390
+ result._positionView,
391
+ collection.vertexCount * 3,
392
+ );
393
+
394
+ this._copySubDataView(
395
+ collection._materialView,
396
+ result._materialView,
397
+ collection.primitiveCount * MaterialClass.packedLength,
398
+ );
399
+
400
+ result.show = collection.show;
401
+ result.debugShowBoundingVolume = collection.debugShowBoundingVolume;
402
+ result._primitiveCount = collection._primitiveCount;
403
+ result._positionCount = collection._positionCount;
404
+
405
+ // Unset PickIds.
406
+ const primitive = new PrimitiveClass();
407
+ for (let i = 0, il = result.primitiveCount; i < il; i++) {
408
+ result.get(i, primitive)._pickId = 0;
409
+ }
410
+
411
+ result._dirtyOffset = 0;
412
+ result._dirtyCount = result.primitiveCount;
413
+
414
+ collection.boundingVolume.clone(result.boundingVolume);
415
+
416
+ return result;
417
+ }
418
+
419
+ /**
420
+ * Returns an empty collection with the same buffer sizes as this collection.
421
+ * Internal utility for operations requiring a working copy of memory.
422
+ *
423
+ * @param {BufferPrimitiveCollection<T>} collection
424
+ * @returns {BufferPrimitiveCollection<T>}
425
+ * @template T extends BufferPrimitive
426
+ * @protected
427
+ * @abstract
428
+ * @ignore
429
+ */
430
+ static _cloneEmpty(collection) {
431
+ DeveloperError.throwInstantiationError();
432
+ }
433
+
434
+ /**
435
+ * Assigns buffers from source collection to target collection, without
436
+ * validation or side effects. Callers must handle any validation, dirty
437
+ * flag updates, etc.
438
+ *
439
+ * @param {BufferPrimitiveCollection<T>} src
440
+ * @param {BufferPrimitiveCollection<T>} dst
441
+ * @template T extends BufferPrimitive
442
+ * @protected
443
+ * @ignore
444
+ */
445
+ static _replaceBuffers(src, dst) {
446
+ dst._primitiveView = src._primitiveView;
447
+ dst._positionView = src._positionView;
448
+ dst._materialView = src._materialView;
449
+ }
450
+
451
+ /**
452
+ * Rebuilds collection bounding volume.
453
+ * @protected
454
+ * @ignore
455
+ */
456
+ _updateBoundingVolume() {
457
+ const TypedArray = /** @type {TypedArrayConstructor} */ (
458
+ this._positionView.constructor
459
+ );
460
+
461
+ // Exclude unused space in the position buffer.
462
+ const vertices = new TypedArray(
463
+ /** @type {ArrayBuffer} */ (this._positionView.buffer),
464
+ this._positionView.byteOffset,
465
+ this._positionCount * 3,
466
+ );
467
+
468
+ BoundingSphere.fromVertices(
469
+ vertices,
470
+ Cartesian3.ZERO,
471
+ 3,
472
+ this.boundingVolume,
473
+ );
474
+ BoundingSphere.transform(
475
+ this.boundingVolume,
476
+ this.modelMatrix,
477
+ this.boundingVolumeWC,
478
+ );
479
+ this._dirtyBoundingVolume = false;
480
+ }
481
+
482
+ /////////////////////////////////////////////////////////////////////////////
483
+ // PRIMITIVE LIFECYCLE
484
+
485
+ /**
486
+ * Makes the given {@link BufferPrimitive} a view onto this collection's
487
+ * primitive at the given index, for use when reading/writing primitive
488
+ * properties. When iterating over a large collection, prefer to reuse
489
+ * the same BufferPrimitive instance throughout the loop — rebinding
490
+ * an existing instance to a different primitive is cheap, and avoids
491
+ * allocating in-memory objects for every object.
492
+ *
493
+ * @example
494
+ * const primitive = new BufferPrimitive();
495
+ * for (let i = 0; i < collection.primitiveCount; i++) {
496
+ * collection.get(i, primitive);
497
+ * primitive.setColor(Color.RED);
498
+ * }
499
+ *
500
+ * @param {number} index
501
+ * @param {BufferPrimitive} result
502
+ * @returns {BufferPrimitive} The BufferPrimitive instance passed as the
503
+ * 'result' argument, now bound to the specified primitive index.
504
+ */
505
+ get(index, result) {
506
+ //>>includeStart('debug', pragmas.debug);
507
+ Check.typeOf.number.greaterThanOrEquals("index", index, 0);
508
+ Check.typeOf.number.lessThan("index", index, this._primitiveCount);
509
+ //>>includeEnd('debug');
510
+
511
+ result._collection = this;
512
+ result._index = index;
513
+ result._byteOffset = index * this._getPrimitiveClass().Layout.__BYTE_LENGTH;
514
+ return result;
515
+ }
516
+
517
+ /**
518
+ * Adds a new primitive to the collection, with the specified options. A
519
+ * {@link BufferPrimitive} instance is linked to the new primitive, using
520
+ * the 'result' argument if given, or a new instance if not. For repeated
521
+ * calls, prefer to reuse a single BufferPrimitive instance rather than
522
+ * allocating a new instance on each call.
523
+ *
524
+ * @param {BufferPrimitiveOptions} options
525
+ * @param {BufferPrimitive} result
526
+ * @returns {BufferPrimitive}
527
+ */
528
+ add(options = Frozen.EMPTY_OBJECT, result) {
529
+ //>>includeStart('debug', pragmas.debug);
530
+ const { ERR_CAPACITY } = BufferPrimitiveCollection.Error;
531
+ assert(this.primitiveCount < this.primitiveCountMax, ERR_CAPACITY);
532
+ //>>includeEnd('debug');
533
+
534
+ const MaterialClass = this._getMaterialClass();
535
+
536
+ result = this.get(this._primitiveCount++, result);
537
+ result.featureId = this._primitiveCount - 1;
538
+ result.show = options.show ?? true;
539
+ result.setMaterial(options.material ?? MaterialClass.DEFAULT_MATERIAL);
540
+ result._pickId = 0; // unset
541
+ result._dirty = true;
542
+ return result;
543
+ }
544
+
545
+ /**
546
+ * Marks primitive at given index as 'dirty', to be updated on next render.
547
+ * @param {number} index
548
+ * @ignore
549
+ */
550
+ _makeDirty(index) {
551
+ if (this._dirtyCount === 0) {
552
+ this._dirtyCount = 1;
553
+ this._dirtyOffset = index;
554
+ } else if (index < this._dirtyOffset) {
555
+ this._dirtyCount += this._dirtyOffset - index;
556
+ this._dirtyOffset = index;
557
+ } else if (index + 1 > this._dirtyOffset + this._dirtyCount) {
558
+ this._dirtyCount = index + 1 - this._dirtyOffset;
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Marks collection bounding volume as 'dirty', to be updated on next render.
564
+ * @ignore
565
+ */
566
+ _makeDirtyBoundingVolume() {
567
+ this._dirtyBoundingVolume = true;
568
+ }
569
+
570
+ /////////////////////////////////////////////////////////////////////////////
571
+ // RENDER
572
+
573
+ /** @param {object} frameState */
574
+ update(frameState) {
575
+ if (this._dirtyBoundingVolume) {
576
+ this._updateBoundingVolume();
577
+ }
578
+ }
579
+
580
+ /////////////////////////////////////////////////////////////////////////////
581
+ // ACCESSORS
582
+
583
+ /**
584
+ * Number of primitives in collection. Must be <= {@link primitiveCountMax}.
585
+ *
586
+ * @type {number}
587
+ * @readonly
588
+ */
589
+ get primitiveCount() {
590
+ return this._primitiveCount;
591
+ }
592
+
593
+ /**
594
+ * Maximum number of primitives this collection can contain. Must be >=
595
+ * {@link primitiveCount}.
596
+ *
597
+ * @type {number}
598
+ * @readonly
599
+ * @default {@link BufferPrimitiveCollection.DEFAULT_CAPACITY}
600
+ */
601
+ get primitiveCountMax() {
602
+ return this._primitiveCountMax;
603
+ }
604
+
605
+ /**
606
+ * Total byte length of buffers owned by this collection. Includes any unused
607
+ * space allocated by {@link primitiveCountMax}, even if no primitives have
608
+ * yet been added in that space.
609
+ *
610
+ * @type {number}
611
+ * @readonly
612
+ */
613
+ get byteLength() {
614
+ return (
615
+ this._primitiveView.byteLength +
616
+ this._positionView.byteLength +
617
+ this._materialView.byteLength
618
+ );
619
+ }
620
+
621
+ /**
622
+ * Number of vertices in collection. Must be <= {@link vertexCountMax}.
623
+ *
624
+ * @type {number}
625
+ * @readonly
626
+ */
627
+ get vertexCount() {
628
+ return this._positionCount;
629
+ }
630
+
631
+ /**
632
+ * Maximum number of vertices this collection can contain. Must be >=
633
+ * {@link vertexCount}.
634
+ *
635
+ * @type {number}
636
+ * @readonly
637
+ * @default {@link BufferPrimitiveCollection.DEFAULT_CAPACITY}
638
+ */
639
+ get vertexCountMax() {
640
+ return this._positionCountMax;
641
+ }
642
+
643
+ /////////////////////////////////////////////////////////////////////////////
644
+ // UTILS
645
+
646
+ /**
647
+ * @param {TypedArray} src
648
+ * @param {TypedArray} dst
649
+ * @param {number} count
650
+ * @protected
651
+ * @ignore
652
+ */
653
+ static _copySubArray(src, dst, count) {
654
+ for (let i = 0; i < count; i++) {
655
+ dst[i] = src[i];
656
+ }
657
+ }
658
+
659
+ /**
660
+ * @param {DataView} src
661
+ * @param {DataView} dst
662
+ * @param {number} byteLength
663
+ * @protected
664
+ * @ignore
665
+ */
666
+ static _copySubDataView(src, dst, byteLength) {
667
+ // No need to match the original array type, just copy in 4-byte chunks.
668
+ this._copySubArray(
669
+ new Uint32Array(src.buffer, src.byteOffset, src.byteLength / 4),
670
+ new Uint32Array(dst.buffer, dst.byteOffset, dst.byteLength / 4),
671
+ byteLength / 4,
672
+ );
673
+ }
674
+
675
+ /////////////////////////////////////////////////////////////////////////////
676
+ // DEBUG
677
+
678
+ /**
679
+ * Returns a JSON-serializable array representing the collection. This encoding
680
+ * is not memory-efficient, and should generally be used for debugging and
681
+ * testing.
682
+ *
683
+ * @example
684
+ * console.table(collection.toJSON());
685
+ *
686
+ * @returns {Array<Object>} List of JSON-serializable objects, one for each
687
+ * primitive in the collection.
688
+ */
689
+ toJSON() {
690
+ const PrimitiveClass = this._getPrimitiveClass();
691
+ const primitive = new PrimitiveClass();
692
+
693
+ const results = [];
694
+ for (let i = 0, il = this.primitiveCount; i < il; i++) {
695
+ results.push(this.get(i, primitive).toJSON());
696
+ }
697
+
698
+ return results;
699
+ }
700
+ }
701
+
702
+ export default BufferPrimitiveCollection;