@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
@@ -0,0 +1,386 @@
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 BufferPolygon from "./BufferPolygon.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 BufferPolygonMaterialVS from "../Shaders/BufferPolygonMaterialVS.js";
19
+ import BufferPolygonMaterialFS from "../Shaders/BufferPolygonMaterialFS.js";
20
+ import EncodedCartesian3 from "../Core/EncodedCartesian3.js";
21
+ import AttributeCompression from "../Core/AttributeCompression.js";
22
+ import IndexDatatype from "../Core/IndexDatatype.js";
23
+ import BoundingSphere from "../Core/BoundingSphere.js";
24
+ import Matrix4 from "../Core/Matrix4.js";
25
+ import BufferPolygonMaterial from "./BufferPolygonMaterial.js";
26
+
27
+ /** @import {Destroyable, TypedArray} from "../Core/globalTypes.js"; */
28
+ /** @import FrameState from "./FrameState.js"; */
29
+ /** @import BufferPolygonCollection from "./BufferPolygonCollection.js"; */
30
+
31
+ /**
32
+ * TODO(PR#13211): Need 'keyof' syntax to avoid duplicating attribute names.
33
+ * @typedef {'positionHigh' | 'positionLow' | 'pickColor' | 'showAndColor'} BufferPolygonAttribute
34
+ * @ignore
35
+ */
36
+
37
+ /**
38
+ * @type {Record<BufferPolygonAttribute, number>}
39
+ * @ignore
40
+ */
41
+ const BufferPolygonAttributeLocations = {
42
+ positionHigh: 0,
43
+ positionLow: 1,
44
+ pickColor: 2,
45
+ showAndColor: 3,
46
+ };
47
+
48
+ /**
49
+ * @typedef {object} BufferPolygonRenderContext
50
+ * @property {VertexArray} [vertexArray]
51
+ * @property {Record<BufferPolygonAttribute, TypedArray>} [attributeArrays]
52
+ * @property {TypedArray} [indexArray]
53
+ * @property {RenderState} [renderState]
54
+ * @property {ShaderProgram} [shaderProgram]
55
+ * @property {DrawCommand} [command]
56
+ * @property {Destroyable[]} [pickIds]
57
+ * @property {Function} destroy
58
+ * @ignore
59
+ */
60
+
61
+ // Scratch variables.
62
+ const polygon = new BufferPolygon();
63
+ const material = new BufferPolygonMaterial();
64
+ const pickColor = new Color();
65
+ const cartesian = new Cartesian3();
66
+ const encodedCartesian = new EncodedCartesian3();
67
+
68
+ /**
69
+ * @param {BufferPolygonCollection} collection
70
+ * @param {FrameState} frameState
71
+ * @param {BufferPolygonRenderContext} [renderContext]
72
+ * @returns {BufferPolygonRenderContext}
73
+ * @ignore
74
+ */
75
+ function renderBufferPolygonCollection(collection, frameState, renderContext) {
76
+ const context = frameState.context;
77
+ renderContext = renderContext || { destroy: destroyRenderContext };
78
+
79
+ if (
80
+ !defined(renderContext.attributeArrays) ||
81
+ !defined(renderContext.indexArray)
82
+ ) {
83
+ const { vertexCountMax, triangleCountMax } = collection;
84
+
85
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
86
+ renderContext.indexArray = IndexDatatype.createTypedArray(
87
+ vertexCountMax,
88
+ triangleCountMax * 3,
89
+ );
90
+
91
+ renderContext.attributeArrays = {
92
+ positionHigh: new Float32Array(vertexCountMax * 3),
93
+ positionLow: new Float32Array(vertexCountMax * 3),
94
+ pickColor: new Uint8Array(vertexCountMax * 4),
95
+ showAndColor: new Float32Array(vertexCountMax * 2),
96
+ };
97
+ }
98
+
99
+ if (!defined(renderContext.pickIds)) {
100
+ renderContext.pickIds = [];
101
+ }
102
+
103
+ if (collection._dirtyCount > 0) {
104
+ const { attributeArrays, pickIds } = renderContext;
105
+ const { _dirtyOffset, _dirtyCount } = collection;
106
+
107
+ const indexArray = renderContext.indexArray;
108
+ const positionHighArray = attributeArrays.positionHigh;
109
+ const positionLowArray = attributeArrays.positionLow;
110
+ const pickColorArray = attributeArrays.pickColor;
111
+ const showAndColorArray = attributeArrays.showAndColor;
112
+
113
+ for (let i = _dirtyOffset, il = _dirtyOffset + _dirtyCount; i < il; i++) {
114
+ collection.get(i, polygon);
115
+
116
+ if (!polygon._dirty) {
117
+ continue;
118
+ }
119
+
120
+ if (collection._allowPicking && polygon._pickId === 0) {
121
+ const pickId = context.createPickId({
122
+ collection,
123
+ index: i,
124
+ get primitive() {
125
+ // Cannot reuse primitives; scene.drillPick() appends to a list.
126
+ return collection.get(i, new BufferPolygon());
127
+ },
128
+ });
129
+ polygon._pickId = pickId.key;
130
+ pickIds.push(pickId);
131
+ }
132
+
133
+ let tOffset = polygon.triangleOffset;
134
+ let vOffset = polygon.vertexOffset;
135
+
136
+ const polygonIndexArray = polygon.getTriangles();
137
+
138
+ // Update index.
139
+ for (let j = 0, jl = polygon.triangleCount; j < jl; j++) {
140
+ indexArray[tOffset * 3] = vOffset + polygonIndexArray[j * 3];
141
+ indexArray[tOffset * 3 + 1] = vOffset + polygonIndexArray[j * 3 + 1];
142
+ indexArray[tOffset * 3 + 2] = vOffset + polygonIndexArray[j * 3 + 2];
143
+
144
+ tOffset++;
145
+ }
146
+
147
+ const show = polygon.show;
148
+ const cartesianArray = polygon.getPositions();
149
+ polygon.getMaterial(material);
150
+ const encodedColor = AttributeCompression.encodeRGB8(material.color);
151
+ Color.fromRgba(polygon._pickId, pickColor);
152
+
153
+ // Update vertex arrays.
154
+ for (let j = 0, jl = polygon.vertexCount; j < jl; j++) {
155
+ // @ts-expect-error TODO(tsd-jsdoc): See https://github.com/CesiumGS/cesium/pull/13302.
156
+ Cartesian3.fromArray(cartesianArray, j * 3, cartesian);
157
+ EncodedCartesian3.fromCartesian(cartesian, encodedCartesian);
158
+
159
+ positionHighArray[vOffset * 3] = encodedCartesian.high.x;
160
+ positionHighArray[vOffset * 3 + 1] = encodedCartesian.high.y;
161
+ positionHighArray[vOffset * 3 + 2] = encodedCartesian.high.z;
162
+
163
+ positionLowArray[vOffset * 3] = encodedCartesian.low.x;
164
+ positionLowArray[vOffset * 3 + 1] = encodedCartesian.low.y;
165
+ positionLowArray[vOffset * 3 + 2] = encodedCartesian.low.z;
166
+
167
+ pickColorArray[vOffset * 4] = Color.floatToByte(pickColor.red);
168
+ pickColorArray[vOffset * 4 + 1] = Color.floatToByte(pickColor.green);
169
+ pickColorArray[vOffset * 4 + 2] = Color.floatToByte(pickColor.blue);
170
+ pickColorArray[vOffset * 4 + 3] = Color.floatToByte(pickColor.alpha);
171
+
172
+ showAndColorArray[vOffset * 2] = show ? 1 : 0;
173
+ showAndColorArray[vOffset * 2 + 1] = encodedColor;
174
+
175
+ vOffset++;
176
+ }
177
+
178
+ polygon._dirty = false;
179
+ }
180
+ }
181
+
182
+ if (!defined(renderContext.vertexArray)) {
183
+ const { attributeArrays } = renderContext;
184
+
185
+ renderContext.vertexArray = new VertexArray({
186
+ context,
187
+
188
+ indexBuffer: Buffer.createIndexBuffer({
189
+ context,
190
+ typedArray: renderContext.indexArray,
191
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
192
+ usage: BufferUsage.STATIC_DRAW,
193
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
194
+ indexDatatype: IndexDatatype.fromTypedArray(renderContext.indexArray),
195
+ }),
196
+
197
+ attributes: [
198
+ {
199
+ index: BufferPolygonAttributeLocations.positionHigh,
200
+ componentDatatype: ComponentDatatype.FLOAT,
201
+ componentsPerAttribute: 3,
202
+ vertexBuffer: Buffer.createVertexBuffer({
203
+ typedArray: attributeArrays.positionHigh,
204
+ context,
205
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
206
+ usage: BufferUsage.STATIC_DRAW,
207
+ }),
208
+ },
209
+ {
210
+ index: BufferPolygonAttributeLocations.positionLow,
211
+ componentDatatype: ComponentDatatype.FLOAT,
212
+ componentsPerAttribute: 3,
213
+ vertexBuffer: Buffer.createVertexBuffer({
214
+ typedArray: attributeArrays.positionLow,
215
+ context,
216
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
217
+ usage: BufferUsage.STATIC_DRAW,
218
+ }),
219
+ },
220
+ {
221
+ index: BufferPolygonAttributeLocations.pickColor,
222
+ componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
223
+ componentsPerAttribute: 4,
224
+ vertexBuffer: Buffer.createVertexBuffer({
225
+ typedArray: attributeArrays.pickColor,
226
+ context,
227
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
228
+ usage: BufferUsage.STATIC_DRAW,
229
+ }),
230
+ },
231
+ {
232
+ index: BufferPolygonAttributeLocations.showAndColor,
233
+ componentDatatype: ComponentDatatype.FLOAT,
234
+ componentsPerAttribute: 2,
235
+ vertexBuffer: Buffer.createVertexBuffer({
236
+ typedArray: attributeArrays.showAndColor,
237
+ context,
238
+ // @ts-expect-error Requires https://github.com/CesiumGS/cesium/pull/13203.
239
+ usage: BufferUsage.STATIC_DRAW,
240
+ }),
241
+ },
242
+ ],
243
+ });
244
+ } else if (collection._dirtyCount > 0) {
245
+ const { indexOffset, indexCount, vertexOffset, vertexCount } =
246
+ getPolygonDirtyRanges(collection);
247
+
248
+ renderContext.vertexArray.copyIndexFromRange(
249
+ renderContext.indexArray,
250
+ indexOffset,
251
+ indexCount,
252
+ );
253
+
254
+ for (const key in BufferPolygonAttributeLocations) {
255
+ if (Object.hasOwn(BufferPolygonAttributeLocations, key)) {
256
+ const attribute = /** @type {BufferPolygonAttribute} */ (key);
257
+ renderContext.vertexArray.copyAttributeFromRange(
258
+ BufferPolygonAttributeLocations[attribute],
259
+ renderContext.attributeArrays[attribute],
260
+ vertexOffset,
261
+ vertexCount,
262
+ );
263
+ }
264
+ }
265
+ }
266
+
267
+ if (!defined(renderContext.renderState)) {
268
+ renderContext.renderState = RenderState.fromCache({
269
+ blending: BlendingState.DISABLED,
270
+ depthTest: { enabled: true },
271
+ });
272
+ }
273
+
274
+ if (!defined(renderContext.shaderProgram)) {
275
+ renderContext.shaderProgram = ShaderProgram.fromCache({
276
+ context,
277
+ vertexShaderSource: new ShaderSource({
278
+ sources: [BufferPolygonMaterialVS],
279
+ }),
280
+ fragmentShaderSource: new ShaderSource({
281
+ sources: [BufferPolygonMaterialFS],
282
+ }),
283
+ attributeLocations: BufferPolygonAttributeLocations,
284
+ });
285
+ }
286
+
287
+ if (
288
+ !defined(renderContext.command) ||
289
+ isCommandDirty(collection, renderContext.command)
290
+ ) {
291
+ renderContext.command = new DrawCommand({
292
+ vertexArray: renderContext.vertexArray,
293
+ renderState: renderContext.renderState,
294
+ shaderProgram: renderContext.shaderProgram,
295
+ primitiveType: PrimitiveType.TRIANGLES,
296
+ pass: Pass.OPAQUE,
297
+ pickId: "v_pickColor",
298
+ owner: collection,
299
+ count: collection.triangleCount * 3,
300
+ modelMatrix: collection.modelMatrix,
301
+ boundingVolume: collection.boundingVolumeWC,
302
+ debugShowBoundingVolume: collection.debugShowBoundingVolume,
303
+ });
304
+ }
305
+
306
+ frameState.commandList.push(renderContext.command);
307
+
308
+ collection._dirtyCount = 0;
309
+ collection._dirtyOffset = 0;
310
+
311
+ return renderContext;
312
+ }
313
+
314
+ /**
315
+ * Returns true if DrawCommand is out of date for the given collection.
316
+ * @param {BufferPolygonCollection} collection
317
+ * @param {DrawCommand} command
318
+ * @ignore
319
+ */
320
+ function isCommandDirty(collection, command) {
321
+ const isModelMatrixEqual = Matrix4.equals(
322
+ collection.modelMatrix,
323
+ command._modelMatrix,
324
+ );
325
+
326
+ const isBoundingVolumeEqual = BoundingSphere.equals(
327
+ collection.boundingVolumeWC,
328
+ command._boundingVolume,
329
+ );
330
+
331
+ return (
332
+ collection.triangleCount * 3 !== command._count ||
333
+ collection.debugShowBoundingVolume !== command.debugShowBoundingVolume ||
334
+ !isModelMatrixEqual ||
335
+ !isBoundingVolumeEqual
336
+ );
337
+ }
338
+
339
+ /**
340
+ * Computes dirty ranges for attribute and index buffers in a collection.
341
+ * @param {BufferPolygonCollection} collection
342
+ * @ignore
343
+ */
344
+ function getPolygonDirtyRanges(collection) {
345
+ const { _dirtyOffset, _dirtyCount } = collection;
346
+
347
+ collection.get(_dirtyOffset, polygon);
348
+ const vertexOffset = polygon.vertexOffset;
349
+ const indexOffset = polygon.triangleOffset * 3;
350
+
351
+ collection.get(_dirtyOffset + _dirtyCount - 1, polygon);
352
+ const vertexCount = polygon.vertexOffset + polygon.vertexCount - vertexOffset;
353
+ const indexCount =
354
+ (polygon.triangleOffset + polygon.triangleCount) * 3 - indexOffset;
355
+
356
+ return { indexOffset, indexCount, vertexOffset, vertexCount };
357
+ }
358
+
359
+ /**
360
+ * Destroys render context resources. Deleting properties from the context
361
+ * object isn't necessary, as collection.destroy() will discard the object.
362
+ * @ignore
363
+ */
364
+ function destroyRenderContext() {
365
+ const context = /** @type {BufferPolygonRenderContext} */ (this);
366
+
367
+ if (defined(context.vertexArray)) {
368
+ context.vertexArray.destroy();
369
+ }
370
+
371
+ if (defined(context.shaderProgram)) {
372
+ context.shaderProgram.destroy();
373
+ }
374
+
375
+ if (defined(context.renderState)) {
376
+ RenderState.removeFromCache(context.renderState);
377
+ }
378
+
379
+ if (defined(context.pickIds)) {
380
+ for (const pickId of context.pickIds) {
381
+ pickId.destroy();
382
+ }
383
+ }
384
+ }
385
+
386
+ export default renderBufferPolygonCollection;