UNPKG

@polygonjs/polygonjs

Version:

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

91 lines (90 loc) 4.19 kB
"use strict"; import { BaseTriggerAndObjectJsNode } from "./_BaseTriggerAndObject"; import { inputObject3D } from "./_BaseObject3D"; import { Poly } from "../../Poly"; import { NodeParamsConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPointType } from "../utils/io/connections/Js"; import { RefJsDefinition } from "./utils/JsDefinition"; var CreatePhysicsRBDsJsNodeInput = /* @__PURE__ */ ((CreatePhysicsRBDsJsNodeInput2) => { CreatePhysicsRBDsJsNodeInput2["OBJECT_3D"] = "rbdObject"; CreatePhysicsRBDsJsNodeInput2["OBJECT_3DS"] = "rbdObjects"; return CreatePhysicsRBDsJsNodeInput2; })(CreatePhysicsRBDsJsNodeInput || {}); var CreatePhysicsRBDsJsNodeOutput = /* @__PURE__ */ ((CreatePhysicsRBDsJsNodeOutput2) => { CreatePhysicsRBDsJsNodeOutput2["RBD_ID"] = "RBDId"; CreatePhysicsRBDsJsNodeOutput2["RBD_IDS"] = "RBDIds"; return CreatePhysicsRBDsJsNodeOutput2; })(CreatePhysicsRBDsJsNodeOutput || {}); class CreatePhysicsRBDsJsParamsConfig extends NodeParamsConfig { } const ParamsConfig = new CreatePhysicsRBDsJsParamsConfig(); export class CreatePhysicsRBDsJsNode extends BaseTriggerAndObjectJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "createPhysicsRBDs"; } initializeNode() { super.initializeNode(); this.io.connection_points.set_input_name_function(this._expectedInputName.bind(this)); this.io.connection_points.set_output_name_function(this._expectedOutputName.bind(this)); 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)); } _expectedInputName(index) { return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D, this._childInputName()][index]; } _expectedOutputName(index) { return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D, this._childOutputName()][index]; } _expectedInputTypes() { return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D, this._childInputType()]; } _expectedOutputTypes() { return [JsConnectionPointType.TRIGGER, JsConnectionPointType.OBJECT_3D, this._childOutputType()]; } _isInputArray() { const firstInputType = this.io.connection_points.input_connection_type(2); return firstInputType == JsConnectionPointType.OBJECT_3D_ARRAY; } _childInputName() { return this._isInputArray() ? "rbdObjects" /* OBJECT_3DS */ : "rbdObject" /* OBJECT_3D */; } _childOutputName() { return this._isInputArray() ? "RBDIds" /* RBD_IDS */ : "RBDId" /* RBD_ID */; } _childInputType() { return this._isInputArray() ? JsConnectionPointType.OBJECT_3D_ARRAY : JsConnectionPointType.OBJECT_3D; } _childOutputType() { return this._isInputArray() ? JsConnectionPointType.STRING_ARRAY : JsConnectionPointType.STRING; } setLines(linesController) { super.setLines(linesController); const outRBDIds = this._addRBDIdRef(linesController); const out = this.jsVarName(this._childOutputName()); linesController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.OBJECT_3D, varName: out, value: `this.${outRBDIds}.value` } ]); } setTriggerableLines(linesController) { const object3D = inputObject3D(this, linesController); const inputName = this._childInputName(); const inputObjects = this.variableForInput(linesController, inputName); const functionName = this._isInputArray() ? "createPhysicsRBDs" : "createPhysicsRBD"; const outRBDIds = this._addRBDIdRef(linesController); const func = Poly.namedFunctionsRegister.getFunction(functionName, this, linesController); const bodyLine = func.asString(object3D, inputObjects, `this.${outRBDIds}`); linesController.addTriggerableLines(this, [bodyLine]); } _addRBDIdRef(linesController) { const outRBDIds = this.jsVarName("rbdIds"); linesController.addDefinitions(this, [ // do not use a ref, as it makes the object reactive new RefJsDefinition(this, linesController, JsConnectionPointType.STRING, outRBDIds, `''`) ]); return outRBDIds; } }