bruce-cesium 7.9.3 → 7.9.4
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.
- package/dist/bruce-cesium.es5.js +256 -30
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +255 -27
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/viewer/camera-controls.js +255 -27
- package/dist/lib/viewer/camera-controls.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/viewer/camera-controls.d.ts +11 -0
- package/package.json +1 -1
package/dist/lib/bruce-cesium.js
CHANGED
|
@@ -97,7 +97,7 @@ __exportStar(require("./widgets/widget-info-view"), exports);
|
|
|
97
97
|
__exportStar(require("./widgets/widget-left-panel"), exports);
|
|
98
98
|
__exportStar(require("./widgets/widget-nav-compass"), exports);
|
|
99
99
|
__exportStar(require("./widgets/widget-view-bar"), exports);
|
|
100
|
-
exports.VERSION = "7.9.
|
|
100
|
+
exports.VERSION = "7.9.4";
|
|
101
101
|
/**
|
|
102
102
|
* Updates the environment instance used by bruce-cesium to one specified.
|
|
103
103
|
* This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FindGapSurfaces = exports.CameraControls = void 0;
|
|
3
|
+
exports.GrabPoint = exports.NearClearance = exports.FindGapSurfaces = exports.CameraControls = void 0;
|
|
4
4
|
const Cesium = require("cesium");
|
|
5
5
|
const drawing_utils_1 = require("../utils/drawing-utils");
|
|
6
6
|
const CESIUM_CAMERA_CONTROLS_KEY = "_nextspace_camera_controls";
|
|
@@ -35,6 +35,11 @@ const PUSH_NOTCHES_DATA_BELOW = 3;
|
|
|
35
35
|
const PUSH_NOTCHES_NOTHING_BELOW = 10;
|
|
36
36
|
// Pushes further apart than this start counting again.
|
|
37
37
|
const PUSH_WINDOW_MS = 1200;
|
|
38
|
+
// How long after a zoom newly loaded terrain may lift the camera, and how much longer while loading.
|
|
39
|
+
const SURFACE_HOLD_MS = 4000;
|
|
40
|
+
const SURFACE_LOADING_MS = 30000;
|
|
41
|
+
// No visible ground lies lower; a stand-in tileset below this is a coarse tile cutting under the curve.
|
|
42
|
+
const GROUND_FLOOR = -500;
|
|
38
43
|
// How far below the ground something must reach to count as data underground, in metres.
|
|
39
44
|
const UNDERGROUND_MARGIN = 3;
|
|
40
45
|
// How long a scan of the scene for underground data and stand-in ground is trusted, in milliseconds.
|
|
@@ -84,6 +89,7 @@ var CameraControls;
|
|
|
84
89
|
push: { notches: 0, at: 0 },
|
|
85
90
|
scan: null,
|
|
86
91
|
undergroundOverride: null,
|
|
92
|
+
surface: { above: false, through: false, until: 0, at: null },
|
|
87
93
|
saved: {
|
|
88
94
|
rotateEventTypes: controller.rotateEventTypes,
|
|
89
95
|
zoomEventTypes: controller.zoomEventTypes,
|
|
@@ -108,7 +114,10 @@ var CameraControls;
|
|
|
108
114
|
listen(window, "pointerup", (e) => onPointerUp(state, e));
|
|
109
115
|
listen(window, "pointercancel", (e) => onPointerUp(state, e));
|
|
110
116
|
listen(canvas, "wheel", (e) => onWheel(state, e), { passive: true });
|
|
111
|
-
state.removals.push(scene.preUpdate.addEventListener(() =>
|
|
117
|
+
state.removals.push(scene.preUpdate.addEventListener(() => {
|
|
118
|
+
syncController(state);
|
|
119
|
+
keepAboveGround(state);
|
|
120
|
+
}));
|
|
112
121
|
syncController(state);
|
|
113
122
|
scene.requestRender();
|
|
114
123
|
}
|
|
@@ -260,6 +269,38 @@ function terrainHeightAt(state, carto) {
|
|
|
260
269
|
const height = globe.getHeight(carto);
|
|
261
270
|
return Number.isFinite(height) ? height : undefined;
|
|
262
271
|
}
|
|
272
|
+
/*
|
|
273
|
+
* The ground's height at a place: the loaded terrain, or the tileset standing in for a hidden globe.
|
|
274
|
+
*/
|
|
275
|
+
function groundHeightAt(state, carto) {
|
|
276
|
+
var _a;
|
|
277
|
+
if (globeShown(state)) {
|
|
278
|
+
return terrainHeightAt(state, carto);
|
|
279
|
+
}
|
|
280
|
+
const tileset = scanScene(state).ground;
|
|
281
|
+
if (!carto || !tileset || ((_a = tileset.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(tileset)) || typeof tileset.getHeight !== "function") {
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
// Only tiles drawn this frame answer, which near the camera are the finest loaded.
|
|
286
|
+
const height = tileset.getHeight(carto, state.viewer.scene);
|
|
287
|
+
return Number.isFinite(height) && height > GROUND_FLOOR ? height : undefined;
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/*
|
|
294
|
+
* Whether the ground is still loading: the globe's tiles, or the stand-in tileset's.
|
|
295
|
+
*/
|
|
296
|
+
function groundLoading(state) {
|
|
297
|
+
var _a;
|
|
298
|
+
if (globeShown(state)) {
|
|
299
|
+
return state.viewer.scene.globe.tilesLoaded === false;
|
|
300
|
+
}
|
|
301
|
+
const tileset = scanScene(state).ground;
|
|
302
|
+
return Boolean(tileset && !((_a = tileset.isDestroyed) === null || _a === void 0 ? void 0 : _a.call(tileset)) && tileset.tilesLoaded === false);
|
|
303
|
+
}
|
|
263
304
|
function ellipsoidOf(state) {
|
|
264
305
|
var _a, _b;
|
|
265
306
|
return (_b = (_a = state.viewer.scene.globe) === null || _a === void 0 ? void 0 : _a.ellipsoid) !== null && _b !== void 0 ? _b : Cesium.Ellipsoid.WGS84;
|
|
@@ -297,8 +338,8 @@ function groundPlane(state) {
|
|
|
297
338
|
if (!carto) {
|
|
298
339
|
return null;
|
|
299
340
|
}
|
|
300
|
-
// Level with the
|
|
301
|
-
const surface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a =
|
|
341
|
+
// Level with the ground under the camera, not sea level, so a guess over high ground is not far too deep.
|
|
342
|
+
const surface = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, (_a = groundHeightAt(state, carto)) !== null && _a !== void 0 ? _a : 0, ellipsoid);
|
|
302
343
|
return Cesium.Plane.fromPointNormal(surface, ellipsoid.geodeticSurfaceNormal(surface, new Cesium.Cartesian3()));
|
|
303
344
|
}
|
|
304
345
|
/*
|
|
@@ -322,6 +363,15 @@ const GAP_SLACK = 0.5;
|
|
|
322
363
|
// Directions around the centre, and how many must hold nearer pixels for the centre to be surrounded.
|
|
323
364
|
const GAP_SECTORS = 8;
|
|
324
365
|
const GAP_SECTORS_NEAR = 6;
|
|
366
|
+
// How far around the cursor, in CSS pixels, nearer parts limit a zoom, and the most buffer pixels read.
|
|
367
|
+
const CLEARANCE_RADIUS_PX = 24;
|
|
368
|
+
const CLEARANCE_RADIUS_MAX = 64;
|
|
369
|
+
// The share of that window that must be nearer, so a stray pixel or a thin cable does not slow the zoom.
|
|
370
|
+
const CLEARANCE_SHARE = 0.05;
|
|
371
|
+
// A pixel at least this share of the level ground's distance on its ray is ground, and never limits.
|
|
372
|
+
const CLEARANCE_GROUND = 0.9;
|
|
373
|
+
// A pan or orbit grabbing this many times farther than the reach grabs at the reach instead.
|
|
374
|
+
const CLEARANCE_GRAB = 2;
|
|
325
375
|
const PACKED_DEPTH = new Cesium.Cartesian4(1, 1 / 255, 1 / 65025, 1 / 16581375);
|
|
326
376
|
/*
|
|
327
377
|
* Distances along the view axis drawn around a window position, rows bottom-up, Infinity where nothing is drawn.
|
|
@@ -370,6 +420,21 @@ function readDepthDistances(scene, position, radius) {
|
|
|
370
420
|
}
|
|
371
421
|
return distances;
|
|
372
422
|
}
|
|
423
|
+
/*
|
|
424
|
+
* The depth window around a position for the gap search and the reach, or null when unreadable.
|
|
425
|
+
*/
|
|
426
|
+
function readWindow(scene, position) {
|
|
427
|
+
const scale = scene.drawingBufferWidth / scene.canvas.clientWidth;
|
|
428
|
+
const clearance = Math.min(Math.round(CLEARANCE_RADIUS_PX * (Number.isFinite(scale) ? scale : 1)), CLEARANCE_RADIUS_MAX);
|
|
429
|
+
const radius = Math.max(GAP_RADII[GAP_RADII.length - 1], clearance);
|
|
430
|
+
try {
|
|
431
|
+
const distances = readDepthDistances(scene, position, radius);
|
|
432
|
+
return distances ? { distances, radius } : null;
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
373
438
|
/*
|
|
374
439
|
* Offsets of the surface pixel around the centre for each radius where clearly nearer pixels surround it.
|
|
375
440
|
*/
|
|
@@ -408,15 +473,7 @@ exports.FindGapSurfaces = FindGapSurfaces;
|
|
|
408
473
|
/*
|
|
409
474
|
* The point cloud surface around a pick that looked through a gap between its points, or null when it did not.
|
|
410
475
|
*/
|
|
411
|
-
function fillGap(scene, position, picked) {
|
|
412
|
-
const radius = GAP_RADII[GAP_RADII.length - 1];
|
|
413
|
-
let distances = null;
|
|
414
|
-
try {
|
|
415
|
-
distances = readDepthDistances(scene, position, radius);
|
|
416
|
-
}
|
|
417
|
-
catch (e) {
|
|
418
|
-
return null;
|
|
419
|
-
}
|
|
476
|
+
function fillGap(scene, position, picked, distances, radius) {
|
|
420
477
|
if (!distances) {
|
|
421
478
|
return null;
|
|
422
479
|
}
|
|
@@ -436,9 +493,81 @@ function fillGap(scene, position, picked) {
|
|
|
436
493
|
return null;
|
|
437
494
|
}
|
|
438
495
|
/*
|
|
439
|
-
* The
|
|
496
|
+
* The view-axis distance within which a share of the window around the cursor is drawn, ground aside.
|
|
497
|
+
*/
|
|
498
|
+
function NearClearance(distances, radius, groundAt) {
|
|
499
|
+
const width = 2 * radius + 1;
|
|
500
|
+
const near = [];
|
|
501
|
+
for (let dy = -radius; dy <= radius; dy++) {
|
|
502
|
+
for (let dx = -radius; dx <= radius; dx++) {
|
|
503
|
+
const distance = distances[(radius + dy) * width + (radius + dx)];
|
|
504
|
+
if (!Number.isFinite(distance)) {
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
const ground = groundAt ? groundAt(dx, dy) : Infinity;
|
|
508
|
+
if (!(ground > 0 && distance >= ground * CLEARANCE_GROUND)) {
|
|
509
|
+
near.push(distance);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
const needed = Math.max(1, Math.ceil(width * width * CLEARANCE_SHARE));
|
|
514
|
+
if (near.length < needed) {
|
|
515
|
+
return Infinity;
|
|
516
|
+
}
|
|
517
|
+
near.sort((a, b) => a - b);
|
|
518
|
+
return near[needed - 1];
|
|
519
|
+
}
|
|
520
|
+
exports.NearClearance = NearClearance;
|
|
521
|
+
/*
|
|
522
|
+
* The level ground's view-axis distance through each window pixel, or null when there is no ground.
|
|
523
|
+
*/
|
|
524
|
+
function groundDistances(state, position) {
|
|
525
|
+
const scene = state.viewer.scene;
|
|
526
|
+
const camera = scene.camera;
|
|
527
|
+
const frustum = camera.frustum;
|
|
528
|
+
if (!(state.getModelSpaceFrame || hasGround(state)) ||
|
|
529
|
+
typeof (frustum === null || frustum === void 0 ? void 0 : frustum.getPixelDimensions) !== "function") {
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
const plane = groundPlane(state);
|
|
533
|
+
if (!plane) {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const width = scene.drawingBufferWidth;
|
|
537
|
+
const height = scene.drawingBufferHeight;
|
|
538
|
+
// The size of one buffer pixel one metre ahead, which turns a pixel offset into a ray direction.
|
|
539
|
+
const pixel = frustum.getPixelDimensions(width, height, 1, 1, new Cesium.Cartesian2());
|
|
540
|
+
const above = Cesium.Plane.getPointDistance(plane, camera.positionWC);
|
|
541
|
+
const normal = plane.normal;
|
|
542
|
+
const along = Cesium.Cartesian3.dot(camera.directionWC, normal);
|
|
543
|
+
const right = Cesium.Cartesian3.dot(camera.rightWC, normal);
|
|
544
|
+
const up = Cesium.Cartesian3.dot(camera.upWC, normal);
|
|
545
|
+
// The cursor's offset from the centre in buffer pixels, rows bottom-up as the window's are.
|
|
546
|
+
const x = Math.floor(position.x * width / scene.canvas.clientWidth) + 0.5 - width / 2;
|
|
547
|
+
const y = height / 2 - Math.floor(position.y * height / scene.canvas.clientHeight) - 0.5;
|
|
548
|
+
return (dx, dy) => {
|
|
549
|
+
const rate = along + (x + dx) * pixel.x * right + (y + dy) * pixel.y * up;
|
|
550
|
+
return rate < 0 ? -above / rate : Infinity;
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
/*
|
|
554
|
+
* The point under a screen position, and how far a zoom toward it may go before passing parts beside it.
|
|
440
555
|
*/
|
|
441
556
|
function pickTarget(state, position) {
|
|
557
|
+
const scene = state.viewer.scene;
|
|
558
|
+
// Read before anything else picks, while the depth still holds the frame on screen.
|
|
559
|
+
const depths = scene.pickPositionSupported ? readWindow(scene, position) : null;
|
|
560
|
+
const target = pickPoint(state, position, depths);
|
|
561
|
+
if (target && depths) {
|
|
562
|
+
target.reach = NearClearance(depths.distances, depths.radius, groundDistances(state, position));
|
|
563
|
+
target.reachFrom = Cesium.Cartesian3.clone(state.viewer.camera.positionWC);
|
|
564
|
+
}
|
|
565
|
+
return target;
|
|
566
|
+
}
|
|
567
|
+
/*
|
|
568
|
+
* The point under a screen position: what is drawn there, else the ground plane, else a point at the last distance.
|
|
569
|
+
*/
|
|
570
|
+
function pickPoint(state, position, depths) {
|
|
442
571
|
const viewer = state.viewer;
|
|
443
572
|
const scene = viewer.scene;
|
|
444
573
|
const camera = viewer.camera;
|
|
@@ -463,12 +592,16 @@ function pickTarget(state, position) {
|
|
|
463
592
|
}
|
|
464
593
|
const plausible = plausibleDistance(state);
|
|
465
594
|
// A click between point cloud points sees the background; turning or zooming about that throws the camera far off.
|
|
466
|
-
const surface =
|
|
595
|
+
const surface = depths ? fillGap(scene, position, ahead !== null && ahead !== void 0 ? ahead : null, depths.distances, depths.radius) : null;
|
|
467
596
|
if (isAhead(camera, surface) && Cesium.Cartesian3.distance(surface, camera.positionWC) < plausible) {
|
|
468
597
|
return { point: surface, source: "pick", ground: false };
|
|
469
598
|
}
|
|
470
599
|
if (isAhead(camera, picked) && Cesium.Cartesian3.distance(picked, camera.positionWC) < plausible) {
|
|
471
|
-
|
|
600
|
+
const ground = isGroundPick(state, position);
|
|
601
|
+
// Right after a jump a stand-in tileset's coarse tiles cut far under the curve; use sea level.
|
|
602
|
+
if (!ground || globeShown(state) || heightOf(state, picked) > GROUND_FLOOR) {
|
|
603
|
+
return { point: picked, source: "pick", ground };
|
|
604
|
+
}
|
|
472
605
|
}
|
|
473
606
|
const ground = groundPlane(state);
|
|
474
607
|
const onGround = ground ? Cesium.IntersectionTests.rayPlane(ray, ground) : null;
|
|
@@ -570,8 +703,8 @@ function onPointerDown(state, e) {
|
|
|
570
703
|
if (!picked) {
|
|
571
704
|
return;
|
|
572
705
|
}
|
|
573
|
-
const target = picked.point;
|
|
574
706
|
const camera = viewer.camera;
|
|
707
|
+
const target = kind === EDrag.Zoom ? picked.point : GrabPoint(camera, position, picked);
|
|
575
708
|
const distance = Cesium.Cartesian3.distance(camera.positionWC, target);
|
|
576
709
|
state.lastDistance = Math.max(distance, MIN_ZOOM_DISTANCE);
|
|
577
710
|
const drag = { kind, pointerId: e.pointerId, last: position, target, up: upAt(state, target), distance, picked };
|
|
@@ -579,10 +712,29 @@ function onPointerDown(state, e) {
|
|
|
579
712
|
drag.plane = panPlane(camera, target, drag.up);
|
|
580
713
|
}
|
|
581
714
|
else if (kind === EDrag.Zoom) {
|
|
715
|
+
holdSurface(state);
|
|
582
716
|
drag.direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(target, camera.positionWC, new Cesium.Cartesian3()), new Cesium.Cartesian3());
|
|
583
717
|
}
|
|
584
718
|
state.drag = drag;
|
|
585
719
|
}
|
|
720
|
+
/*
|
|
721
|
+
* Where a pan or orbit takes hold: the pick, or beside the cursor when it looked far past parts there.
|
|
722
|
+
*/
|
|
723
|
+
function GrabPoint(camera, position, picked) {
|
|
724
|
+
const reach = picked.reach;
|
|
725
|
+
const ray = camera.getPickRay(position);
|
|
726
|
+
if (!ray || reach == null || !Number.isFinite(reach)) {
|
|
727
|
+
return picked.point;
|
|
728
|
+
}
|
|
729
|
+
const facing = Cesium.Cartesian3.dot(ray.direction, camera.directionWC);
|
|
730
|
+
const depth = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(picked.point, camera.positionWC, new Cesium.Cartesian3()), camera.directionWC);
|
|
731
|
+
if (facing <= 0 || depth <= reach * CLEARANCE_GRAB) {
|
|
732
|
+
return picked.point;
|
|
733
|
+
}
|
|
734
|
+
// The reach is along the view axis, so the ray goes a little further to the same depth.
|
|
735
|
+
return Cesium.Ray.getPoint(ray, Math.max(reach, MIN_ZOOM_DISTANCE) / facing);
|
|
736
|
+
}
|
|
737
|
+
exports.GrabPoint = GrabPoint;
|
|
586
738
|
/*
|
|
587
739
|
* A level plane through the grabbed point, or one facing the camera when the level one is seen edge on.
|
|
588
740
|
*/
|
|
@@ -731,6 +883,7 @@ function onWheel(state, e) {
|
|
|
731
883
|
if (!target || !ray) {
|
|
732
884
|
return;
|
|
733
885
|
}
|
|
886
|
+
holdSurface(state);
|
|
734
887
|
const step = zoomStep(state, ray.direction, target, notches);
|
|
735
888
|
Cesium.Cartesian3.add(state.pendingZoom, step, state.pendingZoom);
|
|
736
889
|
state.zoomPosition = Cesium.Cartesian3.clone(camera.position);
|
|
@@ -759,6 +912,8 @@ function easeZoom(state) {
|
|
|
759
912
|
const step = Cesium.Cartesian3.multiplyByScalar(state.pendingZoom, share, new Cesium.Cartesian3());
|
|
760
913
|
Cesium.Cartesian3.subtract(state.pendingZoom, step, state.pendingZoom);
|
|
761
914
|
Cesium.Cartesian3.add(viewer.camera.position, step, viewer.camera.position);
|
|
915
|
+
zoomMoved(state);
|
|
916
|
+
keepAboveGround(state);
|
|
762
917
|
state.zoomPosition = Cesium.Cartesian3.clone(viewer.camera.position);
|
|
763
918
|
viewer.scene.requestRender();
|
|
764
919
|
if (share < 1) {
|
|
@@ -768,6 +923,7 @@ function easeZoom(state) {
|
|
|
768
923
|
function moveAlong(state, direction, target, notches) {
|
|
769
924
|
const step = zoomStep(state, direction, target, notches);
|
|
770
925
|
Cesium.Cartesian3.add(state.viewer.camera.position, step, state.viewer.camera.position);
|
|
926
|
+
zoomMoved(state);
|
|
771
927
|
}
|
|
772
928
|
/*
|
|
773
929
|
* The move for some notches toward a target along a direction, a share of the distance with a floor so it never stalls.
|
|
@@ -777,7 +933,14 @@ function zoomStep(state, direction, picked, notches) {
|
|
|
777
933
|
const target = picked.point;
|
|
778
934
|
// Where the camera will be once the glide already under way ends, which this step continues from.
|
|
779
935
|
const from = Cesium.Cartesian3.add(camera.positionWC, state.pendingZoom, new Cesium.Cartesian3());
|
|
780
|
-
const
|
|
936
|
+
const unit = Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3());
|
|
937
|
+
let distance = Cesium.Cartesian3.distance(from, target);
|
|
938
|
+
// Between parts of a model, each step goes as far as it would on the nearest part around the cursor.
|
|
939
|
+
if (picked.reach != null && picked.reachFrom) {
|
|
940
|
+
const travelled = Cesium.Cartesian3.dot(Cesium.Cartesian3.subtract(from, picked.reachFrom, new Cesium.Cartesian3()), unit);
|
|
941
|
+
distance = Math.min(distance, picked.reach - travelled);
|
|
942
|
+
}
|
|
943
|
+
distance = Math.max(distance, MIN_ZOOM_DISTANCE);
|
|
781
944
|
state.lastDistance = distance;
|
|
782
945
|
let length = distance * ZOOM_SHARE * notches * zoomSpeedShare(state, picked);
|
|
783
946
|
// A geospatial camera zooming out hands over to CesiumJS once it is high enough, so only model-space is capped.
|
|
@@ -789,7 +952,6 @@ function zoomStep(state, direction, picked, notches) {
|
|
|
789
952
|
return new Cesium.Cartesian3();
|
|
790
953
|
}
|
|
791
954
|
}
|
|
792
|
-
const unit = Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3());
|
|
793
955
|
// With the globe hidden there is no hand-over, so zooming out stops where the Earth is a dot.
|
|
794
956
|
if (length < 0 && !state.getModelSpaceFrame && !globeShown(state)) {
|
|
795
957
|
const rise = -Cesium.Cartesian3.dot(unit, upAt(state, from));
|
|
@@ -805,15 +967,14 @@ function zoomStep(state, direction, picked, notches) {
|
|
|
805
967
|
return length > 0 ? resistDescent(state, from, step, picked, notches) : step;
|
|
806
968
|
}
|
|
807
969
|
/*
|
|
808
|
-
* How fast to zoom toward a target: slower toward a guess, or while the
|
|
970
|
+
* How fast to zoom toward a target: slower toward a guess, or while the ground that would give a real one loads.
|
|
809
971
|
*/
|
|
810
972
|
function zoomSpeedShare(state, picked) {
|
|
811
973
|
let share = 1;
|
|
812
974
|
if (picked.source !== "pick") {
|
|
813
975
|
share *= ZOOM_GUESS_SHARE;
|
|
814
976
|
}
|
|
815
|
-
|
|
816
|
-
if (!state.getModelSpaceFrame && globeShown(state) && globe.tilesLoaded === false) {
|
|
977
|
+
if (!state.getModelSpaceFrame && groundLoading(state)) {
|
|
817
978
|
share *= ZOOM_LOADING_SHARE;
|
|
818
979
|
}
|
|
819
980
|
return share;
|
|
@@ -829,16 +990,17 @@ function groundUnderMove(state, from, step, picked) {
|
|
|
829
990
|
if (picked === null || picked === void 0 ? void 0 : picked.ground) {
|
|
830
991
|
return { point: picked.point, up: upAt(state, picked.point) };
|
|
831
992
|
}
|
|
832
|
-
if (!globeShown(state)) {
|
|
833
|
-
return null;
|
|
834
|
-
}
|
|
835
993
|
const ellipsoid = ellipsoidOf(state);
|
|
836
994
|
const end = Cesium.Cartesian3.add(from, step, new Cesium.Cartesian3());
|
|
837
995
|
const carto = ellipsoid.cartesianToCartographic(end);
|
|
838
996
|
if (!carto) {
|
|
839
997
|
return null;
|
|
840
998
|
}
|
|
841
|
-
|
|
999
|
+
// Unloaded terrain counts as sea level; an unknown stand-in tileset counts as nothing.
|
|
1000
|
+
const height = (_b = (_a = groundHeightAt(state, carto)) !== null && _a !== void 0 ? _a : groundHeightAt(state, ellipsoid.cartesianToCartographic(from))) !== null && _b !== void 0 ? _b : (globeShown(state) ? 0 : null);
|
|
1001
|
+
if (height == null) {
|
|
1002
|
+
return null;
|
|
1003
|
+
}
|
|
842
1004
|
const point = Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, height, ellipsoid);
|
|
843
1005
|
return { point, up: ellipsoid.geodeticSurfaceNormal(point, new Cesium.Cartesian3()) };
|
|
844
1006
|
}
|
|
@@ -888,12 +1050,77 @@ function resistDescent(state, from, step, picked, notches) {
|
|
|
888
1050
|
const needed = scanScene(state).undergroundData ? PUSH_NOTCHES_DATA_BELOW : PUSH_NOTCHES_NOTHING_BELOW;
|
|
889
1051
|
if (state.push.notches >= needed) {
|
|
890
1052
|
state.push.notches = 0;
|
|
1053
|
+
state.surface = { above: false, through: true, until: now + SURFACE_HOLD_MS, at: null };
|
|
891
1054
|
// A shallow push would land far along the ground to get under it, so it goes no further than a usual step.
|
|
892
1055
|
const through = Math.min((above + GROUND_BREAK_DEPTH) / sink, Math.max(length, (above + GROUND_BREAK_DEPTH) * 4));
|
|
893
1056
|
return Cesium.Cartesian3.multiplyByScalar(unit, through, new Cesium.Cartesian3());
|
|
894
1057
|
}
|
|
895
1058
|
return Cesium.Cartesian3.multiplyByScalar(unit, toStandOff, new Cesium.Cartesian3());
|
|
896
1059
|
}
|
|
1060
|
+
/*
|
|
1061
|
+
* The camera's height above the loaded ground under it, or undefined without ground or in model-space.
|
|
1062
|
+
*/
|
|
1063
|
+
function heightAboveGround(state) {
|
|
1064
|
+
if (state.getModelSpaceFrame || !hasGround(state)) {
|
|
1065
|
+
return undefined;
|
|
1066
|
+
}
|
|
1067
|
+
const carto = ellipsoidOf(state).cartesianToCartographic(state.viewer.camera.positionWC);
|
|
1068
|
+
const ground = carto ? groundHeightAt(state, carto) : undefined;
|
|
1069
|
+
return ground == null ? undefined : carto.height - ground;
|
|
1070
|
+
}
|
|
1071
|
+
/*
|
|
1072
|
+
* Notes whether the camera is above the ground as a zoom begins, unless it is being pushed through it.
|
|
1073
|
+
*/
|
|
1074
|
+
function holdSurface(state) {
|
|
1075
|
+
var _a;
|
|
1076
|
+
const now = Date.now();
|
|
1077
|
+
if (state.surface.through && now < state.surface.until) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
const at = Cesium.Cartesian3.clone(state.viewer.camera.positionWC);
|
|
1081
|
+
// Ground not loaded yet counts as sea level, as it does for a descent.
|
|
1082
|
+
const above = (_a = heightAboveGround(state)) !== null && _a !== void 0 ? _a : (hasGround(state) && !state.getModelSpaceFrame ? heightOf(state, at) : undefined);
|
|
1083
|
+
state.surface = { above: above != null && above > 0, through: false, until: now + SURFACE_HOLD_MS, at };
|
|
1084
|
+
}
|
|
1085
|
+
/*
|
|
1086
|
+
* Lifts a camera a zoom kept above the ground back over finer ground that loads in higher.
|
|
1087
|
+
*/
|
|
1088
|
+
function keepAboveGround(state) {
|
|
1089
|
+
const surface = state.surface;
|
|
1090
|
+
const now = Date.now();
|
|
1091
|
+
if (!surface.above || !state.ours || now > surface.until + SURFACE_LOADING_MS) {
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
// Ground that has finished loading does not move under a still camera.
|
|
1095
|
+
if (now > surface.until && !groundLoading(state)) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
const camera = state.viewer.camera;
|
|
1099
|
+
// A bookmark, fly-to or pan moved it since, which may mean to go below the ground.
|
|
1100
|
+
if (!surface.at || !Cesium.Cartesian3.equalsEpsilon(camera.positionWC, surface.at, 0, 1e-3)) {
|
|
1101
|
+
surface.above = false;
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
const above = heightAboveGround(state);
|
|
1105
|
+
if (above == null || above >= GROUND_STANDOFF / 2) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const ellipsoid = ellipsoidOf(state);
|
|
1109
|
+
const carto = ellipsoid.cartesianToCartographic(camera.positionWC);
|
|
1110
|
+
Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height - above + GROUND_STANDOFF, ellipsoid, camera.position);
|
|
1111
|
+
// What is left of the glide would take it straight back down.
|
|
1112
|
+
state.pendingZoom = new Cesium.Cartesian3();
|
|
1113
|
+
surface.at = Cesium.Cartesian3.clone(camera.position);
|
|
1114
|
+
state.viewer.scene.requestRender();
|
|
1115
|
+
}
|
|
1116
|
+
/*
|
|
1117
|
+
* Notes where a zoom just put the camera, so the ground hold can tell its moves from others.
|
|
1118
|
+
*/
|
|
1119
|
+
function zoomMoved(state) {
|
|
1120
|
+
if (state.surface.at) {
|
|
1121
|
+
Cesium.Cartesian3.clone(state.viewer.camera.positionWC, state.surface.at);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
897
1124
|
/*
|
|
898
1125
|
* What the scene holds that the camera cares about, rescanned at most every couple of seconds.
|
|
899
1126
|
*/
|
|
@@ -904,7 +1131,7 @@ function scanScene(state) {
|
|
|
904
1131
|
return applyOverride(state, state.scan);
|
|
905
1132
|
}
|
|
906
1133
|
const scene = state.viewer.scene;
|
|
907
|
-
const found = { at: now, undergroundData: false, groundTileset: false };
|
|
1134
|
+
const found = { at: now, undergroundData: false, groundTileset: false, ground: null };
|
|
908
1135
|
// Seeing through the ground is turned on to look at what is under it.
|
|
909
1136
|
if ((_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
910
1137
|
found.undergroundData = true;
|
|
@@ -921,6 +1148,7 @@ function scanScene(state) {
|
|
|
921
1148
|
}
|
|
922
1149
|
if (primitive[GROUND_TILESET_KEY]) {
|
|
923
1150
|
found.groundTileset = true;
|
|
1151
|
+
found.ground = primitive;
|
|
924
1152
|
return;
|
|
925
1153
|
}
|
|
926
1154
|
if (!found.undergroundData && reachesBelowGround(state, lowestPointOf(primitive))) {
|