code wiki / (root) / nx_figuregen.nx

nx_figuregen.nx source

↩ module page · 120 lines · 7824 B

1// nx_figuregen.nx -- ★SOVEREIGN INFINIGEN: a full-body HUMAN FIGURE via the SAME layered anatomy (nx_anatstack: 2// skeleton->muscle->skin), a BIPED body plan (head, neck, chest, abdomen, pelvis, 2 arms, 2 legs + muscles). 3// Seeded proportions (height, build) + skin tone -> varied standing people to place in the world. Renders via the 4// shared anatstack ray-marcher. No ML, no assets. license_tier: ORIGINAL 5import "nx_anatstack.nx" 6const FG_MAGIC_6364136223846793005: i64 = 6364136223846793005 7const FG_MAGIC_1442695040888963407: i64 = 1442695040888963407 8const FG_MAGIC_2147483647: i64 = 2147483647 9const FG_MAGIC_2654435761: i64 = 2654435761 10const FG_MAGIC_1013904223: i64 = 1013904223 11const FG_MAGIC_1280: i64 = 1280 12const FG_MAGIC_1480: i64 = 1480 13const FG_MAGIC_65536: i64 = 65536 14 15func fg_next(st: *i64) -> i64 { var h: i64=st[0]; h=h*FG_MAGIC_6364136223846793005+FG_MAGIC_1442695040888963407; st[0]=h; return (h>>33)&FG_MAGIC_2147483647 } 16func fg_range(st: *i64, lo: i64, hi: i64) -> i64 { return lo + fg_next(st) % (hi-lo+1) } 17func fg_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v } 18 19// limb = upper capsule (a->b) + lower capsule (b->c) + end ellipsoid (hand/foot) 20func fg_limb(P: *i64, i: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64, cx: i64, cy: i64, cz: i64, r: i64, er: i64) -> i64 { 21 var n: i64 = i 22 n = as_caps(P, n, ax, ay, az, bx, by, bz, r, AS_BONE) 23 n = as_caps(P, n, bx, by, bz, cx, cy, cz, r*85/100, AS_BONE) 24 n = as_ellip(P, n, cx, cy, cz, er, er*7/10, er*13/10, AS_BONE) 25 return n 26} 27 28const FG_WORLDH: i64 = 1400 // nominal figure height (for scene-scale) 29 30func figuregen_build(P: *i64, seed: i64, skinout: *i64) -> i64 { 31 let st: *i64 = sys_mmap(16) as *i64 32 st[0] = seed*FG_MAGIC_2654435761 + FG_MAGIC_1013904223; fg_next(st); fg_next(st) 33 let H: i64 = fg_range(st, FG_MAGIC_1280, FG_MAGIC_1480) 34 let build: i64 = fg_range(st, 88, 118) 35 // seeded GARMENT + HAIR colour families (Phase-1: dressed, featured people, not clay golems) 36 let gfam: i64 = fg_range(st, 0, 5) 37 var gcr: i64 = 86; var gcg: i64 = 110; var gcb: i64 = 150 // denim 38 if gfam == 1 { gcr=150; gcg=88; gcb=78 } // rust 39 if gfam == 2 { gcr=98; gcg=124; gcb=88 } // sage 40 if gfam == 3 { gcr=136; gcg=124; gcb=100 } // sand 41 if gfam == 4 { gcr=96; gcg=88; gcb=128 } // plum 42 if gfam == 5 { gcr=124; gcg=102; gcb=78 } // tan 43 let shirt: i64 = gcr + gcg*256 + gcb*FG_MAGIC_65536 + AS_MATTE // cloth = matte 44 let pants: i64 = gcr*62/100 + (gcg*62/100)*256 + (gcb*62/100)*FG_MAGIC_65536 + AS_MATTE 45 let shoes: i64 = 48 + 40*256 + 36*FG_MAGIC_65536 + AS_MATTE 46 let hfam: i64 = fg_range(st, 0, 4) 47 var hcr: i64 = 30; var hcg: i64 = 24; var hcb: i64 = 20 // near-black 48 if hfam == 1 { hcr=74; hcg=50; hcb=30 } // brown 49 if hfam == 2 { hcr=164; hcg=132; hcb=74 } // blonde 50 if hfam == 3 { hcr=118; hcg=56; hcb=32 } // auburn 51 if hfam == 4 { hcr=52; hcg=44; hcb=40 } // dark grey 52 let hair: i64 = hcr + hcg*256 + hcb*FG_MAGIC_65536 + AS_HAIRM // hair sheen 53 let footY: i64 = 0 - H/2 54 let hipY: i64 = footY + H*47/100 55 let shY: i64 = footY + H*80/100 56 let neckY: i64= footY + H*85/100 57 let headY: i64= footY + H*93/100 58 let sw: i64 = H*10/100 * build/100 // shoulder half-width 59 let hw2: i64 = H*6/100 // hip half-width 60 let r0: i64 = H*4/100 * build/100 // limb radius 61 let hrx: i64 = H*58/1000 // head radii 62 let hry: i64 = H*68/1000 63 let hrz: i64 = H*64/1000 64 var i: i64 = 0 65 // --- SKELETON --- 66 i = as_ellip(P, i, 0, headY, 0, hrx, hry, hrz, AS_BONE) // head 67 i = as_caps(P, i, 0, neckY, 0, 0, headY-H*5/100, 0, H*32/1000, AS_BONE) // neck 68 i = as_ellip(P, i, 0, shY-H*7/100, 0, sw, H*11/100, H*6/100*build/100, AS_BONE) // chest 69 i = as_color_last(P, i, shirt) 70 i = as_ellip(P, i, 0, hipY+H*9/100, 0, hw2*13/10*build/100, H*8/100, H*5/100, AS_BONE) // abdomen 71 i = as_color_last(P, i, shirt) 72 i = as_ellip(P, i, 0, hipY, 0, hw2*12/10, H*5/100, H*5/100, AS_BONE) // pelvis 73 i = as_color_last(P, i, pants) 74 // arms (hang at sides, slight bend forward; upper arm = sleeve) 75 i = fg_limb(P, i, 0-sw, shY, 0, 0-sw-H*1/100, shY-H*17/100, H*2/100, 0-sw, shY-H*33/100, H*1/100, r0*8/10, r0*7/10) 76 P[i - AS_STRIDE*3 + 11] = shirt 77 i = fg_limb(P, i, sw, shY, 0, sw+H*1/100, shY-H*17/100, H*2/100, sw, shY-H*33/100, H*1/100, r0*8/10, r0*7/10) 78 P[i - AS_STRIDE*3 + 11] = shirt 79 // legs (trousers + shoes) 80 i = fg_limb(P, i, 0-hw2, hipY, 0, 0-hw2, (hipY+footY)/2, H*2/100, 0-hw2, footY+H*3/100, 0, r0, r0) 81 P[i - AS_STRIDE*3 + 11] = pants 82 P[i - AS_STRIDE*2 + 11] = pants 83 i = as_color_last(P, i, shoes) 84 i = fg_limb(P, i, hw2, hipY, 0, hw2, (hipY+footY)/2, H*2/100, hw2, footY+H*3/100, 0, r0, r0) 85 P[i - AS_STRIDE*3 + 11] = pants 86 P[i - AS_STRIDE*2 + 11] = pants 87 i = as_color_last(P, i, shoes) 88 // --- MUSCLE --- 89 i = as_ellip(P, i, 0-sw, shY-H*2/100, H*1/100, r0*9/10, H*7/100, r0*9/10, AS_MUSCLE) // L deltoid (sleeve) 90 i = as_color_last(P, i, shirt) 91 i = as_ellip(P, i, sw, shY-H*2/100, H*1/100, r0*9/10, H*7/100, r0*9/10, AS_MUSCLE) // R deltoid (sleeve) 92 i = as_color_last(P, i, shirt) 93 i = as_ellip(P, i, 0, shY-H*8/100, H*2/100, sw*9/10, H*8/100, H*5/100, AS_MUSCLE) // pecs (under shirt) 94 i = as_color_last(P, i, shirt) 95 i = as_ellip(P, i, 0-hw2, hipY-H*10/100, H*1/100, r0*12/10, H*11/100, r0*12/10, AS_MUSCLE) // L thigh 96 i = as_color_last(P, i, pants) 97 i = as_ellip(P, i, hw2, hipY-H*10/100, H*1/100, r0*12/10, H*11/100, r0*12/10, AS_MUSCLE) // R thigh 98 i = as_color_last(P, i, pants) 99 // --- FACE + HAIR (Phase-1 features: crisp, low-inflate; face toward -z = the camera at yaw 0) --- 100 let ez: i64 = 0 - hrz - 24 // feature depth (proud of skin) 101 i = as_ellip(P, i, 0, headY + hry*32/100, hrz*20/100, hrx*106/100, hry*80/100, hrz*98/100, AS_MUSCLE) 102 i = as_color_last(P, i, hair) // hair volume (smooth, inflates) 103 i = as_ellip(P, i, 0-hrx*38/100, headY + hry*8/100, ez, H*13/1000, H*11/1000, H*9/1000, AS_MUSCLE) 104 i = as_feature_last(P, i, 30 + 26*256 + 24*FG_MAGIC_65536 + AS_GLOSS) // L eye (glint) 105 i = as_ellip(P, i, hrx*38/100, headY + hry*8/100, ez, H*13/1000, H*11/1000, H*9/1000, AS_MUSCLE) 106 i = as_feature_last(P, i, 30 + 26*256 + 24*FG_MAGIC_65536 + AS_GLOSS) // R eye (glint) 107 i = as_ellip(P, i, 0, headY - hry*10/100, ez - 4, H*7/1000, H*11/1000, H*9/1000, AS_MUSCLE) 108 i = as_feature_last(P, i, 0) // nose (skin, crisp) 109 i = as_ellip(P, i, 0, headY - hry*40/100, ez + 8, H*15/1000, H*5/1000, H*7/1000, AS_MUSCLE) 110 i = as_feature_last(P, i, 172 + 98*256 + 88*FG_MAGIC_65536 + AS_GLOSS) // lips (subtle gloss) 111 // --- skin tone (persongen tone families) --- 112 let fam: i64 = fg_range(st, 0, 4) 113 var sr: i64=232; var sg: i64=196; var sb: i64=166 114 if fam==0 { sr=246; sg=226; sb=208 } 115 if fam==2 { sr=206; sg=162; sb=126 } 116 if fam==3 { sr=168; sg=122; sb=90 } 117 if fam==4 { sr=124; sg=86; sb=62 } 118 skinout[0]=fg_clamp(sr+fg_range(st,0-10,10),40,255); skinout[1]=fg_clamp(sg+fg_range(st,0-10,10),30,255); skinout[2]=fg_clamp(sb+fg_range(st,0-10,10),25,255) 119 return i / AS_STRIDE 120}