code wiki / (root) / nx_treegen.nx

nx_treegen.nx

buildroot/runtime/nx_treegen.nx

26774 B531 linesdepth 2pulls 4 transitivereach 10 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_treegen.nx -- ★SOVEREIGN INFINIGEN: procedural VEGETATION (trees). A seed grows a UNIQUE tree by recursive branching (an L-system-style growth stack): trunk -> branches -> sub-branches -> leaf clusters, with phototropism (upward bias) + seeded angle/length/count variation. Branches = tapering CAPSULES, leaves = green spheres. Self-contained SDF + integer ray-march with a bounding-sphere early-reject (so hundreds of parts stay fast). No ML, no assets. Different seed -> different tree. license_tier: ORIGINAL

dependencies 3 imports · 9 importers

nx_syscalls.nx nx_itrig.nx nx_vecmath.nx nx_treegen.nx nx_colonize_gate.nx nx_diversity_gate.nx nx_diversity_veg_gate.nx nx_gen_content.nx nx_gen_unified.nx nx_gt_annotations_gate.nx nx_livingworld_gate.nx nx_treegen_gate.nx nx_worldpop_gate.nx

imports: nx_syscalls.nxnx_itrig.nxnx_vecmath.nx

imported by: nx_colonize_gate.nxnx_diversity_gate.nxnx_diversity_veg_gate.nxnx_gen_content.nxnx_gen_unified.nxnx_gt_annotations_gate.nxnx_livingworld_gate.nxnx_treegen_gate.nxnx_worldpop_gate.nx

structs

none

consts

9const TG_MAGIC_6364136223846793005: i64 = 6364136223846793005
10const TG_MAGIC_1442695040888963407: i64 = 1442695040888963407
11const TG_MAGIC_2147483647: i64 = 2147483647
12const TG_MAGIC_1024: i64 = 1024
13const TG_MAGIC_1048576: i64 = 1048576
14const TG_MAGIC_65536: i64 = 65536
15const TG_MAGIC_2654435761: i64 = 2654435761
16const TG_MAGIC_1013904223: i64 = 1013904223
17const TG_MAGIC_7919: i64 = 7919
18const TG_MAGIC_1700: i64 = 1700
19const TG_MAGIC_2900: i64 = 2900
20const TG_MAGIC_1400: i64 = 1400
21const TG_MAGIC_2400: i64 = 2400
22const TG_MAGIC_2100: i64 = 2100
23const TG_MAGIC_3400: i64 = 3400
24const TG_MAGIC_4096: i64 = 4096
25const TG_MAGIC_25736: i64 = 25736
26const TG_MAGIC_2600: i64 = 2600
27const TG_MAGIC_1500: i64 = 1500
28const TG_MAGIC_25735: i64 = 25735
29const TG_MAGIC_4090: i64 = 4090
30const TG_MAGIC_1000000: i64 = 1000000
31const TG_MAGIC_1100: i64 = 1100
32const TG_MAGIC_1103515245: i64 = 1103515245
33const TG_MAGIC_12345: i64 = 12345
35const TG_CAP: i64 = 700 // max parts
36const TG_STR: i64 = 14 // per-part: type,kind, cx,cy,cz, bound, p1(3), r, p2(3)
37const TG_CAPS: i64 = 0
38const TG_SPH: i64 = 1
39const TG_WOOD: i64 = 0
40const TG_LEAF: i64 = 1
41const TG_W: i64 = 448
42const TG_H: i64 = 512
43const TG_FOCAL: i64 = 620
338const TG_COL_POINTS: i64 = 420 // attraction points in the envelope
339const TG_COL_MAXN: i64 = 440 // node cap; with TG_CAP 700 parts it leaves room for the leaf spheres
340const TG_COL_MAXIT: i64 = 64 // growth iterations
341const TG_COL_STEP_DIV: i64 = 8 // D = crown_r / 8
342const TG_COL_DMIN: i64 = 8
343const TG_COL_KILL: i64 = 2 // kill distance in steps
344const TG_COL_INFL: i64 = 5 // influence radius in steps
345const TG_COL_RMIN: i64 = 3 // thinnest branch radius
346const TG_COL_NS: i64 = 12 // node stride: x,y,z,parent,children,leaves,spare,pullx,pully,pullz,pulln,spare
347const TG_COL_PS: i64 = 4 // point stride: x,y,z,alive
348const TG_COL_BASE_Y: i64 = 380 // the tree base sits at -TG_COL_BASE_Y, treegen's own convention

functions

45func tg_isqrt(v: i64) -> i64 { return vm_isqrt(v) }
46func tg_abs(v: i64) -> i64 { if v<0 {return 0-v} return v }
47func tg_min(a: i64, b: i64) -> i64 { if a<b {return a} return b }
48func tg_max(a: i64, b: i64) -> i64 { if a>b {return a} return b }
49func tg_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v }
50func tg_next(st: *i64) -> i64 { var h: i64=st[0]; h=h*TG_MAGIC_6364136223846793005+TG_MAGIC_1442695040888963407; st[0]=h; return (h>>33)&TG_MAGIC_2147483647 }
51func tg_range(st: *i64, lo: i64, hi: i64) -> i64 { return lo + tg_next(st) % (hi-lo+1) }
called by 2: treegen_build_sptg_colonize calls 1: tg_next
53func tg_addcaps(P: *i64, n: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64, r: i64, kind: i64) -> i64
60func tg_addsph(P: *i64, n: i64, cx: i64, cy: i64, cz: i64, r: i64, kind: i64) -> i64
68func tg_tilt(dx: i64, dy: i64, dz: i64, ang: i64, phi: i64, out: *i64) -> i64
99func tg_species_palette(species: i64) -> i64
called by 1: treegen_build_sp
110func treegen_build_sp(P: *i64, seed: i64, species: i64) -> i64
220func treegen_build(P: *i64, seed: i64) -> i64 { return treegen_build_sp(P, seed, 0) }
called by 2: mainmain calls 1: treegen_build_sp
222func tg_part_sdf(P: *i64, k: i64, x: i64, y: i64, z: i64) -> i64
called by 1: tg_sdf calls 2: tg_isqrttg_clamp
237func tg_sdf(P: *i64, np: i64, x: i64, y: i64, z: i64, kindout: *i64) -> i64
called by 1: treegen_render calls 1: tg_part_sdf
259func treegen_render(P: *i64, np: i64, yaw: i64, camz: i64, bgr: i64, bgg: i64, bgb: i64, fb: *i64) -> i64
325func tg_w() -> i64 { return TG_W }
326func tg_h() -> i64 { return TG_H }
349func tg_col_inside(px: i64, py: i64, pz: i64, cy: i64, rx: i64, ry: i64) -> i64
called by 1: tg_colonize
356func tg_col_addnode(N: *i64, nn: i64, x: i64, y: i64, z: i64, parent: i64) -> i64
called by 1: tg_colonize
363func tg_colonize(P: *i64, seed: i64, height: i64, crown_r: i64, trunk_permil: i64, trunk_r: i64, leaf_r: i64) -> i64
504func tg_col_envelope(P: *i64, np: i64, out: *i64) -> i64
called by 1: main calls 1: tg_isqrt