UNPKG

@polygonjs/polygonjs

Version:

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

86 lines (85 loc) 3.74 kB
"use strict"; import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base"; import { NodeParamsConfig } from "../utils/params/ParamsConfig"; import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js"; import { JsType } from "../../poly/registers/nodes/types/Js"; import { Poly } from "../../Poly"; import { InitFunctionJsDefinition, TriggeringJsDefinition } from "./utils/JsDefinition"; import { getConnectedOutputNodes, getOutputIndices, nodeMethodName, triggerInputIndex } from "./code/assemblers/actor/ActorAssemblerUtils"; import { setToArray } from "../../../core/SetUtils"; import { CAMERA_CONTROLS_EVENTS, CameraControlsEvent } from "../../viewers/utils/ViewerControlsController"; function _outputName(eventName) { return `${TRIGGER_CONNECTION_NAME}${eventName}`; } class OnViewerControlsEventJsParamsConfig extends NodeParamsConfig { } const ParamsConfig = new OnViewerControlsEventJsParamsConfig(); const _OnViewerControlsEventJsNode = class extends TypedJsNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return JsType.ON_VIEWER_CONTROLS_EVENT; } isTriggering() { return true; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(_OnViewerControlsEventJsNode.OUTPUT_NAME_START, JsConnectionPointType.TRIGGER), new JsConnectionPoint(_OnViewerControlsEventJsNode.OUTPUT_NAME_END, JsConnectionPointType.TRIGGER) // new JsConnectionPoint(OnPerformanceChangeOutputName.aboveThreshold, JsConnectionPointType.BOOLEAN), // new JsConnectionPoint(OnPerformanceChangeOutputName.performance, JsConnectionPointType.FLOAT), ]); } setTriggeringLines(linesController, triggeredMethods) { const listeners = { [CameraControlsEvent.start]: "", [CameraControlsEvent.end]: "" }; CAMERA_CONTROLS_EVENTS.forEach((eventName) => { const triggeredMethods2 = triggerMethod(this, _outputName(eventName)); const _nodeMethodName = nodeMethodName(this, _outputName(eventName)); listeners[eventName] = `this.${_nodeMethodName}.bind(this)`; const value = triggeredMethods2; const dataType = JsConnectionPointType.BOOLEAN; linesController.addDefinitions(this, [ new TriggeringJsDefinition(this, linesController, dataType, _nodeMethodName, value, { triggeringMethodName: eventName, gatherable: false, nodeMethodName: _nodeMethodName }) ]); }); const func = Poly.namedFunctionsRegister.getFunction("onViewerControlsEvent", this, linesController); const bodyLine = func.asString(JSON.stringify(listeners).replace(/\"/g, ""), `this`); linesController.addDefinitions(this, [ new InitFunctionJsDefinition(this, linesController, JsConnectionPointType.OBJECT_3D, this.path(), bodyLine) ]); } }; export let OnViewerControlsEventJsNode = _OnViewerControlsEventJsNode; OnViewerControlsEventJsNode.OUTPUT_NAME_START = _outputName(CameraControlsEvent.start); OnViewerControlsEventJsNode.OUTPUT_NAME_END = _outputName(CameraControlsEvent.end); function triggerMethod(node, outputName) { const outputIndex = getOutputIndices(node, (c) => c.name() == outputName)[0]; const triggerableNodes = /* @__PURE__ */ new Set(); getConnectedOutputNodes({ node, triggerOutputIndices: [outputIndex], triggerableNodes, recursive: false }); const triggerableMethodNames = setToArray(triggerableNodes, []).map((triggerableNode) => { const argIndex = triggerInputIndex(node, triggerableNode); const m = nodeMethodName(triggerableNode); return `this.${m}(${argIndex})`; }); return `${triggerableMethodNames.join(";")}`; }