mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
Add pointer-driven camera scripts with Cesium goldens, and count wheel lines as Cesium does
Five new camera conformance scripts move the camera by user input: a left drag that coasts, thirty pixel-mode and thirty line-mode wheel notches from 5 km, a middle-drag tilt, and Shift and Ctrl drags held too long to coast. The runner turns input steps into pointer events for a driver: a move starts where the pointer last pressed or moved and carries the held button. The golden recorder now drives Cesium's own screen-space camera controller on a stand-in canvas, with Date on the virtual clock so inertia is deterministic. The existing goldens are unchanged. A harness that answers pointer input sets cameraInput and a pointer hook. Harnesses without it, such as the stub, skip the input scripts. The input port reported a line-mode wheel at 33 1/3 pixels a line. It now counts lines as the reference does, 40 pixels a line and 3 lines a page, so a pixel or line wheel converts back to the same pixels.
This commit is contained in:
1 parent
ef616b7905
commit
90499762f5
16 files changed
+1055
-38
No files matched your search
@@ -11,8 +11,14 @@ import {
|
||||
CAMERA_SCRIPTS,
|
||||
DEFAULT_TOLERANCE,
|
||||
runConformance,
|
||||
usesInput,
|
||||
} from '../conformance/index.js';
|
||||
import { FRAME_MS, headlessCamera, withVirtualClock } from './cameraGoldens.js';
|
||||
import {
|
||||
FRAME_MS,
|
||||
dispatchPointer,
|
||||
headlessCamera,
|
||||
withVirtualClock,
|
||||
} from './cameraGoldens.js';
|
||||
import { createCesiumCamera } from './camera.js';
|
||||
import { createCesiumPorts } from './ports.js';
|
||||
import { cameraOf } from '../rendererOf.js';
|
||||
@@ -27,14 +33,20 @@ const QUERY_RECORDS = new Set([
|
||||
/** Commands and records the port does not have yet. */
|
||||
const MISSING = new Set([]);
|
||||
|
||||
const runnable = CAMERA_SCRIPTS.filter((script) =>
|
||||
script.steps.every(
|
||||
(step) =>
|
||||
!MISSING.has(step.do) &&
|
||||
!MISSING.has(step.record) &&
|
||||
!QUERY_RECORDS.has(step.record),
|
||||
),
|
||||
const runnable = CAMERA_SCRIPTS.filter(
|
||||
(script) =>
|
||||
!usesInput(script) &&
|
||||
script.steps.every(
|
||||
(step) =>
|
||||
!MISSING.has(step.do) &&
|
||||
!MISSING.has(step.record) &&
|
||||
!QUERY_RECORDS.has(step.record),
|
||||
),
|
||||
).map((script) => `camera.trace.${script.name}`);
|
||||
/** The scripts that drive the camera by pointer and wheel. */
|
||||
const INPUT_CHECKS = new Set(
|
||||
CAMERA_SCRIPTS.filter(usesInput).map((s) => `camera.trace.${s.name}`),
|
||||
);
|
||||
|
||||
const CHECKS = new Set([
|
||||
...runnable,
|
||||
@@ -42,11 +54,11 @@ const CHECKS = new Set([
|
||||
'camera.controls.settings',
|
||||
]);
|
||||
|
||||
function headlessHarness(clock) {
|
||||
function headlessHarness(clock, { input = false } = {}) {
|
||||
return {
|
||||
name: 'cesium (headless camera)',
|
||||
async create() {
|
||||
const { scene } = headlessCamera();
|
||||
const { scene } = headlessCamera({ input });
|
||||
for (const name of ['preUpdate', 'postUpdate', 'preRender', 'postRender'])
|
||||
scene[name] = new Cesium.Event();
|
||||
scene.primitives = { add() {}, remove() {} };
|
||||
@@ -65,10 +77,30 @@ function headlessHarness(clock) {
|
||||
frameScene() {
|
||||
clock.now += FRAME_MS;
|
||||
scene.tweens.update();
|
||||
if (input) scene.screenSpaceCameraController.update();
|
||||
scene.postUpdate.raiseEvent(scene);
|
||||
},
|
||||
scene,
|
||||
};
|
||||
},
|
||||
...(input
|
||||
? {
|
||||
cameraInput: true,
|
||||
// The contract's event back as the DOM's, a wheel in lines: at 40
|
||||
// px a line, Cesium reads the pixels the script scrolled.
|
||||
pointer: (r, type, x, y, extra) =>
|
||||
dispatchPointer(r.scene, {
|
||||
type,
|
||||
position: { x, y },
|
||||
endPosition: extra.endPosition,
|
||||
button: extra.button ?? 0,
|
||||
modifiers: extra.modifiers,
|
||||
...(type === 'wheel'
|
||||
? { wheel: { deltaY: extra.delta, deltaMode: 1 } }
|
||||
: {}),
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
frame: async (r) => r.frameScene(),
|
||||
now: () => clock.now,
|
||||
toEcef: (p) => {
|
||||
@@ -96,6 +128,22 @@ test('the camera port retraces the reference flights, views and frames', async (
|
||||
assert.equal(report.passed, CHECKS.size);
|
||||
});
|
||||
|
||||
test('Cesium’s own controls under the camera port retrace the drags and wheels, each wheel sent back in the input port’s lines', async () => {
|
||||
assert.ok(INPUT_CHECKS.size >= 4, `only ${INPUT_CHECKS.size} input scripts`);
|
||||
const report = await withVirtualClock((clock) =>
|
||||
runConformance(headlessHarness(clock, { input: true }), {
|
||||
only: (id) => INPUT_CHECKS.has(id),
|
||||
}),
|
||||
);
|
||||
assert.deepEqual(
|
||||
report.results
|
||||
.filter((r) => r.status !== 'pass')
|
||||
.map((r) => `${r.id}: ${r.status} ${r.detail}`),
|
||||
[],
|
||||
);
|
||||
assert.equal(report.passed, INPUT_CHECKS.size);
|
||||
});
|
||||
|
||||
test('a cancelled flight has let go before its callbacks, so they can fly again', async () => {
|
||||
await withVirtualClock(async (clock) => {
|
||||
const { scene, camera } = headlessCamera();
|
||||
|
||||
Reference in new issue
Block a user