UNPKG

@polygonjs/polygonjs

Version:

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

68 lines (67 loc) 2.1 kB
"use strict"; import { TypedAnimNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { NetworkChildNodeType } from "../../poly/NodeContext"; class SubnetInputAnimParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param sets which input of the parent subnet node is used */ this.input = ParamConfig.INTEGER(0, { range: [0, 3], rangeLocked: [true, true], callback: (node) => { SubnetInputAnimNode.PARAM_CALLBACK_reset(node); } }); } } const ParamsConfig = new SubnetInputAnimParamsConfig(); export class SubnetInputAnimNode extends TypedAnimNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return NetworkChildNodeType.INPUT; } initializeNode() { this.io.inputs.setCount(0); this.lifecycle.onAfterAdded(() => { this._setParentInputDependency(); }); } async cook() { const input_index = this.pv.input; const parent = this.parent(); if (parent) { if (parent.io.inputs.hasInput(input_index)) { const container = await parent.containerController.requestInputContainer(input_index); if (container) { const timelineBuilder = container.coreContent(); if (timelineBuilder) { this.setTimelineBuilder(timelineBuilder); return; } } } else { this.states.error.set(`parent has no input ${input_index}`); } this.cookController.endCook(); } else { this.states.error.set(`subnet input has no parent`); } } static PARAM_CALLBACK_reset(node) { node._setParentInputDependency(); } _setParentInputDependency() { if (this._currentParentInputGraphNode) { this.removeGraphInput(this._currentParentInputGraphNode); } const parent = this.parent(); if (parent) { this._currentParentInputGraphNode = parent.io.inputs.inputGraphNode(this.pv.input); this.addGraphInput(this._currentParentInputGraphNode); } } }