3DTilesRendererJS icon indicating copy to clipboard operation
3DTilesRendererJS copied to clipboard

Plugins: Consider plugin that uses / enables use of BatchedMesh

Open gkjohnson opened this issue 2 years ago • 1 comments

Provide a variant of 3d tiles renderer that uses three.js' BatchedMesh to reduce draw calls. Related to gkjohnson/batched-3d-tiles-demo.

Useful for things like google earth and mars tiles.

For an initial set of requirements:

  • Requires all geometry to be of a similar size or maximum-size.
  • Requires that all geometry use a similar size of texture and at most one texture.
  • Requires that all tiles must use a common tile material / shader.

Process:

  • On geometry load copy the texture into a texture array and geometry into the BatchedMesh in a pre-determined buffer size along with the transform.
  • Discard the original geometry on load and store the BatchedMesh and texture index.
  • If we find a mesh that is too large to fit in the pre-allocated buffer length then create a new BatchedMesh.
  • Implement a custom traversal algorithm for batched mesh.

Open Questions:

  • Interoperability with other plugins (with shader, etc)

gkjohnson avatar Nov 15 '23 09:11 gkjohnson

From #628

Related to #604

Add a plugin that fills in a BatchedMesh with the loaded tiles geometry, uses a custom material with support for reading from a texture array, and uploading textures to an array.

See proof of concept here.

Approach

  • Create a preallocated BatchedMesh with enough space and large enough slots for the number of tiles to be rendered.
  • Preallocate a texture array with enough space for each texture needed.
  • Auto expand allocations if needed.
  • Custom materials for rendering with albedo from texture array.
  • We can lose original references to loaded geometry.

Changes Needed

  • Ray casting must change
  • Approach for storing internally references to geometry must change
  • Lots of internal callbacks and functions that rely on "scene" would have to change

Limitations

  • Will not work with Fading tiles.
  • Will only work with tile albedo.

gkjohnson avatar Jul 23 '24 07:07 gkjohnson

To start this could be developed to only work in simple cases (eg earth globe tiles)

gkjohnson avatar Sep 11 '24 06:09 gkjohnson

BatchedMesh optimizing and resizing will help here when we want to resize the gometry to support more / larger tiles than originally anticipated:

  • https://github.com/mrdoob/three.js/pull/29577
  • https://github.com/mrdoob/three.js/pull/29527

gkjohnson avatar Oct 07 '24 13:10 gkjohnson

Options

{
  instanceCount,
  vertexCount,
  indexCount,

  expansionPercent,
  maxExpansionCount,
  
  // possibly just inherit?
  textureSize, generateMipmaps, wrapping, etc,
  material,
}

gkjohnson avatar Oct 10 '24 03:10 gkjohnson