API by package

@threenative/procedural-environment API

Every public function and class in @threenative/procedural-environment. Optional, bake-first procedural nature GLBs for ThreeNative: trees and cover (Arbor), forest floor (forest-kit) and rocks, cliffs and mountains (Outcrop), found by biome.

On this page

Generated from the engine's capability manifest: 11 functions. Each entry is the exported signature, what it is for, and a working example. Start with the package overview.

bakeCity

function · import { bakeCity } from "@threenative/procedural-environment"

Bake an Apex City Kit module to one GLB: a road tile, a building, a street prop, a vehicle, a race kit piece, a block or lot, a sidewalk, transit, a public space, a utility or a decal. The page's own generator and GLTFExporter run headless, so the GLB carries its merged meshes, its materials and textures (Poly Haven CC0 PBR maps and the canvas-drawn signs, liveries and markings) and its road sockets in the root node's extras.

ts
async function bakeCity(options: IBakeCityOptions): Promise<IEnvironmentBake[]>

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • generate a modular city street, intersection, roundabout or highway tile as a GLB
  • a procedural building, storefront, office tower, apartment block, house or warehouse for a city level
  • street props for a city: traffic signal, streetlight, bus shelter, hydrant, bench, mailbox, dumpster
  • a race track kit: starting grid, timing gantry, barriers, tire wall, kerbs, pit lane; or a car, van, kart or formula car

Example

ts
await bakeCity({ module: "office", detail: 1, dressing: false, out: "assets/city" });
await bakeCity({ module: "civic-ad", detail: 1, text: "GRAND PRIX", emissiveSigns: true, out: "assets/city" });
// Modular-road layout built from kit tiles:
await bakeCity({ module: "cross", out: "assets/city" });

Good to know

  • fails closed: an unknown module throws naming the nearest ids; seed is an integer 0 to 4294967295, detail 0 to 2, wet 0 to 100, floors an integer 2 to 12, text at most 24 characters, dressing a boolean
  • the same options write identical bytes on one Node major and machine (fonts draw the sign text); files are written atomically (temporary file, then rename)
  • units are metres, +Y up; stock roads fit a 24 m grid, and custom straights and bends export updated socket positions, directions, widths and lane centres in the root node's extras
  • roadWidth and markings apply to straight and curve; roadLength applies to straight; bendAngle, bendRadius and bendSide apply to curve; roadSurface applies to socketed road modules
  • bake-time only, so keep it a dev dependency; textures are capped at 1024 px like the page's export
  • only bake road tiles (straight, curve, cross, tee, alley, grid, pit, cul-de-sac) when assembling the drivable carriageway from kit tiles; when a level builds its own spline or terrain road, bake scenery modules instead (detail: 1, dressing: false keeps draw counts low)
  • emissiveSigns: true lights canvas-drawn signs (extras.sign) for night scenes; opaqueGlass: true converts transmissive architectural glass to opaque reflective PBR glass so background buildings avoid a full-scene transmission pass

Also found by

  • city kit
  • modular road tiles
  • low poly city buildings
  • cars and vehicles

bakeRock

function · import { bakeRock } from "@threenative/procedural-environment"

Bake a procedural rock (Outcrop) to GLBs, one per level of detail: a boulder, slab, spire, hoodoo, sea stack, mesa, arch, tileable cliff module or a mountain, weathered and coloured for its biome (moss in a forest, snow in the tundra, sand in the desert, algae below the tide line).

ts
async function bakeRock(options: IBakeRockOptions): Promise<IEnvironmentBake[]>

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • generate a procedural rock, boulder or cliff as a GLB for a game level
  • desert mesa, hoodoo or sandstone arch; coastal sea stack; alpine spire; volcanic basalt columns
  • a procedural mountain mesh for the horizon, with snow at altitude

Example

ts
await bakeRock({ form: "cliff", biome: "coastal", seed: 7, lods: [0, 1], out: "assets/rocks" });
await bakeRock({ form: "boulder", biome: "forest", traits: { weathering: 0.8 }, out: "assets/rocks" });
for (const n of [0, 1, 2]) await bakeRock({ form: "cliff", biome: "desert", seed: 7, offset: [n * 10, 0, 0], out: "assets/rocks" }); // three modules of one wall

Good to know

  • fails closed: an unknown form or biome throws naming the nearest ids, as do unknown traits or surface keys, a non-integer seed, a lod outside 0 to 2 and a detail outside 0 to 1
  • the same options write identical bytes; files are written atomically (temporary file, then rename)
  • each GLB carries POSITION, NORMAL and COLOR_0 (linear RGB, rock and cover already blended) on one rock material; units are metres, +Y up, the rock rests on y = 0
  • a cliff module shows a cut face at each end: bake a run with one seed and offset: [n * width, 0, 0], stand the modules one width apart and bury the two ends of the run
  • bake-time only, so keep it a dev dependency; the game owns the material and can re-material by the glTF material name rock

Also found by

  • rocks and boulders
  • cliffs and mountains

bakeVegetation

function · import { bakeVegetation } from "@threenative/procedural-environment"

Bake a procedural tree (Arbor) to GLBs, one per level of detail, ready for ctx.assets.model. Each GLB carries the _WIND vertex attribute, COLOR_0 and TEXCOORD_0 and embeds WebP textures: Arbor trees and cover wear a CC0 bark scan and alpha-masked leaves, blades, fronds and needles painted from CC0 leaf scans; forest-kit wood and stone wear a grey CC0 detail scan, and forest-kit cover and leaf litter a grey CC0 blade or leaf scan, each over the kit's COLOR_0 palette.

ts
async function bakeVegetation(options: IBakeVegetationOptions): Promise<IEnvironmentBake[]>

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • generate a procedural tree, an oak, pine, spruce, palm or any forest species as a GLB
  • procedural oak tree GLB with level of detail for a game forest
  • tree GLB for Unity, Unreal or Godot, with wind weights in a _WIND attribute
  • a fallen mossy log and leaf litter on the forest floor, with a stump, twigs and boulders
  • reeds and cattails at a pond edge, or sedge tussocks, clover and seeding grass as cover

Example

ts
await bakeVegetation({ preset: "oak", seed: 7, lods: [0, 1], out: "assets/trees" });
await bakeVegetation({ preset: "log", seed: 3, out: "assets/debris" });

Good to know

  • fails closed: an unknown preset throws naming the nearest ids, the seed must be an integer and each lod 0 to 2
  • the same preset, seed and lods write identical bytes; files are written atomically (temporary file, then rename)
  • bake-time only, so keep it a dev dependency; the game owns the look and the sway (a TSL render/wind.ts reading _WIND), because Arbor.three is not shipped
  • _WIND is vec4 (trunk sway, branch sway, flutter, phase): forest-kit sway is flutter in z, and debris writes all four zero
  • textures default to "scans" (the bake's scan and leafScan name them); nine presets with no fitting CC0 leaf scan (ginkgo, palms, banana, joshua, flowers, elephantear) keep Arbor's drawn leaf card; textures: "generated" keeps every generator texture byte for byte
  • form, leafImage, barkImage and barkNormalImage patch an Arbor preset only; a forest-kit debris or cover preset throws when given any

Also found by

  • trees
  • palm trees
  • street trees along a road
  • bushes and shrubs
  • grass, flowers and ferns as ground cover
  • dead trees, fallen logs and stumps
  • low poly tree with level of detail
  • realistic textured tree model
  • foliage and vegetation models
  • pine, oak or spruce forest trees
  • grass tufts and clumps

environmentBiomes

function · import { environmentBiomes } from "@threenative/procedural-environment"

Every biome: its id, name, the request words that mean it, the rock surface its rocks wear and the element ids that belong there.

ts
function environmentBiomes(): IEnvironmentBiome[]

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • which biomes can I bake nature for: forest, desert, jungle, tundra, coast, volcano
  • what trees, plants, debris and rocks belong in a desert or an alpine biome

Example

ts
environmentBiomes().map((biome) => biome.id);

Good to know

  • ids match the Strata terrain kits where they overlap (forest, coastal, alpine, desert, tundra)

environmentElements

function · import { environmentElements } from "@threenative/procedural-environment"

Find the nature elements to bake, by biome, kind or words: trees, ground cover, forest-floor debris and rock forms (boulders, cliffs, sea stacks, mesas, arches, mountains), each with the exact bake call.

ts
function environmentElements(filter: IEnvironmentFilter =

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • what can I bake for a desert, a jungle, a coast, a tundra or a volcanic island
  • list the rocks, cliffs and mountains for a biome, or every plant that grows there
  • find a tree or plant by name or latin name, such as pine, palm, cactus or fern

Example

ts
environmentElements({ biome: "desert", kind: "rock" }).map((element) => element.bake);
environmentElements({ search: "palm" });

Good to know

  • fails closed: an unknown biome or kind throws naming the nearest ids
  • biome takes an id or one of its words, so "jungle" finds tropical and "swamp" finds wetland

Also found by

  • nature props for a level
  • jungle and tropical plants
  • desert cactus
  • vegetation for a biome

vegetationPresets

function · import { vegetationPresets } from "@threenative/procedural-environment"

List every preset a bake can grow: id, name, latin name and kind. Trees and cover come from Arbor; the debris rows (log, stump, twig, branch, leaflitter, rock) and the extra cover rows (reeds, tussock, seedgrass, clover, dock, plume) come from forest-kit.

ts
function vegetationPresets(): IVegetationPreset[]

Needs

  • npm i -D @threenative/procedural-environment

Use it to

  • list the oak, pine, spruce, palm and other tree species a bake can grow
  • choose a tree species id for bakeVegetation or a terrain arbor: species
  • what deadwood, leaf litter, boulders, reeds and tussocks can I bake for a forest floor

Example

ts
vegetationPresets().filter((p) => p.kind === "debris").map((p) => p.id);

Good to know

  • ids come from the vendored Arbor and forest-kit presets; trees are kind "tree", grass, ferns and flowers are kind "cover", deadwood, litter and stone are kind "debris"

createStylizedAsset

function · import { createStylizedAsset } from "@threenative/procedural-environment/stylized"

Generate a Stylized Biome Kit or Dungeon piece or scene with its Three.js materials.

ts
function createStylizedAsset( id: string, options: IStylizedAssetOptions =

Needs

  • npm i @threenative/procedural-environment

Use it to

  • create stylized mountain ridges, snowy trees, sandstone formations, or animated water
  • create modular dungeon walls, stairs, arches, dungeon props and fixtures in an overgrown, frozen, or volcanic theme

Example

ts
const { group } = createStylizedAsset("mountain-snow", { seed: 8, variant: 1 });

Good to know

  • the biome shaders, dungeon surface finish, and fire motion use Three.js WebGL materials

scatter

function · import { scatter } from "@threenative/procedural-environment/stylized"

Make instanced batches of a Stylized Biome Kit piece at explicit positions.

ts
function scatter( source: Object3D, placements:

Needs

  • npm i @threenative/procedural-environment

Use it to

  • instance a stylized biome tree or grass asset at many positions

Example

ts
scene.add(scatter(group, [{ x: 5, z: 8 }, { x: 9, z: 10, rot: 1 }]));

sky

function · import { sky } from "@threenative/procedural-environment/stylized"

Build a gradient sky dome with the Stylized Biome Kit's WebGL shader.

ts
function sky(options?:

Needs

  • npm i @threenative/procedural-environment

Use it to

  • a procedural stylized gradient sky dome for an alpine, snow, or desert scene

Example

ts
scene.add(sky({ top: 0x3a8be8, horizon: 0xe2f1ff }));

stylizedAssets

function · import { stylizedAssets } from "@threenative/procedural-environment/stylized"

List the Stylized Biome Kit pieces and scenes, including available variants.

ts
function stylizedAssets(): IStylizedAsset[]

Needs

  • npm i @threenative/procedural-environment

Use it to

  • browse procedural stylized biome assets for alpine forest, snow peaks, or desert canyon
  • browse modular dungeon walls, stone floors, arches, doors, props, fixtures, and assembled dungeon scenes

Example

ts
const rows = stylizedAssets();

terrain

function · import { terrain } from "@threenative/procedural-environment/stylized"

Build stylized heightfield geometry with a color callback and a second-color mask for path edges.

ts
function terrain(options:

Needs

  • npm i @threenative/procedural-environment

Use it to

  • make stylized heightfield terrain with vertex colors and a worn path

Example

ts
const meadow = terrain({ height: (x, z) => 1 + Math.sin(x) * Math.cos(z), color: (_x, _z, _y, _n, out) => out.set(0x55b93e) });
View source on GitHub ↗