Skip to content

Conversation

@querielo
Copy link
Contributor

@querielo querielo commented Nov 4, 2025

Description

Fix buffer sync issues in BatchedMesh.prototype.optimize() that caused incorrect rendering after repacking. The method now:

  • Marks the index buffer as dirty after in-place reordering.
  • Marks moved vertex attributes as dirty after in-place copies.
  • Flags _visibilityChanged so draw ranges and visibility-dependent state get refreshed.

When optimize() compacts geometry ranges, it mutates the underlying typed arrays via copyWithin. However, without setting needsUpdate = true, WebGL/WebGPU buffers aren’t re-uploaded, resulting in stale GPU data and visible artifacts, especially after sequences like add/delete/optimize.

Also, _visibilityChanged must be set to ensure the next render pass rebuilds multi-draw ranges and respects updated starts/counts after repacking.

Copilot AI review requested due to automatic review settings November 4, 2025 16:57
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 355.14
86.33
355.14
86.33
+0 B
+0 B
WebGPU 609.62
170.99
609.62
170.99
+0 B
+0 B
WebGPU Nodes 608.23
170.72
608.23
170.72
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 486.77
121.07
486.77
121.07
+0 B
+0 B
WebGPU 678.47
186.28
678.47
186.28
+0 B
+0 B
WebGPU Nodes 620.47
169.54
620.47
169.54
+0 B
+0 B

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds necessary update flags to the optimize() method in BatchedMesh to ensure geometry data changes are properly synchronized with the GPU. The changes address a bug where optimized geometry buffers were not being marked for update.

  • Adds needsUpdate = true flags for index and attribute buffer updates during optimization
  • Sets _visibilityChanged = true to trigger re-rendering after geometry reorganization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@querielo querielo changed the title Fix index and attribute updates in the optimize method in BatchedMesh Fix index and attribute updates in the optimize method of BatchedMesh Nov 4, 2025
@Mugen87 Mugen87 requested a review from gkjohnson November 4, 2025 17:58
@gkjohnson gkjohnson changed the title Fix index and attribute updates in the optimize method of BatchedMesh BatchedMesh: Fix index and attribute updates in the optimize method Nov 6, 2025
@mrdoob mrdoob added this to the r182 milestone Nov 6, 2025
@mrdoob mrdoob merged commit c01ab58 into mrdoob:dev Nov 6, 2025
16 checks passed
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.

3 participants