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 instance() for custom use #29911

Merged
merged 3 commits into from
Nov 16, 2024
Merged

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Nov 16, 2024

Related issue: #29071

Description

Introduce instance() for custom use.

mesh = new THREE.Mesh( geometry, material );
mesh.count = count;

instanceMatrix = new THREE.InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
instanceMatrix.setUsage( THREE.DynamicDrawUsage );

mesh.material.positionNode = Fn( ( { object } ) => {

	// object is the mesh here
	// .append() will run instance() immediately, appying instanceMatrix transform in positionLocal and normalLocal
	// this way you can get positionLocal before or after instance(()
	instance( object.count, instanceMatrix ).append();

	return positionLocal;

} )();

scene.add( mesh );

// update matrix

dummy.matrix.toArray( instanceMatrix.array, i ++ * 16 );

@sunag sunag added this to the r171 milestone Nov 16, 2024
Copy link

github-actions bot commented Nov 16, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.37
79.06
339.37
79.06
+0 B
+0 B
WebGPU 478.22
132.63
478.37
132.7
+153 B
+64 B
WebGPU Nodes 477.68
132.51
477.84
132.58
+153 B
+69 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 464.82
112.02
464.82
112.02
+0 B
+0 B
WebGPU 546.95
148.2
547.04
148.23
+93 B
+34 B
WebGPU Nodes 502.83
137.91
502.93
137.95
+93 B
+48 B

@sunag sunag marked this pull request as ready for review November 16, 2024 20:16
@sunag sunag merged commit d792454 into mrdoob:dev Nov 16, 2024
12 checks passed
@sunag sunag deleted the dev-improve-instance branch November 16, 2024 20:36
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.

1 participant