From 6e862e7da4487e02d10edd86f5b53a5b0a466e22 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Tue, 4 Jul 2023 14:06:22 -0400 Subject: [PATCH] Extend WebGLMultipleRenderTargets from WebGLRenderTarget (#519) * Extend WebGLMultipleRenderTargets from WebGLRenderTarget * Make it generic * It does have a depth * Update expected types * No need to redeclare --- .../renderers/WebGLMultipleRenderTargets.d.ts | 20 +----- .../src/renderers/WebGLRenderTarget.d.ts | 66 ++++--------------- .../examples/jsm/postprocessing/SavePass.ts | 4 +- 3 files changed, 17 insertions(+), 73 deletions(-) diff --git a/types/three/src/renderers/WebGLMultipleRenderTargets.d.ts b/types/three/src/renderers/WebGLMultipleRenderTargets.d.ts index e2afa2610..899613c28 100644 --- a/types/three/src/renderers/WebGLMultipleRenderTargets.d.ts +++ b/types/three/src/renderers/WebGLMultipleRenderTargets.d.ts @@ -1,16 +1,7 @@ -import { EventDispatcher } from '../core/EventDispatcher'; import { Texture } from '../textures/Texture'; -import { WebGLRenderTargetOptions } from './WebGLRenderTarget'; - -/** - * This class originall extended WebGLMultipleRenderTarget - * However, there are some issues with this method as documented below - */ -export class WebGLMultipleRenderTargets extends EventDispatcher { - texture: Texture[]; - - readonly isWebGLMultipleRenderTargets = true; +import { WebGLRenderTarget, WebGLRenderTargetOptions } from './WebGLRenderTarget'; +export class WebGLMultipleRenderTargets extends WebGLRenderTarget { /** * @param width The width of the render target. * @param height The height of the render target. @@ -20,10 +11,5 @@ export class WebGLMultipleRenderTargets extends EventDispatcher { */ constructor(width?: number, height?: number, count?: number, options?: WebGLRenderTargetOptions); - setSize(width: number, height: number, depth?: number): this; - copy(source: WebGLMultipleRenderTargets): this; - clone(): this; - dispose(): void; - // This is an available method, however it will break the code see https://github.com/mrdoob/three.js/issues/21930 - setTexture(texture: Texture): void; + readonly isWebGLMultipleRenderTargets: true; } diff --git a/types/three/src/renderers/WebGLRenderTarget.d.ts b/types/three/src/renderers/WebGLRenderTarget.d.ts index 86147f9e5..9b5ded8ba 100644 --- a/types/three/src/renderers/WebGLRenderTarget.d.ts +++ b/types/three/src/renderers/WebGLRenderTarget.d.ts @@ -1,7 +1,7 @@ -import { Vector4 } from './../math/Vector4'; -import { Texture } from './../textures/Texture'; -import { DepthTexture } from './../textures/DepthTexture'; -import { EventDispatcher } from './../core/EventDispatcher'; +import { Vector4 } from '../math/Vector4'; +import { Texture } from '../textures/Texture'; +import { DepthTexture } from '../textures/DepthTexture'; +import { EventDispatcher } from '../core/EventDispatcher'; import { Wrapping, TextureDataType, @@ -16,27 +16,28 @@ export interface WebGLRenderTargetOptions { wrapT?: Wrapping | undefined; magFilter?: MagnificationTextureFilter | undefined; minFilter?: MinificationTextureFilter | undefined; + generateMipmaps?: boolean | undefined; // true; format?: number | undefined; // RGBAFormat; type?: TextureDataType | undefined; // UnsignedByteType; anisotropy?: number | undefined; // 1; + colorSpace?: ColorSpace | undefined; depthBuffer?: boolean | undefined; // true; stencilBuffer?: boolean | undefined; // false; - generateMipmaps?: boolean | undefined; // true; depthTexture?: DepthTexture | undefined; - /** @deprecated Use 'colorSpace' in three.js r152+. */ - encoding?: TextureEncoding | undefined; - colorSpace?: ColorSpace | undefined; - /** * Defines the count of MSAA samples. Can only be used with WebGL 2. Default is **0**. * @default 0 */ samples?: number; + /** @deprecated Use 'colorSpace' in three.js r152+. */ + encoding?: TextureEncoding | undefined; } -export class WebGLRenderTarget extends EventDispatcher { +export class WebGLRenderTarget extends EventDispatcher { constructor(width?: number, height?: number, options?: WebGLRenderTargetOptions); + readonly isWebGLRenderTarget: true; + width: number; height: number; depth: number; @@ -47,7 +48,7 @@ export class WebGLRenderTarget extends EventDispatcher { */ scissorTest: boolean; viewport: Vector4; - texture: Texture; + texture: TTexture; /** * @default true @@ -70,49 +71,6 @@ export class WebGLRenderTarget extends EventDispatcher { */ samples: number; - readonly isWebGLRenderTarget: true; - - /** - * @deprecated Use {@link Texture#wrapS texture.wrapS} instead. - */ - wrapS: any; - /** - * @deprecated Use {@link Texture#wrapT texture.wrapT} instead. - */ - wrapT: any; - /** - * @deprecated Use {@link Texture#magFilter texture.magFilter} instead. - */ - magFilter: any; - /** - * @deprecated Use {@link Texture#minFilter texture.minFilter} instead. - */ - minFilter: any; - /** - * @deprecated Use {@link Texture#anisotropy texture.anisotropy} instead. - */ - anisotropy: any; - /** - * @deprecated Use {@link Texture#offset texture.offset} instead. - */ - offset: any; - /** - * @deprecated Use {@link Texture#repeat texture.repeat} instead. - */ - repeat: any; - /** - * @deprecated Use {@link Texture#format texture.format} instead. - */ - format: any; - /** - * @deprecated Use {@link Texture#type texture.type} instead. - */ - type: any; - /** - * @deprecated Use {@link Texture#generateMipmaps texture.generateMipmaps} instead. - */ - generateMipmaps: any; - setSize(width: number, height: number, depth?: number): void; clone(): this; copy(source: WebGLRenderTarget): this; diff --git a/types/three/test/unit/examples/jsm/postprocessing/SavePass.ts b/types/three/test/unit/examples/jsm/postprocessing/SavePass.ts index 490ac60f0..4515f7fa5 100644 --- a/types/three/test/unit/examples/jsm/postprocessing/SavePass.ts +++ b/types/three/test/unit/examples/jsm/postprocessing/SavePass.ts @@ -2,7 +2,7 @@ import * as THREE from 'three'; import { SavePass } from 'three/examples/jsm/postprocessing/SavePass'; let pass = new SavePass(); // $ExpectType SavePass -let rt = pass.renderTarget; // $ExpectType WebGLRenderTarget +let rt = pass.renderTarget; // $ExpectType WebGLRenderTarget pass = new SavePass(new THREE.WebGLRenderTarget(128, 128)); // $ExpectType SavePass -rt = pass.renderTarget; // $ExpectType WebGLRenderTarget +rt = pass.renderTarget; // $ExpectType WebGLRenderTarget