Provide the single-loadout Scene API, SAB-backed meshes, cameras, materials, lights, workers, post effects, and tutorial playgrounds. Batch matching row growth so active GPU loadouts refresh once. Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { Scene } from "../Scene";
|
|
|
|
let nextPostProcess = 1;
|
|
|
|
/** Shared graph-membership behavior for the small post-process handles. */
|
|
export class PostProcess {
|
|
readonly scene: Scene;
|
|
readonly id: string;
|
|
readonly kind: string;
|
|
options: Record<string, unknown>;
|
|
enabled: boolean;
|
|
ready: Promise<void>;
|
|
|
|
protected constructor(scene: Scene, kind: string, options: Record<string, unknown> = {}) {
|
|
this.scene = scene;
|
|
this.kind = kind;
|
|
this.id = `${kind}-${nextPostProcess++}`;
|
|
this.enabled = options.enabled !== false;
|
|
const { enabled: _, ...effectOptions } = options;
|
|
this.options = effectOptions;
|
|
this.ready = scene.setPostProcess(this, this.enabled);
|
|
}
|
|
|
|
setEnabled(enabled: boolean) {
|
|
this.enabled = enabled;
|
|
this.ready = this.scene.setPostProcess(this, enabled);
|
|
return this.ready;
|
|
}
|
|
|
|
update(options: Record<string, unknown>) {
|
|
this.options = { ...this.options, ...options };
|
|
this.ready = this.scene.setPostProcess(this, this.enabled);
|
|
return this.ready;
|
|
}
|
|
|
|
dispose() { return this.setEnabled(false); }
|
|
}
|