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

BatchedMesh setGeometryIdAt getGeometryIdAt #29343

Merged
merged 4 commits into from
Sep 13, 2024
Merged

BatchedMesh setGeometryIdAt getGeometryIdAt #29343

merged 4 commits into from
Sep 13, 2024

Conversation

Makio64
Copy link
Contributor

@Makio64 Makio64 commented Sep 6, 2024

This PR add the possibility to switch the geometryId of an instance with setGeometryIdAt and to get the geometryId of an instance with getGeometryIdAt.

This PR implement this feature in the same way than set/get of matrix/color/visibility.

Before the PR
batchedMesh._drawInfo[instanceId].geometryIndex = geometryId
X

After the PR
batchedMesh.setGeometryIdAt(instanceId, geometryId)
batchedMesh.getGeometryIdAt(instanceId)

Why ?
Currently we can replace a geometry by another but we cant change the geometry use by an instance.

For example in game, while the player explore the level sometimes I needs more instance with rocks geometry and less with trees geometry and sometimes the opposite. In this case with this feature we can re-use the instance in a clever way updating only their geometryId.

Copy link

github-actions bot commented Sep 6, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 685.24
169.64
685.49
169.68
+244 B
+43 B
WebGPU 826.41
221.63
826.65
221.67
+244 B
+44 B
WebGPU Nodes 825.99
221.54
826.23
221.58
+244 B
+43 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 462.02
111.48
462.02
111.48
+0 B
+0 B
WebGPU 525.5
141.64
525.5
141.64
+0 B
+0 B
WebGPU Nodes 482.15
131.46
482.15
131.46
+0 B
+0 B

@cmhhelgeson
Copy link
Contributor

Think this could warrant an example, or perhaps an option for displaying this dynamic switching in one of the existing batch examples.

@Makio64
Copy link
Contributor Author

Makio64 commented Sep 8, 2024

@cmhhelgeson Example patched 👍

@cmhhelgeson
Copy link
Contributor

cmhhelgeson commented Sep 9, 2024

I'm testing the branch using this link: https://raw.githack.com/Makio64/three.js-BatchedMesh-geometryIdAt/dev/examples/webgpu_mesh_batch.html

I'm receiving the error below upon clicking Randomize Geometry:

image

@gkjohnson
Copy link
Collaborator

I'm testing the branch using this link:

Testing these kinds of live links will not work without updated three.js build files.

@Makio64
Copy link
Contributor Author

Makio64 commented Sep 9, 2024

I'm testing the branch using this link:

Testing these kinds of live links will not work without updated three.js build files.

@cmhhelgeson @gkjohnson Its my first PR since long time on threejs, should I add the new build to my PR for testing purpose ?

@gkjohnson
Copy link
Collaborator

should I add the new build to my PR for testing purpose?

No adding the build files will often result in merge conflicts. I just intended to say that if you want to test the PR then you need to pull and run the branch locally.

@Makio64
Copy link
Contributor Author

Makio64 commented Sep 10, 2024

@gkjohnson @cmhhelgeson It should be good to go now. Let me know if you feel it needs other changes.

@gkjohnson gkjohnson merged commit b06a2e9 into mrdoob:dev Sep 13, 2024
12 checks passed
@Mugen87 Mugen87 added this to the r169 milestone Sep 13, 2024
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.

4 participants