mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 02:02:21 +00:00
The dispatcher now builds on renderer.input and the query port, with
positions as plain {x, y}. Its viewer access count is zero and it leaves
the Cesium allow-list. Layers that read the raw engine pick read the Hit,
drawHit or event.native instead, and pickRegistry's resolvePickId and
pickContact take a Hit, with the raw versions kept in the Cesium adapter.
rendererOf gains findInput, provideUnboundInput and provideNativeClick.
event.native carries the engine's pick, drill and pickWindow, and picks
through the follow helper happen inside it. An unbound input port
survives the viewer being bound until it is released.
The query port's pick memo is now per task rather than per frame,
because Cesium's own picks advance the frame number. A click on the sky
skips the depth pass when nothing is on the ray. Touch contact search
keeps its eight-deep drill in a 14x14 window.
56 lines
2.0 KiB
JavaScript
56 lines
2.0 KiB
JavaScript
/**
|
|
* @module sensorPick
|
|
* @description Where a click lands in the pick buffer while a sensor style
|
|
* distorts the picture. Picks read the scene before post-processing, so under
|
|
* the thermal or surveillance shader the pixel the user clicked shows a
|
|
* different spot of the scene: map it back through the shader's barrel
|
|
* distortion and quantization first.
|
|
*/
|
|
import { styleStagesOf } from '../styles/styleStages.js';
|
|
|
|
const SENSOR_STYLES = ['thermal', 'surveillance'];
|
|
|
|
/**
|
|
* The pick-buffer position for a screen click.
|
|
* @param {object} host The scene object the styles are recorded on (the
|
|
* viewer the application's visual effects are made for).
|
|
* @param {{x: number, y: number}} position CSS pixels on the canvas.
|
|
* @param {{width: number, height: number, clientWidth: number,
|
|
* clientHeight: number}} canvas The canvas the scene draws in.
|
|
* @returns {{x: number, y: number}} A new position; the click's own is left
|
|
* alone.
|
|
*/
|
|
export function sensorPickPosition(host, position, canvas) {
|
|
const out = { x: position.x, y: position.y };
|
|
const stages = styleStagesOf(host);
|
|
if (!stages || !canvas) return out;
|
|
for (const style of SENSOR_STYLES) {
|
|
const stage = stages[style];
|
|
if (!stage?.enabled) continue;
|
|
const intensity = stage.uniforms.intensity;
|
|
const w = canvas.clientWidth,
|
|
h = canvas.clientHeight;
|
|
let u = out.x / w,
|
|
v = 1 - out.y / h;
|
|
if (style === 'surveillance') {
|
|
const x = u * 2 - 1,
|
|
y = v * 2 - 1,
|
|
r2 = x * x + y * y;
|
|
const d = 1 + r2 * intensity * 0.25 + r2 * r2 * intensity * 0.075;
|
|
u = (x * d + 1) / 2;
|
|
v = (y * d + 1) / 2;
|
|
}
|
|
const grid = 1 + (stage.uniforms.pixelation - 1) * intensity;
|
|
u +=
|
|
((Math.floor((u * canvas.width) / grid) * grid) / canvas.width - u) *
|
|
intensity;
|
|
v +=
|
|
((Math.floor((v * canvas.height) / grid) * grid) / canvas.height - v) *
|
|
intensity;
|
|
out.x = u * w;
|
|
out.y = (1 - v) * h;
|
|
return out;
|
|
}
|
|
return out;
|
|
}
|