code wiki / _hdl_build / nx_body_proc.nx
nx_body_proc.nx source
↩ module page · 840 lines · 64935 B
1// nx_body_proc.nx -- ★SOVEREIGN PROCEDURAL BODY-CANON GENERATOR (Infinigen-style). Infinigen is the CAPABILITY
2// benchmark -- infinite variety of bodies GENERATED procedurally from parameters + a seed, ZERO hand-crafted
3// or scanned assets. This is the sovereign version: it does not store a body, it stores the RULES that make
4// one. It emits a canon.dat (the P/R/F rows nx_body_gen reads) computed from anthropometric FUNCTIONS of a
5// few high-level knobs, with seeded procedural noise so no two seeds are identical.
6//
7// nx_body_proc <out.dat> <sex 0-1000> <build 0-1000> <musc 0-1000> <noise 0-1000> <seed> [stylize 0-1000]
8// sex 0=male anatomy .. 1000=female (shoulders<->hips, waist, bust)
9// build 0=lean .. 1000=heavy (girth added at waist/limbs)
10// musc 0=soft .. 1000=muscular (limb girth + muscle-relief amplitude)
11// noise individual variation amplitude, per-mille of each radius (0=canonical template)
12// seed any integer -> a specific individual
13// stylize 0=realistic .. 1000=anime/stylized (bigger head, longer legs, slimmer limps, bigger eyes)
14// license_tier: ORIGINAL expect_exit: 0
15import "nx_syscalls.nx"
16const K_MAGIC_1750: i64 = 1750
17const K_MAGIC_1000000: i64 = 1000000
18const K_MAGIC_2654435761: i64 = 2654435761
19const K_MAGIC_1013904223: i64 = 1013904223
20const K_MAGIC_65536: i64 = 65536
21// ★SKELETAL LANDMARKS THE SURFACE ANCHORS ON -- the same per-mille heights nx_skelgen places its joints at,
22// so the canon and the skeleton cannot drift apart about where a girdle is. Changing one without the other
23// now fails nx_skelgen T18/T19 rather than quietly producing a body whose bones miss its skin.
24// BP_ACROMION is LIVE: the acromion ring is anchored on it and nx_skelgen T18/T19 pin the skeleton's
25// shoulder to the same landmark, so the two artifacts can no longer drift apart about where a shoulder is.
26// BP_TROCH is the true hip landmark and is NOT used by the surface -- see the pelvis ring below for the
27// measured reason. It stays here because the number is right and the model is what cannot hold it yet.
28const BP_TROCH: i64 = 530
29const BP_ACROMION: i64 = 818
30
31// integer PRNG (xorshift-ish LCG). Seeded; deterministic per seed -> reproducible "individuals".
32func pr_step(st: *i64) -> i64 { var x: i64 = st[0]; x = x ^ (x << 13); x = x ^ ((x >> 7) & 0x1ffffffffffff); x = x ^ (x << 17); st[0] = x & 0x7fffffffffffffff; return st[0] }
33// signed perturbation in [-amp, amp]
34func pr_pm(st: *i64, amp: i64) -> i64 { if amp <= 0 { return 0 } let r: i64 = pr_step(st) % (2*amp + 1); return r - amp }
35
36func pw(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n+1 } sys_write(fd, s, n); return 0 }
37// write a signed integer + trailing char c into buf at *pos
38func wint(b: *u8, pos: *i64, v: i64, c: i64) -> i64 {
39 var x: i64 = v
40 if x < 0 { b[pos[0]] = 45 as u8; pos[0] = pos[0]+1; x = 0-x }
41 let tmp: *u8 = sys_mmap(24); var i: i64 = 23
42 if x == 0 { tmp[i] = 48 as u8; i = i-1 }
43 while x > 0 { tmp[i] = (48 + x%10) as u8; x = x/10; i = i-1 }
44 var k: i64 = i+1
45 while k < 24 { b[pos[0]] = tmp[k]; pos[0] = pos[0]+1; k = k+1 }
46 b[pos[0]] = c as u8; pos[0] = pos[0]+1
47 return 0
48}
49func satoi(s: *u8) -> i64 { var i: i64=0; var n: i64=0; var sg: i64=1; if s[0]==(45 as u8){sg=0-1;i=1}
50 while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c>=48 { if c<=57 { n=n*10+(c-48) } } i=i+1 } return n*sg }
51
52// emit one R row: y xoff zoff ra rb, carrying this individual's PER-PART variation (st[1] width, st[2] depth).
53// ★INDIVIDUAL VARIATION IS A PROPERTY OF A PART, NOT OF A SLICE. Drawing an independent perturbation per
54// control ring is not anatomy, it is lumpiness: a person's head is a few percent wider or deeper AS A WHOLE.
55// An independent per-ring draw is invisible on the torso (11 rings over 480 permil of stature) and destroys
56// the head (10 rings over 150), which is exactly why the head rendered as a flat-brim MUSHROOM -- rb ran
57// 34,51,76,67,55,66,42 and ra peaked at the CROWN. Same size-dependent class as the GX-24 banding bug: a
58// per-slice error scales inversely with part size, so it hides until a small part exposes it.
59func emitR(b: *u8, pos: *i64, st: *i64, noise: i64, y: i64, xoff: i64, zoff: i64, ra: i64, rb: i64) -> i64 {
60 var a: i64 = ra + ra*st[1]/1000
61 var d: i64 = rb + rb*st[2]/1000
62 if a < 2 { a = 2 } if d < 2 { d = 2 }
63 b[pos[0]]=82 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2 // "R "
64 wint(b,pos,y,32); wint(b,pos,xoff,32); wint(b,pos,zoff,32); wint(b,pos,a,32); wint(b,pos,d,10)
65 return 0
66}
67func emitPm(b: *u8, pos: *i64, st: *i64, noise: i64, mir: i64, rot: i64, ox: i64, oy: i64, oz: i64, mat: i64) -> i64 {
68 // one draw per PART: this individual's width and depth deviation, held for every ring of the part
69 // CORRELATED, AND SMALLER. Per-part noise fixed the lumpiness of a per-slice draw but introduced a
70 // worse defect: ONE draw now shifts an ENTIRE part, so at noise=300 a whole torso could come out 30%
71 // wider while an INDEPENDENT draw made it 30% shallower -- a wide flat slab, the bell-shaped body that
72 // six numeric judges scored as normal and one contact sheet caught. Two corrections, both principled:
73 // 1. a part-wide shift needs a fraction of a per-slice amplitude, not the same one (noise/3);
74 // 2. width and depth must be CORRELATED -- real people are bigger or smaller overall, not wider and
75 // flatter at once. This is the same correlated-manifold rule the village sampler needs, appearing
76 // here at the scale of a single part.
77 let sz: i64 = pr_pm(st, noise/3)
78 st[1] = sz
79 st[2] = sz*3/4 + pr_pm(st, noise/6)
80 b[pos[0]]=80 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2 // "P "
81 wint(b,pos,mir,32); wint(b,pos,rot,32); wint(b,pos,ox,32); wint(b,pos,oy,32); wint(b,pos,oz,32); wint(b,pos,mat,10)
82 return 0
83}
84// ★emitPm + the 7th field, ROTATION ABOUT Z (F1084). Kept as a SEPARATE verb rather than widening emitPm:
85// NishiLang has no call-arity check on this path, so widening a signature silently mis-binds every existing
86// call site. Add a verb, never widen -- the same rule that protected sg_project_clip in the graphics lane.
87func emitPmZ(b: *u8, pos: *i64, st: *i64, noise: i64, mir: i64, rot: i64, ox: i64, oy: i64, oz: i64, mat: i64, rotz: i64) -> i64 {
88 let sz: i64 = pr_pm(st, noise/3)
89 st[1] = sz
90 st[2] = sz*3/4 + pr_pm(st, noise/6)
91 b[pos[0]]=80 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2
92 wint(b,pos,mir,32); wint(b,pos,rot,32); wint(b,pos,ox,32); wint(b,pos,oy,32); wint(b,pos,oz,32); wint(b,pos,mat,32); wint(b,pos,rotz,10)
93 return 0
94}
95func emitP(b: *u8, pos: *i64, st: *i64, noise: i64, mir: i64, rot: i64, ox: i64, oy: i64, oz: i64) -> i64 {
96 return emitPm(b,pos,st,noise,mir,rot,ox,oy,oz,0) // material 0 = flesh
97}
98// ★PROCEDURAL DIGIT (finger/toe): a thin tapered 4-ring tube from base to tip, its own placement part.
99// Emitted by a RULE (the hand/foot loop places N of these), not hand-modelled one by one.
100// ★PLACED digit: the same 4-ring tapered tube, but carrying its part's placement so a digit can run in a
101// direction other than DOWN. A finger hangs off the palm (rot 0); a TOE runs FORWARD off the toe line, which
102// is the foot's own rotated frame -- the reason the feet stayed blunt flippers while the hands got fingers
103// was simply that the digit rule could not be placed anywhere but straight down.
104func emitDigitP(b: *u8, pos: *i64, st: *i64, fx: i64, fz: i64, baseY: i64, tipY: i64, rad: i64,
105 rot: i64, ox: i64, oy: i64, oz: i64) -> i64 {
106 let span: i64 = baseY - tipY
107 emitP(b,pos,st,0, 1, rot, ox, oy, oz)
108 emitR(b,pos,st,0, baseY, fx, fz, rad, rad)
109 emitR(b,pos,st,0, baseY-span/3, fx, fz+1, rad, rad-1)
110 emitR(b,pos,st,0, baseY-span*2/3, fx, fz+2, rad-1, rad-2)
111 emitR(b,pos,st,0, tipY, fx, fz+2, rad-2, rad-2)
112 return 0
113}
114// ★LIMB AS A CURVE PLUS A RADIUS PROFILE -- Infinigen lofts a surface along a skeleton curve with the
115// girth read from genes, so a limb is generated, not written out ring by ring. Stations are produced by a
116// loop; each station's position comes from the limb's path and its radius from a profile evaluated at the
117// normalised station index, peaked at the muscle belly (deltoid on an arm, calf on a shank). The typed
118// table it replaces carried the same anatomy as literals -- same shape, no rule.
119func emitLimbTube(b: *u8, pos: *i64, st: *i64, noise: i64, n: i64, y0: i64, y1: i64, x0: i64, x1: i64,
120 z0: i64, z1: i64, rProx: i64, rPeak: i64, peakT: i64, rDist: i64, depth: i64) -> i64 {
121 var i: i64 = 0
122 while i < n {
123 var t: i64 = 0
124 if n > 1 { t = i*1000/(n-1) }
125 let y: i64 = y0 + (y1-y0)*t/1000
126 let x: i64 = x0 + (x1-x0)*t/1000
127 let z: i64 = z0 + (z1-z0)*t/1000
128 var r: i64 = rDist
129 var pt: i64 = peakT
130 if pt < 1 { pt = 1 }
131 if pt > 999 { pt = 999 }
132 if t <= pt { r = rProx + (rPeak-rProx)*t/pt } else {
133 let u: i64 = (t-pt)*1000/(1000-pt)
134 r = rPeak + (rDist-rPeak)*u/1000
135 }
136 emitR(b,pos,st,noise, y, x, z, r, r*depth/1000)
137 i = i+1
138 }
139 return 0
140}
141// ★RAY SET -- the Infinigen construction, not a typed list. Their creatures instantiate a PART TEMPLATE
142// from a parameter vector and ATTACH it relative to its parent (a position along the parent, not an absolute
143// coordinate), with per-instance values read off a smooth profile rather than written out one by one. A hand
144// and a foot are then the SAME rule with different parameters: n rays spread across the parent's distal
145// edge, each ray's length and radius evaluated at its normalised index from a unimodal profile peaked at the
146// longest ray (middle finger on a hand, hallux on a foot). Changing 4 fingers to 5 toes is a parameter.
147// cx/halfw : the parent's distal edge, so the rays inherit the palm or toe-line width (relative attachment)
148// peak : normalised index of the longest ray | dirn: +1 rays run down (hand), -1 forward (foot frame)
149// plane : the palmar/plantar plane (z in the part frame). ★Each digit sits at fz = plane - its radius,
150// so every ray's +z face lands EXACTLY on the plane regardless of its thickness -- a foot's
151// sole and a palm's face are FLAT by construction. nx_footcheck measured the old constant-fz
152// form leaving toes 3 units below the sole: five different radii on one z line cannot share a
153// plane, so the figure stood on its toe tips.
154func emitRaySet(b: *u8, pos: *i64, st: *i64, cx: i64, halfw: i64, baseY: i64, maxLen: i64, radB: i64,
155 n: i64, peak: i64, dirn: i64, plane: i64, rot: i64, ox: i64, oy: i64, oz: i64) -> i64 {
156 var i: i64 = 0
157 while i < n {
158 var t: i64 = 500
159 if n > 1 { t = i*1000/(n-1) }
160 let x: i64 = cx + (t-500)*2*halfw/1000
161 var d: i64 = t - peak
162 if d < 0 { d = 0-d }
163 var lf: i64 = 1000 - d*d*700/K_MAGIC_1000000
164 if lf < 200 { lf = 200 }
165 let ln: i64 = maxLen*lf/1000
166 var rd: i64 = radB*(1000 - d*350/1000)/1000
167 if rd < 3 { rd = 3 }
168 emitDigitP(b,pos,st, x, plane - rd, baseY, baseY - dirn*ln, rd, rot, ox, oy, oz)
169 i = i+1
170 }
171 return 0
172}
173func emitDigit(b: *u8, pos: *i64, st: *i64, fx: i64, fz: i64, baseY: i64, tipY: i64, rad: i64) -> i64 {
174 let span: i64 = baseY - tipY
175 emitP(b,pos,st,0, 1, 0, 0, 0, 0)
176 emitR(b,pos,st,0, baseY, fx, fz, rad, rad)
177 emitR(b,pos,st,0, baseY-span/3, fx, fz+1, rad, rad-1)
178 emitR(b,pos,st,0, baseY-span*2/3, fx, fz+2, rad-1, rad-2)
179 emitR(b,pos,st,0, tipY, fx, fz+2, rad-2, rad-2)
180 return 0
181}
182// ★★★PROCEDURAL NOSE -- a real PROTRUDING PART, not a radius bump.
183// MEASURED WHY (2026-07-25): at head scale our face benched detail 79 vs the cadaver oracle while the
184// silhouette held 828 -- head-SHAPED, surface-FEATURELESS -- and the eyeball showed NO NOSE AT ALL. A nose
185// had been declared for rungs as an F relief row (an angular RADIUS modulation of the head ellipse) at an
186// amplitude of roughly 8mm, which GX-31 measured as worth ~1 permil and GX-48 measured as BELOW the detail
187// judge's window. The lesson generalises: a protruding anatomical structure cannot be expressed as a radius
188// modulation of the surface it protrudes from -- it needs its own GEOMETRY. So the nose becomes a part, the
189// same machinery the eye already uses, generated from anthropometric ratios rather than typed coordinates.
190// Proportions (per-mille of stature, from the standing canon): nasion ~938, pronasale ~912, subnasale ~904;
191// alar width ~19; projection ~13 (a real nose projects ~23mm on a 1750mm body). Sex dimorphism: the male
192// nose is longer and more projecting; stylize (anime) shortens and narrows it.
193func emitNose(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, faceZ: i64, mat: i64) -> i64 {
194 // dimorphic scalars, each a RULE over the knobs -- no typed geometry
195 let proj: i64 = 15 - 3*sexf/1000 - 4*sty/1000 // forward projection at the tip
196 let alar: i64 = 10 - 2*sexf/1000 - 3*sty/1000 // half-width at the wings
197 // ★CANON Y FROM knowledge/face_tissue.dat (F1128). The nasion was at 938 and the table puts it at 948 --
198 // and once the brow moved up to the glabella at 958, a nose root 20 below it left the bridge starting in
199 // mid-forehead. Subnasale corrected 904 -> 908. The tip was already right at 912, which is a useful
200 // negative check on the table: it agrees with what measurement had already driven us to.
201 // ⚠⚠REVERTED TO THE MEASURED VALUES, and this is the finding of the rung: THE PORTED CANON TRANSFERS FOR
202 // SOME LANDMARKS AND NOT OTHERS. The brow and eye corrections from the same table moved the binding lane
203 // 92 -> 138. Applying its nose values (nasion 938->948, subnasale 904->908) on top COST 56 of that back.
204 // Cause: the table's y-values come from the SDF lane's OWN head frame, and our head part is not the same
205 // shape -- where the two geometries agree the canon transfers, where they differ it does not. ★A CANON IS
206 // MEASURED RELATIVE TO A PARTICULAR HEAD; porting it is a HYPOTHESIS PER LANDMARK, not a global rewrite.
207 // Each value has to be A/B'd against the mesh, which is exactly what the lane judge is for.
208 let rootY: i64 = 938 // nasion (ours, measured-better than the ported 948)
209 let tipY: i64 = 912 + 3*sty/1000 // pronasale -- table and measurement AGREE here
210 let baseY: i64 = 904 + 2*sty/1000 // subnasale (ours, measured-better than 908)
211 emitPm(b,pos,st,0, 0, 0, 0, 0, faceZ, mat) // midline part, no mirror
212 // rings ASCEND: base (widest, wings) -> tip (most forward) -> dorsum -> root (sinks into the brow)
213 emitR(b,pos,st,0, baseY, 0, proj*70/100, alar, alar*60/100)
214 emitR(b,pos,st,0, tipY, 0, proj, alar*80/100, alar*80/100)
215 // ⚠ITERATION 1 (eyeball-driven, the number alone would not have caught it): the first cut made the
216 // dorsum rings narrow (55%/40% of alar) and left the root at zero projection -- so the BRIDGE sat
217 // buried inside the head surface and the nose read as a floating BUTTON rather than a nose. A real
218 // dorsum is a continuous RIDGE from the brow to the tip, so it must stay wide enough to emerge from
219 // the face and keep projecting all the way up to the nasion.
220 emitR(b,pos,st,0, (tipY+rootY)/2, 0, proj*72/100, alar*72/100, alar*72/100)
221 emitR(b,pos,st,0, rootY, 0, proj*38/100, alar*60/100, alar*60/100)
222 return 0
223}
224// ★★★THE REST OF THE FACE AS RULED PARTS (F1083). The nose (above) proved the pattern and the measurement:
225// a protruding structure cannot be an F relief row (a radius modulation of the head ellipse) -- it needs its
226// own geometry. Lips, chin, brow ridge and ears were all still PAINTED (per-triangle colour bands on a
227// smooth ovoid) or absent entirely. Each becomes a part below, generated from anthropometric ratios and the
228// sex/stylize knobs, never typed coordinates. All four are placed by the SAME machinery as the nose and eye.
229
230// LIPS: a protruding band around the mouth line. The groove BETWEEN the lips is what reads as a mouth, so
231// the mid ring pulls back while the two lip rings project -- that concavity is the whole feature.
232func emitLips(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, faceZ: i64, mat: i64) -> i64 {
233 let proj: i64 = 8 + 2*sexf/1000 // female lips project slightly more
234 let halfw: i64 = 15 - 2*sty/1000
235 emitPm(b,pos,st,0, 0, 0, 0, 0, faceZ, mat)
236 emitR(b,pos,st,0, 878, 0, proj*30/100, halfw*55/100, halfw*30/100) // below the lower lip
237 emitR(b,pos,st,0, 884, 0, proj*88/100, halfw*92/100, halfw*42/100) // lower lip
238 emitR(b,pos,st,0, 889, 0, proj*52/100, halfw, halfw*34/100) // the mouth groove: PULLED BACK
239 emitR(b,pos,st,0, 894, 0, proj, halfw*95/100, halfw*44/100) // upper lip
240 emitR(b,pos,st,0, 899, 0, proj*35/100, halfw*60/100, halfw*30/100) // philtrum, fading into the face
241 return 0
242}
243// CHIN: the pogonion, a protruding mass at the base of the face. Male chins are squarer and project more.
244func emitChin(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, faceZ: i64, mat: i64) -> i64 {
245 let proj: i64 = 13 - 4*sexf/1000 - 3*sty/1000
246 let halfw: i64 = 16 - 3*sexf/1000 - 3*sty/1000
247 emitPm(b,pos,st,0, 0, 0, 0, 0, faceZ, mat)
248 emitR(b,pos,st,0, 862, 0, proj*25/100, halfw*45/100, halfw*30/100) // under the jaw
249 emitR(b,pos,st,0, 869, 0, proj, halfw, halfw*52/100) // pogonion (most forward)
250 emitR(b,pos,st,0, 876, 0, proj*70/100, halfw*88/100, halfw*44/100)
251 emitR(b,pos,st,0, 882, 0, proj*30/100, halfw*62/100, halfw*32/100) // mentolabial sulcus
252 return 0
253}
254// ★★★THE CHIN, and WHY it is the fix for a complaint about the MOUTH. The shipped lips read as sitting too
255// low on the face, so the obvious move was to raise them -- but measuring first said otherwise: our mouth
256// centre sits ~24pct of the way up the head from the chin, and a real mouth sits ~25pct, so the HEIGHT WAS
257// ALREADY RIGHT. What was missing was the mass BELOW it. A mouth with no chin under it reads as falling off
258// the bottom of the face no matter where you put it. ★LAW: when a feature looks mispositioned, check whether
259// its NEIGHBOUR is missing before you move it -- proportion is read from what surrounds a feature, not from
260// the feature alone.
261// Built by the same rule as the brow and the lip: a horizontal Z-rotated roll, attached relative to the
262// parent skull, corners tucking with the face curve. Male chins are squarer and project more.
263func emitChinZ(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, headRb: i64, mat: i64) -> i64 {
264 // ⚠ITERATION: the first cut sat at 868 with mass 13 and read as a POINTED witch-chin jutting BELOW the
265 // jaw silhouette -- because the head's radius falls away fast under the jaw ring, so the same forward
266 // mass that merges at 876 protrudes past the outline at 868. A chin is a rounded eminence ON the jaw,
267 // not a spur hanging off it. Raised onto the jaw ring and its mass reduced so it stays inside the
268 // silhouette; the pogonion still leads, it just no longer leaves the face.
269 // ⚠⚠TWO iterations, and the second one MEASURED ITS OWN MISTAKE. Raising the chin onto the jaw ring at
270 // 876 cured the jut but collapsed every lane back to the pre-lip baseline -- because the chin's top edge
271 // then reached 885 and SWALLOWED the lower lip sitting at 881. The judge caught a collision the eye had
272 // not yet noticed. ★LAW: a feature part occupies a BAND, not a point; when adding one beside another,
273 // check that their extents do not overlap, and let the judge tell you when they do.
274 // So the height goes back to where it did not collide, and only the MASS is reduced to stop the jut.
275 let mass: i64 = 10 - 3*sexf/1000 - 2*sty/1000 // how far the chin comes forward
276 let half: i64 = 17 - 3*sexf/1000 - 2*sty/1000 // a male chin is squarer, a female one narrower
277 let chinY: i64 = 866
278 let faceZ: i64 = headRb - mass*40/100
279 let sweep: i64 = mass*80/100
280 emitPmZ(b,pos,st,0, 0, 0, 0, chinY, faceZ, mat, 90)
281 emitR(b,pos,st,0, 0-half, 0, 0-sweep, mass*25/100, mass*35/100)
282 emitR(b,pos,st,0, 0-half*55/100, 0, 0-sweep*30/100, mass*80/100, mass*78/100)
283 emitR(b,pos,st,0, 0, 0, 0, mass, mass*95/100) // pogonion
284 emitR(b,pos,st,0, half*55/100, 0, 0-sweep*30/100, mass*80/100, mass*78/100)
285 emitR(b,pos,st,0, half, 0, 0-sweep, mass*25/100, mass*35/100)
286 return 0
287}
288// ★★★ONE LIP, AS A RULE -- then instantiated as the pair. The operator's construction principle: perfect a
289// single unit, then aggregate it, layer on layer. A lip is a horizontal roll of tissue that is fullest at
290// the midline, tapers to the commissures, and sweeps back with the curve of the face. Build THAT once and
291// the upper and lower lips are two instantiations differing only in height, fullness and projection -- the
292// same way one digit rule gave both hands and both feet.
293// ★The MOUTH is the GAP BETWEEN the two instances: no geometry is emitted there, so the shadow line that
294// reads as a mouth is a consequence of the anatomy rather than a painted rectangle.
295func emitLipZ(b: *u8, pos: *i64, st: *i64, sty: i64, headRb: i64, mat: i64, lipY: i64, full: i64) -> i64 {
296 // ⚠SIZED BY ITERATION, and the first cut is worth recording: at full=6 with a 170pct back-sweep only the
297 // midline tip cleared the skin and the mouth read as a single nub. Both judge and eye agreed there were
298 // no lips -- the instrument correctly reported no change. A real mouth is ~50mm wide and ~18mm tall on a
299 // 1750mm figure, and its corners tuck in rather than sweeping hard back, so the roll stays proud across
300 // most of its width instead of only at its centre.
301 let half: i64 = 17 - 2*sty/1000 // half the mouth width
302 let faceZ: i64 = headRb - full*40/100 // ATTACHED RELATIVE TO THE PARENT (the skull)
303 let sweep: i64 = full*70/100 // corners tuck, they do not sweep hard back
304 emitPmZ(b,pos,st,0, 0, 0, 0, lipY, faceZ, mat, 90)
305 emitR(b,pos,st,0, 0-half, 0, 0-sweep, full*22/100, full*30/100) // commissure, right
306 emitR(b,pos,st,0, 0-half*55/100, 0, 0-sweep*28/100, full*78/100, full*80/100)
307 emitR(b,pos,st,0, 0, 0, 0, full, full) // fullest at the midline
308 emitR(b,pos,st,0, half*55/100, 0, 0-sweep*28/100, full*78/100, full*80/100)
309 emitR(b,pos,st,0, half, 0, 0-sweep, full*22/100, full*30/100) // commissure, left
310 return 0
311}
312// ★★★BROW RIDGE AS A HORIZONTAL PART (F1084 prereq 3, the mechanism unlock). The supraorbital torus runs
313// ACROSS the face -- it is one continuous ridge with a slight dip at the glabella between the brows, not two
314// vertical bumps. Every previous attempt built it as a Y-stacked tube because that was the only shape the
315// part system could express, and it read as goggles or flanges. With rotation about Z the canonical Y-tube
316// turns sideways IN the face plane and the ridge is simply what it is.
317// Anatomy carried as a RULE, not coordinates: rings run laterally from the outer tail through the brow
318// belly to the glabella; the radius profile peaks over each orbit and dips at the midline; projection and
319// heaviness scale with sex (male supraorbital ridge is markedly heavier) and flatten with stylize.
320// ★ATTACHED RELATIVE TO ITS PARENT, not placed at a typed coordinate -- Infinigen's own construction rule
321// and the one this lane keeps relearning. The first cut typed faceZ=47 and the ridge vanished: the head's
322// OWN depth radius at the brow line is 59*headScale/1000, so a ridge whose front reached 53.6 was simply
323// INSIDE the skull. Now the caller passes the parent's brow-line depth (headRb) and the attachment is
324// derived: sit the ridge's axis one burial-depth inside the skin so its base merges, and its own radius
325// then carries the belly PROUD of the surface by construction, at any head scale, for any character.
326func emitBrowZ(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, headRb: i64, mat: i64) -> i64 {
327 let heavy: i64 = 9 - 4*sexf/1000 - 3*sty/1000 // ridge thickness (its radius)
328 let half: i64 = 34 - 4*sty/1000 // lateral half-span, per-mille of stature
329 // ★CORRECTED FROM THE PORTED CANON (knowledge/face_tissue.dat, seq926): the supraorbital ridge belongs at
330 // the GLABELLA (958 on our head frame), not at the EYE LINE (942). It had been typed at 944 -- 14 per-mille
331 // of stature, about 25 mm, too low -- which is why it read as sitting ON the eyes instead of above them.
332 // Found by reading the sibling lane's measured table, not by rendering another attempt.
333 let browY: i64 = 958
334 let faceZ: i64 = headRb - heavy*45/100 // burial = 45pct of the ridge radius
335 // rotZ=90 turns the canonical Y axis into the lateral axis; rings must therefore be centred on y=0 and
336 // the part is then lifted to the brow line by pOy and pushed onto the face by pOz.
337 emitPmZ(b,pos,st,0, 0, 0, 0, browY, faceZ, mat, 90)
338 // ⚠ITERATION (eyeball-driven): a STRAIGHT horizontal ridge exits an ellipsoid skull at the sides, so
339 // the first cut emerged only at its two outer tails and read as a pair of small tabs. The ridge must
340 // follow the SKULL'S CURVE -- which is also what the anatomy does, the supraorbital margin sweeping back
341 // toward the temples. Per-ring zoff recedes with the square of lateral distance, so the ridge stays
342 // inside the head laterally and emerges as one continuous brow across the front.
343 let sweep: i64 = heavy*180/100
344 emitR(b,pos,st,0, 0-half, 0, 0-sweep, heavy*30/100, heavy*40/100) // outer tail, right
345 emitR(b,pos,st,0, 0-half*55/100, 0, 0-sweep*30/100, heavy, heavy*85/100) // belly over right orbit
346 emitR(b,pos,st,0, 0, 0, 0, heavy*74/100, heavy*64/100) // glabella dip, midline
347 emitR(b,pos,st,0, half*55/100, 0, 0-sweep*30/100, heavy, heavy*85/100) // belly over left orbit
348 emitR(b,pos,st,0, half, 0, 0-sweep, heavy*30/100, heavy*40/100) // outer tail, left
349 return 0
350}
351// BROW RIDGE: a projecting shelf over each orbit (mirror gives both). This is the feature that CASTS THE
352// SHADOW over the eye -- without it the eyes read as painted dots no matter how good the eyeball is.
353func emitBrow(b: *u8, pos: *i64, st: *i64, sexf: i64, sty: i64, ex: i64, faceZ: i64, mat: i64) -> i64 {
354 // ⚠AMPLITUDE CORRECTED after the eyeball: the first cut projected 11 over a 15 half-width, which is a
355 // SHELF, not a ridge -- a real supraorbital torus is a subtle swell, and an over-projecting one reads as
356 // a caveman brow (or, with the head's colour bands on it, as goggles). Halved and narrowed.
357 let proj: i64 = 6 - 3*sexf/1000 - 2*sty/1000 // male brow ridge is heavier
358 let halfw: i64 = 11 - 2*sty/1000
359 emitPm(b,pos,st,0, 1, 0, ex, 0, faceZ, mat)
360 emitR(b,pos,st,0, 938, 0, proj*45/100, halfw*70/100, halfw*30/100)
361 emitR(b,pos,st,0, 945, 0, proj, halfw, halfw*38/100) // the ridge crest
362 emitR(b,pos,st,0, 952, 0, proj*40/100, halfw*72/100, halfw*28/100) // fading into the forehead
363 return 0
364}
365// EARS: a plate on the side of the head, mirror gives both. Set BEHIND the mid-line of the skull, spanning
366// roughly brow to nose-base height -- the classic proportional rule.
367func emitEar(b: *u8, pos: *i64, st: *i64, sty: i64, ex: i64, ez: i64, mat: i64) -> i64 {
368 let h: i64 = 6 - 1*sty/1000
369 emitPm(b,pos,st,0, 1, 0, ex, 0, ez, mat)
370 emitR(b,pos,st,0, 906, 0, 0, h*40/100, h*90/100) // lobe
371 emitR(b,pos,st,0, 918, 0, 2, h*62/100, h*160/100) // concha
372 emitR(b,pos,st,0, 930, 0, 2, h*58/100, h*150/100)
373 emitR(b,pos,st,0, 940, 0, 0, h*30/100, h*80/100) // helix top
374 return 0
375}
376// ★EYEBALL: a small sphere placed in the eye socket. mirror=1 gives both eyes. A face needs eyes more than
377// anything -- a smooth egg reads as a mannequin no matter how good the body is.
378func emitEye(b: *u8, pos: *i64, st: *i64, ey: i64, ex: i64, ez: i64, r: i64, mat: i64) -> i64 {
379 emitPm(b,pos,st,0, 1, 0, ex, 0, ez, mat) // material 1..4 = EYE iris colour
380 emitR(b,pos,st,0, ey+r, 0, 0, 1, 1)
381 emitR(b,pos,st,0, ey+r/2, 0, 0, r*82/100, r*82/100)
382 emitR(b,pos,st,0, ey, 0, 0, r, r)
383 emitR(b,pos,st,0, ey-r/2, 0, 0, r*82/100, r*82/100)
384 emitR(b,pos,st,0, ey-r, 0, 0, 1, 1)
385 return 0
386}
387func emitF(b: *u8, pos: *i64, part: i64, y: i64, yw: i64, th: i64, tw: i64, amp: i64) -> i64 {
388 if amp == 0 { return 0 }
389 b[pos[0]]=70 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2 // "F "
390 wint(b,pos,part,32); wint(b,pos,y,32); wint(b,pos,yw,32); wint(b,pos,th,32); wint(b,pos,tw,32); wint(b,pos,amp,10)
391 return 0
392}
393
394// ★★★THE FIRST CONNECTIVE TISSUE IN THE STACK. Until now nx_skelgen wrote knowledge/skel_ref.dat and NOTHING
395// READ IT -- a 21-joint skeleton generated, gated 19/19, and discarded. Meanwhile this emitter carried its own
396// copies of the same landmarks as consts, kept in agreement with the skeleton by a TEST rather than by
397// construction. That is duplication of the worst kind: two artifacts holding the same fact, with a gate
398// standing between them hoping nobody edits one.
399// ★THE INVERSION: the skeleton BECOMES the source. Landmarks are read from its J rows, so the surface cannot
400// disagree with the bone -- not because a test forbids it, but because there is only one number.
401// Contract: J <idx> <parent> <side> <x_mm> <y_mm> <z_mm>, world millimetres, joint 5 = acromion, 0 = hip.
402// ABSENT FILE = the const defaults, so every existing call is bit-identical.
403const BP_SKJ: i64 = 64
404func bp_skel_load(path: *u8, J: *i64, stature: i64) -> i64 {
405 let szp: *i64 = sys_mmap(16) as *i64
406 let mb: *u8 = sys_read_file(path, szp)
407 if (mb as i64) == 0 { return 0-1 }
408 let sz: i64 = szp[0]
409 var n: i64 = 0
410 var i: i64 = 0
411 while i < sz {
412 var e: i64 = i
413 var go: i64 = 1
414 while go == 1 { if e >= sz { go = 0 } else { if mb[e] == (10 as u8) { go = 0 } else { e = e+1 } } }
415 if mb[i] == (74 as u8) { // 'J'
416 // fields: idx parent side x y z -- we want idx (0) and y (4)
417 var k: i64 = i+1
418 var fld: i64 = 0
419 var idx: i64 = 0
420 var yv: i64 = 0
421 while k < e {
422 var c: i64 = mb[k] as i64
423 var neg: i64 = 0
424 var isd: i64 = 0
425 if c == 45 { if k+1 < e { let d: i64 = mb[k+1] as i64
426 if d >= 48 { if d <= 57 { isd = 1; neg = 1 } } } }
427 else { if c >= 48 { if c <= 57 { isd = 1 } } }
428 if isd == 1 {
429 var j: i64 = k
430 if neg == 1 { j = j+1 }
431 var v: i64 = 0
432 var run: i64 = 1
433 while run == 1 {
434 var ok: i64 = 0
435 if j < e { let d2: i64 = mb[j] as i64
436 if d2 >= 48 { if d2 <= 57 { ok = 1 } } }
437 if ok == 1 { v = v*10 + ((mb[j] as i64)-48); j = j+1 } else { run = 0 }
438 }
439 if neg == 1 { v = 0-v }
440 if fld == 0 { idx = v }
441 if fld == 4 { yv = v }
442 fld = fld + 1
443 k = j
444 } else { k = k+1 }
445 }
446 // store the joint HEIGHT back in per-mille of stature, the unit the canon speaks
447 if idx >= 0 { if idx < BP_SKJ { if stature > 0 {
448 J[idx] = (yv*1000 + stature/2)/stature
449 n = n + 1
450 } } }
451 }
452 i = e+1
453 }
454 return n
455}
456func main(argc: i64, argv: *i64) -> i64 {
457 let outp: *u8 = argv[1] as *u8
458 var sex: i64 = 0; var build: i64 = 300; var musc: i64 = 400; var noise: i64 = 0; var seed: i64 = 1; var sty: i64 = 0
459 var eyecol: i64 = 0 // 0 = auto (from seed); else 1 brown 2 blue 3 green 4 amber
460 if argc > 2 { sex = satoi(argv[2] as *u8) }
461 if argc > 3 { build = satoi(argv[3] as *u8) }
462 if argc > 4 { musc = satoi(argv[4] as *u8) }
463 if argc > 5 { noise = satoi(argv[5] as *u8) }
464 if argc > 6 { seed = satoi(argv[6] as *u8) }
465 if argc > 7 { sty = satoi(argv[7] as *u8) }
466 if argc > 8 { eyecol = satoi(argv[8] as *u8) }
467 // ★argv[9]: the SKELETON this body is built on. Absent -> the const landmarks (bit-identical default).
468 let J: *i64 = sys_mmap(BP_SKJ*8) as *i64
469 var jz: i64 = 0
470 while jz < BP_SKJ { J[jz] = 0; jz = jz+1 }
471 var acromion: i64 = BP_ACROMION
472 var troch: i64 = BP_TROCH
473 var skjoints: i64 = 0
474 if argc > 9 {
475 skjoints = bp_skel_load(argv[9] as *u8, J, K_MAGIC_1750)
476 // ★FAIL LOUD, NOT QUIETLY BACK TO THE DEFAULTS. A skeleton that was asked for and could not be read
477 // must stop the run -- silently emitting the const-landmark body would look like success and would
478 // be a body built on a skeleton that was never consulted.
479 if skjoints <= 0 { pw(1, "{\x22organ\x22:\x22nx_body_proc\x22,\x22error\x22:\x22skeleton unreadable or empty\x22}
480" as *u8); return 3 }
481 if J[5] > 0 { acromion = J[5] }
482 if J[0] > 0 { troch = J[0] }
483 }
484 let st: *i64 = sys_mmap(64) as *i64
485 st[0] = seed*K_MAGIC_2654435761 + K_MAGIC_1013904223
486 if st[0] == 0 { st[0] = 1 }
487 // warm the PRNG so nearby seeds diverge
488 var w: i64 = 0
489 while w < 8 { pr_step(st); w = w+1 }
490
491 // ---- ANATOMICAL DIMORPHISM FUNCTIONS (this is the procedural rule engine's knowledge, not a stored body).
492 // All quantities per-mille of stature. sexf in [0,1000]: 0=male, 1000=female.
493 let sexf: i64 = sex
494 // biacromial (shoulder) breadth: male wider. biiliac (hip) breadth: female wider. waist: female narrower.
495 let shoulder: i64 = 112 - 20*sexf/1000 // male 112 -> female 92 (half-width)
496 let hip: i64 = 95 + 22*sexf/1000 // male 95 -> female 117
497 let waist: i64 = 86 - 12*sexf/1000 + 34*build/1000 // female nips in; build adds girth everywhere
498 let chestRa: i64 = 99 - 6*sexf/1000
499 let bustD: i64 = 68 + 26*sexf/1000 // chest DEPTH: female bust projects
500 let neckRa: i64 = 39 - 6*sexf/1000 // female slimmer neck
501 let g: i64 = build*22/1000 // global girth from build (per-mille), added to trunk radii
502 // muscularity -> limb girth multiplier (per-mille) and muscle-relief amplitude
503 let limbMul: i64 = 1000 + 130*musc/1000 - 60*sexf/1000 // female slightly less limb girth
504 let reliefMul: i64 = 300 + 900*musc/1000 // muscle definition scales with muscularity
505 // stylization: anime = much bigger head (heads run ~1/5 stature vs ~1/7.5 realistic), longer legs,
506 // slimmer limbs. These are the stylized-archetype knobs -- the same generator spans realistic..anime.
507 let headScale: i64 = 1000 + 780*sty/1000
508 let legScale: i64 = 1000 + 140*sty/1000
509 let styLimb: i64 = 1000 - 260*sty/1000
510
511 let b: *u8 = sys_mmap(K_MAGIC_65536)
512 let pos: *i64 = sys_mmap(8) as *i64; pos[0] = 0
513 pw(1, "{\x22organ\x22:\x22nx_body_proc\x22,\x22infinigen_style\x22:\x22procedural canon from params+seed, no hand-crafted asset\x22" as *u8)
514
515 // ============ PART 0 TORSO (fully dimorphic) ============
516 emitP(b,pos,st,noise, 0,0,0,0,0)
517 // ★PELVIS re-proportioned by measurement: the crotch (pubic symphysis) sits at ~HALF stature (~470),
518 // NOT 430, and it is NARROW -- below it there are only the two separated legs. The old wide low crotch
519 // (ra 86 @ 430) made a solid block: silhouette 228 @ 429permil vs the oracle's 119 (legs separated).
520 emitR(b,pos,st,noise, 470, 0, 0, 30+g, 40+g) // crotch/pubis -- NARROW + high
521 // ★★★TRIED TO ANCHOR THIS ON THE SKELETON AND THE RENDER REFUTED IT -- REVERTED, WITH THE REASON.
522 // The ring is mislabelled: it says "iliac, widest of pelvis" and sits at 496, a height at which no
523 // pelvic landmark lives (iliac crest ~600; widest hip breadth is BITROCHANTERIC at trochanterion 530).
524 // So it was moved to BP_TROCH to match the skeleton's hip joint -- and the pelvis grew a hard horizontal
525 // rim and read as a bucket. Raising the crotch instead was worse. ★THE BENCH COULD NOT SEE ANY OF IT:
526 // front IoU went 283 -> 282 for the broken shape and 285 for the reverted one, a four-point spread
527 // across four bodies that look obviously different to an eye. Metrics BESIDE the pixels, always.
528 // ★THE CAUSE, and it is structural rather than a number: this pelvis is ONE tube that narrows to a
529 // 36-wide crotch at 470. With the widest ring at 496 the cone from hip to crotch is 26 per-mille and
530 // reads as a rounded bottom; at the anatomically correct 530 it is 60 per-mille and reads as a skirt
531 // with a rim. A real pelvis does not narrow between trochanter and crotch -- it stays wide and SPLITS
532 // into two masses. So the surface cannot carry the true landmark until the pelvis becomes two lofted
533 // masses instead of one narrowing tube, which is the next rung, filed rather than faked.
534 // ★LAW: WHEN THE ANATOMICALLY RIGHT NUMBER MAKES THE SURFACE WORSE, THE MODEL IS TOO COARSE TO HOLD IT
535 // -- moving the number anyway just relocates the error into something the ruler cannot see.
536 emitR(b,pos,st,noise, 496, 0, 0-9, hip, 64+g) // surface ring, NOT the landmark
537 emitR(b,pos,st,noise, 545, 0, 0-2, waist, 60+g*6/10) // waist (dimorphic)
538 emitR(b,pos,st,noise, 620, 0, 5, 92+g*6/10, 64+g*6/10) // lower chest
539 emitR(b,pos,st,noise, 700, 0, 9, chestRa+g/2, bustD) // chest (bust depth)
540 emitR(b,pos,st,noise, 752, 0, 4, shoulder-2, 66) // upper chest / armpit level
541 emitR(b,pos,st,noise, acromion, 0, 0, shoulder, 58) // ★ACROMION -- the widest shoulder point
542 // sits HIGH (~810), not at 757; the
543 // biacromial span was measured 60 vs
544 // oracle 147 @ 833permil = too low+thin
545 emitR(b,pos,st,noise, 838, 0, 0-6, shoulder*52/100, 52) // trapezius slope down from acromion
546 emitR(b,pos,st,noise, 864, 0, 0-9, neckRa+6, neckRa+2) // trap base
547 emitR(b,pos,st,noise, 892, 0, 0-9, neckRa, neckRa) // neck
548 emitR(b,pos,st,noise, 920, 0, 0-6, neckRa-4, neckRa-3) // upper neck (into the head)
549
550 // ============ PART 1 ARM (deltoid caps just BELOW the acromion and hangs down) ============
551 emitP(b,pos,st,noise, 1,0,0,0,0)
552 // ⚠REVERTED: generating this tube with UNIFORM stations on a LINEAR path measured 380 -> 329. The typed
553 // table is not merely a list -- it encodes NON-UNIFORM station density (four rings in the top 74 permil
554 // around the shoulder, then four across the remaining 240) and a NON-LINEAR hang path (x runs 56,76,92,
555 // 108 then only 116,130,144,154). A uniform linear generator destroys both. The rule needs a path curve
556 // and a station-distribution parameter before it can eat this table; see the ray-set rule for the shape
557 // that worked. Kept typed until the generator can reproduce it, because shipping the worse body to look
558 // more principled would be the wrong trade.
559 emitR(b,pos,st,noise, 812, 56, 0, 18*limbMul/1000*styLimb/1000, 19*limbMul/1000*styLimb/1000)
560 emitR(b,pos,st,noise, 792, 76, 0, 34*limbMul/1000*styLimb/1000, 35*limbMul/1000*styLimb/1000)
561 emitR(b,pos,st,noise, 770, 92, 0, 45*limbMul/1000*styLimb/1000, 45*limbMul/1000*styLimb/1000)
562 emitR(b,pos,st,noise, 738, 108, 0, 36*limbMul/1000*styLimb/1000, 38*limbMul/1000*styLimb/1000)
563 emitR(b,pos,st,noise, 700, 116, 0, 31*limbMul/1000*styLimb/1000, 33*limbMul/1000*styLimb/1000)
564 emitR(b,pos,st,noise, 634, 130, 0, 26*limbMul/1000*styLimb/1000, 28*limbMul/1000*styLimb/1000)
565 emitR(b,pos,st,noise, 560, 144, 0, 22*limbMul/1000*styLimb/1000, 24*limbMul/1000*styLimb/1000)
566 emitR(b,pos,st,noise, 500, 154, 0, 18*styLimb/1000, 20*styLimb/1000) // wrist
567 emitR(b,pos,st,noise, 478, 160, 0, 20*styLimb/1000, 13*styLimb/1000) // hand root
568 emitR(b,pos,st,noise, 456, 163, 2, 26*styLimb/1000, 9*styLimb/1000) // palm (wide + FLAT: rb<<ra)
569 emitR(b,pos,st,noise, 438, 163, 2, 27*styLimb/1000, 8*styLimb/1000) // knuckle line (widest, flat)
570
571 // ============ PART 2 LEG (girth + longer-leg stylization) ============
572 emitP(b,pos,st,noise, 1,0,0,0,0)
573 emitR(b,pos,st,noise, 500*legScale/1000, 50, 0-6, 38*limbMul/1000, 50*limbMul/1000) // thigh top at the hip
574 // -- x50/ra38 leaves a
575 // perineal GAP so the
576 // legs SEPARATE (groin
577 // was a merged block)
578 emitR(b,pos,st,noise, 452*legScale/1000, 48, 0-6, 46*limbMul/1000, 56*limbMul/1000) // upper thigh (widest)
579 emitR(b,pos,st,noise, 352*legScale/1000, 45, 0-10, 43*limbMul/1000, 49*limbMul/1000)
580 emitR(b,pos,st,noise, 258*legScale/1000, 47, 0-12, 37*limbMul/1000, 43*limbMul/1000)
581 emitR(b,pos,st,noise, 190*legScale/1000, 48, 0-10, 32*limbMul/1000, 40*limbMul/1000)
582 emitR(b,pos,st,noise, 100*legScale/1000, 48, 0-4, 24*limbMul/1000, 32*limbMul/1000)
583 emitR(b,pos,st,noise, 42, 48, 2, 19, 21)
584 emitR(b,pos,st,noise, 25, 48, 2, 18, 20)
585
586 // ============ PART 3 FOOT (forward, placement rot 90) ============
587 emitP(b,pos,st,noise, 1,90,48,40,0-41)
588 emitR(b,pos,st,noise, 0, 0, 30, 14, 10)
589 emitR(b,pos,st,noise, 16, 0, 14, 24, 26)
590 emitR(b,pos,st,noise, 42, 0, 16, 24, 24)
591 emitR(b,pos,st,noise, 71, 0, 24, 26, 16)
592 emitR(b,pos,st,noise, 96, 0, 28, 28, 12)
593 emitR(b,pos,st,noise, 118, 0, 32, 25, 8)
594 // ★TOES BY THE SAME RULE THAT GAVE FINGERS, placed in the FOOT's rotated frame so they run forward off
595 // the toe line. Great toe medial, stout and longest; the rest taper outward -- five calls, no modelling.
596 let tr: i64 = 5 + build/500 // toe radius, tracks the same build knob
597 // ⚠ toes must REPLACE the flat toe-plate, not extend past it -- and BOTH halves of that sentence are
598 // load-bearing. The first attempt ran them to 174 (~20% longer foot) and the height-normalised side
599 // silhouette fell 831 -> 723; the second attempt shortened them to fit INSIDE a plate that was never
600 // deleted, so nx_footcheck measured 27 of each toe's 34 units buried in the tube (protrusion 46 permil
601 // vs the 200 anatomical floor) -- the blunt hoof with pale nubs. So the tube now ENDS at the toe line
602 // (y118, where the toes begin) and the toes alone carry the foot from there to its unchanged tip at
603 // y152. Foot LENGTH is silhouette-critical and nx_footcheck T6 pins it: structure moved, silhouette not.
604 // 5 rays across the toe line, longest at ray 0 (hallux), running FORWARD in the foot's own frame:
605 // the SAME rule as the hand, four parameters different. plane=40 = the tube's own constant sole line
606 // (every tube ring holds zoff+rb = 40), so the toes stand flush on the same ground the heel does.
607 emitRaySet(b,pos,st, 1, 15, 118, 34, tr+2, 5, 0, 0-1, 40, 90, 48, 40, 0-41)
608
609 // ============ PART 4 HEAD (bigger for anime stylization) ============
610 let hb: i64 = 884 // head base y (fixed to the neck)
611 emitPm(b,pos,st,noise, 0,0,0,0,0, 5) // material 5 = FACE (lips + brows coloured by region)
612 // ★FLAT FACE PLANE: the front z (rz0+rb) is kept nearly CONSTANT (~60-66) from jaw up through brow, so the
613 // face is a near-vertical plane facing forward -- not a receding ovoid. This lights the mouth (it no longer
614 // hides under a jutting chin) and de-eggs the head. Only above the brow and below the jaw does it round off.
615 emitR(b,pos,st,0, 852, 0, 0-6, 30, 34) // skull base buried in the neck (front z 28)
616 emitR(b,pos,st,noise, 876, 0, 8, 40*headScale/1000, 52*headScale/1000) // jaw (front z 60)
617 emitR(b,pos,st,noise, 894, 0, 6, 46*headScale/1000, 60*headScale/1000) // chin + mouth (front z 66)
618 emitR(b,pos,st,noise, hb+32, 0, 4, 50*headScale/1000, 62*headScale/1000) // cheek/nose base (66)
619 emitR(b,pos,st,noise, hb+46, 0, 2, 50*headScale/1000, 62*headScale/1000) // eyes (64)
620 emitR(b,pos,st,noise, hb+61, 0, 0, 48*headScale/1000, 59*headScale/1000) // brow (59)
621 emitR(b,pos,st,noise, hb+79, 0, 0-4, 45*headScale/1000, 54*headScale/1000) // forehead
622 emitR(b,pos,st,noise, hb+96, 0, 0-7, 41*headScale/1000, 47*headScale/1000) // upper skull
623 emitR(b,pos,st,noise, hb+112,0, 0-7, 30*headScale/1000, 34*headScale/1000) // high skull (crown lowered)
624 emitR(b,pos,st,noise, hb+120,0, 0-6, 16*headScale/1000, 18*headScale/1000) // crown (shorter -> less bullet)
625
626 // ============ ★PROCEDURAL HAND: 4 fingers + thumb, PLACED BY A RULE (not modelled one by one) ============
627 // The arm tube ends in a palm at y~430,x~163; digits extend downward from it. mirror=1 gives both hands.
628 // Slimmer for the anime stylization (styLimb), a touch stouter with build.
629 let dr: i64 = 6*styLimb/1000 + build/500 // digit radius
630 // 4 rays across the knuckle line, longest at ray 1 (middle) -- one rule, not four typed fingers.
631 // plane = dr+2 keeps the middle finger byte-where it was (its fz = plane - dr = 2) while the thinner
632 // fingers rise to share its palmar plane -- the same flush rule that fixed the foot's sole.
633 emitRaySet(b,pos,st, 163, 14, 437, 52, dr, 4, 333, 1, dr+2, 0, 0, 0, 0)
634 emitDigit(b,pos,st, 137, 10, 452, 424, dr+1) // thumb (higher, forward, stout)
635
636 // ============ ★EYES: two eyeballs in the sockets (mirror gives both). r a touch bigger for anime. ============
637 // eye colour: an explicit knob (customizer), or auto-varied from the seed so a random character gets a
638 // random-but-deterministic iris colour. This is procedural variation, not a hand-picked asset.
639 var em: i64 = eyecol
640 if em < 1 { em = 1 + (pr_step(st) % 4) }
641 // ★SECOND CANON CORRECTION (knowledge/face_tissue.dat): the eye line belongs at 942, and ours was at 928.
642 // The SAME 14 per-mille deficit the brow had -- the whole feature set was sitting low on the head, which
643 // is why raising the brow alone opened a gap above the eyes. Correcting them together keeps the
644 // brow-to-eye relationship the canon specifies. Two features, one measured offset, found by the port.
645 emitEye(b,pos,st, 942, 19, 55, 11 + 5*sty/1000, em) // canon eye line; wider + forward
646 // ★NOSE as real protruding GEOMETRY (see emitNose): the measured answer to head-scale detail 79.
647 // faceZ 46 sits the part's base just INSIDE the face surface so it merges with the head rather than
648 // floating in front of it (the same burial trick the head's base cap uses at the neck seam).
649 emitNose(b,pos,st, sexf, sty, 46, 5)
650 // ★F1083: the rest of the face as GEOMETRY. Each faceZ buries the part's base just inside the head
651 // surface so it merges rather than floats (the nose's lesson). Ears sit lateral (ex) and behind (ez).
652 // ⚠MATERIAL 0 (plain flesh), NOT 5. A part carrying material 5 inherits the HEAD's region-colouring
653 // rules -- angular colour bands calibrated for the head's geometry and radius. Applied to a small part
654 // those bands land arbitrarily: the first cut of the brow ridge rendered as a SHELF PAINTED WITH BLACK
655 // BARS (it read as goggles). The whole point of this rung is that geometry, not colour, makes a face --
656 // so the feature parts take flesh and let the light do the work.
657 // ⚠⚠NOT SHIPPED -- REVERTED BY EYEBALL AFTER TWO CORRECTION PASSES (F1083, 2026-07-25).
658 // The four rules above are RETAINED, UNUSED (the GX-34 emitLimbTube precedent) because the mechanism is
659 // sound and the placement/shape is not. Measured detail_head rose 288 -> 333 -> 357, and the face got
660 // WORSE both times: the brow read first as a black-barred SHELF (goggles), then as pointed flanges beside
661 // the painted brow band; the chin read as a duckbill below the mouth; the lips never became visible at all.
662 // ★THE FINDING: the detail judge scores LOCAL NORMAL VARIANCE and cannot ask whether that variance is
663 // ANATOMY -- so feature-shaped bumps in the wrong places score exactly like features in the right ones.
664 // This is the GX-13 FBM Goodhart and the GX-58 bell, now reproduced in facial geometry, and it is why a
665 // rising number was not permission to ship. A bad face is worse than an honest egg.
666 // ★WHAT THE NEXT ATTEMPT NEEDS (all three, or it repeats this result):
667 // 1. the painted mat-5 brow/lip colour bands RETIRED first -- geometry and paint fight each other;
668 // 2. a HEAD-REGION judge that scores placement against oracle LANDMARKS, not variance alone;
669 // 3. features authored in the FACE PLANE, not as Y-stacked tubes: a brow ridge and a lip run
670 // HORIZONTALLY, and the part system can only stack rings along Y (rot is about X only), which is the
671 // structural reason these read as vertical blobs. Rotation about Z is the real unlock.
672 // ★F1084: the brow ridge, rebuilt as a HORIZONTAL Z-rotated part and shipped one feature at a time --
673 // the previous rung added four at once and had to revert all four. Its painted colour band is retired
674 // in the emitter in the same change, because paint and geometry cannot both own a feature.
675 emitBrowZ(b,pos,st, sexf, sty, 59*headScale/1000, 0)
676 // ★THE PAIR, from the one rule. Upper lip sits higher and thinner; the lower is fuller and projects a
677 // little more, as it does on a real mouth. Their parent depth is the head's own ring at the mouth line
678 // (60*headScale/1000), so both ride proud of whatever skull the generator produced. Female lips fuller.
679 let lipFull: i64 = 11 + 3*sexf/1000
680 // ★CANON Y (F1128): the table puts the upper lip at 888 and the lower at 880, i.e. 8 apart. Ours were 13
681 // apart (894/881), which is why the mouth read as two separate rolls rather than one closed pair. The
682 // STOMION -- the line between them, which is what actually reads as a mouth -- lands at 882 as the canon
683 // specifies once they are this close.
684 // ⚠⚠THE CANON Y APPLIED LITERALLY CRASHED THE MIDLINE LANE 138 -> 40, AND THE CAUSE IS A LAW ALREADY IN
685 // THIS FILE: A FEATURE PART OCCUPIES A BAND, NOT A POINT. The table's 888/880 are the anatomical
686 // landmarks for the lip CENTRES as infinitesimal points; our lips are TUBES with radius ~9 and ~11, so
687 // centres 8 apart OVERLAP COMPLETELY and merge into one mass -- the groove that reads as a mouth
688 // disappears. The same collision that let the chin swallow the lips, arriving from the opposite
689 // direction. ★A LANDMARK TABLE CANNOT BE APPLIED DIRECTLY TO PARTS WITH EXTENT.
690 // ★THE DERIVED FIX: hold the canon STOMION (882, the line between the lips -- the landmark that actually
691 // reads) as the invariant, and place each lip so its INNER EDGE lands on it. Centre = stomion +/- radius.
692 // The canon is honoured where it matters and the parts stop fighting.
693 // ⚠THE STOMION-DERIVED PLACEMENT WAS ALSO REVERTED, and the numbers alone would have shipped it: mean
694 // 216 -> 222 and detail_head 277 -> 315, both up, headline only -3. But the EYEBALL said the mouth got
695 // WORSE -- the lower lip landed at 871, barely 19 above the chin, and the pair read as one flat mass at
696 // the bottom of the face instead of two lips with a groove. ★SO THE CANON'S STOMION DOES NOT TRANSFER
697 // EITHER: it is measured on the SDF lane's head, and on ours it sits too low. Same lesson as the nose,
698 // now confirmed on a second landmark -- of four values ported from the table, TWO transferred (brow,
699 // eye line: +46 headline) and TWO did not (nose, stomion). ★★A PORTED CANON IS A HYPOTHESIS PER
700 // LANDMARK, AND TWO OUT OF FOUR IS THE MEASURED HIT RATE.
701 emitLipZ(b,pos,st, sty, 60*headScale/1000, 0, 894, lipFull*80/100) // upper (measured-best)
702 emitLipZ(b,pos,st, sty, 60*headScale/1000, 0, 881, lipFull) // lower (measured-best)
703 // ★the chin: the mass a mouth is READ AGAINST. Measuring said our mouth height was already correct and
704 // the absent chin was what made it look low -- so this is the fix for that complaint, not moving the lips.
705 // ⚠⚠NOT SHIPPED after THREE measured attempts -- rule retained, unused (the emitLimbTube precedent).
706 // 868 / mass 13 -> headline 104, mean 211, detail_head 380, but a POINTED witch-chin jutting past the jaw
707 // 876 / mass 9 -> headline 69, mean 162, detail_head 352: cured the jut and SWALLOWED THE LIPS (the
708 // judge caught a collision the eye had missed -- its top edge reached 885, the lip 881)
709 // 866 / mass 10 -> headline 72, mean 201, detail_head 399 (BEST measured), still two STACKED LOBES
710 // ★★★THE ARCHITECTURAL FINDING, and it is why no amount of tuning fixed it: A CHIN IS NOT A PART. It is
711 // the FRONT OF THE JAW -- the visible end of one continuous mandible-plus-soft-tissue mass running ear to
712 // ear. Modelling a prominence of that mass as an isolated horizontal tube can only ever stack a ball
713 // under the mouth, which is exactly what all three attempts rendered. The unit to build is the JAW; the
714 // chin is then a property of its front, the way the glabella dip is a property of the brow ridge rather
715 // than a part of its own. This is the same lesson as the mouth looking low because the chin was absent,
716 // one level deeper: proportion and form are read from continuous structures, not from stacked pieces.
717 // emitChinZ(b,pos,st, sexf, sty, 52*headScale/1000, 0)
718 // emitLips(b,pos,st, sexf, sty, 44, 0)
719 // emitChin(b,pos,st, sexf, sty, 40, 0)
720 // emitBrow(b,pos,st, sexf, sty, 19, 44, 0)
721 // emitEar(b,pos,st, sty, 47, 0-6, 0)
722
723 // ============ RELIEF FEATURES (procedurally modulated by sex / muscularity / stylization) ============
724 // TORSO front/back muscle definition scales with muscularity; the female bust is a large front feature.
725 emitF(b,pos, 0, 706, 62, 62, 34, 78*reliefMul/1000*(1000-sexf)/1000) // pectoral R (male)
726 emitF(b,pos, 0, 706, 62, 118, 34, 78*reliefMul/1000*(1000-sexf)/1000) // pectoral L
727 emitF(b,pos, 0, 698, 40, 62, 30, 60*sexf/1000) // BREAST R (female)
728 emitF(b,pos, 0, 698, 40, 118, 30, 60*sexf/1000) // BREAST L
729 emitF(b,pos, 0, 612, 70, 72, 26, 40*reliefMul/1000) // abdominal R
730 emitF(b,pos, 0, 612, 70, 108, 26, 40*reliefMul/1000) // abdominal L
731 emitF(b,pos, 0, 600, 90, 90, 13, 0-34*reliefMul/1000) // rectus groove
732 emitF(b,pos, 0, 660, 140,270, 15, 0-46) // spinal groove
733 emitF(b,pos, 0, 735, 52, 246, 32, 52*reliefMul/1000) // scapula R
734 emitF(b,pos, 0, 735, 52, 294, 32, 52*reliefMul/1000) // scapula L
735 emitF(b,pos, 0, 470, 54, 250, 40, 86 + 30*sexf/1000) // gluteal R (female fuller)
736 emitF(b,pos, 0, 470, 54, 290, 40, 86 + 30*sexf/1000) // gluteal L
737 emitF(b,pos, 0, 772, 44, 90, 44, 0-30) // supra-clavicular hollow
738 // LEG
739 emitF(b,pos, 2, 372, 90, 90, 52, 54*reliefMul/1000) // quadriceps
740 emitF(b,pos, 2, 340, 80, 270, 46, 40*reliefMul/1000) // hamstring
741 emitF(b,pos, 2, 196, 62, 270, 48, 68*reliefMul/1000) // gastrocnemius
742 emitF(b,pos, 2, 258, 34, 90, 34, 30) // patella
743 // ARM
744 emitF(b,pos, 1, 690, 70, 90, 52, 44*reliefMul/1000) // biceps
745 emitF(b,pos, 1, 690, 70, 270, 52, 36*reliefMul/1000) // triceps
746 // HEAD (face) -- stylization can exaggerate the eye sockets (anime); nose softens for female
747 emitF(b,pos, 4, 921, 22, 90, 17, 150 - 40*sexf/1000) // nose
748 emitF(b,pos, 4, 908, 14, 90, 12, 120 - 30*sexf/1000) // nose tip
749 emitF(b,pos, 4, 946, 16, 90, 40, 44) // brow
750 emitF(b,pos, 4, 896, 18, 90, 26, 70 - 20*sexf/1000) // chin (softer female)
751 emitF(b,pos, 4, 926, 20, 58, 24, 40) // cheekbone R
752 emitF(b,pos, 4, 926, 20, 122, 24, 40) // cheekbone L
753 emitF(b,pos, 4, 929, 14, 66, 16, 0-56 - 30*sty/1000) // eye socket R (holds the eyeball)
754 emitF(b,pos, 4, 929, 14, 114, 16, 0-56 - 30*sty/1000) // eye socket L
755 emitF(b,pos, 4, 924, 10, 90, 10, 40) // nasal bridge (between the eyes)
756 emitF(b,pos, 4, 889, 9, 90, 20, 14) // lips: gentle protrusion, colour does the rest
757 emitF(b,pos, 4, 906, 8, 78, 8, 0-24) // nostril R
758 emitF(b,pos, 4, 906, 8, 102, 8, 0-24) // nostril L
759 emitF(b,pos, 4, 963, 40, 270, 60, 46) // occiput
760
761 // ============ ★PROCEDURAL FINE MUSCLE STRUCTURE ============
762 // GENERATED BY RULES (loops emitting grids/fans), not hand-placed features. This is the surface-detail
763 // frontier the honest DETAIL judge exposed (broad relief alone left the surface a smooth mannequin ~300).
764 // It only appears above ~35% muscularity (real definition needs low body-fat + muscle), and its amplitude
765 // scales with it -- so a soft body stays smooth and a lean muscular one gets a six-pack.
766 let def: i64 = musc - 350
767 if def > 0 {
768 let da: i64 = def*1000/650 // 0..1000 as musc 350->1000
769 // RECTUS ABDOMINIS "six-pack": a GRID -- two columns (L/R of the linea alba) x three rows of bulges,
770 // with a vertical linea groove and horizontal tendinous-intersection grooves generated between them.
771 var r6: i64 = 0
772 while r6 < 3 {
773 let y6: i64 = 558 + r6*36
774 emitF(b,pos, 0, y6, 18, 79, 14, 66*da/1000) // rectus bulge R (column right)
775 emitF(b,pos, 0, y6, 18, 101, 14, 66*da/1000) // rectus bulge L (column left)
776 r6 = r6+1
777 }
778 emitF(b,pos, 0, 600, 130, 90, 7, 0-64*da/1000) // linea alba (sharp vertical groove)
779 var h6: i64 = 0
780 while h6 < 2 { // tendinous intersections (rows)
781 emitF(b,pos, 0, 576 + h6*36, 7, 90, 32, 0-56*da/1000)
782 h6 = h6+1
783 }
784 emitF(b,pos, 0, 676, 12, 62, 32, 0-58*da/1000) // pectoral lower border groove R
785 emitF(b,pos, 0, 676, 12, 118, 32, 0-58*da/1000) // pectoral lower border groove L
786 // SERRATUS ANTERIOR: a fan of finger-like slips on the lower-lateral ribcage -- generated as a series.
787 var sv: i64 = 0
788 while sv < 3 {
789 let ys: i64 = 636 + sv*18
790 emitF(b,pos, 0, ys, 14, 51, 14, 46*da/1000) // serratus slip R
791 emitF(b,pos, 0, ys, 14, 129, 14, 46*da/1000) // serratus slip L
792 sv = sv+1
793 }
794 emitF(b,pos, 0, 752, 22, 66, 17, 50*da/1000) // anterior deltoid head R
795 emitF(b,pos, 0, 752, 22, 114, 17, 50*da/1000) // anterior deltoid head L
796 // BACK definition: erector spinae columns either side of the spinal groove; trapezius wedge; lats.
797 emitF(b,pos, 0, 600, 120, 258, 14, 40*da/1000) // erector R
798 emitF(b,pos, 0, 600, 120, 282, 14, 40*da/1000) // erector L
799 emitF(b,pos, 0, 700, 60, 270, 40, 34*da/1000) // trapezius
800 emitF(b,pos, 0, 660, 70, 230, 20, 30*da/1000) // latissimus R
801 emitF(b,pos, 0, 660, 70, 310, 20, 30*da/1000) // latissimus L
802 // LIMB definition: biceps peak + brachial groove (arm); quadriceps heads + hamstring split (leg); calf heads.
803 emitF(b,pos, 1, 690, 46, 90, 30, 44*da/1000) // biceps peak (sharper than base)
804 emitF(b,pos, 1, 690, 46, 40, 16, 0-30*da/1000) // brachial groove (biceps/triceps sep)
805 emitF(b,pos, 1, 690, 46, 140, 16, 0-30*da/1000)
806 emitF(b,pos, 2, 372, 70, 70, 30, 40*da/1000) // vastus lateralis R-of-front
807 emitF(b,pos, 2, 372, 70, 110, 30, 40*da/1000) // vastus medialis L-of-front
808 emitF(b,pos, 2, 340, 60, 270, 20, 0-30*da/1000) // hamstring split groove
809 emitF(b,pos, 2, 196, 52, 250, 22, 44*da/1000) // gastrocnemius medial head
810 emitF(b,pos, 2, 196, 52, 290, 22, 44*da/1000) // gastrocnemius lateral head
811 // FRONT-FACING limb definition (raises the front-view detail, where arm/leg fronts were still smooth)
812 emitF(b,pos, 2, 372, 58, 90, 22, 42*da/1000) // rectus femoris (center front thigh)
813 emitF(b,pos, 2, 300, 52, 108, 20, 34*da/1000) // vastus medialis teardrop (inner)
814 emitF(b,pos, 2, 372, 54, 132, 22, 0-28*da/1000) // IT-band groove (lateral thigh)
815 emitF(b,pos, 2, 150, 54, 86, 22, 32*da/1000) // tibialis anterior (shin)
816 emitF(b,pos, 2, 258, 30, 90, 20, 36*da/1000) // patella (sharper)
817 emitF(b,pos, 1, 560, 52, 88, 26, 36*da/1000) // forearm flexor bulge (front)
818 emitF(b,pos, 1, 560, 52, 58, 18, 0-24*da/1000) // brachioradialis groove
819 emitF(b,pos, 1, 500, 40, 92, 22, 0-22*da/1000) // wrist taper groove
820 // FRONT-FACING chest: sternum groove + clavicle line, so the upper chest isn't a smooth plate
821 emitF(b,pos, 0, 720, 70, 90, 8, 0-30*da/1000) // sternum midline groove
822 emitF(b,pos, 0, 748, 12, 74, 22, 30*da/1000) // clavicle R
823 emitF(b,pos, 0, 748, 12, 106, 22, 30*da/1000) // clavicle L
824 }
825
826 // ---- write the canon file ----
827 let fd: i64 = sys_openat_wr(outp, 0x1a4) // 0644
828 if fd < 0 { pw(1, ",\x22error\x22:\x22cannot open out\x22}\n" as *u8); return 3 }
829 sys_write(fd, b, pos[0])
830 sys_close(fd)
831 let nb: *u8 = sys_mmap(64); let np2: *i64 = sys_mmap(8) as *i64; np2[0]=0
832 pw(1, ",\x22bytes\x22:" as *u8); wint(nb,np2,pos[0],32); sys_write(1, nb, np2[0]-1)
833 np2[0]=0; pw(1, ",\x22sex\x22:" as *u8); wint(nb,np2,sex,32); sys_write(1, nb, np2[0]-1)
834 np2[0]=0; pw(1, ",\x22build\x22:" as *u8); wint(nb,np2,build,32); sys_write(1, nb, np2[0]-1)
835 np2[0]=0; pw(1, ",\x22musc\x22:" as *u8); wint(nb,np2,musc,32); sys_write(1, nb, np2[0]-1)
836 np2[0]=0; pw(1, ",\x22seed\x22:" as *u8); wint(nb,np2,seed,32); sys_write(1, nb, np2[0]-1)
837 np2[0]=0; pw(1, ",\x22stylize\x22:" as *u8); wint(nb,np2,sty,32); sys_write(1, nb, np2[0]-1)
838 pw(1, "}\n" as *u8)
839 return 0
840}