@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
72 lines (71 loc) • 2.19 kB
JavaScript
"use strict";
import { EventDispatcher } from "three";
export const NODE_CONNECTION_TRIGGERED_EVENT_NAME = "triggered";
export const NODE_CONNECTION_TRIGGERED_EVENT = { type: NODE_CONNECTION_TRIGGERED_EVENT_NAME };
const _TypedNodeConnection = class {
constructor(_nodeSrc, _nodeDest, _outputIndex = 0, _inputIndex = 0) {
this._nodeSrc = _nodeSrc;
this._nodeDest = _nodeDest;
this._outputIndex = _outputIndex;
this._inputIndex = _inputIndex;
if (this._outputIndex == null) {
throw "bad output index";
}
if (this._inputIndex == null) {
throw "bad input index";
}
this._id = _TypedNodeConnection._nextId++;
if (this._nodeSrc.io.connections && this._nodeDest.io.connections) {
this._nodeSrc.io.connections.addOutputConnection(this);
this._nodeDest.io.connections.addInputConnection(this);
}
}
id() {
return this._id;
}
nodeSrc() {
return this._nodeSrc;
}
nodeDest() {
return this._nodeDest;
}
outputIndex() {
return this._outputIndex;
}
inputIndex() {
return this._inputIndex;
}
srcConnectionPoint() {
const connectionPoints = this._nodeSrc.io.outputs.namedOutputConnectionPoints();
if (!connectionPoints) {
return;
}
return connectionPoints[this._outputIndex];
}
destConnectionPoint() {
const connectionPoints = this._nodeDest.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
return connectionPoints[this._inputIndex];
}
disconnect(options = {}) {
if (this._nodeSrc.io.connections && this._nodeDest.io.connections) {
this._nodeSrc.io.connections.removeOutputConnection(this);
this._nodeDest.io.connections.removeInputConnection(this);
}
if (options.setInput === true) {
this._nodeDest.io.inputs.setInput(this._inputIndex, null, void 0, {
ignoreLockedState: options.ignoreLockedState
});
}
}
_eventDispatcher() {
return this.__eventDispatcher;
}
eventDispatcher() {
return this.__eventDispatcher = this.__eventDispatcher || new EventDispatcher();
}
};
export let TypedNodeConnection = _TypedNodeConnection;
TypedNodeConnection._nextId = 0;