fix: use InstancedMesh for CaloCells to prevent WebGL crash (#474)#849
fix: use InstancedMesh for CaloCells to prevent WebGL crash (#474)#849
Conversation
|
@EdwardMoyse @sponce would appreciate a review on this whenever you have time ! |
|
@EdwardMoyse is it working on your local machine? |
| // disappear when panning. | ||
| mesh.computeBoundingSphere(); | ||
|
|
||
| mesh.name = 'CaloCellInstanced'; |
There was a problem hiding this comment.
Maybe just call it CaloCell? I think the fact it is instanced is an implementation detail we shouldn't expose to the user?
|
In general this is very impressive @rx18-eng - the one thing which I think is missing is it is not possible to select CaloCells any more (at least, not with the pulsing outline)? IIRC it was because of this we didn't do it before, but the cuts work well (and the way you did this is very smart IMO) which was another blocker you worked around. |
|
Thanks for your review ! I renamed it to just CaloCell. For the hover - OutlinePass can't target individual instances so I used a color-based approach instead: hovered cell turns white, original color restores when you move away. Also fixed a bug where the info panel wasn't updating between cells (same object reference meant the hover-change check always Recording.2026-04-02.050111.mp4 |
… Signed-off-by: rx18-eng <remopanda78@gmail.com>
d46a377 to
766d3ba
Compare
Title
fix: use InstancedMesh for CaloCells to prevent WebGL crash (#474)
Body
Summary
This fixes the long-standing CaloCells performance issue (#474) where loading ATLAS events with calorimeter data (187,650 cells) would crash the browser. FPS dropped to ~1.8 and WebGL context was lost entirely, making the page unrecoverable.
I spent a good amount of time digging into this one. The root cause was straightforward but the fix touched a lot of surfaces. Phoenix was creating a separate THREE.Mesh (each with its own BoxGeometry + MeshPhongMaterial) for every single cell. That's 187K individual draw calls per frame. No GPU can handle that.
The fix replaces all of that with a single THREE.InstancedMesh (one geometry, one material, one draw call). Per-instance transforms and colors are stored in typed arrays. On my test machine (laptop), loading the same atlas.json that used to crash now runs at a stable 30 FPS with zero impact from CaloCells being enabled.
What changed
Issues I ran into along the way
Performance
Before: 187,000 draw calls, 187,000 scene graph children, 1.8 FPS (context lost on atlas.json)
After: 1 draw call, 1 scene graph child, stable 30 FPS on laptop
Recording.2026-03-26.062745.mp4