code wiki / (root) / nx_body_profile_winding_candidate_t366.nx

nx_body_profile_winding_candidate_t366.nx source

↩ module page · 1333 lines · 84183 B

1// nx_body_gen.nx -- ★THE PRODUCT: a SOVEREIGN PROCEDURAL human body, generated from the first byte up. 2// No scanned mesh, no third-party asset: the body is EMITTED from anthropometric parameters (fractions of 3// stature, per-mille). BodyParts3D is the ORACLE we measure against -- never the product. Competitor 4// platforms are benchmarked on CAPABILITY only; none of their assets are used. 5// 6// v2 (GX-23): the body is now built from CONTINUOUS RING PROFILES, not disjoint cylinders. Each part 7// (torso, arm, leg) is ONE tube threaded through control rings and sub-sampled, so there are no seams 8// where segments used to butt together -- that was the largest silhouette defect vs the oracle. Hands and 9// feet are ring extensions of the arm/leg tubes, so they attach continuously. Normals include the taper 10// slope, so shading follows the true surface rather than a stack of cylinders. 11// nx_body_gen <out.nxmesh> <height> [radial] [sub] [relief] [canonpath] [fat] [prof] [?] [hf] 12// ★★THE CANON PATH IS argv[6] AND IT WAS UNDOCUMENTED (seq1377). It is the single most important input -- 13// this emitter carries NO geometry literals, so WHICH canon you hand it is the whole product -- and its 14// absence from this line is why the nx_skullgen -> mesh chain LOOKED non-composable and cost a 15// measurement cycle. Defaults: relief/RLF argv[5], canon argv[6] (knowledge/canon_male.dat), fat argv[7], 16// prof argv[8], hf argv[10]. ★A usage line that omits a positional does not merely under-document it -- 17// it makes every LATER positional unreachable, because you cannot skip one. 18// license_tier: ORIGINAL expect_exit: 0 19import "nx_syscalls.nx" 20import "nx_profile_contract.nx" 21import "nx_body_skin_cut.nx" 22import "nx_body_rest_registration.nx" 23import "nx_fio.nx" 24import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 25const BG_SMOOTHSTEP_3_PERMIL: i64 = 3000 26const BG_PERMIL_CUBE: i64 = 1000000000 27const BG_PERMIL_SQ: i64 = 1000000 28const BG_CATMULL_DEN: i64 = 2000000 29const BG_F32_MANT_SCALE: i64 = 8388608 30const BG_F32_MANT_MASK: i64 = 8388607 31const BG_DEFAULT_STATURE_MM: i64 = 1750 32 33const BG_Q14: i64 = 16384 34// Bhaskara I's sine approximation (7th century): sin(x deg) ~= 4x(180-x) / (40500 - x(180-x)). 35// 40500 is that method's published constant, not a tuning knob -- the old name BG_MAGIC_40500 hid 36// the fact that this line implements a named algorithm at all. 37const BG_BHASKARA_K: i64 = 40500 38// raised for the face-parts program (F1083): 21 parts at radial 52/sub 8 reached 393,432 of the old 400k, 39// i.e. 6.5k from SILENT truncation of the skin head. Headroom + a truncated flag are now reported every run. 40// ★RAISED AGAIN 2026-08-10, measured binding LIVE: radial 96/sub 24 on even the 5-part canon truncated at 41// 599,998/600,000 (truncated:1) -- 600k sat at MetaHuman-ENTRY density while the ladder (ZBrush-class 42// sculpt density, 32 teeth, 200 eyelashes) needs millions. 2^23 tris = 1.41GB emit buffer of ADDRESS SPACE 43// (lazily mmap'd, resident only what is touched) + ~700MB NXMSH2 write buffer at FULL cap; the renderer 44// (nx_anat_sov) streams ntris from the header with NO cap of its own. Still a loud threshold, and the 45// manifest now reports tris_offered (demand) so a capped emit can never again pass as a complete one. 46const BG_MAXTRI: i64 = 8388608 47// ★★CAPS RAISED TO WHAT THE HARDWARE SUPPORTS, NOT TO A NUMBER SOMEBODY ONCE TYPED. 256 rings and 48 parts 48// were never measured against anything -- and the anatomy ladder ahead (32 teeth, 20 nails, 200 eyelashes, 49// each its own part with its own rings) walks straight through both. The arrays are lazily mmap'd, so a 50// larger cap costs address space rather than resident memory: 8192 rings across 5 arrays is 320KB of 51// reservation. ★The cap is now a REFUSAL THRESHOLD, not a silent truncation point -- which is only safe 52// because the guards above landed in the same change. Raising a bound without a check would have converted 53// a near-miss into a much larger silent overwrite. 54const BG_MAXRING: i64 = 8192 55const BG_MAXFEAT: i64 = 4096 56// ★PART CAP, named + guarded (was a bare 16 in six mmap sizes with NO bound check on the parser's write: 57// a canon with a 17th P row wrote past a 128-byte allocation -- an unguarded array write driven by an 58// EXTERNAL file, which is the classic overflow class and silently "worked" only because mmap rounds to a 59// page. The canon is external input to this emitter, so it is a boundary and must be defensive. Raised to 60// 48 because the face-geometry program needs real feature PARTS (nose, lips, ears) and the canon already 61// carried exactly 16. 62const BG_MAXPART: i64 = 2048 63// surface points are kept at BG_PSUB sub-units so the central-difference tangents keep their precision; 64// integer rounding of a raw-unit point would be ~3% of a one-step tangent and swamp the relief signal 65const BG_PSUB: i64 = 512 66const BG_MAXRS: i64 = 256 67// components are halved down to this before squaring -- keeps enx*enx+... far inside i64 68const BG_NCAP: i64 = 1000000 69// ★LAYER STACK -- the body is built from the first cell up: a bone core, a muscle envelope on the bone, and 70// the skin as the outer envelope of muscle+fat. Each is a real NXMSH2 layer, so it renders/peels separately 71// and the skin's SHAPE EMERGES from the layers beneath instead of being painted on a shell. 72// ★MEASURED SECTION PROFILES (GX-31). Every ring was an ELLIPSE modulated by relief bumps; a real human 73// cross-section is not an ellipse (flat back, scapular bulges, sternal hollow, iliac flare). nx_profile_fit 74// measures those sections off the oracle and emits a DIMENSIONLESS per-angle ratio (1000 = on the ellipse); 75// this emitter applies the ratio to whatever size the rule engine asked for, so the prior is shape-only and 76// the body stays procedural. Same idea as Infinigen taking creature profiles from real references. 77// the prior's angular resolution is carried IN the data file ('N <bins>'), never duplicated as a const in 78// two organs -- a silent bin-count mismatch would misread every row as a rotated body. 79const BG_NBMAX: i64 = 96 80// ★512 -> 2048 (2026-07-30, ws=neuro). A profile carrying every canon part needs parts x stations rows: 81// the skull canon alone is 7 x 167 = 1169, so 512 silently dropped 47 percent of a 973-row file and the 82// emitter reported prof_rows:512 as though that WERE the data. sR is BG_MAXPROF*BG_NBMAX*8 = 1.5MB at 2048. 83const BG_MAXPROF: i64 = 2048 84const BG_PROFCLAMP: i64 = 300 // a single bad measured row can never deform the body more than +/-30% 85// ★per-mille-of-stature band at each part's data extremes over which the prior fades to neutral, so a 86// per-part modulation can never pull two parts apart at the boundary the canon built them to share. 87const BG_PROFEDGE: i64 = 45 88const BG_NLAYER: i64 = 3 89const BG_BONEF: i64 = 400 // bone core radius = 40% of the skin radius (the skeletal armature) 90const BG_MUSCF: i64 = 820 // muscle envelope = 82% of the skin radius (muscle bellies fill toward skin) 91 92// ★★★ONE PLACEMENT ROTATION, USED BY ALL FOUR TRANSFORM SITES. The Z->X->Y chain was written out FOUR 93// TIMES -- position, normal, cap normal, cap centre -- as twenty-four hand-copied lines. That is the 94// duplication class this programme keeps finding the hard way: when rotY was added, the same six lines had 95// to be inserted four times and any one of them could have been missed or transposed silently, because a 96// body with three correct sites and one wrong one still renders. 97// ★A TRANSFORM APPLIED IN FOUR PLACES IS ONE RULE WITH THREE CHANCES TO DRIFT. 98// Extracting it also makes the chain TESTABLE: bg_rot3 is a pure function of nine integers, so the gate can 99// assert the composition order and the mirror convention directly instead of inferring them from a mesh. 100// ORDER IS LOAD-BEARING: rotZ turns the cross-section in its own plane, rotX pitches the part, and rotY -- 101// applied LAST -- is a true world AZIMUTH. Applied first it would merely spin the cross-section. 102func bg_rot3(x: i64, y: i64, z: i64, pzc: i64, pzs: i64, prc: i64, prs: i64, pyc: i64, pys: i64, o: *i64) -> i64 { 103 let zx: i64 = (x*pzc - y*pzs)/BG_Q14 104 let zy: i64 = (x*pzs + y*pzc)/BG_Q14 105 let ry: i64 = (zy*prc - z*prs)/BG_Q14 106 let rz: i64 = (zy*prs + z*prc)/BG_Q14 107 o[2] = (rz*pyc - zx*pys)/BG_Q14 108 o[0] = (rz*pys + zx*pyc)/BG_Q14 109 o[1] = ry 110 return 0 111} 112func bg_hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 113// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 114// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 115// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 116// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 117func bg_pn(v: i64) -> i64 { nxi_out(v); return 0 } 118func bg_satoi(s: *u8) -> i64 { var i: i64=0; var n: i64=0 119 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 } 120func bg_sin_fill(t: *i64) -> i64 { 121 var d: i64=0 122 while d<180 { let P: i64=d*(180-d); t[d]=BG_Q14*4*P/(BG_BHASKARA_K-P); t[d+180]=0-t[d]; d=d+1 } 123 return 0 124} 125func bg_wrap(d: i64) -> i64 { var x: i64=d%360; if x<0 { x=x+360 } return x } 126// shortest angular separation, 0..180 127func bg_angsep(a: i64, b: i64) -> i64 { 128 var d: i64 = bg_wrap(a) - bg_wrap(b) 129 if d < 0 { d = 0-d } 130 if d > 180 { d = 360-d } 131 return d 132} 133// ★ANATOMICAL SURFACE RELIEF. Until now every ring was a plain ellipse, so the body had correct OUTLINE but a 134// featureless surface -- which is exactly what the normal-field judge was penalising (it became the binding 135// constraint at 749 once the silhouettes were fixed). Real anatomy modulates the radius with ANGLE as well as 136// height: pectorals and abdominal bulges at the front, the spinal groove and scapulae at the back, glutes, 137// quadriceps, calves. Each feature is a (part, height, angle, extent, amplitude) tuple with quadratic falloff, 138// summed -- data, not hand-carved geometry. theta: 0=+X right, 90=+Z front, 180=-X left, 270=-Z back. 139func bg_relief(part: i64, ymil: i64, th: i64, fP: *i64, fY: *i64, fYw: *i64, fT: *i64, fTw: *i64, fA: *i64, nf: i64) -> i64 { 140 var s: i64 = 0 141 var k: i64 = 0 142 while k < nf { 143 if fP[k] == part { 144 var dy: i64 = ymil - fY[k] 145 if dy < 0 { dy = 0-dy } 146 if dy < fYw[k] { 147 let dt: i64 = bg_angsep(th, fT[k]) 148 if dt < fTw[k] { 149 let wy: i64 = 1000 - dy*1000/fYw[k] 150 let wt: i64 = 1000 - dt*1000/fTw[k] 151 s = s + fA[k]*wy/1000*wt/1000 152 } 153 } 154 } 155 k = k + 1 156 } 157 return s 158} 159// ANALYTIC SHAPE BASIS (GX-41). displacement = sum of beta_i * basis_i(coord): the body as a mean shape 160// plus weighted deformation functions, the genome being the coefficients. Two properties earned it this slot: 161// (1) REGISTRATION-FREE BY CONSTRUCTION -- the basis is evaluated in OUR body's own parameter space, so the 162// misregistration that killed measured detail transfer (residual sampled at the oracle's coordinates) 163// cannot occur here; 164// (2) it creates surface that faces UP and DOWN. A smooth vertical body has ny approx 0 everywhere, which is 165// why the environment light had nothing to differentiate and why the detail judge sees no busyness. What 166// matters is the GRADIENT dr/dy, not the amplitude -- so the bases vary in HEIGHT, not just in angle, 167// unlike the relief-feature table that measured as worth 1 permil. 168// Anatomical, not noise: intercostal banding over the ribcage, the clavicle trough, the inframammary fold. 169const BG_WK_RAMP: i64 = 1 170const BG_WK_TRI: i64 = 2 171const BG_WK_RIDGE: i64 = 3 172const BG_YK_FLAT: i64 = 1 173const BG_YK_WAVE_RIB: i64 = 2 174const BG_YK_WAVE_SPAN: i64 = 3 175const BG_HALFTURN_DEG: i64 = 180 176// ★THE ROW TAGS AND THE LINE TERMINATOR, NAMED. The walkers below tested `== 66` and `== 10` -- ASCII 177// 'B' and newline written as bare integers. Those two values ARE the grammar of the canon file, and a 178// reader cannot tell a row tag from a threshold at a glance when both are just numbers. 179const BG_ROW_BASIS: i64 = 66 // 'B' -- a shape-basis feature row 180const BG_ROW_LAYER: i64 = 76 // 'L' -- a layer palette row 181const BG_LF: i64 = 10 // end of line 182// walks the basis file for 'B' rows. Same independent-walker shape as bg_parse_open, for the same reason: 183// bg_parse_canon already carries 24 arguments and widening it is the wrong direction. 184func bg_parse_basis(b: *u8, len: i64, kP: *i64, kYlo: *i64, kYhi: *i64, kTh: *i64, kWk: *i64, kW0: *i64, kW1: *i64, kW2: *i64, kAmp: *i64, kYk: *i64, kP0: *i64, kP1: *i64, kP2: *i64, cnt: *i64) -> i64 { 185 let pos: *i64 = sys_mmap(16) as *i64 186 var n: i64 = 0 187 var i: i64 = 0 188 var bol: i64 = 1 189 while i < len { 190 if bol == 1 { 191 if (b[i] as i64) == BG_ROW_BASIS { 192 if n < BG_MAXFEAT { 193 pos[0] = i+1 194 kP[n]=bg_rdint(b,pos,len); kYlo[n]=bg_rdint(b,pos,len); kYhi[n]=bg_rdint(b,pos,len) 195 kTh[n]=bg_rdint(b,pos,len); kWk[n]=bg_rdint(b,pos,len) 196 kW0[n]=bg_rdint(b,pos,len); kW1[n]=bg_rdint(b,pos,len); kW2[n]=bg_rdint(b,pos,len) 197 kAmp[n]=bg_rdint(b,pos,len); kYk[n]=bg_rdint(b,pos,len) 198 kP0[n]=bg_rdint(b,pos,len); kP1[n]=bg_rdint(b,pos,len); kP2[n]=bg_rdint(b,pos,len) 199 i = pos[0] 200 n = n + 1 201 } 202 } 203 } 204 if (b[i] as i64) == BG_LF { bol = 1 } else { bol = 0 } 205 i = i + 1 206 } 207 cnt[0] = n 208 return n 209} 210// ★THE LAYER PALETTE IS DATA TOO. The three layer colours were an IF-LADDER inside the emit loop -- 211// skin 880/700/620, muscle 760/286/262, bone 928/918/872 -- while the radius scales sitting on the SAME 212// lines (BG_MUSCF, BG_BONEF) were already named consts. Half a table named and half raw is the signature 213// of an oversight, not a decision. And as an if-ladder a FOURTH layer could not be expressed at all 214// without editing the emit loop -- the same defect anat_sov's 5-row anchor ladder had. 215// Rows are 'L <layer> <r> <g> <b>' in the SAME canon file, so there is still one file, one read, one 216// walker shape. A row naming a layer outside 0..BG_NLAYER-1 is skipped rather than writing past the array. 217func bg_parse_layers(b: *u8, len: i64, lR: *i64, lG: *i64, lB: *i64, cnt: *i64) -> i64 { 218 let pos: *i64 = sys_mmap(16) as *i64 219 var n: i64 = 0 220 var i: i64 = 0 221 var bol: i64 = 1 222 while i < len { 223 if bol == 1 { 224 if (b[i] as i64) == BG_ROW_LAYER { 225 pos[0] = i+1 226 let ly: i64 = bg_rdint(b,pos,len) 227 if ly >= 0 { if ly < BG_NLAYER { 228 lR[ly]=bg_rdint(b,pos,len); lG[ly]=bg_rdint(b,pos,len); lB[ly]=bg_rdint(b,pos,len) 229 n = n + 1 230 } } 231 i = pos[0] 232 } 233 } 234 if (b[i] as i64) == BG_LF { bol = 1 } else { bol = 0 } 235 i = i + 1 236 } 237 cnt[0] = n 238 return n 239} 240// ★THE SHAPE-BASIS CANON IS DATA (2026-08-14). Every band edge, angular window and amplitude below used to 241// be a literal here: the anatomy this body claims to have, written into the emitter where it could not be 242// revised or varied without a rebuild. nx_magic at threshold 2 surfaced them; at its DEFAULT threshold they 243// all sit under the bar and the organ reports clean. They now live in knowledge/body_shape_basis.conf. 244// ★★THE ARITHMETIC ORDER OF EACH SHAPE IS PRESERVED EXACTLY, because integer division is not associative: 245// amp*(z*1000/half)/1000 and amp*z*1000/half/1000 are DIFFERENT expressions. The acceptance proof is a 246// BIT-IDENTICAL mesh against the banked pre-refactor artifact, so a shape rewritten "equivalently" fails it. 247func bg_shape_basis(part: i64, ymil: i64, th: i64, sinT: *i64, kP: *i64, kYlo: *i64, kYhi: *i64, kTh: *i64, kWk: *i64, kW0: *i64, kW1: *i64, kW2: *i64, kAmp: *i64, kYk: *i64, kP0: *i64, kP1: *i64, kP2: *i64, nk: i64) -> i64 { 248 var s: i64 = 0 249 var k: i64 = 0 250 while k < nk { 251 var hit: i64 = 0 252 if part == kP[k] { if ymil > kYlo[k] { if ymil < kYhi[k] { hit = 1 } } } 253 if hit == 1 { 254 let w: i64 = bg_angsep(th, kTh[k]) 255 let amp: i64 = kAmp[k] 256 if kWk[k] == BG_WK_RAMP { if kYk[k] == BG_YK_FLAT { 257 if w < kW1[k] { s = s + amp*(1000 - w*1000/kW1[k])/1000 } 258 } } 259 if kWk[k] == BG_WK_RAMP { if kYk[k] == BG_YK_WAVE_SPAN { 260 if w < kW1[k] { 261 let ph2: i64 = (ymil-kYlo[k])*1000/(kYhi[k]-kYlo[k]) 262 s = s + amp*sinT[bg_wrap(ph2*BG_HALFTURN_DEG/1000)]/BG_Q14*(1000 - w*1000/kW1[k])/1000 263 } 264 } } 265 if kWk[k] == BG_WK_TRI { if kYk[k] == BG_YK_FLAT { 266 if w > kW0[k] { if w < kW0[k]+2*kW1[k] { 267 var z: i64 = w - kW0[k] 268 if z > kW1[k] { z = 2*kW1[k] - z } 269 if z > 0 { s = s + amp*z*1000/kW1[k]/1000 } 270 } } 271 } } 272 if kWk[k] == BG_WK_RIDGE { if kYk[k] == BG_YK_WAVE_RIB { 273 let dy: i64 = ymil - kYlo[k] 274 let ph: i64 = (dy*kP0[k] - dy*dy/kP1[k] + w*kP2[k]) % 360 275 var aw: i64 = 0 276 if w > kW0[k] { if w < kW1[k] { aw = (w-kW0[k])*1000/(kW1[k]-kW0[k]) } } 277 if w >= kW1[k] { if w < kW2[k] { aw = (kW2[k]-w)*1000/(kW2[k]-kW1[k]) } } 278 if aw > 0 { s = s + amp*sinT[bg_wrap(ph)]/BG_Q14*aw/1000 } 279 } } 280 } 281 k = k + 1 282 } 283 return s 284} 285// ⚠⚠DEAD CODE -- NOTHING CALLS THIS. 2026-08-14: the shape-basis canon moved OUT of the emitter and into 286// knowledge/body_shape_basis.conf, and the live implementation is bg_shape_basis() above, which is table 287// driven. This copy is kept only because a sibling seat was mid-edit in it when the move landed (the 288// zyg_lo/zyg_span/szy_half hoists below are theirs, and they are hoists to NAMED LOCALS -- which satisfies 289// a magic-number ratchet while leaving the policy in code; the numbers are now DATA one function up). 290// ★IF YOU ARE EDITING THIS FUNCTION, YOUR CHANGE HAS NO EFFECT ON ANY EMITTED MESH. Edit the .conf. 291// Delete this whole function once the sibling's lane has landed; the mesh is bit-identical without it 292// (proven: sha f318ade9 both sides, 3,784,792 B). 293// bg_shape_basis_retired REMOVED 2026-08-14: 92 lines, ZERO call sites (grep coverage_complete=1, 294// corpus_complete=1 over 8,769 files -- the only match was its own definition). Its 8 anatomical 295// features now live as B rows in knowledge/body_shape_basis.conf, read by the live bg_shape_basis, 296// which derives every span from the data ((kW1[k]-kW0[k])) instead of carrying a typed copy. 297// ★A RETIRED FUNCTION IS A MEASUREMENT LIABILITY, NOT INERT WEIGHT. nx_magic scans SOURCE, so this 298// fossil's ~30 hardcoded per-mille constants kept being counted as live defects in this organ: the 299// headline "510 magic-number sites in nx_body_gen" was mostly THIS, and a reader diagnosing the organ 300// (2026-08-14) fixed the retired copy believing it was the shipping one. Deleting the body is what 301// makes the count honest -- a _retired SUFFIX IS NOT A GUARD, because a name is read only after you 302// have already decided what the file says. Only the call-site query is a control. 303func bg_isqrt(v: i64) -> i64 { if v<=0 {return 0} var x: i64=v; var y: i64=(x+1)/2; while y<x { x=y; y=(x+v/x)/2 } return x } 304// ★CATMULL-ROM spline through control values p1..p2 (neighbours p0,p3), t in [0,1000]; returns value*1000. 305// THE Infinigen-gap fix: linear interpolation between sparse rings makes every part read as stacked cones with 306// a crease at each ring -- a cubic through the SAME rings gives C1-smooth organic curvature everywhere. 307// Integer-exact at the ends: t=0 -> p1*1000, t=1000 -> p2*1000. 308func bg_cmr(p0: i64, p1: i64, p2: i64, p3: i64, t: i64) -> i64 { 309 let a: i64 = 2*p1 310 let b: i64 = p2 - p0 311 let c: i64 = 2*p0 - 5*p1 + 4*p2 - p3 312 let d: i64 = 3*p1 - p0 + p3 - 3*p2 313 return (a*BG_PERMIL_CUBE + b*t*BG_PERMIL_SQ + c*t*t*1000 + d*t*t*t)/BG_CATMULL_DEN 314} 315// integer IEEE-754 float32 encoder (NishiLang has no float type -- we pack the bits ourselves) 316func bg_f32(v: i64, scale: i64) -> i64 { 317 if v == 0 { return 0 } 318 var neg: i64 = 0 319 var m: i64 = v 320 if m < 0 { neg = 1; m = 0-m } 321 var e: i64 = 0 322 var num: i64 = m 323 var den: i64 = scale 324 while num >= den*2 { den = den*2; e = e+1 } 325 while num < den { num = num*2; e = e-1 } 326 let frac: i64 = ((num - den)*BG_F32_MANT_SCALE)/den 327 var bits: i64 = ((e+127) << 23) | (frac & BG_F32_MANT_MASK) 328 if neg == 1 { bits = bits | (1<<31) } 329 return bits 330} 331func bg_wr32(b: *u8, o: i64, v: i64) -> i64 { 332 b[o]=(v&255) as u8; b[o+1]=((v>>8)&255) as u8; b[o+2]=((v>>16)&255) as u8; b[o+3]=((v>>24)&255) as u8 333 return 0 334} 335 336// ---- CANON PARSER: the emitter reads its geometry from DATA, it carries none. ---- 337// signed-integer token reader: skips leading non-digit/non-minus within [pos,end), reads, advances pos. 338func bg_rdint(b: *u8, pos: *i64, end: i64) -> i64 { 339 var i: i64 = pos[0] 340 var go: i64 = 1 341 while go == 1 { 342 if i >= end { go = 0 } else { 343 let c: i64 = b[i] as i64 344 if c == 45 { go = 0 } else { 345 if c >= 48 { if c <= 57 { go = 0 } else { i = i+1 } } else { i = i+1 } 346 } 347 } 348 } 349 var sg: i64 = 1 350 if i < end { if (b[i] as i64) == 45 { sg = 0-1; i = i+1 } } 351 var v: i64 = 0 352 var g2: i64 = 1 353 while g2 == 1 { 354 if i >= end { g2 = 0 } else { 355 let c: i64 = b[i] as i64 356 if c >= 48 { if c <= 57 { v = v*10 + (c-48); i = i+1 } else { g2 = 0 } } else { g2 = 0 } 357 } 358 } 359 pos[0] = i 360 return v*sg 361} 362// parse a canon buffer: P (part header) / R (control ring) / F (relief feature) lines; '#' = comment. 363// ---- ★★★OPENINGS: THE MECHANISM RELIEF STRUCTURALLY CANNOT PROVIDE (seq1387/seq908) ---- 364// An orbit and a nasal aperture are HOLES. Relief modulates a RADIUS, and a radius modulation can dent a 365// surface but can never remove it -- which is why the skull's six declared hollows moved the mesh and 366// moved nx_bodybench by NOTHING (headline 45, detail_head 14). An 'O' row declares a region where the 367// shell is simply ABSENT: the quad is not emitted, so the surface is genuinely gone and what lies behind 368// it is visible. Same geometry fields as an F row (part, y, y-halfwidth, theta, theta-halfwidth) minus 369// the amplitude, because there is no amount -- the surface is there or it is not. 370// ★PARSED SEPARATELY ON PURPOSE: bg_parse_canon already takes 24 arguments, and widening it further is 371// the wrong shape (that row wants a context array on its next touch, D001). This walks the same buffer 372// independently, so the existing signature and all its callers are untouched. 373// ★★ADDITIVE BY CONSTRUCTION: a canon carrying no O rows yields count 0 and every test below is inert, 374// so every existing canon must emit BIT-IDENTICAL output. That is the acceptance proof, not an opinion. 375func bg_parse_open(b: *u8, len: i64, oP: *i64, oY: *i64, oYw: *i64, oT: *i64, oTw: *i64, cnt: *i64) -> i64 { 376 let pos: *i64 = sys_mmap(16) as *i64 377 var n: i64 = 0 378 var i: i64 = 0 379 var bol: i64 = 1 380 while i < len { 381 if bol == 1 { 382 if (b[i] as i64) == 79 { 383 if n < BG_MAXFEAT { 384 pos[0] = i+1 385 oP[n] = bg_rdint(b, pos, len) 386 oY[n] = bg_rdint(b, pos, len) 387 oYw[n] = bg_rdint(b, pos, len) 388 oT[n] = bg_rdint(b, pos, len) 389 oTw[n] = bg_rdint(b, pos, len) 390 i = pos[0] 391 n = n + 1 392 } 393 } 394 } 395 if (b[i] as i64) == 10 { bol = 1 } else { bol = 0 } 396 i = i + 1 397 } 398 cnt[0] = n 399 return n 400} 401// is this (part, station, angle) inside a declared opening? bg_angsep handles the 0/360 wrap. 402func bg_in_open(part: i64, ymil: i64, thd: i64, oP: *i64, oY: *i64, oYw: *i64, oT: *i64, oTw: *i64, n: i64) -> i64 { 403 var k: i64 = 0 404 while k < n { 405 if oP[k] == part { 406 var dy: i64 = ymil - oY[k] 407 if dy < 0 { dy = 0 - dy } 408 if dy <= oYw[k] { 409 if bg_angsep(thd, oT[k]) <= oTw[k] { return 1 } 410 } 411 } 412 k = k + 1 413 } 414 return 0 415} 416 417func bg_parse_canon(b: *u8, len: i64, ry: *i64, rx0: *i64, rz0: *i64, ra: *i64, rb: *i64, 418 pStart: *i64, pCount: *i64, pMirror: *i64, pRot: *i64, pOx: *i64, pOy: *i64, pOz: *i64, 419 pMat: *i64, pRotZ: *i64, pRotY: *i64, fP: *i64, fY: *i64, fYw: *i64, fT: *i64, fTw: *i64, fA: *i64, counts: *i64) -> i64 { 420 var np: i64 = 0; var n: i64 = 0; var nf: i64 = 0 421 let pos: *i64 = sys_mmap(8) as *i64 422 var i: i64 = 0 423 while i < len { 424 var j: i64 = i 425 var sk: i64 = 1 426 while sk == 1 { 427 if j >= len { sk = 0 } else { 428 let c: i64 = b[j] as i64 429 if c == 32 { j = j+1 } else { if c == 9 { j = j+1 } else { sk = 0 } } 430 } 431 } 432 var tag: i64 = 0 433 if j < len { tag = b[j] as i64 } 434 var e: i64 = i 435 var fe: i64 = 1 436 while fe == 1 { if e >= len { fe = 0 } else { if (b[e] as i64) == 10 { fe = 0 } else { e = e+1 } } } 437 if tag == 80 { // 'P' -- part header 438 // GUARD: refuse LOUD rather than write past the part arrays. The canon is EXTERNAL input, so 439 // this is a boundary; an unguarded write here silently overflowed for every canon past the cap. 440 if np >= BG_MAXPART { 441 bg_hw("CANON-REFUSED part count exceeds BG_MAXPART\n" as *u8) 442 sys_exit(4) 443 } 444 if np > 0 { pCount[np-1] = n - pStart[np-1] } 445 pos[0] = j+1 446 pMirror[np] = bg_rdint(b,pos,e); pRot[np] = bg_rdint(b,pos,e) 447 pOx[np] = bg_rdint(b,pos,e); pOy[np] = bg_rdint(b,pos,e); pOz[np] = bg_rdint(b,pos,e) 448 pMat[np] = bg_rdint(b,pos,e) // optional 6th field: material (0=flesh, 1=eye) 449 // ★optional 7th field: ROTATION ABOUT Z, degrees (F1084 prereq 3). The mechanism gap the face 450 // work hit head-on: a brow ridge and a lip run HORIZONTALLY, but a part could only stack rings 451 // along Y and rotate about X, so every horizontal feature came out a vertical blob. rotZ turns 452 // the canonical Y-tube sideways IN the face plane; absent field parses as 0 = exact identity, 453 // so every existing canon is bit-identical (proven by golden md5 on the standing canon). 454 pRotZ[np] = bg_rdint(b,pos,e) 455 // ★optional 8th field: ROTATION ABOUT Y = AZIMUTH, degrees (S1). rotZ turns a part sideways in 456 // its own plane and rotX pitches it; NEITHER can answer "which compass direction does this limb 457 // point". That is the whole reason a wing, a branching antler and a spine-following ribcage were 458 // inexpressible: parts could only fan within one plane. Applied LAST of the three, so it is a 459 // true world azimuth rather than a spin of the cross-section. ZXY is a complete Euler 460 // parameterisation, so any orientation is now reachable. Absent field parses 0 -> pyc=Q14, 461 // pys=0, and x*Q14/Q14 is integer-exact => every existing canon stays BIT-IDENTICAL. 462 pRotY[np] = bg_rdint(b,pos,e) 463 pStart[np] = n; np = np+1 464 } 465 if tag == 82 { // 'R' -- control ring 466 // ★★THE GUARD THAT WAS MISSING FOR AS LONG AS THE PART GUARD HAS EXISTED. The 'P' branch above 467 // was hardened after an unguarded write silently overflowed -- and the fix was applied to ONE of 468 // the three branches. R and F kept writing past their arrays. ★A HARDENING APPLIED TO ONE 469 // BRANCH OF THREE IS NOT A HARDENING; it is a note saying somebody once knew about the problem. 470 // ⚠WHY IT NEVER SHOWED: the ring pool is GLOBAL across parts (256 entries for the whole body) 471 // and the canon has used 110 of them, so the overflow was always one anatomy rung away rather 472 // than absent. A 32-tooth arch at 4 rings each is 128 rings ON ITS OWN. mmap rounds to a page, 473 // so the first few hundred over-writes would have "worked" -- a wrong body with a clean exit. 474 if n >= BG_MAXRING { 475 bg_hw("CANON-REFUSED ring count exceeds BG_MAXRING\n" as *u8) 476 sys_exit(5) 477 } 478 pos[0] = j+1 479 ry[n] = bg_rdint(b,pos,e); rx0[n] = bg_rdint(b,pos,e); rz0[n] = bg_rdint(b,pos,e) 480 ra[n] = bg_rdint(b,pos,e); rb[n] = bg_rdint(b,pos,e); n = n+1 481 } 482 if tag == 70 { // 'F' -- relief feature 483 // the F pool was a bare unnamed sys_mmap(128*8) with no constant and no check -- it now has both 484 if nf >= BG_MAXFEAT { 485 bg_hw("CANON-REFUSED feature count exceeds BG_MAXFEAT\n" as *u8) 486 sys_exit(6) 487 } 488 pos[0] = j+1 489 fP[nf] = bg_rdint(b,pos,e); fY[nf] = bg_rdint(b,pos,e); fYw[nf] = bg_rdint(b,pos,e) 490 fT[nf] = bg_rdint(b,pos,e); fTw[nf] = bg_rdint(b,pos,e); fA[nf] = bg_rdint(b,pos,e); nf = nf+1 491 } 492 i = e+1 493 } 494 if np > 0 { pCount[np-1] = n - pStart[np-1] } 495 counts[0] = np; counts[1] = n; counts[2] = nf 496 return 0 497} 498 499// parse the measured-profile file: 'S <part> <ymil> <ra> <rb> <24 ratios>' rows, ';' comments. 500// ★DECLARED BIN COUNT, READ BEFORE ALLOCATION (2026-08-23) so the PRIOR'S OWN RESOLUTION sizes the 501// array instead of a compile-time ceiling deciding it. Mirrors bg_parse_prof's own line walk so the 502// two can never disagree about what an 'N' row is. Returns 0 when the file declares none. 503func bg_scan_nb(b: *u8, len: i64) -> i64 { 504 let pos: *i64 = sys_mmap(8) as *i64 505 var i: i64 = 0 506 while i < len { 507 var j: i64 = i 508 var sk: i64 = 1 509 while sk == 1 { 510 if j >= len { sk = 0 } else { 511 let c: i64 = b[j] as i64 512 if c == 32 { j = j+1 } else { if c == 9 { j = j+1 } else { sk = 0 } } 513 } 514 } 515 var e: i64 = i 516 var fe: i64 = 1 517 while fe == 1 { if e >= len { fe = 0 } else { if (b[e] as i64) == 10 { fe = 0 } else { e = e+1 } } } 518 if j < len { if (b[j] as i64) == 78 { pos[0] = j+1; return bg_rdint(b,pos,e) } } 519 i = e+1 520 } 521 return 0 522} 523 524func bg_parse_prof(b: *u8, len: i64, sP: *i64, sY: *i64, sR: *i64, nbo: *i64, stride: i64) -> i64 { 525 var ns: i64 = 0 526 var nb: i64 = 0 527 let pos: *i64 = sys_mmap(8) as *i64 528 var i: i64 = 0 529 while i < len { 530 var j: i64 = i 531 var sk: i64 = 1 532 while sk == 1 { 533 if j >= len { sk = 0 } else { 534 let c: i64 = b[j] as i64 535 if c == 32 { j = j+1 } else { if c == 9 { j = j+1 } else { sk = 0 } } 536 } 537 } 538 var tag: i64 = 0 539 if j < len { tag = b[j] as i64 } 540 var e: i64 = i 541 var fe: i64 = 1 542 while fe == 1 { if e >= len { fe = 0 } else { if (b[e] as i64) == 10 { fe = 0 } else { e = e+1 } } } 543 if tag == 78 { // 'N' -- bins per section 544 pos[0] = j+1 545 nb = bg_rdint(b,pos,e) 546 // ⚠THIS USED TO READ `if nb > BG_NBMAX { nb = 0 }` -- a prior declaring MORE bins than the 547 // compile-time ceiling was SILENTLY DISCARDED WHOLE: nb=0 means every S row is skipped, so 548 // the body emitted with NO measured prior at all and said nothing. A cap that deletes the 549 // data it cannot hold, without a word, is the worst shape a cap can take. The stride is now 550 // DERIVED from this same file's declared N, so for a well-formed prior this is unreachable; 551 // it remains as a fail-loud guard and RECORDS the offered count so the caller can announce. 552 if nb > stride { nbo[2] = nb; nb = 0 } 553 } 554 if tag == 83 { // 'S' 555 // ★COUNT WHAT WAS OFFERED, NOT ONLY WHAT FIT. nbo[1] is the row count PRESENT in the file; the 556 // caller compares it to the accepted count so a cap can never pass itself off as the data. 557 if nb > 0 { nbo[1] = nbo[1] + 1 } 558 if ns < BG_MAXPROF { if nb > 0 { 559 pos[0] = j+1 560 sP[ns] = bg_rdint(b,pos,e); sY[ns] = bg_rdint(b,pos,e) 561 bg_rdint(b,pos,e); bg_rdint(b,pos,e) // measured ra/rb are diagnostics; SIZE stays procedural 562 var k: i64 = 0 563 while k < nb { sR[ns*stride+k] = bg_rdint(b,pos,e); k = k+1 } 564 ns = ns+1 565 }} 566 } 567 i = e+1 568 } 569 nbo[0] = nb 570 return ns 571} 572// look up the shape prior for (part, height, parameter angle): linear in height between the two bracketing 573// measured stations, linear in angle between the two bracketing bins, clamped. Parts with no measured rows 574// (the foot, which runs forward and is measured in its own frame) return 1000 = unchanged. 575// ★HIGH-FREQUENCY RESIDUAL (hf != 0). Four measured attempts agreed that transferring the reference's 576// LOW-frequency shape improves silhouettes and WORSENS surface busyness -- and busyness is the binding 577// judge. The information the detail judge wants is the part of the real section that a smooth shape does 578// NOT explain: the residual against the profile's own smoothed self. Same measured data, opposite band. 579// ★stride is nb, not a ceiling: the array is exactly as wide as the prior declared itself to be. 580func bg_prof_at(sR: *i64, row: i64, b: i64, nb: i64) -> i64 { return sR[row*nb + ((b%nb)+nb)%nb] } 581func bg_prof_smooth(sR: *i64, row: i64, b: i64, nb: i64) -> i64 { 582 var acc: i64 = 0 583 var k: i64 = 0-3 584 while k <= 3 { acc = acc + bg_prof_at(sR,row,b+k,nb); k = k+1 } 585 return acc/7 586} 587func bg_prof(part: i64, ymil: i64, dq: i64, sP: *i64, sY: *i64, sR: *i64, ns: i64, nb: i64, hf: i64) -> i64 { 588 var lo: i64 = 0-1 589 var hi: i64 = 0-1 590 var k: i64 = 0 591 // ★★★PART-EDGE FEATHER (seq1466). The prior is looked up PER PART, so two parts that MEET can be 592 // perturbed to DIFFERENT radii at their shared boundary and stop meeting -- the skin then shows a hard 593 // step. RENDERED AND CONFIRMED: at PROF=1000 layer 0 alone (not a layer-superposition artifact -- that 594 // hypothesis was tested and refuted) carries a collar at the neck, a waist band, a knee seam and a 595 // capped head, and PROF=0 is clean, so the prior introduces them. 596 // ★The canon's parts are built to meet EXACTLY; the prior only has to stop pulling them apart. Fading 597 // its influence to zero at each part's own data extremes preserves the join by construction while 598 // leaving the part's INTERIOR fully modulated, which is where the detail lives. 599 let edge: i64 = BG_PROFEDGE 600 var pmin: i64 = BG_PERMIL_SQ 601 var pmax: i64 = 0 - BG_PERMIL_SQ 602 while k < ns { 603 if sP[k] == part { 604 if sY[k] < pmin { pmin = sY[k] } 605 if sY[k] > pmax { pmax = sY[k] } 606 if sY[k] <= ymil { if lo < 0 { lo = k } else { if sY[k] > sY[lo] { lo = k } } } 607 if sY[k] >= ymil { if hi < 0 { hi = k } else { if sY[k] < sY[hi] { hi = k } } } 608 } 609 k = k+1 610 } 611 if lo < 0 { if hi < 0 { return 1000 } lo = hi } 612 if hi < 0 { hi = lo } 613 let a: i64 = bg_wrap(dq) 614 let fb: i64 = a*nb*1000/360 615 let b0: i64 = (fb/1000) % nb 616 let b1: i64 = (b0+1) % nb 617 let bm: i64 = (b0+nb-1) % nb 618 let b2: i64 = (b0+2) % nb 619 let ft: i64 = fb % 1000 620 // ★CIRCULAR CATMULL-ROM around the ring, not linear between bins. Linear interpolation of the prior puts 621 // a CREASE at every one of the 24 bin boundaries -- a normal discontinuity every ~2 vertices at radial 44 622 // -- and the detail judge punishes busy-where-the-oracle-is-smooth exactly as it punishes smooth-where- 623 // detailed, so a C0 prior scored WORSE than no prior at all (measured: detail 360 -> 333). A cubic through 624 // the same measured bins is C1 by construction. Same fix that removed the axial banding in the lofting. 625 let v0: i64 = bg_cmr(sR[lo*nb+bm], sR[lo*nb+b0], sR[lo*nb+b1], sR[lo*nb+b2], ft)/1000 626 let v1: i64 = bg_cmr(sR[hi*nb+bm], sR[hi*nb+b0], sR[hi*nb+b1], sR[hi*nb+b2], ft)/1000 627 var w: i64 = 0 628 if sY[hi] != sY[lo] { w = (ymil - sY[lo])*1000/(sY[hi]-sY[lo]) } 629 if w < 0 { w = 0 } 630 if w > 1000 { w = 1000 } 631 // ★★★THE RINGING, FIXED WITH THE FIX ALREADY IN THIS FUNCTION -- ONE AXIS OVER. 632 // The comment above records killing a CREASE AT EVERY BIN BOUNDARY in the THETA direction by replacing 633 // linear interpolation with a circular Catmull-Rom, because a C0 prior scored WORSE than no prior at 634 // all (360 -> 333). ***THE AXIAL BLEND WAS STILL LINEAR***, so the prior was C1 AROUND the body and C0 635 // ALONG it: the tangent jumps at EVERY one of the 156 profile rows, and at strong PROF those creases 636 // read as hard horizontal bands. RENDERED AND CONFIRMED at PROF=1000: a pronounced collar at the neck 637 // plus seams at waist and knees -- which is exactly the 'it rings the neck' the default-off rationale 638 // cited, and it was never a property of the DATA, only of how the data was blended. 639 // ★SMOOTHSTEP makes dw/dy vanish at w=0 and w=1, so both sides of every row meet with equal tangent = 640 // C1 across the row. Exact at the ends by construction: w=0 -> 0, w=1000 -> 1000, w=500 -> 500. 641 w = w*w*(BG_SMOOTHSTEP_3_PERMIL - 2*w)/BG_PERMIL_SQ 642 var v: i64 = (v0*(1000-w) + v1*w)/1000 643 if hf != 0 { 644 // subtract the profile's own smoothed shape -> keep ONLY what the smooth shape cannot explain 645 let s0: i64 = bg_prof_smooth(sR, lo, b0, nb) 646 let s1: i64 = bg_prof_smooth(sR, hi, b0, nb) 647 let sv: i64 = (s0*(1000-w) + s1*w)/1000 648 // hf is a FLAG here, not a scale -- the caller applies the scale. Using it as a per-mille multiplier 649 // made (v-sv)*1/1000 truncate to exactly ZERO, so the whole band was a silent no-op that still built 650 // and still benched identically. Match the units of every factor before believing a null result. 651 v = 1000 + (v - sv) 652 } 653 // ★APPLY THE EDGE FEATHER: within `edge` of this part's own data extremes, ramp the modulation back 654 // toward neutral so the part meets its neighbour exactly as the canon built it. Linear in distance is 655 // enough here because the endpoints are what must agree; the axial blend is already C1 (smoothstep). 656 if pmax > pmin { 657 var d: i64 = ymil - pmin 658 let d2: i64 = pmax - ymil 659 if d2 < d { d = d2 } 660 if d < 0 { d = 0 } 661 // ⚠FEATHER REMOVED FROM THE PATH 2026-07-30 (my first disable was WRONG and the bench caught it: 662 // writing (v-1000)*0/edge forces v=1000 near the extremes, which is the MAXIMUM feather, not none -- 663 // it read headline 332, worse than both the feather 340 and the clean 354. Match the units of every 664 // factor before believing a null result -- this file says exactly that 40 lines down about hf.) 665 // ⚠DISABLED 2026-07-30: feather LOST ON BOTH INSTRUMENTS -- headline 354->340, detail_head 309->288 at PROF=1000, AND the render was visually UNCHANGED (same collar, waist band, knee seam). A change that loses the number AND shows nothing to the eye has no case. Kept as a zeroed term rather than deleted so the next diagnosis can see what was tried. THREE hypotheses now refuted BY LOOKING: axial C0 creasing (smoothstep helped numbers, changed nothing visible), layer superposition (layer 0 ALONE is identical), and this. STOP GUESSING: dump radius-vs-y at fixed theta for PROF 0 vs 1000, diff, and read off the exact stations where the step is. 666 } 667 if v > 1000+BG_PROFCLAMP { v = 1000+BG_PROFCLAMP } 668 if v < 1000-BG_PROFCLAMP { v = 1000-BG_PROFCLAMP } 669 return v 670} 671 672// Winding follows the monotonic local ring axis before rigid placement. 673// Swap complete corner attributes; cap orientation is already handled separately. 674func bg_ring_direction(y:*i64,start:i64,count:i64)->i64{ 675 if start<0||count<2{return 0} 676 var direction:i64=1;if y[start+1]<y[start]{direction=-1};if y[start+1]==y[start]{return 0} 677 var i:i64=1;while i<count{if direction==1{if y[start+i]<=y[start+i-1]{return 0}}else{if y[start+i]>=y[start+i-1]{return 0}};i=i+1};return direction 678} 679func bg_reverse_triangle_corners(t:*i64)->i64{ 680 var k:i64=0;while k<3{let position:i64=t[3+k];t[3+k]=t[6+k];t[6+k]=position;let normal:i64=t[12+k];t[12+k]=t[15+k];t[15+k]=normal;k=k+1};return 0 681} 682func bg_generate_cut(argc: i64, argv: *i64, join:*BgCutJoin) -> i64 { 683 let outp: *u8 = argv[1] as *u8 684 var H: i64 = BG_DEFAULT_STATURE_MM 685 if argc > 2 { H = bg_satoi(argv[2] as *u8) } 686 var RS: i64 = 28 687 if argc > 3 { RS = bg_satoi(argv[3] as *u8) } 688 var SUB: i64 = 4 689 if argc > 4 { SUB = bg_satoi(argv[4] as *u8) } 690 // relief amplitude scale, per-mille -- makes the anatomical surface relief a CONTROLLED VARIABLE 691 // measurable against the oracle, rather than a change assumed to help (1000 = as authored) 692 var RLF: i64 = 1000 693 if argc > 5 { RLF = bg_satoi(argv[5] as *u8) } 694 // ★SUBCUTANEOUS FAT (argv[7], per-mille): the layer between muscle and skin. It attenuates how much of 695 // the muscle definition reaches the SKIN surface -- lean (fat 0) shows the abs, heavy (fat high) smooths 696 // them -- so "abs hidden under fat" is EMERGENT from the layer stack, not a hack. Default lean-ish. 697 var FAT: i64 = 250 698 if argc > 7 { FAT = bg_satoi(argv[7] as *u8) } 699 // ★PROF (argv[8], per-mille): how much of the MEASURED section prior to apply. A CONTROLLED VARIABLE -- 700 // 0 reproduces the pre-GX-31 elliptical body exactly, so the A/B is the same code path and any change in 701 // the bench is attributable to the profiles alone (the relief-scale knob earned this pattern in GX-24). 702 // ★DEFAULT OFF, and it stays off until the prior earns it: MEASURED, applying the section prior LOWERS 703 // the honest headline (361 -> 335) because it transfers low-frequency form while flattening the back, 704 // and it rings the neck. Shipping it on by default would have been a silent regression for every other 705 // caller. It stays available as an opt-in so the next rung can build on the measurement, not repeat it. 706 // ★★★DEFAULT 0 -> 250, EARNED 2026-07-30 BY BOTH INSTRUMENTS (seq1441/1448/1451). The rationale above 707 // was correct FOR THE BODY IT WAS WRITTEN AGAINST -- but that body measured 361 baseline and this one 708 // measures 319, so the emitter moved underneath the decision. Re-swept vs the cadaver oracle 709 // knowledge/skin.nxmesh (self_iou=self_shape=self_detail=1000 every run): 710 // PROF 0 -> headline 319 detail_head 155 shape 934 711 // PROF 250 -> headline 360 detail_head 164 shape 934 <-- INTERIOR OPTIMUM, +41, NO shape cost 712 // PROF 500 -> headline 343 detail_head 196 shape 934 713 // PROF 750 -> headline 338 detail_head 242 shape 923 714 // PROF 1000 -> headline 347 detail_head 289 shape 923 715 // ★★AND THE NECK RINGING IS REAL -- I RENDERED IT AND LOOKED, which is the half a bench cannot do. 716 // At PROF=1000 the body shows a pronounced COLLAR AT THE NECK plus hard seams at waist and knees and 717 // a bulbous seamed head: the original author's word 'rings' is exactly right, and their refusal to 718 // ship it on was CORRECT. At PROF=250 those artifacts are ABSENT and the render is INDISTINGUISHABLE 719 // from PROF=0 by eye, while scoring +41. ★So 250 is number-up AND eye-neutral; 1000 was number-up and 720 // eye-DOWN, which is the Goodhart this lane refuses. A rising number is not permission to ship -- a 721 // rising number WITH AN UNCHANGED EYE is. 722 // ⚠The ringing at high prior is an unfixed defect, not a reason to avoid the prior: fixing it is what 723 // would let the strong end of this curve (detail_head 289, +134) be taken. That is the next rung. 724 var PROF: i64 = 250 725 if argc > 8 { PROF = bg_satoi(argv[8] as *u8) } 726 // ★HF (argv[10], per-mille): apply only the measured HIGH-FREQUENCY residual. Independent of PROF so the 727 // two bands are never confounded -- the whole point of the four measurements that led here. 728 var HF: i64 = 0 729 if argc > 10 { HF = bg_satoi(argv[10] as *u8) } 730 // BAS (argv[11], per-mille): analytic shape-basis weight -- a controlled variable like every knob here 731 var BAS: i64 = 0 732 if argc > 11 { BAS = bg_satoi(argv[11] as *u8) } 733 // ★DEC (argv[12], per-mille): measured-prior vs authored-relief DECONFLICTION. Where a part carries 734 // measured prof rows, attenuate the AUTHORED relief by DEC so the two stop double-modulating the same 735 // radius (triangulated 2026-08-10: head-scale A/Bs 226/249/166 -- each prior helped exactly where its 736 // data was faithful and fought the hand relief elsewhere). DEC=0 -> byte-identical output. 737 var DEC: i64 = 0 738 if argc > 12 { DEC = bg_satoi(argv[12] as *u8) } 739 let sinT: *i64 = sys_mmap(400*8) as *i64 740 bg_sin_fill(sinT) 741 742 // ---- CONTROL RINGS, per-mille of stature: y, xoff, zoff, rx, rz ---- 743 let ry: *i64 = sys_mmap(BG_MAXRING*8) as *i64 744 let rx0: *i64 = sys_mmap(BG_MAXRING*8) as *i64 745 let rz0: *i64 = sys_mmap(BG_MAXRING*8) as *i64 746 let ra: *i64 = sys_mmap(BG_MAXRING*8) as *i64 747 let rb: *i64 = sys_mmap(BG_MAXRING*8) as *i64 748 // three consecutive station rings (slot 1 = the station being normalled) -> TRUE surface normals 749 // by CENTRAL difference in both surface parameters 750 let sx: *i64 = sys_mmap(3*BG_MAXRS*8) as *i64 751 let sz: *i64 = sys_mmap(3*BG_MAXRS*8) as *i64 752 let sy: *i64 = sys_mmap(4*8) as *i64 753 let scx: *i64 = sys_mmap(4*8) as *i64 754 let scz: *i64 = sys_mmap(4*8) as *i64 755 // vertex rings: c = current station, pp = previous station (quads are emitted between them) 756 let cpx: *i64 = sys_mmap(BG_MAXRS*8) as *i64 757 let cpy: *i64 = sys_mmap(BG_MAXRS*8) as *i64 758 let cpz: *i64 = sys_mmap(BG_MAXRS*8) as *i64 759 let ppy: *i64 = sys_mmap(BG_MAXRS*8) as *i64 760 let cnx: *i64 = sys_mmap(BG_MAXRS*8) as *i64 761 let cny: *i64 = sys_mmap(BG_MAXRS*8) as *i64 762 let cnz: *i64 = sys_mmap(BG_MAXRS*8) as *i64 763 let ppx: *i64 = sys_mmap(BG_MAXRS*8) as *i64 764 let ppz: *i64 = sys_mmap(BG_MAXRS*8) as *i64 765 let pnx: *i64 = sys_mmap(BG_MAXRS*8) as *i64 766 let pny: *i64 = sys_mmap(BG_MAXRS*8) as *i64 767 let pnz: *i64 = sys_mmap(BG_MAXRS*8) as *i64 768 let pStart: *i64 = sys_mmap(BG_MAXPART*8) as *i64 769 let pCount: *i64 = sys_mmap(BG_MAXPART*8) as *i64 770 let pMirror: *i64 = sys_mmap(BG_MAXPART*8) as *i64 771 // ★PART PLACEMENT. Every part is authored in its own canonical frame as a tube stacked along +Y, then 772 // ROTATED about X and offset into place. Without this a part can only run vertically, which is why the 773 // foot had to be faked as two forward-stretched rings on the end of the leg tube (it read as a blunt 774 // cone, and the error map put the feet among the worst regions). A real foot runs FORWARD, so it is a 775 // Y-tube rotated 90 degrees. Same mechanism gives fingers and toes. Existing parts use rot=0, off=0 776 // and are bit-identical to before. 777 let pRot: *i64 = sys_mmap(BG_MAXPART*8) as *i64 778 let pOx: *i64 = sys_mmap(BG_MAXPART*8) as *i64 779 let pOy: *i64 = sys_mmap(BG_MAXPART*8) as *i64 780 let pOz: *i64 = sys_mmap(BG_MAXPART*8) as *i64 781 let pMat: *i64 = sys_mmap(BG_MAXPART*8) as *i64 782 let pRotZ: *i64 = sys_mmap(BG_MAXPART*8) as *i64 783 let pRotY: *i64 = sys_mmap(BG_MAXPART*8) as *i64 784 let tf3: *i64 = sys_mmap(64) as *i64 785 var pz: i64 = 0 786 while pz < BG_MAXPART { pRot[pz]=0; pOx[pz]=0; pOy[pz]=0; pOz[pz]=0; pMat[pz]=0; pRotZ[pz]=0; pRotY[pz]=0; pz=pz+1 } 787 var n: i64 = 0 788 var np: i64 = 0 789 790 // ---- LOAD THE CANON (DATA-DRIVEN: the emitter carries NO geometry literals; the anthropometric canon -- 791 // every ring and every relief feature -- lives in a data file. A different archetype (male, female, 792 // anime, monster) is a different canon fed to the SAME emit algorithm, and the canon itself is produced 793 // by a PROCEDURAL generator, not typed by hand.) ---- 794 let fP: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 795 let fY: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 796 let fYw: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 797 let fT: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 798 let fTw: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 799 let fA: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 800 var canonp: *u8 = "knowledge/canon_male.dat" as *u8 801 if argc > 6 { canonp = argv[6] as *u8 } 802 let clen: *i64 = sys_mmap(16) as *i64 803 let cbuf: *u8 = sys_read_file(canonp, clen) 804 // ★FIXED 2026-07-30: this literal had UNESCAPED QUOTES -- bg_hw("{"error":...") -- so nx_cc read 805 // `error` as a bare identifier and REFUSED the whole module. nx_body_gen, the emitter behind every 806 // body AND the skull mesh, was NOT BUILDABLE FROM ITS OWN SOURCE; the live binary predates the line. 807 // The file already had the right idiom 350 lines further down (\x22), it just was not used here. 808 if (cbuf as i64) == 0 { bg_hw("{\x22error\x22:\x22cannot read canon file\x22}\n" as *u8); return 3 } 809 let counts: *i64 = sys_mmap(32) as *i64 810 bg_parse_canon(cbuf, clen[0], ry,rx0,rz0,ra,rb, pStart,pCount,pMirror,pRot,pOx,pOy,pOz, pMat, pRotZ, pRotY, fP,fY,fYw,fT,fTw,fA, counts) 811 // ★OPENINGS (seq1387): parsed from the SAME buffer by its own walker, so bg_parse_canon's 24-arg 812 // signature and every caller of it stay untouched. Zero O rows => nopen[0]=0 => provably inert. 813 let oP: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 814 let oY: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 815 let oYw: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 816 let oT: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 817 let oTw: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 818 let nopen: *i64 = sys_mmap(16) as *i64 819 nopen[0] = 0 820 bg_parse_open(cbuf, clen[0], oP, oY, oYw, oT, oTw, nopen) 821 // ★SHAPE-BASIS CANON, loaded as DATA. Applies to every canon exactly as the hardcoded table did, so it 822 // is one file rather than a copy per canon. REFUSES if absent: a body emitted with no basis rows would 823 // be silently smooth-torsoed and browless, which reads as a rendering fault rather than a missing file. 824 let kP: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 825 let kYlo: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 826 let kYhi: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 827 let kTh: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 828 let kWk: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 829 let kW0: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 830 let kW1: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 831 let kW2: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 832 let kAmp: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 833 let kYk: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 834 let kP0: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 835 let kP1: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 836 let kP2: *i64 = sys_mmap(BG_MAXFEAT*8) as *i64 837 let nbasis: *i64 = sys_mmap(16) as *i64 838 nbasis[0] = 0 839 let blen: *i64 = sys_mmap(16) as *i64 840 let bbuf: *u8 = sys_read_file("knowledge/body_shape_basis.conf" as *u8, blen) 841 if (bbuf as i64) == 0 { bg_hw("{\x22error\x22:\x22cannot read knowledge/body_shape_basis.conf -- the shape-basis canon is REQUIRED; refusing to emit a featureless body\x22}\n" as *u8); return 7 } 842 bg_parse_basis(bbuf, blen[0], kP,kYlo,kYhi,kTh,kWk,kW0,kW1,kW2,kAmp,kYk,kP0,kP1,kP2, nbasis) 843 if nbasis[0] < 1 { bg_hw("{\x22error\x22:\x22body_shape_basis.conf declares no B rows -- refusing to emit a featureless body\x22}\n" as *u8); return 7 } 844 // ★LAYER PALETTE, read from L rows in the SAME buffer -- one file, one read, no second config path. 845 // REFUSES on an incomplete palette for the same reason the B rows do: a body emitted with an unpainted 846 // layer looks like a renderer fault, not a missing row, and would be debugged in the wrong organ. 847 let lyR: *i64 = sys_mmap(BG_NLAYER*8) as *i64 848 let lyG: *i64 = sys_mmap(BG_NLAYER*8) as *i64 849 let lyB: *i64 = sys_mmap(BG_NLAYER*8) as *i64 850 let nlay: *i64 = sys_mmap(16) as *i64 851 nlay[0] = 0 852 bg_parse_layers(bbuf, blen[0], lyR, lyG, lyB, nlay) 853 if nlay[0] < BG_NLAYER { bg_hw("{\x22error\x22:\x22body_shape_basis.conf must declare one L row per layer -- refusing to emit a body with an unpainted layer\x22}\n" as *u8); return 7 } 854 np = counts[0]; n = counts[1]; var nf: i64 = counts[2] 855 856 // ---- MEASURED SECTION PROFILES (optional: absent file -> ns 0 -> every lookup returns 1000) ---- 857 let sP: *i64 = sys_mmap(BG_MAXPROF*8) as *i64 858 let sY: *i64 = sys_mmap(BG_MAXPROF*8) as *i64 859 let nbp: *i64 = sys_mmap(32) as *i64 860 nbp[0] = 0 861 nbp[2] = 0 862 var ns: i64 = 0 863 var profp: *u8 = "knowledge/profile_human.dat" as *u8 864 if argc > 9 { profp = argv[9] as *u8 } 865 let plen: *i64 = sys_mmap(16) as *i64 866 let pbuf: *u8 = sys_read_file(profp, plen) 867 // Qualification requires an explicit measured-region contract; diagnostics retain raw data. 868 if PROF != 0||HF != 0 { 869 if (pbuf as i64) == 0 { bg_hw("profile qualification: missing source\n" as *u8); return 5 } 870 let qi: *i64 = sys_mmap(40) as *i64 871 let qv: i64 = profile_contract_scan(pbuf, plen[0], qi) 872 if qv != 0 { 873 bg_hw("profile qualification refused: verdict=" as *u8); bg_pn(qv) 874 bg_hw(" ambiguous_stations=" as *u8); bg_pn(qi[1]) 875 bg_hw(" first_y=" as *u8); bg_pn(qi[2]) 876 bg_hw(" affected_parts=" as *u8); bg_pn(qi[3]); bg_hw("," as *u8); bg_pn(qi[4]) 877 bg_hw(" required=profile-contract-v2 next=map source anatomical regions; retain source and diagnostic captures\n" as *u8) 878 return 5 879 } 880 } 881 // ★★★STRIDE DERIVED FROM THE PRIOR'S OWN DECLARED N (2026-08-23) -- the ceiling is REMOVED, not 882 // raised. BG_NBMAX=96 was a compile-time bound on how finely the measured prior could be carried, 883 // and it was the binding cap the moment PF_NB=48 was lifted in the producer the same day. Worse, 884 // a file declaring MORE bins was silently discarded whole (see bg_parse_prof). Sizing the array 885 // from the file's own N means the consumer can carry ANY resolution the producer can measure, and 886 // there is no number here for anyone to pick. BG_MAXPROF still bounds the ROW count (a different 887 // axis, still a cap, named for the census). 888 var nbdecl: i64 = 0 889 if (pbuf as i64) != 0 { nbdecl = bg_scan_nb(pbuf, plen[0]) } 890 var stride: i64 = nbdecl 891 if stride < 1 { stride = 1 } 892 let sR: *i64 = sys_mmap(BG_MAXPROF*stride*8) as *i64 893 if (pbuf as i64) != 0 { ns = bg_parse_prof(pbuf, plen[0], sP, sY, sR, nbp, stride) } 894 let nbins: i64 = nbp[0] 895 if nbins < 1 { ns = 0 } 896 // per-part prof coverage: which parts the measured prior actually speaks for (drives DEC) 897 let pcov: *i64 = sys_mmap(BG_MAXPART*8) as *i64 898 var pcf: i64 = 0 899 while pcf < ns { if sP[pcf] >= 0 { if sP[pcf] < BG_MAXPART { pcov[sP[pcf]] = 1 } } pcf = pcf + 1 } 900 901 // ---- emit ---- 902 let join_rc:i64=bjc_init(join,RS,np,pCount,pMirror,SUB) 903 if join_rc<0{return bg_join_refuse(join,"input" as *u8,join_rc)} 904 let tri: *i64 = sys_mmap(BG_MAXTRI*21*8) as *i64 905 // ★per-triangle MATERIAL colour (0-1000 each). Lets a feature (eyes) carry its OWN colour instead of the 906 // flat per-layer flesh -- the reason eyes were invisible skin-bumps. Written per tri at emit, read at write. 907 let tcR: *i64 = sys_mmap(BG_MAXTRI*8) as *i64 908 let tcG: *i64 = sys_mmap(BG_MAXTRI*8) as *i64 909 let tcB: *i64 = sys_mmap(BG_MAXTRI*8) as *i64 910 var nt: i64 = 0 911 // demand counter: every tri the geometry WANTED to emit, counted whether or not the cap admitted it. 912 // ntoff > nt is the truncation proof; mirrors the prof_rows_offered pattern below. 913 var ntoff: i64 = 0 914 let layCnt: *i64 = sys_mmap(BG_NLAYER*8) as *i64 915 916 // ★LAYER LOOP -- emit the body once per anatomical layer (bone, muscle, skin), nested inside each other. 917 var Lyr: i64 = 0 918 while Lyr < BG_NLAYER { 919 let lstart: i64 = nt 920 // per-layer radius scale + how much of the muscle relief this layer carries 921 // ★SKIN IS LAYER 0 so the renderer's skin shading (wrap-diffuse SSS + sheen, keyed on layer 0) lands 922 // on it; muscle=1, bone=2 sit inside. Intact z-buffers to the outermost (skin) regardless of order. 923 var rmul: i64 = 1000; var relmul: i64 = 1000 924 // ★COLOUR IS INDEXED, NOT LADDERED -- a new layer needs an L row in the canon, not a new branch 925 // here. rmul and relmul stay as branches deliberately: they are SHAPE, not palette (already-named 926 // consts plus a fat-derived value), and folding them into the same table would put two unrelated 927 // kinds of thing in one row. 928 var lcR: i64 = lyR[Lyr]; var lcG: i64 = lyG[Lyr]; var lcB: i64 = lyB[Lyr] 929 if Lyr == 0 { rmul = 1000; relmul = 1000 - FAT } // SKIN: relief attenuated by fat 930 if Lyr == 1 { rmul = BG_MUSCF; relmul = 1000 } // MUSCLE 931 if Lyr == 2 { rmul = BG_BONEF; relmul = 0 } // BONE 932 if relmul < 0 { relmul = 0 } 933 var p: i64 = 0 934 while p < np { 935 let local_direction:i64=bg_ring_direction(ry,pStart[p],pCount[p]) 936 if local_direction==0{bg_hw("{\x22error\x22:\x22LOCAL_RING_AXIS_NOT_STRICTLY_MONOTONIC\x22}\n" as *u8);return 8} 937 var side: i64 = 0 938 var nsides: i64 = 1 939 if pMirror[p] == 1 { nsides = 2 } 940 while side < nsides { 941 var sgn: i64 = 1 942 if side == 1 { sgn = 0-1 } 943 // ★ONE GLOBAL STATION INDEX. Normals are CENTRAL differences in BOTH surface parameters -- 944 // across stations as well as around the ring -- so they are shared by the quads either side 945 // and vary continuously. The previous one-sided within-band difference made the vertical 946 // tilt CONSTANT per band and step at every boundary: true normals, but visible bandaging. 947 let maxst: i64 = (pCount[p]-1)*SUB 948 let prc: i64 = sinT[bg_wrap(pRot[p]+90)] 949 let prs: i64 = sinT[bg_wrap(pRot[p])] 950 // ★Z-rotation (F1084): applied BEFORE the X-rotation at every transform site. The MIRRORED side 951 // gets the NEGATED angle so a left feature is the true mirror of the right one (a brow that 952 // tilts up-and-out on the right must tilt up-and-out on the left too). rotZ=0 gives pzc=Q14, 953 // pzs=0, and x*Q14/Q14 is integer-exact, so unrotated parts are BIT-IDENTICAL by construction. 954 let pzc: i64 = sinT[bg_wrap(sgn*pRotZ[p]+90)] 955 let pzs: i64 = sinT[bg_wrap(sgn*pRotZ[p])] 956 // ★AZIMUTH IS NEGATED ON THE MIRRORED SIDE, exactly as rotZ is -- mirroring flips X, so a limb 957 // swept BACK on the right must sweep BACK on the left, not forward. rotX is deliberately NOT 958 // negated: a forward pitch stays forward on both sides. Getting this wrong yields a body whose 959 // two halves rotate opposite ways, which reads as a twist rather than as a mirror. 960 let pyc: i64 = sinT[bg_wrap(sgn*pRotY[p]+90)] 961 let pys: i64 = sinT[bg_wrap(sgn*pRotY[p])] 962 var st: i64 = 0 963 while st <= maxst { 964 // evaluate the station ring at st-1, st, st+1 (clamped at the caps) into slots 0,1,2 965 var q: i64 = 0 966 while q < 3 { 967 var stq: i64 = st + q - 1 968 if stq < 0 { stq = 0 } 969 if stq > maxst { stq = maxst } 970 var cq: i64 = stq/SUB 971 if cq > pCount[p]-2 { cq = pCount[p]-2 } 972 let j0: i64 = pStart[p]+cq 973 let j1: i64 = j0+1 974 let fq: i64 = (stq - cq*SUB)*1000/SUB 975 // ★SUB-UNIT SAMPLING. Every station coordinate is computed to BG_PSUB sub-units with ONE 976 // division, instead of rounding to raw units first. The old code rounded y to whole units 977 // before the central-difference tangent, so on a SMALL part (the head is ~1/8 the body) 978 // where dy/station is only a few units, the rounding made uy alternate 6,8,6,8 -> the 979 // vertical tilt oscillated -> horizontal BANDING (proven in the normal map, and immune to 980 // relief and to raising PSUB, because y never went through PSUB). yri etc are per-mille*1000. 981 // Catmull-Rom through the ring and its neighbours (clamped at part ends) -- see bg_cmr. 982 var jm: i64 = j0-1 983 if jm < pStart[p] { jm = pStart[p] } 984 var jp: i64 = j1+1 985 if jp > pStart[p]+pCount[p]-1 { jp = pStart[p]+pCount[p]-1 } 986 let yri: i64 = bg_cmr(ry[jm], ry[j0], ry[j1], ry[jp], fq) 987 let xri: i64 = sgn*bg_cmr(rx0[jm], rx0[j0], rx0[j1], rx0[jp], fq) 988 let zri: i64 = bg_cmr(rz0[jm], rz0[j0], rz0[j1], rz0[jp], fq) 989 var ari: i64 = bg_cmr(ra[jm], ra[j0], ra[j1], ra[jp], fq) 990 var bri: i64 = bg_cmr(rb[jm], rb[j0], rb[j1], rb[jp], fq) 991 if ari < 0 { ari = 0 } // cubic overshoot must never go negative 992 if bri < 0 { bri = 0 } 993 let ymq: i64 = yri/1000 994 let xqs: i64 = xri*H*BG_PSUB/BG_PERMIL_SQ 995 let zqs: i64 = zri*H*BG_PSUB/BG_PERMIL_SQ 996 sy[q] = yri*H*BG_PSUB/BG_PERMIL_SQ 997 scx[q] = xqs 998 scz[q] = zqs 999 let aqs: i64 = ari*rmul/1000*H*BG_PSUB/BG_PERMIL_SQ 1000 let bqs: i64 = bri*rmul/1000*H*BG_PSUB/BG_PERMIL_SQ 1001 var i: i64 = 0 1002 while i < RS { 1003 let dq: i64 = bg_wrap(i*360/RS) 1004 let cw: i64 = sinT[bg_wrap(dq+90)]; let sw: i64 = sinT[dq] 1005 // anatomical relief modulates the radius per ANGLE as well as height, so the 1006 // surface carries real features instead of being an ellipse of revolution. relmul is 1007 // the fraction of that relief THIS layer carries (bone 0, muscle full, skin fat-attenuated). 1008 var relmul2: i64 = relmul 1009 if DEC > 0 { if pcov[p] == 1 { relmul2 = relmul*(1000-DEC)/1000 } } 1010 var rq: i64 = 1000 + bg_relief(p, ymq, dq, fP,fY,fYw,fT,fTw,fA, nf)*RLF/1000*relmul2/1000 1011 if BAS != 0 { rq = rq + bg_shape_basis(p, ymq, dq, sinT, kP,kYlo,kYhi,kTh,kWk,kW0,kW1,kW2,kAmp,kYk,kP0,kP1,kP2, nbasis[0])*BAS/1000*relmul2/1000 } 1012 // ★measured section prior. On a MIRRORED part the ring itself is not mirrored (only its 1013 // centre offset is), so theta 0 stays +X and would put the limb's LATERAL profile on the 1014 // medial side; flip the angle for side 1 so left and right are true mirrors. 1015 if ns > 0 { 1016 var pdq: i64 = dq 1017 if sgn < 0 { pdq = bg_wrap(180-dq) } 1018 if PROF != 0 { 1019 let pv: i64 = bg_prof(p, ymq, pdq, sP, sY, sR, ns, nbins, 0) 1020 rq = rq*(1000 + (pv-1000)*PROF/1000)/1000 1021 } 1022 if HF != 0 { 1023 let hv: i64 = bg_prof(p, ymq, pdq, sP, sY, sR, ns, nbins, 1) 1024 rq = rq*(1000 + (hv-1000)*HF/1000)/1000 1025 } 1026 } 1027 sx[q*BG_MAXRS+i] = xqs + (aqs*rq/1000)*cw/BG_Q14 1028 sz[q*BG_MAXRS+i] = zqs + (bqs*rq/1000)*sw/BG_Q14 1029 i = i+1 1030 } 1031 q = q+1 1032 } 1033 let uy: i64 = sy[2]-sy[0] 1034 var i: i64 = 0 1035 while i < RS { 1036 let ip: i64 = (i+1)%RS 1037 let im: i64 = (i+RS-1)%RS 1038 // dP/dtheta and dP/dstation, both central 1039 let vx: i64 = sx[BG_MAXRS+ip]-sx[BG_MAXRS+im] 1040 let vz: i64 = sz[BG_MAXRS+ip]-sz[BG_MAXRS+im] 1041 let ux: i64 = sx[2*BG_MAXRS+i]-sx[i] 1042 let uz: i64 = sz[2*BG_MAXRS+i]-sz[i] 1043 var enx: i64 = uy*vz 1044 var eny: i64 = uz*vx - ux*vz 1045 var enz: i64 = 0-uy*vx 1046 // keep the components squareable without throwing away the fine detail 1047 var mx: i64 = enx; if mx < 0 { mx = 0-mx } 1048 var m2: i64 = eny; if m2 < 0 { m2 = 0-m2 } 1049 if m2 > mx { mx = m2 } 1050 m2 = enz; if m2 < 0 { m2 = 0-m2 } 1051 if m2 > mx { mx = m2 } 1052 while mx > BG_NCAP { enx=enx/2; eny=eny/2; enz=enz/2; mx=mx/2 } 1053 // outward = agrees with the ring-centre-to-vertex direction (relief included) 1054 let ox: i64 = sx[BG_MAXRS+i]-scx[1] 1055 let oz: i64 = sz[BG_MAXRS+i]-scz[1] 1056 if (enx*ox + enz*oz) < 0 { enx = 0-enx; eny = 0-eny; enz = 0-enz } 1057 var enl: i64 = bg_isqrt(enx*enx + eny*eny + enz*enz) 1058 if enl < 1 { enl = 1 } 1059 var wnx: i64 = enx*BG_Q14/enl 1060 var wny: i64 = eny*BG_Q14/enl 1061 var wnz: i64 = enz*BG_Q14/enl 1062 var wpx: i64 = sx[BG_MAXRS+i]/BG_PSUB 1063 var wpy: i64 = sy[1]/BG_PSUB 1064 var wpz: i64 = sz[BG_MAXRS+i]/BG_PSUB 1065 // place the part: rotate about Z, then about X, then offset (see PART PLACEMENT above) 1066 bg_rot3(wpx,wpy,wpz, pzc,pzs,prc,prs,pyc,pys, tf3) 1067 wpx = tf3[0]; wpy = tf3[1]; wpz = tf3[2] 1068 wpy = wpy + pOy[p]*H/1000 1069 wpz = wpz + pOz[p]*H/1000 1070 wpx = wpx + sgn*pOx[p]*H/1000 1071 bg_rot3(wnx,wny,wnz, pzc,pzs,prc,prs,pyc,pys, tf3) 1072 wnx = tf3[0]; wny = tf3[1]; wnz = tf3[2] 1073 cnx[i] = wnx; cny[i] = wny; cnz[i] = wnz 1074 cpx[i] = wpx; cpy[i] = wpy; cpz[i] = wpz 1075 i = i+1 1076 } 1077 if Lyr==0{let rc:i64=bjc_ring(join,p,side,st,cpx,cpy,cpz,cnx,cny,cnz);if rc<0{return bg_join_refuse(join,"ring" as *u8,rc)}} 1078 let cy: i64 = sy[1]/BG_PSUB 1079 // ★CAP THE TUBE ENDS. An open tube lets the camera see its own inner wall -- that was the 1080 // bright flat trapezoid at the crotch: the torso tube's open bottom, viewed from inside. 1081 // The cap faces along the tube AXIS (from the station-centre difference), so it works for 1082 // the arm and leg tubes too, whose parameter runs downward rather than up. 1083 var capend: i64 = 0 1084 if st == 0 { capend = 1 } 1085 if st == maxst { capend = 2 } 1086 if Lyr==0&&capend>0{if bjc_keep(join,p,side,st,capend)==0{capend=0;if (join as i64)!=0{join.removed=join.removed+RS}}} 1087 if capend > 0 { 1088 var kx: i64 = scx[1]-scx[2]; var ky: i64 = sy[1]-sy[2]; var kz: i64 = scz[1]-scz[2] 1089 if capend == 2 { kx = scx[1]-scx[0]; ky = sy[1]-sy[0]; kz = scz[1]-scz[0] } 1090 var kl: i64 = bg_isqrt(kx*kx+ky*ky+kz*kz) 1091 if kl < 1 { kl = 1 } 1092 kx = kx*BG_Q14/kl; ky = ky*BG_Q14/kl; kz = kz*BG_Q14/kl 1093 // a station ring is planar in xz, so its face normal is purely +/-y: pick the winding 1094 // that agrees with the axis direction. Decided in the CANONICAL frame, before the 1095 // placement rotation -- a rotation preserves orientation, so the choice still holds. 1096 let kyc: i64 = ky 1097 bg_rot3(kx,ky,kz, pzc,pzs,prc,prs,pyc,pys, tf3) 1098 kx = tf3[0]; ky = tf3[1]; kz = tf3[2] 1099 var ccx: i64 = scx[1]/BG_PSUB 1100 var ccy: i64 = cy 1101 var ccz: i64 = scz[1]/BG_PSUB 1102 bg_rot3(ccx,ccy,ccz, pzc,pzs,prc,prs,pyc,pys, tf3) 1103 ccx = tf3[0]; ccy = tf3[1]; ccz = tf3[2] 1104 ccy = ccy + pOy[p]*H/1000 1105 ccz = ccz + pOz[p]*H/1000 1106 ccx = ccx + sgn*pOx[p]*H/1000 1107 var e2: i64 = 0 1108 while e2 < RS { 1109 var v0: i64 = (e2+1)%RS 1110 var v1: i64 = e2 1111 if kyc < 0 { v0 = e2; v1 = (e2+1)%RS } 1112 ntoff = ntoff + 1 1113 if nt < BG_MAXTRI-2 { 1114 let t3: i64 = nt*21 1115 tri[t3]=ccx; tri[t3+1]=ccy; tri[t3+2]=ccz 1116 tri[t3+3]=cpx[v0]; tri[t3+4]=cpy[v0]; tri[t3+5]=cpz[v0] 1117 tri[t3+6]=cpx[v1]; tri[t3+7]=cpy[v1]; tri[t3+8]=cpz[v1] 1118 tri[t3+9]=kx; tri[t3+10]=ky; tri[t3+11]=kz 1119 tri[t3+12]=kx; tri[t3+13]=ky; tri[t3+14]=kz 1120 tri[t3+15]=kx; tri[t3+16]=ky; tri[t3+17]=kz 1121 if Lyr==0{let rc:i64=bjc_face(join,p,side,bjc_words(tri,t3));if rc<0{return bg_join_refuse(join,"witness" as *u8,rc)}} 1122 var cr3: i64 = lcR; var cg3: i64 = lcG; var cb3: i64 = lcB 1123 if pMat[p] >= 1 { if pMat[p] <= 4 { cr3 = 958; cg3 = 954; cb3 = 942 } } // eye cap = sclera 1124 tcR[nt]=cr3; tcG[nt]=cg3; tcB[nt]=cb3 1125 nt = nt+1 1126 } 1127 e2 = e2+1 1128 } 1129 } 1130 if st > 0 { 1131 var e: i64 = 0 1132 while e < RS { 1133 let ep: i64 = (e+1)%RS 1134 // per-quad material colour (flat per-layer, unless a feature material) 1135 var qr: i64 = lcR; var qg: i64 = lcG; var qb: i64 = lcB 1136 if pMat[p] >= 1 { if pMat[p] <= 4 { // EYE (material = iris colour 1..4) 1137 qr = 958; qg = 954; qb = 942 // sclera white 1138 var af: i64 = e*360/RS - 90; if af < 0 { af = 0-af } // 0 at the FRONT (+Z) 1139 var sf: i64 = st - maxst/2; if sf < 0 { sf = 0-sf } 1140 sf = sf*100/maxst // 0 at the eye equator 1141 if af < 34 { if sf < 17 { 1142 qr = 120; qg = 78; qb = 45 // 1 = brown (default) 1143 if pMat[p] == 2 { qr = 86; qg = 122; qb = 170 } // 2 = blue 1144 if pMat[p] == 3 { qr = 92; qg = 134; qb = 92 } // 3 = green 1145 if pMat[p] == 4 { qr = 150; qg = 116; qb = 66 } // 4 = amber/hazel 1146 }} 1147 if af < 14 { if sf < 7 { qr = 24; qg = 22; qb = 24 } } // pupil (near-black) 1148 }} 1149 if pMat[p] == 5 { // FACE (head): colour by region 1150 let ymil: i64 = cy*1000/H 1151 var af2: i64 = e*360/RS - 90; if af2 < 0 { af2 = 0-af2 } // 0 at the FRONT (+Z) 1152 // ★LIP PAINT RETIRED (F1093), same reasoning as the brow: the lips are now two 1153 // real Z-rotated parts with a genuine groove between them, and a colour band 1154 // calibrated for the HEAD's angular frame lands arbitrarily across them. The 1155 // mouth is now a shadow cast by anatomy, not a rectangle drawn on an ovoid. 1156 // ★BROW PAINT RETIRED (F1084 prereq 2). The brow is now a real Z-ROTATED PART, and 1157 // paint fights geometry: this band is calibrated for the HEAD's angular frame, so 1158 // on a small brow part it landed as black bars that read as goggles. A feature is 1159 // either geometry or paint; once it is geometry the paint is a lie on top of it. 1160 } 1161 // ★★THE OPENING TEST. Skipping the quad removes the surface OUTRIGHT -- this is the 1162 // thing a radius modulation structurally cannot do. Written as a flag rather than a 1163 // wrapping block so the brace structure is UNCHANGED (a stray brace here would be a 1164 // silent scoping change in the emitter's hottest loop). 1165 var emit: i64 = 1 1166 if Lyr==0{if bjc_keep(join,p,side,st,0)==0{emit=0;if (join as i64)!=0{join.removed=join.removed+2}}} 1167 if nopen[0] > 0 { if bg_in_open(p, cy*1000/H, e*360/RS, oP,oY,oYw,oT,oTw, nopen[0]) == 1 { emit = 0 } } 1168 // an OPENING is intentional absence -- only cap refusal counts as truncation demand 1169 if emit == 1 { ntoff = ntoff + 2 } 1170 if nt >= BG_MAXTRI-2 { emit = 0 } 1171 if emit == 1 { 1172 let t1: i64 = nt*21 1173 tri[t1]=ppx[e]; tri[t1+1]=ppy[e]; tri[t1+2]=ppz[e] 1174 tri[t1+3]=cpx[e]; tri[t1+4]=cpy[e]; tri[t1+5]=cpz[e] 1175 tri[t1+6]=cpx[ep];tri[t1+7]=cpy[ep]; tri[t1+8]=cpz[ep] 1176 tri[t1+9]=pnx[e]; tri[t1+10]=pny[e]; tri[t1+11]=pnz[e] 1177 tri[t1+12]=cnx[e]; tri[t1+13]=cny[e]; tri[t1+14]=cnz[e] 1178 tri[t1+15]=cnx[ep];tri[t1+16]=cny[ep]; tri[t1+17]=cnz[ep] 1179 if local_direction<0{bg_reverse_triangle_corners(bjc_words(tri,t1))} 1180 if Lyr==0{let rc:i64=bjc_face(join,p,side,bjc_words(tri,t1));if rc<0{return bg_join_refuse(join,"witness" as *u8,rc)}} 1181 tcR[nt]=qr; tcG[nt]=qg; tcB[nt]=qb 1182 nt = nt+1 1183 let t2: i64 = nt*21 1184 tri[t2]=ppx[e]; tri[t2+1]=ppy[e]; tri[t2+2]=ppz[e] 1185 tri[t2+3]=cpx[ep]; tri[t2+4]=cpy[ep]; tri[t2+5]=cpz[ep] 1186 tri[t2+6]=ppx[ep]; tri[t2+7]=ppy[ep]; tri[t2+8]=ppz[ep] 1187 tri[t2+9]=pnx[e]; tri[t2+10]=pny[e]; tri[t2+11]=pnz[e] 1188 tri[t2+12]=cnx[ep]; tri[t2+13]=cny[ep]; tri[t2+14]=cnz[ep] 1189 tri[t2+15]=pnx[ep]; tri[t2+16]=pny[ep]; tri[t2+17]=pnz[ep] 1190 if local_direction<0{bg_reverse_triangle_corners(bjc_words(tri,t2))} 1191 if Lyr==0{let rc:i64=bjc_face(join,p,side,bjc_words(tri,t2));if rc<0{return bg_join_refuse(join,"witness" as *u8,rc)}} 1192 tcR[nt]=qr; tcG[nt]=qg; tcB[nt]=qb 1193 nt = nt+1 1194 } 1195 e = e+1 1196 } 1197 } 1198 var g: i64 = 0 1199 while g < RS { 1200 ppx[g]=cpx[g]; ppy[g]=cpy[g]; ppz[g]=cpz[g] 1201 pnx[g]=cnx[g]; pny[g]=cny[g]; pnz[g]=cnz[g] 1202 g = g+1 1203 } 1204 st = st+1 1205 } 1206 side = side+1 1207 } 1208 p = p+1 1209 } 1210 if Lyr==0&&(join as i64)!=0{ 1211 let joined:i64=bjc_finish(join,tri,tcR,tcG,tcB,nt,BG_MAXTRI,lcR,lcG,lcB) 1212 if joined<0{return bg_join_refuse(join,"bridge" as *u8,joined)} 1213 if join.added!=2*RS||joined!=nt+join.added||join.removed<=0{return bg_join_refuse(join,"bridge-count" as *u8,BJ_BOUNDARY)} 1214 nt=joined;ntoff=ntoff+join.added 1215 } 1216 layCnt[Lyr] = nt - lstart 1217 Lyr = Lyr+1 1218 } 1219 1220 // (the head is now PART 4 above -- the ellipsoid-of-revolution cranium is gone, replaced by a ring-tube 1221 // that inherits true normals + the facial relief table + the crown cap, just like every other part.) 1222 1223 // ---- write NXMSH2 (3 LAYERS: bone, muscle, skin -- contiguous tri ranges) ---- 1224 let hdr: i64 = 16 + BG_NLAYER*24 1225 let bytes: i64 = hdr + nt*84 + nt*4 1226 let buf: *u8 = sys_mmap(bytes + 64) 1227 buf[0]=78 as u8; buf[1]=88 as u8; buf[2]=77 as u8; buf[3]=83 as u8 1228 buf[4]=72 as u8; buf[5]=50 as u8; buf[6]=0 as u8; buf[7]=0 as u8 1229 bg_wr32(buf, 8, BG_NLAYER); bg_wr32(buf, 12, nt) 1230 // layer table: name[16] off4 cnt4, in emit order 0=bone 1=muscle 2=skin 1231 var lo: i64 = 0; var Lw: i64 = 0 1232 while Lw < BG_NLAYER { 1233 let lb: i64 = 16 + Lw*24 1234 var q: i64 = 0 1235 while q < 16 { buf[lb+q]=0 as u8; q=q+1 } 1236 if Lw==0 { buf[lb]=115 as u8; buf[lb+1]=107 as u8; buf[lb+2]=105 as u8; buf[lb+3]=110 as u8 } // "skin" 1237 if Lw==1 { buf[lb]=109 as u8; buf[lb+1]=117 as u8; buf[lb+2]=115 as u8; buf[lb+3]=99 as u8 } // "musc" 1238 if Lw==2 { buf[lb]=98 as u8; buf[lb+1]=111 as u8; buf[lb+2]=110 as u8; buf[lb+3]=101 as u8 } // "bone" 1239 bg_wr32(buf, lb+16, lo); bg_wr32(buf, lb+20, layCnt[Lw]) 1240 lo = lo + layCnt[Lw] 1241 Lw = Lw+1 1242 } 1243 // per-tri geometry + per-TRIANGLE material colour (from the emit; carries feature colours like the eyes). 1244 let l0: i64 = layCnt[0]; let l1: i64 = layCnt[0]+layCnt[1] 1245 var t: i64 = 0 1246 while t < nt { 1247 let o: i64 = hdr + t*84 1248 var j: i64 = 0 1249 while j < 9 { bg_wr32(buf, o+j*4, bg_f32(tri[t*21+j], 1)); j=j+1 } 1250 while j < 18 { bg_wr32(buf, o+j*4, bg_f32(tri[t*21+j], BG_Q14)); j=j+1 } 1251 bg_wr32(buf, o+72, bg_f32(tcR[t], 1000)); bg_wr32(buf, o+76, bg_f32(tcG[t], 1000)); bg_wr32(buf, o+80, bg_f32(tcB[t], 1000)) 1252 t = t+1 1253 } 1254 // per-tri layer id (0=skin, 1=muscle, 2=bone) 1255 var z: i64 = 0 1256 while z < nt { 1257 var lid: i64 = 2 1258 if z < l0 { lid = 0 } else { if z < l1 { lid = 1 } } 1259 bg_wr32(buf, hdr + nt*84 + z*4, lid); z=z+1 1260 } 1261 let fd: i64 = sys_openat_wr(outp, MODE_0644) 1262 sys_write(fd, buf, bytes) 1263 sys_close(fd) 1264 1265 bg_hw("{\x22organ\x22:\x22nx_body_gen\x22,\x22v\x22:2,\x22source\x22:\x22SOVEREIGN PROCEDURAL -- anthropometric canon, continuous ring profiles, no scanned asset\x22" as *u8) 1266 bg_hw(",\x22height\x22:" as *u8); bg_pn(H) 1267 bg_hw(",\x22parts\x22:" as *u8); bg_pn(np) 1268 bg_hw(",\x22control_rings\x22:" as *u8); bg_pn(n) 1269 bg_hw(",\x22radial\x22:" as *u8); bg_pn(RS) 1270 bg_hw(",\x22sub\x22:" as *u8); bg_pn(SUB) 1271 bg_hw(",\x22tris\x22:" as *u8); bg_pn(nt) 1272 bg_hw(",\x22tris_offered\x22:" as *u8); bg_pn(ntoff) 1273 // ★TRUNCATION MUST BE LOUD (F1083). The two raster guards silently STOP emitting at BG_MAXTRI, which is 1274 // the documented root of the \x22red face\x22 bug: the skin layer is emitted LAST, so a full budget drops the 1275 // head/hands and they render as the muscle layer underneath -- a wrong body with a clean exit code. Same 1276 // silent-failure class as the unguarded part array. Report the headroom always, and FAIL LOUD at the cap. 1277 bg_hw(",\x22tri_cap\x22:" as *u8); bg_pn(BG_MAXTRI) 1278 bg_hw(",\x22tri_headroom\x22:" as *u8); bg_pn(BG_MAXTRI - nt) 1279 var trunc: i64 = 0 1280 if nt >= BG_MAXTRI - 4 { trunc = 1 } 1281 if ntoff > nt { trunc = 1 } // demand-based: ANY refused tri marks the mesh truncated, not just a full budget 1282 bg_hw(",\x22truncated\x22:" as *u8); bg_pn(trunc) 1283 bg_hw(",\x22prof_rows\x22:" as *u8); bg_pn(ns) 1284 // ★OFFERED vs ACCEPTED. Equal = the whole file loaded. Greater = the cap ate rows and every number below 1285 // is measured on PARTIAL data -- publish it rather than let a truncated prior look like a measured one. 1286 bg_hw(",\x22prof_rows_offered\x22:" as *u8); bg_pn(nbp[1]) 1287 var proftrunc: i64 = 0 1288 if nbp[1] > ns { proftrunc = 1 } 1289 bg_hw(",\x22prof_truncated\x22:" as *u8); bg_pn(proftrunc) 1290 bg_hw(",\x22prof_scale\x22:" as *u8); bg_pn(PROF) 1291 bg_hw(",\x22dec\x22:" as *u8); bg_pn(DEC) 1292 if (join as i64)!=0{bg_hw(",\x22attachment_removed\x22:" as *u8);bg_pn(join.removed);bg_hw(",\x22attachment_added\x22:" as *u8);bg_pn(join.added)} 1293 bg_hw("}\n" as *u8) 1294 return 0 1295} 1296 1297func bg_join_refuse(j:*BgCutJoin,stage:*u8,code:i64)->i64{ 1298 bg_hw("{\x22error\x22:\x22SKIN_ATTACHMENT_REFUSED\x22,\x22stage\x22:\x22" as *u8);bg_hw(stage);bg_hw("\x22,\x22code\x22:" as *u8);bg_pn(code) 1299 if (j as i64)!=0{bg_hw(",\x22part_a\x22:" as *u8);bg_pn(j.part_a);bg_hw(",\x22station_a\x22:" as *u8);bg_pn(j.station_a);bg_hw(",\x22part_b\x22:" as *u8);bg_pn(j.part_b);bg_hw(",\x22station_b\x22:" as *u8);bg_pn(j.station_b)} 1300 bg_hw("}\n" as *u8);bjc_release(j);return 7 1301} 1302// Optional recipe is versioned and bounded independently of the launcher argument limit. 1303func bg_recipe_error(stage:*u8,code:i64,e:*i64)->i64{ 1304 bg_hw("{\x22error\x22:\x22ATTACHMENT_RECIPE_REFUSED\x22,\x22stage\x22:\x22" as *u8);bg_hw(stage);bg_hw("\x22,\x22code\x22:" as *u8);bg_pn(code) 1305 bg_hw(",\x22expected_version\x22:" as *u8);bg_pn(BJC_RECIPE_VERSION);bg_hw(",\x22expected_tokens\x22:" as *u8);bg_pn(BJC_RECIPE_TOKENS) 1306 if (e as i64)!=0{bg_hw(",\x22token_index\x22:" as *u8);bg_pn(e[1]);bg_hw(",\x22byte_offset\x22:" as *u8);bg_pn(e[2]);bg_hw(",\x22observed_version\x22:" as *u8);bg_pn(e[3]);bg_hw(",\x22input_bytes\x22:" as *u8);bg_pn(e[4])};bg_hw("}\n" as *u8);return 7 1307} 1308func main(argc:i64,argv:*i64)->i64{ 1309 if argc<2||argc>14{return bg_recipe_error("arguments" as *u8,BR_SCHEMA,0 as *i64)} 1310 if argc<=13{return bg_generate_cut(argc,argv,0 as *BgCutJoin)} 1311 let bytes:i64=bjc_join_bytes()+BJC_ERROR_WORDS*8+__size_of(NxFileReadRegion);let arena:*u8=sys_mmap_try(bytes) 1312 if (arena as i64)<=0{return bg_recipe_error("allocation" as *u8,NX_BO_ALLOCATION,0 as *i64)} 1313 let j:*BgCutJoin=arena as *BgCutJoin;let e:*i64=((arena as i64)+bjc_join_bytes()) as *i64 1314 let region:*NxFileReadRegion=((e as i64)+BJC_ERROR_WORDS*8) as *NxFileReadRegion;fio_region_init(region) 1315 var rc:i64=0;var data:*u8=0 as *u8;var extent:i64=0;let opened:i64=fio_region_open(argv[13] as *u8,region) 1316 if opened<0{rc=bg_recipe_error(region.stage,opened,e)}else{ 1317 extent=region.total;e[4]=extent 1318 if extent<=0{rc=bg_recipe_error("empty-file" as *u8,BR_SCHEMA,e)}else{ 1319 data=sys_mmap_try(extent) 1320 if (data as i64)<=0{rc=bg_recipe_error("file-allocation" as *u8,NX_BO_ALLOCATION,e)}else{ 1321 let got:i64=fio_region_next(region,data,extent) 1322 if got!=extent||region.read_bytes!=extent||region.code!=0{rc=bg_recipe_error(region.stage,region.code,e)}else{ 1323 let parsed:i64=bjc_recipe_parse(data,extent,j,e) 1324 if parsed<0{rc=bg_recipe_error("schema" as *u8,parsed,e)}else{rc=bg_generate_cut(argc,argv,j)} 1325 } 1326 } 1327 } 1328 } 1329 let closed:i64=fio_region_close(region);if closed<0&&rc==0{rc=bg_recipe_error("close" as *u8,closed,e)} 1330 if (data as i64)>0{let freed_data:i64=sys_munmap_direct(data,extent);if freed_data<0{rc=bg_recipe_error("file-release" as *u8,NX_BO_RELEASE,e)}} 1331 let released:i64=bjc_release(j);if released<0{rc=bg_recipe_error("release" as *u8,released,e)} 1332 let freed:i64=sys_munmap_direct(arena,bytes);if freed<0{return bg_recipe_error("release-arena" as *u8,NX_BO_RELEASE,0 as *i64)};return rc 1333}