UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

63 lines (62 loc) 2.12 kB
"use strict"; import { Texture, Vector2 } from "three"; import { TypedPostNode, PostParamOptions } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { BlendFunction, EffectPass, TextureEffect } from "postprocessing"; import { BLEND_FUNCTION_MENU_OPTIONS } from "../../../core/post/BlendFunction"; import { NodeContext } from "../../poly/NodeContext"; import { PostType } from "../../poly/registers/nodes/types/Post"; const tmpTexture = new Texture(); class TexturePostParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param texture */ this.texture = ParamConfig.NODE_PATH("", { nodeSelection: { context: NodeContext.COP }, dependentOnFoundNode: false, ...PostParamOptions }); /** @param opacity */ this.opacity = ParamConfig.FLOAT(1, { range: [0, 1], rangeLocked: [true, false], ...PostParamOptions }); /** @param render mode */ this.blendFunction = ParamConfig.INTEGER(BlendFunction.COLOR_DODGE, { ...PostParamOptions, ...BLEND_FUNCTION_MENU_OPTIONS }); } } const ParamsConfig = new TexturePostParamsConfig(); export class TexturePostNode extends TypedPostNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this._rendererSize = new Vector2(); } static type() { return PostType.TEXTURE; } createPass(context) { context.renderer.getSize(this._rendererSize); const effect = new TextureEffect({ texture: tmpTexture }); const pass = new EffectPass(context.camera, effect); this.updatePass(pass); return pass; } async updatePass(pass) { var _a; const effect = pass.effects[0]; effect.blendMode.opacity.value = this.pv.opacity; effect.blendMode.blendFunction = this.pv.blendFunction; const textureNode = this.pv.texture.nodeWithContext(NodeContext.COP, (_a = this.states) == null ? void 0 : _a.error); if (textureNode) { const container = await textureNode.compute(); effect.texture = container.coreContent(); } } }