mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Unsubscribe removed Navara effects and models from warm view frames
This commit is contained in:
1 parent
14f7b32537
commit
05b646daa3
16 files changed
+90
-19
No files matched your search
@@ -0,0 +1,18 @@
|
||||
// Navara auto-binds descriptor.update on creation but does not unregister
|
||||
// that bound function when its handle is deleted. GEV's synchronous effects
|
||||
// and meshes subscribe with their own callback so a parked view can be reused.
|
||||
export function withFrameUpdates(Base) {
|
||||
return class extends Base {
|
||||
#frame = (time) => this.updateFrame(time);
|
||||
|
||||
onCreate() {
|
||||
super.onCreate();
|
||||
this.view.on('preRender', this.#frame);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.view.off('preRender', this.#frame);
|
||||
super.onDestroy();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { withFrameUpdates } from './frameDescriptor.js';
|
||||
|
||||
test('deleting a descriptor unsubscribes only that renderer from the warm view', () => {
|
||||
const frames = new Set();
|
||||
const view = {
|
||||
on(name, cb) {
|
||||
assert.equal(name, 'preRender');
|
||||
frames.add(cb);
|
||||
},
|
||||
off(name, cb) {
|
||||
assert.equal(name, 'preRender');
|
||||
frames.delete(cb);
|
||||
},
|
||||
};
|
||||
class Base {
|
||||
view = view;
|
||||
onCreate() {}
|
||||
onDestroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
}
|
||||
class Layer extends withFrameUpdates(Base) {
|
||||
ticks = [];
|
||||
updateFrame(time) {
|
||||
this.ticks.push(time);
|
||||
}
|
||||
}
|
||||
const a = new Layer(),
|
||||
b = new Layer();
|
||||
a.onCreate();
|
||||
b.onCreate();
|
||||
assert.equal(typeof a.update, 'undefined', 'no duplicate SDK subscription');
|
||||
for (const cb of frames) cb(1);
|
||||
a.onDestroy();
|
||||
for (const cb of frames) cb(2);
|
||||
assert.deepEqual(a.ticks, [1]);
|
||||
assert.deepEqual(b.ticks, [1, 2]);
|
||||
assert.equal(a.destroyed, true);
|
||||
b.onDestroy();
|
||||
assert.equal(frames.size, 0);
|
||||
});
|
||||
@@ -2,6 +2,7 @@
|
||||
// the product way (viewOptions.js) and the GlobeEngine on it. Load it with a
|
||||
// dynamic import() so Navara stays out of the Cesium-mode bundle.
|
||||
|
||||
import { withFrameUpdates } from './frameDescriptor.js';
|
||||
import ThreeView, {
|
||||
Color as NavaraColor,
|
||||
MeshDesc,
|
||||
@@ -209,6 +210,7 @@ export async function createNavaraGlobe({
|
||||
NavaraColor,
|
||||
MeshDesc,
|
||||
EffectDesc,
|
||||
LayerEffectDesc: withFrameUpdates(EffectDesc),
|
||||
NavaraEffect,
|
||||
DrapedMesh,
|
||||
setupMaterialForDrape,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
// asks for one frame (view.forceUpdate); per-frame work runs only on frames
|
||||
// the view draws anyway (S5), so an idle view stays idle.
|
||||
|
||||
import { withFrameUpdates } from '../frameDescriptor.js';
|
||||
import {
|
||||
MeshDesc,
|
||||
PickableInstancedMeshWrapper,
|
||||
@@ -25,7 +26,7 @@ import { createNavaraOverlay } from '../overlay.js';
|
||||
const DESC_NAME = 'gevMoverSet';
|
||||
const registered = new WeakSet();
|
||||
|
||||
class GevMoverSetDesc extends MeshDesc {
|
||||
class GevMoverSetDesc extends withFrameUpdates(MeshDesc) {
|
||||
constructor(view, ctx, config) {
|
||||
super(view, ctx, config);
|
||||
this.gev = config[DESC_NAME];
|
||||
@@ -59,7 +60,7 @@ class GevMoverSetDesc extends MeshDesc {
|
||||
return group;
|
||||
}
|
||||
|
||||
update(time) {
|
||||
updateFrame(time) {
|
||||
updateMover(this.gev.readFrameCamera, this.ctx, this.gev.mover, time);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,15 +27,19 @@ test('disposing a sprite atlas drops decoded images and detaches pending load ca
|
||||
const previous = globalThis.Image;
|
||||
let image;
|
||||
globalThis.Image = class {
|
||||
constructor() { image = this; }
|
||||
constructor() {
|
||||
image = this;
|
||||
}
|
||||
};
|
||||
t.after(() => {
|
||||
if (previous) globalThis.Image = previous;
|
||||
else delete globalThis.Image;
|
||||
});
|
||||
const options = normalizeMoverSetOptions({
|
||||
...spriteOptions, sprite: {
|
||||
sizePx: 24, atlas: { url: '/bracket.svg', cells: { a: [0, 0, 1, 1] } },
|
||||
...spriteOptions,
|
||||
sprite: {
|
||||
sizePx: 24,
|
||||
atlas: { url: '/bracket.svg', cells: { a: [0, 0, 1, 1] } },
|
||||
},
|
||||
});
|
||||
for (const loaded of [false, true]) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// FIRMS opts into a separate native-stage overlay before sharpening/AA.
|
||||
// Only that stage owns an encoded-RGBA8 blend target; W1 stays in place.
|
||||
|
||||
import { withFrameUpdates } from './frameDescriptor.js';
|
||||
import { EffectDesc, Pass as NavaraPass } from '@navaramap/three';
|
||||
import { GevOverlayPass } from './overlayPass.js';
|
||||
import { RGBADepthPacking, Scene } from 'three';
|
||||
@@ -20,7 +21,7 @@ export const OVERLAY_EFFECT_KEY = 'gevOverlay';
|
||||
const PRE_SHARPEN_KEY = 'gevPreSharpenOverlay';
|
||||
const registeredViews = new WeakMap();
|
||||
|
||||
class GevOverlayEffectDesc extends EffectDesc {
|
||||
class GevOverlayEffectDesc extends withFrameUpdates(EffectDesc) {
|
||||
static key = OVERLAY_EFFECT_KEY;
|
||||
// Navara takes the first existing anchor, so the latest pass comes first.
|
||||
static insertAfter = ['fxaa', 'smaa', 'gevSharpen', 'toneMapping'];
|
||||
@@ -56,7 +57,7 @@ class GevOverlayEffectDesc extends EffectDesc {
|
||||
|
||||
// Each drawn frame: the scene depth the overlays test against, then each
|
||||
// overlay's own per-frame work (pixel footprint, origin, viewport).
|
||||
update(time) {
|
||||
updateFrame(time) {
|
||||
const mrt = this.find('mrt');
|
||||
this.overlay.uniforms.tGevSceneDepth.value =
|
||||
mrt?.depthBufferPacking === RGBADepthPacking ? mrt.depthBuffer : null;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
// has no public call to merge effects. A disabled pass is skipped: off costs
|
||||
// nothing.
|
||||
|
||||
import { withFrameUpdates } from './frameDescriptor.js';
|
||||
import { Effect as NavaraEffect, EffectDesc } from '@navaramap/three';
|
||||
import { Effect, EffectAttribute } from 'postprocessing';
|
||||
import { RGBADepthPacking, Uniform } from 'three';
|
||||
@@ -86,7 +87,7 @@ class UnsharpMaskEffect extends Effect {
|
||||
}
|
||||
|
||||
/** config.gevSharpen: { amount } (Cesium's `amount` uniform). */
|
||||
export class SharpenEffectDesc extends EffectDesc {
|
||||
export class SharpenEffectDesc extends withFrameUpdates(EffectDesc) {
|
||||
static key = SHARPEN_EFFECT_KEY;
|
||||
static insertAfter = ['toneMapping'];
|
||||
static insertBefore = ['smaa', 'fxaa', 'gevOverlay', 'final'];
|
||||
@@ -105,7 +106,7 @@ export class SharpenEffectDesc extends EffectDesc {
|
||||
|
||||
// Each frame: the scene depth for the sky mask, when Navara packs it as
|
||||
// RGBA (0.2.1 does); otherwise the whole frame is sharpened.
|
||||
update() {
|
||||
updateFrame() {
|
||||
if (!this.effect) return;
|
||||
const mrt = this.find('mrt');
|
||||
const depth =
|
||||
|
||||
Reference in new issue
Block a user