bruce-cesium 7.3.7 → 7.3.9

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 (30) hide show
  1. package/dist/bruce-cesium.es5.js +431 -53
  2. package/dist/bruce-cesium.es5.js.map +1 -1
  3. package/dist/bruce-cesium.umd.js +429 -51
  4. package/dist/bruce-cesium.umd.js.map +1 -1
  5. package/dist/lib/bruce-cesium.js +1 -1
  6. package/dist/lib/rendering/displaced-surface-primitive.js +63 -24
  7. package/dist/lib/rendering/displaced-surface-primitive.js.map +1 -1
  8. package/dist/lib/rendering/entity-gatherer.js +249 -16
  9. package/dist/lib/rendering/entity-gatherer.js.map +1 -1
  10. package/dist/lib/rendering/entity-render-engine.js +22 -0
  11. package/dist/lib/rendering/entity-render-engine.js.map +1 -1
  12. package/dist/lib/rendering/render-managers/common/historic-utils.js +64 -7
  13. package/dist/lib/rendering/render-managers/common/historic-utils.js.map +1 -1
  14. package/dist/lib/rendering/render-managers/entities/entities-datalab-render-manager.js +5 -0
  15. package/dist/lib/rendering/render-managers/entities/entities-datalab-render-manager.js.map +1 -1
  16. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js +8 -3
  17. package/dist/lib/rendering/render-managers/entities/entities-ids-render-manager.js.map +1 -1
  18. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js +5 -0
  19. package/dist/lib/rendering/render-managers/entities/entities-loaded-render-manager.js.map +1 -1
  20. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js +5 -0
  21. package/dist/lib/rendering/render-managers/entities/entities-render-manager.js.map +1 -1
  22. package/dist/lib/rendering/visuals-register.js +8 -0
  23. package/dist/lib/rendering/visuals-register.js.map +1 -1
  24. package/dist/types/bruce-cesium.d.ts +1 -1
  25. package/dist/types/rendering/displaced-surface-primitive.d.ts +4 -0
  26. package/dist/types/rendering/entity-gatherer.d.ts +27 -4
  27. package/dist/types/rendering/entity-render-engine.d.ts +9 -0
  28. package/dist/types/rendering/render-managers/common/historic-utils.d.ts +12 -4
  29. package/dist/types/rendering/visuals-register.d.ts +5 -0
  30. package/package.json +1 -1
@@ -9493,6 +9493,14 @@
9493
9493
  }
9494
9494
  };
9495
9495
  }
9496
+ /**
9497
+ * Whether this register is holding a record of a visual.
9498
+ * @param visual
9499
+ */
9500
+ HasRego(visual) {
9501
+ const vis = visual;
9502
+ return Boolean(vis && vis._register === this && vis._rego);
9503
+ }
9496
9504
  /**
9497
9505
  * Locates a visual corresponding to a given entity id.
9498
9506
  * If no menu item id is provided, then it will pick the "best" one.
@@ -11019,10 +11027,6 @@
11019
11027
 
11020
11028
  /**
11021
11029
  * How often a historic refresh is worth running, and which Entities it should ask about first.
11022
- *
11023
- * A handful of tracked vehicles can afford to re-read on almost every clock tick. Thousands of
11024
- * parcels cannot, and refreshing them that often was never buying anything since the answer barely
11025
- * changes between ticks.
11026
11030
  */
11027
11031
  var HistoricFetchOrder;
11028
11032
  (function (HistoricFetchOrder) {
@@ -11067,6 +11071,13 @@
11067
11071
  HistoricFetchOrder.IntervalForClock = IntervalForClock;
11068
11072
  // Upper bounds in metres for the distance bands, nearest first.
11069
11073
  HistoricFetchOrder.DEFAULT_BANDS = [500, 2000, 10000, 50000];
11074
+ // How far outside the visible rectangle something still counts as worth re-reading, share of the view itself.
11075
+ HistoricFetchOrder.REFRESH_MARGIN_FRACTION = 0.5;
11076
+ // A close view still gets a usable buffer, and a distant one does not reach half the account.
11077
+ HistoricFetchOrder.MIN_REFRESH_MARGIN_METRES = 250;
11078
+ HistoricFetchOrder.MAX_REFRESH_MARGIN_METRES = 2000;
11079
+ const METRES_PER_DEGREE_LAT = 111320;
11080
+ const MIN_LAT_COSINE = 0.01;
11070
11081
  /**
11071
11082
  * Resolves what to order by from the view monitor, falling back to the camera itself.
11072
11083
  */
@@ -11147,6 +11158,55 @@
11147
11158
  return grouped.filter(group => group.length > 0);
11148
11159
  }
11149
11160
  HistoricFetchOrder.ByCameraDistanceOf = ByCameraDistanceOf;
11161
+ /**
11162
+ * Returns how far past a visible rectangle a refresh should still reach, in metres.
11163
+ */
11164
+ function RefreshMarginFor(bounds) {
11165
+ if (!bounds) {
11166
+ return HistoricFetchOrder.MIN_REFRESH_MARGIN_METRES;
11167
+ }
11168
+ const latSpan = Math.abs(bounds.north - bounds.south) * METRES_PER_DEGREE_LAT;
11169
+ const cosine = Math.max(MIN_LAT_COSINE, Math.cos(Cesium.Math.toRadians((bounds.north + bounds.south) / 2)));
11170
+ const lonDegrees = bounds.west > bounds.east
11171
+ ? (bounds.east + 360) - bounds.west
11172
+ : bounds.east - bounds.west;
11173
+ const lonSpan = Math.abs(lonDegrees) * METRES_PER_DEGREE_LAT * cosine;
11174
+ const span = Math.min(latSpan, lonSpan);
11175
+ if (!(span > 0)) {
11176
+ return HistoricFetchOrder.MIN_REFRESH_MARGIN_METRES;
11177
+ }
11178
+ return Math.min(HistoricFetchOrder.MAX_REFRESH_MARGIN_METRES, Math.max(HistoricFetchOrder.MIN_REFRESH_MARGIN_METRES, span * HistoricFetchOrder.REFRESH_MARGIN_FRACTION));
11179
+ }
11180
+ HistoricFetchOrder.RefreshMarginFor = RefreshMarginFor;
11181
+ /**
11182
+ * Returns the rectangle grown outwards by a margin in metres.
11183
+ */
11184
+ function GrowBounds(bounds, metres) {
11185
+ if (!bounds || !(metres > 0)) {
11186
+ return bounds;
11187
+ }
11188
+ const dLat = metres / METRES_PER_DEGREE_LAT;
11189
+ const north = Math.min(90, bounds.north + dLat);
11190
+ const south = Math.max(-90, bounds.south - dLat);
11191
+ const cosine = Math.cos(Cesium.Math.toRadians((bounds.north + bounds.south) / 2));
11192
+ if (cosine < MIN_LAT_COSINE) {
11193
+ return { north, south, west: -180, east: 180 };
11194
+ }
11195
+ const dLon = metres / (METRES_PER_DEGREE_LAT * cosine);
11196
+ const straddles = bounds.west > bounds.east;
11197
+ const gap = straddles ? bounds.west - bounds.east : 360 - (bounds.east - bounds.west);
11198
+ if (gap <= dLon * 2) {
11199
+ return { north, south, west: -180, east: 180 };
11200
+ }
11201
+ return { north, south, west: wrapLongitude(bounds.west - dLon), east: wrapLongitude(bounds.east + dLon) };
11202
+ }
11203
+ HistoricFetchOrder.GrowBounds = GrowBounds;
11204
+ /*
11205
+ * Returns a longitude folded back into the range the bounds are expressed in.
11206
+ */
11207
+ function wrapLongitude(lon) {
11208
+ return (((lon + 180) % 360) + 360) % 360 - 180;
11209
+ }
11150
11210
  /*
11151
11211
  * Returns whether a world position sits inside a ground rectangle given in degrees.
11152
11212
  */
@@ -11155,17 +11215,22 @@
11155
11215
  if (!degrees) {
11156
11216
  return false;
11157
11217
  }
11158
- const { lat, lon } = degrees;
11218
+ return InDegreeBounds(degrees.lat, degrees.lon, bounds);
11219
+ }
11220
+ HistoricFetchOrder.InBounds = InBounds;
11221
+ /*
11222
+ * The same test for a caller that already holds the degrees and should not pay to resolve them from a world position again.
11223
+ */
11224
+ function InDegreeBounds(lat, lon, bounds) {
11159
11225
  if (lat < bounds.south || lat > bounds.north) {
11160
11226
  return false;
11161
11227
  }
11162
- // A view straddling the antimeridian reports west east of east, so the span is the outside.
11163
11228
  if (bounds.west > bounds.east) {
11164
11229
  return lon >= bounds.west || lon <= bounds.east;
11165
11230
  }
11166
11231
  return lon >= bounds.west && lon <= bounds.east;
11167
11232
  }
11168
- HistoricFetchOrder.InBounds = InBounds;
11233
+ HistoricFetchOrder.InDegreeBounds = InDegreeBounds;
11169
11234
  /*
11170
11235
  * Returns an Entity's world position, or null when it has none to place it by.
11171
11236
  */
@@ -12659,6 +12724,11 @@
12659
12724
  optimizeTolerance: this.item.optimizeTolerance,
12660
12725
  });
12661
12726
  if (this.disposed) {
12727
+ exports.EntityRenderEngine.RemoveAll({
12728
+ viewer: this.viewer,
12729
+ entities: cEntities,
12730
+ register: this.visualsManager
12731
+ });
12662
12732
  this.doDispose();
12663
12733
  return;
12664
12734
  }
@@ -13660,6 +13730,11 @@
13660
13730
  force
13661
13731
  });
13662
13732
  if (this.disposed) {
13733
+ exports.EntityRenderEngine.RemoveAll({
13734
+ viewer: this.viewer,
13735
+ entities: cEntities,
13736
+ register: this.visualsManager
13737
+ });
13663
13738
  this.visualsManager.RemoveRegos({
13664
13739
  menuItemId: this.item.id
13665
13740
  });
@@ -14099,10 +14174,15 @@
14099
14174
  zoomControl: this.item.CameraZoomSettings,
14100
14175
  force: force || changed
14101
14176
  });
14177
+ if (this.disposed) {
14178
+ exports.EntityRenderEngine.RemoveAll({
14179
+ viewer: this.viewer,
14180
+ entities: cEntities,
14181
+ register: this.visualsManager
14182
+ });
14183
+ return;
14184
+ }
14102
14185
  for (let i = 0; i < entities.length; i++) {
14103
- if (this.disposed) {
14104
- break;
14105
- }
14106
14186
  const entity = entities[i];
14107
14187
  const id = entity.Bruce.ID;
14108
14188
  const cEntity = cEntities.get(id);
@@ -14536,6 +14616,19 @@
14536
14616
  // All IDs that have ever been queued.
14537
14617
  // When nothing is in queue, we'll re-request the existing IDs based on timeline changes.
14538
14618
  this.allEIds = new Set();
14619
+ // IDs a historic read has actually answered with a record, rather than falling back to a stub.
14620
+ // A refresh serves these before the ones that have never produced anything.
14621
+ this.everFound = new Set();
14622
+ // Every known Entity bucketed by the ground cell its position falls in, so a refresh can ask
14623
+ // what the view reaches instead of walking the whole set. Built as IDs arrive.
14624
+ this.cells = new Map();
14625
+ // IDs the position source could not place yet. They are always refreshed.
14626
+ this.unplaced = new Set();
14627
+ // The IDs the last decision found inside the view, so a camera move can queue the difference
14628
+ // rather than re-requesting everything it already asked about.
14629
+ this.lastInView = new Set();
14630
+ // Unsubscribes the view monitor listener that queues what the camera has moved onto.
14631
+ this.monitorRemoval = null;
14539
14632
  // Indicates a tick is active.
14540
14633
  // When true, we won't bother calling onTick again.
14541
14634
  this.runningTick = false;
@@ -14586,6 +14679,16 @@
14586
14679
  }
14587
14680
  this.historic = historic;
14588
14681
  this.expandSources = expandSources;
14682
+ if (this.historic) {
14683
+ // Anything already known was taken in before the index was being built, so it is filed
14684
+ // a bounded number at a time from here rather than in one pass now.
14685
+ for (const entityId of this.allEIds) {
14686
+ this.unplaced.add(entityId);
14687
+ }
14688
+ }
14689
+ else {
14690
+ this.clearIndex();
14691
+ }
14589
14692
  if (this.historic) {
14590
14693
  // 4 ticks per second.
14591
14694
  // The fastest data we are working with is 5 times per second.
@@ -14637,6 +14740,8 @@
14637
14740
  this.lastOrderFocus = null;
14638
14741
  this.allEIds.clear();
14639
14742
  this.lastFoundDateTimes.clear();
14743
+ this.everFound.clear();
14744
+ this.clearIndex();
14640
14745
  this.lastDateTime = null;
14641
14746
  }
14642
14747
  ReQueueAll() {
@@ -14647,22 +14752,193 @@
14647
14752
  this.eIdQueued = new Set(this.eIdQueue);
14648
14753
  this.priorityCount = 0;
14649
14754
  this.lastOrderFocus = null;
14755
+ this.clearIndex();
14650
14756
  }
14651
14757
  /**
14652
- * Supplies a lookup from Entity ID to world position, letting the queue resolve what the camera
14653
- * is nearest first. Sources that cannot answer should not call this, and are served in order.
14758
+ * Supplies a lookup from Entity ID to world position, letting the queue resolve what the camera is nearest first.
14759
+ * Sources that cannot answer should not call this, and are served in order.
14654
14760
  */
14655
14761
  SetPositionSource(positionOf) {
14656
14762
  this.positionOf = positionOf;
14657
14763
  this.lastOrderFocus = null;
14764
+ this.cells.clear();
14765
+ this.lastInView.clear();
14766
+ for (const entityId of this.allEIds) {
14767
+ this.unplaced.add(entityId);
14768
+ }
14658
14769
  }
14659
14770
  /**
14660
- * Supplies the view monitor, so the order follows the ground the camera is aimed at and prefers
14661
- * what is on screen. Without one the ordering falls back to distance from the camera itself.
14771
+ * Supplies the view monitor, so the order follows the ground the camera is aimed at and prefers what is on screen.
14772
+ * Without one the ordering falls back to distance from the camera itself.
14662
14773
  */
14663
14774
  SetViewMonitor(monitor) {
14775
+ var _a;
14776
+ (_a = this.monitorRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
14777
+ this.monitorRemoval = null;
14664
14778
  this.monitor = monitor;
14665
14779
  this.lastOrderFocus = null;
14780
+ if (!monitor) {
14781
+ return;
14782
+ }
14783
+ this.monitorRemoval = monitor.Updated().Subscribe(() => {
14784
+ this.admitNewlyInView();
14785
+ });
14786
+ }
14787
+ /*
14788
+ * Queues whatever the camera has moved onto since the last decision.
14789
+ */
14790
+ admitNewlyInView() {
14791
+ if (this.disposed || !this.historic) {
14792
+ return;
14793
+ }
14794
+ const inView = this.decideInView();
14795
+ if (!inView) {
14796
+ return;
14797
+ }
14798
+ const admit = [];
14799
+ for (const entityId of inView) {
14800
+ if (!this.lastInView.has(entityId)) {
14801
+ admit.push(entityId);
14802
+ }
14803
+ }
14804
+ this.lastInView = new Set(inView);
14805
+ if (admit.length) {
14806
+ this.Queue(admit);
14807
+ }
14808
+ }
14809
+ /*
14810
+ * Returns the IDs a refresh should ask about, or null when the view cannot say and the answer has to be everything.
14811
+ */
14812
+ decideInView() {
14813
+ if (!this.historic || !this.positionOf || !this.monitor) {
14814
+ return null;
14815
+ }
14816
+ const area = this.refreshArea();
14817
+ if (!area) {
14818
+ return null;
14819
+ }
14820
+ const inView = [];
14821
+ for (const key of this.candidateCellKeys(area)) {
14822
+ const cell = this.cells.get(key);
14823
+ if (!cell) {
14824
+ continue;
14825
+ }
14826
+ for (let i = 0; i < cell.ids.length; i++) {
14827
+ if (HistoricFetchOrder.InDegreeBounds(cell.lats[i], cell.lons[i], area)) {
14828
+ inView.push(cell.ids[i]);
14829
+ }
14830
+ }
14831
+ }
14832
+ // Anything the source cannot place yet is asked about rather than quietly dropped.
14833
+ for (const entityId of this.unplaced) {
14834
+ inView.push(entityId);
14835
+ }
14836
+ return inView;
14837
+ }
14838
+ /*
14839
+ * Returns the cell keys a rectangle can reach.
14840
+ */
14841
+ candidateCellKeys(area) {
14842
+ const size = EntityGatherer.CELL_DEGREES;
14843
+ const southCell = Math.floor(area.south / size);
14844
+ const northCell = Math.floor(area.north / size);
14845
+ const spans = (area.west > area.east ? [
14846
+ {
14847
+ from: Math.floor(area.west / size),
14848
+ to: Math.floor(180 / size)
14849
+ },
14850
+ {
14851
+ from: Math.floor(-180 / size),
14852
+ to: Math.floor(area.east / size)
14853
+ }
14854
+ ] :
14855
+ [{
14856
+ from: Math.floor(area.west / size),
14857
+ to: Math.floor(area.east / size)
14858
+ }]);
14859
+ let width = 0;
14860
+ for (const span of spans) {
14861
+ width += (span.to - span.from) + 1;
14862
+ }
14863
+ const wanted = ((northCell - southCell) + 1) * width;
14864
+ if (!(wanted > 0) || wanted > this.cells.size) {
14865
+ return Array.from(this.cells.keys());
14866
+ }
14867
+ const keys = [];
14868
+ for (let lat = southCell; lat <= northCell; lat++) {
14869
+ for (const span of spans) {
14870
+ for (let lon = span.from; lon <= span.to; lon++) {
14871
+ keys.push(lat + ":" + lon);
14872
+ }
14873
+ }
14874
+ }
14875
+ return keys;
14876
+ }
14877
+ /*
14878
+ * Files an Entity in the cell its position falls in.
14879
+ */
14880
+ place(entityId) {
14881
+ const degrees = this.degreesOf(entityId);
14882
+ if (!degrees) {
14883
+ this.unplaced.add(entityId);
14884
+ return;
14885
+ }
14886
+ const size = EntityGatherer.CELL_DEGREES;
14887
+ const key = Math.floor(degrees.lat / size) + ":" + Math.floor(degrees.lon / size);
14888
+ let cell = this.cells.get(key);
14889
+ if (!cell) {
14890
+ cell = { ids: [], lats: [], lons: [] };
14891
+ this.cells.set(key, cell);
14892
+ }
14893
+ cell.ids.push(entityId);
14894
+ cell.lats.push(degrees.lat);
14895
+ cell.lons.push(degrees.lon);
14896
+ this.unplaced.delete(entityId);
14897
+ }
14898
+ /*
14899
+ * Retries a bounded number of the Entities the source could not place before, so a late baked
14900
+ * position joins the index without any one tick paying for all of them.
14901
+ */
14902
+ placeStragglers() {
14903
+ if (!this.unplaced.size || !this.positionOf) {
14904
+ return;
14905
+ }
14906
+ let budget = EntityGatherer.PLACE_BATCH;
14907
+ for (const entityId of this.unplaced) {
14908
+ if (budget-- <= 0) {
14909
+ return;
14910
+ }
14911
+ this.place(entityId);
14912
+ }
14913
+ }
14914
+ clearIndex() {
14915
+ this.cells.clear();
14916
+ this.unplaced.clear();
14917
+ this.lastInView.clear();
14918
+ }
14919
+ /*
14920
+ * Returns where an Entity sits in degrees, or null when the source cannot place it.
14921
+ */
14922
+ degreesOf(entityId) {
14923
+ let pos = null;
14924
+ try {
14925
+ pos = this.positionOf ? this.positionOf(entityId) : null;
14926
+ }
14927
+ catch {
14928
+ pos = null;
14929
+ }
14930
+ return pos ? CartesianToDegrees(pos) : null;
14931
+ }
14932
+ /*
14933
+ * Returns the visible rectangle plus the margin a refresh still reaches into,
14934
+ * or null when the view cannot say, which is what leaves every Entity in.
14935
+ */
14936
+ refreshArea() {
14937
+ const focus = HistoricFetchOrder.FocusFrom({ viewer: this.viewer, monitor: this.monitor });
14938
+ if (!(focus === null || focus === void 0 ? void 0 : focus.bounds)) {
14939
+ return null;
14940
+ }
14941
+ return HistoricFetchOrder.GrowBounds(focus.bounds, HistoricFetchOrder.RefreshMarginFor(focus.bounds));
14666
14942
  }
14667
14943
  /**
14668
14944
  * Re-bands the pending queue so the nearest Entities are requested first.
@@ -14675,8 +14951,6 @@
14675
14951
  if (!focus) {
14676
14952
  return;
14677
14953
  }
14678
- // Re-banding on every batch would cost a full pass per request for no change in the answer.
14679
- // Measured on the focus, so panning across the ground counts even when the eye barely moves.
14680
14954
  if (this.lastOrderFocus && !EntityGatherer.boundsChanged(this.lastOrderFocus, focus) &&
14681
14955
  Cesium.Cartesian3.distance(this.lastOrderFocus.origin, focus.origin) < EntityGatherer.REORDER_MOVE_METRES) {
14682
14956
  return;
@@ -14723,26 +14997,47 @@
14723
14997
  });
14724
14998
  const ordered = [];
14725
14999
  for (const band of banded) {
15000
+ // Within a band, the ones a read has answered for go first.
15001
+ // A building that has never produced a record is the one least likely to start now, so it waits.
15002
+ const withData = [];
15003
+ const withoutData = [];
14726
15004
  for (const entityId of band) {
15005
+ (this.everFound.has(entityId) ? withData : withoutData).push(entityId);
15006
+ }
15007
+ for (const entityId of withData) {
15008
+ ordered.push(entityId);
15009
+ }
15010
+ for (const entityId of withoutData) {
14727
15011
  ordered.push(entityId);
14728
15012
  }
14729
15013
  }
14730
15014
  return ordered;
14731
15015
  }
15016
+ /*
15017
+ * Takes an ID into the known set, filing it in the index the first time it is seen.
15018
+ */
15019
+ remember(entityId) {
15020
+ if (this.allEIds.has(entityId)) {
15021
+ return;
15022
+ }
15023
+ this.allEIds.add(entityId);
15024
+ // Only a historic refresh reads the index, so nothing else pays to build it.
15025
+ if (this.historic) {
15026
+ this.place(entityId);
15027
+ }
15028
+ }
14732
15029
  Queue(entityIds, topOfQueue = false) {
14733
15030
  if (this.disposed || !(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
14734
15031
  return;
14735
15032
  }
14736
15033
  let changes = 0;
14737
15034
  if (topOfQueue) {
14738
- // Walked back to front so a repeated ID keeps the position of its last occurrence, then
14739
- // laid down in that order, which is where inserting one at a time leaves them.
14740
15035
  const toFront = [];
14741
15036
  const promoting = new Set();
14742
15037
  let anyAlreadyQueued = false;
14743
15038
  for (let i = entityIds.length - 1; i >= 0; i--) {
14744
15039
  const eId = entityIds[i];
14745
- this.allEIds.add(eId);
15040
+ this.remember(eId);
14746
15041
  if (promoting.has(eId)) {
14747
15042
  continue;
14748
15043
  }
@@ -14778,7 +15073,7 @@
14778
15073
  else {
14779
15074
  for (let i = 0; i < entityIds.length; i++) {
14780
15075
  const eId = entityIds[i];
14781
- this.allEIds.add(eId);
15076
+ this.remember(eId);
14782
15077
  if (this.eIdQueued.has(eId)) {
14783
15078
  continue;
14784
15079
  }
@@ -14793,19 +15088,22 @@
14793
15088
  this.onTick(false);
14794
15089
  }
14795
15090
  Dispose() {
15091
+ var _a;
14796
15092
  if (this.disposed) {
14797
15093
  return;
14798
15094
  }
14799
15095
  this.disposed = true;
15096
+ (_a = this.monitorRemoval) === null || _a === void 0 ? void 0 : _a.call(this);
15097
+ this.monitorRemoval = null;
14800
15098
  this.hDisposals.forEach((d) => d());
14801
15099
  this.hDisposals = [];
14802
- // A tick still awaiting a response resumes after this, and anything left here would have it
14803
- // ask for the whole set again on the way out.
14804
15100
  this.eIdQueue = [];
14805
15101
  this.eIdQueued.clear();
14806
15102
  this.priorityCount = 0;
14807
15103
  this.allEIds.clear();
14808
15104
  this.lastFoundDateTimes.clear();
15105
+ this.everFound.clear();
15106
+ this.clearIndex();
14809
15107
  this.entityDataOverrides.clear();
14810
15108
  }
14811
15109
  checkRange(force) {
@@ -14829,6 +15127,7 @@
14829
15127
  this.lastDateTime = rTime;
14830
15128
  (async () => {
14831
15129
  this.runningTick = true;
15130
+ this.placeStragglers();
14832
15131
  let rerun = false;
14833
15132
  try {
14834
15133
  const handleResponse = async (requestedBatch, entities) => {
@@ -14841,6 +15140,13 @@
14841
15140
  foundById.set(entityId, entity);
14842
15141
  }
14843
15142
  }
15143
+ if (this.historic) {
15144
+ for (const entityId of requestedBatch || []) {
15145
+ if (foundById.has(entityId)) {
15146
+ this.everFound.add(entityId);
15147
+ }
15148
+ }
15149
+ }
14844
15150
  for (const entityId of requestedBatch || []) {
14845
15151
  const override = this.entityDataOverrides.get(entityId);
14846
15152
  if (override) {
@@ -14969,15 +15275,16 @@
14969
15275
  this._onQueueProgress.Trigger(100);
14970
15276
  }
14971
15277
  }
14972
- // Now run through all IDs that we've seen and request them.
15278
+ // Now run through the IDs we've seen that the view still reaches, and request them.
14973
15279
  // We'll skip those that we just requested.
14974
- let allEIds = Array.from(this.allEIds);
15280
+ const inView = this.decideInView();
15281
+ this.lastInView = inView ? new Set(inView) : new Set();
15282
+ let allEIds = inView || Array.from(this.allEIds);
14975
15283
  if (requestedIds.size) {
14976
15284
  allEIds = allEIds.filter((eId) => !requestedIds.has(eId));
14977
15285
  }
14978
15286
  if (allEIds.length) {
14979
- // A historic tick re-reads the whole set, so the near ones are worth resolving
14980
- // first here even more than in the queue above.
15287
+ // The near ones are resolved first out of whatever the view still reaches.
14981
15288
  allEIds = this.bandIds(allEIds);
14982
15289
  while (allEIds.length && !this.disposed && !this.eIdQueue.length) {
14983
15290
  if (this.historic && this.lastDateTime !== rTime) {
@@ -15016,6 +15323,11 @@
15016
15323
  }
15017
15324
  // Below this the whole queue clears in one or two requests, so ordering it buys nothing.
15018
15325
  EntityGatherer.MIN_ORDER_QUEUE = 500;
15326
+ // Side of the ground cells Entities are bucketed into, in degrees.
15327
+ // About a kilometre, so a view covers a handful of them rather than hundreds.
15328
+ EntityGatherer.CELL_DEGREES = 0.01;
15329
+ // How many Entities one tick will try to place in the index.
15330
+ EntityGatherer.PLACE_BATCH = 20000;
15019
15331
  // How far the point being looked at has to move before the queue is worth re-banding, in metres.
15020
15332
  // Under the nearest band's width, so a move that could change what is nearest still triggers one.
15021
15333
  EntityGatherer.REORDER_MOVE_METRES = 250;
@@ -19471,6 +19783,11 @@
19471
19783
  force
19472
19784
  });
19473
19785
  if (this.disposed) {
19786
+ exports.EntityRenderEngine.RemoveAll({
19787
+ viewer: this.viewer,
19788
+ entities: cEntities,
19789
+ register: this.visualsManager
19790
+ });
19474
19791
  return;
19475
19792
  }
19476
19793
  for (let i = 0; i < entities.length; i++) {
@@ -43545,17 +43862,21 @@ uniform vec2 u_maskGroundSize;
43545
43862
  uniform vec4 u_extentDegrees;
43546
43863
  uniform vec4 u_maskGroundDegrees;
43547
43864
  uniform float u_coverageCutoffVertex;
43865
+ //#water
43548
43866
  uniform vec2 u_extentMetres;
43549
43867
  uniform vec2 u_waveOrigin;
43868
+ //#endwater
43550
43869
 
43551
43870
  out vec2 v_st;
43552
43871
  out float v_value;
43553
43872
  out float v_coverage;
43873
+ //#water
43554
43874
  out vec3 v_positionEC;
43555
43875
  out vec3 v_eastEC;
43556
43876
  out vec3 v_northEC;
43557
43877
  out vec3 v_upEC;
43558
43878
  out vec2 v_waveMetres;
43879
+ //#endwater
43559
43880
 
43560
43881
  float decodeGround(vec2 uv) {
43561
43882
  // Channels arrive normalised to 0..1, so they go back to bytes before being reassembled.
@@ -43675,6 +43996,7 @@ void main() {
43675
43996
  // would be lost to float32 rounding at an earth radius.
43676
43997
  vec4 p = czm_translateRelativeToEye(position3DHigh, position3DLow + normal * displacement);
43677
43998
 
43999
+ //#water
43678
44000
  // The local frame at this vertex so a shading normal built in east/north/up meters can be turned into something usable.
43679
44001
  v_upEC = czm_normal * normal;
43680
44002
  vec3 east = normalize(cross(vec3(0.0, 0.0, 1.0), normal));
@@ -43682,16 +44004,9 @@ void main() {
43682
44004
  v_northEC = czm_normal * cross(normal, east);
43683
44005
  v_positionEC = (czm_modelViewRelativeToEye * p).xyz;
43684
44006
 
43685
- /*
43686
- * Where this vertex sits in the ripple field, in metres from an origin that follows the camera.
43687
- *
43688
- * Subtracted here rather than in the fragment shader because the position it is subtracted from
43689
- * spans the whole archive, which over a sound is tens of kilometres. A wave number times that
43690
- * is thousands of radians, and no fragment shader that may only have mediump can step through a
43691
- * cosine at that magnitude: the ripples come out as a flat surface, which is what a first cut of
43692
- * this did. What crosses into the fragment shader is a small number the camera is standing in.
43693
- */
44007
+ // Where this vertex sits in the ripple field, in metres from an origin that follows the camera.
43694
44008
  v_waveMetres = st * u_extentMetres - u_waveOrigin;
44009
+ //#endwater
43695
44010
 
43696
44011
  gl_Position = czm_modelViewProjectionRelativeToEye * p;
43697
44012
  }
@@ -43705,7 +44020,7 @@ uniform float u_valuePacked;
43705
44020
  uniform float u_valueRange;
43706
44021
  uniform float u_exaggeration;
43707
44022
  uniform float u_metresPerTexel;
43708
- uniform float u_waterOn;
44023
+ //#water
43709
44024
  uniform float u_waterWavelength;
43710
44025
  uniform float u_waterAmplitude;
43711
44026
  uniform float u_waterReflectivity;
@@ -43717,15 +44032,18 @@ uniform vec4 u_wavePhase;
43717
44032
  uniform vec4 u_wavePhaseB;
43718
44033
  // Metres the whole ripple field repeats over.
43719
44034
  uniform float u_wavePeriod;
44035
+ //#endwater
43720
44036
 
43721
44037
  in vec2 v_st;
43722
44038
  in float v_value;
43723
44039
  in float v_coverage;
44040
+ //#water
43724
44041
  in vec3 v_positionEC;
43725
44042
  in vec3 v_eastEC;
43726
44043
  in vec3 v_northEC;
43727
44044
  in vec3 v_upEC;
43728
44045
  in vec2 v_waveMetres;
44046
+ //#endwater
43729
44047
 
43730
44048
  /*
43731
44049
  * Scaled per channel for the same reason the vertex shader's decode is: reassembling the pair reaches
@@ -43737,6 +44055,7 @@ float valueAt(vec2 uv) {
43737
44055
  return mix(texel.r, packed16, u_valuePacked);
43738
44056
  }
43739
44057
 
44058
+ //#water
43740
44059
  /*
43741
44060
  * Slope of the ripple field at a point, in metres of rise per metre travelled.
43742
44061
  */
@@ -43812,6 +44131,7 @@ vec4 water(vec3 relief, vec4 color) {
43812
44131
  alpha = clamp(alpha + (1.0 - alpha) * (fresnel * 0.55 + glint), 0.0, 1.0);
43813
44132
  return vec4(lit, alpha);
43814
44133
  }
44134
+ //#endwater
43815
44135
 
43816
44136
  void main() {
43817
44137
  if (v_coverage < u_coverageCutoff) {
@@ -43834,10 +44154,10 @@ void main() {
43834
44154
  float scale = u_valueRange * u_exaggeration;
43835
44155
  vec3 n = normalize(vec3((left - right) * scale, (down - up) * scale, 2.0 * u_metresPerTexel));
43836
44156
 
43837
- if (u_waterOn > 0.5) {
43838
- out_FragColor = water(n, color);
43839
- return;
43840
- }
44157
+ //#water
44158
+ out_FragColor = water(n, color);
44159
+ return;
44160
+ //#endwater
43841
44161
 
43842
44162
  float lambert = clamp(dot(n, normalize(vec3(-0.5, -0.6, 0.62))), 0.0, 1.0);
43843
44163
  color.rgb *= 0.45 + 0.9 * lambert;
@@ -43845,6 +44165,15 @@ void main() {
43845
44165
  out_FragColor = vec4(color.rgb, color.a * v_coverage);
43846
44166
  }
43847
44167
  `;
44168
+ /*
44169
+ * Strips the water-only regions out of a shader source unless this surface is drawing water.
44170
+ */
44171
+ function withWater(source, water) {
44172
+ if (water) {
44173
+ return source.replace(/^\/\/#(end)?water\n/gm, "");
44174
+ }
44175
+ return source.replace(/^\/\/#water\n[\s\S]*?^\/\/#endwater\n/gm, "");
44176
+ }
43848
44177
  /*
43849
44178
  * Rewrites a GLSL 300 es source into the GLSL 100 dialect older Cesium builds author in.
43850
44179
  */
@@ -44173,6 +44502,7 @@ void main() {
44173
44502
  this.texture = null;
44174
44503
  this.textureDirty = true;
44175
44504
  this.shaderProgram = null;
44505
+ this.shaderProgramWater = false;
44176
44506
  this.renderState = null;
44177
44507
  this.destroyed = false;
44178
44508
  this.lastEyePosition = null;
@@ -44192,6 +44522,10 @@ void main() {
44192
44522
  this.water = null;
44193
44523
  this.waterStartMs = now();
44194
44524
  this.waveOrigin = new Cesium.Cartesian2(0, 0);
44525
+ this.extentMetresCache = null;
44526
+ // Written in place each frame rather than reallocated, since they are read per tile.
44527
+ this.wavePhaseScratch = [new Cesium.Cartesian4(), new Cesium.Cartesian4()];
44528
+ this.waterSkyScratch = new Cesium.Cartesian3();
44195
44529
  this.followGround = Boolean(options.followGround);
44196
44530
  this.terrainProvider = options.terrainProvider || null;
44197
44531
  this.extent = options.extent;
@@ -44616,32 +44950,45 @@ void main() {
44616
44950
  * 0..1 surface coordinate into the real distance the ripple wavelength is measured in.
44617
44951
  */
44618
44952
  extentMetres() {
44953
+ // The extent never moves, and this is read once per tile per frame.
44954
+ if (this.extentMetresCache) {
44955
+ return this.extentMetresCache;
44956
+ }
44619
44957
  const southWest = Cesium.Cartesian3.fromDegrees(this.extent.West, this.extent.South, 0);
44620
44958
  const southEast = Cesium.Cartesian3.fromDegrees(this.extent.East, this.extent.South, 0);
44621
44959
  const northWest = Cesium.Cartesian3.fromDegrees(this.extent.West, this.extent.North, 0);
44622
- return new Cesium.Cartesian2(Math.max(1, Cesium.Cartesian3.distance(southWest, southEast)), Math.max(1, Cesium.Cartesian3.distance(southWest, northWest)));
44960
+ this.extentMetresCache = new Cesium.Cartesian2(Math.max(1, Cesium.Cartesian3.distance(southWest, southEast)), Math.max(1, Cesium.Cartesian3.distance(southWest, northWest)));
44961
+ return this.extentMetresCache;
44623
44962
  }
44624
44963
  /*
44625
44964
  * Where each ripple layer has scrolled to, wrapped into one turn.
44626
44965
  */
44627
44966
  wavePhase(from) {
44628
44967
  var _a;
44968
+ const into = this.wavePhaseScratch[from / 4];
44629
44969
  const water = this.water;
44630
44970
  if (!water) {
44631
- return new Cesium.Cartesian4(0, 0, 0, 0);
44971
+ return Cesium.Cartesian4.clone(Cesium.Cartesian4.ZERO, into);
44632
44972
  }
44633
44973
  const speed = (_a = water.speed) !== null && _a !== void 0 ? _a : DEFAULT_WATER_SPEED_METRES_PER_SECOND;
44634
44974
  const period = this.wavePeriod();
44635
44975
  const seconds = (now() - this.waterStartMs) / 1000;
44636
44976
  const base = waveCycles(WATER_WAVES[WATER_BASE_WAVE]);
44637
- const phases = WATER_WAVES.slice(from, from + 4).map((wave) => {
44977
+ const phaseAt = (index) => {
44978
+ const wave = WATER_WAVES[from + index];
44979
+ if (!wave) {
44980
+ return 0;
44981
+ }
44638
44982
  const cycles = waveCycles(wave);
44639
44983
  const waveNumber = 2 * Math.PI * cycles / period;
44640
44984
  const travels = Math.sqrt(base / cycles);
44641
- const travelled = seconds * speed * travels * waveNumber;
44642
- return travelled % (2 * Math.PI);
44643
- });
44644
- return new Cesium.Cartesian4(phases[0] || 0, phases[1] || 0, phases[2] || 0, phases[3] || 0);
44985
+ return (seconds * speed * travels * waveNumber) % (2 * Math.PI);
44986
+ };
44987
+ into.x = phaseAt(0);
44988
+ into.y = phaseAt(1);
44989
+ into.z = phaseAt(2);
44990
+ into.w = phaseAt(3);
44991
+ return into;
44645
44992
  }
44646
44993
  wavePeriod() {
44647
44994
  const wavelength = (this.water && this.water.wavelength) || DEFAULT_WATER_WAVELENGTH_METRES;
@@ -44828,14 +45175,22 @@ void main() {
44828
45175
  return isFinite(nearest) ? Math.max(1, nearest) : 1;
44829
45176
  }
44830
45177
  commandFor(context, tile, mesh) {
45178
+ // Rebuilt when the effect is switched, since which program is wanted is part of it.
45179
+ const wantsWater = Boolean(this.water);
45180
+ if (this.shaderProgram && this.shaderProgramWater !== wantsWater) {
45181
+ this.shaderProgram = null;
45182
+ }
44831
45183
  if (!this.shaderProgram) {
44832
45184
  const glsl300 = usesGlsl300(context);
45185
+ const vertex = withWater(VERTEX_SHADER_GLSL300, wantsWater);
45186
+ const fragment = withWater(FRAGMENT_SHADER_GLSL300, wantsWater);
44833
45187
  this.shaderProgram = Cesium.ShaderProgram.fromCache({
44834
45188
  context,
44835
- vertexShaderSource: glsl300 ? VERTEX_SHADER_GLSL300 : toGlsl100(VERTEX_SHADER_GLSL300, false),
44836
- fragmentShaderSource: glsl300 ? FRAGMENT_SHADER_GLSL300 : toGlsl100(FRAGMENT_SHADER_GLSL300, true),
45189
+ vertexShaderSource: glsl300 ? vertex : toGlsl100(vertex, false),
45190
+ fragmentShaderSource: glsl300 ? fragment : toGlsl100(fragment, true),
44837
45191
  attributeLocations: mesh.attributeLocations
44838
45192
  });
45193
+ this.shaderProgramWater = wantsWater;
44839
45194
  this.renderState = Cesium.RenderState.fromCache({
44840
45195
  depthTest: { enabled: true },
44841
45196
  // Translucent ramp: blend, and leave the depth buffer to the opaque world.
@@ -44911,7 +45266,7 @@ void main() {
44911
45266
  },
44912
45267
  u_waterSky: () => {
44913
45268
  const sky = (self.water && self.water.skyColor) || DEFAULT_WATER_SKY_COLOR;
44914
- return new Cesium.Cartesian3(sky.red / 255, sky.green / 255, sky.blue / 255);
45269
+ return Cesium.Cartesian3.fromElements(sky.red / 255, sky.green / 255, sky.blue / 255, self.waterSkyScratch);
44915
45270
  },
44916
45271
  u_wavePhase: () => self.wavePhase(0),
44917
45272
  u_wavePhaseB: () => self.wavePhase(4),
@@ -44922,6 +45277,7 @@ void main() {
44922
45277
  });
44923
45278
  }
44924
45279
  // Bounding volume belongs to the mesh, so it follows whichever tier is drawing.
45280
+ tile.command.shaderProgram = this.shaderProgram;
44925
45281
  tile.command.vertexArray = mesh.vertexArray;
44926
45282
  tile.command.boundingVolume = mesh.boundingSphere;
44927
45283
  return tile.command;
@@ -46870,6 +47226,28 @@ void main() {
46870
47226
  };
46871
47227
  }
46872
47228
  EntityRenderEngine.Render = Render;
47229
+ /**
47230
+ * Removes what a render produced that nothing has a record of, for a render whose caller has gone away.
47231
+ * @param params
47232
+ */
47233
+ function RemoveAll(params) {
47234
+ const { viewer, entities, register } = params;
47235
+ if (!entities || viewer.isDestroyed()) {
47236
+ return;
47237
+ }
47238
+ entities.forEach((entity) => {
47239
+ if (!entity || (register === null || register === void 0 ? void 0 : register.HasRego(entity))) {
47240
+ return;
47241
+ }
47242
+ try {
47243
+ Remove({ viewer, entity });
47244
+ }
47245
+ catch (e) {
47246
+ console.error("EntityRenderEngine.RemoveAll: failed to remove a visual:", e);
47247
+ }
47248
+ });
47249
+ }
47250
+ EntityRenderEngine.RemoveAll = RemoveAll;
46873
47251
  function Remove(params) {
46874
47252
  function doRemove(params) {
46875
47253
  const { viewer, entity, ignoreParent } = params;
@@ -47695,7 +48073,7 @@ void main() {
47695
48073
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
47696
48074
  })(exports.StyleUtils || (exports.StyleUtils = {}));
47697
48075
 
47698
- const VERSION = "7.3.7";
48076
+ const VERSION = "7.3.9";
47699
48077
  /**
47700
48078
  * Updates the environment instance used by bruce-cesium to one specified.
47701
48079
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.