generateRock()
Generate a rock: a noise-displaced superellipsoid cleaved by fracture planes, with any extra rocks shaped the same way and tumbled against it so the piece stays connected, then a surface pass for tones, strata, cracks, moss, lichen, damp and snow. Pure and deterministic in its params and rng.
function generateRock(
params: RockParams,
rng: () => number,
id?: string,
ctx?: GenerateContext
): RockResult;Defined in: index.ts:71
With ctx.voxelsPerMetre above the native 10 (20, 50 or 100), the same design comes back refined:
a sparse model k times the size with a rounded, grainy surface and hairline cracks.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
params | RockParams | undefined | The rock; not mutated. Start from a PRESETS entry. |
rng | () => number | undefined | Source of all randomness, returning 0..1 (e.g. seededRandom(seed)). |
id? | string | "rock" | The entity id. |
ctx? | GenerateContext | undefined | Optional scale; omitted or 10 voxels per metre gives the coarse model. |
Returns
The entity (kind rock, anchored at its bottom centre raised by shape.sink, so it
sits partly in the ground) and stats.
Example
import { seededRandom } from "@voxolith/renderer/core";
import { cloneParams, generateRock, PRESETS } from "@voxolith/gen-rock";
const p = cloneParams(PRESETS.boulder);
p.species = "sandstone";
p.look.strata = 6;
const { entity } = generateRock(p, seededRandom(5));