@cesium/engine 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/Build/ThirdParty/Workers/z-worker-pako.js +6 -5
  2. package/Build/Workers/{chunk-ZNVSKMQ2.js → chunk-2CSEEWHN.js} +6 -6
  3. package/Build/Workers/{chunk-2ZBL3MVO.js → chunk-34DGOKCO.js} +10 -12
  4. package/Build/Workers/{chunk-QKBGRKKG.js → chunk-3RZK5NNV.js} +4 -4
  5. package/Build/Workers/{chunk-RV7ZOSS6.js → chunk-3S2MFY4B.js} +13 -13
  6. package/Build/Workers/{chunk-5TIV3L26.js → chunk-4AJGCQFX.js} +13 -13
  7. package/Build/Workers/{chunk-YV4H2Y7M.js → chunk-4KIUON73.js} +4 -4
  8. package/Build/Workers/{chunk-QCQUZGXI.js → chunk-4PHPQRSH.js} +4 -4
  9. package/Build/Workers/{chunk-HBQPB6IH.js → chunk-66E3H2KU.js} +12 -12
  10. package/Build/Workers/{chunk-TJBU6GML.js → chunk-6HCAQOVK.js} +6 -6
  11. package/Build/Workers/{chunk-VR5RBW52.js → chunk-7LPEGKOF.js} +7 -7
  12. package/Build/Workers/{chunk-MWV7IZK4.js → chunk-7VZNXIKG.js} +7 -7
  13. package/Build/Workers/{chunk-SE4PXOEA.js → chunk-A6NCZSL3.js} +19 -19
  14. package/Build/Workers/{chunk-Z7FQLK6N.js → chunk-AOFMPKUB.js} +4 -4
  15. package/Build/Workers/{chunk-73FKKY52.js → chunk-AOIKO5Y7.js} +5 -5
  16. package/Build/Workers/{chunk-YDVSBWEO.js → chunk-BDUJXBVF.js} +1 -1
  17. package/Build/Workers/{chunk-ADOVHYWO.js → chunk-C5CE4OG6.js} +469 -6
  18. package/Build/Workers/{chunk-LQJ5FFFR.js → chunk-CE6GTZ4I.js} +11 -13
  19. package/Build/Workers/{chunk-DGDUKCJJ.js → chunk-CYAJYEKW.js} +6 -6
  20. package/Build/Workers/{chunk-NP2GYYE5.js → chunk-FOZQIHZK.js} +6 -6
  21. package/Build/Workers/{chunk-L4BW3RUA.js → chunk-G7CJQKKD.js} +7 -7
  22. package/Build/Workers/{chunk-CO35JNNE.js → chunk-GIFJ77E4.js} +4 -4
  23. package/Build/Workers/{chunk-7COR472O.js → chunk-I5TDPPC4.js} +7197 -5096
  24. package/Build/Workers/{chunk-RMOEYCZW.js → chunk-IBXGK4WV.js} +2 -2
  25. package/Build/Workers/{chunk-GFA4SMXV.js → chunk-JI2445T5.js} +11 -11
  26. package/Build/Workers/{chunk-5R6VWLMH.js → chunk-KPY4F4BW.js} +6 -6
  27. package/Build/Workers/{chunk-C3XBUYBO.js → chunk-LVJCR7DH.js} +17 -17
  28. package/Build/Workers/{chunk-X2F6BEPY.js → chunk-LW7WGHEU.js} +16 -16
  29. package/Build/Workers/{chunk-BCU2LH5T.js → chunk-MWYZ64MH.js} +10 -10
  30. package/Build/Workers/chunk-NI2R52QD.js +961 -0
  31. package/Build/Workers/{chunk-I37B3MZ2.js → chunk-PEABJLCK.js} +1 -1
  32. package/Build/Workers/{chunk-P2YAAMT2.js → chunk-PK7TEP3J.js} +15 -15
  33. package/Build/Workers/{chunk-3NCVAGDA.js → chunk-POLFRINT.js} +14 -14
  34. package/Build/Workers/{chunk-E6WXPSJS.js → chunk-PS6AEMBR.js} +7 -7
  35. package/Build/Workers/{chunk-M2AYBTNH.js → chunk-PWF3YJJ5.js} +13 -13
  36. package/Build/Workers/{chunk-2632RVPI.js → chunk-QKF7XXEQ.js} +7 -7
  37. package/Build/Workers/{chunk-EOXYZ34O.js → chunk-RL73GOEF.js} +2 -2
  38. package/Build/Workers/{chunk-6WF3KIF5.js → chunk-RR7EOKGZ.js} +10 -10
  39. package/Build/Workers/{chunk-GXUXEOE2.js → chunk-S4XDCPKD.js} +1 -1
  40. package/Build/Workers/{chunk-NZWNZA6S.js → chunk-TMMOULW3.js} +5 -5
  41. package/Build/Workers/{chunk-SS4ESNE3.js → chunk-U4IMCOF5.js} +2 -2
  42. package/Build/Workers/{chunk-PXB7T27O.js → chunk-UAJEGIWA.js} +6 -6
  43. package/Build/Workers/{chunk-TZORKRNK.js → chunk-UCPPWV64.js} +1 -1
  44. package/Build/Workers/{chunk-EPKE7GE3.js → chunk-V7JB576Q.js} +5 -5
  45. package/Build/Workers/{chunk-DPUSFA7S.js → chunk-WEGCQ5DY.js} +6 -6
  46. package/Build/Workers/{chunk-N4KXMWQU.js → chunk-WFICTTOE.js} +2 -2
  47. package/Build/Workers/{chunk-P4XKB3QZ.js → chunk-WWP3I7R5.js} +5 -5
  48. package/Build/Workers/{chunk-WHUSTDIB.js → chunk-XHLDDE65.js} +10 -10
  49. package/Build/Workers/{chunk-24YTYWNB.js → chunk-XWML5Y7N.js} +11 -13
  50. package/Build/Workers/{chunk-C6OI26DR.js → chunk-YLZTCEBJ.js} +1 -1
  51. package/Build/Workers/{chunk-LAQP3SCC.js → chunk-ZC4AGBZK.js} +2 -2
  52. package/Build/Workers/{chunk-RSJXEO2A.js → chunk-ZDP32RQI.js} +2 -2
  53. package/Build/Workers/{chunk-ZYPTP7GS.js → chunk-ZWPIM77Q.js} +11 -11
  54. package/Build/Workers/combineGeometry.js +22 -24
  55. package/Build/Workers/createBoxGeometry.js +16 -18
  56. package/Build/Workers/createBoxOutlineGeometry.js +14 -16
  57. package/Build/Workers/createCircleGeometry.js +24 -26
  58. package/Build/Workers/createCircleOutlineGeometry.js +17 -19
  59. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -34
  60. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -31
  61. package/Build/Workers/createCorridorGeometry.js +27 -29
  62. package/Build/Workers/createCorridorOutlineGeometry.js +26 -28
  63. package/Build/Workers/createCylinderGeometry.js +18 -20
  64. package/Build/Workers/createCylinderOutlineGeometry.js +16 -18
  65. package/Build/Workers/createEllipseGeometry.js +24 -26
  66. package/Build/Workers/createEllipseOutlineGeometry.js +17 -19
  67. package/Build/Workers/createEllipsoidGeometry.js +17 -19
  68. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -18
  69. package/Build/Workers/createFrustumGeometry.js +16 -18
  70. package/Build/Workers/createFrustumOutlineGeometry.js +18 -19
  71. package/Build/Workers/createGeometry.js +22 -24
  72. package/Build/Workers/createGroundPolylineGeometry.js +23 -25
  73. package/Build/Workers/createPlaneGeometry.js +14 -16
  74. package/Build/Workers/createPlaneOutlineGeometry.js +13 -15
  75. package/Build/Workers/createPolygonGeometry.js +32 -34
  76. package/Build/Workers/createPolygonOutlineGeometry.js +28 -30
  77. package/Build/Workers/createPolylineGeometry.js +23 -25
  78. package/Build/Workers/createPolylineVolumeGeometry.js +29 -31
  79. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -27
  80. package/Build/Workers/createRectangleGeometry.js +27 -29
  81. package/Build/Workers/createRectangleOutlineGeometry.js +18 -20
  82. package/Build/Workers/createSimplePolylineGeometry.js +21 -23
  83. package/Build/Workers/createSphereGeometry.js +17 -19
  84. package/Build/Workers/createSphereOutlineGeometry.js +16 -18
  85. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  86. package/Build/Workers/createVectorTileClampedPolylines.js +14 -16
  87. package/Build/Workers/createVectorTileGeometries.js +22 -24
  88. package/Build/Workers/createVectorTilePoints.js +12 -12
  89. package/Build/Workers/createVectorTilePolygons.js +20 -22
  90. package/Build/Workers/createVectorTilePolylines.js +14 -16
  91. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -25
  92. package/Build/Workers/createVerticesFromHeightmap.js +23 -25
  93. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -22
  94. package/Build/Workers/createWallGeometry.js +22 -24
  95. package/Build/Workers/createWallOutlineGeometry.js +21 -23
  96. package/Build/Workers/decodeDraco.js +11 -11
  97. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  98. package/Build/Workers/decodeI3S.js +10 -11
  99. package/Build/Workers/transcodeKTX2.js +8 -8
  100. package/Build/Workers/transferTypedArrayTest.js +1 -1
  101. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -22
  102. package/Source/Core/Ion.js +1 -1
  103. package/Source/Core/PixelFormat.js +1 -0
  104. package/Source/Core/Rectangle.js +89 -0
  105. package/Source/DataSources/DataSourceDisplay.js +5 -0
  106. package/Source/Renderer/ShaderBuilder.js +6 -3
  107. package/Source/Scene/ArcGisMapService.js +1 -1
  108. package/Source/Scene/Billboard.js +5 -3
  109. package/Source/Scene/Cesium3DTile.js +65 -0
  110. package/Source/Scene/Cesium3DTileset.js +48 -1
  111. package/Source/Scene/ClippingPolygon.js +212 -0
  112. package/Source/Scene/ClippingPolygonCollection.js +968 -0
  113. package/Source/Scene/Globe.js +14 -0
  114. package/Source/Scene/GlobeSurfaceShaderSet.js +81 -15
  115. package/Source/Scene/GlobeSurfaceTileProvider.js +81 -1
  116. package/Source/Scene/Model/Model.js +83 -0
  117. package/Source/Scene/Model/Model3DTileContent.js +21 -0
  118. package/Source/Scene/Model/ModelClippingPolygonsPipelineStage.js +92 -0
  119. package/Source/Scene/Model/ModelSceneGraph.js +5 -0
  120. package/Source/Scene/Terrain.js +2 -2
  121. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
  122. package/Source/Shaders/Builtin/Functions/clipPolygons.glsl +37 -0
  123. package/Source/Shaders/Builtin/Functions/clipPolygons.js +39 -0
  124. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.glsl +14 -0
  125. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.js +15 -0
  126. package/Source/Shaders/GlobeFS.glsl +12 -0
  127. package/Source/Shaders/GlobeFS.js +12 -0
  128. package/Source/Shaders/GlobeVS.glsl +32 -0
  129. package/Source/Shaders/GlobeVS.js +32 -0
  130. package/Source/Shaders/Model/GeometryStageVS.glsl +1 -1
  131. package/Source/Shaders/Model/GeometryStageVS.js +1 -1
  132. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.glsl +6 -0
  133. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.js +8 -0
  134. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl +27 -0
  135. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.js +29 -0
  136. package/Source/Shaders/Model/ModelFS.glsl +6 -0
  137. package/Source/Shaders/Model/ModelFS.js +7 -1
  138. package/Source/Shaders/Model/ModelVS.glsl +4 -0
  139. package/Source/Shaders/Model/ModelVS.js +4 -0
  140. package/Source/Shaders/PolygonSignedDistanceFS.glsl +100 -0
  141. package/Source/Shaders/PolygonSignedDistanceFS.js +101 -0
  142. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  143. package/index.d.ts +227 -1
  144. package/index.js +34 -26
  145. package/package.json +1 -1
  146. package/Build/Workers/chunk-2KACWKS4.js +0 -501
  147. package/Build/Workers/chunk-2XPLH3JY.js +0 -2977
  148. package/Build/Workers/chunk-X6XOMPWL.js +0 -73
@@ -0,0 +1,968 @@
1
+ import Cartesian2 from "../Core/Cartesian2.js";
2
+ import CesiumMath from "../Core/Math.js";
3
+ import Check from "../Core/Check.js";
4
+ import defaultValue from "../Core/defaultValue.js";
5
+ import defined from "../Core/defined.js";
6
+ import destroyObject from "../Core/destroyObject.js";
7
+ import DeveloperError from "../Core/DeveloperError.js";
8
+ import Event from "../Core/Event.js";
9
+ import Intersect from "../Core/Intersect.js";
10
+ import PixelFormat from "../Core/PixelFormat.js";
11
+ import Rectangle from "../Core/Rectangle.js";
12
+ import ContextLimits from "../Renderer/ContextLimits.js";
13
+ import PixelDatatype from "../Renderer/PixelDatatype.js";
14
+ import RuntimeError from "../Core/RuntimeError.js";
15
+ import Sampler from "../Renderer/Sampler.js";
16
+ import Texture from "../Renderer/Texture.js";
17
+ import TextureMagnificationFilter from "../Renderer/TextureMagnificationFilter.js";
18
+ import TextureMinificationFilter from "../Renderer/TextureMinificationFilter.js";
19
+ import TextureWrap from "../Renderer/TextureWrap.js";
20
+ import ClippingPolygon from "./ClippingPolygon.js";
21
+ import ComputeCommand from "../Renderer/ComputeCommand.js";
22
+ import PolygonSignedDistanceFS from "../Shaders/PolygonSignedDistanceFS.js";
23
+
24
+ /**
25
+ * Specifies a set of clipping polygons. Clipping polygons selectively disable rendering in a region
26
+ * inside or outside the specified list of {@link ClippingPolygon} objects for a single glTF model, 3D Tileset, or the globe.
27
+ *
28
+ * Clipping Polygons are only supported in WebGL 2 contexts.
29
+ *
30
+ * @alias ClippingPolygonCollection
31
+ * @constructor
32
+ *
33
+ * @param {object} [options] Object with the following properties:
34
+ * @param {ClippingPolygon[]} [options.polygons=[]] An array of {@link ClippingPolygon} objects used to selectively disable rendering on the inside of each polygon.
35
+ * @param {boolean} [options.enabled=true] Determines whether the clipping polygons are active.
36
+ * @param {boolean} [options.inverse=false] If true, a region will be clipped if it is outside of every polygon in the collection. Otherwise, a region will only be clipped if it is on the inside of any polygon.
37
+ *
38
+ * @example
39
+ * const positions = Cesium.Cartesian3.fromRadiansArray([
40
+ * -1.3194369277314022,
41
+ * 0.6988062530900625,
42
+ * -1.31941,
43
+ * 0.69879,
44
+ * -1.3193955980204217,
45
+ * 0.6988091578771254,
46
+ * -1.3193931220959367,
47
+ * 0.698743632490865,
48
+ * -1.3194358224045408,
49
+ * 0.6987471965556998,
50
+ * ]);
51
+ *
52
+ * const polygon = new Cesium.ClippingPolygon({
53
+ * positions: positions
54
+ * });
55
+ *
56
+ * const polygons = new Cesium.ClippingPolygonCollection({
57
+ * polygons: [ polygon ]
58
+ * });
59
+ */
60
+ function ClippingPolygonCollection(options) {
61
+ options = defaultValue(options, defaultValue.EMPTY_OBJECT);
62
+
63
+ this._polygons = [];
64
+ this._totalPositions = 0;
65
+
66
+ /**
67
+ * If true, clipping will be enabled.
68
+ *
69
+ * @memberof ClippingPolygonCollection.prototype
70
+ * @type {boolean}
71
+ * @default true
72
+ */
73
+ this.enabled = defaultValue(options.enabled, true);
74
+
75
+ /**
76
+ * If true, a region will be clipped if it is outside of every polygon in the
77
+ * collection. Otherwise, a region will only be clipped if it is
78
+ * inside of any polygon.
79
+ *
80
+ * @memberof ClippingPolygonCollection.prototype
81
+ * @type {boolean}
82
+ * @default false
83
+ */
84
+ this.inverse = defaultValue(options.inverse, false);
85
+
86
+ /**
87
+ * An event triggered when a new clipping polygon is added to the collection. Event handlers
88
+ * are passed the new polygon and the index at which it was added.
89
+ * @type {Event}
90
+ * @default Event()
91
+ */
92
+ this.polygonAdded = new Event();
93
+
94
+ /**
95
+ * An event triggered when a new clipping polygon is removed from the collection. Event handlers
96
+ * are passed the new polygon and the index from which it was removed.
97
+ * @type {Event}
98
+ * @default Event()
99
+ */
100
+ this.polygonRemoved = new Event();
101
+
102
+ // If this ClippingPolygonCollection has an owner, only its owner should update or destroy it.
103
+ // This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPolygonCollection.
104
+ this._owner = undefined;
105
+
106
+ this._float32View = undefined;
107
+ this._extentsFloat32View = undefined;
108
+ this._extentsCount = 0;
109
+
110
+ this._polygonsTexture = undefined;
111
+ this._extentsTexture = undefined;
112
+ this._signedDistanceTexture = undefined;
113
+
114
+ this._signedDistanceComputeCommand = undefined;
115
+
116
+ // Add each ClippingPolygon object.
117
+ const polygons = options.polygons;
118
+ if (defined(polygons)) {
119
+ const polygonsLength = polygons.length;
120
+ for (let i = 0; i < polygonsLength; ++i) {
121
+ this._polygons.push(polygons[i]);
122
+ }
123
+ }
124
+ }
125
+
126
+ Object.defineProperties(ClippingPolygonCollection.prototype, {
127
+ /**
128
+ * Returns the number of polygons in this collection. This is commonly used with
129
+ * {@link ClippingPolygonCollection#get} to iterate over all the polygons
130
+ * in the collection.
131
+ *
132
+ * @memberof ClippingPolygonCollection.prototype
133
+ * @type {number}
134
+ * @readonly
135
+ */
136
+ length: {
137
+ get: function () {
138
+ return this._polygons.length;
139
+ },
140
+ },
141
+
142
+ /**
143
+ * Returns the total number of positions in all polygons in the collection.
144
+ *
145
+ * @memberof ClippingPolygonCollection.prototype
146
+ * @type {number}
147
+ * @readonly
148
+ * @private
149
+ */
150
+ totalPositions: {
151
+ get: function () {
152
+ return this._totalPositions;
153
+ },
154
+ },
155
+
156
+ /**
157
+ * Returns a texture containing the packed computed spherical extents for each polygon
158
+ *
159
+ * @memberof ClippingPolygonCollection.prototype
160
+ * @type {Texture}
161
+ * @readonly
162
+ * @private
163
+ */
164
+ extentsTexture: {
165
+ get: function () {
166
+ return this._extentsTexture;
167
+ },
168
+ },
169
+
170
+ /**
171
+ * Returns the number of packed extents, which can be fewer than the number of polygons.
172
+ *
173
+ * @memberof ClippingPolygonCollection.prototype
174
+ * @type {number}
175
+ * @readonly
176
+ * @private
177
+ */
178
+ extentsCount: {
179
+ get: function () {
180
+ return this._extentsCount;
181
+ },
182
+ },
183
+
184
+ /**
185
+ * Returns the number of pixels needed in the texture containing the packed computed spherical extents for each polygon.
186
+ *
187
+ * @memberof ClippingPolygonCollection.prototype
188
+ * @type {number}
189
+ * @readonly
190
+ * @private
191
+ */
192
+ pixelsNeededForExtents: {
193
+ get: function () {
194
+ return this.length; // With an RGBA texture, each pixel contains min/max latitude and longitude.
195
+ },
196
+ },
197
+
198
+ /**
199
+ * Returns the number of pixels needed in the texture containing the packed polygon positions.
200
+ *
201
+ * @memberof ClippingPolygonCollection.prototype
202
+ * @type {number}
203
+ * @readonly
204
+ * @private
205
+ */
206
+ pixelsNeededForPolygonPositions: {
207
+ get: function () {
208
+ // In an RG FLOAT texture, each polygon position is 2 floats packed to a RG.
209
+ // Each polygon is the number of positions of that polygon, followed by the list of positions
210
+ return this.totalPositions + this.length;
211
+ },
212
+ },
213
+
214
+ /**
215
+ * Returns a texture containing the computed signed distance of each polygon.
216
+ *
217
+ * @memberof ClippingPolygonCollection.prototype
218
+ * @type {Texture}
219
+ * @readonly
220
+ * @private
221
+ */
222
+ clippingTexture: {
223
+ get: function () {
224
+ return this._signedDistanceTexture;
225
+ },
226
+ },
227
+
228
+ /**
229
+ * A reference to the ClippingPolygonCollection's owner, if any.
230
+ *
231
+ * @memberof ClippingPolygonCollection.prototype
232
+ * @readonly
233
+ * @private
234
+ */
235
+ owner: {
236
+ get: function () {
237
+ return this._owner;
238
+ },
239
+ },
240
+
241
+ /**
242
+ * Returns a number encapsulating the state for this ClippingPolygonCollection.
243
+ *
244
+ * Clipping mode is encoded in the sign of the number, which is just the total position count.
245
+ * If this value changes, then shader regeneration is necessary.
246
+ *
247
+ * @memberof ClippingPolygonCollection.prototype
248
+ * @returns {number} A Number that describes the ClippingPolygonCollection's state.
249
+ * @readonly
250
+ * @private
251
+ */
252
+ clippingPolygonsState: {
253
+ get: function () {
254
+ return this.inverse ? -this.extentsCount : this.extentsCount;
255
+ },
256
+ },
257
+ });
258
+
259
+ /**
260
+ * Adds the specified {@link ClippingPolygon} to the collection to be used to selectively disable rendering
261
+ * on the inside of each polygon. Use {@link ClippingPolygonCollection#unionClippingRegions} to modify
262
+ * how modify the clipping behavior of multiple polygons.
263
+ *
264
+ * @param {ClippingPolygon} polygon The ClippingPolygon to add to the collection.
265
+ * @returns {ClippingPolygon} The added ClippingPolygon.
266
+ *
267
+ * @example
268
+ * const polygons = new Cesium.ClippingPolygonCollection();
269
+ *
270
+ * const positions = Cesium.Cartesian3.fromRadiansArray([
271
+ * -1.3194369277314022,
272
+ * 0.6988062530900625,
273
+ * -1.31941,
274
+ * 0.69879,
275
+ * -1.3193955980204217,
276
+ * 0.6988091578771254,
277
+ * -1.3193931220959367,
278
+ * 0.698743632490865,
279
+ * -1.3194358224045408,
280
+ * 0.6987471965556998,
281
+ * ]);
282
+ *
283
+ * polygons.add(new Cesium.ClippingPolygon({
284
+ * positions: positions
285
+ * }));
286
+ *
287
+ *
288
+ *
289
+ * @see ClippingPolygonCollection#remove
290
+ * @see ClippingPolygonCollection#removeAll
291
+ */
292
+ ClippingPolygonCollection.prototype.add = function (polygon) {
293
+ //>>includeStart('debug', pragmas.debug);
294
+ Check.typeOf.object("polygon", polygon);
295
+ //>>includeEnd('debug');
296
+
297
+ const newPlaneIndex = this._polygons.length;
298
+ this._polygons.push(polygon);
299
+ this.polygonAdded.raiseEvent(polygon, newPlaneIndex);
300
+ return polygon;
301
+ };
302
+
303
+ /**
304
+ * Returns the clipping polygon in the collection at the specified index. Indices are zero-based
305
+ * and increase as polygons are added. Removing a polygon polygon all polygons after
306
+ * it to the left, changing their indices. This function is commonly used with
307
+ * {@link ClippingPolygonCollection#length} to iterate over all the polygons
308
+ * in the collection.
309
+ *
310
+ * @param {number} index The zero-based index of the polygon.
311
+ * @returns {ClippingPolygon} The ClippingPolygon at the specified index.
312
+ *
313
+ * @see ClippingPolygonCollection#length
314
+ */
315
+ ClippingPolygonCollection.prototype.get = function (index) {
316
+ //>>includeStart('debug', pragmas.debug);
317
+ Check.typeOf.number("index", index);
318
+ //>>includeEnd('debug');
319
+
320
+ return this._polygons[index];
321
+ };
322
+
323
+ /**
324
+ * Checks whether this collection contains a ClippingPolygon equal to the given ClippingPolygon.
325
+ *
326
+ * @param {ClippingPolygon} polygon The ClippingPolygon to check for.
327
+ * @returns {boolean} true if this collection contains the ClippingPolygon, false otherwise.
328
+ *
329
+ * @see ClippingPolygonCollection#get
330
+ */
331
+ ClippingPolygonCollection.prototype.contains = function (polygon) {
332
+ //>>includeStart('debug', pragmas.debug);
333
+ Check.typeOf.object("polygon", polygon);
334
+ //>>includeEnd('debug');
335
+
336
+ return this._polygons.some((p) => ClippingPolygon.equals(p, polygon));
337
+ };
338
+
339
+ /**
340
+ * Removes the first occurrence of the given ClippingPolygon from the collection.
341
+ *
342
+ * @param {ClippingPolygon} polygon
343
+ * @returns {boolean} <code>true</code> if the polygon was removed; <code>false</code> if the polygon was not found in the collection.
344
+ *
345
+ * @see ClippingPolygonCollection#add
346
+ * @see ClippingPolygonCollection#contains
347
+ * @see ClippingPolygonCollection#removeAll
348
+ */
349
+ ClippingPolygonCollection.prototype.remove = function (polygon) {
350
+ //>>includeStart('debug', pragmas.debug);
351
+ Check.typeOf.object("polygon", polygon);
352
+ //>>includeEnd('debug');
353
+
354
+ const polygons = this._polygons;
355
+ const index = polygons.findIndex((p) => ClippingPolygon.equals(p, polygon));
356
+
357
+ if (index === -1) {
358
+ return false;
359
+ }
360
+
361
+ polygons.splice(index, 1);
362
+
363
+ this.polygonRemoved.raiseEvent(polygon, index);
364
+ return true;
365
+ };
366
+
367
+ const scratchRectangle = new Rectangle();
368
+
369
+ // Map the polygons to a list of extents-- Overlapping extents will be merged
370
+ // into a single encompassing extent
371
+ function getExtents(polygons) {
372
+ const extentsList = [];
373
+ const polygonIndicesList = [];
374
+
375
+ const length = polygons.length;
376
+ for (let polygonIndex = 0; polygonIndex < length; ++polygonIndex) {
377
+ const polygon = polygons[polygonIndex];
378
+ const extents = polygon.computeSphericalExtents();
379
+
380
+ let height = Math.max(extents.height * 2.5, 0.001);
381
+ let width = Math.max(extents.width * 2.5, 0.001);
382
+
383
+ // Pad extents to avoid floating point error when fragment culling at edges.
384
+ let paddedExtents = Rectangle.clone(extents);
385
+ paddedExtents.south -= height;
386
+ paddedExtents.west -= width;
387
+ paddedExtents.north += height;
388
+ paddedExtents.east += width;
389
+
390
+ paddedExtents.south = Math.max(paddedExtents.south, -Math.PI);
391
+ paddedExtents.west = Math.max(paddedExtents.west, -Math.PI);
392
+ paddedExtents.north = Math.min(paddedExtents.north, Math.PI);
393
+ paddedExtents.east = Math.min(paddedExtents.east, Math.PI);
394
+
395
+ const polygonIndices = [polygonIndex];
396
+ for (let i = 0; i < extentsList.length; ++i) {
397
+ const e = extentsList[i];
398
+ if (
399
+ defined(e) &&
400
+ defined(Rectangle.simpleIntersection(e, paddedExtents)) &&
401
+ !Rectangle.equals(e, paddedExtents)
402
+ ) {
403
+ const intersectingPolygons = polygonIndicesList[i];
404
+ polygonIndices.push(...intersectingPolygons);
405
+ intersectingPolygons.reduce(
406
+ (extents, p) =>
407
+ Rectangle.union(
408
+ polygons[p].computeSphericalExtents(scratchRectangle),
409
+ extents,
410
+ extents
411
+ ),
412
+ extents
413
+ );
414
+
415
+ extentsList[i] = undefined;
416
+ polygonIndicesList[i] = undefined;
417
+
418
+ height = Math.max(extents.height * 2.5, 0.001);
419
+ width = Math.max(extents.width * 2.5, 0.001);
420
+
421
+ paddedExtents = Rectangle.clone(extents, paddedExtents);
422
+ paddedExtents.south -= height;
423
+ paddedExtents.west -= width;
424
+ paddedExtents.north += height;
425
+ paddedExtents.east += width;
426
+
427
+ paddedExtents.south = Math.max(paddedExtents.south, -Math.PI);
428
+ paddedExtents.west = Math.max(paddedExtents.west, -Math.PI);
429
+ paddedExtents.north = Math.min(paddedExtents.north, Math.PI);
430
+ paddedExtents.east = Math.min(paddedExtents.east, Math.PI);
431
+
432
+ // Reiterate through the extents list until there are no more intersections
433
+ i = -1;
434
+ }
435
+ }
436
+
437
+ extentsList.push(paddedExtents);
438
+ polygonIndicesList.push(polygonIndices);
439
+ }
440
+
441
+ const extentsIndexByPolygon = new Map();
442
+ polygonIndicesList
443
+ .filter(defined)
444
+ .forEach((polygonIndices, e) =>
445
+ polygonIndices.forEach((p) => extentsIndexByPolygon.set(p, e))
446
+ );
447
+
448
+ return {
449
+ extentsList: extentsList.filter(defined),
450
+ extentsIndexByPolygon: extentsIndexByPolygon,
451
+ };
452
+ }
453
+
454
+ /**
455
+ * Removes all polygons from the collection.
456
+ *
457
+ * @see ClippingPolygonCollection#add
458
+ * @see ClippingPolygonCollection#remove
459
+ */
460
+ ClippingPolygonCollection.prototype.removeAll = function () {
461
+ // Dereference this ClippingPolygonCollection from all ClippingPolygons
462
+ const polygons = this._polygons;
463
+ const polygonsCount = polygons.length;
464
+ for (let i = 0; i < polygonsCount; ++i) {
465
+ const polygon = polygons[i];
466
+ this.polygonRemoved.raiseEvent(polygon, i);
467
+ }
468
+ this._polygons = [];
469
+ };
470
+
471
+ function packPolygonsAsFloats(clippingPolygonCollection) {
472
+ const polygonsFloat32View = clippingPolygonCollection._float32View;
473
+ const extentsFloat32View = clippingPolygonCollection._extentsFloat32View;
474
+ const polygons = clippingPolygonCollection._polygons;
475
+
476
+ const { extentsList, extentsIndexByPolygon } = getExtents(polygons);
477
+
478
+ let floatIndex = 0;
479
+ for (const [polygonIndex, polygon] of polygons.entries()) {
480
+ // Pack the length of the polygon into the polygon texture array buffer
481
+ const length = polygon.length;
482
+ polygonsFloat32View[floatIndex++] = length;
483
+ polygonsFloat32View[floatIndex++] = extentsIndexByPolygon.get(polygonIndex);
484
+
485
+ // Pack the polygon positions into the polygon texture array buffer
486
+ for (let i = 0; i < length; ++i) {
487
+ const spherePoint = polygon.positions[i];
488
+
489
+ // Project into plane with vertical for latitude
490
+ const magXY = Math.hypot(spherePoint.x, spherePoint.y);
491
+
492
+ // Use fastApproximateAtan2 for alignment with shader
493
+ const latitudeApproximation = CesiumMath.fastApproximateAtan2(
494
+ magXY,
495
+ spherePoint.z
496
+ );
497
+ const longitudeApproximation = CesiumMath.fastApproximateAtan2(
498
+ spherePoint.x,
499
+ spherePoint.y
500
+ );
501
+
502
+ polygonsFloat32View[floatIndex++] = latitudeApproximation;
503
+ polygonsFloat32View[floatIndex++] = longitudeApproximation;
504
+ }
505
+ }
506
+
507
+ // Pack extents
508
+ let extentsFloatIndex = 0;
509
+ for (const extents of extentsList) {
510
+ const longitudeRangeInverse = 1.0 / (extents.east - extents.west);
511
+ const latitudeRangeInverse = 1.0 / (extents.north - extents.south);
512
+
513
+ extentsFloat32View[extentsFloatIndex++] = extents.south;
514
+ extentsFloat32View[extentsFloatIndex++] = extents.west;
515
+ extentsFloat32View[extentsFloatIndex++] = latitudeRangeInverse;
516
+ extentsFloat32View[extentsFloatIndex++] = longitudeRangeInverse;
517
+ }
518
+
519
+ clippingPolygonCollection._extentsCount = extentsList.length;
520
+ }
521
+
522
+ const textureResolutionScratch = new Cartesian2();
523
+ /**
524
+ * Called when {@link Viewer} or {@link CesiumWidget} render the scene to
525
+ * build the resources for clipping polygons.
526
+ * <p>
527
+ * Do not call this function directly.
528
+ * </p>
529
+ * @private
530
+ * @throws {RuntimeError} ClippingPolygonCollections are only supported for WebGL 2
531
+ */
532
+ ClippingPolygonCollection.prototype.update = function (frameState) {
533
+ const context = frameState.context;
534
+
535
+ if (!ClippingPolygonCollection.isSupported(frameState)) {
536
+ throw new RuntimeError(
537
+ "ClippingPolygonCollections are only supported for WebGL 2."
538
+ );
539
+ }
540
+
541
+ // It'd be expensive to validate any individual position has changed. Instead verify if the list of polygon positions has had elements added or removed, which should be good enough for most cases.
542
+ const totalPositions = this._polygons.reduce(
543
+ (totalPositions, polygon) => totalPositions + polygon.length,
544
+ 0
545
+ );
546
+
547
+ if (totalPositions === this.totalPositions) {
548
+ return;
549
+ }
550
+
551
+ this._totalPositions = totalPositions;
552
+
553
+ // If there are no clipping polygons, there's nothing to update.
554
+ if (this.length === 0) {
555
+ return;
556
+ }
557
+
558
+ if (defined(this._signedDistanceComputeCommand)) {
559
+ this._signedDistanceComputeCommand.canceled = true;
560
+ this._signedDistanceComputeCommand = undefined;
561
+ }
562
+
563
+ let polygonsTexture = this._polygonsTexture;
564
+ let extentsTexture = this._extentsTexture;
565
+ let signedDistanceTexture = this._signedDistanceTexture;
566
+ if (defined(polygonsTexture)) {
567
+ const currentPixelCount = polygonsTexture.width * polygonsTexture.height;
568
+ // Recreate the texture to double current requirement if it isn't big enough or is 4 times larger than it needs to be.
569
+ // Optimization note: this isn't exactly the classic resizeable array algorithm
570
+ // * not necessarily checking for resize after each add/remove operation
571
+ // * random-access deletes instead of just pops
572
+ // * alloc ops likely more expensive than demonstrable via big-O analysis
573
+ if (
574
+ currentPixelCount < this.pixelsNeededForPolygonPositions ||
575
+ this.pixelsNeededForPolygonPositions < 0.25 * currentPixelCount
576
+ ) {
577
+ polygonsTexture.destroy();
578
+ polygonsTexture = undefined;
579
+ this._polygonsTexture = undefined;
580
+ }
581
+ }
582
+
583
+ if (!defined(polygonsTexture)) {
584
+ const requiredResolution = ClippingPolygonCollection.getTextureResolution(
585
+ polygonsTexture,
586
+ this.pixelsNeededForPolygonPositions,
587
+ textureResolutionScratch
588
+ );
589
+
590
+ polygonsTexture = new Texture({
591
+ context: context,
592
+ width: requiredResolution.x,
593
+ height: requiredResolution.y,
594
+ pixelFormat: PixelFormat.RG,
595
+ pixelDatatype: PixelDatatype.FLOAT,
596
+ sampler: Sampler.NEAREST,
597
+ flipY: false,
598
+ });
599
+ this._float32View = new Float32Array(
600
+ requiredResolution.x * requiredResolution.y * 2
601
+ );
602
+ this._polygonsTexture = polygonsTexture;
603
+ }
604
+
605
+ if (defined(extentsTexture)) {
606
+ const currentPixelCount = extentsTexture.width * extentsTexture.height;
607
+ // Recreate the texture to double current requirement if it isn't big enough or is 4 times larger than it needs to be.
608
+ // Optimization note: this isn't exactly the classic resizeable array algorithm
609
+ // * not necessarily checking for resize after each add/remove operation
610
+ // * random-access deletes instead of just pops
611
+ // * alloc ops likely more expensive than demonstrable via big-O analysis
612
+ if (
613
+ currentPixelCount < this.pixelsNeededForExtents ||
614
+ this.pixelsNeededForExtents < 0.25 * currentPixelCount
615
+ ) {
616
+ extentsTexture.destroy();
617
+ extentsTexture = undefined;
618
+ this._extentsTexture = undefined;
619
+ }
620
+ }
621
+
622
+ if (!defined(extentsTexture)) {
623
+ const requiredResolution = ClippingPolygonCollection.getTextureResolution(
624
+ extentsTexture,
625
+ this.pixelsNeededForExtents,
626
+ textureResolutionScratch
627
+ );
628
+
629
+ extentsTexture = new Texture({
630
+ context: context,
631
+ width: requiredResolution.x,
632
+ height: requiredResolution.y,
633
+ pixelFormat: PixelFormat.RGBA,
634
+ pixelDatatype: PixelDatatype.FLOAT,
635
+ sampler: Sampler.NEAREST,
636
+ flipY: false,
637
+ });
638
+ this._extentsFloat32View = new Float32Array(
639
+ requiredResolution.x * requiredResolution.y * 4
640
+ );
641
+
642
+ this._extentsTexture = extentsTexture;
643
+ }
644
+
645
+ packPolygonsAsFloats(this);
646
+
647
+ extentsTexture.copyFrom({
648
+ source: {
649
+ width: extentsTexture.width,
650
+ height: extentsTexture.height,
651
+ arrayBufferView: this._extentsFloat32View,
652
+ },
653
+ });
654
+
655
+ polygonsTexture.copyFrom({
656
+ source: {
657
+ width: polygonsTexture.width,
658
+ height: polygonsTexture.height,
659
+ arrayBufferView: this._float32View,
660
+ },
661
+ });
662
+
663
+ if (!defined(signedDistanceTexture)) {
664
+ const textureDimensions = ClippingPolygonCollection.getClippingDistanceTextureResolution(
665
+ this,
666
+ textureResolutionScratch
667
+ );
668
+ signedDistanceTexture = new Texture({
669
+ context: context,
670
+ width: textureDimensions.x,
671
+ height: textureDimensions.y,
672
+ pixelFormat: context.webgl2 ? PixelFormat.RED : PixelFormat.LUMINANCE,
673
+ pixelDatatype: PixelDatatype.FLOAT,
674
+ sampler: new Sampler({
675
+ wrapS: TextureWrap.CLAMP_TO_EDGE,
676
+ wrapT: TextureWrap.CLAMP_TO_EDGE,
677
+ minificationFilter: TextureMinificationFilter.LINEAR,
678
+ magnificationFilter: TextureMagnificationFilter.LINEAR,
679
+ }),
680
+ flipY: false,
681
+ });
682
+
683
+ this._signedDistanceTexture = signedDistanceTexture;
684
+ }
685
+
686
+ this._signedDistanceComputeCommand = createSignedDistanceTextureCommand(this);
687
+ };
688
+
689
+ /**
690
+ * Called when {@link Viewer} or {@link CesiumWidget} render the scene to
691
+ * build the resources for clipping polygons.
692
+ * <p>
693
+ * Do not call this function directly.
694
+ * </p>
695
+ * @private
696
+ * @param {FrameState} frameState
697
+ */
698
+ ClippingPolygonCollection.prototype.queueCommands = function (frameState) {
699
+ if (defined(this._signedDistanceComputeCommand)) {
700
+ frameState.commandList.push(this._signedDistanceComputeCommand);
701
+ }
702
+ };
703
+
704
+ function createSignedDistanceTextureCommand(collection) {
705
+ const polygonTexture = collection._polygonsTexture;
706
+ const extentsTexture = collection._extentsTexture;
707
+
708
+ return new ComputeCommand({
709
+ fragmentShaderSource: PolygonSignedDistanceFS,
710
+ outputTexture: collection._signedDistanceTexture,
711
+ uniformMap: {
712
+ u_polygonsLength: function () {
713
+ return collection.length;
714
+ },
715
+ u_extentsLength: function () {
716
+ return collection.extentsCount;
717
+ },
718
+ u_extentsTexture: function () {
719
+ return extentsTexture;
720
+ },
721
+ u_polygonTexture: function () {
722
+ return polygonTexture;
723
+ },
724
+ },
725
+ persists: false,
726
+ owner: collection,
727
+ postExecute: () => {
728
+ collection._signedDistanceComputeCommand = undefined;
729
+ },
730
+ });
731
+ }
732
+
733
+ const scratchRectangleTile = new Rectangle();
734
+ const scratchRectangleIntersection = new Rectangle();
735
+ /**
736
+ * Determines the type intersection with the polygons of this ClippingPolygonCollection instance and the specified {@link TileBoundingVolume}.
737
+ * @private
738
+ *
739
+ * @param {object} tileBoundingVolume The volume to determine the intersection with the polygons.
740
+ * @param {Ellipsoid} [ellipsoid=WGS84] The ellipsoid on which the bounding volumes are defined.
741
+ * @returns {Intersect} The intersection type: {@link Intersect.OUTSIDE} if the entire volume is not clipped, {@link Intersect.INSIDE}
742
+ * if the entire volume should be clipped, and {@link Intersect.INTERSECTING} if the volume intersects the polygons and will partially clipped.
743
+ */
744
+ ClippingPolygonCollection.prototype.computeIntersectionWithBoundingVolume = function (
745
+ tileBoundingVolume,
746
+ ellipsoid
747
+ ) {
748
+ const polygons = this._polygons;
749
+ const length = polygons.length;
750
+
751
+ let intersection = Intersect.OUTSIDE;
752
+ if (this.inverse) {
753
+ intersection = Intersect.INSIDE;
754
+ }
755
+
756
+ for (let i = 0; i < length; ++i) {
757
+ const polygon = polygons[i];
758
+
759
+ const polygonBoundingRectangle = polygon.computeRectangle();
760
+ let tileBoundingRectangle = tileBoundingVolume.rectangle;
761
+ if (
762
+ !defined(tileBoundingRectangle) &&
763
+ defined(tileBoundingVolume.boundingVolume?.computeCorners)
764
+ ) {
765
+ const points = tileBoundingVolume.boundingVolume.computeCorners();
766
+ tileBoundingRectangle = Rectangle.fromCartesianArray(
767
+ points,
768
+ ellipsoid,
769
+ scratchRectangleTile
770
+ );
771
+ }
772
+
773
+ if (!defined(tileBoundingRectangle)) {
774
+ tileBoundingRectangle = Rectangle.fromBoundingSphere(
775
+ tileBoundingVolume.boundingSphere,
776
+ ellipsoid,
777
+ scratchRectangleTile
778
+ );
779
+ }
780
+
781
+ const result = Rectangle.simpleIntersection(
782
+ tileBoundingRectangle,
783
+ polygonBoundingRectangle,
784
+ scratchRectangleIntersection
785
+ );
786
+
787
+ if (defined(result)) {
788
+ intersection = Intersect.INTERSECTING;
789
+ }
790
+ }
791
+
792
+ return intersection;
793
+ };
794
+
795
+ /**
796
+ * Sets the owner for the input ClippingPolygonCollection if there wasn't another owner.
797
+ * Destroys the owner's previous ClippingPolygonCollection if setting is successful.
798
+ *
799
+ * @param {ClippingPolygonCollection} [clippingPolygonsCollection] A ClippingPolygonCollection (or undefined) being attached to an object
800
+ * @param {object} owner An Object that should receive the new ClippingPolygonCollection
801
+ * @param {string} key The Key for the Object to reference the ClippingPolygonCollection
802
+ * @private
803
+ */
804
+ ClippingPolygonCollection.setOwner = function (
805
+ clippingPolygonsCollection,
806
+ owner,
807
+ key
808
+ ) {
809
+ // Don't destroy the ClippingPolygonCollection if it is already owned by newOwner
810
+ if (clippingPolygonsCollection === owner[key]) {
811
+ return;
812
+ }
813
+ // Destroy the existing ClippingPolygonCollection, if any
814
+ owner[key] = owner[key] && owner[key].destroy();
815
+ if (defined(clippingPolygonsCollection)) {
816
+ //>>includeStart('debug', pragmas.debug);
817
+ if (defined(clippingPolygonsCollection._owner)) {
818
+ throw new DeveloperError(
819
+ "ClippingPolygonCollection should only be assigned to one object"
820
+ );
821
+ }
822
+ //>>includeEnd('debug');
823
+ clippingPolygonsCollection._owner = owner;
824
+ owner[key] = clippingPolygonsCollection;
825
+ }
826
+ };
827
+
828
+ /**
829
+ * Function for checking if the context will allow clipping polygons, which require floating point textures.
830
+ *
831
+ * @param {Scene|object} scene The scene that will contain clipped objects and clipping textures.
832
+ * @returns {boolean} <code>true</code> if the context supports clipping polygons.
833
+ */
834
+ ClippingPolygonCollection.isSupported = function (scene) {
835
+ return scene?.context.webgl2;
836
+ };
837
+
838
+ /**
839
+ * Function for getting packed texture resolution.
840
+ * If the ClippingPolygonCollection hasn't been updated, returns the resolution that will be
841
+ * allocated based on the provided needed pixels.
842
+ *
843
+ * @param {Texture} texture The texture to be packed.
844
+ * @param {number} pixelsNeeded The number of pixels needed based on the current polygon count.
845
+ * @param {Cartesian2} result A Cartesian2 for the result.
846
+ * @returns {Cartesian2} The required resolution.
847
+ * @private
848
+ */
849
+ ClippingPolygonCollection.getTextureResolution = function (
850
+ texture,
851
+ pixelsNeeded,
852
+ result
853
+ ) {
854
+ if (defined(texture)) {
855
+ result.x = texture.width;
856
+ result.y = texture.height;
857
+ return result;
858
+ }
859
+
860
+ const maxSize = ContextLimits.maximumTextureSize;
861
+ result.x = Math.min(pixelsNeeded, maxSize);
862
+ result.y = Math.ceil(pixelsNeeded / result.x);
863
+
864
+ // Allocate twice as much space as needed to avoid frequent texture reallocation.
865
+ result.y *= 2;
866
+
867
+ return result;
868
+ };
869
+
870
+ /**
871
+ * Function for getting the clipping collection's signed distance texture resolution.
872
+ * If the ClippingPolygonCollection hasn't been updated, returns the resolution that will be
873
+ * allocated based on the current settings
874
+ *
875
+ * @param {ClippingPolygonCollection} clippingPolygonCollection The clipping polygon collection
876
+ * @param {Cartesian2} result A Cartesian2 for the result.
877
+ * @returns {Cartesian2} The required resolution.
878
+ * @private
879
+ */
880
+ ClippingPolygonCollection.getClippingDistanceTextureResolution = function (
881
+ clippingPolygonCollection,
882
+ result
883
+ ) {
884
+ const texture = clippingPolygonCollection.signedDistanceTexture;
885
+ if (defined(texture)) {
886
+ result.x = texture.width;
887
+ result.y = texture.height;
888
+ return result;
889
+ }
890
+
891
+ result.x = Math.min(ContextLimits.maximumTextureSize, 4096);
892
+ result.y = Math.min(ContextLimits.maximumTextureSize, 4096);
893
+
894
+ return result;
895
+ };
896
+
897
+ /**
898
+ * Function for getting the clipping collection's extents texture resolution.
899
+ * If the ClippingPolygonCollection hasn't been updated, returns the resolution that will be
900
+ * allocated based on the current polygon count.
901
+ *
902
+ * @param {ClippingPolygonCollection} clippingPolygonCollection The clipping polygon collection
903
+ * @param {Cartesian2} result A Cartesian2 for the result.
904
+ * @returns {Cartesian2} The required resolution.
905
+ * @private
906
+ */
907
+ ClippingPolygonCollection.getClippingExtentsTextureResolution = function (
908
+ clippingPolygonCollection,
909
+ result
910
+ ) {
911
+ const texture = clippingPolygonCollection.extentsTexture;
912
+ if (defined(texture)) {
913
+ result.x = texture.width;
914
+ result.y = texture.height;
915
+ return result;
916
+ }
917
+
918
+ return ClippingPolygonCollection.getTextureResolution(
919
+ texture,
920
+ clippingPolygonCollection.pixelsNeededForExtents,
921
+ result
922
+ );
923
+ };
924
+
925
+ /**
926
+ * Returns true if this object was destroyed; otherwise, false.
927
+ * <br /><br />
928
+ * If this object was destroyed, it should not be used; calling any function other than
929
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
930
+ *
931
+ * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
932
+ *
933
+ * @see ClippingPolygonCollection#destroy
934
+ */
935
+ ClippingPolygonCollection.prototype.isDestroyed = function () {
936
+ return false;
937
+ };
938
+
939
+ /**
940
+ * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
941
+ * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
942
+ * <br /><br />
943
+ * Once an object is destroyed, it should not be used; calling any function other than
944
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
945
+ * assign the return value (<code>undefined</code>) to the object as done in the example.
946
+ *
947
+ * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
948
+ *
949
+ *
950
+ * @example
951
+ * clippingPolygons = clippingPolygons && clippingPolygons.destroy();
952
+ *
953
+ * @see ClippingPolygonCollection#isDestroyed
954
+ */
955
+ ClippingPolygonCollection.prototype.destroy = function () {
956
+ if (defined(this._signedDistanceComputeCommand)) {
957
+ this._signedDistanceComputeCommand.canceled = true;
958
+ }
959
+
960
+ this._polygonsTexture =
961
+ this._polygonsTexture && this._polygonsTexture.destroy();
962
+ this._extentsTexture = this._extentsTexture && this._extentsTexture.destroy();
963
+ this._signedDistanceTexture =
964
+ this._signedDistanceTexture && this._signedDistanceTexture.destroy();
965
+ return destroyObject(this);
966
+ };
967
+
968
+ export default ClippingPolygonCollection;