threejs-worldgen
    Preparing search index...

    Class Lightning

    Lightning bolts and flashes from a Weather's thunderstorms. The strikes come from weather.strikes, so they are deterministic in time; each bolt's shape (a jagged channel with branches) is seeded by its strike, flickers through a few return strokes and lights the scene with a flash. All visible bolts are one merged geometry and one draw call. Subscribe with Lightning.onStrike to ignite wildfires or play thunder.

    const lightning = new Lightning({ weather, camera })
    scene.add(lightning.object)
    lightning.onStrike((s) => wildfire.ignite(s.x, s.z))
    // each frame: lightning.update(time)
    Index
    active: Strike[] = []

    Strikes visible on the last update.

    camera: Camera

    Camera strikes are shown around.

    flash: number = 0

    Current flash brightness 0…1 (drive sky or cloud brightness with it).

    ground: ((x: number, z: number) => number) | null

    Ground height (frame coordinates).

    light: PointLight = ...

    The flash light.

    object: Group<Object3DEventMap> = ...

    Add this to your scene (bolts and the flash light).

    Resolved settings.

    uniforms: {
        brightness: UniformArrayNode<string>;
        color: UniformNode<"color", Color>;
    } = ...

    Shader uniforms.

    Type Declaration

    • brightness: UniformArrayNode<string>

      Per-bolt brightness.

    • color: UniformNode<"color", Color>

      Bolt colour × intensity.

    weather: Weather

    Weather read for strikes.

    • Calls listener once for each strike as time passes it. Returns an unsubscribe function.

      Parameters

      • listener: (strike: Strike) => void

      Returns () => void

    • Sets the frame position at render-space zero (floating origin), [x, y, z].

      Parameters

      • origin: readonly number[]

      Returns this

    • Shows the strikes around the camera at time seconds and fires onStrike for new ones.

      Parameters

      • time: number

      Returns void