|
@@ -3,6 +3,7 @@ import ArrayElementNode from '../utils/ArrayElementNode.js';
|
|
|
import ConvertNode from '../utils/ConvertNode.js';
|
|
|
import JoinNode from '../utils/JoinNode.js';
|
|
|
import SplitNode from '../utils/SplitNode.js';
|
|
|
+import SetNode from '../utils/SetNode.js';
|
|
|
import ConstNode from '../core/ConstNode.js';
|
|
|
import { getValueFromType, getValueType } from '../core/NodeUtils.js';
|
|
|
|
|
@@ -17,6 +18,8 @@ export function addNodeElement( name, nodeElement ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+const parseSwizzle = ( props ) => props.replace( /r|s/g, 'x' ).replace( /g|t/g, 'y' ).replace( /b|p/g, 'z' ).replace( /a|q/g, 'w' );
|
|
|
+
|
|
|
const shaderNodeHandler = {
|
|
|
|
|
|
construct( NodeClosure, params ) {
|
|
@@ -51,19 +54,31 @@ const shaderNodeHandler = {
|
|
|
|
|
|
// accessing properties ( swizzle )
|
|
|
|
|
|
- prop = prop
|
|
|
- .replace( /r|s/g, 'x' )
|
|
|
- .replace( /g|t/g, 'y' )
|
|
|
- .replace( /b|p/g, 'z' )
|
|
|
- .replace( /a|q/g, 'w' );
|
|
|
+ prop = parseSwizzle( prop );
|
|
|
|
|
|
return nodeObject( new SplitNode( node, prop ) );
|
|
|
|
|
|
- } else if ( prop === 'width' || prop === 'height' ) {
|
|
|
+ } else if ( /^set[XYZWRGBASTPQ]{1,4}$/.test( prop ) === true ) {
|
|
|
+
|
|
|
+ // set properties ( swizzle )
|
|
|
+
|
|
|
+ prop = parseSwizzle( prop.slice( 3 ).toLowerCase() );
|
|
|
+
|
|
|
+ // sort to xyzw sequence
|
|
|
+
|
|
|
+ prop = prop.split( '' ).sort().join( '' );
|
|
|
+
|
|
|
+ return ( value ) => nodeObject( new SetNode( node, prop, value ) );
|
|
|
+
|
|
|
+ } else if ( prop === 'width' || prop === 'height' || prop === 'depth' ) {
|
|
|
|
|
|
// accessing property
|
|
|
|
|
|
- return nodeObject( new SplitNode( node, prop === 'width' ? 'x' : 'y' ) );
|
|
|
+ if ( prop === 'width' ) prop = 'x';
|
|
|
+ else if ( prop === 'height' ) prop = 'y';
|
|
|
+ else if ( prop === 'depth' ) prop = 'z';
|
|
|
+
|
|
|
+ return nodeObject( new SplitNode( node, prop ) );
|
|
|
|
|
|
} else if ( /^\d+$/.test( prop ) === true ) {
|
|
|
|