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

BatchedGeometry #25050

Closed
wants to merge 1 commit into from
Closed

BatchedGeometry #25050

wants to merge 1 commit into from

Conversation

takahirox
Copy link
Collaborator

@takahirox takahirox commented Dec 1, 2022

Related issue: #22376

Description

This PR adds BatchedGeometry to addons.

BatchedGeometry allows to render many dynamic and different shape object referring to the same material with a single draw call. Please read #22376 (comment) for basic concept in more details.

Demo: https://raw.githack.com/takahirox/three.js/BatchedGeometry/examples/index.html#webgl_geometry_batch

API

// Initialize
const geometry = new BatchedGeometry(maxVertexCount, maxIndexCount);
const ids = [];

for (let i = 0; i < geometries.length; i++) {
  const id = geometry.apply(geometries[i]);
  geometry.setMatrixAt(id, matrices[i]);
  ids.push(id);
}

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

// update
for (let i = 0; i < ids.length; i++) {
  const id = ids[i];
  geometry.getMatrixAt(id, matrix);
  // update translate/quaternion/scale here
  geometry.setMatrixAt(id, matrix);
}

@takahirox
Copy link
Collaborator Author

Closing because I realized that updating positions/normals in CPU and/or uploading attribute arrays are slow and BatchedGeometry is useless.

It seems that matrices must be applied in shader (GPU) for the performance. The geometry level API doesn't really fit for it then I made another PR with mesh level API #25059

@takahirox takahirox closed this Dec 2, 2022
@takahirox takahirox deleted the BatchedGeometry branch December 2, 2022 08:00
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