forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBypassNode.js
93 lines (69 loc) · 1.64 KB
/
BypassNode.js
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
import Node from './Node.js';
import { addMethodChaining, nodeProxy } from '../tsl/TSLCore.js';
/**
* The class generates the code of a given node but returns another node in the output.
* This can be used to call a method or node that does not return a value, i.e.
* type `void` on an input where returning a value is required. Example:
*
* ```js
* material.colorNode = myColor.bypass( runVoidFn() )
*```
*
* @augments Node
*/
class BypassNode extends Node {
static get type() {
return 'BypassNode';
}
/**
* Constructs a new bypass node.
*
* @param {Node} outputNode - The output node.
* @param {Node} callNode - The call node.
*/
constructor( outputNode, callNode ) {
super();
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isBypassNode = true;
/**
* The output node.
*
* @type {Node}
*/
this.outputNode = outputNode;
/**
* The call node.
*
* @type {Node}
*/
this.callNode = callNode;
}
getNodeType( builder ) {
return this.outputNode.getNodeType( builder );
}
generate( builder ) {
const snippet = this.callNode.build( builder, 'void' );
if ( snippet !== '' ) {
builder.addLineFlowCode( snippet, this );
}
return this.outputNode.build( builder );
}
}
export default BypassNode;
/**
* TSL function for creating a bypass node.
*
* @tsl
* @function
* @param {Node} outputNode - The output node.
* @param {Node} callNode - The call node.
* @returns {BypassNode}
*/
export const bypass = /*@__PURE__*/ nodeProxy( BypassNode ).setParameterLength( 2 );
addMethodChaining( 'bypass', bypass );