threejs-worldgen
    Preparing search index...

    Class Scatter

    Streams instanced objects (trees, rocks, shrubs…) over terrain in camera-centred tiles.

    Each tile places every layer with seamless blue noise (see poissonDisk), filtered by density, slope, height and clumping noise, so the world is a pure function of seed and position. Instances of each layer and level of detail are pooled into one instanced mesh, so draw calls don't grow with the number of tiles.

    const scatter = Scatter.create({ camera, scene, terrain, layers: [
    { name: 'boulder', spacing: 12, lods: [{ distance: 150, geometry, material }], align: 1, scale: [0.6, 1.8] },
    ] })
    Index
    camera: Camera

    Camera the tiles follow. Can be swapped at any time.

    object: Group<Object3DEventMap> = ...

    Root of all pooled meshes. Added to scene for you when one is passed to Scatter.create.

    sampleHeight: HeightFn

    Terrain height at world (x, z); NaN where there is no terrain.

    settings: ScatterSettings

    Resolved settings. Read-only: change them with Scatter.set / Scatter.reset.

    stats: ScatterStats = ...

    Live counters, refreshed on every Scatter.update.

    • Removes the scatter from the scene and drops its pools (reclaimed by GC, see retire). Layer geometries and materials are yours to dispose.

      Returns void

    • Instances within radius of world (x, z), for gameplay and collision. Deterministic: tiles that are not streamed in are generated on the fly (not cached), so results don't depend on where the camera is.

      Parameters

      • x: number
      • z: number
      • radius: number

      Returns ScatterInstance[]

    • Throws away all generated tiles; they are rebuilt (within the build budget) over the next frames.

      Returns void

    • Changes settings, merging into what was set before (layers is replaced as a whole). Only what changed is redone: placement changes regenerate the affected layer groups, LOD/material changes only rebuild the pools. Density functions are read when a tile is generated; call Scatter.regenerate after changing what one returns.

      Parameters

      Returns this

    • Streams tiles in and out around the camera, generates pending ones within the budget and, when the camera has moved far enough or tiles changed, re-sorts instances into levels of detail. Called automatically when a scene was given (and by <Scatter>); otherwise call it once per frame.

      Parameters

      • budget: number = ...

        Milliseconds for tile generation this frame. Defaults to settings.buildBudget.

      Returns void