code wiki / _hdl_build / nx_body_proc_partorder_t239.nx
nx_body_proc_partorder_t239.nx source
↩ module page · 1101 lines · 76613 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}
456const BP_NDIM: i64 = 21
457func bp_err(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 }
458// reads the dimorphism coefficients. Refuses rather than emitting a canon on zeroed coefficients, which
459// would produce a dimensionless body -- something that reads as a generator bug, not a missing file.
460func bp_rdint(b: *u8, pos: *i64, end: i64) -> i64 {
461 var i: i64 = pos[0]
462 var go: i64 = 1
463 while go == 1 {
464 if i >= end { go = 0 } else {
465 let c: i64 = b[i] as i64
466 if c == 45 { go = 0 } else { if c >= 48 { if c <= 57 { go = 0 } else { i = i+1 } } else { i = i+1 } }
467 }
468 }
469 var sg: i64 = 1
470 if i < end { if (b[i] as i64) == 45 { sg = 0-1; i = i+1 } }
471 var v: i64 = 0
472 var g2: i64 = 1
473 while g2 == 1 {
474 if i >= end { g2 = 0 } else {
475 let c2: i64 = b[i] as i64
476 if c2 >= 48 { if c2 <= 57 { v = v*10 + (c2-48); i = i+1 } else { g2 = 0 } } else { g2 = 0 }
477 }
478 }
479 pos[0] = i
480 return v*sg
481}
482func bp_load_dimorph_from(D: *i64, path: *u8) -> i64 {
483 var z: i64 = 0
484 while z < BP_NDIM { D[z] = 0; z = z + 1 }
485 let ln: *i64 = sys_mmap(16) as *i64
486 let b: *u8 = sys_read_file(path, ln)
487 if (b as i64) == 0 {
488 bp_err("BODYPROC-REFUSE cannot read knowledge/body_dimorphism.conf -- the dimorphism rule set is REQUIRED\n" as *u8)
489 sys_exit(7)
490 }
491 let len: i64 = ln[0]
492 let pos: *i64 = sys_mmap(16) as *i64
493 var seen: i64 = 0
494 var i: i64 = 0
495 var bol: i64 = 1
496 while i < len {
497 if bol == 1 {
498 if (b[i] as i64) == 68 {
499 pos[0] = i+1
500 let idx: i64 = bp_rdint(b, pos, len)
501 let val: i64 = bp_rdint(b, pos, len)
502 if idx >= 0 { if idx < BP_NDIM { D[idx] = val; seen = seen + 1 } }
503 i = pos[0]
504 }
505 }
506 if (b[i] as i64) == 10 { bol = 1 } else { bol = 0 }
507 i = i + 1
508 }
509 if seen < BP_NDIM {
510 bp_err("BODYPROC-REFUSE body_dimorphism.conf declares fewer coefficients than the model needs -- refusing to emit a canon with zeroed dimensions\n" as *u8)
511 sys_exit(7)
512 }
513 return seen
514}
515func bp_load_dimorph(D: *i64) -> i64 { return bp_load_dimorph_from(D, "knowledge/body_dimorphism.conf" as *u8) }
516func bp_streq(a: *u8, b2: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b2[i] { return 0 } i = i + 1 } if b2[i] != (0 as u8) { return 0 } return 1 }
517func bp_pnum(v: i64) -> i64 {
518 let t: *u8 = sys_mmap(32)
519 let p: *i64 = sys_mmap(8) as *i64
520 p[0] = 0
521 wint(t, p, v, 32)
522 sys_write(1, t, p[0] - 1)
523 return 0
524}
525// AT7 (aesthetictwin): the skeletal floor under the waist. The pubic ring the torso already emits
526// (30+g at station 470) is the model's bone-anchored pelvic half-breadth; a waist dialled below its
527// own bone cannot emit. DERIVED, not typed: it moves with build through D13 exactly as the emitted
528// pubis does, and the crotch emit call below consumes THIS function so there is exactly one copy of
529// the law and the guard cannot drift from the geometry it guards. Declared imprecision: the true
530// lumbar floor is the vertebral column, which this canon does not yet carry; the pubic ring is the
531// nearest bone-anchored expression and stands in until a lumbar row exists.
532func bp_thoracic_floor(g: i64) -> i64 { return 30 + g }
533// ONE COPY OF THE WAIST AND GIRTH EXPRESSIONS: the emit path in main and the floorcheck verb both call
534// these, so the checker cannot drift from the geometry it checks (the jobclaim shared-classifier law).
535func bp_waist_of(D: *i64, sexf: i64, build: i64) -> i64 { return D[4] - D[5]*sexf/1000 + D[6]*build/1000 }
536func bp_girth_of(D: *i64, build: i64) -> i64 { return build*D[13]/1000 }
537func bp_floorcheck(sexf: i64, build: i64, dp: *u8) -> i64 {
538 let D: *i64 = sys_mmap(BP_NDIM*8) as *i64
539 bp_load_dimorph_from(D, dp)
540 let waist: i64 = bp_waist_of(D, sexf, build)
541 let g: i64 = bp_girth_of(D, build)
542 let flr: i64 = bp_thoracic_floor(g)
543 pw(1, "FLOORCHECK waist=" as *u8); bp_pnum(waist)
544 pw(1, " floor=" as *u8); bp_pnum(flr)
545 if waist < flr { pw(1, " verdict=REFUSE -- a waist below the pelvic-bone floor cannot emit\n" as *u8); return 6 }
546 pw(1, " verdict=OK\n" as *u8)
547 return 0
548}
549func bp_tok(b: *u8, pos: *i64, end: i64, out: *u8, cap: i64) -> i64 {
550 var i: i64 = pos[0]
551 var sk: i64 = 1
552 while sk == 1 {
553 if i >= end { sk = 0 } else {
554 let c: i64 = b[i] as i64
555 if c == 32 { i = i + 1 } else { if c == 9 { i = i + 1 } else { sk = 0 } }
556 }
557 }
558 var n: i64 = 0
559 var go: i64 = 1
560 while go == 1 {
561 if i >= end { go = 0 } else {
562 let c2: i64 = b[i] as i64
563 if c2 == 32 { go = 0 } else { if c2 == 9 { go = 0 } else { if c2 == 10 { go = 0 } else { if c2 == 13 { go = 0 } else {
564 if n < cap - 1 { out[n] = c2 as u8; n = n + 1 }
565 i = i + 1
566 } } } }
567 }
568 }
569 out[n] = 0 as u8
570 pos[0] = i
571 return n
572}
573func bp_find(hay: *u8, hn: i64, needle: *u8) -> i64 {
574 var nl: i64 = 0
575 while needle[nl] != (0 as u8) { nl = nl + 1 }
576 if nl == 0 { return 0 - 1 }
577 var i: i64 = 0
578 while i + nl <= hn {
579 var j: i64 = 0
580 var hit: i64 = 1
581 while j < nl { if hay[i + j] != needle[j] { hit = 0; j = nl } else { j = j + 1 } }
582 if hit == 1 { return i }
583 i = i + 1
584 }
585 return 0 - 1
586}
587func bp_ev_refuse(reason: *u8, m: *u8) -> i64 {
588 pw(1, "AESTHETIC-CANON-REFUSE " as *u8)
589 pw(1, reason)
590 pw(1, " marker=" as *u8)
591 pw(1, m)
592 pw(1, "\n" as *u8)
593 return 4
594}
595// AT1 (aesthetictwin): the evidence-graded aesthetic canon. Every target row carries a class from
596// REPLICATED, CONTESTED or REFUTED plus the key of a source pinned in aesthetictwin.refs; a REFUTED
597// row may be an axis to measure and may never be a steering target; a row whose key does not resolve
598// is refused BY NAME. The refs register is probed at the given path and then at the buildroot twin,
599// because the compare files live in the buildroot knowledge tree while this organ runs from the
600// serving root -- the browser-gate lesson: the path set is unsatisfiable from any single root.
601func bp_evidence_grade(cp: *u8, rp: *u8) -> i64 {
602 let cl: *i64 = sys_mmap(16) as *i64
603 let cb: *u8 = sys_read_file(cp, cl)
604 if (cb as i64) == 0 { return bp_ev_refuse("cannot read canon conf" as *u8, cp) }
605 let cn: i64 = cl[0]
606 let rl: *i64 = sys_mmap(16) as *i64
607 var rb: *u8 = sys_read_file(rp, rl)
608 if (rb as i64) == 0 { rb = sys_read_file("buildroot/knowledge/compare/aesthetictwin.refs" as *u8, rl) }
609 if (rb as i64) == 0 { return bp_ev_refuse("cannot read refs register from the given path or the buildroot twin" as *u8, rp) }
610 let rn: i64 = rl[0]
611 let region: *u8 = sys_mmap(64)
612 let marker: *u8 = sys_mmap(64)
613 let vals: *u8 = sys_mmap(32)
614 let spreads: *u8 = sys_mmap(32)
615 let unit: *u8 = sys_mmap(32)
616 let cls: *u8 = sys_mmap(32)
617 let kind: *u8 = sys_mmap(32)
618 let key: *u8 = sys_mmap(64)
619 let needle: *u8 = sys_mmap(96)
620 let pos: *i64 = sys_mmap(16) as *i64
621 var rows: i64 = 0
622 var nrep: i64 = 0
623 var ncon: i64 = 0
624 var nref: i64 = 0
625 var ntgt: i64 = 0
626 var i: i64 = 0
627 var bol: i64 = 1
628 while i < cn {
629 if bol == 1 { if (cb[i] as i64) == 65 { if i + 1 < cn { if (cb[i+1] as i64) == 32 {
630 pos[0] = i + 1
631 bp_tok(cb, pos, cn, region, 64)
632 bp_tok(cb, pos, cn, marker, 64)
633 bp_tok(cb, pos, cn, vals, 32)
634 bp_tok(cb, pos, cn, spreads, 32)
635 bp_tok(cb, pos, cn, unit, 32)
636 bp_tok(cb, pos, cn, cls, 32)
637 bp_tok(cb, pos, cn, kind, 32)
638 let kl: i64 = bp_tok(cb, pos, cn, key, 64)
639 if kl == 0 { return bp_ev_refuse("short row, eight fields required" as *u8, marker) }
640 var ci: i64 = 0 - 1
641 if bp_streq(cls, "REPLICATED" as *u8) == 1 { ci = 0 }
642 if bp_streq(cls, "CONTESTED" as *u8) == 1 { ci = 1 }
643 if bp_streq(cls, "REFUTED" as *u8) == 1 { ci = 2 }
644 if ci < 0 { return bp_ev_refuse("unknown evidence class" as *u8, marker) }
645 var ki: i64 = 0 - 1
646 if bp_streq(kind, "TARGET" as *u8) == 1 { ki = 0 }
647 if bp_streq(kind, "POPULATION" as *u8) == 1 { ki = 1 }
648 if bp_streq(kind, "AXIS" as *u8) == 1 { ki = 2 }
649 if ki < 0 { return bp_ev_refuse("unknown kind" as *u8, marker) }
650 if ci == 2 { if ki == 0 { return bp_ev_refuse("a REFUTED marker may be measured and may never be a steering target" as *u8, marker) } }
651 needle[0] = 124 as u8
652 var q: i64 = 0
653 while key[q] != (0 as u8) { needle[q+1] = key[q]; q = q + 1 }
654 needle[q+1] = 124 as u8
655 needle[q+2] = 0 as u8
656 if bp_find(rb, rn, needle) < 0 { return bp_ev_refuse("refkey does not resolve in the refs register" as *u8, key) }
657 pw(1, "CANON " as *u8); pw(1, region); pw(1, "/" as *u8); pw(1, marker)
658 pw(1, " class=" as *u8); pw(1, cls)
659 pw(1, " kind=" as *u8); pw(1, kind)
660 pw(1, " value=" as *u8); bp_pnum(satoi(vals))
661 pw(1, " ref=" as *u8); pw(1, key)
662 pw(1, "\n" as *u8)
663 rows = rows + 1
664 if ci == 0 { nrep = nrep + 1 }
665 if ci == 1 { ncon = ncon + 1 }
666 if ci == 2 { nref = nref + 1 }
667 if ki == 0 { ntgt = ntgt + 1 }
668 i = pos[0]
669 } } } }
670 if i < cn { if (cb[i] as i64) == 10 { bol = 1 } else { bol = 0 } }
671 i = i + 1
672 }
673 var part: i64 = 0
674 if nrep + ncon + nref == rows { part = 1 }
675 pw(1, "AESTHETIC-CANON rows=" as *u8); bp_pnum(rows)
676 pw(1, " replicated=" as *u8); bp_pnum(nrep)
677 pw(1, " contested=" as *u8); bp_pnum(ncon)
678 pw(1, " refuted=" as *u8); bp_pnum(nref)
679 pw(1, " targets=" as *u8); bp_pnum(ntgt)
680 pw(1, " partition_ok=" as *u8); bp_pnum(part)
681 pw(1, "\n" as *u8)
682 if rows < 10 { return bp_ev_refuse("fewer than ten graded rows -- an aggregate bound to no denominator is not a canon" as *u8, cp) }
683 if part == 0 { return bp_ev_refuse("partition does not sum" as *u8, cp) }
684 return 0
685}
686func main(argc: i64, argv: *i64) -> i64 {
687 if argc > 1 {
688 if bp_streq(argv[1] as *u8, "evidence" as *u8) == 1 {
689 var cp: *u8 = "knowledge/aesthetic_canon.conf" as *u8
690 var rp: *u8 = "knowledge/compare/aesthetictwin.refs" as *u8
691 if argc > 2 { cp = argv[2] as *u8 }
692 if argc > 3 { rp = argv[3] as *u8 }
693 sys_exit(bp_evidence_grade(cp, rp))
694 }
695 if bp_streq(argv[1] as *u8, "floorcheck" as *u8) == 1 {
696 if argc < 4 { pw(1, "usage: nx_body_proc floorcheck <sexf> <build> [dimorphconf]\n" as *u8); sys_exit(2) }
697 var dp: *u8 = "knowledge/body_dimorphism.conf" as *u8
698 if argc > 4 { dp = argv[4] as *u8 }
699 sys_exit(bp_floorcheck(satoi(argv[2] as *u8), satoi(argv[3] as *u8), dp))
700 }
701 }
702 let outp: *u8 = argv[1] as *u8
703 var sex: i64 = 0; var build: i64 = 300; var musc: i64 = 400; var noise: i64 = 0; var seed: i64 = 1; var sty: i64 = 0
704 var eyecol: i64 = 0 // 0 = auto (from seed); else 1 brown 2 blue 3 green 4 amber
705 if argc > 2 { sex = satoi(argv[2] as *u8) }
706 if argc > 3 { build = satoi(argv[3] as *u8) }
707 if argc > 4 { musc = satoi(argv[4] as *u8) }
708 if argc > 5 { noise = satoi(argv[5] as *u8) }
709 if argc > 6 { seed = satoi(argv[6] as *u8) }
710 if argc > 7 { sty = satoi(argv[7] as *u8) }
711 if argc > 8 { eyecol = satoi(argv[8] as *u8) }
712 // ★argv[9]: the SKELETON this body is built on. Absent -> the const landmarks (bit-identical default).
713 let J: *i64 = sys_mmap(BP_SKJ*8) as *i64
714 var jz: i64 = 0
715 while jz < BP_SKJ { J[jz] = 0; jz = jz+1 }
716 var acromion: i64 = BP_ACROMION
717 var troch: i64 = BP_TROCH
718 var skjoints: i64 = 0
719 if argc > 9 {
720 skjoints = bp_skel_load(argv[9] as *u8, J, K_MAGIC_1750)
721 // ★FAIL LOUD, NOT QUIETLY BACK TO THE DEFAULTS. A skeleton that was asked for and could not be read
722 // must stop the run -- silently emitting the const-landmark body would look like success and would
723 // be a body built on a skeleton that was never consulted.
724 if skjoints <= 0 { pw(1, "{\x22organ\x22:\x22nx_body_proc\x22,\x22error\x22:\x22skeleton unreadable or empty\x22}
725" as *u8); return 3 }
726 if J[5] > 0 { acromion = J[5] }
727 if J[0] > 0 { troch = J[0] }
728 }
729 let st: *i64 = sys_mmap(64) as *i64
730 st[0] = seed*K_MAGIC_2654435761 + K_MAGIC_1013904223
731 if st[0] == 0 { st[0] = 1 }
732 // warm the PRNG so nearby seeds diverge
733 var w: i64 = 0
734 while w < 8 { pr_step(st); w = w+1 }
735
736 // ---- ANATOMICAL DIMORPHISM FUNCTIONS (this is the procedural rule engine's knowledge, not a stored body).
737 // ★AND KNOWLEDGE THAT CANNOT BE REVISED WITHOUT A REBUILD IS POLICY IN CODE. The 21 coefficients that
738 // were written here now live in knowledge/body_dimorphism.conf; what remains is the model SHAPE.
739 // The arithmetic order of every expression is preserved exactly -- the acceptance proof for this move
740 // is a bit-identical emitted canon.
741 // All quantities per-mille of stature. sexf in [0,1000]: 0=male, 1000=female.
742 let D: *i64 = sys_mmap(BP_NDIM*8) as *i64
743 bp_load_dimorph(D)
744 let sexf: i64 = sex
745 // biacromial (shoulder) breadth: male wider. biiliac (hip) breadth: female wider. waist: female narrower.
746 let shoulder: i64 = D[0] - D[1]*sexf/1000
747 let hip: i64 = D[2] + D[3]*sexf/1000
748 let waist: i64 = bp_waist_of(D, sexf, build)
749 let chestRa: i64 = D[7] - D[8]*sexf/1000
750 let bustD: i64 = D[9] + D[10]*sexf/1000
751 let neckRa: i64 = D[11] - D[12]*sexf/1000
752 let g: i64 = bp_girth_of(D, build)
753 let limbMul: i64 = 1000 + D[14]*musc/1000 - D[15]*sexf/1000
754 let reliefMul: i64 = D[16] + D[17]*musc/1000
755 let headScale: i64 = 1000 + D[18]*sty/1000
756 let legScale: i64 = 1000 + D[19]*sty/1000
757 let styLimb: i64 = 1000 - D[20]*sty/1000
758
759 // AT7 (aesthetictwin): refuse an anatomically impossible torso instead of emitting it in silence.
760 let bpflr: i64 = bp_thoracic_floor(g)
761 if waist < bpflr {
762 pw(1, "BODYPROC-REFUSE waist=" as *u8); bp_pnum(waist)
763 pw(1, " below the pelvic-bone floor=" as *u8); bp_pnum(bpflr)
764 pw(1, " -- a waist thinner than its own bone cannot emit (AT7)\n" as *u8)
765 sys_exit(6)
766 }
767 let b: *u8 = sys_mmap(K_MAGIC_65536)
768 let pos: *i64 = sys_mmap(8) as *i64; pos[0] = 0
769 pw(1, "{\x22organ\x22:\x22nx_body_proc\x22,\x22infinigen_style\x22:\x22procedural canon from params+seed, no hand-crafted asset\x22" as *u8)
770
771 // ============ PART 0 TORSO (fully dimorphic) ============
772 emitP(b,pos,st,noise, 0,0,0,0,0)
773 // ★PELVIS re-proportioned by measurement: the crotch (pubic symphysis) sits at ~HALF stature (~470),
774 // NOT 430, and it is NARROW -- below it there are only the two separated legs. The old wide low crotch
775 // (ra 86 @ 430) made a solid block: silhouette 228 @ 429permil vs the oracle's 119 (legs separated).
776 emitR(b,pos,st,noise, 470, 0, 0, bp_thoracic_floor(g), 40+g) // crotch/pubis -- NARROW + high; ONE copy: the AT7 floor IS this bone ring
777 // ★★★TRIED TO ANCHOR THIS ON THE SKELETON AND THE RENDER REFUTED IT -- REVERTED, WITH THE REASON.
778 // The ring is mislabelled: it says "iliac, widest of pelvis" and sits at 496, a height at which no
779 // pelvic landmark lives (iliac crest ~600; widest hip breadth is BITROCHANTERIC at trochanterion 530).
780 // So it was moved to BP_TROCH to match the skeleton's hip joint -- and the pelvis grew a hard horizontal
781 // rim and read as a bucket. Raising the crotch instead was worse. ★THE BENCH COULD NOT SEE ANY OF IT:
782 // front IoU went 283 -> 282 for the broken shape and 285 for the reverted one, a four-point spread
783 // across four bodies that look obviously different to an eye. Metrics BESIDE the pixels, always.
784 // ★THE CAUSE, and it is structural rather than a number: this pelvis is ONE tube that narrows to a
785 // 36-wide crotch at 470. With the widest ring at 496 the cone from hip to crotch is 26 per-mille and
786 // reads as a rounded bottom; at the anatomically correct 530 it is 60 per-mille and reads as a skirt
787 // with a rim. A real pelvis does not narrow between trochanter and crotch -- it stays wide and SPLITS
788 // into two masses. So the surface cannot carry the true landmark until the pelvis becomes two lofted
789 // masses instead of one narrowing tube, which is the next rung, filed rather than faked.
790 // ★LAW: WHEN THE ANATOMICALLY RIGHT NUMBER MAKES THE SURFACE WORSE, THE MODEL IS TOO COARSE TO HOLD IT
791 // -- moving the number anyway just relocates the error into something the ruler cannot see.
792 emitR(b,pos,st,noise, 496, 0, 0-9, hip, 64+g) // surface ring, NOT the landmark
793 emitR(b,pos,st,noise, 545, 0, 0-2, waist, 60+g*6/10) // waist (dimorphic)
794 emitR(b,pos,st,noise, 620, 0, 5, 92+g*6/10, 64+g*6/10) // lower chest
795 emitR(b,pos,st,noise, 700, 0, 9, chestRa+g/2, bustD) // chest (bust depth)
796 emitR(b,pos,st,noise, 752, 0, 4, shoulder-2, 66) // upper chest / armpit level
797 emitR(b,pos,st,noise, acromion, 0, 0, shoulder, 58) // ★ACROMION -- the widest shoulder point
798 // sits HIGH (~810), not at 757; the
799 // biacromial span was measured 60 vs
800 // oracle 147 @ 833permil = too low+thin
801 emitR(b,pos,st,noise, 838, 0, 0-6, shoulder*52/100, 52) // trapezius slope down from acromion
802 emitR(b,pos,st,noise, 864, 0, 0-9, neckRa+6, neckRa+2) // trap base
803 emitR(b,pos,st,noise, 892, 0, 0-9, neckRa, neckRa) // neck
804 emitR(b,pos,st,noise, 920, 0, 0-6, neckRa-4, neckRa-3) // upper neck (into the head)
805
806 // ============ PART 1 ARM (deltoid caps just BELOW the acromion and hangs down) ============
807 emitP(b,pos,st,noise, 1,0,0,0,0)
808 // ⚠REVERTED: generating this tube with UNIFORM stations on a LINEAR path measured 380 -> 329. The typed
809 // table is not merely a list -- it encodes NON-UNIFORM station density (four rings in the top 74 permil
810 // around the shoulder, then four across the remaining 240) and a NON-LINEAR hang path (x runs 56,76,92,
811 // 108 then only 116,130,144,154). A uniform linear generator destroys both. The rule needs a path curve
812 // and a station-distribution parameter before it can eat this table; see the ray-set rule for the shape
813 // that worked. Kept typed until the generator can reproduce it, because shipping the worse body to look
814 // more principled would be the wrong trade.
815 emitR(b,pos,st,noise, 812, 56, 0, 18*limbMul/1000*styLimb/1000, 19*limbMul/1000*styLimb/1000)
816 emitR(b,pos,st,noise, 792, 76, 0, 34*limbMul/1000*styLimb/1000, 35*limbMul/1000*styLimb/1000)
817 emitR(b,pos,st,noise, 770, 92, 0, 45*limbMul/1000*styLimb/1000, 45*limbMul/1000*styLimb/1000)
818 emitR(b,pos,st,noise, 738, 108, 0, 36*limbMul/1000*styLimb/1000, 38*limbMul/1000*styLimb/1000)
819 emitR(b,pos,st,noise, 700, 116, 0, 31*limbMul/1000*styLimb/1000, 33*limbMul/1000*styLimb/1000)
820 emitR(b,pos,st,noise, 634, 130, 0, 26*limbMul/1000*styLimb/1000, 28*limbMul/1000*styLimb/1000)
821 emitR(b,pos,st,noise, 560, 144, 0, 22*limbMul/1000*styLimb/1000, 24*limbMul/1000*styLimb/1000)
822 emitR(b,pos,st,noise, 500, 154, 0, 18*styLimb/1000, 20*styLimb/1000) // wrist
823 emitR(b,pos,st,noise, 478, 160, 0, 20*styLimb/1000, 13*styLimb/1000) // hand root
824 emitR(b,pos,st,noise, 456, 163, 2, 26*styLimb/1000, 9*styLimb/1000) // palm (wide + FLAT: rb<<ra)
825 emitR(b,pos,st,noise, 438, 163, 2, 27*styLimb/1000, 8*styLimb/1000) // knuckle line (widest, flat)
826
827 // ============ PART 2 LEG (girth + longer-leg stylization) ============
828 emitP(b,pos,st,noise, 1,0,0,0,0)
829 emitR(b,pos,st,noise, 500*legScale/1000, 50, 0-6, 38*limbMul/1000, 50*limbMul/1000) // thigh top at the hip
830 // -- x50/ra38 leaves a
831 // perineal GAP so the
832 // legs SEPARATE (groin
833 // was a merged block)
834 emitR(b,pos,st,noise, 452*legScale/1000, 48, 0-6, 46*limbMul/1000, 56*limbMul/1000) // upper thigh (widest)
835 emitR(b,pos,st,noise, 352*legScale/1000, 45, 0-10, 43*limbMul/1000, 49*limbMul/1000)
836 emitR(b,pos,st,noise, 258*legScale/1000, 47, 0-12, 37*limbMul/1000, 43*limbMul/1000)
837 emitR(b,pos,st,noise, 190*legScale/1000, 48, 0-10, 32*limbMul/1000, 40*limbMul/1000)
838 emitR(b,pos,st,noise, 100*legScale/1000, 48, 0-4, 24*limbMul/1000, 32*limbMul/1000)
839 emitR(b,pos,st,noise, 42, 48, 2, 19, 21)
840 emitR(b,pos,st,noise, 25, 48, 2, 18, 20)
841
842 // ============ PART 3 FOOT (forward, placement rot 90) ============
843 emitP(b,pos,st,noise, 1,90,48,40,0-41)
844 emitR(b,pos,st,noise, 0, 0, 30, 14, 10)
845 emitR(b,pos,st,noise, 16, 0, 14, 24, 26)
846 emitR(b,pos,st,noise, 42, 0, 16, 24, 24)
847 emitR(b,pos,st,noise, 71, 0, 24, 26, 16)
848 emitR(b,pos,st,noise, 96, 0, 28, 28, 12)
849 emitR(b,pos,st,noise, 118, 0, 32, 25, 8)
850 // ★TOES BY THE SAME RULE THAT GAVE FINGERS, placed in the FOOT's rotated frame so they run forward off
851 // the toe line. Great toe medial, stout and longest; the rest taper outward -- five calls, no modelling.
852 let tr: i64 = 5 + build/500 // toe radius, tracks the same build knob
853 // ⚠ toes must REPLACE the flat toe-plate, not extend past it -- and BOTH halves of that sentence are
854 // load-bearing. The first attempt ran them to 174 (~20% longer foot) and the height-normalised side
855 // silhouette fell 831 -> 723; the second attempt shortened them to fit INSIDE a plate that was never
856 // deleted, so nx_footcheck measured 27 of each toe's 34 units buried in the tube (protrusion 46 permil
857 // vs the 200 anatomical floor) -- the blunt hoof with pale nubs. So the tube now ENDS at the toe line
858 // (y118, where the toes begin) and the toes alone carry the foot from there to its unchanged tip at
859 // y152. Foot LENGTH is silhouette-critical and nx_footcheck T6 pins it: structure moved, silhouette not.
860 // 5 rays across the toe line, longest at ray 0 (hallux), running FORWARD in the foot's own frame:
861 // the SAME rule as the hand, four parameters different. plane=40 = the tube's own constant sole line
862 // (every tube ring holds zoff+rb = 40), so the toes stand flush on the same ground the heel does.
863 // Emit accessory toe parts after the canonical torso/arm/leg/foot/head prefix.
864
865 // ============ PART 4 HEAD (bigger for anime stylization) ============
866 let hb: i64 = 884 // head base y (fixed to the neck)
867 emitPm(b,pos,st,noise, 0,0,0,0,0, 5) // material 5 = FACE (lips + brows coloured by region)
868 // ★FLAT FACE PLANE: the front z (rz0+rb) is kept nearly CONSTANT (~60-66) from jaw up through brow, so the
869 // face is a near-vertical plane facing forward -- not a receding ovoid. This lights the mouth (it no longer
870 // hides under a jutting chin) and de-eggs the head. Only above the brow and below the jaw does it round off.
871 emitR(b,pos,st,0, 852, 0, 0-6, 30, 34) // skull base buried in the neck (front z 28)
872 emitR(b,pos,st,noise, 876, 0, 8, 40*headScale/1000, 52*headScale/1000) // jaw (front z 60)
873 emitR(b,pos,st,noise, 894, 0, 6, 46*headScale/1000, 60*headScale/1000) // chin + mouth (front z 66)
874 emitR(b,pos,st,noise, hb+32, 0, 4, 50*headScale/1000, 62*headScale/1000) // cheek/nose base (66)
875 emitR(b,pos,st,noise, hb+46, 0, 2, 50*headScale/1000, 62*headScale/1000) // eyes (64)
876 emitR(b,pos,st,noise, hb+61, 0, 0, 48*headScale/1000, 59*headScale/1000) // brow (59)
877 emitR(b,pos,st,noise, hb+79, 0, 0-4, 45*headScale/1000, 54*headScale/1000) // forehead
878 emitR(b,pos,st,noise, hb+96, 0, 0-7, 41*headScale/1000, 47*headScale/1000) // upper skull
879 emitR(b,pos,st,noise, hb+112,0, 0-7, 30*headScale/1000, 34*headScale/1000) // high skull (crown lowered)
880 emitR(b,pos,st,noise, hb+120,0, 0-6, 16*headScale/1000, 18*headScale/1000) // crown (shorter -> less bullet)
881
882 // P ordinals are the existing canon contract: F relief, shape-basis B rows and measured S rows
883 // address the head after torso, arm, leg and foot. Inserting accessory parts before it silently
884 // redirected facial detail into the first toe. Preserve that prefix when composing new parts.
885 emitRaySet(b,pos,st, 1, 15, 118, 34, tr+2, 5, 0, 0-1, 40, 90, 48, 40, 0-41)
886
887 // ============ ★PROCEDURAL HAND: 4 fingers + thumb, PLACED BY A RULE (not modelled one by one) ============
888 // The arm tube ends in a palm at y~430,x~163; digits extend downward from it. mirror=1 gives both hands.
889 // Slimmer for the anime stylization (styLimb), a touch stouter with build.
890 let dr: i64 = 6*styLimb/1000 + build/500 // digit radius
891 // 4 rays across the knuckle line, longest at ray 1 (middle) -- one rule, not four typed fingers.
892 // plane = dr+2 keeps the middle finger byte-where it was (its fz = plane - dr = 2) while the thinner
893 // fingers rise to share its palmar plane -- the same flush rule that fixed the foot's sole.
894 emitRaySet(b,pos,st, 163, 14, 437, 52, dr, 4, 333, 1, dr+2, 0, 0, 0, 0)
895 emitDigit(b,pos,st, 137, 10, 452, 424, dr+1) // thumb (higher, forward, stout)
896
897 // ============ ★EYES: two eyeballs in the sockets (mirror gives both). r a touch bigger for anime. ============
898 // eye colour: an explicit knob (customizer), or auto-varied from the seed so a random character gets a
899 // random-but-deterministic iris colour. This is procedural variation, not a hand-picked asset.
900 var em: i64 = eyecol
901 if em < 1 { em = 1 + (pr_step(st) % 4) }
902 // ★SECOND CANON CORRECTION (knowledge/face_tissue.dat): the eye line belongs at 942, and ours was at 928.
903 // The SAME 14 per-mille deficit the brow had -- the whole feature set was sitting low on the head, which
904 // is why raising the brow alone opened a gap above the eyes. Correcting them together keeps the
905 // brow-to-eye relationship the canon specifies. Two features, one measured offset, found by the port.
906 emitEye(b,pos,st, 942, 19, 55, 11 + 5*sty/1000, em) // canon eye line; wider + forward
907 // ★NOSE as real protruding GEOMETRY (see emitNose): the measured answer to head-scale detail 79.
908 // faceZ 46 sits the part's base just INSIDE the face surface so it merges with the head rather than
909 // floating in front of it (the same burial trick the head's base cap uses at the neck seam).
910 emitNose(b,pos,st, sexf, sty, 46, 5)
911 // ★F1083: the rest of the face as GEOMETRY. Each faceZ buries the part's base just inside the head
912 // surface so it merges rather than floats (the nose's lesson). Ears sit lateral (ex) and behind (ez).
913 // ⚠MATERIAL 0 (plain flesh), NOT 5. A part carrying material 5 inherits the HEAD's region-colouring
914 // rules -- angular colour bands calibrated for the head's geometry and radius. Applied to a small part
915 // those bands land arbitrarily: the first cut of the brow ridge rendered as a SHELF PAINTED WITH BLACK
916 // BARS (it read as goggles). The whole point of this rung is that geometry, not colour, makes a face --
917 // so the feature parts take flesh and let the light do the work.
918 // ⚠⚠NOT SHIPPED -- REVERTED BY EYEBALL AFTER TWO CORRECTION PASSES (F1083, 2026-07-25).
919 // The four rules above are RETAINED, UNUSED (the GX-34 emitLimbTube precedent) because the mechanism is
920 // sound and the placement/shape is not. Measured detail_head rose 288 -> 333 -> 357, and the face got
921 // WORSE both times: the brow read first as a black-barred SHELF (goggles), then as pointed flanges beside
922 // the painted brow band; the chin read as a duckbill below the mouth; the lips never became visible at all.
923 // ★THE FINDING: the detail judge scores LOCAL NORMAL VARIANCE and cannot ask whether that variance is
924 // ANATOMY -- so feature-shaped bumps in the wrong places score exactly like features in the right ones.
925 // This is the GX-13 FBM Goodhart and the GX-58 bell, now reproduced in facial geometry, and it is why a
926 // rising number was not permission to ship. A bad face is worse than an honest egg.
927 // ★WHAT THE NEXT ATTEMPT NEEDS (all three, or it repeats this result):
928 // 1. the painted mat-5 brow/lip colour bands RETIRED first -- geometry and paint fight each other;
929 // 2. a HEAD-REGION judge that scores placement against oracle LANDMARKS, not variance alone;
930 // 3. features authored in the FACE PLANE, not as Y-stacked tubes: a brow ridge and a lip run
931 // HORIZONTALLY, and the part system can only stack rings along Y (rot is about X only), which is the
932 // structural reason these read as vertical blobs. Rotation about Z is the real unlock.
933 // ★F1084: the brow ridge, rebuilt as a HORIZONTAL Z-rotated part and shipped one feature at a time --
934 // the previous rung added four at once and had to revert all four. Its painted colour band is retired
935 // in the emitter in the same change, because paint and geometry cannot both own a feature.
936 emitBrowZ(b,pos,st, sexf, sty, 59*headScale/1000, 0)
937 // ★THE PAIR, from the one rule. Upper lip sits higher and thinner; the lower is fuller and projects a
938 // little more, as it does on a real mouth. Their parent depth is the head's own ring at the mouth line
939 // (60*headScale/1000), so both ride proud of whatever skull the generator produced. Female lips fuller.
940 let lipFull: i64 = 11 + 3*sexf/1000
941 // ★CANON Y (F1128): the table puts the upper lip at 888 and the lower at 880, i.e. 8 apart. Ours were 13
942 // apart (894/881), which is why the mouth read as two separate rolls rather than one closed pair. The
943 // STOMION -- the line between them, which is what actually reads as a mouth -- lands at 882 as the canon
944 // specifies once they are this close.
945 // ⚠⚠THE CANON Y APPLIED LITERALLY CRASHED THE MIDLINE LANE 138 -> 40, AND THE CAUSE IS A LAW ALREADY IN
946 // THIS FILE: A FEATURE PART OCCUPIES A BAND, NOT A POINT. The table's 888/880 are the anatomical
947 // landmarks for the lip CENTRES as infinitesimal points; our lips are TUBES with radius ~9 and ~11, so
948 // centres 8 apart OVERLAP COMPLETELY and merge into one mass -- the groove that reads as a mouth
949 // disappears. The same collision that let the chin swallow the lips, arriving from the opposite
950 // direction. ★A LANDMARK TABLE CANNOT BE APPLIED DIRECTLY TO PARTS WITH EXTENT.
951 // ★THE DERIVED FIX: hold the canon STOMION (882, the line between the lips -- the landmark that actually
952 // reads) as the invariant, and place each lip so its INNER EDGE lands on it. Centre = stomion +/- radius.
953 // The canon is honoured where it matters and the parts stop fighting.
954 // ⚠THE STOMION-DERIVED PLACEMENT WAS ALSO REVERTED, and the numbers alone would have shipped it: mean
955 // 216 -> 222 and detail_head 277 -> 315, both up, headline only -3. But the EYEBALL said the mouth got
956 // WORSE -- the lower lip landed at 871, barely 19 above the chin, and the pair read as one flat mass at
957 // the bottom of the face instead of two lips with a groove. ★SO THE CANON'S STOMION DOES NOT TRANSFER
958 // EITHER: it is measured on the SDF lane's head, and on ours it sits too low. Same lesson as the nose,
959 // now confirmed on a second landmark -- of four values ported from the table, TWO transferred (brow,
960 // eye line: +46 headline) and TWO did not (nose, stomion). ★★A PORTED CANON IS A HYPOTHESIS PER
961 // LANDMARK, AND TWO OUT OF FOUR IS THE MEASURED HIT RATE.
962 emitLipZ(b,pos,st, sty, 60*headScale/1000, 0, 894, lipFull*80/100) // upper (measured-best)
963 emitLipZ(b,pos,st, sty, 60*headScale/1000, 0, 881, lipFull) // lower (measured-best)
964 // ★the chin: the mass a mouth is READ AGAINST. Measuring said our mouth height was already correct and
965 // the absent chin was what made it look low -- so this is the fix for that complaint, not moving the lips.
966 // ⚠⚠NOT SHIPPED after THREE measured attempts -- rule retained, unused (the emitLimbTube precedent).
967 // 868 / mass 13 -> headline 104, mean 211, detail_head 380, but a POINTED witch-chin jutting past the jaw
968 // 876 / mass 9 -> headline 69, mean 162, detail_head 352: cured the jut and SWALLOWED THE LIPS (the
969 // judge caught a collision the eye had missed -- its top edge reached 885, the lip 881)
970 // 866 / mass 10 -> headline 72, mean 201, detail_head 399 (BEST measured), still two STACKED LOBES
971 // ★★★THE ARCHITECTURAL FINDING, and it is why no amount of tuning fixed it: A CHIN IS NOT A PART. It is
972 // the FRONT OF THE JAW -- the visible end of one continuous mandible-plus-soft-tissue mass running ear to
973 // ear. Modelling a prominence of that mass as an isolated horizontal tube can only ever stack a ball
974 // under the mouth, which is exactly what all three attempts rendered. The unit to build is the JAW; the
975 // chin is then a property of its front, the way the glabella dip is a property of the brow ridge rather
976 // than a part of its own. This is the same lesson as the mouth looking low because the chin was absent,
977 // one level deeper: proportion and form are read from continuous structures, not from stacked pieces.
978 // emitChinZ(b,pos,st, sexf, sty, 52*headScale/1000, 0)
979 // emitLips(b,pos,st, sexf, sty, 44, 0)
980 // emitChin(b,pos,st, sexf, sty, 40, 0)
981 // emitBrow(b,pos,st, sexf, sty, 19, 44, 0)
982 // emitEar(b,pos,st, sty, 47, 0-6, 0)
983
984 // ============ RELIEF FEATURES (procedurally modulated by sex / muscularity / stylization) ============
985 // TORSO front/back muscle definition scales with muscularity; the female bust is a large front feature.
986 emitF(b,pos, 0, 706, 62, 62, 34, 78*reliefMul/1000*(1000-sexf)/1000) // pectoral R (male)
987 emitF(b,pos, 0, 706, 62, 118, 34, 78*reliefMul/1000*(1000-sexf)/1000) // pectoral L
988 emitF(b,pos, 0, 698, 40, 62, 30, 60*sexf/1000) // BREAST R (female)
989 emitF(b,pos, 0, 698, 40, 118, 30, 60*sexf/1000) // BREAST L
990 emitF(b,pos, 0, 612, 70, 72, 26, 40*reliefMul/1000) // abdominal R
991 emitF(b,pos, 0, 612, 70, 108, 26, 40*reliefMul/1000) // abdominal L
992 emitF(b,pos, 0, 600, 90, 90, 13, 0-34*reliefMul/1000) // rectus groove
993 emitF(b,pos, 0, 660, 140,270, 15, 0-46) // spinal groove
994 emitF(b,pos, 0, 735, 52, 246, 32, 52*reliefMul/1000) // scapula R
995 emitF(b,pos, 0, 735, 52, 294, 32, 52*reliefMul/1000) // scapula L
996 emitF(b,pos, 0, 470, 54, 250, 40, 86 + 30*sexf/1000) // gluteal R (female fuller)
997 emitF(b,pos, 0, 470, 54, 290, 40, 86 + 30*sexf/1000) // gluteal L
998 emitF(b,pos, 0, 772, 44, 90, 44, 0-30) // supra-clavicular hollow
999 // LEG
1000 emitF(b,pos, 2, 372, 90, 90, 52, 54*reliefMul/1000) // quadriceps
1001 emitF(b,pos, 2, 340, 80, 270, 46, 40*reliefMul/1000) // hamstring
1002 emitF(b,pos, 2, 196, 62, 270, 48, 68*reliefMul/1000) // gastrocnemius
1003 emitF(b,pos, 2, 258, 34, 90, 34, 30) // patella
1004 // ARM
1005 emitF(b,pos, 1, 690, 70, 90, 52, 44*reliefMul/1000) // biceps
1006 emitF(b,pos, 1, 690, 70, 270, 52, 36*reliefMul/1000) // triceps
1007 // HEAD (face) -- stylization can exaggerate the eye sockets (anime); nose softens for female
1008 emitF(b,pos, 4, 921, 22, 90, 17, 150 - 40*sexf/1000) // nose
1009 emitF(b,pos, 4, 908, 14, 90, 12, 120 - 30*sexf/1000) // nose tip
1010 emitF(b,pos, 4, 946, 16, 90, 40, 44) // brow
1011 emitF(b,pos, 4, 896, 18, 90, 26, 70 - 20*sexf/1000) // chin (softer female)
1012 emitF(b,pos, 4, 926, 20, 58, 24, 40) // cheekbone R
1013 emitF(b,pos, 4, 926, 20, 122, 24, 40) // cheekbone L
1014 emitF(b,pos, 4, 929, 14, 66, 16, 0-56 - 30*sty/1000) // eye socket R (holds the eyeball)
1015 emitF(b,pos, 4, 929, 14, 114, 16, 0-56 - 30*sty/1000) // eye socket L
1016 emitF(b,pos, 4, 924, 10, 90, 10, 40) // nasal bridge (between the eyes)
1017 emitF(b,pos, 4, 889, 9, 90, 20, 14) // lips: gentle protrusion, colour does the rest
1018 emitF(b,pos, 4, 906, 8, 78, 8, 0-24) // nostril R
1019 emitF(b,pos, 4, 906, 8, 102, 8, 0-24) // nostril L
1020 emitF(b,pos, 4, 963, 40, 270, 60, 46) // occiput
1021
1022 // ============ ★PROCEDURAL FINE MUSCLE STRUCTURE ============
1023 // GENERATED BY RULES (loops emitting grids/fans), not hand-placed features. This is the surface-detail
1024 // frontier the honest DETAIL judge exposed (broad relief alone left the surface a smooth mannequin ~300).
1025 // It only appears above ~35% muscularity (real definition needs low body-fat + muscle), and its amplitude
1026 // scales with it -- so a soft body stays smooth and a lean muscular one gets a six-pack.
1027 let def: i64 = musc - 350
1028 if def > 0 {
1029 let da: i64 = def*1000/650 // 0..1000 as musc 350->1000
1030 // RECTUS ABDOMINIS "six-pack": a GRID -- two columns (L/R of the linea alba) x three rows of bulges,
1031 // with a vertical linea groove and horizontal tendinous-intersection grooves generated between them.
1032 var r6: i64 = 0
1033 while r6 < 3 {
1034 let y6: i64 = 558 + r6*36
1035 emitF(b,pos, 0, y6, 18, 79, 14, 66*da/1000) // rectus bulge R (column right)
1036 emitF(b,pos, 0, y6, 18, 101, 14, 66*da/1000) // rectus bulge L (column left)
1037 r6 = r6+1
1038 }
1039 emitF(b,pos, 0, 600, 130, 90, 7, 0-64*da/1000) // linea alba (sharp vertical groove)
1040 var h6: i64 = 0
1041 while h6 < 2 { // tendinous intersections (rows)
1042 emitF(b,pos, 0, 576 + h6*36, 7, 90, 32, 0-56*da/1000)
1043 h6 = h6+1
1044 }
1045 emitF(b,pos, 0, 676, 12, 62, 32, 0-58*da/1000) // pectoral lower border groove R
1046 emitF(b,pos, 0, 676, 12, 118, 32, 0-58*da/1000) // pectoral lower border groove L
1047 // SERRATUS ANTERIOR: a fan of finger-like slips on the lower-lateral ribcage -- generated as a series.
1048 var sv: i64 = 0
1049 while sv < 3 {
1050 let ys: i64 = 636 + sv*18
1051 emitF(b,pos, 0, ys, 14, 51, 14, 46*da/1000) // serratus slip R
1052 emitF(b,pos, 0, ys, 14, 129, 14, 46*da/1000) // serratus slip L
1053 sv = sv+1
1054 }
1055 emitF(b,pos, 0, 752, 22, 66, 17, 50*da/1000) // anterior deltoid head R
1056 emitF(b,pos, 0, 752, 22, 114, 17, 50*da/1000) // anterior deltoid head L
1057 // BACK definition: erector spinae columns either side of the spinal groove; trapezius wedge; lats.
1058 emitF(b,pos, 0, 600, 120, 258, 14, 40*da/1000) // erector R
1059 emitF(b,pos, 0, 600, 120, 282, 14, 40*da/1000) // erector L
1060 emitF(b,pos, 0, 700, 60, 270, 40, 34*da/1000) // trapezius
1061 emitF(b,pos, 0, 660, 70, 230, 20, 30*da/1000) // latissimus R
1062 emitF(b,pos, 0, 660, 70, 310, 20, 30*da/1000) // latissimus L
1063 // LIMB definition: biceps peak + brachial groove (arm); quadriceps heads + hamstring split (leg); calf heads.
1064 emitF(b,pos, 1, 690, 46, 90, 30, 44*da/1000) // biceps peak (sharper than base)
1065 emitF(b,pos, 1, 690, 46, 40, 16, 0-30*da/1000) // brachial groove (biceps/triceps sep)
1066 emitF(b,pos, 1, 690, 46, 140, 16, 0-30*da/1000)
1067 emitF(b,pos, 2, 372, 70, 70, 30, 40*da/1000) // vastus lateralis R-of-front
1068 emitF(b,pos, 2, 372, 70, 110, 30, 40*da/1000) // vastus medialis L-of-front
1069 emitF(b,pos, 2, 340, 60, 270, 20, 0-30*da/1000) // hamstring split groove
1070 emitF(b,pos, 2, 196, 52, 250, 22, 44*da/1000) // gastrocnemius medial head
1071 emitF(b,pos, 2, 196, 52, 290, 22, 44*da/1000) // gastrocnemius lateral head
1072 // FRONT-FACING limb definition (raises the front-view detail, where arm/leg fronts were still smooth)
1073 emitF(b,pos, 2, 372, 58, 90, 22, 42*da/1000) // rectus femoris (center front thigh)
1074 emitF(b,pos, 2, 300, 52, 108, 20, 34*da/1000) // vastus medialis teardrop (inner)
1075 emitF(b,pos, 2, 372, 54, 132, 22, 0-28*da/1000) // IT-band groove (lateral thigh)
1076 emitF(b,pos, 2, 150, 54, 86, 22, 32*da/1000) // tibialis anterior (shin)
1077 emitF(b,pos, 2, 258, 30, 90, 20, 36*da/1000) // patella (sharper)
1078 emitF(b,pos, 1, 560, 52, 88, 26, 36*da/1000) // forearm flexor bulge (front)
1079 emitF(b,pos, 1, 560, 52, 58, 18, 0-24*da/1000) // brachioradialis groove
1080 emitF(b,pos, 1, 500, 40, 92, 22, 0-22*da/1000) // wrist taper groove
1081 // FRONT-FACING chest: sternum groove + clavicle line, so the upper chest isn't a smooth plate
1082 emitF(b,pos, 0, 720, 70, 90, 8, 0-30*da/1000) // sternum midline groove
1083 emitF(b,pos, 0, 748, 12, 74, 22, 30*da/1000) // clavicle R
1084 emitF(b,pos, 0, 748, 12, 106, 22, 30*da/1000) // clavicle L
1085 }
1086
1087 // ---- write the canon file ----
1088 let fd: i64 = sys_openat_wr(outp, 0x1a4) // 0644
1089 if fd < 0 { pw(1, ",\x22error\x22:\x22cannot open out\x22}\n" as *u8); return 3 }
1090 sys_write(fd, b, pos[0])
1091 sys_close(fd)
1092 let nb: *u8 = sys_mmap(64); let np2: *i64 = sys_mmap(8) as *i64; np2[0]=0
1093 pw(1, ",\x22bytes\x22:" as *u8); wint(nb,np2,pos[0],32); sys_write(1, nb, np2[0]-1)
1094 np2[0]=0; pw(1, ",\x22sex\x22:" as *u8); wint(nb,np2,sex,32); sys_write(1, nb, np2[0]-1)
1095 np2[0]=0; pw(1, ",\x22build\x22:" as *u8); wint(nb,np2,build,32); sys_write(1, nb, np2[0]-1)
1096 np2[0]=0; pw(1, ",\x22musc\x22:" as *u8); wint(nb,np2,musc,32); sys_write(1, nb, np2[0]-1)
1097 np2[0]=0; pw(1, ",\x22seed\x22:" as *u8); wint(nb,np2,seed,32); sys_write(1, nb, np2[0]-1)
1098 np2[0]=0; pw(1, ",\x22stylize\x22:" as *u8); wint(nb,np2,sty,32); sys_write(1, nb, np2[0]-1)
1099 pw(1, "}\n" as *u8)
1100 return 0
1101}