bruce-cesium 7.0.3 → 7.0.5

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.
@@ -6068,7 +6068,22 @@
6068
6068
  }
6069
6069
  return obj;
6070
6070
  }
6071
+ /*
6072
+ * Cache identity for a terrain provider we cannot name, which is anything without our own metadata on it and not
6073
+ * Cesium's own flat ellipsoid. Deliberately not FlatTerrain, see shouldCullEntity.
6074
+ */
6075
+ const UNRECOGNISED_TERRAIN_ID = "unrecognised-terrain";
6076
+ // Keyed by entity id alone. A cached sphere is only as good as the geometry it was measured from, so anything
6077
+ // changing that geometry has to call InvalidateBounds, see it for why nothing can be inferred instead.
6071
6078
  const boundingSphereCache = new BModels.LRUCache(100000);
6079
+ /*
6080
+ * Forgets what is known about an entity's extent, so the next check measures it again.
6081
+ */
6082
+ function invalidateBounds(entityIds) {
6083
+ for (let i = 0; i < entityIds.length; i++) {
6084
+ boundingSphereCache.Delete(entityIds[i]);
6085
+ }
6086
+ }
6072
6087
  function getPositionsFromEntity(viewer, entity) {
6073
6088
  let positions = [];
6074
6089
  let heightRef;
@@ -6185,10 +6200,11 @@
6185
6200
  let boundingSphere;
6186
6201
  const terrainId = (_c = (_b = (_a = exports.ViewUtils.GatherTerrainTile({
6187
6202
  viewer
6188
- })) === null || _a === void 0 ? void 0 : _a.terrain) === null || _b === void 0 ? void 0 : _b.tilesetId) !== null && _c !== void 0 ? _c : BModels.ProjectViewTile.EDefaultTerrain.FlatTerrain;
6189
- const cacheKey = terrainId + cEntity.id;
6203
+ })) === null || _a === void 0 ? void 0 : _a.terrain) === null || _b === void 0 ? void 0 : _b.tilesetId) !== null && _c !== void 0 ? _c : UNRECOGNISED_TERRAIN_ID;
6204
+ const cacheKey = cEntity.id;
6190
6205
  const cacheData = boundingSphereCache.Get(cacheKey);
6191
- if (cacheData) {
6206
+ // A sphere measured under different terrain cannot be reused, since the height treatment differs.
6207
+ if (cacheData && (cacheData == -1 || cacheData.terrainId == terrainId)) {
6192
6208
  boundingSphere = cacheData;
6193
6209
  }
6194
6210
  else {
@@ -6244,7 +6260,8 @@
6244
6260
  }
6245
6261
  boundingSphere = {
6246
6262
  heightRef: positions.heightRef,
6247
- sphere: sphere
6263
+ sphere: sphere,
6264
+ terrainId: terrainId
6248
6265
  };
6249
6266
  if (!doNotCache) {
6250
6267
  boundingSphereCache.Set(cacheKey, boundingSphere);
@@ -6339,6 +6356,8 @@
6339
6356
  rego.relation != null ||
6340
6357
  // Explicitly being either shown or hidden.
6341
6358
  rego.overrideShow != null ||
6359
+ // Being dragged around right now, so its extent is changing faster than we could measure it.
6360
+ rego.editing == true ||
6342
6361
  // Part of a collection we did not create, eg. a geojson data source, which may have its own rules for
6343
6362
  // what is in the scene. Our own per-menu-item data sources are fair game.
6344
6363
  (rego.collection && !IsCCollectionOwned(rego.collection)) ||
@@ -6627,6 +6646,38 @@
6627
6646
  return isCullingIgnored(viewer, rego);
6628
6647
  }
6629
6648
  VisualRegisterCuller.IsCullingIgnored = IsCullingIgnored;
6649
+ /**
6650
+ * Discards what the culler knows about an entity's extent, so its next check measures the geometry again.
6651
+ * @param visuals an entity, an entity id, or an array of either.
6652
+ */
6653
+ function InvalidateBounds(visuals) {
6654
+ const list = Array.isArray(visuals) ? visuals : [visuals];
6655
+ const ids = [];
6656
+ for (let i = 0; i < list.length; i++) {
6657
+ const item = list[i];
6658
+ if (!item) {
6659
+ continue;
6660
+ }
6661
+ if (typeof item == "string") {
6662
+ ids.push(item);
6663
+ continue;
6664
+ }
6665
+ const parts = exports.EntityUtils.GatherEntity({
6666
+ entity: item
6667
+ });
6668
+ for (let j = 0; j < parts.length; j++) {
6669
+ const part = parts[j];
6670
+ if (!(part instanceof Cesium.Entity)) {
6671
+ continue;
6672
+ }
6673
+ ids.push(part.id);
6674
+ // The per-entity answer is derived from the sphere, so it goes stale with it.
6675
+ delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
6676
+ }
6677
+ }
6678
+ invalidateBounds(ids);
6679
+ }
6680
+ VisualRegisterCuller.InvalidateBounds = InvalidateBounds;
6630
6681
  function IsCulled(viewer, rego, visual) {
6631
6682
  if (isCullingIgnored(viewer, rego)) {
6632
6683
  return false;
@@ -8093,6 +8144,58 @@
8093
8144
  exports.CesiumEntityStyler.UpdateColorSetting("highlight", color);
8094
8145
  }
8095
8146
  }
8147
+ /**
8148
+ * Marks visuals as being actively edited, which exempts them from culling until it is turned back off.
8149
+ */
8150
+ SetEditing(params) {
8151
+ var _a, _b;
8152
+ const { entityIds, editing, menuItemId, requestRender } = params;
8153
+ if (!(entityIds === null || entityIds === void 0 ? void 0 : entityIds.length)) {
8154
+ return;
8155
+ }
8156
+ let changed = false;
8157
+ for (let i = 0; i < entityIds.length; i++) {
8158
+ const regos = this.rego[entityIds[i]];
8159
+ if (!regos) {
8160
+ continue;
8161
+ }
8162
+ for (let j = 0; j < regos.length; j++) {
8163
+ const rego = regos[j];
8164
+ if (menuItemId && rego.menuItemId !== menuItemId) {
8165
+ continue;
8166
+ }
8167
+ if (Boolean(rego.editing) == Boolean(editing)) {
8168
+ continue;
8169
+ }
8170
+ // Null rather than false, so the rego does not carry a key for every visual ever edited.
8171
+ rego.editing = editing ? true : null;
8172
+ changed = true;
8173
+ if (editing) {
8174
+ const parts = exports.EntityUtils.GatherEntity({
8175
+ entity: rego.visual
8176
+ });
8177
+ for (let k = 0; k < parts.length; k++) {
8178
+ const part = parts[k];
8179
+ if (!(part instanceof Cesium.Entity)) {
8180
+ continue;
8181
+ }
8182
+ const wasCulled = part[VisualRegisterCuller.VISUAL_CULL_KEY];
8183
+ delete part[VisualRegisterCuller.VISUAL_CULL_KEY];
8184
+ if (wasCulled && !IsCEntityInScene(this.viewer, part)) {
8185
+ AddCEntityToScene(this.viewer, part, rego.collection);
8186
+ }
8187
+ }
8188
+ }
8189
+ else {
8190
+ // The geometry almost certainly moved, so what was measured before is worthless.
8191
+ VisualRegisterCuller.InvalidateBounds(rego.visual);
8192
+ }
8193
+ }
8194
+ }
8195
+ if (changed && requestRender != false) {
8196
+ (_b = (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.scene) === null || _b === void 0 ? void 0 : _b.requestRender();
8197
+ }
8198
+ }
8096
8199
  SetSelected(params) {
8097
8200
  var _a;
8098
8201
  let { entityIds, selected, refreshIfSelected, requestRender, menuItemId, source } = params;
@@ -39423,6 +39526,7 @@
39423
39526
  if (bandCheck) {
39424
39527
  cEntity._bandCheck = bandCheck;
39425
39528
  }
39529
+ VisualRegisterCuller.InvalidateBounds(cEntity);
39426
39530
  });
39427
39531
  return {
39428
39532
  entities: cEntities,
@@ -40189,7 +40293,7 @@
40189
40293
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
40190
40294
  })(exports.StyleUtils || (exports.StyleUtils = {}));
40191
40295
 
40192
- const VERSION = "7.0.3";
40296
+ const VERSION = "7.0.5";
40193
40297
  /**
40194
40298
  * Updates the environment instance used by bruce-cesium to one specified.
40195
40299
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.