@cesium/engine 9.0.0 → 9.2.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 (189) hide show
  1. package/Build/ThirdParty/Workers/pako_deflate.min.js +108 -210
  2. package/Build/ThirdParty/Workers/pako_inflate.min.js +466 -568
  3. package/Build/ThirdParty/Workers/z-worker-pako.js +56 -105
  4. package/Build/Workers/{chunk-VR5RBW52.js → chunk-26NE4LRW.js} +7 -7
  5. package/Build/Workers/{chunk-P2YAAMT2.js → chunk-26XJDV3D.js} +15 -15
  6. package/Build/Workers/{chunk-L4BW3RUA.js → chunk-2TRB253J.js} +7 -7
  7. package/Build/Workers/{chunk-NP2GYYE5.js → chunk-3PV5HQ2R.js} +6 -6
  8. package/Build/Workers/{chunk-BCU2LH5T.js → chunk-3VDHTBY5.js} +10 -10
  9. package/Build/Workers/{chunk-WHUSTDIB.js → chunk-4RG6WOXH.js} +10 -10
  10. package/Build/Workers/{chunk-P4XKB3QZ.js → chunk-5OK5JFDP.js} +5 -5
  11. package/Build/Workers/{chunk-2ZBL3MVO.js → chunk-7HLZRYGD.js} +10 -12
  12. package/Build/Workers/chunk-7PFZ4Z7C.js +961 -0
  13. package/Build/Workers/{chunk-24YTYWNB.js → chunk-A5CSB5ZE.js} +11 -13
  14. package/Build/Workers/{chunk-RMOEYCZW.js → chunk-AROLUUGS.js} +2 -2
  15. package/Build/Workers/{chunk-3NCVAGDA.js → chunk-BBBTT36L.js} +14 -14
  16. package/Build/Workers/{chunk-QKBGRKKG.js → chunk-BNT2SNWU.js} +4 -4
  17. package/Build/Workers/{chunk-LQJ5FFFR.js → chunk-CFBGPZU6.js} +11 -13
  18. package/Build/Workers/{chunk-C6OI26DR.js → chunk-CVCVMOQA.js} +1 -1
  19. package/Build/Workers/{chunk-SS4ESNE3.js → chunk-DIVFF6DK.js} +2 -2
  20. package/Build/Workers/{chunk-PXB7T27O.js → chunk-EJZVBTX4.js} +6 -6
  21. package/Build/Workers/{chunk-TZORKRNK.js → chunk-EODIOQ35.js} +1 -1
  22. package/Build/Workers/{chunk-QCQUZGXI.js → chunk-ETC45PHH.js} +5 -6
  23. package/Build/Workers/{chunk-E6WXPSJS.js → chunk-G7IAO7CW.js} +7 -7
  24. package/Build/Workers/{chunk-X2F6BEPY.js → chunk-GOQEANLM.js} +16 -16
  25. package/Build/Workers/{chunk-7COR472O.js → chunk-GUFV24F4.js} +7197 -5096
  26. package/Build/Workers/{chunk-5TIV3L26.js → chunk-GX2BWBN2.js} +13 -13
  27. package/Build/Workers/{chunk-ADOVHYWO.js → chunk-GX5LMUGZ.js} +469 -6
  28. package/Build/Workers/{chunk-2632RVPI.js → chunk-I6CW7ZE5.js} +7 -7
  29. package/Build/Workers/{chunk-YDVSBWEO.js → chunk-IF2OX6R4.js} +3 -5
  30. package/Build/Workers/{chunk-RSJXEO2A.js → chunk-IXYFH7DV.js} +95 -155
  31. package/Build/Workers/{chunk-ZNVSKMQ2.js → chunk-K5F23SZO.js} +6 -6
  32. package/Build/Workers/{chunk-MWV7IZK4.js → chunk-KTZK2UDR.js} +7 -7
  33. package/Build/Workers/{chunk-HBQPB6IH.js → chunk-LZFFO4KB.js} +12 -12
  34. package/Build/Workers/{chunk-GFA4SMXV.js → chunk-OYP23VAL.js} +11 -11
  35. package/Build/Workers/{chunk-ZYPTP7GS.js → chunk-PHT53MCH.js} +11 -11
  36. package/Build/Workers/{chunk-TJBU6GML.js → chunk-PUQR43HZ.js} +6 -6
  37. package/Build/Workers/{chunk-CO35JNNE.js → chunk-QZIWFSRM.js} +4 -4
  38. package/Build/Workers/{chunk-C3XBUYBO.js → chunk-RDR4KVPA.js} +17 -17
  39. package/Build/Workers/{chunk-YV4H2Y7M.js → chunk-RRUO4QEK.js} +4 -4
  40. package/Build/Workers/{chunk-LAQP3SCC.js → chunk-RTIT7UDN.js} +2 -2
  41. package/Build/Workers/{chunk-Z7FQLK6N.js → chunk-SC3TBKST.js} +4 -4
  42. package/Build/Workers/{chunk-GXUXEOE2.js → chunk-TDIGL45B.js} +1 -1
  43. package/Build/Workers/{chunk-EOXYZ34O.js → chunk-TP4FFUAH.js} +2 -2
  44. package/Build/Workers/{chunk-N4KXMWQU.js → chunk-U2LSTOMA.js} +2 -2
  45. package/Build/Workers/{chunk-6WF3KIF5.js → chunk-U6MTSO6A.js} +47 -84
  46. package/Build/Workers/{chunk-I37B3MZ2.js → chunk-UICVDDCQ.js} +1 -1
  47. package/Build/Workers/{chunk-DPUSFA7S.js → chunk-UKJCFXVV.js} +6 -6
  48. package/Build/Workers/{chunk-EPKE7GE3.js → chunk-UYKG3UFK.js} +5 -5
  49. package/Build/Workers/{chunk-RV7ZOSS6.js → chunk-W4OS542B.js} +13 -13
  50. package/Build/Workers/{chunk-DGDUKCJJ.js → chunk-WHDEZSAL.js} +6 -6
  51. package/Build/Workers/{chunk-NZWNZA6S.js → chunk-WOYQB5HM.js} +5 -5
  52. package/Build/Workers/{chunk-M2AYBTNH.js → chunk-WP3LCUOE.js} +13 -13
  53. package/Build/Workers/{chunk-73FKKY52.js → chunk-YGNQJ4YI.js} +5 -5
  54. package/Build/Workers/{chunk-SE4PXOEA.js → chunk-YGTWKLFY.js} +19 -19
  55. package/Build/Workers/{chunk-5R6VWLMH.js → chunk-ZHJDE6JN.js} +6 -6
  56. package/Build/Workers/combineGeometry.js +22 -24
  57. package/Build/Workers/createBoxGeometry.js +16 -18
  58. package/Build/Workers/createBoxOutlineGeometry.js +14 -16
  59. package/Build/Workers/createCircleGeometry.js +24 -26
  60. package/Build/Workers/createCircleOutlineGeometry.js +17 -19
  61. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -34
  62. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -31
  63. package/Build/Workers/createCorridorGeometry.js +27 -29
  64. package/Build/Workers/createCorridorOutlineGeometry.js +26 -28
  65. package/Build/Workers/createCylinderGeometry.js +18 -20
  66. package/Build/Workers/createCylinderOutlineGeometry.js +16 -18
  67. package/Build/Workers/createEllipseGeometry.js +24 -26
  68. package/Build/Workers/createEllipseOutlineGeometry.js +17 -19
  69. package/Build/Workers/createEllipsoidGeometry.js +17 -19
  70. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -18
  71. package/Build/Workers/createFrustumGeometry.js +16 -18
  72. package/Build/Workers/createFrustumOutlineGeometry.js +18 -19
  73. package/Build/Workers/createGeometry.js +22 -24
  74. package/Build/Workers/createGroundPolylineGeometry.js +23 -25
  75. package/Build/Workers/createPlaneGeometry.js +14 -16
  76. package/Build/Workers/createPlaneOutlineGeometry.js +13 -15
  77. package/Build/Workers/createPolygonGeometry.js +32 -34
  78. package/Build/Workers/createPolygonOutlineGeometry.js +28 -30
  79. package/Build/Workers/createPolylineGeometry.js +23 -25
  80. package/Build/Workers/createPolylineVolumeGeometry.js +29 -31
  81. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -27
  82. package/Build/Workers/createRectangleGeometry.js +27 -29
  83. package/Build/Workers/createRectangleOutlineGeometry.js +18 -20
  84. package/Build/Workers/createSimplePolylineGeometry.js +21 -23
  85. package/Build/Workers/createSphereGeometry.js +17 -19
  86. package/Build/Workers/createSphereOutlineGeometry.js +16 -18
  87. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  88. package/Build/Workers/createVectorTileClampedPolylines.js +14 -16
  89. package/Build/Workers/createVectorTileGeometries.js +22 -24
  90. package/Build/Workers/createVectorTilePoints.js +12 -12
  91. package/Build/Workers/createVectorTilePolygons.js +20 -22
  92. package/Build/Workers/createVectorTilePolylines.js +14 -16
  93. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +23 -25
  94. package/Build/Workers/createVerticesFromHeightmap.js +23 -25
  95. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +19 -22
  96. package/Build/Workers/createWallGeometry.js +22 -24
  97. package/Build/Workers/createWallOutlineGeometry.js +21 -23
  98. package/Build/Workers/decodeDraco.js +11 -11
  99. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +12 -19
  100. package/Build/Workers/decodeI3S.js +10 -11
  101. package/Build/Workers/transcodeKTX2.js +44 -80
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -22
  104. package/Source/Core/Ion.js +1 -1
  105. package/Source/Core/Math.js +0 -5
  106. package/Source/Core/PixelFormat.js +1 -0
  107. package/Source/Core/Rectangle.js +89 -0
  108. package/Source/Core/TaskProcessor.js +19 -3
  109. package/Source/Core/sampleTerrain.js +3 -3
  110. package/Source/DataSources/DataSourceDisplay.js +5 -0
  111. package/Source/Renderer/ShaderBuilder.js +6 -3
  112. package/Source/Scene/ArcGisMapService.js +1 -1
  113. package/Source/Scene/Billboard.js +7 -5
  114. package/Source/Scene/Cesium3DTile.js +65 -0
  115. package/Source/Scene/Cesium3DTileset.js +48 -1
  116. package/Source/Scene/ClippingPolygon.js +212 -0
  117. package/Source/Scene/ClippingPolygonCollection.js +968 -0
  118. package/Source/Scene/Globe.js +14 -0
  119. package/Source/Scene/GlobeSurfaceShaderSet.js +81 -15
  120. package/Source/Scene/GlobeSurfaceTileProvider.js +81 -1
  121. package/Source/Scene/GltfLoader.js +458 -435
  122. package/Source/Scene/GltfLoaderUtil.js +3 -12
  123. package/Source/Scene/GltfPipeline/forEachTextureInMaterial.js +23 -7
  124. package/Source/Scene/GltfStructuralMetadataLoader.js +11 -9
  125. package/Source/Scene/Label.js +1 -1
  126. package/Source/Scene/Model/AlphaPipelineStage.js +1 -1
  127. package/Source/Scene/Model/GeometryPipelineStage.js +15 -43
  128. package/Source/Scene/Model/ImageBasedLightingPipelineStage.js +7 -0
  129. package/Source/Scene/Model/LightingPipelineStage.js +2 -4
  130. package/Source/Scene/Model/MaterialPipelineStage.js +346 -29
  131. package/Source/Scene/Model/Model.js +91 -3
  132. package/Source/Scene/Model/Model3DTileContent.js +21 -0
  133. package/Source/Scene/Model/ModelClippingPolygonsPipelineStage.js +92 -0
  134. package/Source/Scene/Model/ModelSceneGraph.js +5 -0
  135. package/Source/Scene/Model/ModelUtility.js +3 -0
  136. package/Source/Scene/Model/VerticalExaggerationPipelineStage.js +4 -6
  137. package/Source/Scene/ModelComponents.js +169 -1
  138. package/Source/Scene/PickDepth.js +23 -15
  139. package/Source/Scene/ResourceCache.js +41 -50
  140. package/Source/Scene/ResourceCacheKey.js +41 -53
  141. package/Source/Scene/Terrain.js +2 -2
  142. package/Source/Shaders/Builtin/CzmBuiltins.js +6 -8
  143. package/Source/Shaders/Builtin/Functions/clipPolygons.glsl +37 -0
  144. package/Source/Shaders/Builtin/Functions/clipPolygons.js +39 -0
  145. package/Source/Shaders/Builtin/Functions/maximumComponent.glsl +21 -0
  146. package/Source/Shaders/Builtin/Functions/maximumComponent.js +23 -0
  147. package/Source/Shaders/Builtin/Functions/pbrLighting.glsl +108 -44
  148. package/Source/Shaders/Builtin/Functions/pbrLighting.js +108 -44
  149. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.glsl +14 -0
  150. package/Source/Shaders/Builtin/Functions/unpackClippingExtents.js +15 -0
  151. package/Source/Shaders/Builtin/Structs/modelMaterial.glsl +14 -0
  152. package/Source/Shaders/Builtin/Structs/modelMaterial.js +14 -0
  153. package/Source/Shaders/GlobeFS.glsl +13 -1
  154. package/Source/Shaders/GlobeFS.js +13 -1
  155. package/Source/Shaders/GlobeVS.glsl +32 -0
  156. package/Source/Shaders/GlobeVS.js +32 -0
  157. package/Source/Shaders/Model/GeometryStageVS.glsl +1 -1
  158. package/Source/Shaders/Model/GeometryStageVS.js +1 -1
  159. package/Source/Shaders/Model/ImageBasedLightingStageFS.glsl +211 -133
  160. package/Source/Shaders/Model/ImageBasedLightingStageFS.js +212 -133
  161. package/Source/Shaders/Model/LightingStageFS.glsl +113 -48
  162. package/Source/Shaders/Model/LightingStageFS.js +113 -48
  163. package/Source/Shaders/Model/MaterialStageFS.glsl +399 -137
  164. package/Source/Shaders/Model/MaterialStageFS.js +399 -137
  165. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.glsl +6 -0
  166. package/Source/Shaders/Model/ModelClippingPolygonsStageFS.js +8 -0
  167. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.glsl +27 -0
  168. package/Source/Shaders/Model/ModelClippingPolygonsStageVS.js +29 -0
  169. package/Source/Shaders/Model/ModelFS.glsl +6 -0
  170. package/Source/Shaders/Model/ModelFS.js +7 -1
  171. package/Source/Shaders/Model/ModelVS.glsl +4 -0
  172. package/Source/Shaders/Model/ModelVS.js +4 -0
  173. package/Source/Shaders/PolygonSignedDistanceFS.glsl +100 -0
  174. package/Source/Shaders/PolygonSignedDistanceFS.js +101 -0
  175. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  176. package/index.d.ts +230 -4
  177. package/index.js +234 -229
  178. package/package.json +1 -1
  179. package/Build/Workers/chunk-2KACWKS4.js +0 -501
  180. package/Build/Workers/chunk-2XPLH3JY.js +0 -2977
  181. package/Build/Workers/chunk-X6XOMPWL.js +0 -73
  182. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.glsl +0 -16
  183. package/Source/Shaders/Builtin/Functions/defaultPbrMaterial.js +0 -18
  184. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.glsl +0 -37
  185. package/Source/Shaders/Builtin/Functions/pbrMetallicRoughnessMaterial.js +0 -39
  186. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.glsl +0 -30
  187. package/Source/Shaders/Builtin/Functions/pbrSpecularGlossinessMaterial.js +0 -32
  188. package/Source/Shaders/Builtin/Structs/pbrParameters.glsl +0 -16
  189. package/Source/Shaders/Builtin/Structs/pbrParameters.js +0 -18
@@ -12,15 +12,20 @@ import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
12
12
  import LightingModel from "./LightingModel.js";
13
13
  import ModelUtility from "./ModelUtility.js";
14
14
 
15
- const Material = ModelComponents.Material;
16
- const MetallicRoughness = ModelComponents.MetallicRoughness;
17
- const SpecularGlossiness = ModelComponents.SpecularGlossiness;
15
+ const {
16
+ Material,
17
+ MetallicRoughness,
18
+ SpecularGlossiness,
19
+ Specular,
20
+ Clearcoat,
21
+ } = ModelComponents;
18
22
 
19
23
  /**
20
24
  * The material pipeline stage processes textures and other uniforms needed
21
25
  * to render a primitive. This handles the following material types:
22
26
  * <ul>
23
27
  * <li>Basic glTF materials (PBR metallic roughness model)</li>
28
+ * <li>The `KHR_materials_specular` glTF extension</li>
24
29
  * <li>The `KHR_materials_pbrSpecularGlossiness` glTF extension</li>
25
30
  * <li>The `KHR_materials_unlit` glTF extension</li>
26
31
  * </ul>
@@ -59,20 +64,19 @@ MaterialPipelineStage.process = function (
59
64
  // gltf-pipeline automatically creates a default material so this will always
60
65
  // be defined.
61
66
  const material = primitive.material;
62
- const model = renderResources.model;
67
+ const { model, uniformMap, shaderBuilder } = renderResources;
63
68
 
64
69
  // Classification models only use position and feature ID attributes,
65
70
  // so textures should be disabled to avoid compile errors.
66
71
  const hasClassification = defined(model.classificationType);
67
72
  const disableTextures = hasClassification;
68
73
 
69
- const uniformMap = renderResources.uniformMap;
70
- const shaderBuilder = renderResources.shaderBuilder;
71
-
72
74
  // When textures are loaded incrementally, fall back to a default 1x1 texture
73
- const defaultTexture = frameState.context.defaultTexture;
74
- const defaultNormalTexture = frameState.context.defaultNormalTexture;
75
- const defaultEmissiveTexture = frameState.context.defaultEmissiveTexture;
75
+ const {
76
+ defaultTexture,
77
+ defaultNormalTexture,
78
+ defaultEmissiveTexture,
79
+ } = frameState.context;
76
80
 
77
81
  processMaterialUniforms(
78
82
  material,
@@ -86,15 +90,51 @@ MaterialPipelineStage.process = function (
86
90
 
87
91
  if (defined(material.specularGlossiness)) {
88
92
  processSpecularGlossinessUniforms(
89
- material,
93
+ material.specularGlossiness,
90
94
  uniformMap,
91
95
  shaderBuilder,
92
96
  defaultTexture,
93
97
  disableTextures
94
98
  );
95
99
  } else {
100
+ if (
101
+ defined(material.specular) &&
102
+ ModelUtility.supportedExtensions.KHR_materials_specular
103
+ ) {
104
+ processSpecularUniforms(
105
+ material.specular,
106
+ uniformMap,
107
+ shaderBuilder,
108
+ defaultTexture,
109
+ disableTextures
110
+ );
111
+ }
112
+ if (
113
+ defined(material.anisotropy) &&
114
+ ModelUtility.supportedExtensions.KHR_materials_anisotropy
115
+ ) {
116
+ processAnisotropyUniforms(
117
+ material.anisotropy,
118
+ uniformMap,
119
+ shaderBuilder,
120
+ defaultTexture,
121
+ disableTextures
122
+ );
123
+ }
124
+ if (
125
+ defined(material.clearcoat) &&
126
+ ModelUtility.supportedExtensions.KHR_materials_clearcoat
127
+ ) {
128
+ processClearcoatUniforms(
129
+ material.clearcoat,
130
+ uniformMap,
131
+ shaderBuilder,
132
+ defaultTexture,
133
+ disableTextures
134
+ );
135
+ }
96
136
  processMetallicRoughnessUniforms(
97
- material,
137
+ material.metallicRoughness,
98
138
  uniformMap,
99
139
  shaderBuilder,
100
140
  defaultTexture,
@@ -245,7 +285,13 @@ function processMaterialUniforms(
245
285
  defaultEmissiveTexture,
246
286
  disableTextures
247
287
  ) {
248
- const emissiveFactor = material.emissiveFactor;
288
+ const {
289
+ emissiveFactor,
290
+ emissiveTexture,
291
+ normalTexture,
292
+ occlusionTexture,
293
+ } = material;
294
+
249
295
  if (
250
296
  defined(emissiveFactor) &&
251
297
  !Cartesian3.equals(emissiveFactor, Material.DEFAULT_EMISSIVE_FACTOR)
@@ -264,7 +310,6 @@ function processMaterialUniforms(
264
310
  ShaderDestination.FRAGMENT
265
311
  );
266
312
 
267
- const emissiveTexture = material.emissiveTexture;
268
313
  if (defined(emissiveTexture) && !disableTextures) {
269
314
  processTexture(
270
315
  shaderBuilder,
@@ -277,7 +322,6 @@ function processMaterialUniforms(
277
322
  }
278
323
  }
279
324
 
280
- const normalTexture = material.normalTexture;
281
325
  if (defined(normalTexture) && !disableTextures) {
282
326
  processTexture(
283
327
  shaderBuilder,
@@ -289,7 +333,6 @@ function processMaterialUniforms(
289
333
  );
290
334
  }
291
335
 
292
- const occlusionTexture = material.occlusionTexture;
293
336
  if (defined(occlusionTexture) && !disableTextures) {
294
337
  processTexture(
295
338
  shaderBuilder,
@@ -302,21 +345,37 @@ function processMaterialUniforms(
302
345
  }
303
346
  }
304
347
 
348
+ /**
349
+ * Add uniforms and defines for the KHR_materials_pbrSpecularGlossiness extension
350
+ *
351
+ * @param {ModelComponents.SpecularGlossiness} specularGlossiness
352
+ * @param {Object<string, Function>} uniformMap The uniform map to modify.
353
+ * @param {ShaderBuilder} shaderBuilder
354
+ * @param {Texture} defaultTexture
355
+ * @param {boolean} disableTextures
356
+ * @private
357
+ */
305
358
  function processSpecularGlossinessUniforms(
306
- material,
359
+ specularGlossiness,
307
360
  uniformMap,
308
361
  shaderBuilder,
309
362
  defaultTexture,
310
363
  disableTextures
311
364
  ) {
312
- const specularGlossiness = material.specularGlossiness;
365
+ const {
366
+ diffuseTexture,
367
+ diffuseFactor,
368
+ specularGlossinessTexture,
369
+ specularFactor,
370
+ glossinessFactor,
371
+ } = specularGlossiness;
372
+
313
373
  shaderBuilder.addDefine(
314
374
  "USE_SPECULAR_GLOSSINESS",
315
375
  undefined,
316
376
  ShaderDestination.FRAGMENT
317
377
  );
318
378
 
319
- const diffuseTexture = specularGlossiness.diffuseTexture;
320
379
  if (defined(diffuseTexture) && !disableTextures) {
321
380
  processTexture(
322
381
  shaderBuilder,
@@ -328,7 +387,6 @@ function processSpecularGlossinessUniforms(
328
387
  );
329
388
  }
330
389
 
331
- const diffuseFactor = specularGlossiness.diffuseFactor;
332
390
  if (
333
391
  defined(diffuseFactor) &&
334
392
  !Cartesian4.equals(diffuseFactor, SpecularGlossiness.DEFAULT_DIFFUSE_FACTOR)
@@ -348,8 +406,6 @@ function processSpecularGlossinessUniforms(
348
406
  );
349
407
  }
350
408
 
351
- const specularGlossinessTexture =
352
- specularGlossiness.specularGlossinessTexture;
353
409
  if (defined(specularGlossinessTexture) && !disableTextures) {
354
410
  processTexture(
355
411
  shaderBuilder,
@@ -361,7 +417,6 @@ function processSpecularGlossinessUniforms(
361
417
  );
362
418
  }
363
419
 
364
- const specularFactor = specularGlossiness.specularFactor;
365
420
  if (
366
421
  defined(specularFactor) &&
367
422
  !Cartesian3.equals(
@@ -371,20 +426,19 @@ function processSpecularGlossinessUniforms(
371
426
  ) {
372
427
  shaderBuilder.addUniform(
373
428
  "vec3",
374
- "u_specularFactor",
429
+ "u_legacySpecularFactor",
375
430
  ShaderDestination.FRAGMENT
376
431
  );
377
- uniformMap.u_specularFactor = function () {
432
+ uniformMap.u_legacySpecularFactor = function () {
378
433
  return specularGlossiness.specularFactor;
379
434
  };
380
435
  shaderBuilder.addDefine(
381
- "HAS_SPECULAR_FACTOR",
436
+ "HAS_LEGACY_SPECULAR_FACTOR",
382
437
  undefined,
383
438
  ShaderDestination.FRAGMENT
384
439
  );
385
440
  }
386
441
 
387
- const glossinessFactor = specularGlossiness.glossinessFactor;
388
442
  if (
389
443
  defined(glossinessFactor) &&
390
444
  glossinessFactor !== SpecularGlossiness.DEFAULT_GLOSSINESS_FACTOR
@@ -405,14 +459,277 @@ function processSpecularGlossinessUniforms(
405
459
  }
406
460
  }
407
461
 
462
+ /**
463
+ * Add uniforms and defines for the KHR_materials_specular extension
464
+ *
465
+ * @param {ModelComponents.Specular} specular
466
+ * @param {Object<string, Function>} uniformMap The uniform map to modify.
467
+ * @param {ShaderBuilder} shaderBuilder
468
+ * @param {Texture} defaultTexture
469
+ * @param {boolean} disableTextures
470
+ * @private
471
+ */
472
+ function processSpecularUniforms(
473
+ specular,
474
+ uniformMap,
475
+ shaderBuilder,
476
+ defaultTexture,
477
+ disableTextures
478
+ ) {
479
+ const {
480
+ specularTexture,
481
+ specularFactor,
482
+ specularColorTexture,
483
+ specularColorFactor,
484
+ } = specular;
485
+
486
+ shaderBuilder.addDefine(
487
+ "USE_SPECULAR",
488
+ undefined,
489
+ ShaderDestination.FRAGMENT
490
+ );
491
+
492
+ if (defined(specularTexture) && !disableTextures) {
493
+ processTexture(
494
+ shaderBuilder,
495
+ uniformMap,
496
+ specularTexture,
497
+ "u_specularTexture",
498
+ "SPECULAR",
499
+ defaultTexture
500
+ );
501
+ }
502
+
503
+ if (
504
+ defined(specularFactor) &&
505
+ specularFactor !== Specular.DEFAULT_SPECULAR_FACTOR
506
+ ) {
507
+ shaderBuilder.addUniform(
508
+ "float",
509
+ "u_specularFactor",
510
+ ShaderDestination.FRAGMENT
511
+ );
512
+ uniformMap.u_specularFactor = function () {
513
+ return specular.specularFactor;
514
+ };
515
+ shaderBuilder.addDefine(
516
+ "HAS_SPECULAR_FACTOR",
517
+ undefined,
518
+ ShaderDestination.FRAGMENT
519
+ );
520
+ }
521
+
522
+ if (defined(specularColorTexture) && !disableTextures) {
523
+ processTexture(
524
+ shaderBuilder,
525
+ uniformMap,
526
+ specularColorTexture,
527
+ "u_specularColorTexture",
528
+ "SPECULAR_COLOR",
529
+ defaultTexture
530
+ );
531
+ }
532
+
533
+ if (
534
+ defined(specularColorFactor) &&
535
+ !Cartesian3.equals(
536
+ specularColorFactor,
537
+ Specular.DEFAULT_SPECULAR_COLOR_FACTOR
538
+ )
539
+ ) {
540
+ shaderBuilder.addUniform(
541
+ "vec3",
542
+ "u_specularColorFactor",
543
+ ShaderDestination.FRAGMENT
544
+ );
545
+ uniformMap.u_specularColorFactor = function () {
546
+ return specular.specularColorFactor;
547
+ };
548
+ shaderBuilder.addDefine(
549
+ "HAS_SPECULAR_COLOR_FACTOR",
550
+ undefined,
551
+ ShaderDestination.FRAGMENT
552
+ );
553
+ }
554
+ }
555
+
556
+ const scratchAnisotropy = new Cartesian3();
557
+
558
+ /**
559
+ * Add uniforms and defines for the KHR_materials_anisotropy extension
560
+ *
561
+ * @param {ModelComponents.Anisotropy} anisotropy
562
+ * @param {Object<string, Function>} uniformMap The uniform map to modify.
563
+ * @param {ShaderBuilder} shaderBuilder
564
+ * @param {Texture} defaultTexture
565
+ * @param {boolean} disableTextures
566
+ * @private
567
+ */
568
+ function processAnisotropyUniforms(
569
+ anisotropy,
570
+ uniformMap,
571
+ shaderBuilder,
572
+ defaultTexture,
573
+ disableTextures
574
+ ) {
575
+ const {
576
+ anisotropyStrength,
577
+ anisotropyRotation,
578
+ anisotropyTexture,
579
+ } = anisotropy;
580
+
581
+ shaderBuilder.addDefine(
582
+ "USE_ANISOTROPY",
583
+ undefined,
584
+ ShaderDestination.FRAGMENT
585
+ );
586
+
587
+ if (defined(anisotropyTexture) && !disableTextures) {
588
+ processTexture(
589
+ shaderBuilder,
590
+ uniformMap,
591
+ anisotropyTexture,
592
+ "u_anisotropyTexture",
593
+ "ANISOTROPY",
594
+ defaultTexture
595
+ );
596
+ }
597
+
598
+ // Pre-compute cos and sin of rotation, since they are the same for all fragments.
599
+ // Combine with strength as one vec3 uniform.
600
+ const cosRotation = Math.cos(anisotropyRotation);
601
+ const sinRotation = Math.sin(anisotropyRotation);
602
+ shaderBuilder.addUniform("vec3", "u_anisotropy", ShaderDestination.FRAGMENT);
603
+ uniformMap.u_anisotropy = function () {
604
+ return Cartesian3.fromElements(
605
+ cosRotation,
606
+ sinRotation,
607
+ anisotropyStrength,
608
+ scratchAnisotropy
609
+ );
610
+ };
611
+ }
612
+
613
+ /**
614
+ * Add uniforms and defines for the KHR_materials_clearcoat extension
615
+ *
616
+ * @param {ModelComponents.Clearcoat} clearcoat
617
+ * @param {Object<string, Function>} uniformMap The uniform map to modify.
618
+ * @param {ShaderBuilder} shaderBuilder
619
+ * @param {Texture} defaultTexture
620
+ * @param {boolean} disableTextures
621
+ * @private
622
+ */
623
+ function processClearcoatUniforms(
624
+ clearcoat,
625
+ uniformMap,
626
+ shaderBuilder,
627
+ defaultTexture,
628
+ disableTextures
629
+ ) {
630
+ const {
631
+ clearcoatFactor,
632
+ clearcoatTexture,
633
+ clearcoatRoughnessFactor,
634
+ clearcoatRoughnessTexture,
635
+ clearcoatNormalTexture,
636
+ } = clearcoat;
637
+
638
+ shaderBuilder.addDefine(
639
+ "USE_CLEARCOAT",
640
+ undefined,
641
+ ShaderDestination.FRAGMENT
642
+ );
643
+
644
+ if (
645
+ defined(clearcoatFactor) &&
646
+ clearcoatFactor !== Clearcoat.DEFAULT_CLEARCOAT_FACTOR
647
+ ) {
648
+ shaderBuilder.addUniform(
649
+ "float",
650
+ "u_clearcoatFactor",
651
+ ShaderDestination.FRAGMENT
652
+ );
653
+ uniformMap.u_clearcoatFactor = function () {
654
+ return clearcoat.clearcoatFactor;
655
+ };
656
+ shaderBuilder.addDefine(
657
+ "HAS_CLEARCOAT_FACTOR",
658
+ undefined,
659
+ ShaderDestination.FRAGMENT
660
+ );
661
+ }
662
+
663
+ if (defined(clearcoatTexture) && !disableTextures) {
664
+ processTexture(
665
+ shaderBuilder,
666
+ uniformMap,
667
+ clearcoatTexture,
668
+ "u_clearcoatTexture",
669
+ "CLEARCOAT",
670
+ defaultTexture
671
+ );
672
+ }
673
+
674
+ if (
675
+ defined(clearcoatRoughnessFactor) &&
676
+ clearcoatFactor !== Clearcoat.DEFAULT_CLEARCOAT_ROUGHNESS_FACTOR
677
+ ) {
678
+ shaderBuilder.addUniform(
679
+ "float",
680
+ "u_clearcoatRoughnessFactor",
681
+ ShaderDestination.FRAGMENT
682
+ );
683
+ uniformMap.u_clearcoatRoughnessFactor = function () {
684
+ return clearcoat.clearcoatRoughnessFactor;
685
+ };
686
+ shaderBuilder.addDefine(
687
+ "HAS_CLEARCOAT_ROUGHNESS_FACTOR",
688
+ undefined,
689
+ ShaderDestination.FRAGMENT
690
+ );
691
+ }
692
+
693
+ if (defined(clearcoatRoughnessTexture) && !disableTextures) {
694
+ processTexture(
695
+ shaderBuilder,
696
+ uniformMap,
697
+ clearcoatRoughnessTexture,
698
+ "u_clearcoatRoughnessTexture",
699
+ "CLEARCOAT_ROUGHNESS",
700
+ defaultTexture
701
+ );
702
+ }
703
+
704
+ if (defined(clearcoatNormalTexture) && !disableTextures) {
705
+ processTexture(
706
+ shaderBuilder,
707
+ uniformMap,
708
+ clearcoatNormalTexture,
709
+ "u_clearcoatNormalTexture",
710
+ "CLEARCOAT_NORMAL",
711
+ defaultTexture
712
+ );
713
+ }
714
+ }
715
+
716
+ /**
717
+ * Add uniforms and defines for the PBR metallic roughness model
718
+ *
719
+ * @param {ModelComponents.MetallicRoughness} metallicRoughness
720
+ * @param {Object<string, Function>} uniformMap The uniform map to modify.
721
+ * @param {ShaderBuilder} shaderBuilder
722
+ * @param {Texture} defaultTexture
723
+ * @param {boolean} disableTextures
724
+ * @private
725
+ */
408
726
  function processMetallicRoughnessUniforms(
409
- material,
727
+ metallicRoughness,
410
728
  uniformMap,
411
729
  shaderBuilder,
412
730
  defaultTexture,
413
731
  disableTextures
414
732
  ) {
415
- const metallicRoughness = material.metallicRoughness;
416
733
  shaderBuilder.addDefine(
417
734
  "USE_METALLIC_ROUGHNESS",
418
735
  undefined,
@@ -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) {
@@ -2195,6 +2250,10 @@ function updatePickIds(model) {
2195
2250
  }
2196
2251
  }
2197
2252
 
2253
+ // Matrix3 is a row-major constructor.
2254
+ // The same constructor in GLSL will produce the transpose of this.
2255
+ const yUpToZUp = new Matrix3(-1, 0, 0, 0, 0, 1, 0, -1, 0);
2256
+
2198
2257
  function updateReferenceMatrices(model, frameState) {
2199
2258
  const modelMatrix = defined(model._clampedModelMatrix)
2200
2259
  ? model._clampedModelMatrix
@@ -2212,15 +2271,16 @@ function updateReferenceMatrices(model, frameState) {
2212
2271
  referenceMatrix,
2213
2272
  iblReferenceFrameMatrix4
2214
2273
  );
2215
- iblReferenceFrameMatrix3 = Matrix4.getMatrix3(
2274
+ iblReferenceFrameMatrix3 = Matrix4.getRotation(
2216
2275
  iblReferenceFrameMatrix4,
2217
2276
  iblReferenceFrameMatrix3
2218
2277
  );
2219
- iblReferenceFrameMatrix3 = Matrix3.getRotation(
2278
+ iblReferenceFrameMatrix3 = Matrix3.transpose(
2220
2279
  iblReferenceFrameMatrix3,
2221
2280
  iblReferenceFrameMatrix3
2222
2281
  );
2223
- model._iblReferenceFrameMatrix = Matrix3.transpose(
2282
+ model._iblReferenceFrameMatrix = Matrix3.multiply(
2283
+ yUpToZUp,
2224
2284
  iblReferenceFrameMatrix3,
2225
2285
  model._iblReferenceFrameMatrix
2226
2286
  );
@@ -2537,6 +2597,21 @@ Model.prototype.pick = function (
2537
2597
  );
2538
2598
  };
2539
2599
 
2600
+ /**
2601
+ * Gets whether or not clipping polygons are enabled for this model.
2602
+ *
2603
+ * @returns {boolean} <code>true</code> if clipping polygons are enabled for this model, <code>false</code>.
2604
+ * @private
2605
+ */
2606
+ Model.prototype.isClippingPolygonsEnabled = function () {
2607
+ const clippingPolygons = this._clippingPolygons;
2608
+ return (
2609
+ defined(clippingPolygons) &&
2610
+ clippingPolygons.enabled &&
2611
+ clippingPolygons.length !== 0
2612
+ );
2613
+ };
2614
+
2540
2615
  /**
2541
2616
  * Returns true if this object was destroyed; otherwise, false.
2542
2617
  * <br /><br />
@@ -2606,6 +2681,17 @@ Model.prototype.destroy = function () {
2606
2681
  }
2607
2682
  this._clippingPlanes = undefined;
2608
2683
 
2684
+ // Only destroy the ClippingPolygonCollection if this is the owner.
2685
+ const clippingPolygonCollection = this._clippingPolygons;
2686
+ if (
2687
+ defined(clippingPolygonCollection) &&
2688
+ !clippingPolygonCollection.isDestroyed() &&
2689
+ clippingPolygonCollection.owner === this
2690
+ ) {
2691
+ clippingPolygonCollection.destroy();
2692
+ }
2693
+ this._clippingPolygons = undefined;
2694
+
2609
2695
  // Only destroy the ImageBasedLighting if this is the owner.
2610
2696
  if (
2611
2697
  this._shouldDestroyImageBasedLighting &&
@@ -2689,6 +2775,7 @@ Model.prototype.destroyModelResources = function () {
2689
2775
  * @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
2776
  * @param {Color} [options.outlineColor=Color.BLACK] The color to use when rendering outlines.
2691
2777
  * @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.
2778
+ * @param {ClippingPolygonCollection} [options.clippingPolygons] The {@link ClippingPolygonCollection} used to selectively disable rendering the model.
2692
2779
  * @param {Cartesian3} [options.lightColor] The light color when shading the model. When <code>undefined</code> the scene's light color is used instead.
2693
2780
  * @param {ImageBasedLighting} [options.imageBasedLighting] The properties for managing image-based lighting on this model.
2694
2781
  * @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 +3138,7 @@ function makeModelOptions(loader, modelType, options) {
3051
3138
  showOutline: options.showOutline,
3052
3139
  outlineColor: options.outlineColor,
3053
3140
  clippingPlanes: options.clippingPlanes,
3141
+ clippingPolygons: options.clippingPolygons,
3054
3142
  lightColor: options.lightColor,
3055
3143
  imageBasedLighting: options.imageBasedLighting,
3056
3144
  backFaceCulling: options.backFaceCulling,