voxolith

encodeState()

Pack a generator, its parameters and a seed into a shareable code: URL-safe base64, typically a few dozen characters. Only the declared params travel, each clamped and snapped to its spec, so a value off the step grid decodes to the nearest step.

function encodeState<P>(gen: EntityGenerator<P>, state: Omit<GeneratorState<P>, "generator" | "version">): string;

Defined in: engine/src/share.ts:241

Type Parameters

Type Parameter
P

Parameters

ParameterTypeDescription
genEntityGenerator<P>-
stateOmit<GeneratorState<P>, "generator" | "version">The seed (as an unsigned 32-bit integer) and the parameters.

Returns

string

The code; decodeState turns it back into the state.

Example

const code = encodeState(broadleafGenerator, { seed: 42, params: broadleafGenerator.defaults });
const tree = generateFromState(decodeState(code));

On this page