threejs-worldgen
    Preparing search index...

    Class FaunaLayer<S, T>Abstract

    Base class of a streamed animal layer (FishSchools, BirdFlocks; land herds later): deterministic per-tile spawning around the camera, one Flock per group, fixed-step simulation near the camera, and one instanced mesh per species. Subclasses supply the species table, the habitat rules, the mesh and material, and the per-member look and animation.

    Coordinates are the world's local frame (re-centred on the camera on planets); instance matrices are relative to an anchor near the camera, so GPU data stays small at any distance from the origin.

    Type Parameters

    Hierarchy (View Summary)

    Index
    camera: Camera

    Camera the tiles follow.

    frame: LocalFrame

    The frame groups live in (the world itself on flat worlds).

    input: Partial<T> = {}

    Input so far (merged by set).

    object: Group<Object3DEventMap> = ...

    Root object (placed in the current frame).

    salt: number

    Separates this kind's spawns from other kinds with the same seed.

    settings: T

    Resolved settings. Change them with set() / reset().

    stats: FaunaStats = ...

    Live counters, refreshed by update().

    time: number = 0

    Seconds simulated.

    views: Map<string, SpeciesView> = ...

    Per-species meshes.

    world: World

    The world.

    • Advances member i's animation (motion, 4 floats) and returns its roll (bank) angle.

      Parameters

      • species: S
      • group: FaunaGroup
      • i: number
      • dt: number
      • speed: number
      • turnRate: number

      Returns number

    • Pushes a species' look (and the layer's states) into its material.

      Parameters

      • id: string
      • species: S
      • geometry: BufferGeometry

      Returns void

    • Creates the geometry for a species (called when geometryKey changes).

      Parameters

      • species: S

      Returns BufferGeometry

    • Creates the material for a species.

      Parameters

      • id: string

      Returns Material

    • Removes the layer from the scene and frees its GPU resources.

      Returns void

    • Geometry rebuild key of a species.

      Parameters

      • species: S

      Returns string

    • Sets member i's scale (xyz into scale) and look (4 into look) from rand.

      Parameters

      • species: S
      • rand: () => number
      • scale: Float32Array
      • look: Float32Array
      • i: number

      Returns void

    • Extra placement-relevant settings of a subclass (JSON-compared).

      Returns unknown

    • Steepest pitch, radians.

      Parameters

      • species: S

      Returns number

    • Whatever about a species changes placement (JSON-compared).

      Parameters

      • species: S

      Returns unknown

    • Replaces all settings: anything not in input goes back to the defaults.

      Parameters

      • input: object | Partial<T> = {}

      Returns this

    • Changes settings, merging into earlier ones (nested objects merge, arrays replace). Looks apply at once; placement changes respawn groups.

      Parameters

      • input: object | Partial<T>

      Returns this

    • Moves the floating origin. Same as set({ origin }).

      Parameters

      • origin: readonly number[]

      Returns this

    • The species table.

      Returns Readonly<Record<string, S>>

    • Streams tiles around the camera, spawns within the time budget, steps the flocks at a fixed rate and writes the instances. Called automatically when a scene was given; otherwise once per frame.

      Parameters

      • delta: number = ...

        Seconds since the last frame; measured if omitted.

      • budget: number = ...

        Milliseconds for spawning this frame. Defaults to settings.buildBudget.

      Returns void