Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Introduce array() #30386

Merged
merged 3 commits into from
Jan 23, 2025
Merged

TSL: Introduce array() #30386

merged 3 commits into from
Jan 23, 2025

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Jan 23, 2025

Closes #30097

Description

The implementation has two types of declarations array( [ ...nodes ] ) and array( 'type', count ). Both are compatible with .toConst() and .toVar() and have been updated in parse. TempNode has also been updated to automatically generate cache if .toVar() is not used.

// style 1 - constants
const a = array( [ vec3(), vec3() ] );

// style 1 - runtime values
const b = array( [ uniform( 1 ), a.element( 0 ).x ] );

// style 2 - constants
const c = array( 'vec3', 2 );

// style 3 - constants / runtime values
const d = vec3( 0, 0, 1 ).toArray( 2 ); // the result will be: [ vec3( 0, 0, 1 ), vec3( 0, 0, 1 ) ]

// .toVar() and assigns
const e = array( [ vec3(), vec3() ] ).toVar();
e.element( 0 ).assign( vec3() );

// .toConst()
const f = array( [ vec3(), vec3() ] ).toConst();
const v = f.element( 0 );

Copy link

github-actions bot commented Jan 23, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.25
78.28
336.25
78.28
+0 B
+0 B
WebGPU 510.54
141.69
511.94
142.13
+1.41 kB
+434 B
WebGPU Nodes 510
141.59
511.41
142.02
+1.41 kB
+435 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.25
112.13
465.25
112.13
+0 B
+0 B
WebGPU 584.54
158.41
585.91
158.79
+1.37 kB
+386 B
WebGPU Nodes 539.92
147.96
541.29
148.37
+1.37 kB
+407 B

@sunag sunag marked this pull request as ready for review January 23, 2025 01:11
@sunag
Copy link
Collaborator Author

sunag commented Jan 23, 2025

@RenaudRohlinger I implemented your suggestion of .toArray() it can be done in just one line of code 023bd77. Now it can be used on any node, and can fill an array with default values, for example vec3( 0, 0, 1 ).toArray( 3 ).

@RenaudRohlinger
Copy link
Collaborator

RenaudRohlinger commented Jan 23, 2025

Thanks for this! It’s great to see the NodeBuilder part in both our PRs is somehow similar. After learning @mrdoob code style, it feels like I’m finally starting to get the hang of @sunag style too! 🤭😁

@sunag
Copy link
Collaborator Author

sunag commented Jan 23, 2025

Certainly yes, I'm happy to see how similar the PRs were. Always grateful for your help and suggestions :)

@sunag sunag merged commit 7c01f6e into mrdoob:dev Jan 23, 2025
12 checks passed
@sunag sunag deleted the dev-array-2 branch January 23, 2025 05:56
@sunag sunag added this to the r173 milestone Jan 23, 2025
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 'property', using array of float or vec, or mat etc..
2 participants