threejs-worldgen
    Preparing search index...

    Class PuddleField

    Rain water on terrain as a CPU height field: rain adds depth everywhere, water runs downhill and levels out (an explicit, mass-conserving relaxation of the water surface between neighbouring cells), soaks in and evaporates, so it gathers in low spots as puddles that grow while it rains and drain or dry when it stops. It also keeps a surface wetness 0…1. Both are plain row-major arrays from (minX, minZ), the layout of threejs-weathering's state field, for weathering and rendering to read. Deterministic (fixed internal step).

    Index
    • A dry field over height (none: flat at 0).

      Parameters

      • input: {
            cellSize?: number;
            dryTime?: number;
            evaporation?: number;
            flowSpeed?: number;
            infiltration?: number;
            origin?: [number, number];
            resolution?: [number, number];
            wetTime?: number;
        } = {}
        • OptionalcellSize?: number

          Cell size, metres. Fixed at construction.

        • OptionaldryTime?: number

          Seconds for a wet surface without standing water to dry (e-folding).

        • Optionalevaporation?: number

          Evaporation, mm/h.

        • OptionalflowSpeed?: number

          How fast water runs off and levels out, m/s (a sheet-flow speed: one cell per cellSize / flowSpeed seconds).

        • Optionalinfiltration?: number

          Water soaking into the ground, mm/h.

        • Optionalorigin?: [number, number]

          World x, z of the field's minimum corner (cell (i, k) is centred at origin + (i + ½, k + ½)·cellSize).

        • Optionalresolution?: [number, number]

          Cells along x and z. Fixed at construction.

        • OptionalwetTime?: number

          Seconds for a dry surface to get wet under rain (e-folding).

      • height: MPMHeightFn | null = null

      Returns PuddleField

    depth: Float32Array

    Standing water per cell, metres (row-major, x fastest).

    ground: Float32Array

    Terrain height at the cell centres, world metres.

    nx: number

    Cells along x and z.

    nz: number
    options: PuddleOptions

    Resolved settings.

    time: number = 0

    Simulated seconds.

    wetness: Float32Array

    Surface wetness per cell, 0…1.

    • Standing water and wetness at world (x, z), bilinear between cell centres (0 outside the field).

      Parameters

      • x: number
      • z: number
      • out: { depth: number; wetness: number } = ...

      Returns { depth: number; wetness: number }

    • Merges input into the settings (resolution and cellSize stay; moving origin re-bakes the ground and keeps the water per cell).

      Parameters

      • input: {
            cellSize?: number;
            dryTime?: number;
            evaporation?: number;
            flowSpeed?: number;
            infiltration?: number;
            origin?: [number, number];
            resolution?: [number, number];
            wetTime?: number;
        }
        • OptionalcellSize?: number

          Cell size, metres. Fixed at construction.

        • OptionaldryTime?: number

          Seconds for a wet surface without standing water to dry (e-folding).

        • Optionalevaporation?: number

          Evaporation, mm/h.

        • OptionalflowSpeed?: number

          How fast water runs off and levels out, m/s (a sheet-flow speed: one cell per cellSize / flowSpeed seconds).

        • Optionalinfiltration?: number

          Water soaking into the ground, mm/h.

        • Optionalorigin?: [number, number]

          World x, z of the field's minimum corner (cell (i, k) is centred at origin + (i + ½, k + ½)·cellSize).

        • Optionalresolution?: [number, number]

          Cells along x and z. Fixed at construction.

        • OptionalwetTime?: number

          Seconds for a dry surface to get wet under rain (e-folding).

      • Optionalheight: MPMHeightFn | null

      Returns this

    • One internal step of dt seconds: rain, flow, losses, wetness.

      Parameters

      • dt: number
      • rain: number = 0

      Returns void

    • Advances dt seconds with rain falling at rain mm/h (0: dry weather) in fixed internal steps. Past 64 steps (fast-forward) the steps lengthen instead: water and time stay exact, levelling lags.

      Parameters

      • dt: number
      • rain: number = 0

      Returns this