@@ -3,6 +3,7 @@ import ArrayElementNode from '../utils/ArrayElementNode.js';
3
3
import ConvertNode from '../utils/ConvertNode.js' ;
4
4
import JoinNode from '../utils/JoinNode.js' ;
5
5
import SplitNode from '../utils/SplitNode.js' ;
6
+ import SetNode from '../utils/SetNode.js' ;
6
7
import ConstNode from '../core/ConstNode.js' ;
7
8
import { getValueFromType , getValueType } from '../core/NodeUtils.js' ;
8
9
@@ -17,6 +18,8 @@ export function addNodeElement( name, nodeElement ) {
17
18
18
19
}
19
20
21
+ const parseSwizzle = ( props ) => props . replace ( / r | s / g, 'x' ) . replace ( / g | t / g, 'y' ) . replace ( / b | p / g, 'z' ) . replace ( / a | q / g, 'w' ) ;
22
+
20
23
const shaderNodeHandler = {
21
24
22
25
construct ( NodeClosure , params ) {
@@ -51,19 +54,31 @@ const shaderNodeHandler = {
51
54
52
55
// accessing properties ( swizzle )
53
56
54
- prop = prop
55
- . replace ( / r | s / g, 'x' )
56
- . replace ( / g | t / g, 'y' )
57
- . replace ( / b | p / g, 'z' )
58
- . replace ( / a | q / g, 'w' ) ;
57
+ prop = parseSwizzle ( prop ) ;
59
58
60
59
return nodeObject ( new SplitNode ( node , prop ) ) ;
61
60
62
- } else if ( prop === 'width' || prop === 'height' ) {
61
+ } else if ( / ^ s e t [ X Y Z W R G B A S T P Q ] { 1 , 4 } $ / . test ( prop ) === true ) {
62
+
63
+ // set properties ( swizzle )
64
+
65
+ prop = parseSwizzle ( prop . slice ( 3 ) . toLowerCase ( ) ) ;
66
+
67
+ // sort to xyzw sequence
68
+
69
+ prop = prop . split ( '' ) . sort ( ) . join ( '' ) ;
70
+
71
+ return ( value ) => nodeObject ( new SetNode ( node , prop , value ) ) ;
72
+
73
+ } else if ( prop === 'width' || prop === 'height' || prop === 'depth' ) {
63
74
64
75
// accessing property
65
76
66
- return nodeObject ( new SplitNode ( node , prop === 'width' ? 'x' : 'y' ) ) ;
77
+ if ( prop === 'width' ) prop = 'x' ;
78
+ else if ( prop === 'height' ) prop = 'y' ;
79
+ else if ( prop === 'depth' ) prop = 'z' ;
80
+
81
+ return nodeObject ( new SplitNode ( node , prop ) ) ;
67
82
68
83
} else if ( / ^ \d + $ / . test ( prop ) === true ) {
69
84
0 commit comments