@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
56 lines (55 loc) • 2.57 kB
JavaScript
"use strict";
import { JsConnectionPointType } from "../utils/io/connections/Js";
import { ParamlessTypedJsNode } from "./_Base";
const OUTPUT_NAME = "val";
export var TwoWaySwitchJsNodeInputName = /* @__PURE__ */ ((TwoWaySwitchJsNodeInputName2) => {
TwoWaySwitchJsNodeInputName2["CONDITION"] = "condition";
TwoWaySwitchJsNodeInputName2["IF_TRUE"] = "ifTrue";
TwoWaySwitchJsNodeInputName2["IF_FALSE"] = "ifFalse";
return TwoWaySwitchJsNodeInputName2;
})(TwoWaySwitchJsNodeInputName || {});
const InputNames = [
"condition" /* CONDITION */,
"ifTrue" /* IF_TRUE */,
"ifFalse" /* IF_FALSE */
];
export class TwoWaySwitchJsNode extends ParamlessTypedJsNode {
static type() {
return "twoWaySwitch";
}
// public readonly gl_connections_controller: GlConnectionsController = new GlConnectionsController(this);
initializeNode() {
super.initializeNode();
this.io.connection_points.initializeNode();
this.io.connection_points.set_expected_input_types_function(this._expectedInputTypes.bind(this));
this.io.connection_points.set_expected_output_types_function(this._expectedOutputTypes.bind(this));
this.io.connection_points.set_input_name_function(this._expectedInputName.bind(this));
this.io.connection_points.set_output_name_function(this._expectedOutputName.bind(this));
}
_expectedInputName(index) {
return InputNames[index];
}
_expectedOutputName() {
return OUTPUT_NAME;
}
_expectedInputTypes() {
const second_or_third_connection = this.io.connections.inputConnection(1) || this.io.connections.inputConnection(2);
const srcConnectionPoint = second_or_third_connection ? second_or_third_connection.srcConnectionPoint() : null;
const type = (srcConnectionPoint == null ? void 0 : srcConnectionPoint.type()) || JsConnectionPointType.FLOAT;
return [JsConnectionPointType.BOOLEAN, type, type];
}
_expectedOutputTypes() {
const type = this._expectedInputTypes()[1];
return [type];
}
setLines(shadersCollectionController) {
const condition = this.variableForInput(shadersCollectionController, "condition" /* CONDITION */);
const ifTrue = this.variableForInput(shadersCollectionController, "ifTrue" /* IF_TRUE */);
const ifFalse = this.variableForInput(shadersCollectionController, "ifFalse" /* IF_FALSE */);
const out = this.jsVarName(OUTPUT_NAME);
const bodyLine = `${condition} ? ${ifTrue} : ${ifFalse}`;
shadersCollectionController.addBodyOrComputed(this, [
{ dataType: JsConnectionPointType.PLANE, varName: out, value: bodyLine }
]);
}
}