@cesium/engine 22.2.0 → 22.3.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 (215) hide show
  1. package/Build/Workers/{chunk-C35SJ4QP.js → chunk-2MLJ46ZZ.js} +13 -13
  2. package/Build/Workers/{chunk-JERDRSEI.js → chunk-4BBANFU6.js} +1 -1
  3. package/Build/Workers/{chunk-JONWM4IO.js → chunk-4O2ARYS7.js} +1 -1
  4. package/Build/Workers/{chunk-VGH2CSC7.js → chunk-4R6FGUFP.js} +9 -9
  5. package/Build/Workers/{chunk-IVN5HSOI.js → chunk-5PJB7ASO.js} +6 -6
  6. package/Build/Workers/{chunk-35J4D6PX.js → chunk-6GBGEUWR.js} +2 -2
  7. package/Build/Workers/{chunk-DCR62BCO.js → chunk-6WDMPXQ7.js} +12 -12
  8. package/Build/Workers/{chunk-4ZQN7M7E.js → chunk-7ATKQRBM.js} +10 -10
  9. package/Build/Workers/{chunk-FPRM6PCE.js → chunk-7SLNBIZS.js} +5 -34
  10. package/Build/Workers/{chunk-VSZ5DB2W.js → chunk-7U5YNLF3.js} +1 -1
  11. package/Build/Workers/{chunk-I4D5IP46.js → chunk-AFGP5BXS.js} +7 -7
  12. package/Build/Workers/{chunk-IWOSJVFQ.js → chunk-AWELU5C6.js} +14 -14
  13. package/Build/Workers/{chunk-LDSQMLRC.js → chunk-BO22JHBX.js} +3 -3
  14. package/Build/Workers/{chunk-2YVTOY5Z.js → chunk-D2PEV362.js} +10 -10
  15. package/Build/Workers/{chunk-PSHZAHFE.js → chunk-D63Z7KKL.js} +11 -11
  16. package/Build/Workers/{chunk-AMWXJ5A7.js → chunk-D6OKR3BQ.js} +2 -2
  17. package/Build/Workers/{chunk-I45CATZK.js → chunk-E4YDCSQK.js} +9 -9
  18. package/Build/Workers/{chunk-YFEZPDAY.js → chunk-EAAH543Q.js} +11 -11
  19. package/Build/Workers/{chunk-SDUH3N6G.js → chunk-EOSX23OS.js} +4 -4
  20. package/Build/Workers/{chunk-A3NUMZBG.js → chunk-EUDHHS7K.js} +6 -6
  21. package/Build/Workers/{chunk-BKYJBTHW.js → chunk-EY5HOJFQ.js} +5 -5
  22. package/Build/Workers/{chunk-64PJ4MTB.js → chunk-FDOLXORR.js} +7 -7
  23. package/Build/Workers/{chunk-WH4HDRGN.js → chunk-FS42VX2H.js} +2 -2
  24. package/Build/Workers/{chunk-ED4UXMYY.js → chunk-FUDC3KOT.js} +5 -5
  25. package/Build/Workers/{chunk-CQCEPC6N.js → chunk-HWGP4GVC.js} +13 -13
  26. package/Build/Workers/{chunk-QO6Z5UJE.js → chunk-IHFAFGR2.js} +2 -2
  27. package/Build/Workers/{chunk-72LZ3FN6.js → chunk-IXL46IYV.js} +12 -12
  28. package/Build/Workers/{chunk-JFN2DQHY.js → chunk-K2PLKJJG.js} +5 -5
  29. package/Build/Workers/{chunk-NY3CWLIZ.js → chunk-K4PGSAR5.js} +8 -8
  30. package/Build/Workers/{chunk-UBJYWGMV.js → chunk-KIJR26N3.js} +16 -16
  31. package/Build/Workers/{chunk-MWGB6DLR.js → chunk-L4OFWHNI.js} +1 -1
  32. package/Build/Workers/{chunk-XPNY2VY3.js → chunk-LK7GEFGB.js} +2 -2
  33. package/Build/Workers/{chunk-3JB2X2PR.js → chunk-LWZHJWYK.js} +6 -6
  34. package/Build/Workers/{chunk-ZGWX2R5I.js → chunk-LYBNPUEI.js} +4 -4
  35. package/Build/Workers/{chunk-4I7BCCNU.js → chunk-M5DVYXJJ.js} +6 -6
  36. package/Build/Workers/{chunk-4MCPC4TE.js → chunk-MASEF4OV.js} +8 -8
  37. package/Build/Workers/{chunk-FM5XPC2E.js → chunk-N66PIK46.js} +4 -4
  38. package/Build/Workers/{chunk-C6FTHSJA.js → chunk-N6XBJBI7.js} +6 -6
  39. package/Build/Workers/{chunk-7OPRTZBT.js → chunk-NO3LMU7T.js} +7 -7
  40. package/Build/Workers/{chunk-DIJ7IG5D.js → chunk-NVL7JXAQ.js} +10 -10
  41. package/Build/Workers/{chunk-O3GWUTWM.js → chunk-OOYICVOK.js} +1 -1
  42. package/Build/Workers/{chunk-K6BXEBAF.js → chunk-PJLRXIMS.js} +17 -17
  43. package/Build/Workers/{chunk-7CDQUIP5.js → chunk-S2KVL7OJ.js} +8 -8
  44. package/Build/Workers/{chunk-PMDPP22G.js → chunk-T5MJDW43.js} +7 -7
  45. package/Build/Workers/{chunk-GMHDOQPH.js → chunk-TCOUGKXF.js} +4 -4
  46. package/Build/Workers/{chunk-ZUWF63QU.js → chunk-TMGLPEZW.js} +4 -4
  47. package/Build/Workers/{chunk-JUOSYFXT.js → chunk-TY5JXMVO.js} +1 -1
  48. package/Build/Workers/{chunk-3HUEBDFC.js → chunk-VIQIKMTZ.js} +14 -14
  49. package/Build/Workers/{chunk-N5MNKWED.js → chunk-VRAAQ3FS.js} +2 -2
  50. package/Build/Workers/{chunk-K64RQCRK.js → chunk-W5NV72VR.js} +17 -17
  51. package/Build/Workers/{chunk-G6WQA27G.js → chunk-WHLGBMBC.js} +5 -5
  52. package/Build/Workers/{chunk-2JNPWPLE.js → chunk-WUWPKBOZ.js} +6 -6
  53. package/Build/Workers/{chunk-MSTAVM2N.js → chunk-XLIJV3YZ.js} +10 -10
  54. package/Build/Workers/{chunk-V26Y7ZQL.js → chunk-Y5MRBKQN.js} +37 -27
  55. package/Build/Workers/{chunk-L2FSBEW2.js → chunk-YHPBT4I5.js} +5 -5
  56. package/Build/Workers/{chunk-7MGTX4WP.js → chunk-ZGGVEGTA.js} +12 -12
  57. package/Build/Workers/{chunk-P7ISUYLW.js → chunk-ZWWN2CQH.js} +4 -4
  58. package/Build/Workers/combineGeometry.js +24 -24
  59. package/Build/Workers/createBoxGeometry.js +18 -18
  60. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  61. package/Build/Workers/createCircleGeometry.js +26 -26
  62. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  63. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  64. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  65. package/Build/Workers/createCorridorGeometry.js +29 -29
  66. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  67. package/Build/Workers/createCylinderGeometry.js +20 -20
  68. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  69. package/Build/Workers/createEllipseGeometry.js +26 -26
  70. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  71. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  73. package/Build/Workers/createFrustumGeometry.js +18 -18
  74. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  75. package/Build/Workers/createGeometry.js +24 -24
  76. package/Build/Workers/createGroundPolylineGeometry.js +22 -22
  77. package/Build/Workers/createPlaneGeometry.js +16 -16
  78. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  79. package/Build/Workers/createPolygonGeometry.js +32 -32
  80. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  81. package/Build/Workers/createPolylineGeometry.js +25 -25
  82. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  83. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  84. package/Build/Workers/createRectangleGeometry.js +27 -27
  85. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  86. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  87. package/Build/Workers/createSphereGeometry.js +19 -19
  88. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  89. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  90. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  91. package/Build/Workers/createVectorTileGeometries.js +24 -24
  92. package/Build/Workers/createVectorTilePoints.js +13 -13
  93. package/Build/Workers/createVectorTilePolygons.js +22 -22
  94. package/Build/Workers/createVectorTilePolylines.js +14 -14
  95. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  96. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  97. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  98. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  99. package/Build/Workers/createWallGeometry.js +24 -24
  100. package/Build/Workers/createWallOutlineGeometry.js +23 -23
  101. package/Build/Workers/decodeDraco.js +10 -10
  102. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  103. package/Build/Workers/decodeI3S.js +10 -10
  104. package/Build/Workers/gaussianSplatSorter.js +4 -4
  105. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  106. package/Build/Workers/incrementallyBuildTerrainPicker.js +20 -12
  107. package/Build/Workers/transcodeKTX2.js +6 -6
  108. package/Build/Workers/transferTypedArrayTest.js +1 -1
  109. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  110. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  111. package/Source/Core/BoxGeometry.js +1 -1
  112. package/Source/Core/CornerType.js +1 -1
  113. package/Source/Core/CorridorGeometry.js +1 -1
  114. package/Source/Core/FeatureDetection.js +1 -32
  115. package/Source/Core/Geometry.js +1 -1
  116. package/Source/Core/IntersectionTests.js +2 -2
  117. package/Source/Core/Ion.js +1 -1
  118. package/Source/Core/PinBuilder.js +1 -1
  119. package/Source/Core/PolygonGeometry.js +1 -1
  120. package/Source/Core/PolylineGeometry.js +1 -1
  121. package/Source/Core/PolylineVolumeGeometry.js +1 -1
  122. package/Source/Core/RectangleGeometry.js +1 -1
  123. package/Source/Core/ScreenSpaceEventHandler.js +4 -8
  124. package/Source/Core/TerrainMesh.js +11 -8
  125. package/Source/Core/TerrainPicker.js +24 -7
  126. package/Source/Core/VideoSynchronizer.js +1 -1
  127. package/Source/Core/WallGeometry.js +1 -1
  128. package/Source/Core/writeTextToCanvas.js +40 -86
  129. package/Source/DataSources/BillboardGraphics.js +1 -1
  130. package/Source/DataSources/BoxGraphics.js +1 -1
  131. package/Source/DataSources/CallbackPositionProperty.js +1 -1
  132. package/Source/DataSources/CorridorGraphics.js +1 -1
  133. package/Source/DataSources/CzmlDataSource.js +1 -1
  134. package/Source/DataSources/EllipseGraphics.js +1 -1
  135. package/Source/DataSources/EllipsoidGraphics.js +1 -1
  136. package/Source/DataSources/Entity.js +1 -1
  137. package/Source/DataSources/EntityCluster.js +2 -2
  138. package/Source/DataSources/GeoJsonDataSource.js +2 -2
  139. package/Source/DataSources/GpxDataSource.js +1 -1
  140. package/Source/DataSources/KmlDataSource.js +1 -1
  141. package/Source/DataSources/KmlTour.js +1 -1
  142. package/Source/DataSources/LabelGraphics.js +1 -1
  143. package/Source/DataSources/ModelGraphics.js +1 -1
  144. package/Source/DataSources/PlaneGraphics.js +1 -1
  145. package/Source/DataSources/PolygonGraphics.js +1 -1
  146. package/Source/DataSources/PolylineGraphics.js +1 -1
  147. package/Source/DataSources/PolylineVolumeGraphics.js +1 -1
  148. package/Source/DataSources/RectangleGraphics.js +1 -1
  149. package/Source/DataSources/WallGraphics.js +1 -1
  150. package/Source/DataSources/exportKml.js +1 -1
  151. package/Source/Renderer/Context.js +11 -10
  152. package/Source/Renderer/ContextLimits.js +66 -33
  153. package/Source/Renderer/ShaderSource.js +19 -18
  154. package/Source/Renderer/Texture.js +1 -1
  155. package/Source/Renderer/Texture3D.js +166 -7
  156. package/Source/Renderer/TextureAtlas.js +2 -2
  157. package/Source/Scene/Appearance.js +1 -1
  158. package/Source/Scene/ArcGisMapService.js +1 -1
  159. package/Source/Scene/Billboard.js +1 -1
  160. package/Source/Scene/BillboardCollection.js +1 -1
  161. package/Source/Scene/BillboardTexture.js +4 -1
  162. package/Source/Scene/Camera.js +13 -2
  163. package/Source/Scene/ClippingPlaneCollection.js +2 -2
  164. package/Source/Scene/CloudCollection.js +2 -2
  165. package/Source/Scene/CumulusCloud.js +1 -1
  166. package/Source/Scene/DynamicEnvironmentMapManager.js +41 -26
  167. package/Source/Scene/Fog.js +1 -1
  168. package/Source/Scene/GaussianSplatPrimitive.js +1 -1
  169. package/Source/Scene/Globe.js +3 -10
  170. package/Source/Scene/GltfLoader.js +10 -0
  171. package/Source/Scene/ImageBasedLighting.js +2 -2
  172. package/Source/Scene/ImageryLayerCollection.js +2 -2
  173. package/Source/Scene/ImageryProvider.js +2 -2
  174. package/Source/Scene/Label.js +1 -1
  175. package/Source/Scene/LabelCollection.js +1 -1
  176. package/Source/Scene/Material.js +1 -1
  177. package/Source/Scene/MaterialAppearance.js +1 -1
  178. package/Source/Scene/Megatexture.js +174 -242
  179. package/Source/Scene/Model/MaterialPipelineStage.js +17 -0
  180. package/Source/Scene/Model/Model.js +1 -1
  181. package/Source/Scene/ModelComponents.js +10 -0
  182. package/Source/Scene/ParticleSystem.js +2 -2
  183. package/Source/Scene/PointPrimitive.js +1 -1
  184. package/Source/Scene/Polyline.js +0 -1
  185. package/Source/Scene/PolylineCollection.js +1 -4
  186. package/Source/Scene/PolylineColorAppearance.js +1 -6
  187. package/Source/Scene/PolylineMaterialAppearance.js +1 -6
  188. package/Source/Scene/PostProcessStageCollection.js +1 -1
  189. package/Source/Scene/QuadtreePrimitive.js +6 -3
  190. package/Source/Scene/ShadowMap.js +1 -2
  191. package/Source/Scene/Vector3DTileClampedPolylines.js +1 -5
  192. package/Source/Scene/Vector3DTilePolylines.js +1 -5
  193. package/Source/Scene/VoxelPrimitive.js +16 -33
  194. package/Source/Scene/VoxelRenderResources.js +1 -8
  195. package/Source/Scene/VoxelTraversal.js +16 -61
  196. package/Source/Scene/WebMapTileServiceImageryProvider.js +1 -1
  197. package/Source/Scene/createElevationBandMaterial.js +1 -1
  198. package/Source/Scene/processVoxelProperties.js +1 -1
  199. package/Source/Shaders/Builtin/Functions/columbusViewMorph.glsl +8 -1
  200. package/Source/Shaders/Builtin/Functions/columbusViewMorph.js +8 -1
  201. package/Source/Shaders/Model/ModelFS.glsl +8 -0
  202. package/Source/Shaders/Model/ModelFS.js +8 -0
  203. package/Source/Shaders/Model/ModelVS.glsl +2 -0
  204. package/Source/Shaders/Model/ModelVS.js +2 -0
  205. package/Source/Shaders/Voxels/IntersectionUtils.glsl +1 -1
  206. package/Source/Shaders/Voxels/IntersectionUtils.js +1 -1
  207. package/Source/Shaders/Voxels/Megatexture.glsl +15 -83
  208. package/Source/Shaders/Voxels/Megatexture.js +15 -83
  209. package/Source/Shaders/Voxels/Octree.glsl +6 -9
  210. package/Source/Shaders/Voxels/Octree.js +6 -9
  211. package/Source/Widget/CesiumWidget.js +1 -1
  212. package/Source/Workers/incrementallyBuildTerrainPicker.js +16 -2
  213. package/index.d.ts +18 -4
  214. package/index.js +90 -90
  215. package/package.json +2 -1
@@ -1,17 +1,15 @@
1
- import Cartesian2 from "../Core/Cartesian2.js";
2
1
  import Cartesian3 from "../Core/Cartesian3.js";
3
- import ComponentDatatype from "../Core/ComponentDatatype.js";
2
+ import Check from "../Core/Check.js";
4
3
  import ContextLimits from "../Renderer/ContextLimits.js";
5
4
  import defined from "../Core/defined.js";
6
5
  import destroyObject from "../Core/destroyObject.js";
7
6
  import DeveloperError from "../Core/DeveloperError.js";
8
- import CesiumMath from "../Core/Math.js";
9
7
  import MetadataComponentType from "./MetadataComponentType.js";
10
8
  import PixelDatatype from "../Renderer/PixelDatatype.js";
11
9
  import PixelFormat from "../Core/PixelFormat.js";
12
10
  import RuntimeError from "../Core/RuntimeError.js";
13
11
  import Sampler from "../Renderer/Sampler.js";
14
- import Texture from "../Renderer/Texture.js";
12
+ import Texture3D from "../Renderer/Texture3D.js";
15
13
  import TextureMagnificationFilter from "../Renderer/TextureMagnificationFilter.js";
16
14
  import TextureMinificationFilter from "../Renderer/TextureMinificationFilter.js";
17
15
  import TextureWrap from "../Renderer/TextureWrap.js";
@@ -26,6 +24,9 @@ import TextureWrap from "../Renderer/TextureWrap.js";
26
24
  * @param {MetadataComponentType} componentType The component type of the metadata.
27
25
  * @param {number} [availableTextureMemoryBytes=134217728] An upper limit on the texture memory size in bytes.
28
26
  *
27
+ * @exception {RuntimeError} The GL context does not support a 3D texture large enough to contain a tile with the given dimensions.
28
+ * @exception {RuntimeError} Not enough texture memory available to create a megatexture with the given tile dimensions.
29
+ *
29
30
  * @private
30
31
  */
31
32
  function Megatexture(
@@ -33,52 +34,28 @@ function Megatexture(
33
34
  dimensions,
34
35
  channelCount,
35
36
  componentType,
36
- availableTextureMemoryBytes,
37
+ availableTextureMemoryBytes = 134217728, // 128 MB
38
+ tileCount,
37
39
  ) {
38
- const maximumTextureMemoryByteLength = 512 * 1024 * 1024;
39
- availableTextureMemoryBytes = Math.min(
40
- availableTextureMemoryBytes ?? 128 * 1024 * 1024,
41
- maximumTextureMemoryByteLength,
42
- );
43
-
44
40
  // TODO there are a lot of texture packing rules, see https://github.com/CesiumGS/cesium/issues/9572
45
- // Unsigned short textures not allowed in webgl 1, so treat as float
46
- if (componentType === MetadataComponentType.UNSIGNED_SHORT) {
47
- componentType = MetadataComponentType.FLOAT32;
48
- }
49
-
50
- if (
51
- componentType === MetadataComponentType.FLOAT32 &&
52
- !context.floatingPointTexture
53
- ) {
54
- throw new RuntimeError("Floating point texture not supported");
55
- }
56
-
57
41
  const pixelDataType = getPixelDataType(componentType);
58
- const pixelFormat = getPixelFormat(channelCount, context.webgl2);
59
- const componentTypeByteLength =
60
- MetadataComponentType.getSizeInBytes(componentType);
61
- const textureDimension = getTextureDimension(
42
+ const pixelFormat = getPixelFormat(channelCount);
43
+
44
+ const bytesPerSample =
45
+ channelCount * MetadataComponentType.getSizeInBytes(componentType);
46
+ const textureDimension = Megatexture.get3DTextureDimension(
47
+ dimensions,
48
+ bytesPerSample,
62
49
  availableTextureMemoryBytes,
63
- channelCount,
64
- componentTypeByteLength,
50
+ tileCount,
65
51
  );
66
52
 
67
- const sliceCountPerRegionX = Math.ceil(Math.sqrt(dimensions.x));
68
- const sliceCountPerRegionY = Math.ceil(dimensions.z / sliceCountPerRegionX);
69
- const voxelCountPerRegionX = sliceCountPerRegionX * dimensions.x;
70
- const voxelCountPerRegionY = sliceCountPerRegionY * dimensions.y;
71
- const regionCountPerMegatextureX = Math.floor(
72
- textureDimension / voxelCountPerRegionX,
73
- );
74
- const regionCountPerMegatextureY = Math.floor(
75
- textureDimension / voxelCountPerRegionY,
53
+ const tileCounts = Cartesian3.divideComponents(
54
+ textureDimension,
55
+ dimensions,
56
+ new Cartesian3(),
76
57
  );
77
58
 
78
- if (regionCountPerMegatextureX === 0 || regionCountPerMegatextureY === 0) {
79
- throw new RuntimeError("Tileset is too large to fit into megatexture");
80
- }
81
-
82
59
  /**
83
60
  * @type {number}
84
61
  * @readonly
@@ -96,87 +73,43 @@ function Megatexture(
96
73
  * @readonly
97
74
  */
98
75
  this.textureMemoryByteLength =
99
- componentTypeByteLength * channelCount * textureDimension ** 2;
76
+ bytesPerSample *
77
+ textureDimension.x *
78
+ textureDimension.y *
79
+ textureDimension.z;
100
80
 
101
81
  /**
102
82
  * @type {Cartesian3}
103
83
  * @readonly
104
84
  */
105
- this.voxelCountPerTile = Cartesian3.clone(dimensions, new Cartesian3());
106
-
107
- /**
108
- * @type {number}
109
- * @readonly
110
- */
111
- this.maximumTileCount =
112
- regionCountPerMegatextureX * regionCountPerMegatextureY;
113
-
114
- /**
115
- * @type {Cartesian2}
116
- * @readonly
117
- */
118
- this.regionCountPerMegatexture = new Cartesian2(
119
- regionCountPerMegatextureX,
120
- regionCountPerMegatextureY,
121
- );
85
+ this.tileCounts = Cartesian3.clone(tileCounts, new Cartesian3());
122
86
 
123
87
  /**
124
- * @type {Cartesian2}
125
- * @readonly
126
- */
127
- this.voxelCountPerRegion = new Cartesian2(
128
- voxelCountPerRegionX,
129
- voxelCountPerRegionY,
130
- );
131
-
132
- /**
133
- * @type {Cartesian2}
134
- * @readonly
135
- */
136
- this.sliceCountPerRegion = new Cartesian2(
137
- sliceCountPerRegionX,
138
- sliceCountPerRegionY,
139
- );
140
-
141
- /**
142
- * @type {Cartesian2}
143
- * @readonly
144
- */
145
- this.voxelSizeUv = new Cartesian2(
146
- 1.0 / textureDimension,
147
- 1.0 / textureDimension,
148
- );
149
-
150
- /**
151
- * @type {Cartesian2}
88
+ * @type {Cartesian3}
152
89
  * @readonly
153
90
  */
154
- this.sliceSizeUv = new Cartesian2(
155
- dimensions.x / textureDimension,
156
- dimensions.y / textureDimension,
157
- );
91
+ this.voxelCountPerTile = Cartesian3.clone(dimensions, new Cartesian3());
158
92
 
159
93
  /**
160
- * @type {Cartesian2}
94
+ * @type {number}
161
95
  * @readonly
162
96
  */
163
- this.regionSizeUv = new Cartesian2(
164
- voxelCountPerRegionX / textureDimension,
165
- voxelCountPerRegionY / textureDimension,
166
- );
97
+ this.maximumTileCount = tileCounts.x * tileCounts.y * tileCounts.z;
167
98
 
168
99
  /**
169
- * @type {Texture}
100
+ * @type {Texture3D}
170
101
  * @readonly
171
102
  */
172
- this.texture = new Texture({
103
+ this.texture = new Texture3D({
173
104
  context: context,
174
105
  pixelFormat: pixelFormat,
175
106
  pixelDatatype: pixelDataType,
176
107
  flipY: false,
177
- width: textureDimension,
178
- height: textureDimension,
108
+ width: textureDimension.x,
109
+ height: textureDimension.y,
110
+ depth: textureDimension.z,
179
111
  sampler: new Sampler({
112
+ wrapR: TextureWrap.CLAMP_TO_EDGE,
180
113
  wrapS: TextureWrap.CLAMP_TO_EDGE,
181
114
  wrapT: TextureWrap.CLAMP_TO_EDGE,
182
115
  minificationFilter: TextureMinificationFilter.LINEAR,
@@ -184,17 +117,6 @@ function Megatexture(
184
117
  }),
185
118
  });
186
119
 
187
- const componentDatatype =
188
- MetadataComponentType.toComponentDatatype(componentType);
189
-
190
- /**
191
- * @type {Array}
192
- */
193
- this.tileVoxelDataTemp = ComponentDatatype.createTypedArray(
194
- componentDatatype,
195
- voxelCountPerRegionX * voxelCountPerRegionY * channelCount,
196
- );
197
-
198
120
  /**
199
121
  * @type {MegatextureNode[]}
200
122
  * @readonly
@@ -229,8 +151,42 @@ function Megatexture(
229
151
  * @readonly
230
152
  */
231
153
  this.occupiedCount = 0;
154
+
155
+ this._nearestSampling = false;
232
156
  }
233
157
 
158
+ Object.defineProperties(Megatexture.prototype, {
159
+ /**
160
+ * Gets or sets the nearest sampling flag.
161
+ * @type {boolean}
162
+ */
163
+ nearestSampling: {
164
+ get: function () {
165
+ return this._nearestSampling;
166
+ },
167
+ set: function (nearestSampling) {
168
+ //>>includeStart('debug', pragmas.debug);
169
+ Check.typeOf.bool("nearestSampling", nearestSampling);
170
+ //>>includeEnd('debug');
171
+ if (this._nearestSampling === nearestSampling) {
172
+ return;
173
+ }
174
+ if (nearestSampling) {
175
+ this.texture.sampler = Sampler.NEAREST;
176
+ } else {
177
+ this.texture.sampler = new Sampler({
178
+ wrapR: TextureWrap.CLAMP_TO_EDGE,
179
+ wrapS: TextureWrap.CLAMP_TO_EDGE,
180
+ wrapT: TextureWrap.CLAMP_TO_EDGE,
181
+ minificationFilter: TextureMinificationFilter.LINEAR,
182
+ magnificationFilter: TextureMagnificationFilter.LINEAR,
183
+ });
184
+ }
185
+ this._nearestSampling = nearestSampling;
186
+ },
187
+ },
188
+ });
189
+
234
190
  /**
235
191
  * Get the pixel data type to use in a megatexture.
236
192
  * TODO support more
@@ -255,49 +211,23 @@ function getPixelDataType(componentType) {
255
211
  * Get the pixel format to use for a megatexture.
256
212
  *
257
213
  * @param {number} channelCount The number of channels in the metadata. Must be 1 to 4.
258
- * @param {boolean} webgl2 true if the context is using webgl2
259
214
  * @returns {PixelFormat} The pixel format to use for a megatexture.
260
215
  *
261
216
  * @private
262
217
  */
263
- function getPixelFormat(channelCount, webgl2) {
264
- if (channelCount === 1) {
265
- return webgl2 ? PixelFormat.RED : PixelFormat.LUMINANCE;
266
- } else if (channelCount === 2) {
267
- return webgl2 ? PixelFormat.RG : PixelFormat.LUMINANCE_ALPHA;
268
- } else if (channelCount === 3) {
269
- return PixelFormat.RGB;
270
- } else if (channelCount === 4) {
271
- return PixelFormat.RGBA;
218
+ function getPixelFormat(channelCount) {
219
+ switch (channelCount) {
220
+ case 1:
221
+ return PixelFormat.RED;
222
+ case 2:
223
+ return PixelFormat.RG;
224
+ case 3:
225
+ return PixelFormat.RGB;
226
+ case 4:
227
+ return PixelFormat.RGBA;
272
228
  }
273
229
  }
274
230
 
275
- /**
276
- * Compute the largest size of a square texture that will fit in the available memory.
277
- *
278
- * @param {number} availableTextureMemoryBytes An upper limit on the texture memory size.
279
- * @param {number} channelCount The number of metadata channels per texel.
280
- * @param {number} componentByteLength The byte length of each component of the metadata.
281
- * @returns {number} The dimension of the square texture to use for the megatexture.
282
- *
283
- * @private
284
- */
285
- function getTextureDimension(
286
- availableTextureMemoryBytes,
287
- channelCount,
288
- componentByteLength,
289
- ) {
290
- // Compute how many texels will fit in the available memory
291
- const texelCount = Math.floor(
292
- availableTextureMemoryBytes / (channelCount * componentByteLength),
293
- );
294
- // Return the largest power of two texture size that will fit in memory
295
- return Math.min(
296
- ContextLimits.maximumTextureSize,
297
- CesiumMath.previousPowerOfTwo(Math.floor(Math.sqrt(texelCount))),
298
- );
299
- }
300
-
301
231
  /**
302
232
  * @alias MegatextureNode
303
233
  * @constructor
@@ -327,6 +257,8 @@ function MegatextureNode(index) {
327
257
  * Add an array of tile metadata to the megatexture.
328
258
  * @param {Array} data The data to be added.
329
259
  * @returns {number} The index of the tile's location in the megatexture.
260
+ *
261
+ * @exception {DeveloperError} Trying to add when there are no empty spots.
330
262
  */
331
263
  Megatexture.prototype.add = function (data) {
332
264
  if (this.isFull()) {
@@ -356,6 +288,7 @@ Megatexture.prototype.add = function (data) {
356
288
 
357
289
  /**
358
290
  * @param {number} index
291
+ * @exception {DeveloperError} Megatexture index out of bounds.
359
292
  */
360
293
  Megatexture.prototype.remove = function (index) {
361
294
  if (index < 0 || index >= this.maximumTileCount) {
@@ -389,130 +322,129 @@ Megatexture.prototype.isFull = function () {
389
322
  };
390
323
 
391
324
  /**
392
- * @param {number} tileCount The total number of tiles in the tileset.
393
- * @param {Cartesian3} dimensions The number of voxels in each dimension of the tile.
394
- * @param {number} channelCount The number of channels in the metadata.
395
- * @param {MetadataComponentType} componentType The type of one channel of the metadata.
396
- * @returns {number}
325
+ * Compute a 3D texture dimension that contains the given number of tiles, or as many tiles as can fit within the available texture memory.
326
+ * Not used outside the class, but exposed for testing.
327
+ * @param {Cartesian3} tileDimensions The dimensions of one tile in number of voxels.
328
+ * @param {number} bytesPerSample The number of bytes per voxel sample.
329
+ * @param {number} availableTextureMemoryBytes An upper limit on the texture memory size in bytes.
330
+ * @param {number} [tileCount] The total number of tiles in the tileset.
331
+ * @returns {Cartesian3} The computed 3D texture dimensions.
332
+ *
333
+ * @exception {RuntimeError} The GL context does not support a 3D texture large enough to contain a tile with the given dimensions.
334
+ * @exception {RuntimeError} Not enough texture memory available to create a megatexture with the given tile dimensions.
335
+ * @private
397
336
  */
398
- Megatexture.getApproximateTextureMemoryByteLength = function (
337
+ Megatexture.get3DTextureDimension = function (
338
+ tileDimensions,
339
+ bytesPerSample,
340
+ availableTextureMemoryBytes,
399
341
  tileCount,
400
- dimensions,
401
- channelCount,
402
- componentType,
403
342
  ) {
404
- // TODO there's a lot of code duplicate with Megatexture constructor
343
+ const { maximum3DTextureSize } = ContextLimits;
344
+ if (Cartesian3.maximumComponent(tileDimensions) > maximum3DTextureSize) {
345
+ throw new RuntimeError(
346
+ "The GL context does not support a 3D texture large enough to contain a tile with the given dimensions.",
347
+ );
348
+ }
405
349
 
406
- // Unsigned short textures not allowed in webgl 1, so treat as float
407
- if (componentType === MetadataComponentType.UNSIGNED_SHORT) {
408
- componentType = MetadataComponentType.FLOAT32;
350
+ // Find the number of tiles we can fit.
351
+ const tileSizeInBytes =
352
+ bytesPerSample * tileDimensions.x * tileDimensions.y * tileDimensions.z;
353
+ const maxTileCount = Math.floor(
354
+ availableTextureMemoryBytes / tileSizeInBytes,
355
+ );
356
+ if (maxTileCount < 1) {
357
+ throw new RuntimeError(
358
+ "Not enough texture memory available to create a megatexture with the given tile dimensions.",
359
+ );
409
360
  }
410
361
 
411
- const datatypeSizeInBytes =
412
- MetadataComponentType.getSizeInBytes(componentType);
413
- const voxelCountTotal =
414
- tileCount * dimensions.x * dimensions.y * dimensions.z;
362
+ if (defined(tileCount)) {
363
+ tileCount = Math.min(tileCount, maxTileCount);
364
+ } else {
365
+ tileCount = maxTileCount;
366
+ }
415
367
 
416
- const sliceCountPerRegionX = Math.ceil(Math.sqrt(dimensions.x));
417
- const sliceCountPerRegionY = Math.ceil(dimensions.z / sliceCountPerRegionX);
418
- const voxelCountPerRegionX = sliceCountPerRegionX * dimensions.x;
419
- const voxelCountPerRegionY = sliceCountPerRegionY * dimensions.y;
368
+ // Sort the tile dimensions from largest to smallest.
369
+ const sortedDimensions = Object.entries(tileDimensions).sort(
370
+ (a, b) => b[1] - a[1],
371
+ );
420
372
 
421
- // Find the power of two that can fit all tile data, accounting for slices.
422
- // There's probably a non-iterative solution for this, but this is good enough for now.
423
- let textureDimension = CesiumMath.previousPowerOfTwo(
424
- Math.floor(Math.sqrt(voxelCountTotal)),
373
+ // Compute the number of tiles that we can fit along each axis of a 3D texture,
374
+ // starting from the largest texture the context can support
375
+ const tilesPerDimension = sortedDimensions.map(([axis, dimension]) =>
376
+ Math.floor(maximum3DTextureSize / dimension),
425
377
  );
426
- for (;;) {
427
- const regionCountX = Math.floor(textureDimension / voxelCountPerRegionX);
428
- const regionCountY = Math.floor(textureDimension / voxelCountPerRegionY);
429
- const regionCount = regionCountX * regionCountY;
430
- if (regionCount >= tileCount) {
378
+
379
+ // Reduce the number of tiles along each dimension until the total number of
380
+ // tiles is close to but not less than tileCount.
381
+ // Start from the dimension along which the tiles are largest, since
382
+ // along this dimension each removed slice will contain the most tiles.
383
+ for (let i = 0; i < 3; i++) {
384
+ const currentTileCount = getVolume(tilesPerDimension);
385
+ if (currentTileCount < tileCount) {
431
386
  break;
432
- } else {
433
- textureDimension *= 2;
434
387
  }
388
+ const sliceDimensions = tilesPerDimension.slice();
389
+ sliceDimensions.splice(i, 1);
390
+ const tilesPerSlice = sliceDimensions[0] * sliceDimensions[1];
391
+ const excessTiles = currentTileCount - tileCount;
392
+ const slicesToRemove = Math.floor(excessTiles / tilesPerSlice);
393
+ tilesPerDimension[i] -= slicesToRemove;
435
394
  }
436
395
 
437
- const textureMemoryByteLength =
438
- textureDimension * textureDimension * channelCount * datatypeSizeInBytes;
439
- return textureMemoryByteLength;
396
+ // Make sure we are less than maximumTileCount (to fit within memory)
397
+ if (getVolume(tilesPerDimension) > maxTileCount) {
398
+ tilesPerDimension[2] = Math.floor(
399
+ maxTileCount / (tilesPerDimension[0] * tilesPerDimension[1]),
400
+ );
401
+ }
402
+
403
+ // Compute the final texture dimensions
404
+ const textureDimension = new Cartesian3();
405
+ for (let i = 0; i < 3; i++) {
406
+ const [axis, dimension] = sortedDimensions[i];
407
+ textureDimension[axis] = tilesPerDimension[i] * dimension;
408
+ }
409
+
410
+ return textureDimension;
440
411
  };
441
412
 
413
+ function getVolume(dimensionsArray) {
414
+ return dimensionsArray.reduce((p, d) => p * d);
415
+ }
416
+
442
417
  /**
443
418
  * Write an array of tile metadata to the megatexture.
444
419
  * @param {number} index The index of the tile's location in the megatexture.
445
- * @param {Float32Array|Uint16Array|Uint8Array} data The data to be written.
420
+ * @param {Float32Array|Uint16Array|Uint8Array} tileData The data to be written.
446
421
  */
447
- Megatexture.prototype.writeDataToTexture = function (index, data) {
448
- // Unsigned short textures not allowed in webgl 1, so treat as float
449
- const tileData =
450
- data.constructor === Uint16Array ? new Float32Array(data) : data;
451
-
452
- const {
453
- tileVoxelDataTemp,
454
- voxelCountPerTile,
455
- sliceCountPerRegion,
456
- voxelCountPerRegion,
457
- channelCount,
458
- regionCountPerMegatexture,
459
- } = this;
460
-
461
- for (let z = 0; z < voxelCountPerTile.z; z++) {
462
- const sliceVoxelOffsetX = (z % sliceCountPerRegion.x) * voxelCountPerTile.x;
463
- const sliceVoxelOffsetY =
464
- Math.floor(z / sliceCountPerRegion.x) * voxelCountPerTile.y;
465
- for (let y = 0; y < voxelCountPerTile.y; y++) {
466
- const readOffset = getReadOffset(voxelCountPerTile, y, z);
467
- const writeOffset =
468
- (sliceVoxelOffsetY + y) * voxelCountPerRegion.x + sliceVoxelOffsetX;
469
- for (let x = 0; x < voxelCountPerTile.x; x++) {
470
- const readIndex = readOffset + x;
471
- const writeIndex = writeOffset + x;
472
- for (let c = 0; c < channelCount; c++) {
473
- tileVoxelDataTemp[writeIndex * channelCount + c] =
474
- tileData[readIndex * channelCount + c];
475
- }
476
- }
477
- }
478
- }
479
-
480
- const voxelOffsetX =
481
- (index % regionCountPerMegatexture.x) * voxelCountPerRegion.x;
482
- const voxelOffsetY =
483
- Math.floor(index / regionCountPerMegatexture.x) * voxelCountPerRegion.y;
422
+ Megatexture.prototype.writeDataToTexture = function (index, tileData) {
423
+ const { tileCounts, voxelCountPerTile } = this;
484
424
 
485
425
  const source = {
486
- arrayBufferView: tileVoxelDataTemp,
487
- width: voxelCountPerRegion.x,
488
- height: voxelCountPerRegion.y,
426
+ arrayBufferView: tileData,
427
+ width: voxelCountPerTile.x,
428
+ height: voxelCountPerTile.y,
429
+ depth: voxelCountPerTile.z,
489
430
  };
490
431
 
432
+ const tilesPerZ = tileCounts.x * tileCounts.y;
433
+ const iz = Math.floor(index / tilesPerZ);
434
+ const remainder = index - iz * tilesPerZ;
435
+ const iy = Math.floor(remainder / tileCounts.x);
436
+ const ix = remainder - iy * tileCounts.x;
437
+
491
438
  const copyOptions = {
492
439
  source: source,
493
- xOffset: voxelOffsetX,
494
- yOffset: voxelOffsetY,
440
+ xOffset: ix * voxelCountPerTile.x,
441
+ yOffset: iy * voxelCountPerTile.y,
442
+ zOffset: iz * voxelCountPerTile.z,
495
443
  };
496
444
 
497
445
  this.texture.copyFrom(copyOptions);
498
446
  };
499
447
 
500
- /**
501
- * Get the offset into the data array for a given row of contiguous voxel data.
502
- *
503
- * @param {Cartesian3} dimensions The number of voxels in each dimension of the tile.
504
- * @param {number} y The y index of the voxel row
505
- * @param {number} z The z index of the voxel row
506
- * @returns {number} The offset into the data array
507
- * @private
508
- */
509
- function getReadOffset(dimensions, y, z) {
510
- const voxelsPerInputSlice = dimensions.y * dimensions.x;
511
- const sliceIndex = z;
512
- const rowIndex = y;
513
- return sliceIndex * voxelsPerInputSlice + rowIndex * dimensions.x;
514
- }
515
-
516
448
  /**
517
449
  * Returns true if this object was destroyed; otherwise, false.
518
450
  * <br /><br />
@@ -167,6 +167,23 @@ MaterialPipelineStage.process = function (
167
167
  alphaOptions.alphaCutoff = material.alphaCutoff;
168
168
  }
169
169
 
170
+ // Configure and handle point diameter for POINTS primitives (BENTLEY_materials_point_style extension).
171
+ if (defined(material.pointDiameter)) {
172
+ shaderBuilder.addDefine(
173
+ "HAS_POINT_DIAMETER",
174
+ undefined,
175
+ ShaderDestination.VERTEX,
176
+ );
177
+ shaderBuilder.addUniform(
178
+ "float",
179
+ "u_pointDiameter",
180
+ ShaderDestination.VERTEX,
181
+ );
182
+ uniformMap.u_pointDiameter = function () {
183
+ return material.pointDiameter * frameState.pixelRatio;
184
+ };
185
+ }
186
+
170
187
  shaderBuilder.addFragmentLines(MaterialStageFS);
171
188
 
172
189
  if (material.doubleSided) {
@@ -175,7 +175,7 @@ import ModelImagery from "./ModelImagery.js";
175
175
  *
176
176
  * @see Model.fromGltfAsync
177
177
  *
178
- * @demo {@link https://sandcastle.cesium.com/index.html?src=3D%20Models.html|Cesium Sandcastle Models Demo}
178
+ * @demo {@link https://sandcastle.cesium.com/index.html?id=3d-models|Cesium Sandcastle Models Demo}
179
179
  */
180
180
  function Model(options) {
181
181
  options = options ?? Frozen.EMPTY_OBJECT;
@@ -1623,6 +1623,16 @@ function Material() {
1623
1623
  * @private
1624
1624
  */
1625
1625
  this.unlit = false;
1626
+
1627
+ /**
1628
+ * The point diameter in pixels for POINTS primitives. This is set by the
1629
+ * BENTLEY_materials_point_style extension.
1630
+ *
1631
+ * @type {number|undefined}
1632
+ * @default undefined
1633
+ * @private
1634
+ */
1635
+ this.pointDiameter = undefined;
1626
1636
  }
1627
1637
 
1628
1638
  /**
@@ -52,8 +52,8 @@ const defaultImageSize = new Cartesian2(1.0, 1.0);
52
52
  * @param {number} [options.minimumMass] Sets the minimum bound for the mass of a particle in kilograms. A particle's actual mass will be chosen as a random amount above this value.
53
53
  * @param {number} [options.maximumMass] Sets the maximum mass of particles in kilograms. A particle's actual mass will be chosen as a random amount below this value.
54
54
  * @demo {@link https://cesium.com/learn/cesiumjs-learn/cesiumjs-particle-systems/|Particle Systems Tutorial}
55
- * @demo {@link https://sandcastle.cesium.com/?src=Particle%20System.html&label=Showcases|Particle Systems Tutorial Demo}
56
- * @demo {@link https://sandcastle.cesium.com/?src=Particle%20System%20Fireworks.html&label=Showcases|Particle Systems Fireworks Demo}
55
+ * @demo {@link https://sandcastle.cesium.com/?id=particle-system|Particle Systems Tutorial Demo}
56
+ * @demo {@link https://sandcastle.cesium.com/?id=particle-system-fireworks|Particle Systems Fireworks Demo}
57
57
  */
58
58
  function ParticleSystem(options) {
59
59
  options = options ?? Frozen.EMPTY_OBJECT;
@@ -39,7 +39,7 @@ import SplitDirection from "./SplitDirection.js";
39
39
  * @internalConstructor
40
40
  * @class
41
41
  *
42
- * @demo {@link https://sandcastle.cesium.com/index.html?src=Points.html|Cesium Sandcastle Points Demo}
42
+ * @demo {@link https://sandcastle.cesium.com/index.html?id=points|Cesium Sandcastle Points Demo}
43
43
  */
44
44
  function PointPrimitive(options, pointPrimitiveCollection) {
45
45
  options = options ?? Frozen.EMPTY_OBJECT;
@@ -83,7 +83,6 @@ function Polyline(options, polylineCollection) {
83
83
 
84
84
  this._actualLength = undefined;
85
85
 
86
- // eslint-disable-next-line no-use-before-define
87
86
  this._propertiesChanged = new Uint32Array(NUMBER_OF_PROPERTIES);
88
87
  this._polylineCollection = polylineCollection;
89
88
  this._dirty = false;
@@ -11,7 +11,6 @@ import defined from "../Core/defined.js";
11
11
  import destroyObject from "../Core/destroyObject.js";
12
12
  import DeveloperError from "../Core/DeveloperError.js";
13
13
  import EncodedCartesian3 from "../Core/EncodedCartesian3.js";
14
- import FeatureDetection from "../Core/FeatureDetection.js";
15
14
  import IndexDatatype from "../Core/IndexDatatype.js";
16
15
  import Intersect from "../Core/Intersect.js";
17
16
  import CesiumMath from "../Core/Math.js";
@@ -1294,9 +1293,7 @@ PolylineBucket.prototype.updateShader = function (
1294
1293
  defines.push("POLYLINE_DASH");
1295
1294
  }
1296
1295
 
1297
- if (!FeatureDetection.isInternetExplorer()) {
1298
- defines.push("CLIP_POLYLINE");
1299
- }
1296
+ defines.push("CLIP_POLYLINE");
1300
1297
 
1301
1298
  const fs = new ShaderSource({
1302
1299
  defines: defines,