From cc0d10f89cbf69c732344c2bef7eef7a548c9ee4 Mon Sep 17 00:00:00 2001 From: Paras Sanghavi Date: Sun, 21 Mar 2021 02:35:09 -0700 Subject: [PATCH] chore(TS): Move RenderPass into a TypeScript class def (#40) --- .../{RenderPass.js => RenderPass.ts} | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) rename src/postprocessing/{RenderPass.js => RenderPass.ts} (52%) diff --git a/src/postprocessing/RenderPass.js b/src/postprocessing/RenderPass.ts similarity index 52% rename from src/postprocessing/RenderPass.js rename to src/postprocessing/RenderPass.ts index c25b00ff..85289ce2 100644 --- a/src/postprocessing/RenderPass.js +++ b/src/postprocessing/RenderPass.ts @@ -1,31 +1,40 @@ -import { Color } from 'three' -import { Pass } from '../postprocessing/Pass' - -var RenderPass = function (scene, camera, overrideMaterial, clearColor, clearAlpha) { - Pass.call(this) - - this.scene = scene - this.camera = camera - - this.overrideMaterial = overrideMaterial - - this.clearColor = clearColor - this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0 - - this.clear = true - this.clearDepth = false - this.needsSwap = false - this._oldClearColor = new Color() -} - -RenderPass.prototype = Object.assign(Object.create(Pass.prototype), { - constructor: RenderPass, - - render: function (renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */) { - var oldAutoClear = renderer.autoClear +import { Camera, Color, Material, Scene, WebGLRenderTarget, WebGLRenderer } from 'three' +import { Pass } from './Pass' + +class RenderPass extends Pass { + public scene: Scene + public camera: Camera + public overrideMaterial: Material | undefined + public clearColor: Color | undefined + public clearAlpha: number + public clearDepth = false + private _oldClearColor = new Color() + + constructor(scene: Scene, camera: Camera, overrideMaterial?: Material, clearColor?: Color, clearAlpha = 0) { + super() + + this.scene = scene + this.camera = camera + + this.overrideMaterial = overrideMaterial + + this.clearColor = clearColor + this.clearAlpha = clearAlpha + + this.clear = true + this.needsSwap = false + } + + public render( + renderer: WebGLRenderer, + writeBuffer: WebGLRenderTarget, + readBuffer: WebGLRenderTarget /*, deltaTime, maskActive */, + ): void { + let oldAutoClear = renderer.autoClear renderer.autoClear = false - var oldClearAlpha, oldOverrideMaterial + let oldClearAlpha + let oldOverrideMaterial: Material | null = null if (this.overrideMaterial !== undefined) { oldOverrideMaterial = this.scene.overrideMaterial @@ -59,7 +68,7 @@ RenderPass.prototype = Object.assign(Object.create(Pass.prototype), { } renderer.autoClear = oldAutoClear - }, -}) + } +} export { RenderPass }