@cesium/engine 13.1.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/Build/Workers/{chunk-APCS5YJI.js → chunk-25TOENEE.js} +7 -7
  2. package/Build/Workers/{chunk-FNCXBBCF.js → chunk-2AVIUB5H.js} +2 -2
  3. package/Build/Workers/{chunk-OZTFRHA2.js → chunk-3JZGPJMZ.js} +6 -6
  4. package/Build/Workers/{chunk-5JY4LYO3.js → chunk-3LHBH4TC.js} +7 -7
  5. package/Build/Workers/{chunk-MGABCOOH.js → chunk-3LZF23RY.js} +6 -6
  6. package/Build/Workers/{chunk-AXYZUG4N.js → chunk-5S2B46UQ.js} +1 -1
  7. package/Build/Workers/{chunk-2SRHVCFD.js → chunk-67ONR44K.js} +6 -6
  8. package/Build/Workers/{chunk-PBJQFLKS.js → chunk-6EDBC234.js} +11 -11
  9. package/Build/Workers/{chunk-GSLKQJM2.js → chunk-6EV4VOET.js} +10 -10
  10. package/Build/Workers/{chunk-OGRXNUR2.js → chunk-7ITUZTFH.js} +1 -1
  11. package/Build/Workers/{chunk-IP7F2MVW.js → chunk-ARVZCY6X.js} +7 -7
  12. package/Build/Workers/{chunk-EYZFEJX3.js → chunk-B2UQN3DH.js} +6 -6
  13. package/Build/Workers/{chunk-WE4KF4AM.js → chunk-B2Y4ZS6X.js} +9 -9
  14. package/Build/Workers/{chunk-DWIKWWEE.js → chunk-BD2TPFGC.js} +5 -5
  15. package/Build/Workers/{chunk-5ICYLS6B.js → chunk-CHX2K5AC.js} +10 -10
  16. package/Build/Workers/{chunk-NQDKNE7V.js → chunk-CJGVEABL.js} +13 -13
  17. package/Build/Workers/{chunk-B34JXFHF.js → chunk-DYJHEP3B.js} +5 -5
  18. package/Build/Workers/{chunk-J7BMSSY7.js → chunk-E3H7AVMK.js} +13 -13
  19. package/Build/Workers/{chunk-TOHDFUJM.js → chunk-EZNAJPP5.js} +4 -4
  20. package/Build/Workers/{chunk-K62EHZFT.js → chunk-F7ZI463G.js} +15 -15
  21. package/Build/Workers/{chunk-EJ5DT5BP.js → chunk-FMZ5CX6V.js} +1 -1
  22. package/Build/Workers/{chunk-OARMSJUU.js → chunk-FRAWHNSR.js} +2 -2
  23. package/Build/Workers/{chunk-S3UM4OKP.js → chunk-GGV2XJHE.js} +7 -7
  24. package/Build/Workers/{chunk-SAKQO5NX.js → chunk-GK4QU6QI.js} +2 -2
  25. package/Build/Workers/{chunk-LFUFGHL3.js → chunk-HYPB7FAV.js} +10 -10
  26. package/Build/Workers/{chunk-3SCCWLZS.js → chunk-I4HO2ED2.js} +9 -9
  27. package/Build/Workers/{chunk-K6SQV4IS.js → chunk-IGINOLDX.js} +6 -6
  28. package/Build/Workers/{chunk-IXNXKVOB.js → chunk-ISQSYLZY.js} +4 -4
  29. package/Build/Workers/{chunk-PM76TX2X.js → chunk-JZAMRL5I.js} +6 -6
  30. package/Build/Workers/{chunk-CBE4HRBH.js → chunk-K5G2WELR.js} +7 -7
  31. package/Build/Workers/{chunk-EHGQQA7C.js → chunk-L5SO4Y5V.js} +1 -1
  32. package/Build/Workers/{chunk-M2AA2ARJ.js → chunk-LCMJQVIF.js} +11 -11
  33. package/Build/Workers/{chunk-HI73PIPQ.js → chunk-MWJW37I7.js} +2 -2
  34. package/Build/Workers/{chunk-WAJNX74N.js → chunk-NAGMYRDW.js} +27 -20
  35. package/Build/Workers/{chunk-WUIDEXAN.js → chunk-OYO6TKMU.js} +7 -7
  36. package/Build/Workers/{chunk-YVGU235V.js → chunk-PUTA3AE2.js} +4 -4
  37. package/Build/Workers/{chunk-ZWSWJYJP.js → chunk-Q5BHMNKU.js} +13 -13
  38. package/Build/Workers/{chunk-LQT2ZK7D.js → chunk-QTEX3Y4V.js} +17 -17
  39. package/Build/Workers/{chunk-UBAHTE4Q.js → chunk-QZKN2RXM.js} +1 -1
  40. package/Build/Workers/{chunk-T34EOLFR.js → chunk-RO2Z3LCR.js} +14 -14
  41. package/Build/Workers/{chunk-PTFIVVLX.js → chunk-RRN6LRDX.js} +12 -12
  42. package/Build/Workers/{chunk-B6IJY6AN.js → chunk-SLIA3GQP.js} +7 -7
  43. package/Build/Workers/{chunk-GIOZHX7U.js → chunk-TFCOEX3W.js} +2 -2
  44. package/Build/Workers/{chunk-KRVALCCI.js → chunk-TU6ZXHVU.js} +5 -5
  45. package/Build/Workers/{chunk-54I6VSRP.js → chunk-VJ2PDF64.js} +6 -6
  46. package/Build/Workers/{chunk-BMFWWTD7.js → chunk-VMVPONIV.js} +5 -5
  47. package/Build/Workers/{chunk-CNPP6TQ2.js → chunk-WPXU45PH.js} +4 -4
  48. package/Build/Workers/{chunk-2ONAV62A.js → chunk-XDHM4G3P.js} +7 -7
  49. package/Build/Workers/{chunk-KO232FLP.js → chunk-XED3RXKO.js} +2 -2
  50. package/Build/Workers/{chunk-5I3LPAS7.js → chunk-YNYCGTQH.js} +5 -5
  51. package/Build/Workers/{chunk-THDHWSEJ.js → chunk-Z4SI54EB.js} +4 -4
  52. package/Build/Workers/{chunk-R2KGFZBA.js → chunk-ZVDLC3T4.js} +13 -13
  53. package/Build/Workers/combineGeometry.js +22 -22
  54. package/Build/Workers/createBoxGeometry.js +16 -16
  55. package/Build/Workers/createBoxOutlineGeometry.js +14 -14
  56. package/Build/Workers/createCircleGeometry.js +24 -24
  57. package/Build/Workers/createCircleOutlineGeometry.js +17 -17
  58. package/Build/Workers/createCoplanarPolygonGeometry.js +31 -31
  59. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +29 -29
  60. package/Build/Workers/createCorridorGeometry.js +27 -27
  61. package/Build/Workers/createCorridorOutlineGeometry.js +26 -26
  62. package/Build/Workers/createCylinderGeometry.js +18 -18
  63. package/Build/Workers/createCylinderOutlineGeometry.js +16 -16
  64. package/Build/Workers/createEllipseGeometry.js +24 -24
  65. package/Build/Workers/createEllipseOutlineGeometry.js +17 -17
  66. package/Build/Workers/createEllipsoidGeometry.js +17 -17
  67. package/Build/Workers/createEllipsoidOutlineGeometry.js +16 -16
  68. package/Build/Workers/createFrustumGeometry.js +16 -16
  69. package/Build/Workers/createFrustumOutlineGeometry.js +16 -16
  70. package/Build/Workers/createGeometry.js +22 -22
  71. package/Build/Workers/createGroundPolylineGeometry.js +20 -20
  72. package/Build/Workers/createPlaneGeometry.js +14 -14
  73. package/Build/Workers/createPlaneOutlineGeometry.js +13 -13
  74. package/Build/Workers/createPolygonGeometry.js +30 -30
  75. package/Build/Workers/createPolygonOutlineGeometry.js +28 -28
  76. package/Build/Workers/createPolylineGeometry.js +23 -23
  77. package/Build/Workers/createPolylineVolumeGeometry.js +29 -29
  78. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +25 -25
  79. package/Build/Workers/createRectangleGeometry.js +25 -25
  80. package/Build/Workers/createRectangleOutlineGeometry.js +18 -18
  81. package/Build/Workers/createSimplePolylineGeometry.js +21 -21
  82. package/Build/Workers/createSphereGeometry.js +17 -17
  83. package/Build/Workers/createSphereOutlineGeometry.js +16 -16
  84. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  85. package/Build/Workers/createVectorTileClampedPolylines.js +13 -13
  86. package/Build/Workers/createVectorTileGeometries.js +22 -22
  87. package/Build/Workers/createVectorTilePoints.js +12 -12
  88. package/Build/Workers/createVectorTilePolygons.js +20 -20
  89. package/Build/Workers/createVectorTilePolylines.js +13 -13
  90. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +20 -20
  91. package/Build/Workers/createVerticesFromHeightmap.js +20 -20
  92. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +17 -17
  93. package/Build/Workers/createWallGeometry.js +22 -22
  94. package/Build/Workers/createWallOutlineGeometry.js +21 -21
  95. package/Build/Workers/decodeDraco.js +15 -14
  96. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  97. package/Build/Workers/decodeI3S.js +10 -10
  98. package/Build/Workers/transcodeKTX2.js +50 -43
  99. package/Build/Workers/transferTypedArrayTest.js +1 -1
  100. package/Build/Workers/upsampleQuantizedTerrainMesh.js +20 -20
  101. package/Source/Core/Color.js +3 -3
  102. package/Source/Core/Credit.js +3 -3
  103. package/Source/Core/DistanceDisplayCondition.js +3 -3
  104. package/Source/Core/EllipsoidRhumbLine.js +1 -1
  105. package/Source/Core/Ion.js +1 -1
  106. package/Source/Core/OrientedBoundingBox.js +2 -2
  107. package/Source/Core/PolygonGeometryLibrary.js +26 -4
  108. package/Source/Core/Spherical.js +3 -3
  109. package/Source/Core/TexturePacker.js +166 -0
  110. package/Source/Core/writeTextToCanvas.js +0 -1
  111. package/Source/DataSources/BillboardVisualizer.js +3 -3
  112. package/Source/DataSources/BoundingSphereState.js +3 -3
  113. package/Source/DataSources/DataSourceClock.js +1 -1
  114. package/Source/DataSources/DataSourceDisplay.js +5 -2
  115. package/Source/DataSources/EntityCluster.js +44 -19
  116. package/Source/Renderer/AutomaticUniforms.js +2 -2
  117. package/Source/Renderer/Context.js +0 -4
  118. package/Source/Renderer/Texture.js +6 -5
  119. package/Source/Renderer/TextureAtlas.js +802 -0
  120. package/Source/Scene/ArcGisMapService.js +1 -1
  121. package/Source/Scene/Billboard.js +87 -142
  122. package/Source/Scene/BillboardCollection.js +132 -202
  123. package/Source/Scene/BillboardLoadState.js +44 -0
  124. package/Source/Scene/BillboardTexture.js +348 -0
  125. package/Source/Scene/Camera.js +2 -2
  126. package/Source/Scene/Cesium3DTile.js +56 -28
  127. package/Source/Scene/Cesium3DTilesVoxelProvider.js +403 -132
  128. package/Source/Scene/Cesium3DTilesetStatistics.js +0 -1
  129. package/Source/Scene/ClippingPolygon.js +2 -2
  130. package/Source/Scene/Expression.js +1 -0
  131. package/Source/Scene/GltfDracoLoader.js +45 -0
  132. package/Source/Scene/GltfIndexBufferLoader.js +5 -0
  133. package/Source/Scene/GltfLoader.js +22 -9
  134. package/Source/Scene/GltfVertexBufferLoader.js +13 -0
  135. package/Source/Scene/ITwinData.js +47 -1
  136. package/Source/Scene/ImageryLayer.js +1 -1
  137. package/Source/Scene/ImplicitSubtree.js +2 -0
  138. package/Source/Scene/KeyframeNode.js +16 -2
  139. package/Source/Scene/Label.js +1 -1
  140. package/Source/Scene/LabelCollection.js +212 -193
  141. package/Source/Scene/Megatexture.js +145 -81
  142. package/Source/Scene/Model/CustomShader.js +0 -2
  143. package/Source/Scene/Model/Model.js +1 -1
  144. package/Source/Scene/Model/ModelUtility.js +5 -1
  145. package/Source/Scene/Multiple3DTileContent.js +21 -8
  146. package/Source/Scene/PointPrimitive.js +1 -1
  147. package/Source/Scene/ResourceCache.js +17 -1
  148. package/Source/Scene/Scene.js +39 -15
  149. package/Source/Scene/ScreenSpaceCameraController.js +0 -8
  150. package/Source/Scene/SpatialNode.js +4 -11
  151. package/Source/Scene/Vector3DTilePoints.js +2 -5
  152. package/Source/Scene/VoxelBoxShape.js +12 -5
  153. package/Source/Scene/VoxelCell.js +6 -5
  154. package/Source/Scene/VoxelContent.js +171 -107
  155. package/Source/Scene/VoxelCylinderShape.js +65 -58
  156. package/Source/Scene/VoxelEllipsoidShape.js +15 -5
  157. package/Source/Scene/VoxelMetadataOrder.js +12 -0
  158. package/Source/Scene/VoxelPrimitive.js +245 -53
  159. package/Source/Scene/VoxelProvider.js +44 -29
  160. package/Source/Scene/VoxelRenderResources.js +30 -7
  161. package/Source/Scene/VoxelShape.js +10 -3
  162. package/Source/Scene/VoxelTraversal.js +326 -166
  163. package/Source/Scene/WebMapTileServiceImageryProvider.js +2 -2
  164. package/Source/Scene/createGooglePhotorealistic3DTileset.js +5 -8
  165. package/Source/Scene/processVoxelProperties.js +3 -0
  166. package/Source/Shaders/GlobeFS.glsl +10 -1
  167. package/Source/Shaders/GlobeFS.js +10 -1
  168. package/Source/Shaders/PolylineCommon.glsl +1 -1
  169. package/Source/Shaders/PolylineCommon.js +1 -1
  170. package/Source/Shaders/Voxels/Megatexture.glsl +4 -16
  171. package/Source/Shaders/Voxels/Megatexture.js +4 -16
  172. package/Source/Shaders/Voxels/Octree.glsl +44 -7
  173. package/Source/Shaders/Voxels/Octree.js +44 -7
  174. package/Source/Shaders/Voxels/VoxelFS.glsl +9 -15
  175. package/Source/Shaders/Voxels/VoxelFS.js +9 -15
  176. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +15 -15
  177. package/Source/Shaders/Voxels/convertUvToCylinder.js +15 -15
  178. package/Source/Widget/CesiumWidget.js +16 -10
  179. package/Source/Workers/decodeDraco.js +4 -4
  180. package/index.d.ts +321 -110
  181. package/index.js +209 -205
  182. package/package.json +2 -2
  183. package/Source/Scene/TextureAtlas.js +0 -558
@@ -1,4 +1,5 @@
1
1
  import AttributeCompression from "../Core/AttributeCompression.js";
2
+ import BoundingRectangle from "../Core/BoundingRectangle.js";
2
3
  import BoundingSphere from "../Core/BoundingSphere.js";
3
4
  import Cartesian2 from "../Core/Cartesian2.js";
4
5
  import Cartesian3 from "../Core/Cartesian3.js";
@@ -8,7 +9,6 @@ import ComponentDatatype from "../Core/ComponentDatatype.js";
8
9
  import defaultValue from "../Core/defaultValue.js";
9
10
  import defined from "../Core/defined.js";
10
11
  import destroyObject from "../Core/destroyObject.js";
11
- import DeveloperError from "../Core/DeveloperError.js";
12
12
  import EncodedCartesian3 from "../Core/EncodedCartesian3.js";
13
13
  import IndexDatatype from "../Core/IndexDatatype.js";
14
14
  import CesiumMath from "../Core/Math.js";
@@ -32,7 +32,7 @@ import HeightReference, { isHeightReferenceClamp } from "./HeightReference.js";
32
32
  import HorizontalOrigin from "./HorizontalOrigin.js";
33
33
  import SceneMode from "./SceneMode.js";
34
34
  import SDFSettings from "./SDFSettings.js";
35
- import TextureAtlas from "./TextureAtlas.js";
35
+ import TextureAtlas from "../Renderer/TextureAtlas.js";
36
36
  import VerticalOrigin from "./VerticalOrigin.js";
37
37
 
38
38
  const SHOW_INDEX = Billboard.SHOW_INDEX;
@@ -148,9 +148,15 @@ function BillboardCollection(options) {
148
148
  this._scene = options.scene;
149
149
  this._batchTable = options.batchTable;
150
150
 
151
- this._textureAtlas = undefined;
152
- this._textureAtlasGUID = undefined;
151
+ let textureAtlas = options.textureAtlas; // Hidden option for internal use
152
+ if (!defined(textureAtlas)) {
153
+ textureAtlas = new TextureAtlas();
154
+ }
155
+ this._textureAtlas = textureAtlas;
156
+ this._textureAtlasGUID = textureAtlas.guid;
153
157
  this._destroyTextureAtlas = true;
158
+ this._billboardTextureCache = new Map();
159
+
154
160
  this._sp = undefined;
155
161
  this._spTranslucent = undefined;
156
162
  this._rsOpaque = undefined;
@@ -205,6 +211,8 @@ function BillboardCollection(options) {
205
211
 
206
212
  this._colorCommands = [];
207
213
 
214
+ this._allBillboardsReady = false;
215
+
208
216
  /**
209
217
  * Determines if billboards in this collection will be shown.
210
218
  *
@@ -319,13 +327,12 @@ function BillboardCollection(options) {
319
327
 
320
328
  this._highlightColor = Color.clone(Color.WHITE); // Only used by Vector3DTilePoints
321
329
 
322
- const that = this;
323
330
  this._uniforms = {
324
- u_atlas: function () {
325
- return that._textureAtlas.texture;
331
+ u_atlas: () => {
332
+ return this.textureAtlas.texture;
326
333
  },
327
- u_highlightColor: function () {
328
- return that._highlightColor;
334
+ u_highlightColor: () => {
335
+ return this._highlightColor;
329
336
  },
330
337
  };
331
338
 
@@ -353,6 +360,7 @@ Object.defineProperties(BillboardCollection.prototype, {
353
360
  * in the collection.
354
361
  * @memberof BillboardCollection.prototype
355
362
  * @type {number}
363
+ * @readonly
356
364
  */
357
365
  length: {
358
366
  get: function () {
@@ -372,13 +380,16 @@ Object.defineProperties(BillboardCollection.prototype, {
372
380
  return this._textureAtlas;
373
381
  },
374
382
  set: function (value) {
383
+ //>>includeStart('debug', pragmas.debug);
384
+ Check.defined("textureAtlas", value);
385
+ //>>includeEnd('debug');
386
+
375
387
  if (this._textureAtlas !== value) {
376
388
  this._textureAtlas =
377
389
  this._destroyTextureAtlas &&
378
390
  this._textureAtlas &&
379
391
  this._textureAtlas.destroy();
380
392
  this._textureAtlas = value;
381
- this._createVertexArray = true; // New per-billboard texture coordinates
382
393
  }
383
394
  },
384
395
  },
@@ -398,12 +409,10 @@ Object.defineProperties(BillboardCollection.prototype, {
398
409
  * // Set destroyTextureAtlas
399
410
  * // Destroy a billboard collection but not its texture atlas.
400
411
  *
401
- * const atlas = new TextureAtlas({
402
- * scene : scene,
403
- * images : images
404
- * });
412
+ * const atlas = new TextureAtlas();
405
413
  * billboards.textureAtlas = atlas;
406
414
  * billboards.destroyTextureAtlas = false;
415
+ *
407
416
  * billboards = billboards.destroy();
408
417
  * console.log(atlas.isDestroyed()); // False
409
418
  */
@@ -415,6 +424,45 @@ Object.defineProperties(BillboardCollection.prototype, {
415
424
  this._destroyTextureAtlas = value;
416
425
  },
417
426
  },
427
+
428
+ /**
429
+ * Returns the size in bytes of the WebGL texture resources.
430
+ * @private
431
+ * @memberof BillboardCollection.prototype
432
+ * @type {number}
433
+ * @readonly
434
+ */
435
+ sizeInBytes: {
436
+ get: function () {
437
+ return this._textureAtlas.sizeInBytes;
438
+ },
439
+ },
440
+
441
+ /**
442
+ * True when all billboards currently in the collection are ready for rendering.
443
+ * @private
444
+ * @memberof BillboardCollection.prototype
445
+ * @type {boolean}
446
+ * @readonly
447
+ */
448
+ ready: {
449
+ get: function () {
450
+ return this._allBillboardsReady;
451
+ },
452
+ },
453
+
454
+ /**
455
+ * Cache of loaded billboard images.
456
+ * @private
457
+ * @memberof BillboardCollection.prototype
458
+ * @type {Map<string, BillboardTexture>}
459
+ * @readonly
460
+ */
461
+ billboardTextureCache: {
462
+ get: function () {
463
+ return this._billboardTextureCache;
464
+ },
465
+ },
418
466
  });
419
467
 
420
468
  function destroyBillboards(billboards) {
@@ -836,7 +884,6 @@ const writePositionScratch = new EncodedCartesian3();
836
884
  function writePositionScaleAndRotation(
837
885
  billboardCollection,
838
886
  frameState,
839
- textureAtlasCoordinates,
840
887
  vafWriters,
841
888
  billboard,
842
889
  ) {
@@ -909,10 +956,11 @@ const LOWER_RIGHT = 2.0;
909
956
  const UPPER_RIGHT = 3.0;
910
957
  const UPPER_LEFT = 1.0;
911
958
 
959
+ const scratchBoundingRectangle = new BoundingRectangle();
960
+
912
961
  function writeCompressedAttrib0(
913
962
  billboardCollection,
914
963
  frameState,
915
- textureAtlasCoordinates,
916
964
  vafWriters,
917
965
  billboard,
918
966
  ) {
@@ -958,15 +1006,10 @@ function writeCompressedAttrib0(
958
1006
  let bottomLeftY = 0;
959
1007
  let width = 0;
960
1008
  let height = 0;
961
- const index = billboard._imageIndex;
962
- if (index !== -1) {
963
- const imageRectangle = textureAtlasCoordinates[index];
964
-
965
- //>>includeStart('debug', pragmas.debug);
966
- if (!defined(imageRectangle)) {
967
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
968
- }
969
- //>>includeEnd('debug');
1009
+ if (billboard.ready) {
1010
+ const imageRectangle = billboard.computeTextureCoordinates(
1011
+ scratchBoundingRectangle,
1012
+ );
970
1013
 
971
1014
  bottomLeftX = imageRectangle.x;
972
1015
  bottomLeftY = imageRectangle.y;
@@ -1057,7 +1100,6 @@ function writeCompressedAttrib0(
1057
1100
  function writeCompressedAttrib1(
1058
1101
  billboardCollection,
1059
1102
  frameState,
1060
- textureAtlasCoordinates,
1061
1103
  vafWriters,
1062
1104
  billboard,
1063
1105
  ) {
@@ -1087,24 +1129,7 @@ function writeCompressedAttrib1(
1087
1129
  }
1088
1130
  }
1089
1131
 
1090
- let width = 0;
1091
- const index = billboard._imageIndex;
1092
- if (index !== -1) {
1093
- const imageRectangle = textureAtlasCoordinates[index];
1094
-
1095
- //>>includeStart('debug', pragmas.debug);
1096
- if (!defined(imageRectangle)) {
1097
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
1098
- }
1099
- //>>includeEnd('debug');
1100
-
1101
- width = imageRectangle.width;
1102
- }
1103
-
1104
- const textureWidth = billboardCollection._textureAtlas.texture.width;
1105
- const imageWidth = Math.round(
1106
- defaultValue(billboard.width, textureWidth * width),
1107
- );
1132
+ const imageWidth = billboard.width ?? 0;
1108
1133
  billboardCollection._maxSize = Math.max(
1109
1134
  billboardCollection._maxSize,
1110
1135
  imageWidth,
@@ -1143,7 +1168,6 @@ function writeCompressedAttrib1(
1143
1168
  function writeCompressedAttrib2(
1144
1169
  billboardCollection,
1145
1170
  frameState,
1146
- textureAtlasCoordinates,
1147
1171
  vafWriters,
1148
1172
  billboard,
1149
1173
  ) {
@@ -1163,24 +1187,7 @@ function writeCompressedAttrib2(
1163
1187
  billboardCollection._allSizedInMeters =
1164
1188
  billboardCollection._allSizedInMeters && sizeInMeters === 1.0;
1165
1189
 
1166
- let height = 0;
1167
- const index = billboard._imageIndex;
1168
- if (index !== -1) {
1169
- const imageRectangle = textureAtlasCoordinates[index];
1170
-
1171
- //>>includeStart('debug', pragmas.debug);
1172
- if (!defined(imageRectangle)) {
1173
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
1174
- }
1175
- //>>includeEnd('debug');
1176
-
1177
- height = imageRectangle.height;
1178
- }
1179
-
1180
- const dimensions = billboardCollection._textureAtlas.texture.dimensions;
1181
- const imageHeight = Math.round(
1182
- defaultValue(billboard.height, dimensions.y * height),
1183
- );
1190
+ const imageHeight = billboard.height ?? 0;
1184
1191
  billboardCollection._maxSize = Math.max(
1185
1192
  billboardCollection._maxSize,
1186
1193
  imageHeight,
@@ -1222,7 +1229,6 @@ function writeCompressedAttrib2(
1222
1229
  function writeEyeOffset(
1223
1230
  billboardCollection,
1224
1231
  frameState,
1225
- textureAtlasCoordinates,
1226
1232
  vafWriters,
1227
1233
  billboard,
1228
1234
  ) {
@@ -1243,24 +1249,18 @@ function writeEyeOffset(
1243
1249
  );
1244
1250
 
1245
1251
  if (billboardCollection._instanced) {
1246
- let width = 0;
1247
- let height = 0;
1248
- const index = billboard._imageIndex;
1249
- if (index !== -1) {
1250
- const imageRectangle = textureAtlasCoordinates[index];
1252
+ scratchCartesian2.x = 0;
1253
+ scratchCartesian2.y = 0;
1251
1254
 
1252
- //>>includeStart('debug', pragmas.debug);
1253
- if (!defined(imageRectangle)) {
1254
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
1255
- }
1256
- //>>includeEnd('debug');
1255
+ if (billboard.ready) {
1256
+ const imageRectangle = billboard.computeTextureCoordinates(
1257
+ scratchBoundingRectangle,
1258
+ );
1257
1259
 
1258
- width = imageRectangle.width;
1259
- height = imageRectangle.height;
1260
+ scratchCartesian2.x = imageRectangle.width;
1261
+ scratchCartesian2.y = imageRectangle.height;
1260
1262
  }
1261
1263
 
1262
- scratchCartesian2.x = width;
1263
- scratchCartesian2.y = height;
1264
1264
  const compressedTexCoordsRange =
1265
1265
  AttributeCompression.compressTextureCoordinates(scratchCartesian2);
1266
1266
 
@@ -1278,7 +1278,6 @@ function writeEyeOffset(
1278
1278
  function writeScaleByDistance(
1279
1279
  billboardCollection,
1280
1280
  frameState,
1281
- textureAtlasCoordinates,
1282
1281
  vafWriters,
1283
1282
  billboard,
1284
1283
  ) {
@@ -1318,7 +1317,6 @@ function writeScaleByDistance(
1318
1317
  function writePixelOffsetScaleByDistance(
1319
1318
  billboardCollection,
1320
1319
  frameState,
1321
- textureAtlasCoordinates,
1322
1320
  vafWriters,
1323
1321
  billboard,
1324
1322
  ) {
@@ -1358,7 +1356,6 @@ function writePixelOffsetScaleByDistance(
1358
1356
  function writeCompressedAttribute3(
1359
1357
  billboardCollection,
1360
1358
  frameState,
1361
- textureAtlasCoordinates,
1362
1359
  vafWriters,
1363
1360
  billboard,
1364
1361
  ) {
@@ -1398,33 +1395,8 @@ function writeCompressedAttribute3(
1398
1395
  let imageWidth;
1399
1396
 
1400
1397
  if (!defined(billboard._labelDimensions)) {
1401
- let height = 0;
1402
- let width = 0;
1403
- const index = billboard._imageIndex;
1404
- if (index !== -1) {
1405
- const imageRectangle = textureAtlasCoordinates[index];
1406
-
1407
- //>>includeStart('debug', pragmas.debug);
1408
- if (!defined(imageRectangle)) {
1409
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
1410
- }
1411
- //>>includeEnd('debug');
1412
-
1413
- height = imageRectangle.height;
1414
- width = imageRectangle.width;
1415
- }
1416
-
1417
- imageHeight = Math.round(
1418
- defaultValue(
1419
- billboard.height,
1420
- billboardCollection._textureAtlas.texture.dimensions.y * height,
1421
- ),
1422
- );
1423
-
1424
- const textureWidth = billboardCollection._textureAtlas.texture.width;
1425
- imageWidth = Math.round(
1426
- defaultValue(billboard.width, textureWidth * width),
1427
- );
1398
+ imageWidth = billboard.width ?? 0;
1399
+ imageHeight = billboard.height ?? 0;
1428
1400
  } else {
1429
1401
  imageWidth = billboard._labelDimensions.x;
1430
1402
  imageHeight = billboard._labelDimensions.y;
@@ -1449,7 +1421,6 @@ function writeCompressedAttribute3(
1449
1421
  function writeTextureCoordinateBoundsOrLabelTranslate(
1450
1422
  billboardCollection,
1451
1423
  frameState,
1452
- textureAtlasCoordinates,
1453
1424
  vafWriters,
1454
1425
  billboard,
1455
1426
  ) {
@@ -1489,20 +1460,15 @@ function writeTextureCoordinateBoundsOrLabelTranslate(
1489
1460
  return;
1490
1461
  }
1491
1462
 
1492
- //write texture coordinate bounds, used by depth testing in fragment shader
1463
+ // Write texture coordinate bounds, used by depth testing in fragment shader
1493
1464
  let minX = 0;
1494
1465
  let minY = 0;
1495
1466
  let width = 0;
1496
1467
  let height = 0;
1497
- const index = billboard._imageIndex;
1498
- if (index !== -1) {
1499
- const imageRectangle = textureAtlasCoordinates[index];
1500
-
1501
- //>>includeStart('debug', pragmas.debug);
1502
- if (!defined(imageRectangle)) {
1503
- throw new DeveloperError(`Invalid billboard image index: ${index}`);
1504
- }
1505
- //>>includeEnd('debug');
1468
+ if (billboard.ready) {
1469
+ const imageRectangle = billboard.computeTextureCoordinates(
1470
+ scratchBoundingRectangle,
1471
+ );
1506
1472
 
1507
1473
  minX = imageRectangle.x;
1508
1474
  minY = imageRectangle.y;
@@ -1524,13 +1490,7 @@ function writeTextureCoordinateBoundsOrLabelTranslate(
1524
1490
  }
1525
1491
  }
1526
1492
 
1527
- function writeBatchId(
1528
- billboardCollection,
1529
- frameState,
1530
- textureAtlasCoordinates,
1531
- vafWriters,
1532
- billboard,
1533
- ) {
1493
+ function writeBatchId(billboardCollection, frameState, vafWriters, billboard) {
1534
1494
  if (!defined(billboardCollection._batchTable)) {
1535
1495
  return;
1536
1496
  }
@@ -1551,13 +1511,7 @@ function writeBatchId(
1551
1511
  }
1552
1512
  }
1553
1513
 
1554
- function writeSDF(
1555
- billboardCollection,
1556
- frameState,
1557
- textureAtlasCoordinates,
1558
- vafWriters,
1559
- billboard,
1560
- ) {
1514
+ function writeSDF(billboardCollection, frameState, vafWriters, billboard) {
1561
1515
  if (!billboardCollection._sdf) {
1562
1516
  return;
1563
1517
  }
@@ -1594,7 +1548,6 @@ function writeSDF(
1594
1548
  function writeSplitDirection(
1595
1549
  billboardCollection,
1596
1550
  frameState,
1597
- textureAtlasCoordinates,
1598
1551
  vafWriters,
1599
1552
  billboard,
1600
1553
  ) {
@@ -1622,94 +1575,56 @@ function writeSplitDirection(
1622
1575
  function writeBillboard(
1623
1576
  billboardCollection,
1624
1577
  frameState,
1625
- textureAtlasCoordinates,
1626
1578
  vafWriters,
1627
1579
  billboard,
1628
1580
  ) {
1629
1581
  writePositionScaleAndRotation(
1630
1582
  billboardCollection,
1631
1583
  frameState,
1632
- textureAtlasCoordinates,
1633
1584
  vafWriters,
1634
1585
  billboard,
1635
1586
  );
1636
1587
  writeCompressedAttrib0(
1637
1588
  billboardCollection,
1638
1589
  frameState,
1639
- textureAtlasCoordinates,
1640
1590
  vafWriters,
1641
1591
  billboard,
1642
1592
  );
1643
1593
  writeCompressedAttrib1(
1644
1594
  billboardCollection,
1645
1595
  frameState,
1646
- textureAtlasCoordinates,
1647
1596
  vafWriters,
1648
1597
  billboard,
1649
1598
  );
1650
1599
  writeCompressedAttrib2(
1651
1600
  billboardCollection,
1652
1601
  frameState,
1653
- textureAtlasCoordinates,
1654
- vafWriters,
1655
- billboard,
1656
- );
1657
- writeEyeOffset(
1658
- billboardCollection,
1659
- frameState,
1660
- textureAtlasCoordinates,
1661
- vafWriters,
1662
- billboard,
1663
- );
1664
- writeScaleByDistance(
1665
- billboardCollection,
1666
- frameState,
1667
- textureAtlasCoordinates,
1668
1602
  vafWriters,
1669
1603
  billboard,
1670
1604
  );
1605
+ writeEyeOffset(billboardCollection, frameState, vafWriters, billboard);
1606
+ writeScaleByDistance(billboardCollection, frameState, vafWriters, billboard);
1671
1607
  writePixelOffsetScaleByDistance(
1672
1608
  billboardCollection,
1673
1609
  frameState,
1674
- textureAtlasCoordinates,
1675
1610
  vafWriters,
1676
1611
  billboard,
1677
1612
  );
1678
1613
  writeCompressedAttribute3(
1679
1614
  billboardCollection,
1680
1615
  frameState,
1681
- textureAtlasCoordinates,
1682
1616
  vafWriters,
1683
1617
  billboard,
1684
1618
  );
1685
1619
  writeTextureCoordinateBoundsOrLabelTranslate(
1686
1620
  billboardCollection,
1687
1621
  frameState,
1688
- textureAtlasCoordinates,
1689
- vafWriters,
1690
- billboard,
1691
- );
1692
- writeBatchId(
1693
- billboardCollection,
1694
- frameState,
1695
- textureAtlasCoordinates,
1696
- vafWriters,
1697
- billboard,
1698
- );
1699
- writeSDF(
1700
- billboardCollection,
1701
- frameState,
1702
- textureAtlasCoordinates,
1703
- vafWriters,
1704
- billboard,
1705
- );
1706
- writeSplitDirection(
1707
- billboardCollection,
1708
- frameState,
1709
- textureAtlasCoordinates,
1710
1622
  vafWriters,
1711
1623
  billboard,
1712
1624
  );
1625
+ writeBatchId(billboardCollection, frameState, vafWriters, billboard);
1626
+ writeSDF(billboardCollection, frameState, vafWriters, billboard);
1627
+ writeSplitDirection(billboardCollection, frameState, vafWriters, billboard);
1713
1628
  }
1714
1629
 
1715
1630
  function recomputeActualPositions(
@@ -1838,7 +1753,7 @@ function createDebugCommand(billboardCollection, context) {
1838
1753
  const drawCommand = context.createViewportQuadCommand(fs, {
1839
1754
  uniformMap: {
1840
1755
  billboard_texture: function () {
1841
- return billboardCollection._textureAtlas.texture;
1756
+ return billboardCollection.textureAtlas.texture;
1842
1757
  },
1843
1758
  },
1844
1759
  });
@@ -1865,9 +1780,6 @@ BillboardCollection.prototype.update = function (frameState) {
1865
1780
  return;
1866
1781
  }
1867
1782
 
1868
- let billboards = this._billboards;
1869
- let billboardsLength = billboards.length;
1870
-
1871
1783
  const context = frameState.context;
1872
1784
  this._instanced = context.instancedArrays;
1873
1785
  attributeLocations = this._instanced
@@ -1877,21 +1789,40 @@ BillboardCollection.prototype.update = function (frameState) {
1877
1789
  ? getIndexBufferInstanced
1878
1790
  : getIndexBufferBatched;
1879
1791
 
1880
- let textureAtlas = this._textureAtlas;
1881
- if (!defined(textureAtlas)) {
1882
- textureAtlas = this._textureAtlas = new TextureAtlas({
1883
- context: context,
1884
- });
1792
+ let billboards = this._billboards;
1793
+ let billboardsLength = billboards.length;
1794
+ let allBillboardsReady = true;
1795
+ for (let i = 0; i < billboardsLength; ++i) {
1796
+ const billboard = billboards[i];
1797
+ if (defined(billboard.loadError)) {
1798
+ console.error(
1799
+ `Error loading image for billboard: ${billboard.loadError}`,
1800
+ );
1801
+ billboard.image = undefined;
1802
+ }
1885
1803
 
1886
- for (let ii = 0; ii < billboardsLength; ++ii) {
1887
- billboards[ii]._loadImage();
1804
+ if (billboard.textureDirty) {
1805
+ this._updateBillboard(billboard, IMAGE_INDEX_INDEX);
1806
+ }
1807
+
1808
+ if (billboard.show) {
1809
+ allBillboardsReady = allBillboardsReady && billboard.ready;
1888
1810
  }
1889
1811
  }
1890
1812
 
1891
- const textureAtlasCoordinates = textureAtlas.textureCoordinates;
1892
- if (textureAtlasCoordinates.length === 0) {
1893
- // Can't write billboard vertices until we have texture coordinates
1894
- // provided by a texture atlas
1813
+ // Queue any texture resource updates for after the frame is rendered
1814
+ const textureAtlas = this._textureAtlas;
1815
+ frameState.afterRender.push(() => {
1816
+ if (this.isDestroyed()) {
1817
+ return;
1818
+ }
1819
+
1820
+ return textureAtlas.update(frameState.context);
1821
+ });
1822
+
1823
+ if (!defined(textureAtlas.texture)) {
1824
+ // Can't write billboard vertices until the texture atlas
1825
+ // has been updated once
1895
1826
  return;
1896
1827
  }
1897
1828
 
@@ -1939,13 +1870,8 @@ BillboardCollection.prototype.update = function (frameState) {
1939
1870
  for (let i = 0; i < billboardsLength; ++i) {
1940
1871
  const billboard = this._billboards[i];
1941
1872
  billboard._dirty = false; // In case it needed an update.
1942
- writeBillboard(
1943
- this,
1944
- frameState,
1945
- textureAtlasCoordinates,
1946
- vafWriters,
1947
- billboard,
1948
- );
1873
+ billboard.textureDirty = false;
1874
+ writeBillboard(this, frameState, vafWriters, billboard);
1949
1875
  }
1950
1876
 
1951
1877
  // Different billboard collections share the same index buffer.
@@ -1992,7 +1918,7 @@ BillboardCollection.prototype.update = function (frameState) {
1992
1918
  writers.push(writeCompressedAttrib2);
1993
1919
  }
1994
1920
 
1995
- if (properties[EYE_OFFSET_INDEX]) {
1921
+ if (properties[IMAGE_INDEX_INDEX] || properties[EYE_OFFSET_INDEX]) {
1996
1922
  writers.push(writeEyeOffset);
1997
1923
  }
1998
1924
 
@@ -2036,9 +1962,10 @@ BillboardCollection.prototype.update = function (frameState) {
2036
1962
  for (let m = 0; m < billboardsToUpdateLength; ++m) {
2037
1963
  const b = billboardsToUpdate[m];
2038
1964
  b._dirty = false;
1965
+ b.textureDirty = false;
2039
1966
 
2040
1967
  for (let n = 0; n < numWriters; ++n) {
2041
- writers[n](this, frameState, textureAtlasCoordinates, vafWriters, b);
1968
+ writers[n](this, frameState, vafWriters, b);
2042
1969
  }
2043
1970
  }
2044
1971
  this._vaf.commit(getIndexBuffer(context));
@@ -2046,9 +1973,10 @@ BillboardCollection.prototype.update = function (frameState) {
2046
1973
  for (let h = 0; h < billboardsToUpdateLength; ++h) {
2047
1974
  const bb = billboardsToUpdate[h];
2048
1975
  bb._dirty = false;
1976
+ bb.textureDirty = false;
2049
1977
 
2050
1978
  for (let o = 0; o < numWriters; ++o) {
2051
- writers[o](this, frameState, textureAtlasCoordinates, vafWriters, bb);
1979
+ writers[o](this, frameState, vafWriters, bb);
2052
1980
  }
2053
1981
 
2054
1982
  if (this._instanced) {
@@ -2412,6 +2340,8 @@ BillboardCollection.prototype.update = function (frameState) {
2412
2340
  commandList.push(this.debugCommand);
2413
2341
  }
2414
2342
  }
2343
+
2344
+ this._allBillboardsReady = allBillboardsReady;
2415
2345
  };
2416
2346
 
2417
2347
  /**
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Defines loading state of a image as any request is resolved and the WebGL resources are updated.
3
+ * @private
4
+ * @enum {number}
5
+ */
6
+ const BillboardLoadState = Object.freeze({
7
+ /**
8
+ * There is no image data to load.
9
+ * @private
10
+ * @type {number}
11
+ * @constant
12
+ */
13
+ NONE: 0,
14
+ /**
15
+ * Image data is in the process of downloading, or WebGL resources are being updated.
16
+ * @private
17
+ * @type {number}
18
+ * @constant
19
+ */
20
+ LOADING: 2,
21
+ /**
22
+ * The image data has been downloaded and the WebGL resources have been created. It is ready for rendering.
23
+ * @private
24
+ * @type {number}
25
+ * @constant
26
+ */
27
+ LOADED: 3,
28
+ /**
29
+ * There was an error while downloading an image or updating the WebGL resources.
30
+ * @private
31
+ * @type {number}
32
+ * @constant
33
+ */
34
+ ERROR: 4,
35
+ /**
36
+ * Updating the WebGL resources failed, due to the resource being destroyed or another error.
37
+ * @private
38
+ * @type {number}
39
+ * @constant
40
+ */
41
+ FAILED: 5,
42
+ });
43
+
44
+ export default BillboardLoadState;