voxolith
API reference@voxolith/gen-treeFunctions

generateTree()

Generate a tree: grow the skeleton, voxelise and bark the wood, hang and carve the foliage, shade it, apply the season, then drop anything not connected to the base, so the result is always one piece. Pure and deterministic: the same params and rng sequence give the same tree.

function generateTree(
   params: TreeParams, 
   rng: () => number, 
   id?: string, 
   ctx?: GenerateContext
): TreeResult;

Defined in: tree/src/index.ts:128

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

Parameters

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

Returns

TreeResult

The entity (kind tree.broadleaf or tree.conifer, anchored at the foot of the trunk) and stats.

Example

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

const p = cloneParams(PRESETS.oak);
p.look.season = "autumn";
const { entity, stats } = generateTree(p, seededRandom(7));
const fine = generateTree(p, seededRandom(7), "oak", { voxelsPerMetre: 100 }).entity; // sparse

On this page