@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
@@ -449,6 +449,20 @@ Object.defineProperties(Globe.prototype, {
449
449
  this._surface.tileProvider.clippingPlanes = value;
450
450
  },
451
451
  },
452
+ /**
453
+ * A property specifying a {@link ClippingPolygonCollection} used to selectively disable rendering inside or outside a list of polygons.
454
+ *
455
+ * @memberof Globe.prototype
456
+ * @type {ClippingPolygonCollection}
457
+ */
458
+ clippingPolygons: {
459
+ get: function () {
460
+ return this._surface.tileProvider.clippingPolygons;
461
+ },
462
+ set: function (value) {
463
+ this._surface.tileProvider.clippingPolygons = value;
464
+ },
465
+ },
452
466
  /**
453
467
  * A property specifying a {@link Rectangle} used to limit globe rendering to a cartographic area.
454
468
  * Defaults to the maximum extent of cartographic coordinates.
@@ -10,13 +10,15 @@ function GlobeSurfaceShader(
10
10
  flags,
11
11
  material,
12
12
  shaderProgram,
13
- clippingShaderState
13
+ clippingShaderState,
14
+ clippingPolygonShaderState
14
15
  ) {
15
16
  this.numberOfDayTextures = numberOfDayTextures;
16
17
  this.flags = flags;
17
18
  this.material = material;
18
19
  this.shaderProgram = shaderProgram;
19
20
  this.clippingShaderState = clippingShaderState;
21
+ this.clippingPolygonShaderState = clippingPolygonShaderState;
20
22
  }
21
23
 
22
24
  /**
@@ -60,6 +62,31 @@ function getPositionMode(sceneMode) {
60
62
  return positionMode;
61
63
  }
62
64
 
65
+ function getPolygonClippingFunction(context) {
66
+ // return a noop for webgl1
67
+ if (!context.webgl2) {
68
+ return `void clipPolygons(highp sampler2D clippingDistance, int regionsLength, vec2 clippingPosition, int regionIndex) {
69
+ }`;
70
+ }
71
+
72
+ return `void clipPolygons(highp sampler2D clippingDistance, int regionsLength, vec2 clippingPosition, int regionIndex) {
73
+ czm_clipPolygons(clippingDistance, regionsLength, clippingPosition, regionIndex);
74
+ }`;
75
+ }
76
+
77
+ function getUnpackClippingFunction(context) {
78
+ // return a noop for webgl1
79
+ if (!context.webgl2) {
80
+ return `vec4 unpackClippingExtents(highp sampler2D extentsTexture, int index) {
81
+ return vec4();
82
+ }`;
83
+ }
84
+
85
+ return `vec4 unpackClippingExtents(highp sampler2D extentsTexture, int index) {
86
+ return czm_unpackClippingExtents(extentsTexture, index);
87
+ }`;
88
+ }
89
+
63
90
  function get2DYPositionFraction(useWebMercatorProjection) {
64
91
  const get2DYPositionFractionGeographicProjection =
65
92
  "float get2DYPositionFraction(vec2 textureCoordinates) { return get2DGeographicYPositionFraction(textureCoordinates); }";
@@ -95,6 +122,8 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
95
122
  const enableFog = options.enableFog;
96
123
  const enableClippingPlanes = options.enableClippingPlanes;
97
124
  const clippingPlanes = options.clippingPlanes;
125
+ const enableClippingPolygons = options.enableClippingPolygons;
126
+ const clippingPolygons = options.clippingPolygons;
98
127
  const clippedByBoundaries = options.clippedByBoundaries;
99
128
  const hasImageryLayerCutout = options.hasImageryLayerCutout;
100
129
  const colorCorrect = options.colorCorrect;
@@ -152,16 +181,17 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
152
181
  (quantization << 18) |
153
182
  (applySplit << 19) |
154
183
  (enableClippingPlanes << 20) |
155
- (cartographicLimitRectangleFlag << 21) |
156
- (imageryCutoutFlag << 22) |
157
- (colorCorrect << 23) |
158
- (highlightFillTile << 24) |
159
- (colorToAlpha << 25) |
160
- (hasGeodeticSurfaceNormals << 26) |
161
- (hasExaggeration << 27) |
162
- (showUndergroundColor << 28) |
163
- (translucent << 29) |
164
- (applyDayNightAlpha << 30);
184
+ (enableClippingPolygons << 21) |
185
+ (cartographicLimitRectangleFlag << 22) |
186
+ (imageryCutoutFlag << 23) |
187
+ (colorCorrect << 24) |
188
+ (highlightFillTile << 25) |
189
+ (colorToAlpha << 26) |
190
+ (hasGeodeticSurfaceNormals << 27) |
191
+ (hasExaggeration << 28) |
192
+ (showUndergroundColor << 29) |
193
+ (translucent << 30) |
194
+ (applyDayNightAlpha << 31);
165
195
 
166
196
  let currentClippingShaderState = 0;
167
197
  if (defined(clippingPlanes) && clippingPlanes.length > 0) {
@@ -169,13 +199,23 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
169
199
  ? clippingPlanes.clippingPlanesState
170
200
  : 0;
171
201
  }
202
+
203
+ let currentClippingPolygonsShaderState = 0;
204
+ if (defined(clippingPolygons) && clippingPolygons.length > 0) {
205
+ currentClippingPolygonsShaderState = enableClippingPolygons
206
+ ? clippingPolygons.clippingPolygonsState
207
+ : 0;
208
+ }
209
+
172
210
  let surfaceShader = surfaceTile.surfaceShader;
173
211
  if (
174
212
  defined(surfaceShader) &&
175
213
  surfaceShader.numberOfDayTextures === numberOfDayTextures &&
176
214
  surfaceShader.flags === flags &&
177
215
  surfaceShader.material === this.material &&
178
- surfaceShader.clippingShaderState === currentClippingShaderState
216
+ surfaceShader.clippingShaderState === currentClippingShaderState &&
217
+ surfaceShader.clippingPolygonShaderState ===
218
+ currentClippingPolygonsShaderState
179
219
  ) {
180
220
  return surfaceShader.shaderProgram;
181
221
  }
@@ -190,16 +230,25 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
190
230
  if (
191
231
  !defined(surfaceShader) ||
192
232
  surfaceShader.material !== this.material ||
193
- surfaceShader.clippingShaderState !== currentClippingShaderState
233
+ surfaceShader.clippingShaderState !== currentClippingShaderState ||
234
+ surfaceShader.clippingPolygonShaderState !==
235
+ currentClippingPolygonsShaderState
194
236
  ) {
195
237
  // Cache miss - we've never seen this combination of numberOfDayTextures and flags before.
196
238
  const vs = this.baseVertexShaderSource.clone();
197
239
  const fs = this.baseFragmentShaderSource.clone();
198
240
 
241
+ // Need to go before GlobeFS
199
242
  if (currentClippingShaderState !== 0) {
200
243
  fs.sources.unshift(
201
244
  getClippingFunction(clippingPlanes, frameState.context)
202
- ); // Need to go before GlobeFS
245
+ );
246
+ }
247
+
248
+ // Need to go before GlobeFS
249
+ if (currentClippingPolygonsShaderState !== 0) {
250
+ fs.sources.unshift(getPolygonClippingFunction(frameState.context));
251
+ vs.sources.unshift(getUnpackClippingFunction(frameState.context));
203
252
  }
204
253
 
205
254
  vs.defines.push(quantizationDefine);
@@ -292,6 +341,22 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
292
341
  fs.defines.push("ENABLE_CLIPPING_PLANES");
293
342
  }
294
343
 
344
+ if (enableClippingPolygons) {
345
+ fs.defines.push("ENABLE_CLIPPING_POLYGONS");
346
+ vs.defines.push("ENABLE_CLIPPING_POLYGONS");
347
+
348
+ if (clippingPolygons.inverse) {
349
+ fs.defines.push("CLIPPING_INVERSE");
350
+ }
351
+
352
+ fs.defines.push(
353
+ `CLIPPING_POLYGON_REGIONS_LENGTH ${clippingPolygons.extentsCount}`
354
+ );
355
+ vs.defines.push(
356
+ `CLIPPING_POLYGON_REGIONS_LENGTH ${clippingPolygons.extentsCount}`
357
+ );
358
+ }
359
+
295
360
  if (colorCorrect) {
296
361
  fs.defines.push("COLOR_CORRECT");
297
362
  }
@@ -377,7 +442,8 @@ GlobeSurfaceShaderSet.prototype.getShaderProgram = function (options) {
377
442
  flags,
378
443
  this.material,
379
444
  shader,
380
- currentClippingShaderState
445
+ currentClippingShaderState,
446
+ currentClippingPolygonsShaderState
381
447
  );
382
448
  }
383
449
 
@@ -38,6 +38,7 @@ import RenderState from "../Renderer/RenderState.js";
38
38
  import VertexArray from "../Renderer/VertexArray.js";
39
39
  import BlendingState from "./BlendingState.js";
40
40
  import ClippingPlaneCollection from "./ClippingPlaneCollection.js";
41
+ import ClippingPolygonCollection from "./ClippingPolygonCollection.js";
41
42
  import DepthFunction from "./DepthFunction.js";
42
43
  import GlobeSurfaceTile from "./GlobeSurfaceTile.js";
43
44
  import ImageryLayer from "./ImageryLayer.js";
@@ -170,6 +171,13 @@ function GlobeSurfaceTileProvider(options) {
170
171
  */
171
172
  this._clippingPlanes = undefined;
172
173
 
174
+ /**
175
+ * A property specifying a {@link ClippingPolygonCollection} used to selectively disable rendering inside or outside a list of polygons.
176
+ * @type {ClippingPolygonCollection}
177
+ * @private
178
+ */
179
+ this._clippingPolygons = undefined;
180
+
173
181
  /**
174
182
  * A property specifying a {@link Rectangle} used to selectively limit terrain and imagery rendering.
175
183
  * @type {Rectangle}
@@ -290,7 +298,7 @@ Object.defineProperties(GlobeSurfaceTileProvider.prototype, {
290
298
  },
291
299
  },
292
300
  /**
293
- * The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
301
+ * The {@link ClippingPlaneCollection} used to selectively disable rendering.
294
302
  *
295
303
  * @type {ClippingPlaneCollection}
296
304
  *
@@ -304,6 +312,22 @@ Object.defineProperties(GlobeSurfaceTileProvider.prototype, {
304
312
  ClippingPlaneCollection.setOwner(value, this, "_clippingPlanes");
305
313
  },
306
314
  },
315
+
316
+ /**
317
+ * The {@link ClippingPolygonCollection} used to selectively disable rendering inside or outside a list of polygons.
318
+ *
319
+ * @type {ClippingPolygonCollection}
320
+ *
321
+ * @private
322
+ */
323
+ clippingPolygons: {
324
+ get: function () {
325
+ return this._clippingPolygons;
326
+ },
327
+ set: function (value) {
328
+ ClippingPolygonCollection.setOwner(value, this, "_clippingPolygons");
329
+ },
330
+ },
307
331
  });
308
332
 
309
333
  function sortTileImageryByLayerIndex(a, b) {
@@ -391,6 +415,14 @@ GlobeSurfaceTileProvider.prototype.beginUpdate = function (frameState) {
391
415
  if (defined(clippingPlanes) && clippingPlanes.enabled) {
392
416
  clippingPlanes.update(frameState);
393
417
  }
418
+
419
+ // update clipping polygons
420
+ const clippingPolygons = this._clippingPolygons;
421
+ if (defined(clippingPolygons) && clippingPolygons.enabled) {
422
+ clippingPolygons.update(frameState);
423
+ clippingPolygons.queueCommands(frameState);
424
+ }
425
+
394
426
  this._usedDrawCommands = 0;
395
427
 
396
428
  this._hasLoadedTilesThisFrame = false;
@@ -657,6 +689,11 @@ function isUndergroundVisible(tileProvider, frameState) {
657
689
  return true;
658
690
  }
659
691
 
692
+ const clippingPolygons = tileProvider._clippingPolygons;
693
+ if (defined(clippingPolygons) && clippingPolygons.enabled) {
694
+ return true;
695
+ }
696
+
660
697
  if (
661
698
  !Rectangle.equals(
662
699
  tileProvider.cartographicLimitRectangle,
@@ -775,6 +812,16 @@ GlobeSurfaceTileProvider.prototype.computeTileVisibility = function (
775
812
  }
776
813
  }
777
814
 
815
+ const clippingPolygons = this._clippingPolygons;
816
+ if (defined(clippingPolygons) && clippingPolygons.enabled) {
817
+ const polygonIntersection = clippingPolygons.computeIntersectionWithBoundingVolume(
818
+ tileBoundingRegion
819
+ );
820
+ tile.isClipped = polygonIntersection !== Intersect.OUTSIDE;
821
+ // Polygon clipping intersections are determined by outer rectangles, therefore we cannot
822
+ // preemptively determine if a tile is completely clipped or not here.
823
+ }
824
+
778
825
  let visibility;
779
826
  const intersection = cullingVolume.computeVisibility(boundingVolume);
780
827
 
@@ -1364,6 +1411,8 @@ GlobeSurfaceTileProvider.prototype.isDestroyed = function () {
1364
1411
  GlobeSurfaceTileProvider.prototype.destroy = function () {
1365
1412
  this._tileProvider = this._tileProvider && this._tileProvider.destroy();
1366
1413
  this._clippingPlanes = this._clippingPlanes && this._clippingPlanes.destroy();
1414
+ this._clippingPolygons =
1415
+ this._clippingPolygons && this._clippingPolygons.destroy();
1367
1416
  this._removeLayerAddedListener =
1368
1417
  this._removeLayerAddedListener && this._removeLayerAddedListener();
1369
1418
  this._removeLayerRemovedListener =
@@ -1755,6 +1804,21 @@ function createTileUniformMap(frameState, globeSurfaceTileProvider) {
1755
1804
  style.alpha = this.properties.clippingPlanesEdgeWidth;
1756
1805
  return style;
1757
1806
  },
1807
+ u_clippingDistance: function () {
1808
+ const texture =
1809
+ globeSurfaceTileProvider._clippingPolygons.clippingTexture;
1810
+ if (defined(texture)) {
1811
+ return texture;
1812
+ }
1813
+ return frameState.context.defaultTexture;
1814
+ },
1815
+ u_clippingExtents: function () {
1816
+ const texture = globeSurfaceTileProvider._clippingPolygons.extentsTexture;
1817
+ if (defined(texture)) {
1818
+ return texture;
1819
+ }
1820
+ return frameState.context.defaultTexture;
1821
+ },
1758
1822
  u_minimumBrightness: function () {
1759
1823
  return frameState.fog.minimumBrightness;
1760
1824
  },
@@ -2039,6 +2103,8 @@ const surfaceShaderSetOptionsScratch = {
2039
2103
  enableFog: undefined,
2040
2104
  enableClippingPlanes: undefined,
2041
2105
  clippingPlanes: undefined,
2106
+ enableClippingPolygons: undefined,
2107
+ clippingPolygons: undefined,
2042
2108
  clippedByBoundaries: undefined,
2043
2109
  hasImageryLayerCutout: undefined,
2044
2110
  colorCorrect: undefined,
@@ -2166,6 +2232,13 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
2166
2232
  ) {
2167
2233
  --maxTextures;
2168
2234
  }
2235
+ if (
2236
+ defined(tileProvider.clippingPolygons) &&
2237
+ tileProvider.clippingPolygons.enabled
2238
+ ) {
2239
+ --maxTextures;
2240
+ --maxTextures;
2241
+ }
2169
2242
 
2170
2243
  maxTextures -= globeTranslucencyState.numberOfTextureUniforms;
2171
2244
 
@@ -2726,6 +2799,11 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
2726
2799
  uniformMapProperties.clippingPlanesEdgeWidth = clippingPlanes.edgeWidth;
2727
2800
  }
2728
2801
 
2802
+ // update clipping polygons
2803
+ const clippingPolygons = tileProvider._clippingPolygons;
2804
+ const clippingPolygonsEnabled =
2805
+ defined(clippingPolygons) && clippingPolygons.enabled && tile.isClipped;
2806
+
2729
2807
  surfaceShaderSetOptions.numberOfDayTextures = numberOfDayTextures;
2730
2808
  surfaceShaderSetOptions.applyBrightness = applyBrightness;
2731
2809
  surfaceShaderSetOptions.applyContrast = applyContrast;
@@ -2738,6 +2816,8 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) {
2738
2816
  surfaceShaderSetOptions.enableFog = applyFog;
2739
2817
  surfaceShaderSetOptions.enableClippingPlanes = clippingPlanesEnabled;
2740
2818
  surfaceShaderSetOptions.clippingPlanes = clippingPlanes;
2819
+ surfaceShaderSetOptions.enableClippingPolygons = clippingPolygonsEnabled;
2820
+ surfaceShaderSetOptions.clippingPolygons = clippingPolygons;
2741
2821
  surfaceShaderSetOptions.hasImageryLayerCutout = applyCutout;
2742
2822
  surfaceShaderSetOptions.colorCorrect = colorCorrect;
2743
2823
  surfaceShaderSetOptions.highlightFillTile = highlightFillTile;
@@ -17,6 +17,7 @@ import Resource from "../../Core/Resource.js";
17
17
  import RuntimeError from "../../Core/RuntimeError.js";
18
18
  import Pass from "../../Renderer/Pass.js";
19
19
  import ClippingPlaneCollection from "../ClippingPlaneCollection.js";
20
+ import ClippingPolygonCollection from "../ClippingPolygonCollection.js";
20
21
  import ColorBlendMode from "../ColorBlendMode.js";
21
22
  import GltfLoader from "../GltfLoader.js";
22
23
  import HeightReference, {
@@ -147,6 +148,7 @@ import pickModel from "./pickModel.js";
147
148
  * @privateParam {boolean} [options.showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.
148
149
  * @privateParam {Color} [options.outlineColor=Color.BLACK] The color to use when rendering outlines.
149
150
  * @privateParam {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.
151
+ * @privateParam {ClippingPolygonCollection} [options.clippingPolygons] The {@link ClippingPolygonCollection} used to selectively disable rendering the model.
150
152
  * @privateParam {Cartesian3} [options.lightColor] The light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
151
153
  * @privateParam {ImageBasedLighting} [options.imageBasedLighting] The properties for managing image-based lighting on this model.
152
154
  * @privateParam {boolean} [options.backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.
@@ -370,6 +372,20 @@ function Model(options) {
370
372
  this._clippingPlanesState = 0; // If this value changes, the shaders need to be regenerated.
371
373
  this._clippingPlanesMatrix = Matrix4.clone(Matrix4.IDENTITY); // Derived from reference matrix and the current view matrix
372
374
 
375
+ // If the given clipping polygons don't have an owner, make this model its owner.
376
+ // Otherwise, the clipping polygons are passed down from a tileset.
377
+ const clippingPolygons = options.clippingPolygons;
378
+ if (defined(clippingPolygons) && clippingPolygons.owner === undefined) {
379
+ ClippingPolygonCollection.setOwner(
380
+ clippingPolygons,
381
+ this,
382
+ "_clippingPolygons"
383
+ );
384
+ } else {
385
+ this._clippingPolygons = clippingPolygons;
386
+ }
387
+ this._clippingPolygonsState = 0; // If this value changes, the shaders need to be regenerated.
388
+
373
389
  this._lightColor = Cartesian3.clone(options.lightColor);
374
390
 
375
391
  this._imageBasedLighting = defined(options.imageBasedLighting)
@@ -1303,6 +1319,26 @@ Object.defineProperties(Model.prototype, {
1303
1319
  },
1304
1320
  },
1305
1321
 
1322
+ /**
1323
+ * The {@link ClippingPolygonCollection} used to selectively disable rendering the model.
1324
+ *
1325
+ * @memberof Model.prototype
1326
+ *
1327
+ * @type {ClippingPolygonCollection}
1328
+ */
1329
+ clippingPolygons: {
1330
+ get: function () {
1331
+ return this._clippingPolygons;
1332
+ },
1333
+ set: function (value) {
1334
+ if (value !== this._clippingPolygons) {
1335
+ // Handle destroying old clipping polygons, new clipping polygons ownership
1336
+ ClippingPolygonCollection.setOwner(value, this, "_clippingPolygons");
1337
+ this.resetDrawCommands();
1338
+ }
1339
+ },
1340
+ },
1341
+
1306
1342
  /**
1307
1343
  * The light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
1308
1344
  * <p>
@@ -1801,6 +1837,7 @@ Model.prototype.update = function (frameState) {
1801
1837
  updateSilhouette(this, frameState);
1802
1838
  updateSkipLevelOfDetail(this, frameState);
1803
1839
  updateClippingPlanes(this, frameState);
1840
+ updateClippingPolygons(this, frameState);
1804
1841
  updateSceneMode(this, frameState);
1805
1842
  updateFog(this, frameState);
1806
1843
  updateVerticalExaggeration(this, frameState);
@@ -1987,6 +2024,24 @@ function updateClippingPlanes(model, frameState) {
1987
2024
  }
1988
2025
  }
1989
2026
 
2027
+ function updateClippingPolygons(model, frameState) {
2028
+ // Update the clipping polygon collection / state for this model to detect any changes.
2029
+ let currentClippingPolygonsState = 0;
2030
+ if (model.isClippingPolygonsEnabled()) {
2031
+ if (model._clippingPolygons.owner === model) {
2032
+ model._clippingPolygons.update(frameState);
2033
+ model._clippingPolygons.queueCommands(frameState);
2034
+ }
2035
+ currentClippingPolygonsState =
2036
+ model._clippingPolygons.clippingPolygonsState;
2037
+ }
2038
+
2039
+ if (currentClippingPolygonsState !== model._clippingPolygonsState) {
2040
+ model.resetDrawCommands();
2041
+ model._clippingPolygonsState = currentClippingPolygonsState;
2042
+ }
2043
+ }
2044
+
1990
2045
  function updateSceneMode(model, frameState) {
1991
2046
  if (frameState.mode !== model._sceneMode) {
1992
2047
  if (model._projectTo2D) {
@@ -2537,6 +2592,21 @@ Model.prototype.pick = function (
2537
2592
  );
2538
2593
  };
2539
2594
 
2595
+ /**
2596
+ * Gets whether or not clipping polygons are enabled for this model.
2597
+ *
2598
+ * @returns {boolean} <code>true</code> if clipping polygons are enabled for this model, <code>false</code>.
2599
+ * @private
2600
+ */
2601
+ Model.prototype.isClippingPolygonsEnabled = function () {
2602
+ const clippingPolygons = this._clippingPolygons;
2603
+ return (
2604
+ defined(clippingPolygons) &&
2605
+ clippingPolygons.enabled &&
2606
+ clippingPolygons.length !== 0
2607
+ );
2608
+ };
2609
+
2540
2610
  /**
2541
2611
  * Returns true if this object was destroyed; otherwise, false.
2542
2612
  * <br /><br />
@@ -2606,6 +2676,17 @@ Model.prototype.destroy = function () {
2606
2676
  }
2607
2677
  this._clippingPlanes = undefined;
2608
2678
 
2679
+ // Only destroy the ClippingPolygonCollection if this is the owner.
2680
+ const clippingPolygonCollection = this._clippingPolygons;
2681
+ if (
2682
+ defined(clippingPolygonCollection) &&
2683
+ !clippingPolygonCollection.isDestroyed() &&
2684
+ clippingPolygonCollection.owner === this
2685
+ ) {
2686
+ clippingPolygonCollection.destroy();
2687
+ }
2688
+ this._clippingPolygons = undefined;
2689
+
2609
2690
  // Only destroy the ImageBasedLighting if this is the owner.
2610
2691
  if (
2611
2692
  this._shouldDestroyImageBasedLighting &&
@@ -2689,6 +2770,7 @@ Model.prototype.destroyModelResources = function () {
2689
2770
  * @param {boolean} [options.showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.
2690
2771
  * @param {Color} [options.outlineColor=Color.BLACK] The color to use when rendering outlines.
2691
2772
  * @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.
2773
+ * @param {ClippingPolygonCollection} [options.clippingPolygons] The {@link ClippingPolygonCollection} used to selectively disable rendering the model.
2692
2774
  * @param {Cartesian3} [options.lightColor] The light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
2693
2775
  * @param {ImageBasedLighting} [options.imageBasedLighting] The properties for managing image-based lighting on this model.
2694
2776
  * @param {boolean} [options.backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the material's doubleSided property; when false, back face culling is disabled. Back faces are not culled if the model's color is translucent.
@@ -3051,6 +3133,7 @@ function makeModelOptions(loader, modelType, options) {
3051
3133
  showOutline: options.showOutline,
3052
3134
  outlineColor: options.outlineColor,
3053
3135
  clippingPlanes: options.clippingPlanes,
3136
+ clippingPolygons: options.clippingPolygons,
3054
3137
  lightColor: options.lightColor,
3055
3138
  imageBasedLighting: options.imageBasedLighting,
3056
3139
  backFaceCulling: options.backFaceCulling,
@@ -255,6 +255,27 @@ Model3DTileContent.prototype.update = function (tileset, frameState) {
255
255
  model._clippingPlanesState = 0;
256
256
  }
257
257
 
258
+ // Updating clipping polygons requires more effort because of ownership checks
259
+ const tilesetClippingPolygons = tileset.clippingPolygons;
260
+ if (defined(tilesetClippingPolygons) && tile.clippingPolygonsDirty) {
261
+ // Dereference the clipping polygons from the model if they are irrelevant.
262
+ model._clippingPolygons =
263
+ tilesetClippingPolygons.enabled && tile._isClippedByPolygon
264
+ ? tilesetClippingPolygons
265
+ : undefined;
266
+ }
267
+
268
+ // If the model references a different ClippingPolygonCollection from the tileset,
269
+ // update the model to use the new ClippingPolygonCollection.
270
+ if (
271
+ defined(tilesetClippingPolygons) &&
272
+ defined(model._clippingPolygons) &&
273
+ model._clippingPolygons !== tilesetClippingPolygons
274
+ ) {
275
+ model._clippingPolygons = tilesetClippingPolygons;
276
+ model._clippingPolygonsState = 0;
277
+ }
278
+
258
279
  model.update(frameState);
259
280
 
260
281
  if (!this._ready && model.ready) {
@@ -0,0 +1,92 @@
1
+ import combine from "../../Core/combine.js";
2
+ import ModelClippingPolygonsStageVS from "../../Shaders/Model/ModelClippingPolygonsStageVS.js";
3
+ import ModelClippingPolygonsStageFS from "../../Shaders/Model/ModelClippingPolygonsStageFS.js";
4
+ import ShaderDestination from "../../Renderer/ShaderDestination.js";
5
+
6
+ /**
7
+ * The model clipping planes stage is responsible for applying clipping planes to the model.
8
+ *
9
+ * @namespace ModelClippingPolygonsPipelineStage
10
+ *
11
+ * @private
12
+ */
13
+ const ModelClippingPolygonsPipelineStage = {
14
+ name: "ModelClippingPolygonsPipelineStage", // Helps with debugging
15
+ };
16
+
17
+ /**
18
+ * Process a model for polygon clipping. This modifies the following parts of the render resources:
19
+ *
20
+ * <ul>
21
+ * <li>adds a define to both the vertex and fragment shaders to indicate that the model has clipping polygons</li>
22
+ * <li>adds the defines to both the vertex and fragment shaders for parameters related to clipping polygons, such as the number of polygons</li>
23
+ * <li>adds a function to the vertex shader to determine lookup uvs</li>
24
+ * <li>adds a function to the fragment shader to discard clipped regions</li>
25
+ * <li>adds the uniforms to the vertex and fragment shaders for the clipping extents texture and clipping distance respectively</li>
26
+ * <li>adds a varying for lookup uvs in the clipping texture</li>
27
+ *</ul>
28
+ *
29
+ * @param {ModelRenderResources} renderResources The render resources for this model.
30
+ * @param {Model} model The model.
31
+ * @param {FrameState} frameState The frameState.
32
+ *
33
+ * @private
34
+ */
35
+ ModelClippingPolygonsPipelineStage.process = function (
36
+ renderResources,
37
+ model,
38
+ frameState
39
+ ) {
40
+ const clippingPolygons = model.clippingPolygons;
41
+ const shaderBuilder = renderResources.shaderBuilder;
42
+
43
+ shaderBuilder.addDefine(
44
+ "ENABLE_CLIPPING_POLYGONS",
45
+ undefined,
46
+ ShaderDestination.BOTH
47
+ );
48
+
49
+ if (clippingPolygons.inverse) {
50
+ shaderBuilder.addDefine(
51
+ "CLIPPING_INVERSE",
52
+ undefined,
53
+ ShaderDestination.FRAGMENT
54
+ );
55
+ }
56
+
57
+ shaderBuilder.addDefine(
58
+ "CLIPPING_POLYGON_REGIONS_LENGTH",
59
+ clippingPolygons.extentsCount,
60
+ ShaderDestination.BOTH
61
+ );
62
+
63
+ shaderBuilder.addUniform(
64
+ "sampler2D",
65
+ "model_clippingDistance",
66
+ ShaderDestination.FRAGMENT
67
+ );
68
+
69
+ shaderBuilder.addUniform(
70
+ "sampler2D",
71
+ "model_clippingExtents",
72
+ ShaderDestination.VERTEX
73
+ );
74
+
75
+ shaderBuilder.addVarying("vec2", "v_clippingPosition");
76
+ shaderBuilder.addVarying("int", "v_regionIndex", "flat");
77
+ shaderBuilder.addVertexLines(ModelClippingPolygonsStageVS);
78
+ shaderBuilder.addFragmentLines(ModelClippingPolygonsStageFS);
79
+
80
+ const uniformMap = {
81
+ model_clippingDistance: function () {
82
+ return clippingPolygons.clippingTexture;
83
+ },
84
+ model_clippingExtents: function () {
85
+ return clippingPolygons.extentsTexture;
86
+ },
87
+ };
88
+
89
+ renderResources.uniformMap = combine(uniformMap, renderResources.uniformMap);
90
+ };
91
+
92
+ export default ModelClippingPolygonsPipelineStage;
@@ -14,6 +14,7 @@ import ImageBasedLightingPipelineStage from "./ImageBasedLightingPipelineStage.j
14
14
  import ModelArticulation from "./ModelArticulation.js";
15
15
  import ModelColorPipelineStage from "./ModelColorPipelineStage.js";
16
16
  import ModelClippingPlanesPipelineStage from "./ModelClippingPlanesPipelineStage.js";
17
+ import ModelClippingPolygonsPipelineStage from "./ModelClippingPolygonsPipelineStage.js";
17
18
  import ModelNode from "./ModelNode.js";
18
19
  import ModelRuntimeNode from "./ModelRuntimeNode.js";
19
20
  import ModelRuntimePrimitive from "./ModelRuntimePrimitive.js";
@@ -626,6 +627,10 @@ ModelSceneGraph.prototype.configurePipeline = function (frameState) {
626
627
  modelPipelineStages.push(ModelClippingPlanesPipelineStage);
627
628
  }
628
629
 
630
+ if (model.isClippingPolygonsEnabled()) {
631
+ modelPipelineStages.push(ModelClippingPolygonsPipelineStage);
632
+ }
633
+
629
634
  if (model.hasSilhouette(frameState)) {
630
635
  modelPipelineStages.push(ModelSilhouettePipelineStage);
631
636
  }
@@ -83,7 +83,7 @@ Object.defineProperties(Terrain.prototype, {
83
83
 
84
84
  /**
85
85
  * Returns true when the terrain provider has been successfully created. Otherwise, returns false.
86
- * @memberof Viewer.prototype
86
+ * @memberof Terrain.prototype
87
87
  *
88
88
  * @type {boolean}
89
89
  * @readonly
@@ -96,7 +96,7 @@ Object.defineProperties(Terrain.prototype, {
96
96
 
97
97
  /**
98
98
  * The terrain provider providing surface geometry to a globe. Do not use until {@link Terrain.readyEvent} is raised.
99
- * @memberof Viewer.prototype
99
+ * @memberof Terrain.prototype
100
100
  *
101
101
  * @type {TerrainProvider}
102
102
  * @readonly