question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BatchedMesh: Proposal

See original GitHub issue

Currently the APIs available for reducing draw calls include:

I think we might be able to solve some common difficulties with reducing draw calls, even where the objects to be rendered are not instances of the same thing. I’ve floated the idea in a couple of earlier comments (https://github.com/mrdoob/three.js/issues/19164#issuecomment-631237304, https://github.com/mrdoob/three.js/issues/18918#issuecomment-602395984) but wanted to open a separate issue for it.

Calling this BatchedMesh for now, it’s meant to be a way of (1) merging, (2) rendering, and (3) updating a group of objects that would otherwise be drawn as separate Mesh instances. The objects must all be the same primitive type (i.e. triangles), must share a material, and must have compatible vertex attributes (e.g. if one has normals, they all have normals). With those requirements we could offer an API like:

// Create BatchedMesh with max vertex and triangle counts to support. If 
// geometry is not indexed, maxTriangleCount is optional. The 'template'
// geometry could just be the first geometry we'll add later — it isn't stored,
// but is used to determine which vertex attributes to allocate.
const batchedMesh = new BatchedMesh( templateGeometry, material, maxVertexCount, maxTriangleCount );

// Append geometry, up to max vertex and triangle limit.
const id1 = batchedMesh.add( geometry1, matrix1 );
const id2 = batchedMesh.add( geometry2, matrix2 );
const id3 = batchedMesh.add( geometry3, matrix3 );

scene.add( batchedMesh );

renderer.render( scene, camera );

// Update object position dynamically. For small objects this may be cheaper than
// a separate draw call. For large objects, it may be better to draw the object
// separately than to update it with dynamic batching.
batchedMesh.setMatrixAt( id1, otherMatrix );

renderer.render( scene, camera );

This offers a few advantages over mergeBufferGeometries(). First, you get an ID that lets you remove or modify each geometry later. Second, we can potentially do much faster raycasting (we know the bounding box and transform of each member geometry) and return that ID as a result. Third, we can do frustum culling (maybe?) by updating the index buffer.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:50
  • Comments:60 (10 by maintainers)

github_iconTop GitHub Comments

8reactions
agviegascommented, Jul 27, 2022

Hi all! The devs of IFC.js here.

We would benefit greatly from this feature and are willing to invest resources into this. I don’t know the state and how much it would take to finish this, but if one/many people are willing to get paid for getting this done, you can count on us to finance it. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

BatchMesh Memory Issue - Questions - three.js forum
There are other possible meanings like this BatchedMesh proposal, three-batch-manager, and three-batch-mesh. My entire model is still at 1 drawCall but with ...
Read more >
"@onirenaud @ggsimm @hmans @donrmccurdy's pr is super ...
BatchedMesh : Proposal · Issue #22376 · mrdoob/three.js. Currently the APIs available for reducing draw calls include: InstancedMesh BufferGeometryUtils.
Read more >
Issues · mrdoob/three.js · GitHub
BatchedMesh : Proposal Suggestion. #22376 opened Aug 20, 2021 by donmccurdy · 55 17 · Selective lighting Enhancement. #5180 opened Aug 10, ...
Read more >
Weekly Update 342: Convenience improvements! · Gloria Victis ...
... we're working on an update that we plan to apply for next week, ... /WorldStreamer/BatchedMeshes/world_models_x21_z0_meshes.manifest (647 B) ...
Read more >
Static batching
However, blocking some types of cookies may impact your experience of the site and the services we are able to offer. More information ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found