Skip to content

Conversation

@sunag
Copy link
Collaborator

@sunag sunag commented Aug 7, 2025

Fixes #31587

Description

It brings a safer approach, instead of interpret the function before the call, it performs the eval at the moment the properties are requested during the function call. This is only necessary for functions that don’t have a defined layout.

Below are some examples of declaration and invocation

const f1 = Fn( ( [ { x, y }, a, b, c ], builder ) => {

	if ( a ) console.log( 'f1', x, y, a.value, b.value, c );
	else console.log( 'f1', x, y );
	return x;

} );

const f2 = Fn( ( [ x = .1 ] ) => {

	console.log( 'f2', x );
	return x;

} );

const f3 = Fn( ( [ a, b ], builder ) => {

	console.log( 'f3', a.value, b.value );
	return a;

} );

const f4 = Fn( ( { a, b }, builder ) => {

	console.log( 'f4', a.value, b.value );
	return a;

} );

const f5 = Fn( ( { a, b }, builder ) => {

	console.log( 'f5' );
	return a;

}, { a: 'float', b: 'float', return: 'float' } );

const f6 = Fn( ( [ a, b ], builder ) => {

	console.log( 'f6' );
	return a;

}, { a: 'float', b: 'float', return: 'float' } );

material.colorNode = add(
	f1( { x: .1, y: 2 }, 1, 2, { x: 0 } ),
	f1( { x: .1, y: 2 } ),
	f2(),
	f3( .1, 2 ),
	f4( { a: .1, b: 2 } ),
	f4( .1, 2 ),
	f5( .1, 2 ),
	f5( { a: .1, b: 2 } ),
	f6( .1, 2 ),
	f6( { a: .1, b: 2 } )
);

@sunag sunag added this to the r180 milestone Aug 7, 2025
@github-actions
Copy link

github-actions bot commented Aug 7, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.63
79.03
338.63
79.03
+0 B
+0 B
WebGPU 567.9
157.11
568.25
157.2
+355 B
+95 B
WebGPU Nodes 566.51
156.86
566.86
156.95
+355 B
+94 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.38
113.78
470.38
113.78
+0 B
+0 B
WebGPU 641.64
173.58
641.99
173.68
+355 B
+96 B
WebGPU Nodes 596.28
162.88
596.64
162.97
+355 B
+96 B

@sunag sunag marked this pull request as ready for review August 7, 2025 02:08
@sunag sunag merged commit f250f75 into mrdoob:dev Aug 8, 2025
9 checks passed
@sunag sunag deleted the dev-tsl-fn branch August 8, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TSL: Remove the object form in Fn to resolve ambiguity

1 participant