threejs-grass
    Preparing search index...

    Class GrassMap

    A world-space control texture covering a square of terrain: where grass grows and how tall. Channels: R = coverage (0 none … 1 full), G = height (0.5 = 1x … 1 = 2x). Outside its square, grass grows normally. Edits (paint/fill/load) show up immediately.

    const map = new GrassMap({ center: [0, 0], size: 300 })
    map.paint(10, -4, { mode: 'erase', radius: 2, strength: 1 }) // a clearing
    grass.set({ grassMap: map })
    Index
    data: Uint8Array

    Raw RGBA bytes, row-major, row 0 at minZ. Set texture.needsUpdate = true after editing directly.

    minX: number

    World X of the square's west edge.

    minZ: number

    World Z of the square's north (−Z) edge.

    resolution: number

    Texels per side.

    size: number

    Edge length of the mapped square in metres.

    texture: DataTexture

    GPU texture sampled by the grass (and by grass.mapNode()).

    • Frees the GPU texture.

      Returns void

    • Sets the whole map to one coverage (0..1) and height multiplier (0..2). fill(0) clears all grass.

      Parameters

      • coverage: number = 1
      • height: number = 1

      Returns void

    • Replaces the map's contents with an image (scaled to resolution). See GrassMap.fromImage.

      Parameters

      • image: CanvasImageSource & { height: number; width: number }

      Returns this

    • Applies a soft round brush at world (x, z).

      Parameters

      • x: number
      • z: number
      • __namedParameters: Brush

      Returns boolean

      false if the brush is entirely outside the map.

    • Raw map as a canvas (R = coverage, G = height); round-trips through GrassMap.fromImage.

      Returns HTMLCanvasElement

    • PNG data URL of the map, e.g. to save a painted layout.

      Returns string

    • Creates a map from an image (red = coverage, green = height, mid-grey = 1x), read as a top-down view with its top edge towards −Z. Round-trips with GrassMap.toDataURL.

      Parameters

      • image: CanvasImageSource & { height: number; width: number }
      • options: Omit<GrassMapOptions, "coverage" | "height"> = {}

      Returns GrassMap