import { PMREMGenerator, Scene, Texture, WebGLRenderer } from "three"; /** * Compatibility helpers that paper over differences between the classic `WebGLRenderer` and the * (experimental) `WebGPURenderer` / node-based renderer family. Keeps backend-specific branching * out of the engine core. */ /** * Minimal PMREMGenerator surface used by the engine — satisfied by both the classic (WebGL) * `PMREMGenerator` and the backend-agnostic one used with the `WebGPURenderer`. */ export interface IPMREMGenerator { fromScene(scene: Scene, sigma?: number, near?: number, far?: number): { texture: Texture }; dispose(): void; } /** * Backend-agnostic PMREMGenerator class (from `three/webgpu`), registered when a `WebGPURenderer` * is created. The classic three `PMREMGenerator` is WebGL-only, and `three/webgpu` is only loaded * on demand, so we can't statically import this one here. */ let _webgpuPMREMGenerator: typeof import("three/webgpu").PMREMGenerator | undefined; /** * Registers the backend-agnostic PMREMGenerator class. Called by the engine when it creates the * (experimental) `WebGPURenderer`, since `three/webgpu` is dynamically imported there. */ export function registerWebGPUPMREMGenerator(ctor: typeof import("three/webgpu").PMREMGenerator): void { _webgpuPMREMGenerator = ctor; } /** * Creates a PMREMGenerator appropriate for the given renderer. The classic three `PMREMGenerator` * is WebGL-only (it reads `renderer.state`); a `WebGPURenderer` (including its `forceWebGL` / WebGL2 * mode) needs the backend-agnostic one. Dispose the returned generator when done. */ export function createPMREMGenerator(renderer: WebGLRenderer): IPMREMGenerator { const isWebGPURenderer = (renderer as unknown as { isWebGPURenderer?: boolean }).isWebGPURenderer === true; if (isWebGPURenderer && _webgpuPMREMGenerator) { // renderer is a WebGPURenderer at runtime (stored as WebGLRenderer in the experimental path). return new _webgpuPMREMGenerator(renderer as any); } return new PMREMGenerator(renderer); }