forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayElementNode.js
75 lines (56 loc) · 1.37 KB
/
ArrayElementNode.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
import Node from '../core/Node.js';
/**
* Base class for representing element access on an array-like
* node data structures.
*
* @augments Node
*/
class ArrayElementNode extends Node { // @TODO: If extending from TempNode it breaks webgpu_compute
static get type() {
return 'ArrayElementNode';
}
/**
* Constructs an array element node.
*
* @param {Node} node - The array-like node.
* @param {Node} indexNode - The index node that defines the element access.
*/
constructor( node, indexNode ) {
super();
/**
* The array-like node.
*
* @type {Node}
*/
this.node = node;
/**
* The index node that defines the element access.
*
* @type {Node}
*/
this.indexNode = indexNode;
/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isArrayElementNode = true;
}
/**
* This method is overwritten since the node type is inferred from the array-like node.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {String} The node type.
*/
getNodeType( builder ) {
return this.node.getElementType( builder );
}
generate( builder ) {
const nodeSnippet = this.node.build( builder );
const indexSnippet = this.indexNode.build( builder, 'uint' );
return `${ nodeSnippet }[ ${ indexSnippet } ]`;
}
}
export default ArrayElementNode;