voxolith
API reference@voxolith/gen-grassFunctions

generateGrass()

Generate a patch of ground cover: tufts scattered evenly over a disc, each fanning blades out of the ground that arc over under their own weight, shaded dark to light from base to tip, with optional flower or seed heads and snow. Blades are independent pieces; any voxel that does not reach the...

function generateGrass(
   params: GrassParams, 
   rng: () => number, 
   id?: string, 
   ctx?: GenerateContext
): GrassResult;

Defined in: grass/src/index.ts:110

Generate a patch of ground cover: tufts scattered evenly over a disc, each fanning blades out of the ground that arc over under their own weight, shaded dark to light from base to tip, with optional flower or seed heads and snow. Blades are independent pieces; any voxel that does not reach the ground is dropped. Pure and deterministic in its params and rng.

With ctx.voxelsPerMetre above the native 10 (20, 50 or 100), the same design comes back refined: a sparse model k times the size, blades redrawn from the skeleton.

Parameters

ParameterTypeDefault valueDescription
paramsGrassParamsundefinedThe patch; not mutated. Start from a PRESETS entry.
rng() => numberundefinedSource of all randomness, returning 0..1 (e.g. seededRandom(seed)).
id?string"grass"The entity id.
ctx?GenerateContextundefinedOptional scale; omitted or 10 voxels per metre gives the coarse model.

Returns

GrassResult

The entity (kind groundcover, anchored at the centre of the patch on the ground) and stats.

Example

import { seededRandom } from "@voxolith/renderer/core";
import { cloneParams, generateGrass, PRESETS } from "@voxolith/gen-grass";

const p = cloneParams(PRESETS.meadow);
p.shape.footprint = 20;
const { entity } = generateGrass(p, seededRandom(11));

On this page