File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
packages/voxel-renderer/src/world Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @jolly-pixel/voxel.renderer " : patch
3+ ---
4+
5+ Drain and remove empty VoxelLayer
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ export class VoxelLayer {
7373 #visible: boolean ;
7474 #chunks = new Map < string , VoxelChunk > ( ) ;
7575 #chunkSize: number ;
76+ #pendingRemoval: VoxelChunk [ ] = [ ] ;
7677
7778 constructor (
7879 options : VoxelLayerOptions
@@ -235,6 +236,7 @@ export class VoxelLayer {
235236 this . #chunks. delete (
236237 this . #createChunkKey( cx , cy , cz )
237238 ) ;
239+ this . #pendingRemoval. push ( chunk ) ;
238240 }
239241 }
240242
@@ -320,6 +322,12 @@ export class VoxelLayer {
320322 yield * this . #chunks. values ( ) ;
321323 }
322324
325+ * drainPendingRemovals ( ) : IterableIterator < VoxelChunk > {
326+ while ( this . #pendingRemoval. length > 0 ) {
327+ yield this . #pendingRemoval. pop ( ) ! ;
328+ }
329+ }
330+
323331 get chunkCount ( ) : number {
324332 return this . #chunks. size ;
325333 }
Original file line number Diff line number Diff line change @@ -399,6 +399,14 @@ export class VoxelWorld {
399399 yield { layer, chunk } ;
400400 }
401401 } while ( this . #layersToRemove. length > 0 ) ;
402+
403+ // Drain individual chunks that became empty this frame.
404+ // Their Three.js meshes must be removed even though the layer is still active.
405+ for ( const layer of this . #layers) {
406+ for ( const chunk of layer . drainPendingRemovals ( ) ) {
407+ yield { layer, chunk } ;
408+ }
409+ }
402410 }
403411
404412 clear ( ) : void {
You can’t perform that action at this time.
0 commit comments