@forbespro/lead-agent
Version:
Lead Chat Agent React Component
139 lines (138 loc) • 5.72 kB
JavaScript
import { Vector2 as a, WebGLRenderTarget as d, HalfFloatType as p, NoBlending as l, Clock as c } from "three";
import { CopyShader as g } from "./index49.js";
import { ShaderPass as _ } from "./index50.js";
import { MaskPass as o, ClearMaskPass as u } from "./index51.js";
class P {
/**
* Constructs a new effect composer.
*
* @param {WebGLRenderer} renderer - The renderer.
* @param {WebGLRenderTarget} [renderTarget] - This render target and a clone will
* be used as the internal read and write buffers. If not given, the composer creates
* the buffers automatically.
*/
constructor(e, t) {
if (this.renderer = e, this._pixelRatio = e.getPixelRatio(), t === void 0) {
const s = e.getSize(new a());
this._width = s.width, this._height = s.height, t = new d(this._width * this._pixelRatio, this._height * this._pixelRatio, { type: p }), t.texture.name = "EffectComposer.rt1";
} else
this._width = t.width, this._height = t.height;
this.renderTarget1 = t, this.renderTarget2 = t.clone(), this.renderTarget2.texture.name = "EffectComposer.rt2", this.writeBuffer = this.renderTarget1, this.readBuffer = this.renderTarget2, this.renderToScreen = !0, this.passes = [], this.copyPass = new _(g), this.copyPass.material.blending = l, this.clock = new c();
}
/**
* Swaps the internal read/write buffers.
*/
swapBuffers() {
const e = this.readBuffer;
this.readBuffer = this.writeBuffer, this.writeBuffer = e;
}
/**
* Adds the given pass to the pass chain.
*
* @param {Pass} pass - The pass to add.
*/
addPass(e) {
this.passes.push(e), e.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio);
}
/**
* Inserts the given pass at a given index.
*
* @param {Pass} pass - The pass to insert.
* @param {number} index - The index into the pass chain.
*/
insertPass(e, t) {
this.passes.splice(t, 0, e), e.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio);
}
/**
* Removes the given pass from the pass chain.
*
* @param {Pass} pass - The pass to remove.
*/
removePass(e) {
const t = this.passes.indexOf(e);
t !== -1 && this.passes.splice(t, 1);
}
/**
* Returns `true` if the pass for the given index is the last enabled pass in the pass chain.
*
* @param {number} passIndex - The pass index.
* @return {boolean} Whether the the pass for the given index is the last pass in the pass chain.
*/
isLastEnabledPass(e) {
for (let t = e + 1; t < this.passes.length; t++)
if (this.passes[t].enabled)
return !1;
return !0;
}
/**
* Executes all enabled post-processing passes in order to produce the final frame.
*
* @param {number} deltaTime - The delta time in seconds. If not given, the composer computes
* its own time delta value.
*/
render(e) {
e === void 0 && (e = this.clock.getDelta());
const t = this.renderer.getRenderTarget();
let s = !1;
for (let i = 0, r = this.passes.length; i < r; i++) {
const h = this.passes[i];
if (h.enabled !== !1) {
if (h.renderToScreen = this.renderToScreen && this.isLastEnabledPass(i), h.render(this.renderer, this.writeBuffer, this.readBuffer, e, s), h.needsSwap) {
if (s) {
const f = this.renderer.getContext(), n = this.renderer.state.buffers.stencil;
n.setFunc(f.NOTEQUAL, 1, 4294967295), this.copyPass.render(this.renderer, this.writeBuffer, this.readBuffer, e), n.setFunc(f.EQUAL, 1, 4294967295);
}
this.swapBuffers();
}
o !== void 0 && (h instanceof o ? s = !0 : h instanceof u && (s = !1));
}
}
this.renderer.setRenderTarget(t);
}
/**
* Resets the internal state of the EffectComposer.
*
* @param {WebGLRenderTarget} [renderTarget] - This render target has the same purpose like
* the one from the constructor. If set, it is used to setup the read and write buffers.
*/
reset(e) {
if (e === void 0) {
const t = this.renderer.getSize(new a());
this._pixelRatio = this.renderer.getPixelRatio(), this._width = t.width, this._height = t.height, e = this.renderTarget1.clone(), e.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio);
}
this.renderTarget1.dispose(), this.renderTarget2.dispose(), this.renderTarget1 = e, this.renderTarget2 = e.clone(), this.writeBuffer = this.renderTarget1, this.readBuffer = this.renderTarget2;
}
/**
* Resizes the internal read and write buffers as well as all passes. Similar to {@link WebGLRenderer#setSize},
* this method honors the current pixel ration.
*
* @param {number} width - The width in logical pixels.
* @param {number} height - The height in logical pixels.
*/
setSize(e, t) {
this._width = e, this._height = t;
const s = this._width * this._pixelRatio, i = this._height * this._pixelRatio;
this.renderTarget1.setSize(s, i), this.renderTarget2.setSize(s, i);
for (let r = 0; r < this.passes.length; r++)
this.passes[r].setSize(s, i);
}
/**
* Sets device pixel ratio. This is usually used for HiDPI device to prevent blurring output.
* Setting the pixel ratio will automatically resize the composer.
*
* @param {number} pixelRatio - The pixel ratio to set.
*/
setPixelRatio(e) {
this._pixelRatio = e, this.setSize(this._width, this._height);
}
/**
* Frees the GPU-related resources allocated by this instance. Call this
* method whenever the composer is no longer used in your app.
*/
dispose() {
this.renderTarget1.dispose(), this.renderTarget2.dispose(), this.copyPass.dispose();
}
}
export {
P as EffectComposer
};