bruce-cesium 3.1.4 → 3.1.6

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.
@@ -1,6 +1,6 @@
1
1
  import { Cartes, ProjectViewTile, Carto, Entity as Entity$1, Geometry, Tileset, MathUtils, LRUCache, DelayQueue, ZoomControl, Style, EntityTag, Calculator, EntityLod, EntityType, ClientFile, ObjectUtils, Bounds, EntityRelationType, BruceEvent, EntityCoords, Api, EntitySource, MenuItem, EntityRelation, ENVIRONMENT, AbstractApi, ProjectViewBookmark, EntityAttachment, EntityAttachmentType, EntityAttribute, ProjectView, ProjectViewLegacyTile, ProgramKey, Camera } from 'bruce-models';
2
2
  import * as Cesium from 'cesium';
3
- import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, Entity, Primitive, Cesium3DTileFeature, SceneMode, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Model, Cesium3DTileColorBlendMode, HeadingPitchRange, Cesium3DTileStyle, createOsmBuildings, KmlDataSource, OrthographicFrustum, EasingFunction, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, CesiumInspector, defined, SceneTransforms, EllipsoidGeodesic, sampleTerrainMostDetailed, ColorMaterialProperty, BoundingSphere, GeometryInstance, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, Intersect } from 'cesium';
3
+ import { Cartographic, Cartesian2, Math as Math$1, Cartesian3, CallbackProperty, Color, HeightReference, Rectangle, JulianDate, SceneMode, Entity, Primitive, Cesium3DTileFeature, DistanceDisplayCondition, NearFarScalar, HorizontalOrigin, VerticalOrigin, ClassificationType, ArcType, CornerType, ShadowMode, PolygonHierarchy, PolylineGraphics, HeadingPitchRoll, Transforms, ColorBlendMode, Model, Cesium3DTileColorBlendMode, HeadingPitchRange, createOsmBuildings, Cesium3DTileStyle, KmlDataSource, SceneTransforms, OrthographicFrustum, EasingFunction, createWorldTerrain, EllipsoidTerrainProvider, CesiumTerrainProvider, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, UrlTemplateImageryProvider, TileMapServiceImageryProvider, IonImageryProvider, CesiumInspector, defined, Cesium3DTileset, Matrix4, Matrix3, IonResource, Ion, EllipsoidGeodesic, sampleTerrainMostDetailed, PolygonPipeline, ScreenSpaceEventHandler, ScreenSpaceEventType, ColorMaterialProperty, BoundingSphere, GeometryInstance, Intersect } from 'cesium';
4
4
 
5
5
  /*! *****************************************************************************
6
6
  Copyright (c) Microsoft Corporation. All rights reserved.
@@ -976,7 +976,7 @@ var EntityUtils;
976
976
  });
977
977
  }); };
978
978
  getEntityPositions = function (sample) { return __awaiter(_this, void 0, void 0, function () {
979
- var entityId, entity, tileset, tilesetId, e_1, evaluateRendered, evaluateRecord, renderedPosses, recordPosses, e_2, tSettings, pos3d, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset, sphere;
979
+ var entityId, entity, tileset, tilesetId, e_1, evaluateRendered, evaluateRecord, renderedPosses, recordPosses, e_2, tSettings, pos3d, alt, alt, heading, pitch, roll, matrix4, offset, m1, hpr, transform, transformedOffset;
980
980
  var _this = this;
981
981
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
982
982
  return __generator(this, function (_l) {
@@ -1102,7 +1102,7 @@ var EntityUtils;
1102
1102
  posses.push(pos3d_1);
1103
1103
  if (visual.model) {
1104
1104
  modelExt = visual.model;
1105
- if (modelExt._radius) {
1105
+ if (modelExt._radius && modelExt._radius > -1) {
1106
1106
  sphere = BoundingSphere.fromPoints([pos3d_1]);
1107
1107
  sphere.radius = modelExt._radius;
1108
1108
  spheres.push(sphere);
@@ -1229,7 +1229,7 @@ var EntityUtils;
1229
1229
  case 12:
1230
1230
  tSettings = tileset === null || tileset === void 0 ? void 0 : tileset.settings;
1231
1231
  pos3d = null;
1232
- if (!(((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude) || ((_c = tSettings === null || tSettings === void 0 ? void 0 : tSettings.location) === null || _c === void 0 ? void 0 : _c.longitude))) return [3 /*break*/, 15];
1232
+ if (!(((_b = entity === null || entity === void 0 ? void 0 : entity.location) === null || _b === void 0 ? void 0 : _b.longitude) || ((_c = tSettings === null || tSettings === void 0 ? void 0 : tSettings.location) === null || _c === void 0 ? void 0 : _c.longitude))) return [3 /*break*/, 14];
1233
1233
  if ((_d = entity === null || entity === void 0 ? void 0 : entity.location) === null || _d === void 0 ? void 0 : _d.longitude) {
1234
1234
  alt = +entity.location.altitude;
1235
1235
  if (isNaN(alt)) {
@@ -1244,7 +1244,7 @@ var EntityUtils;
1244
1244
  }
1245
1245
  pos3d = Cartesian3.fromDegrees(+tSettings.location.longitude, +tSettings.location.latitude, alt);
1246
1246
  }
1247
- if (!(entity === null || entity === void 0 ? void 0 : entity.worldPosition)) return [3 /*break*/, 15];
1247
+ if (!(entity === null || entity === void 0 ? void 0 : entity.worldPosition)) return [3 /*break*/, 14];
1248
1248
  heading = 0;
1249
1249
  pitch = 0;
1250
1250
  roll = 0;
@@ -1295,13 +1295,6 @@ var EntityUtils;
1295
1295
  pos3d = _l.sent();
1296
1296
  _l.label = 14;
1297
1297
  case 14:
1298
- if ((entity === null || entity === void 0 ? void 0 : entity.geometryRadius) && (pos3d === null || pos3d === void 0 ? void 0 : pos3d.x)) {
1299
- sphere = BoundingSphere.fromPoints([pos3d]);
1300
- sphere.radius = entity.geometryRadius;
1301
- spheres.push(sphere);
1302
- }
1303
- _l.label = 15;
1304
- case 15:
1305
1298
  if (pos3d) {
1306
1299
  return [2 /*return*/, [pos3d]];
1307
1300
  }
@@ -2108,7 +2101,19 @@ var TERRAIN_HEIGHT_TOLERANCE = 400;
2108
2101
  // Tolerance to use when number of entities is lower than x in the scene.
2109
2102
  var TERRAIN_HEIGHT_TOLERANCE_LOW_COUNT = 30;
2110
2103
  var TERRAIN_HEIGHT_TOLERANCE_LOW_ENTITY_THRESHOLD = 100;
2104
+ /**
2105
+ * Returns the terrain height for a given position.
2106
+ * This will not sample most-detailed and instead the current state of the terrain.
2107
+ * TODO: If something is VERY far from the camera, we should just return 0.
2108
+ * @param viewer
2109
+ * @param pos3d
2110
+ * @returns
2111
+ */
2111
2112
  var getTerrainOffset = function (viewer, pos3d) {
2113
+ var _a;
2114
+ if (!((_a = viewer.terrainProvider) === null || _a === void 0 ? void 0 : _a.ready)) {
2115
+ return null;
2116
+ }
2112
2117
  var terrain = ViewUtils.GatherTerrainTile({
2113
2118
  viewer: viewer
2114
2119
  }).terrain;
@@ -2120,8 +2125,8 @@ var getTerrainOffset = function (viewer, pos3d) {
2120
2125
  var keys = Array.from(_terrainCache.Entries());
2121
2126
  var tolerance = viewer.entities.values.length > TERRAIN_HEIGHT_TOLERANCE_LOW_ENTITY_THRESHOLD ? TERRAIN_HEIGHT_TOLERANCE : TERRAIN_HEIGHT_TOLERANCE_LOW_COUNT;
2122
2127
  for (var i = 0; i < keys.length; i++) {
2123
- var _a = keys[i], key_1 = _a[0], offset_1 = _a[1];
2124
- var _b = key_1.split("_"), terrainId2 = _b[0], x = _b[1], y = _b[2], z = _b[3];
2128
+ var _b = keys[i], key_1 = _b[0], offset_1 = _b[1];
2129
+ var _c = key_1.split("_"), terrainId2 = _c[0], x = _c[1], y = _c[2], z = _c[3];
2125
2130
  if (terrainId2 != terrainId) {
2126
2131
  continue;
2127
2132
  }
@@ -2177,12 +2182,6 @@ var adjustPos3d = function (viewer, heightRef, pos3d) {
2177
2182
  }
2178
2183
  return newPos3d;
2179
2184
  };
2180
- function getValue(viewer, obj) {
2181
- if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
2182
- return obj.getValue(viewer.scene.lastRenderTime);
2183
- }
2184
- return obj;
2185
- }
2186
2185
  function isFlatTerrain(viewer) {
2187
2186
  var _a;
2188
2187
  if (!viewer) {
@@ -2192,6 +2191,12 @@ function isFlatTerrain(viewer) {
2192
2191
  viewer: viewer
2193
2192
  }).terrain) === null || _a === void 0 ? void 0 : _a.tilesetId) == ProjectViewTile.EDefaultTerrain.FlatTerrain;
2194
2193
  }
2194
+ function getValue(viewer, obj) {
2195
+ if (obj === null || obj === void 0 ? void 0 : obj.getValue) {
2196
+ return obj.getValue(viewer.scene.lastRenderTime);
2197
+ }
2198
+ return obj;
2199
+ }
2195
2200
  var boundingSphereCache = new LRUCache(100000);
2196
2201
  function getPositionsFromEntity(viewer, entity) {
2197
2202
  var positions = [];
@@ -2202,7 +2207,6 @@ function getPositionsFromEntity(viewer, entity) {
2202
2207
  return null;
2203
2208
  }
2204
2209
  heightRef = getValue(viewer, entity.billboard.heightReference);
2205
- pos3d = adjustPos3d(viewer, heightRef, pos3d);
2206
2210
  positions.push(pos3d);
2207
2211
  }
2208
2212
  else if (entity.polyline) {
@@ -2220,8 +2224,7 @@ function getPositionsFromEntity(viewer, entity) {
2220
2224
  }
2221
2225
  heightRef = getValue(viewer, entity.polyline.clampToGround) == false ? HeightReference.NONE : HeightReference.CLAMP_TO_GROUND;
2222
2226
  for (var i = 0; i < posses.length; i++) {
2223
- var pos3d = adjustPos3d(viewer, heightRef, posses[i]);
2224
- positions.push(pos3d);
2227
+ positions.push(posses[i]);
2225
2228
  }
2226
2229
  }
2227
2230
  else if (entity.polygon) {
@@ -2240,8 +2243,7 @@ function getPositionsFromEntity(viewer, entity) {
2240
2243
  }
2241
2244
  heightRef = getValue(viewer, entity.polygon.heightReference);
2242
2245
  for (var i = 0; i < posses.length; i++) {
2243
- var pos3d = adjustPos3d(viewer, heightRef, posses[i]);
2244
- positions.push(pos3d);
2246
+ positions.push(posses[i]);
2245
2247
  }
2246
2248
  }
2247
2249
  else if (entity.corridor) {
@@ -2259,8 +2261,7 @@ function getPositionsFromEntity(viewer, entity) {
2259
2261
  }
2260
2262
  heightRef = getValue(viewer, entity.corridor.heightReference);
2261
2263
  for (var i = 0; i < posses.length; i++) {
2262
- var pos3d = adjustPos3d(viewer, heightRef, posses[i]);
2263
- positions.push(pos3d);
2264
+ positions.push(posses[i]);
2264
2265
  }
2265
2266
  }
2266
2267
  else if (entity.ellipse) {
@@ -2269,7 +2270,6 @@ function getPositionsFromEntity(viewer, entity) {
2269
2270
  return null;
2270
2271
  }
2271
2272
  heightRef = getValue(viewer, entity.ellipse.heightReference);
2272
- pos3d = adjustPos3d(viewer, heightRef, pos3d);
2273
2273
  positions.push(pos3d);
2274
2274
  }
2275
2275
  else if (entity.model) {
@@ -2278,7 +2278,6 @@ function getPositionsFromEntity(viewer, entity) {
2278
2278
  return null;
2279
2279
  }
2280
2280
  heightRef = getValue(viewer, entity.model.heightReference);
2281
- pos3d = adjustPos3d(viewer, heightRef, pos3d);
2282
2281
  positions.push(pos3d);
2283
2282
  }
2284
2283
  else if (entity.point) {
@@ -2287,7 +2286,6 @@ function getPositionsFromEntity(viewer, entity) {
2287
2286
  return null;
2288
2287
  }
2289
2288
  heightRef = getValue(viewer, entity.point.heightReference);
2290
- pos3d = adjustPos3d(viewer, heightRef, pos3d);
2291
2289
  positions.push(pos3d);
2292
2290
  }
2293
2291
  if (!(positions === null || positions === void 0 ? void 0 : positions.length)) {
@@ -2302,19 +2300,21 @@ function getPositionsFromEntity(viewer, entity) {
2302
2300
  positions[i] = Cartographic.toCartesian(carto);
2303
2301
  }
2304
2302
  }
2305
- return positions;
2303
+ return {
2304
+ positions: positions,
2305
+ heightRef: heightRef
2306
+ };
2306
2307
  }
2307
2308
  function computeBoundingSphereFromPositions(positions) {
2308
2309
  return BoundingSphere.fromPoints(positions);
2309
2310
  }
2310
2311
  function shouldCullEntity(viewer, cEntity) {
2311
- var _a, _b;
2312
+ var _a, _b, _c;
2312
2313
  var camera = viewer.scene.camera;
2313
2314
  var boundingSphere;
2314
2315
  var terrainId = (_b = (_a = ViewUtils.GatherTerrainTile({
2315
2316
  viewer: viewer
2316
2317
  }).terrain) === null || _a === void 0 ? void 0 : _a.tilesetId) !== null && _b !== void 0 ? _b : ProjectViewTile.EDefaultTerrain.FlatTerrain;
2317
- var cullSphere;
2318
2318
  var cacheKey = terrainId + cEntity.id;
2319
2319
  var cacheData = boundingSphereCache.Get(cacheKey);
2320
2320
  if (cacheData) {
@@ -2322,17 +2322,20 @@ function shouldCullEntity(viewer, cEntity) {
2322
2322
  }
2323
2323
  else {
2324
2324
  var positions = getPositionsFromEntity(viewer, cEntity);
2325
- if (positions) {
2326
- boundingSphere = computeBoundingSphereFromPositions(positions);
2325
+ if ((_c = positions === null || positions === void 0 ? void 0 : positions.positions) === null || _c === void 0 ? void 0 : _c.length) {
2326
+ // Sphere calculated from entity positions.
2327
+ // We will evaluate the visual now to see if the sphere should be counted, for example 3D models might not be loaded yet.
2328
+ var sphere = computeBoundingSphereFromPositions(positions.positions);
2329
+ // If a 3D model is not loaded, we'll avoid caching the sphere data.
2327
2330
  var doNotCache = false;
2328
2331
  if (cEntity.model) {
2329
2332
  var model = cEntity.model;
2330
2333
  if (model._radius && !isNaN(model._radius)) {
2331
- boundingSphere.radius = Math.max(model._radius, MODEL_MIN_RADIUS);
2334
+ sphere.radius = Math.max(model._radius, MODEL_MIN_RADIUS);
2332
2335
  }
2333
2336
  else {
2334
2337
  // Unknown size. Ignoring.
2335
- boundingSphere = -1;
2338
+ sphere = null;
2336
2339
  doNotCache = !model._radiusLoaded;
2337
2340
  }
2338
2341
  }
@@ -2349,24 +2352,28 @@ function shouldCullEntity(viewer, cEntity) {
2349
2352
  }
2350
2353
  }
2351
2354
  if (radius && !isNaN(radius)) {
2352
- boundingSphere.radius = radius;
2355
+ sphere.radius = radius;
2353
2356
  }
2354
2357
  }
2355
2358
  // Check for extrusion.
2356
2359
  else if (cEntity.polygon) {
2357
2360
  var extrusion = getValue(viewer, cEntity.polygon.extrudedHeight);
2358
2361
  if (extrusion && !isNaN(extrusion)) {
2359
- if (!boundingSphere.radius) {
2360
- boundingSphere.radius = extrusion;
2362
+ if (!sphere.radius) {
2363
+ sphere.radius = extrusion;
2361
2364
  }
2362
- else if (extrusion > boundingSphere.radius / 2) {
2363
- boundingSphere.radius = extrusion;
2365
+ else if (extrusion > sphere.radius / 2) {
2366
+ sphere.radius = extrusion;
2364
2367
  }
2365
2368
  }
2366
2369
  }
2367
2370
  else if (cEntity.point || cEntity.billboard) {
2368
- boundingSphere.radius = Math.max(boundingSphere.radius, POINT_MIN_RADIUS);
2371
+ sphere.radius = Math.max(sphere.radius, POINT_MIN_RADIUS);
2369
2372
  }
2373
+ boundingSphere = {
2374
+ heightRef: positions.heightRef,
2375
+ sphere: sphere
2376
+ };
2370
2377
  if (!doNotCache) {
2371
2378
  boundingSphereCache.Set(cacheKey, boundingSphere);
2372
2379
  }
@@ -2375,18 +2382,13 @@ function shouldCullEntity(viewer, cEntity) {
2375
2382
  boundingSphereCache.Set(cacheKey, -1);
2376
2383
  }
2377
2384
  }
2378
- if (!boundingSphere || boundingSphere == -1) {
2385
+ if (!boundingSphere || boundingSphere == -1 || !boundingSphere.sphere) {
2379
2386
  return false;
2380
2387
  }
2388
+ var adjustedSphere = boundingSphere.sphere.clone();
2389
+ adjustedSphere.center = adjustPos3d(viewer, boundingSphere.heightRef, adjustedSphere.center);
2381
2390
  var cullingVolume = camera.frustum.computeCullingVolume(camera.position, camera.direction, camera.up);
2382
- var visibility = cullingVolume.computeVisibility(boundingSphere);
2383
- if (cullSphere) {
2384
- cullSphere.ellipsoid.material =
2385
- (visibility == Intersect.INSIDE ||
2386
- visibility == Intersect.INTERSECTING) ? Color.GREEN.withAlpha(0.1) :
2387
- Color.RED.withAlpha(0.1);
2388
- viewer.scene.requestRender();
2389
- }
2391
+ var visibility = cullingVolume.computeVisibility(adjustedSphere);
2390
2392
  return visibility !== Intersect.INSIDE && visibility !== Intersect.INTERSECTING;
2391
2393
  }
2392
2394
  // Amount of entities to check per interval.
@@ -2452,6 +2454,8 @@ function runCullChecker(register) {
2452
2454
  }
2453
2455
  var viewer = register.Viewer;
2454
2456
  var entityIds = register.GetEntityIds();
2457
+ // We'll use the terrain cache per culler cycle.
2458
+ _terrainCache.Clear();
2455
2459
  checkInterval = setInterval(function () {
2456
2460
  if (viewer.isDestroyed() || !viewer.scene) {
2457
2461
  clearInterval(checkInterval);
@@ -2536,6 +2540,15 @@ var VisualRegisterCuller;
2536
2540
  (_a = checkQueue.Call) === null || _a === void 0 ? void 0 : _a.call(checkQueue);
2537
2541
  }
2538
2542
  });
2543
+ var terrChangeTimeout = null;
2544
+ var terrChangeRemoval = register.Viewer.scene.terrainProviderChanged.addEventListener(function () {
2545
+ clearTimeout(terrChangeTimeout);
2546
+ terrChangeTimeout = setTimeout(function () {
2547
+ var _a;
2548
+ MarkShouldRecheck(register.Viewer);
2549
+ (_a = checkQueue.Call) === null || _a === void 0 ? void 0 : _a.call(checkQueue);
2550
+ }, 2500);
2551
+ });
2539
2552
  checkQueue.Call();
2540
2553
  return function (params) {
2541
2554
  var uncull = (params || {}).uncull;
@@ -2545,6 +2558,10 @@ var VisualRegisterCuller;
2545
2558
  moveEndRemoval = null;
2546
2559
  updateRemoval === null || updateRemoval === void 0 ? void 0 : updateRemoval();
2547
2560
  updateRemoval = null;
2561
+ terrChangeRemoval === null || terrChangeRemoval === void 0 ? void 0 : terrChangeRemoval();
2562
+ terrChangeRemoval = null;
2563
+ clearTimeout(terrChangeTimeout);
2564
+ terrChangeTimeout = null;
2548
2565
  checkInterval === null || checkInterval === void 0 ? void 0 : checkInterval();
2549
2566
  checkInterval = null;
2550
2567
  checkWaiting = false;
@@ -18735,7 +18752,7 @@ var CesiumViewMonitor;
18735
18752
  CesiumViewMonitor$$1.Monitor = Monitor;
18736
18753
  })(CesiumViewMonitor || (CesiumViewMonitor = {}));
18737
18754
 
18738
- var VERSION$1 = "3.1.4";
18755
+ var VERSION$1 = "3.1.6";
18739
18756
 
18740
18757
  export { VERSION$1 as VERSION, CesiumViewMonitor, ViewerUtils, MenuItemManager, EntityRenderEngine, MenuItemCreator, VisualsRegister, RenderManager, EntitiesIdsRenderManager, EntitiesLoadedRenderManager, EntitiesRenderManager, EntityRenderManager, TilesetCadRenderManager, TilesetArbRenderManager, TilesetEntitiesRenderManager, TilesetOsmRenderManager, TilesetPointcloudRenderManager, TilesetGooglePhotosRenderManager, DataSourceStaticKmlManager, RelationsRenderManager, SharedGetters, CesiumParabola, EntityLabel, ViewRenderEngine, TileRenderEngine, TilesetRenderEngine, CESIUM_INSPECTOR_KEY, ViewUtils, DrawingUtils, MeasureUtils, EntityUtils, Draw3dPolygon, Draw3dPolyline };
18741
18758
  //# sourceMappingURL=bruce-cesium.es5.js.map