@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
62 lines (61 loc) • 2.74 kB
JavaScript
;
import { ParamlessTypedGlNode } from "./_Base";
import { ThreeToGl } from "../../../core/ThreeToGl";
const OUTPUT_NAME = "val";
var TwoWaySwitchGlNodeInputName = /* @__PURE__ */ ((TwoWaySwitchGlNodeInputName2) => {
TwoWaySwitchGlNodeInputName2["CONDITION"] = "condition";
TwoWaySwitchGlNodeInputName2["IF_TRUE"] = "ifTrue";
TwoWaySwitchGlNodeInputName2["IF_FALSE"] = "ifFalse";
return TwoWaySwitchGlNodeInputName2;
})(TwoWaySwitchGlNodeInputName || {});
const InputNames = [
"condition" /* CONDITION */,
"ifTrue" /* IF_TRUE */,
"ifFalse" /* IF_FALSE */
];
import { GlConnectionPointType } from "../utils/io/connections/Gl";
export class TwoWaySwitchGlNode extends ParamlessTypedGlNode {
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._expected_input_types.bind(this));
this.io.connection_points.set_expected_output_types_function(this._expected_output_types.bind(this));
this.io.connection_points.set_input_name_function(this._gl_input_name.bind(this));
this.io.connection_points.set_output_name_function(this._gl_output_name.bind(this));
}
_gl_input_name(index) {
return InputNames[index];
}
_gl_output_name() {
return OUTPUT_NAME;
}
_expected_input_types() {
const second_or_third_connection = this.io.connections.inputConnection(1) || this.io.connections.inputConnection(2);
const srcConnectionPoint = second_or_third_connection == null ? void 0 : second_or_third_connection.srcConnectionPoint();
const type = (srcConnectionPoint == null ? void 0 : srcConnectionPoint.type()) || GlConnectionPointType.FLOAT;
return [GlConnectionPointType.BOOL, type, type];
}
_expected_output_types() {
const type = this._expected_input_types()[1];
return [type];
}
setLines(shaders_collection_controller) {
const value = this.glVarName(OUTPUT_NAME);
const condition = ThreeToGl.bool(this.variableForInput("condition" /* CONDITION */));
const ifTrue = ThreeToGl.any(this.variableForInput("ifTrue" /* IF_TRUE */));
const ifFalse = ThreeToGl.any(this.variableForInput("ifFalse" /* IF_FALSE */));
const glType = this._expected_output_types()[0];
const bodyLines = [];
bodyLines.push(`${glType} ${value}`);
bodyLines.push(`if(${condition}){`);
bodyLines.push(`${value} = ${ifTrue}`);
bodyLines.push(`} else {`);
bodyLines.push(`${value} = ${ifFalse}`);
bodyLines.push(`}`);
shaders_collection_controller.addBodyLines(this, bodyLines);
}
}