hex-world
    Preparing search index...

    Class ChunkManager

    Manages the Three.js meshes for a HexMap using a chunk-based streaming system.

    The map is divided into NxN cell chunks. update(camera) loads chunks within loadRadius of the camera each frame and unloads those that have moved out of range. Each chunk is a single merged BufferGeometry draw call for terrain, with optional separate meshes per liquid type for surface, shore, estuary, rivers, and waterfall spray/foam, plus roads and scatter features.

    Call markDirty(col, row) after modifying map data to trigger a geometry rebuild for the affected chunk on the next update().

    Index

    Constructors

    Properties

    Streaming lifecycle events — chunkLoaded once a chunk's meshes are in the scene, chunkUnloaded once they're out of it and disposed.

    chunks.events.on('chunkLoaded', ({ bounds }) => spawnPropsIn(bounds));
    
    chunkSize: number

    Accessors

    • get loadedWaterChunkCount(): number

      Total number of liquid surface meshes currently in the scene (all types combined).

      Returns number

    • get loadedShoreChunkCount(): number

      Number of shore foam meshes currently in the scene (all liquid types combined).

      Returns number

    • get loadedWaterfallFoamChunkCount(): number

      Number of waterfall plunge-pool meshes currently in the scene (all liquid types combined).

      Returns number

    • get loadedWaterfallSprayChunkCount(): number

      Number of waterfall spray particle systems currently in the scene (all liquid types combined).

      Returns number

    • get terrainMeshes(): Mesh<
          BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
          Material<MaterialEventMap> | Material<MaterialEventMap>[],
          Object3DEventMap,
      >[]

      Currently loaded terrain meshes — pass to pickHexFromMeshes for accurate raycasting.

      Returns Mesh<
          BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
          Material<MaterialEventMap> | Material<MaterialEventMap>[],
          Object3DEventMap,
      >[]

    • get geometryRevision(): number

      Changes whenever a terrain chunk is loaded, unloaded, or rebuilt.

      Returns number

    Methods

    • Call every frame with the current camera. Loads chunks within loadRadius, unloads those outside.

      Parameters

      • camera: Camera
      • dt: number = 0

      Returns void

    • Mark the chunk containing cell (col, row) as needing a geometry rebuild. Call after modifying map cell data.

      Cells on a chunk border also mark the adjacent chunk(s): their shore strips, skirts, bridges, and road geometry sample this cell, so rebuilding only the edited cell's chunk would leave the neighbour's geometry stale.

      Parameters

      • col: number
      • row: number

      Returns void

    • markDirty for a batch of cells — pairs with MapEdit.cells after undo/redo.

      Parameters

      • cells: Iterable<{ col: number; row: number }>

      Returns void

    • Replace the scatter definitions and rebuild every loaded chunk's scatter in place — terrain, liquids, and roads are untouched. This is what an editor's scatter builder calls on every change, so it has to be cheap relative to a full chunk rebuild, and it is: instanced meshes only.

      Parameters

      Returns void

    • Toggle whether unexplored cells are hidden. Independent of dimming.

      Parameters

      • enabled: boolean

      Returns void

    • Toggle whether explored-but-not-visible cells are dimmed. Independent of hide.

      Parameters

      • enabled: boolean

      Returns void

    • Dispose all loaded chunk meshes and their geometries, removing them from the scene.

      Does NOT dispose resources the caller passed in and still owns: the terrain material and its texture array, road material, liquid materials, scatter geometries/materials, and any FogData texture. Dispose those yourself when tearing down the scene for good.

      Returns void

    • Swap in a different HexMap without recreating the manager: all loaded chunks are unloaded and chunks for the new map stream in on the next update() (or loadAll()). Materials, terrain definitions, and options are kept. Water surfaces are recomputed so the new map renders correctly even if it was edited without a computeWaterSurfaces call.

      Parameters

      Returns void

    • Swap terrain definitions (and optionally the terrain material) in place — e.g. after the user defines custom terrain or loads a pack. All loaded chunks are unloaded and rebuilt with the new definitions on the next update() / loadAll(); water surfaces are recomputed because liquid terrain membership may have changed.

      The caller keeps ownership of the previous material (dispose it yourself if it is no longer used elsewhere).

      Parameters

      Returns void

    • Swap the liquid types (descriptors + material sets) in place — e.g. after the user edits a liquid's appearance or defines a new one. All loaded chunks are unloaded and rebuilt with the new liquids on the next update() / loadAll().

      The caller keeps ownership of the previous materials (dispose the ones that are no longer used).

      Parameters

      Returns void