bruce-cesium 7.9.4 → 7.9.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.
- package/dist/bruce-cesium.es5.js +884 -134
- package/dist/bruce-cesium.es5.js.map +1 -1
- package/dist/bruce-cesium.umd.js +877 -131
- package/dist/bruce-cesium.umd.js.map +1 -1
- package/dist/lib/bruce-cesium.js +1 -1
- package/dist/lib/rendering/displaced-surface-primitive.js +699 -124
- package/dist/lib/rendering/displaced-surface-primitive.js.map +1 -1
- package/dist/lib/rendering/entity-render-engine-polygon.js +1 -0
- package/dist/lib/rendering/entity-render-engine-polygon.js.map +1 -1
- package/dist/lib/viewer/camera-controls.js +181 -6
- package/dist/lib/viewer/camera-controls.js.map +1 -1
- package/dist/types/bruce-cesium.d.ts +1 -1
- package/dist/types/rendering/displaced-surface-primitive.d.ts +101 -3
- package/dist/types/viewer/camera-controls.d.ts +30 -0
- package/package.json +1 -1
package/dist/bruce-cesium.umd.js
CHANGED
|
@@ -1385,6 +1385,20 @@ void main()
|
|
|
1385
1385
|
const HIDDEN_GLOBE_MAX_HEIGHT = 10000000;
|
|
1386
1386
|
// Marks a tileset that stands in for the globe, such as Google's photorealistic tiles.
|
|
1387
1387
|
const GROUND_TILESET_KEY = "_nextspace_camera_ground";
|
|
1388
|
+
// A viewer's own mouse scheme and wheel direction, kept on the viewer so a host may set them before Attach.
|
|
1389
|
+
const MOUSE_KEY = "_nextspace_camera_mouse";
|
|
1390
|
+
// Marks a wheel event these controls turned round, so it is not turned back again.
|
|
1391
|
+
const MIRRORED_WHEEL_KEY = "_nextspace_mirrored";
|
|
1392
|
+
(function (ECameraMouseScheme) {
|
|
1393
|
+
// CesiumJS's own: left drag pans, middle or ctrl drag orbits, right drag zooms.
|
|
1394
|
+
ECameraMouseScheme["Default"] = "default";
|
|
1395
|
+
// Autodesk Fusion, Revit, Navisworks and AutoCAD: middle drag pans, shift+middle orbits, ctrl+shift+middle zooms.
|
|
1396
|
+
ECameraMouseScheme["Autodesk"] = "autodesk";
|
|
1397
|
+
// SketchUp: middle drag orbits, shift+middle pans.
|
|
1398
|
+
ECameraMouseScheme["SketchUp"] = "sketchup";
|
|
1399
|
+
})(exports.ECameraMouseScheme || (exports.ECameraMouseScheme = {}));
|
|
1400
|
+
// What a viewer without its own setting uses: the app user's preference, set once for every viewer the app makes.
|
|
1401
|
+
const _mouseDefault = { scheme: exports.ECameraMouseScheme.Default, wheelReversed: false };
|
|
1388
1402
|
var EDrag;
|
|
1389
1403
|
(function (EDrag) {
|
|
1390
1404
|
EDrag["Pan"] = "pan";
|
|
@@ -1396,7 +1410,7 @@ void main()
|
|
|
1396
1410
|
* Takes over mouse drag and wheel navigation close to the ground; CesiumJS keeps planet scale, pinch and look.
|
|
1397
1411
|
*/
|
|
1398
1412
|
function Attach(viewer) {
|
|
1399
|
-
var _a, _b, _c;
|
|
1413
|
+
var _a, _b, _c, _d;
|
|
1400
1414
|
if (!viewer || viewer.isDestroyed() || viewer[CESIUM_CAMERA_CONTROLS_KEY]) {
|
|
1401
1415
|
return;
|
|
1402
1416
|
}
|
|
@@ -1422,11 +1436,13 @@ void main()
|
|
|
1422
1436
|
rotateEventTypes: controller.rotateEventTypes,
|
|
1423
1437
|
zoomEventTypes: controller.zoomEventTypes,
|
|
1424
1438
|
tiltEventTypes: controller.tiltEventTypes,
|
|
1439
|
+
translateEventTypes: controller.translateEventTypes,
|
|
1425
1440
|
enableCollisionDetection: controller.enableCollisionDetection,
|
|
1426
1441
|
backFaceAlpha: (_b = (_a = scene.globe) === null || _a === void 0 ? void 0 : _a.translucency) === null || _b === void 0 ? void 0 : _b.backFaceAlpha,
|
|
1427
1442
|
showSkirts: (_c = scene.globe) === null || _c === void 0 ? void 0 : _c.showSkirts
|
|
1428
1443
|
},
|
|
1429
1444
|
ours: false,
|
|
1445
|
+
cesiumScheme: null,
|
|
1430
1446
|
removals: []
|
|
1431
1447
|
};
|
|
1432
1448
|
viewer[CESIUM_CAMERA_CONTROLS_KEY] = state;
|
|
@@ -1442,6 +1458,9 @@ void main()
|
|
|
1442
1458
|
listen(window, "pointerup", (e) => onPointerUp(state, e));
|
|
1443
1459
|
listen(window, "pointercancel", (e) => onPointerUp(state, e));
|
|
1444
1460
|
listen(canvas, "wheel", (e) => onWheel(state, e), { passive: true });
|
|
1461
|
+
// Caught before the canvas sees it, so CesiumJS's controller and these controls both get the turned wheel.
|
|
1462
|
+
const wheelHost = (_d = canvas.parentElement) !== null && _d !== void 0 ? _d : window;
|
|
1463
|
+
listen(wheelHost, "wheel", (e) => mirrorWheel(state, e), { capture: true, passive: false });
|
|
1445
1464
|
state.removals.push(scene.preUpdate.addEventListener(() => {
|
|
1446
1465
|
syncController(state);
|
|
1447
1466
|
keepAboveGround(state);
|
|
@@ -1477,6 +1496,52 @@ void main()
|
|
|
1477
1496
|
return Boolean(viewer === null || viewer === void 0 ? void 0 : viewer[CESIUM_CAMERA_CONTROLS_KEY]);
|
|
1478
1497
|
}
|
|
1479
1498
|
CameraControls.IsAttached = IsAttached;
|
|
1499
|
+
/**
|
|
1500
|
+
* Picks which mouse buttons pan, orbit and zoom, here and for CesiumJS's controller above the hand-over height.
|
|
1501
|
+
*/
|
|
1502
|
+
function SetMouseScheme(viewer, scheme) {
|
|
1503
|
+
if (!viewer || viewer.isDestroyed()) {
|
|
1504
|
+
return;
|
|
1505
|
+
}
|
|
1506
|
+
viewer[MOUSE_KEY] = { ...viewer[MOUSE_KEY], scheme: knownScheme(scheme) };
|
|
1507
|
+
const state = viewer[CESIUM_CAMERA_CONTROLS_KEY];
|
|
1508
|
+
if (state && !state.ours) {
|
|
1509
|
+
applyCesiumGestures(state);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
CameraControls.SetMouseScheme = SetMouseScheme;
|
|
1513
|
+
/**
|
|
1514
|
+
* Sets the scheme for every viewer without its own, such as the app user's preference; viewers follow next frame.
|
|
1515
|
+
*/
|
|
1516
|
+
function SetMouseSchemeDefault(scheme) {
|
|
1517
|
+
_mouseDefault.scheme = knownScheme(scheme);
|
|
1518
|
+
}
|
|
1519
|
+
CameraControls.SetMouseSchemeDefault = SetMouseSchemeDefault;
|
|
1520
|
+
function GetMouseScheme(viewer) {
|
|
1521
|
+
return mouseOf(viewer).scheme;
|
|
1522
|
+
}
|
|
1523
|
+
CameraControls.GetMouseScheme = GetMouseScheme;
|
|
1524
|
+
/**
|
|
1525
|
+
* Makes wheel forward zoom out instead of in, for these controls and CesiumJS's controller alike.
|
|
1526
|
+
*/
|
|
1527
|
+
function SetMouseWheelReversed(viewer, reversed) {
|
|
1528
|
+
if (!viewer || viewer.isDestroyed()) {
|
|
1529
|
+
return;
|
|
1530
|
+
}
|
|
1531
|
+
viewer[MOUSE_KEY] = { ...viewer[MOUSE_KEY], wheelReversed: Boolean(reversed) };
|
|
1532
|
+
}
|
|
1533
|
+
CameraControls.SetMouseWheelReversed = SetMouseWheelReversed;
|
|
1534
|
+
/**
|
|
1535
|
+
* Sets the wheel direction for every viewer without its own, such as the app user's preference.
|
|
1536
|
+
*/
|
|
1537
|
+
function SetMouseWheelReversedDefault(reversed) {
|
|
1538
|
+
_mouseDefault.wheelReversed = Boolean(reversed);
|
|
1539
|
+
}
|
|
1540
|
+
CameraControls.SetMouseWheelReversedDefault = SetMouseWheelReversedDefault;
|
|
1541
|
+
function GetMouseWheelReversed(viewer) {
|
|
1542
|
+
return mouseOf(viewer).wheelReversed;
|
|
1543
|
+
}
|
|
1544
|
+
CameraControls.GetMouseWheelReversed = GetMouseWheelReversed;
|
|
1480
1545
|
/**
|
|
1481
1546
|
* Marks a tileset as standing in for the globe (Google's photorealistic tiles), so the camera treats it as ground.
|
|
1482
1547
|
*/
|
|
@@ -1486,6 +1551,13 @@ void main()
|
|
|
1486
1551
|
}
|
|
1487
1552
|
}
|
|
1488
1553
|
CameraControls.SetGroundTileset = SetGroundTileset;
|
|
1554
|
+
/**
|
|
1555
|
+
* Whether a tileset was marked as standing in for the globe.
|
|
1556
|
+
*/
|
|
1557
|
+
function IsGroundTileset(tileset) {
|
|
1558
|
+
return Boolean(tileset === null || tileset === void 0 ? void 0 : tileset[GROUND_TILESET_KEY]);
|
|
1559
|
+
}
|
|
1560
|
+
CameraControls.IsGroundTileset = IsGroundTileset;
|
|
1489
1561
|
/**
|
|
1490
1562
|
* Says whether the scene has data underground, which makes the ground easier to push through; null scans for it.
|
|
1491
1563
|
*/
|
|
@@ -1534,11 +1606,67 @@ void main()
|
|
|
1534
1606
|
}
|
|
1535
1607
|
CameraControls.SetModelSpace = SetModelSpace;
|
|
1536
1608
|
})(exports.CameraControls || (exports.CameraControls = {}));
|
|
1609
|
+
/*
|
|
1610
|
+
* The scheme and wheel direction a viewer uses: its own where set, else the app default.
|
|
1611
|
+
*/
|
|
1612
|
+
function mouseOf(viewer) {
|
|
1613
|
+
var _a, _b;
|
|
1614
|
+
const own = viewer === null || viewer === void 0 ? void 0 : viewer[MOUSE_KEY];
|
|
1615
|
+
return {
|
|
1616
|
+
scheme: (_a = own === null || own === void 0 ? void 0 : own.scheme) !== null && _a !== void 0 ? _a : _mouseDefault.scheme,
|
|
1617
|
+
wheelReversed: (_b = own === null || own === void 0 ? void 0 : own.wheelReversed) !== null && _b !== void 0 ? _b : _mouseDefault.wheelReversed
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
/*
|
|
1621
|
+
* A scheme this version knows, or Default for one saved by a newer app or mistyped.
|
|
1622
|
+
*/
|
|
1623
|
+
function knownScheme(scheme) {
|
|
1624
|
+
return Object.values(exports.ECameraMouseScheme).includes(scheme) ? scheme : exports.ECameraMouseScheme.Default;
|
|
1625
|
+
}
|
|
1537
1626
|
function restoreCesiumGestures(state) {
|
|
1538
1627
|
const controller = state.viewer.scene.screenSpaceCameraController;
|
|
1539
1628
|
controller.rotateEventTypes = state.saved.rotateEventTypes;
|
|
1540
1629
|
controller.zoomEventTypes = state.saved.zoomEventTypes;
|
|
1541
1630
|
controller.tiltEventTypes = state.saved.tiltEventTypes;
|
|
1631
|
+
if (state.saved.translateEventTypes !== undefined) {
|
|
1632
|
+
controller.translateEventTypes = state.saved.translateEventTypes;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
/*
|
|
1636
|
+
* Gives CesiumJS's controller its own gestures under the mouse scheme, so the buttons do not swap at the hand-over.
|
|
1637
|
+
*/
|
|
1638
|
+
function applyCesiumGestures(state) {
|
|
1639
|
+
restoreCesiumGestures(state);
|
|
1640
|
+
const scheme = mouseOf(state.viewer).scheme;
|
|
1641
|
+
state.cesiumScheme = scheme;
|
|
1642
|
+
if (scheme === exports.ECameraMouseScheme.Default) {
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
const middle = Cesium.CameraEventType.MIDDLE_DRAG;
|
|
1646
|
+
const shiftMiddle = { eventType: middle, modifier: Cesium.KeyboardEventModifier.SHIFT };
|
|
1647
|
+
const tilt = asEventTypes(state.saved.tiltEventTypes);
|
|
1648
|
+
// A host that moved CesiumJS's middle drag elsewhere has its own mapping, which is left alone.
|
|
1649
|
+
if (!tilt.includes(middle)) {
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
// CesiumJS orbits with tilt and pans with rotate in 3D, or translate in 2D and Columbus view.
|
|
1653
|
+
const orbit = scheme === exports.ECameraMouseScheme.Autodesk ? shiftMiddle : middle;
|
|
1654
|
+
const pan = scheme === exports.ECameraMouseScheme.Autodesk ? middle : shiftMiddle;
|
|
1655
|
+
const controller = state.viewer.scene.screenSpaceCameraController;
|
|
1656
|
+
controller.tiltEventTypes = tilt.map((type) => (type === middle ? orbit : type));
|
|
1657
|
+
controller.rotateEventTypes = [...asEventTypes(state.saved.rotateEventTypes), pan];
|
|
1658
|
+
if (state.saved.translateEventTypes !== undefined) {
|
|
1659
|
+
controller.translateEventTypes = [...asEventTypes(state.saved.translateEventTypes), pan];
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
/*
|
|
1663
|
+
* CesiumJS takes one event type or a list of them; this always gives a list.
|
|
1664
|
+
*/
|
|
1665
|
+
function asEventTypes(types) {
|
|
1666
|
+
if (types == null) {
|
|
1667
|
+
return [];
|
|
1668
|
+
}
|
|
1669
|
+
return Array.isArray(types) ? types : [types];
|
|
1542
1670
|
}
|
|
1543
1671
|
/*
|
|
1544
1672
|
* Decides each frame who has the mouse: these controls near the ground, CesiumJS for planets, orthographic and tracking.
|
|
@@ -1550,6 +1678,9 @@ void main()
|
|
|
1550
1678
|
}
|
|
1551
1679
|
const ours = shouldControl(state);
|
|
1552
1680
|
if (ours === state.ours) {
|
|
1681
|
+
if (!ours && state.cesiumScheme !== mouseOf(viewer).scheme) {
|
|
1682
|
+
applyCesiumGestures(state);
|
|
1683
|
+
}
|
|
1553
1684
|
return;
|
|
1554
1685
|
}
|
|
1555
1686
|
state.ours = ours;
|
|
@@ -1560,7 +1691,7 @@ void main()
|
|
|
1560
1691
|
controller.tiltEventTypes = [Cesium.CameraEventType.PINCH];
|
|
1561
1692
|
}
|
|
1562
1693
|
else {
|
|
1563
|
-
|
|
1694
|
+
applyCesiumGestures(state);
|
|
1564
1695
|
}
|
|
1565
1696
|
}
|
|
1566
1697
|
function shouldControl(state) {
|
|
@@ -1974,9 +2105,18 @@ void main()
|
|
|
1974
2105
|
return Cesium.Cartesian3.dot(toPoint, camera.directionWC) > 0;
|
|
1975
2106
|
}
|
|
1976
2107
|
/*
|
|
1977
|
-
* Picks which gesture a button and its modifiers start
|
|
2108
|
+
* Picks which gesture a button and its modifiers start under the mouse scheme; Default matches CesiumJS's own mapping.
|
|
1978
2109
|
*/
|
|
1979
|
-
function dragKind(e) {
|
|
2110
|
+
function dragKind(e, scheme) {
|
|
2111
|
+
if (scheme === exports.ECameraMouseScheme.Autodesk && e.button === 1) {
|
|
2112
|
+
if (e.shiftKey && e.ctrlKey) {
|
|
2113
|
+
return EDrag.Zoom;
|
|
2114
|
+
}
|
|
2115
|
+
return e.shiftKey ? EDrag.Orbit : EDrag.Pan;
|
|
2116
|
+
}
|
|
2117
|
+
if (scheme === exports.ECameraMouseScheme.SketchUp && e.button === 1) {
|
|
2118
|
+
return e.shiftKey ? EDrag.Pan : EDrag.Orbit;
|
|
2119
|
+
}
|
|
1980
2120
|
if (e.shiftKey) {
|
|
1981
2121
|
// Shift drag looks around, which CesiumJS still handles.
|
|
1982
2122
|
return null;
|
|
@@ -2020,7 +2160,7 @@ void main()
|
|
|
2020
2160
|
return;
|
|
2021
2161
|
}
|
|
2022
2162
|
}
|
|
2023
|
-
const kind = dragKind(e);
|
|
2163
|
+
const kind = dragKind(e, mouseOf(viewer).scheme);
|
|
2024
2164
|
if (!kind || !allows(state, kind)) {
|
|
2025
2165
|
return;
|
|
2026
2166
|
}
|
|
@@ -2216,6 +2356,37 @@ void main()
|
|
|
2216
2356
|
state.zoomFrame = requestAnimationFrame(() => easeZoom(state));
|
|
2217
2357
|
}
|
|
2218
2358
|
}
|
|
2359
|
+
/*
|
|
2360
|
+
* Swaps a wheel event over the scene for one turned round, so wheel forward zooms out when the user asked for that.
|
|
2361
|
+
*/
|
|
2362
|
+
function mirrorWheel(state, e) {
|
|
2363
|
+
const viewer = state.viewer;
|
|
2364
|
+
const canvas = viewer.isDestroyed() ? null : viewer.scene.canvas;
|
|
2365
|
+
if (!canvas || e.target !== canvas || e[MIRRORED_WHEEL_KEY] || !mouseOf(viewer).wheelReversed) {
|
|
2366
|
+
return;
|
|
2367
|
+
}
|
|
2368
|
+
e.stopImmediatePropagation();
|
|
2369
|
+
e.preventDefault();
|
|
2370
|
+
const mirrored = new WheelEvent("wheel", {
|
|
2371
|
+
bubbles: true,
|
|
2372
|
+
cancelable: true,
|
|
2373
|
+
clientX: e.clientX,
|
|
2374
|
+
clientY: e.clientY,
|
|
2375
|
+
screenX: e.screenX,
|
|
2376
|
+
screenY: e.screenY,
|
|
2377
|
+
ctrlKey: e.ctrlKey,
|
|
2378
|
+
shiftKey: e.shiftKey,
|
|
2379
|
+
altKey: e.altKey,
|
|
2380
|
+
metaKey: e.metaKey,
|
|
2381
|
+
buttons: e.buttons,
|
|
2382
|
+
deltaMode: e.deltaMode,
|
|
2383
|
+
deltaX: e.deltaX,
|
|
2384
|
+
deltaY: -e.deltaY,
|
|
2385
|
+
deltaZ: e.deltaZ
|
|
2386
|
+
});
|
|
2387
|
+
mirrored[MIRRORED_WHEEL_KEY] = true;
|
|
2388
|
+
canvas.dispatchEvent(mirrored);
|
|
2389
|
+
}
|
|
2219
2390
|
/*
|
|
2220
2391
|
* Applies part of the outstanding wheel movement each frame, so a notch glides rather than jumps.
|
|
2221
2392
|
*/
|
|
@@ -57558,12 +57729,6 @@ void main()
|
|
|
57558
57729
|
const SKIRT_FRACTION = 0.015;
|
|
57559
57730
|
// Alpha below which a texel counts as no-data and is not drawn at all.
|
|
57560
57731
|
const COVERAGE_CUTOFF = 0.35;
|
|
57561
|
-
// Terrain is sampled on this grid and interpolated between samples.
|
|
57562
|
-
// Per-texel sampling would be hundreds of thousands of lookups for a surface whose own data is far coarser than that.
|
|
57563
|
-
const GROUND_SAMPLES_PER_SIDE = 64;
|
|
57564
|
-
// Terrain detail level the samples are taken at.
|
|
57565
|
-
// Most-detailed would fetch every tile under a parcel that can be a hundred kilometres across.
|
|
57566
|
-
const GROUND_SAMPLE_LEVEL = 11;
|
|
57567
57732
|
// Height window the packed ground texture covers, wide enough for any terrain on Earth.
|
|
57568
57733
|
// Ground samples across the clearance regions rather than the whole extent.
|
|
57569
57734
|
const MASK_GROUND_SAMPLES_PER_SIDE = 128;
|
|
@@ -57571,9 +57736,23 @@ void main()
|
|
|
57571
57736
|
const MASK_GROUND_LEVEL_MAX = 13;
|
|
57572
57737
|
const MASK_GROUND_LEVEL_MIN = 8;
|
|
57573
57738
|
const MASK_GROUND_TILE_BUDGET = 64;
|
|
57739
|
+
// Finest terrain level a ground block is read at, and how many terrain tiles one block may pull.
|
|
57740
|
+
const FINE_GROUND_LEVEL_MAX = 18;
|
|
57741
|
+
const FINE_GROUND_TILE_BUDGET = 16;
|
|
57574
57742
|
// Longest side of the rasterised region mask. The mask decides whether a texel is held up, so it
|
|
57575
57743
|
// wants to be finer than the value raster it is compared against.
|
|
57576
57744
|
const MASK_TEXTURE_MAX_SIDE = 1024;
|
|
57745
|
+
const DEFAULT_DRAPE_LIFT_METRES = 4;
|
|
57746
|
+
const DEFAULT_DRAPE_BAND_METRES = 3;
|
|
57747
|
+
// A ground tileset is measured against the ground raster at this many points around the camera, this far apart.
|
|
57748
|
+
const OFFSET_PROBES_PER_SIDE = 3;
|
|
57749
|
+
const OFFSET_PROBE_SPACING_METRES = 250;
|
|
57750
|
+
// The camera has to move this far before a ground tileset is measured again.
|
|
57751
|
+
const OFFSET_REPROBE_METRES = 1500;
|
|
57752
|
+
// Low percentile of tileset minus ground, so roofs and canopy over a probe do not lift the water.
|
|
57753
|
+
const OFFSET_PERCENTILE = 0.25;
|
|
57754
|
+
const WGS84_A = 6378137.0;
|
|
57755
|
+
const WGS84_E2 = 0.00669437999014;
|
|
57577
57756
|
// Stands in for "no floor" and "no clearance", far below anything the sheet can reach.
|
|
57578
57757
|
const NO_LIMIT_METRES = -1e6;
|
|
57579
57758
|
// Ripple layers to cycle across the field's own repeat.
|
|
@@ -57618,6 +57797,32 @@ void main()
|
|
|
57618
57797
|
const GROUND_MAX_METRES = 9000;
|
|
57619
57798
|
const DEFAULT_LOW_COLOR = { red: 255, green: 255, blue: 255, alpha: 0.12 };
|
|
57620
57799
|
const DEFAULT_HIGH_COLOR = { red: 21, green: 96, blue: 196, alpha: 0.92 };
|
|
57800
|
+
// Decodes the packed ground raster, shared by both shaders.
|
|
57801
|
+
const GROUND_GLSL = `
|
|
57802
|
+
float decodeGround(vec2 uv) {
|
|
57803
|
+
// Channels arrive normalised to 0..1, so they go back to bytes before being reassembled.
|
|
57804
|
+
vec3 bytes = texture(u_groundTexture, uv).rgb * 255.0;
|
|
57805
|
+
float normalised = dot(bytes, vec3(65536.0, 256.0, 1.0)) / 16777215.0;
|
|
57806
|
+
return u_groundRange.x + normalised * (u_groundRange.y - u_groundRange.x);
|
|
57807
|
+
}
|
|
57808
|
+
|
|
57809
|
+
/*
|
|
57810
|
+
* Bilinear by hand, because the height is packed across three channels and hardware filtering would
|
|
57811
|
+
* blend the packing rather than the heights, turning a smooth slope into noise at every texel edge.
|
|
57812
|
+
*/
|
|
57813
|
+
float sampleGround(vec2 uv) {
|
|
57814
|
+
vec2 texel = 1.0 / u_groundSize;
|
|
57815
|
+
vec2 coord = uv * u_groundSize - 0.5;
|
|
57816
|
+
vec2 base = floor(coord);
|
|
57817
|
+
vec2 f = coord - base;
|
|
57818
|
+
vec2 origin = (base + 0.5) * texel;
|
|
57819
|
+
float h00 = decodeGround(origin);
|
|
57820
|
+
float h10 = decodeGround(origin + vec2(texel.x, 0.0));
|
|
57821
|
+
float h01 = decodeGround(origin + vec2(0.0, texel.y));
|
|
57822
|
+
float h11 = decodeGround(origin + texel);
|
|
57823
|
+
return mix(mix(h00, h10, f.x), mix(h01, h11, f.x), f.y);
|
|
57824
|
+
}
|
|
57825
|
+
`;
|
|
57621
57826
|
const VERTEX_SHADER_GLSL300 = `
|
|
57622
57827
|
in vec3 position3DHigh;
|
|
57623
57828
|
in vec3 position3DLow;
|
|
@@ -57652,6 +57857,9 @@ uniform vec2 u_maskGroundSize;
|
|
|
57652
57857
|
uniform vec4 u_extentDegrees;
|
|
57653
57858
|
uniform vec4 u_maskGroundDegrees;
|
|
57654
57859
|
uniform float u_coverageCutoffVertex;
|
|
57860
|
+
uniform float u_drape;
|
|
57861
|
+
uniform float u_drapeLift;
|
|
57862
|
+
uniform float u_groundOffset;
|
|
57655
57863
|
//#water
|
|
57656
57864
|
uniform vec2 u_extentMetres;
|
|
57657
57865
|
uniform vec2 u_waveOrigin;
|
|
@@ -57660,6 +57868,7 @@ uniform vec2 u_waveOrigin;
|
|
|
57660
57868
|
out vec2 v_st;
|
|
57661
57869
|
out float v_value;
|
|
57662
57870
|
out float v_coverage;
|
|
57871
|
+
out vec3 v_eyeEC;
|
|
57663
57872
|
//#water
|
|
57664
57873
|
out vec3 v_positionEC;
|
|
57665
57874
|
out vec3 v_eastEC;
|
|
@@ -57668,30 +57877,7 @@ out vec3 v_upEC;
|
|
|
57668
57877
|
out vec2 v_waveMetres;
|
|
57669
57878
|
//#endwater
|
|
57670
57879
|
|
|
57671
|
-
|
|
57672
|
-
// Channels arrive normalised to 0..1, so they go back to bytes before being reassembled.
|
|
57673
|
-
vec3 packed = texture(u_groundTexture, uv).rgb * 255.0;
|
|
57674
|
-
float normalised = dot(packed, vec3(65536.0, 256.0, 1.0)) / 16777215.0;
|
|
57675
|
-
return u_groundRange.x + normalised * (u_groundRange.y - u_groundRange.x);
|
|
57676
|
-
}
|
|
57677
|
-
|
|
57678
|
-
/*
|
|
57679
|
-
* Bilinear by hand, because the height is packed across three channels and hardware filtering would
|
|
57680
|
-
* blend the packing rather than the heights, turning a smooth slope into noise at every texel edge.
|
|
57681
|
-
*/
|
|
57682
|
-
float sampleGround(vec2 uv) {
|
|
57683
|
-
vec2 texel = 1.0 / u_groundSize;
|
|
57684
|
-
vec2 coord = uv * u_groundSize - 0.5;
|
|
57685
|
-
vec2 base = floor(coord);
|
|
57686
|
-
vec2 f = coord - base;
|
|
57687
|
-
vec2 origin = (base + 0.5) * texel;
|
|
57688
|
-
float h00 = decodeGround(origin);
|
|
57689
|
-
float h10 = decodeGround(origin + vec2(texel.x, 0.0));
|
|
57690
|
-
float h01 = decodeGround(origin + vec2(0.0, texel.y));
|
|
57691
|
-
float h11 = decodeGround(origin + texel);
|
|
57692
|
-
return mix(mix(h00, h10, f.x), mix(h01, h11, f.x), f.y);
|
|
57693
|
-
}
|
|
57694
|
-
|
|
57880
|
+
${GROUND_GLSL}
|
|
57695
57881
|
/*
|
|
57696
57882
|
* Height of the terrain under a point of the surface, read from the region's own ground raster.
|
|
57697
57883
|
*
|
|
@@ -57773,12 +57959,13 @@ void main() {
|
|
|
57773
57959
|
|
|
57774
57960
|
// Value zero sits at the polygon's own altitude, plus the terrain underneath when the polygon
|
|
57775
57961
|
// is following the ground rather than absolutely positioned.
|
|
57776
|
-
float ground = sampleGround(st) * u_groundWeight;
|
|
57962
|
+
float ground = (sampleGround(st) + u_groundOffset) * u_groundWeight;
|
|
57777
57963
|
|
|
57778
57964
|
// Coverage scales the displacement only where it is measured from the terrain, because there a
|
|
57779
57965
|
// zero means the surface sits on the ground.
|
|
57780
57966
|
float coverageScale = mix(1.0, v_coverage, u_groundWeight);
|
|
57781
|
-
|
|
57967
|
+
// Draped, the sheet only has to stand above what is drawn; the fragment paints the drawn surface behind it.
|
|
57968
|
+
float placed = u_baseHeight + ground + metres * coverageScale + u_drapeLift * u_drape;
|
|
57782
57969
|
|
|
57783
57970
|
// Held above whichever is higher, the region's own floor or the terrain under it plus a margin.
|
|
57784
57971
|
// Only inside the region: lifting the whole sheet would raise it over dry land as well.
|
|
@@ -57802,6 +57989,7 @@ void main() {
|
|
|
57802
57989
|
v_waveMetres = st * u_extentMetres - u_waveOrigin;
|
|
57803
57990
|
//#endwater
|
|
57804
57991
|
|
|
57992
|
+
v_eyeEC = (czm_modelViewRelativeToEye * p).xyz;
|
|
57805
57993
|
gl_Position = czm_modelViewProjectionRelativeToEye * p;
|
|
57806
57994
|
}
|
|
57807
57995
|
`;
|
|
@@ -57816,7 +58004,32 @@ uniform float u_valuePacked;
|
|
|
57816
58004
|
uniform float u_valueRange;
|
|
57817
58005
|
uniform float u_exaggeration;
|
|
57818
58006
|
uniform float u_metresPerTexel;
|
|
58007
|
+
uniform float u_valueMin;
|
|
58008
|
+
uniform sampler2D u_groundTexture;
|
|
58009
|
+
uniform vec2 u_groundRange;
|
|
58010
|
+
uniform vec2 u_groundSize;
|
|
58011
|
+
uniform float u_groundWeight;
|
|
58012
|
+
uniform float u_groundOffset;
|
|
58013
|
+
uniform float u_drape;
|
|
58014
|
+
// Metres a drawn surface may stand above the water level and still be painted, below zero to paint whatever is drawn.
|
|
58015
|
+
uniform float u_drapeBand;
|
|
58016
|
+
// The extent centre on the ellipsoid in eye coordinates, with its east, north and up axes.
|
|
58017
|
+
uniform vec3 u_drapeCentreEC;
|
|
58018
|
+
uniform vec3 u_drapeEastEC;
|
|
58019
|
+
uniform vec3 u_drapeNorthEC;
|
|
58020
|
+
uniform vec3 u_drapeUpEC;
|
|
58021
|
+
// Centre longitude and latitude in radians, then the meridian and prime vertical radii of curvature there.
|
|
58022
|
+
uniform vec4 u_drapeGeo;
|
|
58023
|
+
// West, East, North, South in radians.
|
|
58024
|
+
uniform vec4 u_extentRadians;
|
|
58025
|
+
uniform sampler2D u_maskTexture;
|
|
58026
|
+
uniform float u_maskWeight;
|
|
58027
|
+
uniform float u_maskFill;
|
|
58028
|
+
uniform float u_maskFillValue;
|
|
58029
|
+
uniform float u_maskFloor;
|
|
57819
58030
|
//#water
|
|
58031
|
+
uniform vec2 u_extentMetres;
|
|
58032
|
+
uniform vec2 u_waveOrigin;
|
|
57820
58033
|
uniform float u_waterWavelength;
|
|
57821
58034
|
uniform float u_waterAmplitude;
|
|
57822
58035
|
uniform float u_waterReflectivity;
|
|
@@ -57833,6 +58046,7 @@ uniform float u_wavePeriod;
|
|
|
57833
58046
|
in vec2 v_st;
|
|
57834
58047
|
in float v_value;
|
|
57835
58048
|
in float v_coverage;
|
|
58049
|
+
in vec3 v_eyeEC;
|
|
57836
58050
|
//#water
|
|
57837
58051
|
in vec3 v_positionEC;
|
|
57838
58052
|
in vec3 v_eastEC;
|
|
@@ -57854,6 +58068,72 @@ float valueAt(vec2 uv) {
|
|
|
57854
58068
|
return mix(decodeValue(texture(u_valueTextureFrom, uv)), decodeValue(texture(u_valueTexture, uv)), u_valueFade);
|
|
57855
58069
|
}
|
|
57856
58070
|
|
|
58071
|
+
${GROUND_GLSL}
|
|
58072
|
+
|
|
58073
|
+
/*
|
|
58074
|
+
* The opaque surface drawn behind this pixel, or false when none, outside the extent, or above the band.
|
|
58075
|
+
*/
|
|
58076
|
+
bool drawnBehind(out vec2 uv, out float value, out float coverage, out vec3 positionEC) {
|
|
58077
|
+
float depth = czm_unpackDepth(texture(czm_globeDepthTexture, gl_FragCoord.xy / czm_viewport.zw));
|
|
58078
|
+
if (depth <= 0.0 || depth >= 1.0) {
|
|
58079
|
+
return false;
|
|
58080
|
+
}
|
|
58081
|
+
vec4 eye = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth);
|
|
58082
|
+
positionEC = eye.xyz / eye.w;
|
|
58083
|
+
|
|
58084
|
+
// East, north and up metres from the extent centre, small numbers that keep their precision.
|
|
58085
|
+
vec3 offset = positionEC - u_drapeCentreEC;
|
|
58086
|
+
float east = dot(offset, u_drapeEastEC);
|
|
58087
|
+
float north = dot(offset, u_drapeNorthEC);
|
|
58088
|
+
float up = dot(offset, u_drapeUpEC);
|
|
58089
|
+
float latitude = u_drapeGeo.y + north / u_drapeGeo.z;
|
|
58090
|
+
float longitude = u_drapeGeo.x + east / (u_drapeGeo.w * cos(latitude));
|
|
58091
|
+
uv = vec2((longitude - u_extentRadians.x) / (u_extentRadians.y - u_extentRadians.x),
|
|
58092
|
+
(u_extentRadians.z - latitude) / (u_extentRadians.z - u_extentRadians.w));
|
|
58093
|
+
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
|
|
58094
|
+
return false;
|
|
58095
|
+
}
|
|
58096
|
+
|
|
58097
|
+
// Bilinear by hand between texel centres, so cell edges on the ground read as a shoreline, not squares.
|
|
58098
|
+
vec2 coord = uv / u_texelSize - 0.5;
|
|
58099
|
+
vec2 base = floor(coord);
|
|
58100
|
+
vec2 f = coord - base;
|
|
58101
|
+
vec2 origin = (base + 0.5) * u_texelSize;
|
|
58102
|
+
vec2 values = vec2(0.0);
|
|
58103
|
+
vec2 weights = vec2(0.0);
|
|
58104
|
+
for (int i = 0; i < 4; i++) {
|
|
58105
|
+
vec2 step01 = vec2(float(i - (i / 2) * 2), float(i / 2));
|
|
58106
|
+
vec2 at = origin + step01 * u_texelSize;
|
|
58107
|
+
float w = mix(1.0 - f.x, f.x, step01.x) * mix(1.0 - f.y, f.y, step01.y);
|
|
58108
|
+
vec4 texelTo = texture(u_valueTexture, at);
|
|
58109
|
+
vec4 texelFrom = texture(u_valueTextureFrom, at);
|
|
58110
|
+
float a = mix(texelFrom.a, texelTo.a, u_valueFade);
|
|
58111
|
+
// Weighted by coverage too, so a no-data neighbour fades the edge instead of dragging the value to zero.
|
|
58112
|
+
values += vec2(mix(decodeValue(texelFrom), decodeValue(texelTo), u_valueFade) * a, a) * w;
|
|
58113
|
+
weights += vec2(a, 1.0) * w;
|
|
58114
|
+
}
|
|
58115
|
+
value = values.x / max(values.y, 1e-6);
|
|
58116
|
+
coverage = values.y;
|
|
58117
|
+
|
|
58118
|
+
// A region known to be water paints its gaps here too, the same way the vertex shader fills them.
|
|
58119
|
+
float inMask = u_maskWeight * texture(u_maskTexture, uv).a;
|
|
58120
|
+
float hasData = step(u_coverageCutoff, coverage);
|
|
58121
|
+
value = mix(value, mix(u_maskFillValue, max(value, u_maskFillValue), hasData), inMask * u_maskFill);
|
|
58122
|
+
coverage = max(coverage, inMask * u_maskFill);
|
|
58123
|
+
|
|
58124
|
+
if (u_drapeBand >= 0.0) {
|
|
58125
|
+
// The tangent plane falls away from the ellipsoid by distance squared over twice the radius.
|
|
58126
|
+
float height = up + (east * east + north * north) / (2.0 * u_drapeGeo.w);
|
|
58127
|
+
float level = (sampleGround(uv) + u_groundOffset) * u_groundWeight + u_valueMin + value * u_valueRange * u_exaggeration;
|
|
58128
|
+
// Inside a region the water is never below its known floor, so a deck or bank under that floor is still wet.
|
|
58129
|
+
level = mix(level, max(level, u_maskFloor), step(0.5, inMask));
|
|
58130
|
+
if (height - level > u_drapeBand) {
|
|
58131
|
+
return false;
|
|
58132
|
+
}
|
|
58133
|
+
}
|
|
58134
|
+
return true;
|
|
58135
|
+
}
|
|
58136
|
+
|
|
57857
58137
|
//#water
|
|
57858
58138
|
/*
|
|
57859
58139
|
* Slope of the ripple field at a point, in metres of rise per metre travelled.
|
|
@@ -57885,17 +58165,17 @@ ${WATER_WAVES.map((wave, index) => {
|
|
|
57885
58165
|
* The sheet shaded as a water surface: a flat body colour seen through a sun glint and a grazing
|
|
57886
58166
|
* sky reflection, with the ripple field standing in for a geometry it is far too fine to carry.
|
|
57887
58167
|
*/
|
|
57888
|
-
vec4 water(vec3 relief, vec4 color) {
|
|
57889
|
-
float metresPerPixel = czm_metersPerPixel(vec4(
|
|
58168
|
+
vec4 water(vec3 relief, vec4 color, vec3 positionEC, vec2 waveMetres, float coverage) {
|
|
58169
|
+
float metresPerPixel = czm_metersPerPixel(vec4(positionEC, 1.0));
|
|
57890
58170
|
float detail;
|
|
57891
|
-
vec2 slope = rippleSlope(
|
|
58171
|
+
vec2 slope = rippleSlope(waveMetres, metresPerPixel, detail);
|
|
57892
58172
|
|
|
57893
58173
|
// relief arrives normalised, so its horizontal part over its vertical part is the slope it means.
|
|
57894
58174
|
vec2 reliefSlope = relief.xy / max(relief.z, 1e-3);
|
|
57895
58175
|
vec3 local = normalize(vec3(-(slope + reliefSlope), 1.0));
|
|
57896
58176
|
vec3 normalEC = normalize(local.x * v_eastEC + local.y * v_northEC + local.z * v_upEC);
|
|
57897
58177
|
|
|
57898
|
-
vec3 view = normalize(-
|
|
58178
|
+
vec3 view = normalize(-positionEC);
|
|
57899
58179
|
// Drawn with culling off, so the underside of the sheet arrives with its normal pointing away.
|
|
57900
58180
|
normalEC = dot(normalEC, view) < 0.0 ? -normalEC : normalEC;
|
|
57901
58181
|
vec3 sun = normalize(czm_sunDirectionEC);
|
|
@@ -57922,46 +58202,54 @@ vec4 water(vec3 relief, vec4 color) {
|
|
|
57922
58202
|
/*
|
|
57923
58203
|
* The same fog the globe under it is already drawing with.
|
|
57924
58204
|
*/
|
|
57925
|
-
lit = czm_fog(length(
|
|
58205
|
+
lit = czm_fog(length(positionEC), lit, u_waterSky);
|
|
57926
58206
|
|
|
57927
58207
|
// A reflection seen through a half-transparent sheet is not a reflection, so the surface is
|
|
57928
58208
|
// allowed to close up exactly where it is being reflective.
|
|
57929
|
-
float alpha = color.a *
|
|
58209
|
+
float alpha = color.a * coverage;
|
|
57930
58210
|
alpha = clamp(alpha + (1.0 - alpha) * (fresnel * 0.55 + glint), 0.0, 1.0);
|
|
57931
58211
|
return vec4(lit, alpha);
|
|
57932
58212
|
}
|
|
57933
58213
|
//#endwater
|
|
57934
58214
|
|
|
57935
58215
|
void main() {
|
|
57936
|
-
|
|
58216
|
+
vec2 uv = v_st;
|
|
58217
|
+
float value = v_value;
|
|
58218
|
+
float coverage = v_coverage;
|
|
58219
|
+
vec3 positionEC = v_eyeEC;
|
|
58220
|
+
// Clamped: paint what is drawn behind this pixel, so the water sits on it however far off the sheet is.
|
|
58221
|
+
if (u_drape > 0.5 && !drawnBehind(uv, value, coverage, positionEC)) {
|
|
58222
|
+
discard;
|
|
58223
|
+
}
|
|
58224
|
+
if (coverage < u_coverageCutoff) {
|
|
57937
58225
|
discard;
|
|
57938
58226
|
}
|
|
57939
58227
|
// The ramp is baked to a lookup rather than lerped between two colours, so a banded style with a
|
|
57940
58228
|
// hidden floor reads the same here as it does on the flat drape.
|
|
57941
58229
|
// Without it this surface painted water the style hides, and the cell grid then correctly refused to outline any of it.
|
|
57942
|
-
vec4 color = texture(u_rampTexture, vec2(clamp(
|
|
58230
|
+
vec4 color = texture(u_rampTexture, vec2(clamp(value, 0.0, 1.0), 0.5));
|
|
57943
58231
|
if (color.a <= 0.0) {
|
|
57944
58232
|
discard;
|
|
57945
58233
|
}
|
|
57946
58234
|
|
|
57947
58235
|
// Relief shading from the value gradient, so the displacement reads at a distance without
|
|
57948
58236
|
// recomputing vertex normals every time the texture changes.
|
|
57949
|
-
float left = valueAt(
|
|
57950
|
-
float right = valueAt(
|
|
57951
|
-
float down = valueAt(
|
|
57952
|
-
float up = valueAt(
|
|
58237
|
+
float left = valueAt(uv - vec2(u_texelSize.x, 0.0));
|
|
58238
|
+
float right = valueAt(uv + vec2(u_texelSize.x, 0.0));
|
|
58239
|
+
float down = valueAt(uv - vec2(0.0, u_texelSize.y));
|
|
58240
|
+
float up = valueAt(uv + vec2(0.0, u_texelSize.y));
|
|
57953
58241
|
float scale = u_valueRange * u_exaggeration;
|
|
57954
58242
|
vec3 n = normalize(vec3((left - right) * scale, (down - up) * scale, 2.0 * u_metresPerTexel));
|
|
57955
58243
|
|
|
57956
58244
|
//#water
|
|
57957
|
-
out_FragColor = water(n, color);
|
|
58245
|
+
out_FragColor = water(n, color, positionEC, mix(v_waveMetres, uv * u_extentMetres - u_waveOrigin, u_drape), coverage);
|
|
57958
58246
|
return;
|
|
57959
58247
|
//#endwater
|
|
57960
58248
|
|
|
57961
58249
|
float lambert = clamp(dot(n, normalize(vec3(-0.5, -0.6, 0.62))), 0.0, 1.0);
|
|
57962
58250
|
color.rgb *= 0.45 + 0.9 * lambert;
|
|
57963
58251
|
|
|
57964
|
-
out_FragColor = vec4(color.rgb, color.a *
|
|
58252
|
+
out_FragColor = vec4(color.rgb, color.a * coverage);
|
|
57965
58253
|
}
|
|
57966
58254
|
`;
|
|
57967
58255
|
/*
|
|
@@ -58007,9 +58295,25 @@ void main() {
|
|
|
58007
58295
|
// No probe means no evidence the host rewrites anything, so trust the context alone.
|
|
58008
58296
|
modernizes = false;
|
|
58009
58297
|
}
|
|
58010
|
-
_glsl300Support =
|
|
58298
|
+
_glsl300Support = context.webgl2 ? !modernizes : demotes(context);
|
|
58011
58299
|
return _glsl300Support;
|
|
58012
58300
|
}
|
|
58301
|
+
/*
|
|
58302
|
+
* True when the host takes GLSL 300 and rewrites it down itself on a WebGL1 context, as Cesium 1.102 onwards does.
|
|
58303
|
+
*/
|
|
58304
|
+
function demotes(context) {
|
|
58305
|
+
try {
|
|
58306
|
+
const probe = new Cesium.ShaderSource({
|
|
58307
|
+
sources: ["in float a_probe;\nout float v_probe;\nvoid main() { v_probe = a_probe; gl_Position = vec4(0.0); }"],
|
|
58308
|
+
includeBuiltIns: false
|
|
58309
|
+
});
|
|
58310
|
+
const combined = probe.createCombinedVertexShader(context);
|
|
58311
|
+
return combined.indexOf("attribute") >= 0;
|
|
58312
|
+
}
|
|
58313
|
+
catch (e) {
|
|
58314
|
+
return false;
|
|
58315
|
+
}
|
|
58316
|
+
}
|
|
58013
58317
|
/*
|
|
58014
58318
|
* Places grid node (fx, fy) on the ellipsoid, stepping the way the raster was sampled.
|
|
58015
58319
|
* A raster sampled at lon/lat has to be walked in degrees; one sampled linearly across a projected CRS has to be walked in tangent-plane metres.
|
|
@@ -58291,9 +58595,334 @@ void main() {
|
|
|
58291
58595
|
}
|
|
58292
58596
|
return MASK_GROUND_LEVEL_MIN;
|
|
58293
58597
|
}
|
|
58598
|
+
// Ground under a clamped value surface: coarse everywhere first, then refined block by block nearest the camera.
|
|
58599
|
+
let GroundRaster;
|
|
58600
|
+
(function (GroundRaster) {
|
|
58601
|
+
// Height window the packed raster covers, wide enough for any terrain on Earth.
|
|
58602
|
+
GroundRaster.MIN_METRES = -1000;
|
|
58603
|
+
GroundRaster.MAX_METRES = 9000;
|
|
58604
|
+
const PACKED_MAX = 16777215;
|
|
58605
|
+
// Samples per side of the first pass over the whole extent.
|
|
58606
|
+
const COARSE_SAMPLES = 64;
|
|
58607
|
+
// Samples per side of one refined block.
|
|
58608
|
+
GroundRaster.BLOCK_SAMPLES = 64;
|
|
58609
|
+
const MAX_SIDE = 2048;
|
|
58610
|
+
// Blocks being sampled at once, so a fast camera does not queue the whole model.
|
|
58611
|
+
const MAX_IN_FLIGHT = 2;
|
|
58612
|
+
// A block is refined once the camera is within this many block widths of it.
|
|
58613
|
+
const REFINE_BLOCK_WIDTHS = 12;
|
|
58614
|
+
/**
|
|
58615
|
+
* Raster side for a value source of the given size: a whole number of blocks, at least one, at most the cap.
|
|
58616
|
+
*/
|
|
58617
|
+
function SideFor(width, height) {
|
|
58618
|
+
const wanted = Math.max(1, Math.round(Math.max(width || 0, height || 0)));
|
|
58619
|
+
const blocks = Math.ceil(wanted / GroundRaster.BLOCK_SAMPLES);
|
|
58620
|
+
return Math.min(MAX_SIDE, Math.max(1, blocks) * GroundRaster.BLOCK_SAMPLES);
|
|
58621
|
+
}
|
|
58622
|
+
GroundRaster.SideFor = SideFor;
|
|
58623
|
+
/**
|
|
58624
|
+
* Packs a height into three bytes the way the vertex shader unpacks it.
|
|
58625
|
+
*/
|
|
58626
|
+
function Pack(height, into, at) {
|
|
58627
|
+
const known = typeof height === "number" && isFinite(height);
|
|
58628
|
+
const clamped = Math.min(GroundRaster.MAX_METRES, Math.max(GroundRaster.MIN_METRES, known ? height : 0));
|
|
58629
|
+
const packed = Math.round(((clamped - GroundRaster.MIN_METRES) / (GroundRaster.MAX_METRES - GroundRaster.MIN_METRES)) * PACKED_MAX);
|
|
58630
|
+
into[at] = (packed >> 16) & 255;
|
|
58631
|
+
into[at + 1] = (packed >> 8) & 255;
|
|
58632
|
+
into[at + 2] = packed & 255;
|
|
58633
|
+
into[at + 3] = known ? 255 : 0;
|
|
58634
|
+
}
|
|
58635
|
+
GroundRaster.Pack = Pack;
|
|
58636
|
+
/**
|
|
58637
|
+
* Bilinear between texel centres, the way the shader reads it.
|
|
58638
|
+
*/
|
|
58639
|
+
function Bilinear(heights, side, u, v) {
|
|
58640
|
+
const read = (x, y) => heights[Math.min(side - 1, Math.max(0, y)) * side + Math.min(side - 1, Math.max(0, x))];
|
|
58641
|
+
const x = u * side - 0.5;
|
|
58642
|
+
const y = v * side - 0.5;
|
|
58643
|
+
const x0 = Math.floor(x);
|
|
58644
|
+
const y0 = Math.floor(y);
|
|
58645
|
+
const fx = x - x0;
|
|
58646
|
+
const fy = y - y0;
|
|
58647
|
+
const top = read(x0, y0) + (read(x0 + 1, y0) - read(x0, y0)) * fx;
|
|
58648
|
+
const bottom = read(x0, y0 + 1) + (read(x0 + 1, y0 + 1) - read(x0, y0 + 1)) * fx;
|
|
58649
|
+
return top + (bottom - top) * fy;
|
|
58650
|
+
}
|
|
58651
|
+
GroundRaster.Bilinear = Bilinear;
|
|
58652
|
+
class Raster {
|
|
58653
|
+
constructor(extent, side, sampler) {
|
|
58654
|
+
this.extent = extent;
|
|
58655
|
+
this.sampler = sampler;
|
|
58656
|
+
this.inFlight = new Set();
|
|
58657
|
+
this.dirty = [];
|
|
58658
|
+
this.coarseDone = false;
|
|
58659
|
+
this.coarseStarted = false;
|
|
58660
|
+
this.disposed = false;
|
|
58661
|
+
this.version = 0;
|
|
58662
|
+
this.side = Math.max(GroundRaster.BLOCK_SAMPLES, Math.round(side / GroundRaster.BLOCK_SAMPLES) * GroundRaster.BLOCK_SAMPLES);
|
|
58663
|
+
this.blocksPerSide = this.side / GroundRaster.BLOCK_SAMPLES;
|
|
58664
|
+
this.pixels = new Uint8Array(this.side * this.side * 4);
|
|
58665
|
+
this.heights = new Float32Array(this.side * this.side);
|
|
58666
|
+
this.refined = new Uint8Array(this.blocksPerSide * this.blocksPerSide);
|
|
58667
|
+
}
|
|
58668
|
+
Dispose() {
|
|
58669
|
+
this.disposed = true;
|
|
58670
|
+
}
|
|
58671
|
+
HasCoarse() {
|
|
58672
|
+
return this.coarseDone;
|
|
58673
|
+
}
|
|
58674
|
+
/**
|
|
58675
|
+
* Changes whenever any height changes.
|
|
58676
|
+
*/
|
|
58677
|
+
GetVersion() {
|
|
58678
|
+
return this.version;
|
|
58679
|
+
}
|
|
58680
|
+
RefinedCount() {
|
|
58681
|
+
return this.refined.reduce((sum, value) => sum + value, 0);
|
|
58682
|
+
}
|
|
58683
|
+
InFlightCount() {
|
|
58684
|
+
return this.inFlight.size;
|
|
58685
|
+
}
|
|
58686
|
+
/**
|
|
58687
|
+
* Metres above the ellipsoid at a normalised point, north at v zero.
|
|
58688
|
+
*/
|
|
58689
|
+
HeightAt(u, v) {
|
|
58690
|
+
return Bilinear(this.heights, this.side, u, v);
|
|
58691
|
+
}
|
|
58692
|
+
/**
|
|
58693
|
+
* The regions changed since the last call.
|
|
58694
|
+
*/
|
|
58695
|
+
TakeDirty() {
|
|
58696
|
+
const dirty = this.dirty;
|
|
58697
|
+
this.dirty = [];
|
|
58698
|
+
return dirty;
|
|
58699
|
+
}
|
|
58700
|
+
/**
|
|
58701
|
+
* Samples the whole extent once, at the cheap level.
|
|
58702
|
+
*/
|
|
58703
|
+
StartCoarse() {
|
|
58704
|
+
if (this.coarseStarted) {
|
|
58705
|
+
return Promise.resolve();
|
|
58706
|
+
}
|
|
58707
|
+
this.coarseStarted = true;
|
|
58708
|
+
const positions = this.grid(0, 0, 1, 1, COARSE_SAMPLES);
|
|
58709
|
+
return this.sampler.coarse(positions)
|
|
58710
|
+
.then((heights) => {
|
|
58711
|
+
if (this.disposed) {
|
|
58712
|
+
return;
|
|
58713
|
+
}
|
|
58714
|
+
const coarse = new Float32Array(COARSE_SAMPLES * COARSE_SAMPLES);
|
|
58715
|
+
for (let i = 0; i < coarse.length; i++) {
|
|
58716
|
+
const h = heights[i];
|
|
58717
|
+
coarse[i] = typeof h === "number" && isFinite(h) ? h : 0;
|
|
58718
|
+
}
|
|
58719
|
+
for (let y = 0; y < this.side; y++) {
|
|
58720
|
+
for (let x = 0; x < this.side; x++) {
|
|
58721
|
+
this.write(x, y, Bilinear(coarse, COARSE_SAMPLES, (x + 0.5) / this.side, (y + 0.5) / this.side));
|
|
58722
|
+
}
|
|
58723
|
+
}
|
|
58724
|
+
this.coarseDone = true;
|
|
58725
|
+
this.markDirty(0, 0, this.side, this.side);
|
|
58726
|
+
})
|
|
58727
|
+
.catch(() => {
|
|
58728
|
+
// Terrain that cannot be sampled leaves the sheet at its base height.
|
|
58729
|
+
});
|
|
58730
|
+
}
|
|
58731
|
+
/*
|
|
58732
|
+
* Starts sampling the unrefined visible blocks nearest the eye (world coordinates), up to the cap.
|
|
58733
|
+
*/
|
|
58734
|
+
Refine(eye, isVisible) {
|
|
58735
|
+
if (!this.coarseDone || this.disposed || this.inFlight.size >= MAX_IN_FLIGHT) {
|
|
58736
|
+
return 0;
|
|
58737
|
+
}
|
|
58738
|
+
const candidates = [];
|
|
58739
|
+
const blockMetres = this.blockMetres();
|
|
58740
|
+
for (let by = 0; by < this.blocksPerSide; by++) {
|
|
58741
|
+
for (let bx = 0; bx < this.blocksPerSide; bx++) {
|
|
58742
|
+
const index = by * this.blocksPerSide + bx;
|
|
58743
|
+
if (this.refined[index] || this.inFlight.has(index)) {
|
|
58744
|
+
continue;
|
|
58745
|
+
}
|
|
58746
|
+
const sphere = this.blockSphere(bx, by, blockMetres);
|
|
58747
|
+
const distance = Math.max(0, Cesium.Cartesian3.distance(eye, sphere.center) - sphere.radius);
|
|
58748
|
+
if (distance > blockMetres * REFINE_BLOCK_WIDTHS) {
|
|
58749
|
+
continue;
|
|
58750
|
+
}
|
|
58751
|
+
if (isVisible && !isVisible(sphere)) {
|
|
58752
|
+
continue;
|
|
58753
|
+
}
|
|
58754
|
+
candidates.push({ index, distance });
|
|
58755
|
+
}
|
|
58756
|
+
}
|
|
58757
|
+
candidates.sort((a, b) => a.distance - b.distance);
|
|
58758
|
+
let started = 0;
|
|
58759
|
+
for (const candidate of candidates) {
|
|
58760
|
+
if (this.inFlight.size >= MAX_IN_FLIGHT) {
|
|
58761
|
+
break;
|
|
58762
|
+
}
|
|
58763
|
+
this.refineBlock(candidate.index);
|
|
58764
|
+
started++;
|
|
58765
|
+
}
|
|
58766
|
+
return started;
|
|
58767
|
+
}
|
|
58768
|
+
refineBlock(index) {
|
|
58769
|
+
this.inFlight.add(index);
|
|
58770
|
+
const bx = index % this.blocksPerSide;
|
|
58771
|
+
const by = Math.floor(index / this.blocksPerSide);
|
|
58772
|
+
const u0 = bx / this.blocksPerSide;
|
|
58773
|
+
const v0 = by / this.blocksPerSide;
|
|
58774
|
+
const span = 1 / this.blocksPerSide;
|
|
58775
|
+
const positions = this.grid(u0, v0, span, span, GroundRaster.BLOCK_SAMPLES);
|
|
58776
|
+
const e = this.extent;
|
|
58777
|
+
const box = {
|
|
58778
|
+
West: Cesium.Math.lerp(e.West, e.East, u0),
|
|
58779
|
+
East: Cesium.Math.lerp(e.West, e.East, u0 + span),
|
|
58780
|
+
North: Cesium.Math.lerp(e.North, e.South, v0),
|
|
58781
|
+
South: Cesium.Math.lerp(e.North, e.South, v0 + span)
|
|
58782
|
+
};
|
|
58783
|
+
this.sampler.fine(positions, box)
|
|
58784
|
+
.then((heights) => {
|
|
58785
|
+
if (this.disposed) {
|
|
58786
|
+
return;
|
|
58787
|
+
}
|
|
58788
|
+
for (let row = 0; row < GroundRaster.BLOCK_SAMPLES; row++) {
|
|
58789
|
+
for (let col = 0; col < GroundRaster.BLOCK_SAMPLES; col++) {
|
|
58790
|
+
const h = heights[row * GroundRaster.BLOCK_SAMPLES + col];
|
|
58791
|
+
// Keeping the coarse height where the source has nothing finer.
|
|
58792
|
+
if (typeof h === "number" && isFinite(h)) {
|
|
58793
|
+
this.write(bx * GroundRaster.BLOCK_SAMPLES + col, by * GroundRaster.BLOCK_SAMPLES + row, h);
|
|
58794
|
+
}
|
|
58795
|
+
}
|
|
58796
|
+
}
|
|
58797
|
+
this.markDirty(bx * GroundRaster.BLOCK_SAMPLES, by * GroundRaster.BLOCK_SAMPLES, GroundRaster.BLOCK_SAMPLES, GroundRaster.BLOCK_SAMPLES);
|
|
58798
|
+
})
|
|
58799
|
+
.catch(() => {
|
|
58800
|
+
// A block that cannot be sampled keeps its coarse heights.
|
|
58801
|
+
})
|
|
58802
|
+
.then(() => {
|
|
58803
|
+
this.refined[index] = 1;
|
|
58804
|
+
this.inFlight.delete(index);
|
|
58805
|
+
});
|
|
58806
|
+
}
|
|
58807
|
+
/*
|
|
58808
|
+
* Positions at texel centres of a sub-box, given in normalised extent coordinates, north at v zero.
|
|
58809
|
+
*/
|
|
58810
|
+
grid(u0, v0, uSpan, vSpan, samples) {
|
|
58811
|
+
const positions = [];
|
|
58812
|
+
const e = this.extent;
|
|
58813
|
+
for (let row = 0; row < samples; row++) {
|
|
58814
|
+
const v = v0 + vSpan * (row + 0.5) / samples;
|
|
58815
|
+
const latitude = Cesium.Math.lerp(e.North, e.South, v);
|
|
58816
|
+
for (let col = 0; col < samples; col++) {
|
|
58817
|
+
const u = u0 + uSpan * (col + 0.5) / samples;
|
|
58818
|
+
positions.push(Cesium.Cartographic.fromDegrees(Cesium.Math.lerp(e.West, e.East, u), latitude));
|
|
58819
|
+
}
|
|
58820
|
+
}
|
|
58821
|
+
return positions;
|
|
58822
|
+
}
|
|
58823
|
+
write(x, y, height) {
|
|
58824
|
+
const at = y * this.side + x;
|
|
58825
|
+
this.heights[at] = height;
|
|
58826
|
+
Pack(height, this.pixels, at * 4);
|
|
58827
|
+
}
|
|
58828
|
+
markDirty(x, y, width, height) {
|
|
58829
|
+
this.dirty.push({ x, y, width, height });
|
|
58830
|
+
this.version++;
|
|
58831
|
+
}
|
|
58832
|
+
blockMetres() {
|
|
58833
|
+
const e = this.extent;
|
|
58834
|
+
const midLat = (e.North + e.South) / 2;
|
|
58835
|
+
const west = Cesium.Cartesian3.fromDegrees(e.West, midLat);
|
|
58836
|
+
const east = Cesium.Cartesian3.fromDegrees(e.East, midLat);
|
|
58837
|
+
const south = Cesium.Cartesian3.fromDegrees(e.West, e.South);
|
|
58838
|
+
const north = Cesium.Cartesian3.fromDegrees(e.West, e.North);
|
|
58839
|
+
const across = Math.max(Cesium.Cartesian3.distance(west, east), Cesium.Cartesian3.distance(south, north));
|
|
58840
|
+
return across / this.blocksPerSide;
|
|
58841
|
+
}
|
|
58842
|
+
blockSphere(bx, by, blockMetres) {
|
|
58843
|
+
const e = this.extent;
|
|
58844
|
+
const u = (bx + 0.5) / this.blocksPerSide;
|
|
58845
|
+
const v = (by + 0.5) / this.blocksPerSide;
|
|
58846
|
+
const centre = Cesium.Cartesian3.fromDegrees(Cesium.Math.lerp(e.West, e.East, u), Cesium.Math.lerp(e.North, e.South, v), this.HeightAt(u, v));
|
|
58847
|
+
return new Cesium.BoundingSphere(centre, blockMetres * Math.SQRT1_2);
|
|
58848
|
+
}
|
|
58849
|
+
}
|
|
58850
|
+
GroundRaster.Raster = Raster;
|
|
58851
|
+
})(GroundRaster = DisplacedSurfacePrimitive.GroundRaster || (DisplacedSurfacePrimitive.GroundRaster = {}));
|
|
58852
|
+
/**
|
|
58853
|
+
* Drawn ground minus sampled ground: a low percentile, so roofs and canopy over a probe are ignored.
|
|
58854
|
+
*/
|
|
58855
|
+
function GroundOffsetFrom(differences) {
|
|
58856
|
+
const known = differences.filter((d) => typeof d === "number" && isFinite(d)).sort((a, b) => a - b);
|
|
58857
|
+
if (!known.length) {
|
|
58858
|
+
return null;
|
|
58859
|
+
}
|
|
58860
|
+
return known[Math.floor(OFFSET_PERCENTILE * (known.length - 1))];
|
|
58861
|
+
}
|
|
58862
|
+
DisplacedSurfacePrimitive.GroundOffsetFrom = GroundOffsetFrom;
|
|
58863
|
+
/*
|
|
58864
|
+
* The first shown tileset standing in for the globe, such as Google's photorealistic tiles.
|
|
58865
|
+
*/
|
|
58866
|
+
function findGroundTileset(collection) {
|
|
58867
|
+
if (!collection) {
|
|
58868
|
+
return null;
|
|
58869
|
+
}
|
|
58870
|
+
for (let i = 0; i < collection.length; i++) {
|
|
58871
|
+
const primitive = collection.get(i);
|
|
58872
|
+
if (!primitive || primitive.show === false) {
|
|
58873
|
+
continue;
|
|
58874
|
+
}
|
|
58875
|
+
if (typeof primitive.length === "number" && typeof primitive.get === "function") {
|
|
58876
|
+
const nested = findGroundTileset(primitive);
|
|
58877
|
+
if (nested) {
|
|
58878
|
+
return nested;
|
|
58879
|
+
}
|
|
58880
|
+
}
|
|
58881
|
+
else if (exports.CameraControls.IsGroundTileset(primitive)) {
|
|
58882
|
+
return primitive;
|
|
58883
|
+
}
|
|
58884
|
+
}
|
|
58885
|
+
return null;
|
|
58886
|
+
}
|
|
58887
|
+
/*
|
|
58888
|
+
* The finest level a ground block can be sampled at within a few tiles, and no finer than the terrain has there.
|
|
58889
|
+
*/
|
|
58890
|
+
function fineLevelFor(box, provider) {
|
|
58891
|
+
const scheme = provider && provider.tilingScheme;
|
|
58892
|
+
let available = FINE_GROUND_LEVEL_MAX;
|
|
58893
|
+
const availability = provider && provider.availability;
|
|
58894
|
+
if (availability && typeof availability.computeMaximumLevelAtPosition === "function") {
|
|
58895
|
+
const centre = Cesium.Cartographic.fromDegrees((box.West + box.East) / 2, (box.North + box.South) / 2);
|
|
58896
|
+
available = Math.min(available, availability.computeMaximumLevelAtPosition(centre));
|
|
58897
|
+
}
|
|
58898
|
+
for (let level = available; level > MASK_GROUND_LEVEL_MIN; level--) {
|
|
58899
|
+
const across = scheme && typeof scheme.getNumberOfXTilesAtLevel === "function"
|
|
58900
|
+
? scheme.getNumberOfXTilesAtLevel(level)
|
|
58901
|
+
: Math.pow(2, level + 1);
|
|
58902
|
+
const down = scheme && typeof scheme.getNumberOfYTilesAtLevel === "function"
|
|
58903
|
+
? scheme.getNumberOfYTilesAtLevel(level)
|
|
58904
|
+
: Math.pow(2, level);
|
|
58905
|
+
const tiles = Math.ceil((box.East - box.West) / (360 / across) + 1)
|
|
58906
|
+
* Math.ceil((box.North - box.South) / (180 / down) + 1);
|
|
58907
|
+
if (tiles <= FINE_GROUND_TILE_BUDGET) {
|
|
58908
|
+
return level;
|
|
58909
|
+
}
|
|
58910
|
+
}
|
|
58911
|
+
return MASK_GROUND_LEVEL_MIN;
|
|
58912
|
+
}
|
|
58913
|
+
/*
|
|
58914
|
+
* Heights for a ground raster from a terrain provider: a cheap level first, then the finest in budget per block.
|
|
58915
|
+
*/
|
|
58916
|
+
function terrainSampler(provider, extent) {
|
|
58917
|
+
const heightsOf = (sampled) => (sampled || []).map((c) => (c && isFinite(c.height) ? c.height : undefined));
|
|
58918
|
+
return {
|
|
58919
|
+
coarse: (positions) => Promise.resolve(Cesium.sampleTerrain(provider, groundLevelFor(extent, provider), positions)).then(heightsOf),
|
|
58920
|
+
fine: (positions, box) => Promise.resolve(Cesium.sampleTerrain(provider, fineLevelFor(box, provider), positions)).then(heightsOf)
|
|
58921
|
+
};
|
|
58922
|
+
}
|
|
58294
58923
|
class Surface {
|
|
58295
58924
|
constructor(options, hasCoverage) {
|
|
58296
|
-
var _a, _b, _c, _d;
|
|
58925
|
+
var _a, _b, _c, _d, _e, _f;
|
|
58297
58926
|
this.show = true;
|
|
58298
58927
|
this.valueSource = null;
|
|
58299
58928
|
this.lastPresentVersion = -1;
|
|
@@ -58314,9 +58943,22 @@ void main() {
|
|
|
58314
58943
|
this.lastEyePosition = null;
|
|
58315
58944
|
this.lastSelectionMs = -Infinity;
|
|
58316
58945
|
this.selectionDirty = true;
|
|
58946
|
+
this.groundRaster = null;
|
|
58947
|
+
this.groundTextureSide = 0;
|
|
58948
|
+
// Draping reads globe coordinates back from depth, true only in 3D; 2D and Columbus keep the raised sheet.
|
|
58949
|
+
this.drapeActive = false;
|
|
58950
|
+
// Drawn ground minus the ground raster, measured where a ground tileset such as Google's is shown.
|
|
58951
|
+
this.groundOffset = 0;
|
|
58952
|
+
this.offsetProbe = { at: null, busy: false };
|
|
58953
|
+
this.drapeFrame = {
|
|
58954
|
+
centreEC: new Cesium.Cartesian3(),
|
|
58955
|
+
eastEC: new Cesium.Cartesian3(),
|
|
58956
|
+
northEC: new Cesium.Cartesian3(),
|
|
58957
|
+
upEC: new Cesium.Cartesian3(),
|
|
58958
|
+
geo: new Cesium.Cartesian4(),
|
|
58959
|
+
extent: new Cesium.Cartesian4()
|
|
58960
|
+
};
|
|
58317
58961
|
this.groundTexture = null;
|
|
58318
|
-
this.groundPixels = null;
|
|
58319
|
-
this.groundRequested = false;
|
|
58320
58962
|
this.groundClearance = null;
|
|
58321
58963
|
this.maskTexture = null;
|
|
58322
58964
|
this.maskPixels = null;
|
|
@@ -58333,13 +58975,18 @@ void main() {
|
|
|
58333
58975
|
this.wavePhaseScratch = [new Cesium.Cartesian4(), new Cesium.Cartesian4()];
|
|
58334
58976
|
this.waterSkyScratch = new Cesium.Cartesian3();
|
|
58335
58977
|
this.followGround = Boolean(options.followGround);
|
|
58978
|
+
this.groundRasterSide = options.groundRasterSide;
|
|
58979
|
+
this.scene = options.scene || null;
|
|
58980
|
+
this.drape = Boolean(options.followGround) && options.drape !== false;
|
|
58981
|
+
this.drapeLift = (_a = options.drapeLift) !== null && _a !== void 0 ? _a : DEFAULT_DRAPE_LIFT_METRES;
|
|
58982
|
+
this.drapeBand = (_b = options.drapeBand) !== null && _b !== void 0 ? _b : DEFAULT_DRAPE_BAND_METRES;
|
|
58336
58983
|
this.terrainProvider = options.terrainProvider || null;
|
|
58337
58984
|
this.extent = options.extent;
|
|
58338
58985
|
this.source = options.source || null;
|
|
58339
|
-
this.valueMin = (
|
|
58340
|
-
this.valueMax = (
|
|
58341
|
-
this.exaggeration = (
|
|
58342
|
-
this.baseHeight = (
|
|
58986
|
+
this.valueMin = (_c = options.valueMin) !== null && _c !== void 0 ? _c : 0;
|
|
58987
|
+
this.valueMax = (_d = options.valueMax) !== null && _d !== void 0 ? _d : 1;
|
|
58988
|
+
this.exaggeration = (_e = options.exaggeration) !== null && _e !== void 0 ? _e : 1;
|
|
58989
|
+
this.baseHeight = (_f = options.baseHeight) !== null && _f !== void 0 ? _f : 0;
|
|
58343
58990
|
this.packedValue = Boolean(options.packedValue);
|
|
58344
58991
|
this.pixelPlacement = options.pixelPlacement;
|
|
58345
58992
|
this.tileSkirts = Boolean(options.tileSkirts);
|
|
@@ -58444,8 +59091,9 @@ void main() {
|
|
|
58444
59091
|
return;
|
|
58445
59092
|
}
|
|
58446
59093
|
this.terrainProvider = provider;
|
|
58447
|
-
this.
|
|
58448
|
-
this.
|
|
59094
|
+
this.dropGroundRaster();
|
|
59095
|
+
this.groundOffset = 0;
|
|
59096
|
+
this.offsetProbe = { at: null, busy: false };
|
|
58449
59097
|
this.maskGroundPixels = null;
|
|
58450
59098
|
this.maskGroundRequested = false;
|
|
58451
59099
|
this.maskGroundLevel = 0;
|
|
@@ -58499,15 +59147,15 @@ void main() {
|
|
|
58499
59147
|
? (pixels[at] * 256 + pixels[at + 1]) / 65535
|
|
58500
59148
|
: pixels[at] / 255;
|
|
58501
59149
|
const metres = this.valueMin + normalised * (this.valueMax - this.valueMin) * this.exaggeration;
|
|
58502
|
-
const following = this.
|
|
58503
|
-
const ground = following ? this.
|
|
59150
|
+
const following = this.hasGround();
|
|
59151
|
+
const ground = following ? this.groundRaster.HeightAt(fx, fy) + this.groundOffset : 0;
|
|
58504
59152
|
return this.baseHeight + ground + metres * (following ? coverage : 1);
|
|
58505
59153
|
}
|
|
58506
59154
|
/**
|
|
58507
59155
|
* Changes whenever HeightAt would answer differently for the same frame.
|
|
58508
59156
|
*/
|
|
58509
59157
|
GetPlacementKey() {
|
|
58510
|
-
return [this.
|
|
59158
|
+
return [this.groundRaster ? this.groundRaster.GetVersion() : 0, this.baseHeight, this.exaggeration, this.followGround ? 1 : 0].join("|");
|
|
58511
59159
|
}
|
|
58512
59160
|
/**
|
|
58513
59161
|
* Repaints the sheet with new colours, keeping its geometry and the frames it is reading.
|
|
@@ -58533,25 +59181,19 @@ void main() {
|
|
|
58533
59181
|
return this.rampPixels;
|
|
58534
59182
|
}
|
|
58535
59183
|
/*
|
|
58536
|
-
*
|
|
58537
|
-
*/
|
|
58538
|
-
|
|
58539
|
-
|
|
58540
|
-
|
|
58541
|
-
|
|
58542
|
-
|
|
58543
|
-
|
|
58544
|
-
|
|
58545
|
-
|
|
58546
|
-
|
|
58547
|
-
|
|
58548
|
-
|
|
58549
|
-
const y0 = Math.floor(y);
|
|
58550
|
-
const fx = x - x0;
|
|
58551
|
-
const fy = y - y0;
|
|
58552
|
-
const top = read(x0, y0) + (read(x0 + 1, y0) - read(x0, y0)) * fx;
|
|
58553
|
-
const bottom = read(x0, y0 + 1) + (read(x0 + 1, y0 + 1) - read(x0, y0 + 1)) * fx;
|
|
58554
|
-
return top + (bottom - top) * fy;
|
|
59184
|
+
* Whether a clamped sheet has ground to stand on yet.
|
|
59185
|
+
*/
|
|
59186
|
+
hasGround() {
|
|
59187
|
+
return this.followGround && Boolean(this.groundRaster) && this.groundRaster.HasCoarse();
|
|
59188
|
+
}
|
|
59189
|
+
/*
|
|
59190
|
+
* Lets go of the ground raster, so samples still in flight land nowhere.
|
|
59191
|
+
*/
|
|
59192
|
+
dropGroundRaster() {
|
|
59193
|
+
if (this.groundRaster) {
|
|
59194
|
+
this.groundRaster.Dispose();
|
|
59195
|
+
this.groundRaster = null;
|
|
59196
|
+
}
|
|
58555
59197
|
}
|
|
58556
59198
|
/**
|
|
58557
59199
|
* Feeds the surface from an animated frame series.
|
|
@@ -58605,8 +59247,13 @@ void main() {
|
|
|
58605
59247
|
this.syncTexture(context);
|
|
58606
59248
|
}
|
|
58607
59249
|
this.syncRampTexture(context);
|
|
58608
|
-
this.requestGround();
|
|
59250
|
+
this.requestGround(frameState);
|
|
58609
59251
|
this.syncGroundTexture(context);
|
|
59252
|
+
this.drapeActive = this.drape && frameState.mode === Cesium.SceneMode.SCENE3D;
|
|
59253
|
+
if (this.drapeActive) {
|
|
59254
|
+
this.probeGroundOffset(frameState);
|
|
59255
|
+
this.updateDrapeFrame(frameState);
|
|
59256
|
+
}
|
|
58610
59257
|
this.requestMaskGround();
|
|
58611
59258
|
this.syncMaskTextures(context);
|
|
58612
59259
|
// A tile needs one mesh before it has a bounding sphere to measure against.
|
|
@@ -58663,6 +59310,7 @@ void main() {
|
|
|
58663
59310
|
this.groundTexture.destroy();
|
|
58664
59311
|
this.groundTexture = null;
|
|
58665
59312
|
}
|
|
59313
|
+
this.dropGroundRaster();
|
|
58666
59314
|
if (this.maskTexture) {
|
|
58667
59315
|
this.maskTexture.destroy();
|
|
58668
59316
|
this.maskTexture = null;
|
|
@@ -58674,42 +59322,108 @@ void main() {
|
|
|
58674
59322
|
return undefined;
|
|
58675
59323
|
}
|
|
58676
59324
|
/*
|
|
58677
|
-
*
|
|
58678
|
-
|
|
58679
|
-
|
|
58680
|
-
|
|
59325
|
+
* The extent centre's frame in eye coordinates, in double precision each frame, for the draped fragment shader.
|
|
59326
|
+
*/
|
|
59327
|
+
updateDrapeFrame(frameState) {
|
|
59328
|
+
const e = this.extent;
|
|
59329
|
+
const lon = Cesium.Math.toRadians((e.West + e.East) / 2);
|
|
59330
|
+
const lat = Cesium.Math.toRadians((e.North + e.South) / 2);
|
|
59331
|
+
const centre = Cesium.Cartesian3.fromRadians(lon, lat, 0);
|
|
59332
|
+
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(centre);
|
|
59333
|
+
const view = frameState.camera.viewMatrix;
|
|
59334
|
+
const f = this.drapeFrame;
|
|
59335
|
+
Cesium.Matrix4.multiplyByPoint(view, centre, f.centreEC);
|
|
59336
|
+
const axis = new Cesium.Cartesian3();
|
|
59337
|
+
const columns = [f.eastEC, f.northEC, f.upEC];
|
|
59338
|
+
for (let i = 0; i < 3; i++) {
|
|
59339
|
+
Cesium.Matrix4.getColumn(enu, i, axis);
|
|
59340
|
+
Cesium.Matrix4.multiplyByPointAsVector(view, axis, columns[i]);
|
|
59341
|
+
Cesium.Cartesian3.normalize(columns[i], columns[i]);
|
|
59342
|
+
}
|
|
59343
|
+
const sin = Math.sin(lat);
|
|
59344
|
+
const w = 1 - WGS84_E2 * sin * sin;
|
|
59345
|
+
f.geo = new Cesium.Cartesian4(lon, lat, WGS84_A * (1 - WGS84_E2) / Math.pow(w, 1.5), WGS84_A / Math.sqrt(w));
|
|
59346
|
+
f.extent = new Cesium.Cartesian4(Cesium.Math.toRadians(e.West), Cesium.Math.toRadians(e.East), Cesium.Math.toRadians(e.North), Cesium.Math.toRadians(e.South));
|
|
59347
|
+
}
|
|
59348
|
+
/*
|
|
59349
|
+
* Measures a shown ground tileset such as Google's against the ground raster near the camera.
|
|
58681
59350
|
*/
|
|
58682
|
-
|
|
58683
|
-
|
|
59351
|
+
probeGroundOffset(frameState) {
|
|
59352
|
+
const raster = this.groundRaster;
|
|
59353
|
+
const scene = this.scene;
|
|
59354
|
+
if (!raster || !raster.HasCoarse() || !scene || this.offsetProbe.busy || typeof scene.sampleHeightMostDetailed !== "function") {
|
|
58684
59355
|
return;
|
|
58685
59356
|
}
|
|
58686
|
-
|
|
58687
|
-
|
|
58688
|
-
if (!this.terrainProvider || typeof sampler !== "function") {
|
|
59357
|
+
const eye = frameState.camera.positionWC;
|
|
59358
|
+
if (this.offsetProbe.at && Cesium.Cartesian3.distance(this.offsetProbe.at, eye) < OFFSET_REPROBE_METRES) {
|
|
58689
59359
|
return;
|
|
58690
59360
|
}
|
|
58691
|
-
|
|
58692
|
-
|
|
58693
|
-
|
|
58694
|
-
|
|
58695
|
-
|
|
58696
|
-
|
|
58697
|
-
|
|
58698
|
-
|
|
59361
|
+
this.offsetProbe.at = Cesium.Cartesian3.clone(eye);
|
|
59362
|
+
const tileset = findGroundTileset(scene.primitives);
|
|
59363
|
+
if (!tileset || !scene.sampleHeightSupported) {
|
|
59364
|
+
this.groundOffset = 0;
|
|
59365
|
+
return;
|
|
59366
|
+
}
|
|
59367
|
+
const e = this.extent;
|
|
59368
|
+
const camera = Cesium.Cartographic.fromCartesian(eye);
|
|
59369
|
+
if (!camera) {
|
|
59370
|
+
return;
|
|
59371
|
+
}
|
|
59372
|
+
const toDegrees = 180 / (Math.PI * WGS84_A);
|
|
59373
|
+
const latStep = OFFSET_PROBE_SPACING_METRES * toDegrees;
|
|
59374
|
+
const lonStep = latStep / Math.max(0.1, Math.cos(camera.latitude));
|
|
59375
|
+
const lon0 = Math.min(e.East, Math.max(e.West, Cesium.Math.toDegrees(camera.longitude)));
|
|
59376
|
+
const lat0 = Math.min(e.North, Math.max(e.South, Cesium.Math.toDegrees(camera.latitude)));
|
|
59377
|
+
const probes = [];
|
|
59378
|
+
const half = (OFFSET_PROBES_PER_SIDE - 1) / 2;
|
|
59379
|
+
for (let row = 0; row < OFFSET_PROBES_PER_SIDE; row++) {
|
|
59380
|
+
for (let col = 0; col < OFFSET_PROBES_PER_SIDE; col++) {
|
|
59381
|
+
const lon = Math.min(e.East, Math.max(e.West, lon0 + (col - half) * lonStep));
|
|
59382
|
+
const lat = Math.min(e.North, Math.max(e.South, lat0 + (row - half) * latStep));
|
|
59383
|
+
probes.push(Cesium.Cartographic.fromDegrees(lon, lat));
|
|
58699
59384
|
}
|
|
58700
59385
|
}
|
|
58701
|
-
|
|
58702
|
-
|
|
58703
|
-
|
|
59386
|
+
this.offsetProbe.busy = true;
|
|
59387
|
+
Promise.resolve(scene.sampleHeightMostDetailed(probes, [this]))
|
|
59388
|
+
.then((drawn) => {
|
|
59389
|
+
if (this.destroyed || this.groundRaster !== raster) {
|
|
58704
59390
|
return;
|
|
58705
59391
|
}
|
|
58706
|
-
|
|
59392
|
+
const differences = (drawn || []).map((c) => {
|
|
59393
|
+
const u = (Cesium.Math.toDegrees(c.longitude) - e.West) / (e.East - e.West);
|
|
59394
|
+
const v = (e.North - Cesium.Math.toDegrees(c.latitude)) / (e.North - e.South);
|
|
59395
|
+
return c && isFinite(c.height) ? c.height - raster.HeightAt(u, v) : NaN;
|
|
59396
|
+
});
|
|
59397
|
+
const offset = GroundOffsetFrom(differences);
|
|
59398
|
+
if (offset !== null) {
|
|
59399
|
+
this.groundOffset = offset;
|
|
59400
|
+
}
|
|
58707
59401
|
})
|
|
58708
59402
|
.catch(() => {
|
|
58709
|
-
//
|
|
58710
|
-
|
|
59403
|
+
// Unmeasured, the sheet keeps its last offset.
|
|
59404
|
+
})
|
|
59405
|
+
.then(() => {
|
|
59406
|
+
this.offsetProbe.busy = false;
|
|
58711
59407
|
});
|
|
58712
59408
|
}
|
|
59409
|
+
/*
|
|
59410
|
+
* Starts the ground raster a clamped sheet stands on, and refines it near the camera each frame.
|
|
59411
|
+
*/
|
|
59412
|
+
requestGround(frameState) {
|
|
59413
|
+
if (!this.followGround || !this.terrainProvider || !this.sourceDims) {
|
|
59414
|
+
return;
|
|
59415
|
+
}
|
|
59416
|
+
if (!this.groundRaster) {
|
|
59417
|
+
const side = this.groundRasterSide || GroundRaster.SideFor(this.sourceDims.width, this.sourceDims.height);
|
|
59418
|
+
this.groundRaster = new GroundRaster.Raster(this.extent, side, terrainSampler(this.terrainProvider, this.extent));
|
|
59419
|
+
this.groundRaster.StartCoarse();
|
|
59420
|
+
return;
|
|
59421
|
+
}
|
|
59422
|
+
const culling = frameState.cullingVolume;
|
|
59423
|
+
this.groundRaster.Refine(frameState.camera.positionWC, culling
|
|
59424
|
+
? (sphere) => culling.computeVisibility(sphere) !== Cesium.Intersect.OUTSIDE
|
|
59425
|
+
: undefined);
|
|
59426
|
+
}
|
|
58713
59427
|
/*
|
|
58714
59428
|
* Samples the terrain under the clearance regions.
|
|
58715
59429
|
*
|
|
@@ -58738,10 +59452,10 @@ void main() {
|
|
|
58738
59452
|
// does not cover are never asked for at all.
|
|
58739
59453
|
const slots = [];
|
|
58740
59454
|
for (let row = 0; row < MASK_GROUND_SAMPLES_PER_SIDE; row++) {
|
|
58741
|
-
const fy = row /
|
|
59455
|
+
const fy = (row + 0.5) / MASK_GROUND_SAMPLES_PER_SIDE;
|
|
58742
59456
|
const latitude = Cesium.Math.lerp(box.North, box.South, fy);
|
|
58743
59457
|
for (let col = 0; col < MASK_GROUND_SAMPLES_PER_SIDE; col++) {
|
|
58744
|
-
const fx = col /
|
|
59458
|
+
const fx = (col + 0.5) / MASK_GROUND_SAMPLES_PER_SIDE;
|
|
58745
59459
|
const at = Cesium.Cartographic.fromDegrees(Cesium.Math.lerp(box.West, box.East, fx), latitude);
|
|
58746
59460
|
// An imported terrain covers a survey area, so asking outside it answers 404 and
|
|
58747
59461
|
// fills the console with failures for points that were never going to have a height.
|
|
@@ -58825,27 +59539,48 @@ void main() {
|
|
|
58825
59539
|
* shader always has a texture bound whether or not this surface follows the ground.
|
|
58826
59540
|
*/
|
|
58827
59541
|
syncGroundTexture(context) {
|
|
58828
|
-
|
|
59542
|
+
const raster = this.hasGround() ? this.groundRaster : null;
|
|
59543
|
+
const side = raster ? raster.side : 1;
|
|
59544
|
+
if (!this.groundTexture || this.groundTextureSide !== side) {
|
|
59545
|
+
if (this.groundTexture) {
|
|
59546
|
+
this.groundTexture.destroy();
|
|
59547
|
+
}
|
|
59548
|
+
const stand = new Uint8Array(4);
|
|
59549
|
+
GroundRaster.Pack(0, stand, 0);
|
|
59550
|
+
this.groundTexture = new Cesium.Texture({
|
|
59551
|
+
context,
|
|
59552
|
+
pixelFormat: Cesium.PixelFormat.RGBA,
|
|
59553
|
+
source: { width: side, height: side, arrayBufferView: raster ? raster.pixels : stand },
|
|
59554
|
+
flipY: false,
|
|
59555
|
+
sampler: new Cesium.Sampler({
|
|
59556
|
+
wrapS: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
59557
|
+
wrapT: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
59558
|
+
// Nearest, because the shader interpolates decoded heights itself.
|
|
59559
|
+
minificationFilter: Cesium.TextureMinificationFilter.NEAREST,
|
|
59560
|
+
magnificationFilter: Cesium.TextureMagnificationFilter.NEAREST
|
|
59561
|
+
})
|
|
59562
|
+
});
|
|
59563
|
+
this.groundTextureSide = side;
|
|
59564
|
+
if (raster) {
|
|
59565
|
+
raster.TakeDirty();
|
|
59566
|
+
}
|
|
58829
59567
|
return;
|
|
58830
59568
|
}
|
|
58831
|
-
if (
|
|
58832
|
-
|
|
59569
|
+
if (!raster) {
|
|
59570
|
+
return;
|
|
59571
|
+
}
|
|
59572
|
+
for (const region of raster.TakeDirty()) {
|
|
59573
|
+
const block = new Uint8Array(region.width * region.height * 4);
|
|
59574
|
+
for (let row = 0; row < region.height; row++) {
|
|
59575
|
+
const from = ((region.y + row) * side + region.x) * 4;
|
|
59576
|
+
block.set(raster.pixels.subarray(from, from + region.width * 4), row * region.width * 4);
|
|
59577
|
+
}
|
|
59578
|
+
this.groundTexture.copyFrom({
|
|
59579
|
+
source: { width: region.width, height: region.height, arrayBufferView: block },
|
|
59580
|
+
xOffset: region.x,
|
|
59581
|
+
yOffset: region.y
|
|
59582
|
+
});
|
|
58833
59583
|
}
|
|
58834
|
-
const size = this.groundPixels ? GROUND_SAMPLES_PER_SIDE : 1;
|
|
58835
|
-
const arrayBufferView = this.groundPixels || packHeights([{ height: 0 }]);
|
|
58836
|
-
this.groundTexture = new Cesium.Texture({
|
|
58837
|
-
context,
|
|
58838
|
-
pixelFormat: Cesium.PixelFormat.RGBA,
|
|
58839
|
-
source: { width: size, height: size, arrayBufferView },
|
|
58840
|
-
flipY: false,
|
|
58841
|
-
sampler: new Cesium.Sampler({
|
|
58842
|
-
wrapS: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
58843
|
-
wrapT: Cesium.TextureWrap.CLAMP_TO_EDGE,
|
|
58844
|
-
// Nearest, because the shader interpolates decoded heights itself.
|
|
58845
|
-
minificationFilter: Cesium.TextureMinificationFilter.NEAREST,
|
|
58846
|
-
magnificationFilter: Cesium.TextureMagnificationFilter.NEAREST
|
|
58847
|
-
})
|
|
58848
|
-
});
|
|
58849
59584
|
}
|
|
58850
59585
|
/*
|
|
58851
59586
|
* Metres the extent spans west to east and north to south, which is what turns the shader's
|
|
@@ -59166,9 +59901,9 @@ void main() {
|
|
|
59166
59901
|
u_valueFade: () => (self.fade && self.fade.from ? self.fade.mix : 1),
|
|
59167
59902
|
u_groundTexture: () => self.groundTexture,
|
|
59168
59903
|
u_valuePacked: () => (self.packedValue ? 1 : 0),
|
|
59169
|
-
u_groundWeight: () => (self.
|
|
59904
|
+
u_groundWeight: () => (self.hasGround() ? 1 : 0),
|
|
59170
59905
|
u_groundRange: () => new Cesium.Cartesian2(GROUND_MIN_METRES, GROUND_MAX_METRES),
|
|
59171
|
-
u_groundSize: () => new Cesium.Cartesian2(self.
|
|
59906
|
+
u_groundSize: () => new Cesium.Cartesian2(self.groundTextureSide || 1, self.groundTextureSide || 1),
|
|
59172
59907
|
u_maskTexture: () => self.maskTexture,
|
|
59173
59908
|
u_maskGroundTexture: () => self.maskGroundTexture,
|
|
59174
59909
|
u_maskWeight: () => (self.groundClearance && self.maskPixels ? 1 : 0),
|
|
@@ -59227,7 +59962,17 @@ void main() {
|
|
|
59227
59962
|
u_wavePhaseB: () => self.wavePhase(4),
|
|
59228
59963
|
u_wavePeriod: () => self.wavePeriod(),
|
|
59229
59964
|
u_waveOrigin: () => self.waveOrigin,
|
|
59230
|
-
u_extentMetres: () => self.extentMetres()
|
|
59965
|
+
u_extentMetres: () => self.extentMetres(),
|
|
59966
|
+
u_drape: () => (self.drapeActive ? 1 : 0),
|
|
59967
|
+
u_drapeLift: () => self.drapeLift,
|
|
59968
|
+
u_drapeBand: () => self.drapeBand,
|
|
59969
|
+
u_groundOffset: () => self.groundOffset,
|
|
59970
|
+
u_drapeCentreEC: () => self.drapeFrame.centreEC,
|
|
59971
|
+
u_drapeEastEC: () => self.drapeFrame.eastEC,
|
|
59972
|
+
u_drapeNorthEC: () => self.drapeFrame.northEC,
|
|
59973
|
+
u_drapeUpEC: () => self.drapeFrame.upEC,
|
|
59974
|
+
u_drapeGeo: () => self.drapeFrame.geo,
|
|
59975
|
+
u_extentRadians: () => self.drapeFrame.extent
|
|
59231
59976
|
}
|
|
59232
59977
|
});
|
|
59233
59978
|
}
|
|
@@ -60156,6 +60901,7 @@ void main() {
|
|
|
60156
60901
|
baseHeight: placement.baseHeight,
|
|
60157
60902
|
followGround: placement.followGround,
|
|
60158
60903
|
terrainProvider: viewer && viewer.terrainProvider,
|
|
60904
|
+
scene: viewer && viewer.scene,
|
|
60159
60905
|
valueMin: extrusionArchive.metadata.ValueMin,
|
|
60160
60906
|
valueMax: extrusionArchive.metadata.ValueMax,
|
|
60161
60907
|
packedValue: exports.TextureFrameSeriesAnimator.IsPackedValue(extrusionArchive.metadata),
|
|
@@ -62150,7 +62896,7 @@ void main() {
|
|
|
62150
62896
|
StyleUtils.ApplyTypeStyle = ApplyTypeStyle;
|
|
62151
62897
|
})(exports.StyleUtils || (exports.StyleUtils = {}));
|
|
62152
62898
|
|
|
62153
|
-
const VERSION = "7.9.
|
|
62899
|
+
const VERSION = "7.9.6";
|
|
62154
62900
|
/**
|
|
62155
62901
|
* Updates the environment instance used by bruce-cesium to one specified.
|
|
62156
62902
|
* This can be used to ensure that the instance a parent is referencing is shared between bruce-cesium, bruce-models, and the parent app.
|