UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (53 loc) 2.41 kB
"use strict"; import { Poly } from "../../Poly"; import { JsConnectionPointType } from "../utils/io/connections/Js"; import { ParamlessTypedJsNode } from "./_Base"; const ALLOWED_TYPES = [JsConnectionPointType.BOOLEAN, JsConnectionPointType.BOOLEAN_ARRAY]; export class BaseLogicOperationJsNode extends ParamlessTypedJsNode { initializeNode() { super.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) { const type = this._expectedInputTypes()[0]; return `${type}${index}`; } _expectedInputTypes() { const firstInputType = this.io.connection_points.first_input_connection_type(); const type = firstInputType != null && ALLOWED_TYPES.includes(firstInputType) ? firstInputType : JsConnectionPointType.BOOLEAN; const currentConnections = this.io.connections.existingInputConnections(); const expectedCount = currentConnections ? Math.max(currentConnections.length + 1, 2) : 2; const expectedInputTypes = []; for (let i = 0; i < expectedCount; i++) { expectedInputTypes.push(type); } return expectedInputTypes; } _expectedOutputTypes() { return [JsConnectionPointType.BOOLEAN]; } setLines(shadersCollectionController) { const inputValuesCount = this._expectedInputTypes().length - 1; const inputArgs = []; for (let i = 0; i < inputValuesCount; i++) { const element = this.variableForInput(shadersCollectionController, this._expectedInputName(i)); inputArgs.push(element); } const inputElements = `[${inputArgs.join(",")}]`; const dataType = this._expectedInputTypes()[0]; const varName = this.jsVarName(this._expectedOutputName(0)); const firstType = this._expectedInputTypes()[0]; const functionName = this._functionName(firstType); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType, varName, value: func.asString(inputElements) } ]); } }