nx_treegen.nx
buildroot/runtime/nx_treegen.nx
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
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
| 9 | const TG_MAGIC_6364136223846793005: i64 = 6364136223846793005 |
| 10 | const TG_MAGIC_1442695040888963407: i64 = 1442695040888963407 |
| 11 | const TG_MAGIC_2147483647: i64 = 2147483647 |
| 12 | const TG_MAGIC_1024: i64 = 1024 |
| 13 | const TG_MAGIC_1048576: i64 = 1048576 |
| 14 | const TG_MAGIC_65536: i64 = 65536 |
| 15 | const TG_MAGIC_2654435761: i64 = 2654435761 |
| 16 | const TG_MAGIC_1013904223: i64 = 1013904223 |
| 17 | const TG_MAGIC_7919: i64 = 7919 |
| 18 | const TG_MAGIC_1700: i64 = 1700 |
| 19 | const TG_MAGIC_2900: i64 = 2900 |
| 20 | const TG_MAGIC_1400: i64 = 1400 |
| 21 | const TG_MAGIC_2400: i64 = 2400 |
| 22 | const TG_MAGIC_2100: i64 = 2100 |
| 23 | const TG_MAGIC_3400: i64 = 3400 |
| 24 | const TG_MAGIC_4096: i64 = 4096 |
| 25 | const TG_MAGIC_25736: i64 = 25736 |
| 26 | const TG_MAGIC_2600: i64 = 2600 |
| 27 | const TG_MAGIC_1500: i64 = 1500 |
| 28 | const TG_MAGIC_25735: i64 = 25735 |
| 29 | const TG_MAGIC_4090: i64 = 4090 |
| 30 | const TG_MAGIC_1000000: i64 = 1000000 |
| 31 | const TG_MAGIC_1100: i64 = 1100 |
| 32 | const TG_MAGIC_1103515245: i64 = 1103515245 |
| 33 | const TG_MAGIC_12345: i64 = 12345 |
| 35 | const TG_CAP: i64 = 700 // max parts |
| 36 | const TG_STR: i64 = 14 // per-part: type,kind, cx,cy,cz, bound, p1(3), r, p2(3) |
| 37 | const TG_CAPS: i64 = 0 |
| 38 | const TG_SPH: i64 = 1 |
| 39 | const TG_WOOD: i64 = 0 |
| 40 | const TG_LEAF: i64 = 1 |
| 41 | const TG_W: i64 = 448 |
| 42 | const TG_H: i64 = 512 |
| 43 | const TG_FOCAL: i64 = 620 |
| 338 | const TG_COL_POINTS: i64 = 420 // attraction points in the envelope |
| 339 | const TG_COL_MAXN: i64 = 440 // node cap; with TG_CAP 700 parts it leaves room for the leaf spheres |
| 340 | const TG_COL_MAXIT: i64 = 64 // growth iterations |
| 341 | const TG_COL_STEP_DIV: i64 = 8 // D = crown_r / 8 |
| 342 | const TG_COL_DMIN: i64 = 8 |
| 343 | const TG_COL_KILL: i64 = 2 // kill distance in steps |
| 344 | const TG_COL_INFL: i64 = 5 // influence radius in steps |
| 345 | const TG_COL_RMIN: i64 = 3 // thinnest branch radius |
| 346 | const TG_COL_NS: i64 = 12 // node stride: x,y,z,parent,children,leaves,spare,pullx,pully,pullz,pulln,spare |
| 347 | const TG_COL_PS: i64 = 4 // point stride: x,y,z,alive |
| 348 | const TG_COL_BASE_Y: i64 = 380 // the tree base sits at -TG_COL_BASE_Y, treegen's own convention |
functions
| 45 | func tg_isqrt(v: i64) -> i64 { return vm_isqrt(v) } |
| 46 | func tg_abs(v: i64) -> i64 { if v<0 {return 0-v} return v } |
| 47 | func tg_min(a: i64, b: i64) -> i64 { if a<b {return a} return b } |
| 48 | func tg_max(a: i64, b: i64) -> i64 { if a>b {return a} return b } |
| 49 | func tg_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v } |
| 50 | func 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 } |
| 51 | func tg_range(st: *i64, lo: i64, hi: i64) -> i64 { return lo + tg_next(st) % (hi-lo+1) } |
| 53 | func tg_addcaps(P: *i64, n: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64, r: i64, kind: i64) -> i64 |
| 60 | func tg_addsph(P: *i64, n: i64, cx: i64, cy: i64, cz: i64, r: i64, kind: i64) -> i64 |
| 68 | func tg_tilt(dx: i64, dy: i64, dz: i64, ang: i64, phi: i64, out: *i64) -> i64 |
| 99 | func tg_species_palette(species: i64) -> i64 called by 1: treegen_build_sp |
| 110 | func treegen_build_sp(P: *i64, seed: i64, species: i64) -> i64 called by 6: mainmainnx_gennx_genmaintreegen_build calls 9: tg_species_palettesys_mmaptg_nexttg_rangetg_addcapsit_cos4096+3 |
| 220 | func treegen_build(P: *i64, seed: i64) -> i64 { return treegen_build_sp(P, seed, 0) } |
| 222 | func tg_part_sdf(P: *i64, k: i64, x: i64, y: i64, z: i64) -> i64 |
| 237 | func tg_sdf(P: *i64, np: i64, x: i64, y: i64, z: i64, kindout: *i64) -> i64 |
| 259 | func treegen_render(P: *i64, np: i64, yaw: i64, camz: i64, bgr: i64, bgg: i64, bgb: i64, fb: *i64) -> i64 |
| 325 | func tg_w() -> i64 { return TG_W } |
| 326 | func tg_h() -> i64 { return TG_H } |
| 349 | func tg_col_inside(px: i64, py: i64, pz: i64, cy: i64, rx: i64, ry: i64) -> i64 called by 1: tg_colonize |
| 356 | func tg_col_addnode(N: *i64, nn: i64, x: i64, y: i64, z: i64, parent: i64) -> i64 called by 1: tg_colonize |
| 363 | func tg_colonize(P: *i64, seed: i64, height: i64, crown_r: i64, trunk_permil: i64, trunk_r: i64, leaf_r: i64) -> i64 |
| 504 | func tg_col_envelope(P: *i64, np: i64, out: *i64) -> i64 |