forked from bbc/VideoContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphnode.js
More file actions
124 lines (108 loc) · 3.56 KB
/
graphnode.js
File metadata and controls
124 lines (108 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//Matthew Shotton, R&D User Experience,© BBC 2015
const TYPE = "GraphNode";
class GraphNode {
/**
* Base class from which all processing and source nodes are derrived.
*/
constructor(gl, renderGraph, inputNames, limitConnections = false) {
this._renderGraph = renderGraph;
this._limitConnections = limitConnections;
this._inputNames = inputNames;
this._destroyed = false;
//Setup WebGL output texture
this._gl = gl;
this._renderGraph = renderGraph;
this._rendered = false;
this._displayName = TYPE;
}
/**
* Get a string representation of the class name.
*
* @return String A string of the class name.
*/
get displayName() {
return this._displayName;
}
/**
* Get the names of the inputs to this node.
*
* @return {String[]} An array of the names of the inputs ot the node.
*/
get inputNames() {
return this._inputNames.slice();
}
/**
* The maximum number of connections that can be made to this node. If there is not limit this will return Infinity.
*
* @return {number} The number of connections which can be made to this node.
*/
get maximumConnections() {
if (this._limitConnections === false) return Infinity;
return this._inputNames.length;
}
/**
* Get an array of all the nodes which connect to this node.
*
* @return {GraphNode[]} An array of nodes which connect to this node.
*/
get inputs() {
let result = this._renderGraph.getInputsForNode(this);
result = result.filter(function(n) {
return n !== undefined;
});
return result;
}
/**
* Get an array of all the nodes which this node outputs to.
*
* @return {GraphNode[]} An array of nodes which this node connects to.
*/
get outputs() {
return this._renderGraph.getOutputsForNode(this);
}
/**
* Get whether the node has been destroyed or not.
*
* @return {boolean} A true/false value of whather the node has been destoryed or not.
*/
get destroyed() {
return this._destroyed;
}
/**
* Connect this node to the targetNode
*
* @param {GraphNode} targetNode - the node to connect.
* @param {(number| String)} [targetPort] - the port on the targetNode to connect to, this can be an index, a string identifier, or undefined (in which case the next available port will be connected to).
*
*/
connect(targetNode, targetPort) {
return this._renderGraph.registerConnection(this, targetNode, targetPort);
}
/**
* Disconnect this node from the targetNode. If targetNode is undefind remove all out-bound connections.
*
* @param {GraphNode} [targetNode] - the node to disconnect from. If undefined, disconnect from all nodes.
*
*/
disconnect(targetNode) {
if (targetNode === undefined) {
let toRemove = this._renderGraph.getOutputsForNode(this);
toRemove.forEach(target => this._renderGraph.unregisterConnection(this, target));
if (toRemove.length > 0) return true;
return false;
}
return this._renderGraph.unregisterConnection(this, targetNode);
}
/**
* Destory this node, removing it from the graph.
*/
destroy() {
this.disconnect();
for (let input of this.inputs) {
input.disconnect(this);
}
this._destroyed = true;
}
}
export { TYPE as GRAPHTYPE };
export default GraphNode;