bruce-cesium 7.7.8 → 7.7.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.
@@ -1,6 +1,6 @@
1
1
  import * as Cesium from 'cesium';
2
- import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, HeightReference, ColorBlendMode, HeadingPitchRoll, Model, ClassificationType, ConstantPositionProperty, DistanceDisplayCondition, ArcType, CornerType, JulianDate, Quaternion, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, HorizontalOrigin, VerticalOrigin, SceneMode, IntersectionTests, Ray, SceneTransforms, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, FeatureDetection, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, OrthographicFrustum, EasingFunction, WebGLConstants, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, CesiumInspector, ClockRange, ShadowMode, DynamicEnvironmentMapManager, GeometryInstance, PrimitiveCollection, PolylineCollection, LabelCollection, LabelStyle, Material, Event, CustomDataSource, CameraEventType, Plane, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
- import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, EntityLod, UrlUtils, Geometry as Geometry$1, Bounds, ClientFileValueMap, Color as Color$1, Assembly, EntityCoords, ZoomControl, ProjectView, ProjectViewBookmark, Api, EntityRelation, BruceApi, ProgramKey, ProjectViewLegacyTile, Camera, EntitySource, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
2
+ import { Cartographic, ColorMaterialProperty, Entity, Color, ConstantProperty, CallbackProperty, Primitive, Cesium3DTileFeature, ConstantPositionProperty, HeightReference, DistanceDisplayCondition, ShaderSource, Cartesian3, Math as Math$1, Ellipsoid, Transforms, Matrix4, Geometry, GeometryAttribute, ComponentDatatype, PrimitiveType, BoundingSphere, GeometryPipeline, Cartesian2, Cartesian4, sampleTerrain, Texture, PixelFormat, Sampler, TextureWrap, TextureMinificationFilter, TextureMagnificationFilter, PixelDatatype, VertexArray, BufferUsage, ShaderProgram, RenderState, BlendingState, DrawCommand, Pass, JulianDate, Quaternion, HeadingPitchRoll, ColorBlendMode, Model, ClassificationType, HorizontalOrigin, VerticalOrigin, ArcType, CornerType, SceneMode, IntersectionTests, Ray, SceneTransforms, ImageMaterialProperty, PolygonHierarchy, PolylineGraphics, Rectangle, NearFarScalar, Matrix3, KmlDataSource, GeoJsonDataSource, FeatureDetection, Cesium3DTileStyle, HeadingPitchRange, Ion, IonResource, Cesium3DTileColorBlendMode, OrthographicFrustum, EasingFunction, Cesium3DTileset, EllipsoidTerrainProvider, IonImageryProvider, createWorldImagery, createWorldImageryAsync, BingMapsImageryProvider, BingMapsStyle, MapboxImageryProvider, MapboxStyleImageryProvider, ArcGisMapServerImageryProvider, OpenStreetMapImageryProvider, UrlTemplateImageryProvider, GridImageryProvider, GeographicTilingScheme, ImageryLayer, TileMapServiceImageryProvider, CesiumTerrainProvider, Intersect, WebGLConstants, EllipsoidGeodesic, sampleTerrainMostDetailed, defined, PolygonPipeline, ModelGraphics, PolygonGraphics, CorridorGraphics, PointGraphics, BillboardGraphics, EllipseGraphics, PolylineDashMaterialProperty, ShadowMode, CustomDataSource, CesiumInspector, ClockRange, DynamicEnvironmentMapManager, PrimitiveCollection, PolylineCollection, LabelCollection, LabelStyle, Material, GeometryInstance, Event, CameraEventType, Plane, OrientedBoundingBox, ScreenSpaceEventHandler, ScreenSpaceEventType, Fullscreen, CzmlDataSource } from 'cesium';
3
+ import { Cartes, LRUCache, Carto, ProjectViewTile, EntityHistoricData, BruceEvent, DelayQueue, Entity as Entity$1, EntityTag, PathUtils, ClientFile, ENVIRONMENT, EntityAttachmentType, EntityRelationType, EntityType, Tileset, Calculator, DataLab, Style, ObjectUtils, MenuItem, AccountConcept, RecordChangeFeed, EntityLod, UrlUtils, Api, Geometry as Geometry$1, Bounds, ClientFileValueMap, Color as Color$1, Assembly, EntityCoords, ZoomControl, ProjectView, ProjectViewBookmark, EntityRelation, BruceApi, EntitySource, Camera, ProgramKey, ProjectViewLegacyTile, Account, AccountLimits, Session, EntityAttachment, EntityAttribute, MathUtils, ProjectViewBookmarkGroup } from 'bruce-models';
4
4
 
5
5
  /**
6
6
  * Ensures a number is returned from a given value.
@@ -926,6 +926,32 @@ const ZOOM_EASE = 0.35;
926
926
  const GRAZING_SINE = 0.12;
927
927
  // Closest the view may get to straight up or down while orbiting, in radians, so the camera never flips over.
928
928
  const ORBIT_POLE_MARGIN = Math$1.toRadians(1);
929
+ // How far above the ground a camera coming down from above stops, until pushed on through.
930
+ const GROUND_STANDOFF = 2;
931
+ // Height above the ground within which a descent slows, so the ground is approached rather than hit.
932
+ const GROUND_APPROACH = 10;
933
+ // The slowest a descent gets near the ground, as a share of its usual speed.
934
+ const GROUND_APPROACH_FLOOR = 0.5;
935
+ // How far below the ground a push through it lands, so the camera is clearly under it.
936
+ const GROUND_BREAK_DEPTH = 1.5;
937
+ // Wheel notches of pushing at the ground that take the camera through it, with and without data found below it.
938
+ const PUSH_NOTCHES_DATA_BELOW = 3;
939
+ const PUSH_NOTCHES_NOTHING_BELOW = 10;
940
+ // Pushes further apart than this start counting again.
941
+ const PUSH_WINDOW_MS = 1200;
942
+ // How far below the ground something must reach to count as data underground, in metres.
943
+ const UNDERGROUND_MARGIN = 3;
944
+ // How long a scan of the scene for underground data and stand-in ground is trusted, in milliseconds.
945
+ const SCENE_SCAN_MS = 2000;
946
+ // The most entities one scan looks at, so a large scene is sampled rather than walked each time.
947
+ const SCENE_SCAN_ENTITIES = 3000;
948
+ // Zoom speed, as a share of the usual, toward a point that is a guess (nothing drawn there) or while terrain loads.
949
+ const ZOOM_GUESS_SHARE = 0.5;
950
+ const ZOOM_LOADING_SHARE = 0.7;
951
+ // The highest a camera zooms out to with the globe hidden, which CesiumJS's controller cannot navigate.
952
+ const HIDDEN_GLOBE_MAX_HEIGHT = 10000000;
953
+ // Marks a tileset that stands in for the globe, such as Google's photorealistic tiles.
954
+ const GROUND_TILESET_KEY = "_nextspace_camera_ground";
929
955
  var EDrag;
930
956
  (function (EDrag) {
931
957
  EDrag["Pan"] = "pan";
@@ -959,6 +985,9 @@ var CameraControls;
959
985
  zoomFrame: null,
960
986
  zoomPosition: null,
961
987
  lastDistance: 100,
988
+ push: { notches: 0, at: 0 },
989
+ scan: null,
990
+ undergroundOverride: null,
962
991
  saved: {
963
992
  rotateEventTypes: controller.rotateEventTypes,
964
993
  zoomEventTypes: controller.zoomEventTypes,
@@ -1015,6 +1044,25 @@ var CameraControls;
1015
1044
  return Boolean(viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY]);
1016
1045
  }
1017
1046
  CameraControls.IsAttached = IsAttached;
1047
+ /**
1048
+ * Marks a tileset as standing in for the globe (Google's photorealistic tiles), so the camera treats it as ground.
1049
+ */
1050
+ function SetGroundTileset(tileset, isGround) {
1051
+ if (tileset) {
1052
+ tileset[GROUND_TILESET_KEY] = isGround;
1053
+ }
1054
+ }
1055
+ CameraControls.SetGroundTileset = SetGroundTileset;
1056
+ /**
1057
+ * Says whether the scene has data underground, which makes the ground easier to push through; null scans for it.
1058
+ */
1059
+ function SetUndergroundData(viewer, present) {
1060
+ const state = viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY];
1061
+ if (state) {
1062
+ state.undergroundOverride = present;
1063
+ }
1064
+ }
1065
+ CameraControls.SetUndergroundData = SetUndergroundData;
1018
1066
  /**
1019
1067
  * Switches to navigating model-space measured from the frame getFrame returns, or back to geospatial with null.
1020
1068
  */
@@ -1095,8 +1143,27 @@ function shouldControl(state) {
1095
1143
  if (state.getModelSpaceFrame) {
1096
1144
  return true;
1097
1145
  }
1146
+ // CesiumJS's controller measures against the globe, so with it hidden these controls keep the camera at any height.
1147
+ if (!globeShown(state)) {
1148
+ return true;
1149
+ }
1098
1150
  return heightOf(state, camera.positionWC) < GEO_HANDOFF_HEIGHT;
1099
1151
  }
1152
+ function globeShown(state) {
1153
+ const globe = state.viewer.scene.globe;
1154
+ return Boolean(globe) && globe.show !== false;
1155
+ }
1156
+ /*
1157
+ * The terrain's height at a place from the tiles loaded, undefined with the globe hidden or nothing loaded there.
1158
+ */
1159
+ function terrainHeightAt(state, carto) {
1160
+ const globe = state.viewer.scene.globe;
1161
+ if (!carto || !globeShown(state) || typeof globe.getHeight !== "function") {
1162
+ return undefined;
1163
+ }
1164
+ const height = globe.getHeight(carto);
1165
+ return Number.isFinite(height) ? height : undefined;
1166
+ }
1100
1167
  function ellipsoidOf(state) {
1101
1168
  var _a, _b;
1102
1169
  return (_b = (_a = state.viewer.scene.globe) === null || _a === void 0 ? void 0 : _a.ellipsoid) !== null && _b !== void 0 ? _b : Ellipsoid.WGS84;
@@ -1123,16 +1190,19 @@ function upAt(state, position) {
1123
1190
  * The level plane standing in for the ground when nothing is drawn under the cursor.
1124
1191
  */
1125
1192
  function groundPlane(state) {
1193
+ var _a;
1126
1194
  if (state.getModelSpaceFrame) {
1127
1195
  const frame = state.getModelSpaceFrame();
1128
1196
  return Plane.fromPointNormal(Matrix4.getTranslation(frame, new Cartesian3()), upAt(state, null));
1129
1197
  }
1130
1198
  const camera = state.viewer.camera;
1131
1199
  const ellipsoid = ellipsoidOf(state);
1132
- const surface = ellipsoid.scaleToGeodeticSurface(camera.positionWC, new Cartesian3());
1133
- if (!surface) {
1200
+ const carto = ellipsoid.cartesianToCartographic(camera.positionWC);
1201
+ if (!carto) {
1134
1202
  return null;
1135
1203
  }
1204
+ // Level with the terrain under the camera, not sea level, so a guess over high ground is not far too deep.
1205
+ const surface = Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
1136
1206
  return Plane.fromPointNormal(surface, ellipsoid.geodeticSurfaceNormal(surface, new Cartesian3()));
1137
1207
  }
1138
1208
  /*
@@ -1170,14 +1240,44 @@ function pickTarget(state, position) {
1170
1240
  }
1171
1241
  const plausible = plausibleDistance(state);
1172
1242
  if (isAhead(camera, picked) && Cartesian3.distance(picked, camera.positionWC) < plausible) {
1173
- return picked;
1243
+ return { point: picked, source: "pick", ground: isGroundPick(state, position) };
1174
1244
  }
1175
1245
  const ground = groundPlane(state);
1176
1246
  const onGround = ground ? IntersectionTests.rayPlane(ray, ground) : null;
1177
1247
  if (isAhead(camera, onGround) && Cartesian3.distance(onGround, camera.positionWC) < plausible) {
1178
- return onGround;
1248
+ // The plane stands in for the ground only where there is ground to stand in for.
1249
+ return { point: onGround, source: "plane", ground: !state.getModelSpaceFrame && hasGround(state) };
1250
+ }
1251
+ return { point: Ray.getPoint(ray, state.lastDistance), source: "last", ground: false };
1252
+ }
1253
+ /*
1254
+ * Whether what is drawn under a screen position is the ground: the globe, or a tileset standing in for it.
1255
+ */
1256
+ function isGroundPick(state, position) {
1257
+ var _a, _b, _c;
1258
+ if (state.getModelSpaceFrame) {
1259
+ return false;
1260
+ }
1261
+ const scene = state.viewer.scene;
1262
+ let picked;
1263
+ try {
1264
+ picked = typeof scene.pick === "function" ? scene.pick(position) : undefined;
1265
+ }
1266
+ catch (e) {
1267
+ picked = undefined;
1179
1268
  }
1180
- return Ray.getPoint(ray, state.lastDistance);
1269
+ if (!picked) {
1270
+ // Nothing pickable means the globe, when it is drawn.
1271
+ return globeShown(state);
1272
+ }
1273
+ const tileset = (_b = (_a = picked.tileset) !== null && _a !== void 0 ? _a : picked.primitive) !== null && _b !== void 0 ? _b : (_c = picked.content) === null || _c === void 0 ? void 0 : _c.tileset;
1274
+ return Boolean(tileset === null || tileset === void 0 ? void 0 : tileset[GROUND_TILESET_KEY]);
1275
+ }
1276
+ /*
1277
+ * Whether there is ground to come down onto: the globe drawn, or a tileset standing in for it.
1278
+ */
1279
+ function hasGround(state) {
1280
+ return globeShown(state) || scanScene(state).groundTileset;
1181
1281
  }
1182
1282
  function isAhead(camera, point) {
1183
1283
  if (!point || !Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) {
@@ -1238,14 +1338,15 @@ function onPointerDown(state, e) {
1238
1338
  return;
1239
1339
  }
1240
1340
  const position = canvasPosition(viewer, e);
1241
- const target = pickTarget(state, position);
1242
- if (!target) {
1341
+ const picked = pickTarget(state, position);
1342
+ if (!picked) {
1243
1343
  return;
1244
1344
  }
1345
+ const target = picked.point;
1245
1346
  const camera = viewer.camera;
1246
1347
  const distance = Cartesian3.distance(camera.positionWC, target);
1247
1348
  state.lastDistance = Math.max(distance, MIN_ZOOM_DISTANCE);
1248
- const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance };
1349
+ const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance, picked };
1249
1350
  if (kind === EDrag.Pan) {
1250
1351
  drag.plane = panPlane(camera, target, drag.up);
1251
1352
  }
@@ -1288,7 +1389,7 @@ function onPointerMove(state, e) {
1288
1389
  break;
1289
1390
  case EDrag.Zoom:
1290
1391
  // Dragging down zooms in, as it does in CesiumJS.
1291
- moveAlong(state, drag.direction, drag.target, dy / DRAG_PIXELS_PER_NOTCH);
1392
+ moveAlong(state, drag.direction, drag.picked, dy / DRAG_PIXELS_PER_NOTCH);
1292
1393
  break;
1293
1394
  }
1294
1395
  drag.last = position;
@@ -1321,6 +1422,14 @@ function pan(state, drag, position) {
1321
1422
  if (length > limit) {
1322
1423
  Cartesian3.multiplyByScalar(delta, limit / length, delta);
1323
1424
  }
1425
+ // A pan never takes a camera above the ground down through it; it keeps the sideways part of the move.
1426
+ if (wouldSinkBelowGround(state, camera.position, delta)) {
1427
+ const up = upAt(state, camera.position);
1428
+ const down = Cartesian3.dot(delta, up);
1429
+ if (down < 0) {
1430
+ Cartesian3.subtract(delta, Cartesian3.multiplyByScalar(up, down, new Cartesian3()), delta);
1431
+ }
1432
+ }
1324
1433
  Cartesian3.add(camera.position, delta, camera.position);
1325
1434
  }
1326
1435
  /*
@@ -1342,7 +1451,13 @@ function orbit(state, drag, dx, dy) {
1342
1451
  const right = Cartesian3.cross(camera.direction, up, new Cartesian3());
1343
1452
  if (Cartesian3.magnitude(right) > Math$1.EPSILON6) {
1344
1453
  Cartesian3.normalize(right, right);
1454
+ const before = Cartesian3.clone(camera.position);
1345
1455
  rotateAbout(camera, drag.target, right, pitch);
1456
+ // Orbiting does not swing a camera above the ground down through it; the tilt that would is undone.
1457
+ const moved = Cartesian3.subtract(camera.position, before, new Cartesian3());
1458
+ if (wouldSinkBelowGround(state, before, moved)) {
1459
+ rotateAbout(camera, drag.target, right, -pitch);
1460
+ }
1346
1461
  }
1347
1462
  levelCamera(camera, upAt(state, camera.position));
1348
1463
  }
@@ -1429,22 +1544,262 @@ function moveAlong(state, direction, target, notches) {
1429
1544
  /*
1430
1545
  * The move for some notches toward a target along a direction, a share of the distance with a floor so it never stalls.
1431
1546
  */
1432
- function zoomStep(state, direction, target, notches) {
1547
+ function zoomStep(state, direction, picked, notches) {
1433
1548
  const camera = state.viewer.camera;
1434
- const distance = Math.max(Cartesian3.distance(camera.positionWC, target), MIN_ZOOM_DISTANCE);
1549
+ const target = picked.point;
1550
+ // Where the camera will be once the glide already under way ends, which this step continues from.
1551
+ const from = Cartesian3.add(camera.positionWC, state.pendingZoom, new Cartesian3());
1552
+ const distance = Math.max(Cartesian3.distance(from, target), MIN_ZOOM_DISTANCE);
1435
1553
  state.lastDistance = distance;
1436
- let length = distance * ZOOM_SHARE * notches;
1554
+ let length = distance * ZOOM_SHARE * notches * zoomSpeedShare(state, picked);
1437
1555
  // A geospatial camera zooming out hands over to CesiumJS once it is high enough, so only model-space is capped.
1438
1556
  if (length < 0 && state.getModelSpaceFrame) {
1439
1557
  const origin = Matrix4.getTranslation(state.getModelSpaceFrame(), new Cartesian3());
1440
- const pending = Cartesian3.add(camera.positionWC, state.pendingZoom, new Cartesian3());
1441
- const range = Cartesian3.distance(pending, origin);
1558
+ const range = Cartesian3.distance(from, origin);
1442
1559
  length = Math.max(length, range - MODEL_SPACE_MAX_RANGE);
1443
1560
  if (length >= 0) {
1444
1561
  return new Cartesian3();
1445
1562
  }
1446
1563
  }
1447
- return Cartesian3.multiplyByScalar(Cartesian3.normalize(direction, new Cartesian3()), length, new Cartesian3());
1564
+ const unit = Cartesian3.normalize(direction, new Cartesian3());
1565
+ // With the globe hidden there is no hand-over, so zooming out stops where the Earth is a dot.
1566
+ if (length < 0 && !state.getModelSpaceFrame && !globeShown(state)) {
1567
+ const rise = -Cartesian3.dot(unit, upAt(state, from));
1568
+ const headroom = HIDDEN_GLOBE_MAX_HEIGHT - heightOf(state, from);
1569
+ if (rise > 0) {
1570
+ length = Math.max(length, -Math.max(headroom, 0) / rise);
1571
+ }
1572
+ if (length >= 0) {
1573
+ return new Cartesian3();
1574
+ }
1575
+ }
1576
+ const step = Cartesian3.multiplyByScalar(unit, length, new Cartesian3());
1577
+ return length > 0 ? resistDescent(state, from, step, picked, notches) : step;
1578
+ }
1579
+ /*
1580
+ * How fast to zoom toward a target: slower toward a guess, or while the terrain that would give a real one loads.
1581
+ */
1582
+ function zoomSpeedShare(state, picked) {
1583
+ let share = 1;
1584
+ if (picked.source !== "pick") {
1585
+ share *= ZOOM_GUESS_SHARE;
1586
+ }
1587
+ const globe = state.viewer.scene.globe;
1588
+ if (!state.getModelSpaceFrame && globeShown(state) && globe.tilesLoaded === false) {
1589
+ share *= ZOOM_LOADING_SHARE;
1590
+ }
1591
+ return share;
1592
+ }
1593
+ /*
1594
+ * The ground a move comes down onto: the ground picked, else the terrain under where the move ends; null for none.
1595
+ */
1596
+ function groundUnderMove(state, from, step, picked) {
1597
+ var _a, _b;
1598
+ if (state.getModelSpaceFrame || !hasGround(state)) {
1599
+ return null;
1600
+ }
1601
+ if (picked === null || picked === void 0 ? void 0 : picked.ground) {
1602
+ return { point: picked.point, up: upAt(state, picked.point) };
1603
+ }
1604
+ if (!globeShown(state)) {
1605
+ return null;
1606
+ }
1607
+ const ellipsoid = ellipsoidOf(state);
1608
+ const end = Cartesian3.add(from, step, new Cartesian3());
1609
+ const carto = ellipsoid.cartesianToCartographic(end);
1610
+ if (!carto) {
1611
+ return null;
1612
+ }
1613
+ const height = (_b = (_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : terrainHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : 0;
1614
+ const point = Cartesian3.fromRadians(carto.longitude, carto.latitude, height, ellipsoid);
1615
+ return { point, up: ellipsoid.geodeticSurfaceNormal(point, new Cartesian3()) };
1616
+ }
1617
+ /*
1618
+ * Whether a move takes a camera that is above the ground to within the stand-off of it or below.
1619
+ */
1620
+ function wouldSinkBelowGround(state, from, step) {
1621
+ const ground = groundUnderMove(state, from, step, null);
1622
+ if (!ground) {
1623
+ return false;
1624
+ }
1625
+ const before = Cartesian3.dot(Cartesian3.subtract(from, ground.point, new Cartesian3()), ground.up);
1626
+ const after = before + Cartesian3.dot(step, ground.up);
1627
+ return before > 0 && after < Math.min(GROUND_STANDOFF, before);
1628
+ }
1629
+ /*
1630
+ * Slows a camera coming down from above as it nears the ground and stops it just above, until pushed on enough to
1631
+ * pass through; harder when nothing is known to be underground. A camera already below the ground moves freely.
1632
+ */
1633
+ function resistDescent(state, from, step, picked, notches) {
1634
+ const ground = groundUnderMove(state, from, step, picked);
1635
+ const length = Cartesian3.magnitude(step);
1636
+ if (!ground || length === 0) {
1637
+ return step;
1638
+ }
1639
+ const above = Cartesian3.dot(Cartesian3.subtract(from, ground.point, new Cartesian3()), ground.up);
1640
+ const unit = Cartesian3.divideByScalar(step, length, new Cartesian3());
1641
+ const sink = -Cartesian3.dot(unit, ground.up);
1642
+ if (above <= 0 || sink <= 0) {
1643
+ return step;
1644
+ }
1645
+ let allowed = length;
1646
+ if (above < GROUND_APPROACH) {
1647
+ allowed *= Math.max(above / GROUND_APPROACH, GROUND_APPROACH_FLOOR);
1648
+ }
1649
+ const toStandOff = Math.max(above - GROUND_STANDOFF, 0) / sink;
1650
+ if (allowed <= toStandOff) {
1651
+ return Cartesian3.multiplyByScalar(unit, allowed, new Cartesian3());
1652
+ }
1653
+ // Held at the stand-off: each push counts, and enough close together go through.
1654
+ const now = Date.now();
1655
+ if (now - state.push.at > PUSH_WINDOW_MS) {
1656
+ state.push.notches = 0;
1657
+ }
1658
+ state.push.at = now;
1659
+ state.push.notches += Math.abs(notches);
1660
+ const needed = scanScene(state).undergroundData ? PUSH_NOTCHES_DATA_BELOW : PUSH_NOTCHES_NOTHING_BELOW;
1661
+ if (state.push.notches >= needed) {
1662
+ state.push.notches = 0;
1663
+ // A shallow push would land far along the ground to get under it, so it goes no further than a usual step.
1664
+ const through = Math.min((above + GROUND_BREAK_DEPTH) / sink, Math.max(length, (above + GROUND_BREAK_DEPTH) * 4));
1665
+ return Cartesian3.multiplyByScalar(unit, through, new Cartesian3());
1666
+ }
1667
+ return Cartesian3.multiplyByScalar(unit, toStandOff, new Cartesian3());
1668
+ }
1669
+ /*
1670
+ * What the scene holds that the camera cares about, rescanned at most every couple of seconds.
1671
+ */
1672
+ function scanScene(state) {
1673
+ var _a, _b;
1674
+ const now = Date.now();
1675
+ if (state.scan && now - state.scan.at < SCENE_SCAN_MS) {
1676
+ return applyOverride(state, state.scan);
1677
+ }
1678
+ const scene = state.viewer.scene;
1679
+ const found = { at: now, undergroundData: false, groundTileset: false };
1680
+ // Seeing through the ground is turned on to look at what is under it.
1681
+ if ((_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.enabled) {
1682
+ found.undergroundData = true;
1683
+ }
1684
+ const visit = (primitive) => {
1685
+ if (!primitive || primitive.show === false || (primitive.isDestroyed && primitive.isDestroyed())) {
1686
+ return;
1687
+ }
1688
+ if (typeof primitive.length === "number" && typeof primitive.get === "function") {
1689
+ for (let i = 0; i < primitive.length; i++) {
1690
+ visit(primitive.get(i));
1691
+ }
1692
+ return;
1693
+ }
1694
+ if (primitive[GROUND_TILESET_KEY]) {
1695
+ found.groundTileset = true;
1696
+ return;
1697
+ }
1698
+ if (!found.undergroundData && reachesBelowGround(state, lowestPointOf(primitive))) {
1699
+ found.undergroundData = true;
1700
+ }
1701
+ };
1702
+ visit(scene.primitives);
1703
+ if (!found.undergroundData) {
1704
+ found.undergroundData = entitiesBelowGround(state);
1705
+ }
1706
+ state.scan = found;
1707
+ return applyOverride(state, found);
1708
+ }
1709
+ function applyOverride(state, found) {
1710
+ return state.undergroundOverride == null ? found : { ...found, undergroundData: state.undergroundOverride };
1711
+ }
1712
+ /*
1713
+ * The lowest point of a tileset or model: its root box's lowest corner, or its bounding sphere's centre.
1714
+ */
1715
+ function lowestPointOf(primitive) {
1716
+ var _a, _b, _c;
1717
+ const volume = (_a = primitive === null || primitive === void 0 ? void 0 : primitive.root) === null || _a === void 0 ? void 0 : _a.boundingVolume;
1718
+ if (volume) {
1719
+ const region = Number.isFinite(volume.minimumHeight) && volume.rectangle;
1720
+ if (region) {
1721
+ return Cartesian3.fromRadians(Rectangle.center(volume.rectangle).longitude, Rectangle.center(volume.rectangle).latitude, volume.minimumHeight);
1722
+ }
1723
+ const box = volume.boundingVolume;
1724
+ const corners = box instanceof OrientedBoundingBox && typeof OrientedBoundingBox.computeCorners === "function" ? OrientedBoundingBox.computeCorners(box) : null;
1725
+ if (corners === null || corners === void 0 ? void 0 : corners.length) {
1726
+ return lowestOf(corners);
1727
+ }
1728
+ }
1729
+ // A sphere's centre, as its radius reaches below the ground for anything standing on it.
1730
+ return (_c = (_b = primitive === null || primitive === void 0 ? void 0 : primitive.boundingSphere) === null || _b === void 0 ? void 0 : _b.center) !== null && _c !== void 0 ? _c : null;
1731
+ }
1732
+ function lowestOf(points) {
1733
+ var _a, _b;
1734
+ let lowest = null;
1735
+ let lowestHeight = Number.POSITIVE_INFINITY;
1736
+ for (const point of points) {
1737
+ const height = (_b = (_a = Cartographic.fromCartesian(point)) === null || _a === void 0 ? void 0 : _a.height) !== null && _b !== void 0 ? _b : Number.POSITIVE_INFINITY;
1738
+ if (height < lowestHeight) {
1739
+ lowestHeight = height;
1740
+ lowest = point;
1741
+ }
1742
+ }
1743
+ return lowest;
1744
+ }
1745
+ /*
1746
+ * Whether a point is clearly below the ground at its place: the terrain there, else sea level.
1747
+ */
1748
+ function reachesBelowGround(state, point) {
1749
+ var _a;
1750
+ if (!point) {
1751
+ return false;
1752
+ }
1753
+ const carto = ellipsoidOf(state).cartesianToCartographic(point);
1754
+ if (!carto) {
1755
+ return false;
1756
+ }
1757
+ return carto.height < ((_a = terrainHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0) - UNDERGROUND_MARGIN;
1758
+ }
1759
+ /*
1760
+ * Whether any of the first entities sits clearly below the ground: a point, or a line's first or last vertex.
1761
+ */
1762
+ function entitiesBelowGround(state) {
1763
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
1764
+ const viewer = state.viewer;
1765
+ const collections = [viewer.entities];
1766
+ const sources = viewer.dataSources;
1767
+ for (let i = 0; i < ((_a = sources === null || sources === void 0 ? void 0 : sources.length) !== null && _a !== void 0 ? _a : 0); i++) {
1768
+ collections.push((_b = sources.get(i)) === null || _b === void 0 ? void 0 : _b.entities);
1769
+ }
1770
+ const time = (_d = (_c = viewer.clock) === null || _c === void 0 ? void 0 : _c.currentTime) !== null && _d !== void 0 ? _d : JulianDate.now();
1771
+ let seen = 0;
1772
+ for (const collection of collections) {
1773
+ for (const entity of (_e = collection === null || collection === void 0 ? void 0 : collection.values) !== null && _e !== void 0 ? _e : []) {
1774
+ if (seen++ >= SCENE_SCAN_ENTITIES) {
1775
+ return false;
1776
+ }
1777
+ if (!entity || entity.show === false) {
1778
+ continue;
1779
+ }
1780
+ const graphic = (_j = (_h = (_g = (_f = entity.model) !== null && _f !== void 0 ? _f : entity.point) !== null && _g !== void 0 ? _g : entity.billboard) !== null && _h !== void 0 ? _h : entity.box) !== null && _j !== void 0 ? _j : entity.cylinder;
1781
+ const reference = (_l = (_k = graphic === null || graphic === void 0 ? void 0 : graphic.heightReference) === null || _k === void 0 ? void 0 : _k.getValue) === null || _l === void 0 ? void 0 : _l.call(_k, time);
1782
+ if (reference === HeightReference.CLAMP_TO_GROUND) {
1783
+ continue;
1784
+ }
1785
+ const position = (_o = (_m = entity.position) === null || _m === void 0 ? void 0 : _m.getValue) === null || _o === void 0 ? void 0 : _o.call(_m, time);
1786
+ if (position) {
1787
+ const relative = reference === HeightReference.RELATIVE_TO_GROUND;
1788
+ const height = relative ? (_p = ellipsoidOf(state).cartesianToCartographic(position)) === null || _p === void 0 ? void 0 : _p.height : null;
1789
+ if (relative ? height < -UNDERGROUND_MARGIN : reachesBelowGround(state, position)) {
1790
+ return true;
1791
+ }
1792
+ }
1793
+ const line = entity.polyline;
1794
+ if (line && !((_r = (_q = line.clampToGround) === null || _q === void 0 ? void 0 : _q.getValue) === null || _r === void 0 ? void 0 : _r.call(_q, time))) {
1795
+ const positions = (_u = (_t = (_s = line.positions) === null || _s === void 0 ? void 0 : _s.getValue) === null || _t === void 0 ? void 0 : _t.call(_s, time)) !== null && _u !== void 0 ? _u : [];
1796
+ if (positions.length && (reachesBelowGround(state, positions[0]) || reachesBelowGround(state, positions[positions.length - 1]))) {
1797
+ return true;
1798
+ }
1799
+ }
1800
+ }
1801
+ }
1802
+ return false;
1448
1803
  }
1449
1804
 
1450
1805
  const CESIUM_INSPECTOR_KEY = "_nextspace_inspector";
@@ -30917,6 +31272,8 @@ var TilesetGooglePhotosRenderManager;
30917
31272
  this.doDispose();
30918
31273
  return;
30919
31274
  }
31275
+ // Photorealistic tiles cover the Earth, so the camera treats them as the ground when the globe is hidden.
31276
+ CameraControls.SetGroundTileset(this.cTileset, true);
30920
31277
  this.viewer.scene.primitives.add(this.cTileset);
30921
31278
  this.applyColorMask();
30922
31279
  this.viewer.scene.requestRender();
@@ -59971,7 +60328,7 @@ var StyleUtils;
59971
60328
  StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
59972
60329
  })(StyleUtils || (StyleUtils = {}));
59973
60330
 
59974
- const VERSION = "7.7.8";
60331
+ const VERSION = "7.7.9";
59975
60332
  /**
59976
60333
  * Updates the environment instance used by bruce-cesium to one specified.
59977
60334
  * This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.