Builtin Library
README.md
curve.branch (procNode)
Branches sprouting from curves, generation after generation: each curve sends out branches children from along its length, turned off it by up to angle, ratio as long, wandering as they go. Cracks spreading, lightning forking, roots and veins.
Each generation is one pass of a fold. The parents of the pass are the previous generation's curves (the starting curves for the first). Every parent sends out branches walkers: a walker starts start + (1 - start) * draw of the way along its parent (core.sample_curve), heads off at the parent's tangent turned by up to angle about the plane's normal or about an axis drawn around the tangent, and takes segments steps of length parentLength * ratio * (1 - t / 2) / segments, turning by up to wander degrees at each. Walkers of parents with no length are dropped. Every walker owns a run of segments + 1 slots, walker after walker; each step writes the walker's position into its slot (core.scatter) and the finished slots are the curves' points (curve.strands).
The draws come from the growth scope, one channel per generation, step and use, so one seed grows the same branches everywhere. Each generation holds parents * branches curves of segments + 1 points.
Built from: curve.tag_trunks, core.arclength, core.sample_curve, core.select, core.scatter, core.points, core.concat, curve.strands, points.axis_basis, rand.unit, g:fold.
Inputs
curve(Curves). The curves growth starts from. They come out unchanged as generation 0.generations(Float). Default3. At least 0. How many times branches sprout from the branches before them.branches(Float). Default3. At least 0. How many children each curve sends out per generation.angle(Float). Default35. How far a child turns off its parent at most, in degrees; each turns between half this and all of it, to one side or the other.ratio(Float). Default0.6. A child's length as a share of its parent's, less the further along the parent it sprouts.segments(Float). Default8. At least 1. Spans in each child, which is where it can wander.wander(Float). Default15. How far a child may turn at each of its points, in degrees, drawn anew at each: 0 grows straight, larger grows jagged.start(Float). Default0.15. 0 to 1. How far along its parent, 0 to 1, a child may sprout at the earliest.normal(Vec3). Default{ x = 0, y = 0, z = 0 }. Keeps the growth in the plane this faces, as cracks keep to the surface they run over. Zero grows in every direction.seed(Float). Default1. Which of the possible growths this is; the same seed grows the same branches.
Outputs
curve: the starting curves followed by every generation's curves. Each point carriesgeneration(0 for the starting curves) andu(how far along its curve it stands, 0 to 1); each vertex carriessand each curvelength, fromcore.arclength.
Example
local line = g.curve.line({ start = vector.create(0, 0, 0), finish = vector.create(4, 0, 0), segments = 4 })
local cracks = g.curve.branch({ curve = line, generations = 2, branches = 2, segments = 4, seed = 3 })
One trunk, two children and four grandchildren: seven curves, the children of five points each.