mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw the Bhote Koshi event through the renderer's ports and take it off the Cesium list
The flood is two draw sets per layer: the corridor's dashed halo and glowing core as draped lines (on tiles too under photoreal, on terrain otherwise), moved in the frame the event moves them, and the surge front as a clamped point. Only what changed is drawn again. Neither set is pickable, and height queries see through both, so the shot paths no longer list them to exclude. The before/after images are globe-port layers on either side of the split, over every layer drawn when they are added and draped on the globe's surface only, as before. The divider moves the globe port's split. An image that fails to load now takes the comparison (the pair, the divider and its labels) down and leaves the event on, where a failed provider used to fail the enable. Evidence heights come through heightsOf, whose batch can now count an answer from the bare ellipsoid as a miss, so points still fall back to their authored elevations without terrain. The camera, canvas and the event's vector maths go through the camera port, the renderer and src/geo (lerp joins geo/vector).
This commit is contained in:
1 parent
bddb890326
commit
6bbe35f232
6 files changed
+570
-312
No files matched your search
+281
-169
@@ -1,4 +1,3 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { isPointerFree } from './inputOwnership.js';
|
||||
import {
|
||||
clearOverlaySource,
|
||||
@@ -28,9 +27,17 @@ import { createImagerySplit } from '../ui/imagerySplit.js';
|
||||
import { formatDate, t, tn, msg, onLocaleChange } from '../i18n/index.js';
|
||||
import { useBhoteKoshiPanelStore } from '../ui/stores/bhoteKoshiPanel.js';
|
||||
import { applicationPinia } from '../ui/vueRuntime.js';
|
||||
import { heightsFor } from '../render/cesium/heights.js';
|
||||
import { cameraOf } from '../render/cesium/camera.js';
|
||||
import { findCamera } from '../render/rendererOf.js';
|
||||
import { heightsOf } from '../queries/heights.js';
|
||||
import {
|
||||
cameraOf,
|
||||
drawOf,
|
||||
findCamera,
|
||||
findGlobe,
|
||||
rendererOf,
|
||||
} from '../render/rendererOf.js';
|
||||
import { hexColor } from '../render/color.js';
|
||||
import { fromDegrees } from '../geo/ellipsoid.js';
|
||||
import { clone, lerp, lerpInto, toRadians, vec } from '../geo/vector.js';
|
||||
|
||||
export const BHOTE_KOSHI_LAYER_ID = 'bhote-koshi-2026';
|
||||
export const BHOTE_KOSHI_OVERLAY_SOURCE_ID = 'bhote-koshi-witnesses';
|
||||
@@ -49,8 +56,24 @@ const SCENE_PATH_RENDER_HOLD = 'bhote-koshi-scene-path-travel';
|
||||
const SCENE_MEDIA_MIN_PLAYBACK_SECONDS = 6;
|
||||
const SCENE_MEDIA_EXIT_SECONDS = 0.65;
|
||||
const BHOTE_EVENT_ACCENT = WORLD_OVERLAY_STYLE.accent;
|
||||
const FLOOD_COLOR = Cesium.Color.fromCssColorString('#d8954e').withAlpha(0.68);
|
||||
const SURGE_COLOR = Cesium.Color.fromCssColorString('#e8b47c');
|
||||
const FLOOD_ACCENT = '#d8954e';
|
||||
const FLOOD_HALO_COLOR = hexColor(FLOOD_ACCENT, 0.38);
|
||||
const FLOOD_CORE_COLOR = hexColor(FLOOD_ACCENT, 0.96);
|
||||
const SURGE_COLOR = hexColor('#e8b47c');
|
||||
const SURGE_OUTLINE_COLOR = [0, 0, 0, 0.85];
|
||||
const FLOOD_HALO_ID = 'bhote-koshi-flood-halo';
|
||||
const FLOOD_CORE_ID = 'bhote-koshi-flood-core';
|
||||
const SURGE_FRONT_ID = 'bhote-koshi-surge-front';
|
||||
const IMAGERY_CREDIT = Object.freeze({
|
||||
text: 'Vantor WorldView Open Data · CC BY-NC 4.0',
|
||||
});
|
||||
|
||||
// Each layer's draw sets have ids of their own.
|
||||
let layerSerial = 0;
|
||||
|
||||
/** Whether two positions are the same point; either may be null. */
|
||||
const samePoint = (a, b) =>
|
||||
a === b || (Boolean(a && b) && a.x === b.x && a.y === b.y && a.z === b.z);
|
||||
const CINEMATIC_INPUT_EVENTS = Object.freeze(['pointerdown', 'wheel']);
|
||||
const CINEMATIC_VIEW_SPECS = Object.freeze([
|
||||
{
|
||||
@@ -122,12 +145,23 @@ const DEFAULT_EVENT_LOADER = async () => {
|
||||
throw new Error(`Bhote Koshi event pack unavailable (${response.status})`);
|
||||
return response.json();
|
||||
};
|
||||
const DEFAULT_IMAGERY_PROVIDER_FACTORY = (url, options) =>
|
||||
Cesium.SingleTileImageryProvider.fromUrl(url, options);
|
||||
/** The globe port's spec for one of the event's images, over `rectangle`. */
|
||||
const DEFAULT_IMAGERY_SPEC_FACTORY = (url, { rectangle, credit }) => ({
|
||||
kind: 'single-image',
|
||||
url,
|
||||
rectangle,
|
||||
credit,
|
||||
});
|
||||
/**
|
||||
* Terrain heights under the observations, once the most detailed terrain
|
||||
* has loaded. The bare ellipsoid answers no height, as there is no terrain
|
||||
* to sample then.
|
||||
*/
|
||||
const DEFAULT_TERRAIN_SAMPLER = async (viewer, observations) => {
|
||||
if (!viewer?.scene || !viewer.terrainProvider?.availability) return null;
|
||||
const heights = await heightsFor(viewer.scene).batch(observations, {
|
||||
if (!viewer) return null;
|
||||
const heights = await heightsOf(viewer).batch(observations, {
|
||||
against: 'terrain',
|
||||
ellipsoidMisses: true,
|
||||
});
|
||||
return heights.map((height) => ({ height }));
|
||||
};
|
||||
@@ -181,7 +215,7 @@ export function visibleSegmentCount(progress, segmentCount) {
|
||||
|
||||
/**
|
||||
* Build a corridor whose final vertex is the exact animated surge position.
|
||||
* Returns true only when the Cesium polyline assignments need refreshing.
|
||||
* Returns true only when the drawn corridor needs refreshing.
|
||||
*/
|
||||
export function updateCorridorPositionCache(progress, terrainPositions, cache) {
|
||||
const positions = Array.isArray(terrainPositions) ? terrainPositions : [];
|
||||
@@ -204,15 +238,15 @@ export function updateCorridorPositionCache(progress, terrainPositions, cache) {
|
||||
const startIndex = Math.min(segmentCount - 1, Math.floor(scaledProgress));
|
||||
const segmentProgress =
|
||||
normalizedProgress >= 1 ? 1 : scaledProgress - startIndex;
|
||||
cache.headPosition = Cesium.Cartesian3.lerp(
|
||||
cache.headPosition = lerpInto(
|
||||
positions[startIndex],
|
||||
positions[startIndex + 1],
|
||||
segmentProgress,
|
||||
cache.headPosition || new Cesium.Cartesian3(),
|
||||
cache.headPosition || vec(),
|
||||
);
|
||||
cache.positions = positions.slice(0, startIndex + 1);
|
||||
if (segmentProgress > 0) {
|
||||
cache.positions.push(Cesium.Cartesian3.clone(cache.headPosition));
|
||||
cache.positions.push(clone(cache.headPosition));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -519,19 +553,19 @@ export function sampleCinematicPose(progress, keyframes, result = {}) {
|
||||
: (linearAmount - BHOTE_KOSHI_CAMERA_HOLD_RATIO) /
|
||||
(1 - BHOTE_KOSHI_CAMERA_HOLD_RATIO);
|
||||
const amount = travelAmount * travelAmount * (3 - 2 * travelAmount);
|
||||
result.target = Cesium.Cartesian3.lerp(
|
||||
result.target = lerpInto(
|
||||
from.target,
|
||||
to.target,
|
||||
amount,
|
||||
result.target || new Cesium.Cartesian3(),
|
||||
result.target || vec(),
|
||||
);
|
||||
result.headingDeg = interpolateHeadingDegrees(
|
||||
from.headingDeg,
|
||||
to.headingDeg,
|
||||
amount,
|
||||
);
|
||||
result.pitchDeg = Cesium.Math.lerp(from.pitchDeg, to.pitchDeg, amount);
|
||||
result.rangeM = Cesium.Math.lerp(from.rangeM, to.rangeM, amount);
|
||||
result.pitchDeg = lerp(from.pitchDeg, to.pitchDeg, amount);
|
||||
result.rangeM = lerp(from.rangeM, to.rangeM, amount);
|
||||
result.fromId = from.id;
|
||||
result.toId = to.id;
|
||||
return result;
|
||||
@@ -885,14 +919,14 @@ function openExternal(url) {
|
||||
|
||||
function focusView(viewer, viewpoint) {
|
||||
announceNavigationAuthority('bhote-koshi-event-focus');
|
||||
const target = Cesium.Cartesian3.fromDegrees(
|
||||
const target = fromDegrees(
|
||||
viewpoint.lon,
|
||||
viewpoint.lat,
|
||||
viewpoint.targetElevationM,
|
||||
);
|
||||
const offset = {
|
||||
heading: Cesium.Math.toRadians(viewpoint.headingDeg),
|
||||
pitch: Cesium.Math.toRadians(viewpoint.pitchDeg),
|
||||
heading: toRadians(viewpoint.headingDeg),
|
||||
pitch: toRadians(viewpoint.pitchDeg),
|
||||
range: viewpoint.rangeM,
|
||||
};
|
||||
const camera = cameraOf(viewer);
|
||||
@@ -985,7 +1019,7 @@ export function createBhoteKoshiEventLayer({
|
||||
overlayHost = DEFAULT_OVERLAY_HOST,
|
||||
renderHost = DEFAULT_RENDER_HOST,
|
||||
eventLoader = DEFAULT_EVENT_LOADER,
|
||||
imageryProviderFactory = DEFAULT_IMAGERY_PROVIDER_FACTORY,
|
||||
imagerySpecFactory = DEFAULT_IMAGERY_SPEC_FACTORY,
|
||||
terrainSampler = DEFAULT_TERRAIN_SAMPLER,
|
||||
mediaLoader = DEFAULT_MEDIA_LOADER,
|
||||
evidenceFrameFactory = createEvidenceFrame,
|
||||
@@ -1011,12 +1045,19 @@ export function createBhoteKoshiEventLayer({
|
||||
let _splitControl = null;
|
||||
let _beforeLayer = null;
|
||||
let _afterLayer = null;
|
||||
let _imageryLayerCollection = null;
|
||||
let _floodDataSource = null;
|
||||
// An event image failed to load this enable: no comparison is shown.
|
||||
let _imageryFailed = false;
|
||||
const _serial = ++layerSerial;
|
||||
// The flood's draw sets: the corridor's halo and core lines, and the
|
||||
// surge front. Null while the layer is off.
|
||||
let _floodSets = null;
|
||||
let _floodSurfaceMode = null;
|
||||
let _floodHalo = null;
|
||||
let _floodCore = null;
|
||||
let _surgePoint = null;
|
||||
// What the flood shows, set as the story moves, and what was last drawn
|
||||
// of it (`drawFlood`).
|
||||
let _floodShow = false;
|
||||
let _surgeShow = false;
|
||||
let _surgePosition = null;
|
||||
let _floodDrawn = null;
|
||||
let _terrainPositions = [];
|
||||
let _sourceShotPaths = new Map();
|
||||
let _scenePathPositionCache = new Map();
|
||||
@@ -1050,7 +1091,7 @@ export function createBhoteKoshiEventLayer({
|
||||
let _cinematicKeyframes = [];
|
||||
let _cinematicActive = false;
|
||||
let _cinematicReplayArmed = false;
|
||||
let _cinematicPose = { target: new Cesium.Cartesian3() };
|
||||
let _cinematicPose = { target: vec() };
|
||||
const _cinematicOffset = { heading: 0, pitch: 0, range: 0 };
|
||||
let _lastCinematicProgress = null;
|
||||
let _cameraInputTarget = null;
|
||||
@@ -1066,7 +1107,6 @@ export function createBhoteKoshiEventLayer({
|
||||
let _comparisonLease = null;
|
||||
let _introTimer = null;
|
||||
let _introGeneration = 0;
|
||||
let _lastSurgePosition = null;
|
||||
let _lastSurgeVisible = null;
|
||||
let _presentation = 'standalone';
|
||||
let _sceneBeatId = null;
|
||||
@@ -1152,33 +1192,52 @@ export function createBhoteKoshiEventLayer({
|
||||
}
|
||||
|
||||
async function createImagery(event) {
|
||||
const rectangle = Cesium.Rectangle.fromDegrees(
|
||||
event.imagery.rectangle.west,
|
||||
event.imagery.rectangle.south,
|
||||
event.imagery.rectangle.east,
|
||||
event.imagery.rectangle.north,
|
||||
);
|
||||
const [beforeProvider, afterProvider] = await Promise.all([
|
||||
imageryProviderFactory(eventAsset(event.imagery.before.path), {
|
||||
rectangle,
|
||||
credit: 'Vantor WorldView Open Data · CC BY-NC 4.0',
|
||||
}),
|
||||
imageryProviderFactory(eventAsset(event.imagery.after.path), {
|
||||
rectangle,
|
||||
credit: 'Vantor WorldView Open Data · CC BY-NC 4.0',
|
||||
}),
|
||||
_imageryFailed = false;
|
||||
const { west, south, east, north } = event.imagery.rectangle;
|
||||
const options = {
|
||||
rectangle: { west, south, east, north },
|
||||
credit: IMAGERY_CREDIT,
|
||||
};
|
||||
const [beforeSpec, afterSpec] = await Promise.all([
|
||||
imagerySpecFactory(eventAsset(event.imagery.before.path), options),
|
||||
imagerySpecFactory(eventAsset(event.imagery.after.path), options),
|
||||
]);
|
||||
if (!_enabled) return;
|
||||
_imageryLayerCollection = _viewer.imageryLayers;
|
||||
_beforeLayer = _imageryLayerCollection.addImageryProvider(beforeProvider);
|
||||
_afterLayer = _imageryLayerCollection.addImageryProvider(afterProvider);
|
||||
_beforeLayer.splitDirection = Cesium.SplitDirection.LEFT;
|
||||
_afterLayer.splitDirection = Cesium.SplitDirection.RIGHT;
|
||||
_beforeLayer.alpha = 0.96;
|
||||
_afterLayer.alpha = 0.96;
|
||||
const globe = findGlobe(_viewer);
|
||||
if (!globe)
|
||||
throw new Error('Bhote Koshi imagery needs a globe to drape on');
|
||||
_beforeLayer = addEventImagery(globe, beforeSpec, 'left');
|
||||
_afterLayer = addEventImagery(globe, afterSpec, 'right');
|
||||
setSplit(_split);
|
||||
}
|
||||
|
||||
/**
|
||||
* One of the before/after images, on its side of the split, over every
|
||||
* layer drawn so far. It drapes on the globe's surface only, as the
|
||||
* comparison is drawn on terrain.
|
||||
*/
|
||||
function addEventImagery(globe, spec, split) {
|
||||
const layer = globe.imagery.add(spec, globe.imagery.list().length);
|
||||
layer.split = split;
|
||||
layer.alpha = 0.96;
|
||||
layer.drapeOn = 'surface';
|
||||
layer.on('tileError', (error) => imageryFailed(error));
|
||||
return layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* An image that did not load: without both images there is nothing to
|
||||
* compare, so the pair and the comparison's divider and labels go.
|
||||
*/
|
||||
function imageryFailed(error) {
|
||||
if (_imageryFailed) return;
|
||||
_imageryFailed = true;
|
||||
console.warn('[Data:BhoteKoshi] Event imagery unavailable:', error);
|
||||
removeImagery();
|
||||
syncPresentationMode();
|
||||
renderHost.request('bhote-koshi-imagery-failed');
|
||||
}
|
||||
|
||||
async function resolveEvidenceAnchors(event, signal) {
|
||||
const observations = Array.isArray(event.evidenceSpine)
|
||||
? event.evidenceSpine
|
||||
@@ -1198,7 +1257,7 @@ export function createBhoteKoshiEventLayer({
|
||||
// A miss is null or undefined, never sea level.
|
||||
const sampledHeight = Number(sampled?.[index]?.height ?? Number.NaN);
|
||||
const fallbackHeight = Number(observation.fallbackElevationM) || 0;
|
||||
return Cesium.Cartesian3.fromDegrees(
|
||||
return fromDegrees(
|
||||
observation.lon,
|
||||
observation.lat,
|
||||
(Number.isFinite(sampledHeight) ? sampledHeight : fallbackHeight) + 18,
|
||||
@@ -1239,7 +1298,7 @@ export function createBhoteKoshiEventLayer({
|
||||
function showWitnessEmbed() {
|
||||
const witness = _event?.witnessAnchors?.[0];
|
||||
if (!witness?.sourceUrl) return false;
|
||||
const anchor = Cesium.Cartesian3.fromDegrees(
|
||||
const anchor = fromDegrees(
|
||||
witness.lon,
|
||||
witness.lat,
|
||||
(Number(witness.elevationM) || 0) + 18,
|
||||
@@ -1565,22 +1624,21 @@ export function createBhoteKoshiEventLayer({
|
||||
const cached = _scenePathPositionCache.get(cacheKey);
|
||||
if (cached) return cached;
|
||||
const positions = (_sourceShotPaths.get(beatId) || []).map((point) => {
|
||||
const position = Cesium.Cartographic.fromDegrees(point.lon, point.lat);
|
||||
const position = { lon: point.lon, lat: point.lat };
|
||||
let height;
|
||||
// Some schematic reaches have a source elevation profile. Do not replace
|
||||
// it with coarse mesh heights on entry/exit from the comparison surface:
|
||||
// a single high sample can make the front dive backward in screen space.
|
||||
if (_sceneControls.evidencePathElevation !== 'source') {
|
||||
// Sample once while preparing the shot, never from an animation frame.
|
||||
const heights = _viewer?.scene ? heightsFor(_viewer.scene) : null;
|
||||
height = heights?.now(position, {
|
||||
exclude: [_floodCore, _floodHalo, _surgePoint].filter(Boolean),
|
||||
});
|
||||
// The flood's own sets are not ground: queries see through them.
|
||||
const heights = _viewer ? heightsOf(_viewer) : null;
|
||||
height = heights?.now(position);
|
||||
if (!Number.isFinite(height))
|
||||
height = heights?.now(position, { against: 'terrain' });
|
||||
}
|
||||
if (!Number.isFinite(height)) height = point.fallbackElevationM;
|
||||
return Cesium.Cartesian3.fromDegrees(point.lon, point.lat, height + 8);
|
||||
return fromDegrees(point.lon, point.lat, height + 8);
|
||||
});
|
||||
_scenePathPositionCache.set(cacheKey, positions);
|
||||
return positions;
|
||||
@@ -2477,11 +2535,7 @@ export function createBhoteKoshiEventLayer({
|
||||
const elevationOffsetM =
|
||||
_presentation === BHOTE_KOSHI_SCENE_PRESENTATION ? 55 : 8;
|
||||
_terrainPositions = event.reconstruction.corridor.map((point) =>
|
||||
Cesium.Cartesian3.fromDegrees(
|
||||
point.lon,
|
||||
point.lat,
|
||||
point.elevationM + elevationOffsetM,
|
||||
),
|
||||
fromDegrees(point.lon, point.lat, point.elevationM + elevationOffsetM),
|
||||
);
|
||||
prepareScenePath();
|
||||
_evidenceTimeline = buildEvidenceTimeline(
|
||||
@@ -2519,86 +2573,157 @@ export function createBhoteKoshiEventLayer({
|
||||
updateProgress(_progress);
|
||||
}
|
||||
|
||||
function createFloodDataSource() {
|
||||
const tileSafe = usesPhotorealFloodSurface();
|
||||
_floodSurfaceMode = tileSafe ? 'tiles' : 'terrain';
|
||||
const haloMaterial = new Cesium.PolylineDashMaterialProperty({
|
||||
color: FLOOD_COLOR.withAlpha(0.38),
|
||||
dashLength: 18,
|
||||
});
|
||||
const coreMaterial = new Cesium.PolylineGlowMaterialProperty({
|
||||
color: FLOOD_COLOR.withAlpha(0.96),
|
||||
glowPower: 0.24,
|
||||
taperPower: 0.7,
|
||||
});
|
||||
_floodDataSource = new Cesium.CustomDataSource('bhote-koshi-flood');
|
||||
_floodHalo = _floodDataSource.entities.add({
|
||||
id: 'bhote-koshi-flood-halo',
|
||||
/** The flood's draw sets, drawing nothing until the story shows it. */
|
||||
function createFloodSets() {
|
||||
_floodSurfaceMode = usesPhotorealFloodSurface() ? 'tiles' : 'terrain';
|
||||
const draw = drawOf(_viewer);
|
||||
const prefix = `${BHOTE_KOSHI_LAYER_ID}:${_serial}`;
|
||||
// Presentation only: clicks go through to what is under them.
|
||||
_floodSets = {
|
||||
lines: draw.lines({ id: `${prefix}:flood`, pickable: false }),
|
||||
surge: draw.points({
|
||||
id: `${prefix}:surge-front`,
|
||||
pickable: false,
|
||||
clampTo: 'both',
|
||||
}),
|
||||
};
|
||||
resetFloodDrawn();
|
||||
}
|
||||
|
||||
function resetFloodDrawn() {
|
||||
_floodShow = false;
|
||||
_surgeShow = false;
|
||||
_surgePosition = null;
|
||||
_lastSurgeVisible = null;
|
||||
_floodDrawn = {
|
||||
positions: null,
|
||||
show: false,
|
||||
polyline: {
|
||||
positions: new Cesium.CallbackProperty(
|
||||
() => _corridorPositionCache.positions,
|
||||
false,
|
||||
),
|
||||
width: 18,
|
||||
// Dynamic non-ground Cesium lines do not support depthFailMaterial.
|
||||
// Classify the active surface so later-refined mesh tiles cannot bury it.
|
||||
clampToGround: true,
|
||||
material: haloMaterial,
|
||||
classificationType: tileSafe
|
||||
? Cesium.ClassificationType.BOTH
|
||||
: Cesium.ClassificationType.TERRAIN,
|
||||
surge: null,
|
||||
surgeShow: false,
|
||||
};
|
||||
}
|
||||
|
||||
function removeFloodSets() {
|
||||
_floodSets?.lines.dispose();
|
||||
_floodSets?.surge.dispose();
|
||||
_floodSets = null;
|
||||
_floodSurfaceMode = null;
|
||||
resetFloodDrawn();
|
||||
}
|
||||
|
||||
/**
|
||||
* The corridor's lines along `positions`: a dashed halo under a glowing
|
||||
* core, draped on the surface the flood is drawn on (tiles too under
|
||||
* photoreal, so later-refined tiles cannot bury it).
|
||||
*/
|
||||
function floodLines(positions, show) {
|
||||
const clampTo = _floodSurfaceMode === 'tiles' ? 'both' : 'terrain';
|
||||
return [
|
||||
{
|
||||
id: FLOOD_HALO_ID,
|
||||
positions,
|
||||
widthPx: 18,
|
||||
mode: 'draped',
|
||||
clampTo,
|
||||
style: { kind: 'dash', color: FLOOD_HALO_COLOR, length: 18 },
|
||||
show,
|
||||
},
|
||||
});
|
||||
_floodCore = _floodDataSource.entities.add({
|
||||
id: 'bhote-koshi-flood-core',
|
||||
show: false,
|
||||
polyline: {
|
||||
positions: new Cesium.CallbackProperty(
|
||||
() => _corridorPositionCache.positions,
|
||||
false,
|
||||
),
|
||||
width: 5,
|
||||
clampToGround: true,
|
||||
material: coreMaterial,
|
||||
classificationType: tileSafe
|
||||
? Cesium.ClassificationType.BOTH
|
||||
: Cesium.ClassificationType.TERRAIN,
|
||||
{
|
||||
id: FLOOD_CORE_ID,
|
||||
positions,
|
||||
widthPx: 5,
|
||||
mode: 'draped',
|
||||
clampTo,
|
||||
style: {
|
||||
kind: 'glow',
|
||||
color: FLOOD_CORE_COLOR,
|
||||
power: 0.24,
|
||||
taper: 0.7,
|
||||
},
|
||||
show,
|
||||
},
|
||||
});
|
||||
_surgePoint = _floodDataSource.entities.add({
|
||||
id: 'bhote-koshi-surge-front',
|
||||
show: false,
|
||||
position: Cesium.Cartesian3.ZERO,
|
||||
point: {
|
||||
pixelSize: 11,
|
||||
color: SURGE_COLOR,
|
||||
outlineColor: Cesium.Color.BLACK.withAlpha(0.85),
|
||||
outlineWidth: 3,
|
||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||
disableDepthTestDistance: tileSafe ? Number.POSITIVE_INFINITY : 0,
|
||||
},
|
||||
});
|
||||
_viewer.dataSources.add(_floodDataSource);
|
||||
];
|
||||
}
|
||||
|
||||
function surgeItem(position, show) {
|
||||
return {
|
||||
id: SURGE_FRONT_ID,
|
||||
pos: position,
|
||||
height: 'clampGround',
|
||||
pixelSize: 11,
|
||||
color: SURGE_COLOR,
|
||||
outlineColor: SURGE_OUTLINE_COLOR,
|
||||
outlineWidth: 3,
|
||||
disableDepthTest:
|
||||
_floodSurfaceMode === 'tiles' ? Number.POSITIVE_INFINITY : 0,
|
||||
show,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the flood as it now stands, changing only what changed: the
|
||||
* corridor where it has grown to and whether it shows, and the surge
|
||||
* front's place and whether it shows.
|
||||
*/
|
||||
function drawFlood() {
|
||||
if (!_floodSets) return;
|
||||
const drawn = _floodDrawn;
|
||||
const positions = _corridorPositionCache.positions;
|
||||
if (positions.length > 1) {
|
||||
if (positions !== drawn.positions || _floodShow !== drawn.show) {
|
||||
_floodSets.lines.upsert(floodLines(positions, _floodShow));
|
||||
drawn.positions = positions;
|
||||
drawn.show = _floodShow;
|
||||
}
|
||||
} else if (drawn.show) {
|
||||
// Too short to be a line: the last one drawn hides, kept so the next
|
||||
// can still be drawn where it moves in the same frame.
|
||||
_floodSets.lines.upsert(floodLines(drawn.positions, false));
|
||||
drawn.show = false;
|
||||
}
|
||||
if (
|
||||
_surgePosition &&
|
||||
(!samePoint(_surgePosition, drawn.surge) ||
|
||||
_surgeShow !== drawn.surgeShow)
|
||||
) {
|
||||
drawn.surge = _surgePosition;
|
||||
drawn.surgeShow = _surgeShow;
|
||||
_floodSets.surge.upsert([surgeItem(drawn.surge, _surgeShow)]);
|
||||
}
|
||||
}
|
||||
|
||||
function syncFloodSurfaceMode() {
|
||||
const nextMode = usesPhotorealFloodSurface() ? 'tiles' : 'terrain';
|
||||
if (!_viewer || !_floodDataSource || _floodSurfaceMode === nextMode) return;
|
||||
_viewer.dataSources.remove(_floodDataSource, true);
|
||||
_floodDataSource = null;
|
||||
_floodHalo = null;
|
||||
_floodCore = null;
|
||||
_surgePoint = null;
|
||||
_lastSurgePosition = null;
|
||||
_lastSurgeVisible = null;
|
||||
if (!_viewer || !_floodSets || _floodSurfaceMode === nextMode) return;
|
||||
// Drawn anew on the other surface as the story next moves.
|
||||
removeFloodSets();
|
||||
_corridorPositionCache = { visibleCount: -1, positions: [] };
|
||||
createFloodDataSource();
|
||||
createFloodSets();
|
||||
}
|
||||
|
||||
/** The canvas the scene is drawn on, for its pointer events. */
|
||||
function sceneCanvas() {
|
||||
if (!_viewer) return null;
|
||||
return rendererOf(_viewer)?.canvas ?? _viewer.scene?.canvas ?? null;
|
||||
}
|
||||
|
||||
/** The split as the divider moves it: the globe's, through its port. */
|
||||
function splitScene() {
|
||||
const imagery = findGlobe(_viewer)?.imagery;
|
||||
if (!imagery?.setSplit) return null;
|
||||
return {
|
||||
get splitPosition() {
|
||||
return imagery.getSplit();
|
||||
},
|
||||
set splitPosition(value) {
|
||||
imagery.setSplit(value);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function createSplitControl(event) {
|
||||
_splitControl = createImagerySplit({
|
||||
scene: _viewer.scene,
|
||||
scene: splitScene(),
|
||||
initialValue: _split,
|
||||
id: 'bhote-koshi-split-line',
|
||||
handleClass: 'bhote-koshi-split-handle',
|
||||
@@ -2618,7 +2743,7 @@ export function createBhoteKoshiEventLayer({
|
||||
function applyCinematicCamera() {
|
||||
if (
|
||||
!_cinematicActive ||
|
||||
!_viewer?.camera ||
|
||||
!findCamera(_viewer) ||
|
||||
_cinematicKeyframes.length === 0
|
||||
)
|
||||
return;
|
||||
@@ -2629,8 +2754,8 @@ export function createBhoteKoshiEventLayer({
|
||||
_cinematicPose,
|
||||
);
|
||||
if (!pose) return;
|
||||
_cinematicOffset.heading = Cesium.Math.toRadians(pose.headingDeg);
|
||||
_cinematicOffset.pitch = Cesium.Math.toRadians(pose.pitchDeg);
|
||||
_cinematicOffset.heading = toRadians(pose.headingDeg);
|
||||
_cinematicOffset.pitch = toRadians(pose.pitchDeg);
|
||||
_cinematicOffset.range = pose.rangeM;
|
||||
findCamera(_viewer)?.lookAt(pose.target, _cinematicOffset);
|
||||
_lastCinematicProgress = _progress;
|
||||
@@ -2753,7 +2878,7 @@ export function createBhoteKoshiEventLayer({
|
||||
}
|
||||
|
||||
function attachCameraInputRelease() {
|
||||
_cameraInputTarget = _viewer?.scene?.canvas || null;
|
||||
_cameraInputTarget = sceneCanvas();
|
||||
for (const type of CINEMATIC_INPUT_EVENTS) {
|
||||
_cameraInputTarget?.addEventListener?.(type, handleManualCameraInput);
|
||||
}
|
||||
@@ -2799,7 +2924,7 @@ export function createBhoteKoshiEventLayer({
|
||||
}
|
||||
|
||||
function attachEvidenceCardActivation() {
|
||||
_evidenceClickTarget = _viewer?.scene?.canvas || null;
|
||||
_evidenceClickTarget = sceneCanvas();
|
||||
_evidenceClickTarget?.addEventListener?.('click', handleEvidenceCardClick);
|
||||
}
|
||||
|
||||
@@ -3248,7 +3373,8 @@ export function createBhoteKoshiEventLayer({
|
||||
function syncPresentationMode() {
|
||||
const sceneDirected = _presentation === BHOTE_KOSHI_SCENE_PRESENTATION;
|
||||
const imageryAvailable =
|
||||
!sceneDirected || _sceneControls.imageryComparison === true;
|
||||
!_imageryFailed &&
|
||||
(!sceneDirected || _sceneControls.imageryComparison === true);
|
||||
const scrubberAvailable =
|
||||
!sceneDirected || Boolean(_sceneController?.seekScene);
|
||||
const knownSceneBeat =
|
||||
@@ -3298,13 +3424,13 @@ export function createBhoteKoshiEventLayer({
|
||||
}
|
||||
|
||||
function updateFloodTrace(progress) {
|
||||
if (!_floodHalo || !_floodCore) return;
|
||||
if (!_floodSets) return;
|
||||
if (
|
||||
_presentation === BHOTE_KOSHI_SCENE_PRESENTATION &&
|
||||
_sceneSurface !== BHOTE_KOSHI_SCENE_EVIDENCE_BEAT
|
||||
) {
|
||||
_floodHalo.show = false;
|
||||
_floodCore.show = false;
|
||||
_floodShow = false;
|
||||
drawFlood();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
@@ -3315,31 +3441,24 @@ export function createBhoteKoshiEventLayer({
|
||||
)
|
||||
)
|
||||
return;
|
||||
const positions = _corridorPositionCache.positions;
|
||||
_floodHalo.show = positions.length > 1;
|
||||
_floodCore.show = positions.length > 1;
|
||||
_floodShow = _corridorPositionCache.positions.length > 1;
|
||||
drawFlood();
|
||||
}
|
||||
|
||||
function updateSurgeFront(progress) {
|
||||
if (!_surgePoint) return;
|
||||
if (!_floodSets) return;
|
||||
if (
|
||||
_presentation === BHOTE_KOSHI_SCENE_PRESENTATION &&
|
||||
_sceneSurface !== BHOTE_KOSHI_SCENE_EVIDENCE_BEAT
|
||||
) {
|
||||
_surgePoint.show = false;
|
||||
_surgeShow = false;
|
||||
drawFlood();
|
||||
return;
|
||||
}
|
||||
const headPosition = _corridorPositionCache.headPosition;
|
||||
if (
|
||||
headPosition &&
|
||||
!Cesium.Cartesian3.equals(_lastSurgePosition, headPosition)
|
||||
) {
|
||||
_surgePoint.position = headPosition;
|
||||
_lastSurgePosition = Cesium.Cartesian3.clone(
|
||||
headPosition,
|
||||
_lastSurgePosition || new Cesium.Cartesian3(),
|
||||
);
|
||||
}
|
||||
// A copy, as the cache's head is written in place as the flood moves.
|
||||
if (headPosition && !samePoint(_surgePosition, headPosition))
|
||||
_surgePosition = clone(headPosition);
|
||||
const visible =
|
||||
Boolean(headPosition) &&
|
||||
progress > 0 &&
|
||||
@@ -3348,9 +3467,10 @@ export function createBhoteKoshiEventLayer({
|
||||
sceneKeepsFloodVisible() ||
|
||||
progress < 1);
|
||||
if (_lastSurgeVisible !== visible) {
|
||||
_surgePoint.show = visible;
|
||||
_surgeShow = visible;
|
||||
_lastSurgeVisible = visible;
|
||||
}
|
||||
drawFlood();
|
||||
}
|
||||
|
||||
function updateProgress(progress) {
|
||||
@@ -3451,11 +3571,10 @@ export function createBhoteKoshiEventLayer({
|
||||
}
|
||||
|
||||
function removeImagery() {
|
||||
if (_beforeLayer) _imageryLayerCollection?.remove(_beforeLayer, true);
|
||||
if (_afterLayer) _imageryLayerCollection?.remove(_afterLayer, true);
|
||||
_beforeLayer?.remove();
|
||||
_afterLayer?.remove();
|
||||
_beforeLayer = null;
|
||||
_afterLayer = null;
|
||||
_imageryLayerCollection = null;
|
||||
}
|
||||
|
||||
async function init(viewer) {
|
||||
@@ -3489,7 +3608,7 @@ export function createBhoteKoshiEventLayer({
|
||||
throwIfEnableCancelled(signal, _enabled);
|
||||
await syncTerrainComparison();
|
||||
throwIfEnableCancelled(signal, _enabled);
|
||||
createFloodDataSource();
|
||||
createFloodSets();
|
||||
createSplitControl(event);
|
||||
_panelRefs = createPanelRecords(event);
|
||||
_panelOwner = {};
|
||||
@@ -3614,14 +3733,7 @@ export function createBhoteKoshiEventLayer({
|
||||
closeFrame(slot.poster);
|
||||
}
|
||||
_evidenceFrameSlots = [];
|
||||
if (_floodDataSource) _viewer.dataSources.remove(_floodDataSource, true);
|
||||
_floodDataSource = null;
|
||||
_floodSurfaceMode = null;
|
||||
_floodHalo = null;
|
||||
_floodCore = null;
|
||||
_surgePoint = null;
|
||||
_lastSurgePosition = null;
|
||||
_lastSurgeVisible = null;
|
||||
removeFloodSets();
|
||||
if (_panelOwner && panelStore.panel?.owner === _panelOwner) {
|
||||
panelStore.connect(null);
|
||||
panelStore.publish(null);
|
||||
|
||||
Reference in new issue
Block a user