UNPKG

@polygonjs/polygonjs

Version:

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

57 lines (56 loc) 1.7 kB
"use strict"; import { TypedCopNode } from "./_Base"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; class SwitchCopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param input index */ this.input = ParamConfig.INTEGER(0, { range: [0, 3], rangeLocked: [true, true], callback: (node) => { SwitchCopNode.PARAM_CALLBACK_setInputsEvaluation(node); } }); } } const ParamsConfig = new SwitchCopParamsConfig(); export class SwitchCopNode extends TypedCopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "switch"; } initializeNode() { this.io.inputs.setCount(0, 4); this.io.inputs.initInputsClonedState(InputCloneMode.NEVER); this.io.inputs.onEnsureListenToSingleInputIndexUpdated(async () => { await this._callbackUpdateInputsEvaluation(); }); } async cook() { const input_index = this.pv.input; if (this.io.inputs.hasInput(input_index)) { const container = await this.containerController.requestInputContainer(input_index); if (container) { this.setTexture(container.texture()); return; } } else { this.states.error.set(`no input ${input_index}`); } this.cookController.endCook(); } async _callbackUpdateInputsEvaluation() { if (this.p.input.isDirty()) { await this.p.input.compute(); } this.io.inputs.listenToSingleInputIndex(this.pv.input); } static PARAM_CALLBACK_setInputsEvaluation(node) { node._callbackUpdateInputsEvaluation(); } }