Skip to content

Commit b8f39e4

Browse files
authored
TSL: Sequential object as parameters for Fn( { .. } ) (#31498)
1 parent b5db6ad commit b8f39e4

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/nodes/tsl/TSLCore.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,36 @@ class ShaderCallNodeInternal extends Node {
396396

397397
} else {
398398

399+
let inputs = inputNodes;
400+
401+
if ( Array.isArray( inputs ) ) {
402+
403+
// If inputs is an array, we need to convert it to a Proxy
404+
// so we can call TSL functions using the syntax `Fn( ( { r, g, b } ) => { ... } )`
405+
// and call through `fn( 0, 1, 0 )` or `fn( { r: 0, g: 1, b: 0 } )`
406+
407+
let index = 0;
408+
409+
inputs = new Proxy( inputs, {
410+
get: ( target, property, receiver ) => {
411+
412+
if ( target[ property ] === undefined ) {
413+
414+
return target[ index ++ ];
415+
416+
} else {
417+
418+
return Reflect.get( target, property, receiver );
419+
420+
}
421+
422+
}
423+
} );
424+
425+
}
426+
399427
const jsFunc = shaderNode.jsFunc;
400-
const outputNode = inputNodes !== null || jsFunc.length > 1 ? jsFunc( inputNodes || [], builder ) : jsFunc( builder );
428+
const outputNode = inputs !== null || jsFunc.length > 1 ? jsFunc( inputs || [], builder ) : jsFunc( builder );
401429

402430
result = nodeObject( outputNode );
403431

0 commit comments

Comments
 (0)