ConiferGen: deterministic generator for the alpineProps conifers.
local ConiferGen = require("~.ConiferGen")
local out = ConiferGen.generate("spruce", "veteran", 2)
-- out.lods[0] = { bark, leaf, snow, toon, tsnow }, out.lods[1] = { bark, leaf, snow },
-- out.lods[2] = { bark, leaf, snow, barkw? } (Geo geometries)
local snag = ConiferGen.generate("deadSpruce", nil, 1) -- lods[k] = { bark, snow }
How a conifer is grown. Spruce, fir, larch, stone pine and the young pines
are EXCURRENT: one leader to the top with whorls of primary branches every
annual shoot, each branch shaped by its species (spruce droops and turns its
tips up, old spruce hangs curtains of twigs; fir lies flat in tiers and an
old fir flattens into a stork's nest; larch droops long twigs; stone pine
turns up dense and, old, forks into several tops), its length cut by a
per-species crown profile (narrow cone, flat-topped cone, rounded column).
Mature and old Scots pines and the treeline windbent pine grow PINE-form:
a clear bole into a few big upturned limbs carrying clumped needle tufts,
under a flat (or wind-flagged) crown. Mountain pine is MULTI-stemmed:
sprawling stems curving up from the base into a dome. Krummholz is a
wind-bent mat streaming leeward (+X). Dead and fallen trees are bark only.
Needles are alpha-cut spray cards (UV 0..1 per card, v = 1 at the base),
vertex alpha = wind weight (0 base -> 1 tip), RGB = shade/tint (darker in the
crown core). Snow is opaque pads on the upper side of branch layers and
foliage clumps (or ridges along bare branches); far LODs are coarse cards
placed where the near cards are, so the silhouette and colour hold at 300 m.
The `toon` part is stacked jagged cone tiers (spruce/fir/larch) or clumped
blobs (pines), `tsnow` its snow caps.
Tool-time work: ConiferBake calls this; nothing loads it at runtime.
Tube, growth and blob helpers follow forestProps' TreeGen (Beechwood Brook, MIT).
smooth(a: number, b: number, x: number) → number
| arg | type | description |
|---|
| a | number | |
| b | number | |
| x | number | |
mix(a: number, b: number, t: number) → number
| arg | type | description |
|---|
| a | number | |
| b | number | |
| t | number | |
dirEl(az: number, elDeg: number) → void
| arg | type | description |
|---|
| az | number | |
| elDeg | number | |
horiz(v: { number }) → void
| arg | type | description |
|---|
| v | { number } | |
hlen(v: { number }) → number
| arg | type | description |
|---|
| v | { number } | |
byAge(age: string, t: { any }) → any
| arg | type | description |
|---|
| age | string | |
| t | { any } | |
cfgFor(kind: string, age: string?) → any
Every field a config may carry (all lengths in metres, angles in degrees):
form excurrent | pine | multi | krummholz | dead | fallen
H R trunkR height, crown radius, trunk radius at the base
crownBase fraction of H where the live crown starts
profile cone | stork | column | egg | umbrella (crown radius over the crown height)
whorl perWhorl inter whorl spacing, branches per whorl, interwhorl branches
el droop tipUp primary elevation bottom->top, droop along it, tip upturn
lat lateral twigs { spacing, frac, max, angle, tMin, rise, gravity, hangP, hangLen }
foliage spray | fir | larch | tuft ; cardW cardH roll vertP leafShare
snow branch | cell | ridge
toon tiers | blobs
| arg | type | description |
|---|
| kind | string | |
| age | string? | |
profile(c: any, u: number) → number
| arg | type | description |
|---|
| c | any | |
| u | number | |
crownR(c: any, y: number) → number
| arg | type | description |
|---|
| c | any | |
| y | number | |
newBranch(level: number, nodes: { Node }, vOffset: number) → any
| arg | type | description |
|---|
| level | number | |
| nodes | { Node } | |
| vOffset | number | |
nodeAt(b: any, t: number) → void
| arg | type | description |
|---|
| b | any | |
| t | number | |
tAtHeight(b: any, y: number) → number
| arg | type | description |
|---|
| b | any | |
| y | number | |
path(p0: { number }, dirFn: (number) → void
Polyline along a direction function of the fraction t.
| arg | type | description |
|---|
| p0 | { number } | |
| dirFn | (number | |
keepAbove(nodes: { Node }, y0: number) → void
| arg | type | description |
|---|
| nodes | { Node } | |
| y0 | number | |
addLaterals(c: any, rng: any, b: any, all: { any }) → void
Lateral twigs along a branch: alternating sides in the branch's own plane
(flat sprays), or hanging curtains (old spruce), or drooping (larch).
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| b | any | |
| all | { any } | |
addStubs(c: any, rng: any, trunk: any, y0: number, y1: number, n: number, all: { any }) → void
Short dead stubs on the bare bole below the crown (spruce, fir, larch, old pines).
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| trunk | any | |
| y0 | number | |
| y1 | number | |
| n | number | |
| all | { any } | |
excurrent(c: any, rng: any, all: { any }) → void
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
primary(axis: any, nd: Node, az: number, u: number, lenMul: number, inter: boolean) → void
| arg | type | description |
|---|
| axis | any | |
| nd | Node | |
| az | number | |
| u | number | |
| lenMul | number | |
| inter | boolean | |
pineLimbs(c: any, rng: any, all: { any }) → void
Pine-form crowns: a bole into big upturned limbs, sub-branches, and twigs
whose ends carry the needle tufts. `flag` keeps limbs on the lee side (+X).
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
outside(p: { number }, slack: number) → boolean
| arg | type | description |
|---|
| p | { number } | |
| slack | number | |
subBranches(limb: any) → void
| arg | type | description |
|---|
| limb | any | |
multiStem(c: any, rng: any, all: { any }) → void
Mountain pine: several stems sprawling out of one base and curving up.
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
yMax(rr: number) → number
| arg | type | description |
|---|
| rr | number | |
outside(p: { number }) → boolean
| arg | type | description |
|---|
| p | { number } | |
krummholzSkel(c: any, rng: any, all: { any }) → void
Krummholz: stunted spruce stems bent leeward (+X) into a flat-topped mat,
branches only on the lee side, dead stubs to windward.
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
lee(st: any, t: number, lenMul: number, skirt: boolean) → void
| arg | type | description |
|---|
| st | any | |
| t | number | |
| lenMul | number | |
| skirt | boolean | |
deadSnag(c: any, rng: any, all: { any }) → void
Dead spruce snag: silver bole with a snapped top, drooping dead branches
(longest mid-crown), stubs low down.
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
fallen(c: any, rng: any, all: { any }) → void
Fallen spruce: lying along +X from its root collar at the origin, branch
stubs whorled round the stem (none into the ground), a snapped top.
| arg | type | description |
|---|
| c | any | |
| rng | any | |
| all | { any } | |
barkTint(c: any, p: { number }, level: number) → void
| arg | type | description |
|---|
| c | any | |
| p | { number } | |
| level | number | |
tube(g: any, c: any, nodesIn: { Node }, o: any) → void
| arg | type | description |
|---|
| g | any | |
| c | any | |
| nodesIn | { Node } | |
| o | any | |
cap(ii: number, dirSign: number) → void
| arg | type | description |
|---|
| ii | number | |
| dirSign | number | |
sidesFor(level: number, r: number, lod: number) → number
| arg | type | description |
|---|
| level | number | |
| r | number | |
| lod | number | |
strideFor(level: number, lod: number) → number
| arg | type | description |
|---|
| level | number | |
| lod | number | |
tubeTris(nNodes: number, stride: number, sides: number) → number
| arg | type | description |
|---|
| nNodes | number | |
| stride | number | |
| sides | number | |
barkMesh(c: any, branches: { any }, lod: number, maxLevel: number, budget: number?) → any
Bark for one LOD within a triangle budget: trunks and leaders always, then
finer branches lowest level first, thickest first, until the budget is spent.
| arg | type | description |
|---|
| c | any | |
| branches | { any } | |
| lod | number | |
| maxLevel | number | |
| budget | number? | |
crownCentreAt(c: any, y: number) → void
| arg | type | description |
|---|
| c | any | |
| y | number | |
shellQ(c: any, p: { number }) → number
How far out in the crown a point is (0 core .. 1 shell), for shading.
| arg | type | description |
|---|
| c | any | |
| p | { number } | |
outwardAt(c: any, p: { number }) → void
| arg | type | description |
|---|
| c | any | |
| p | { number } | |
hostsFor(c: any, branches: { any }) → void
Hosts: { b, t0, t1, mode } spans of branches that carry needles.
| arg | type | description |
|---|
| c | any | |
| branches | { any } | |
placeCards(c: any, branches: { any }, rng: any, target: number) → void
| arg | type | description |
|---|
| c | any | |
| branches | { any } | |
| rng | any | |
| target | number | |
cardMesh(c: any, cards: { any }, every: number, sizeMul: number, offset: number?) → any
| arg | type | description |
|---|
| c | any | |
| cards | { any } | |
| every | number | |
| sizeMul | number | |
| offset | number? | |
vtx(p: { number }, u: number, v: number, a: number) → number
| arg | type | description |
|---|
| p | { number } | |
| u | number | |
| v | number | |
| a | number | |
farCards(c: any, cards: { any }, target: number) → void
Far cards: every n-th near card (outer shell first), enlarged to keep the coverage.
| arg | type | description |
|---|
| c | any | |
| cards | { any } | |
| target | number | |
snowVertex(g: any, p: { number }, n: { number }, shade: number) → number
| arg | type | description |
|---|
| g | any | |
| p | { number } | |
| n | { number } | |
| shade | number | |
pad(g: any, ctr: { number }, along: { number }, ra: number, rb: number, T: number, segs: number, seed: number) → void
A snow pad: a pillowed ellipse (radii ra along `along`, rb across) with a
skirt drooping over its edge. 3 * segs triangles.
| arg | type | description |
|---|
| g | any | |
| ctr | { number } | |
| along | { number } | |
| ra | number | |
| rb | number | |
| T | number | |
| segs | number | |
| seed | number | |
ridge(g: any, b: any, stride: number, widthMul: number, Tmul: number) → void
Snow along the upper side of a bare branch: a ridge three vertices wide.
| arg | type | description |
|---|
| g | any | |
| b | any | |
| stride | number | |
| widthMul | number | |
| Tmul | number | |
ridgeTris(b: any, stride: number) → number
| arg | type | description |
|---|
| b | any | |
| stride | number | |
branchPads(c: any, branches: { any }, rng: any) → void
Pads along the exposed outer part of every needle-bearing primary branch.
| arg | type | description |
|---|
| c | any | |
| branches | { any } | |
| rng | any | |
cellPads(c: any, cards: { any }, cell: number, rng: any) → void
Pads on the tops of foliage clumps (pines, mountain pine, krummholz): the
cards are binned into cells; a cell with no clump right above it gets a pad.
| arg | type | description |
|---|
| c | any | |
| cards | { any } | |
| cell | number | |
| rng | any | |
padsMesh(pads: { any }, budget: number, segs: number, sizeMul: number) → any
| arg | type | description |
|---|
| pads | { any } | |
| budget | number | |
| segs | number | |
| sizeMul | number | |
tierShape(c: any, i: number, nTiers: number) → void
| arg | type | description |
|---|
| c | any | |
| i | number | |
| nTiers | number | |
toonTiers(c: any, nTiers: number, sides: number) → any
Stacked jagged cone tiers (toon spruce, fir, larch, young pines).
| arg | type | description |
|---|
| c | any | |
| nTiers | number | |
| sides | number | |
toonTierSnow(c: any, nTiers: number, sides: number) → any
Snow caps on the toon tiers: the upper part of each cone, a little proud of it.
| arg | type | description |
|---|
| c | any | |
| nTiers | number | |
| sides | number | |
onCone(f: number) → void
| arg | type | description |
|---|
| f | number | |
icosphere(subdiv: number) → void
| arg | type | description |
|---|
| subdiv | number | |
mid(a: number, b: number) → number
| arg | type | description |
|---|
| a | number | |
| b | number | |
toonBlobs(c: any, cards: { any }) → void
Clumped blobs for the toon pines: the cards binned into cells, one squashed
sphere per well-filled cell. Returns the mesh and the blob list (for tsnow).
| arg | type | description |
|---|
| c | any | |
| cards | { any } | |
toonBlobSnow(blobs: { any }, sides: number) → any
| arg | type | description |
|---|
| blobs | { any } | |
| sides | number | |
onBlob(ang: number, k: number) → void
points on the squashed sphere at polar angles ~35 and ~62 degrees, pushed out a hair
| arg | type | description |
|---|
| ang | number | |
| k | number | |
boundsOf(list: { any }) → void
| arg | type | description |
|---|
| list | { any } | |
shareBounds(parts: { any }) → void
Same bounds for every part of one LOD (two unreferenced corner vertices), so
MeshLod measures each part as the whole tree and all parts swap together.
| arg | type | description |
|---|
| parts | { any } | |
skeleton(c: any, rng: any) → void
| arg | type | description |
|---|
| c | any | |
| rng | any | |
bareSnow(c: any, branches: { any }, lod: number, budget: number) → any
| arg | type | description |
|---|
| c | any | |
| branches | { any } | |
| lod | number | |
| budget | number | |
generate(kind: string, age: string?, variant: number) → any
Generate one conifer (species at an age, or a dead/odd kind), returning Geo geometries per LOD.
| arg | type | description |
|---|
| kind | string | |
| age | string? | |
| variant | number | |