code wiki / _hdl_build / nx_skullgen.nx

nx_skullgen.nx source

↩ module page · 541 lines · 33918 B

1// nx_skullgen.nx -- F1108/seq900 KEYSTONE: THE SKULL, GENERATED. Inside-out, from the first byte up. 2// 3// OPERATOR, and he was right: "you arent building from the inside out aka a skull to give it structure ... 4// take the skull and bones those should have all been generatable by now then you just layer on top." 5// Every facial feature this program fought with is a property of BONE -- the brow ridge is the supraorbital 6// margin of the frontal bone, the chin is the mental protuberance of the mandible, the cheekbones are the 7// zygomatic arches, the eye sockets are the orbits. We had been sticking those onto a smooth SKIN ovoid, 8// which is why three tuned chin attempts all rendered as lobes stacked under a mouth: pieces stuck on a 9// blob look like pieces stuck on a blob. The structure has to exist first and the surface layers onto it. 10// 11// This organ does NOT store a skull -- it stores the RULES that make one, and emits them as a canon of 12// P/R/F rows that the proven emitter turns into geometry. So the skull inherits spline lofting, true 13// central-difference normals, capped tubes, per-part placement and rotation about Z for free, and it is 14// data generated by anatomy rather than a modelled asset. The oracle it is scored against is the 15// BodyParts3D skull (171,248 real scanned triangles, CC BY-SA 2.1 Japan) -- a RULER, never the product. 16// 17// nx_skullgen <out.dat> [sex 0-1000] [seed] [robust 0-1000] 18// nx_skullgen selftest 19// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26). 20import "nx_gate_verdict.nx" 21import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 22 23const SK_BUF: i64 = 65536 24const SK_MODE: i64 = 420 25const SK_MINP: i64 = 7 26const SK_MINR: i64 = 30 27// RECORD TAG BYTES of the .dat canon format: ASCII 'P', 'R', 'F'. Named because the raw 70 is 28// otherwise INDISTINGUISHABLE from the anatomical 70-percent proportions a few lines away 29// (`vlt*70/SK_PERCENT`) -- one value carrying two entirely unrelated meanings in one file, which is 30// the defect rule 11 exists to stop and which a value-keyed auto-hoist would have FUSED. 31// ASCII bytes used as DELIMITERS in the .dat writer/reader. Named for the same reason as the tags: 32// in this one file 32 is simultaneously the ASCII space, a 32-bit field width (sk_wint) and an mmap 33// size, and 10 is simultaneously the newline, the decimal base and a skull dimension. Three unrelated 34// meanings per value -- a value-keyed hoist fuses them and none can ever be changed independently. 35// ---- THE CANON: cranial base proportions and their dimorphism coefficients ---- 36// Rule-derived, NOT tuner-fitted (contrast nx_skullsdf's ss_defaults, whose values are the output of 37// coordinate descent and MUST stay with their optimizer). Each is a named anatomical fact, so these 38// are the exact rows a later `skull_canon.conf` will assign -- naming first, externalising second, 39// because a conf that assigns to bare literals has nothing to bind to. 40// BASE = the value at sexf=0, robust=0. SEXF/ROBUST = per-mille slope on each knob. 41const SK_BROW_BASE: i64 = 12 // supraorbital margin: heavy male, light female 42const SK_BROW_SEXF: i64 = 5 43const SK_BROW_ROBUST: i64 = 6 44const SK_JAW_BASE: i64 = 46 // mandible breadth: square male, tapered female 45const SK_JAW_SEXF: i64 = 6 46const SK_JAW_ROBUST: i64 = 5 47const SK_VAULT_BASE: i64 = 52 // cranial vault half-breadth 48const SK_VAULT_SEXF: i64 = 2 49const SK_ZYG_BASE: i64 = 50 // zygomatic (cheekbone) projection 50const SK_ZYG_SEXF: i64 = 3 51const SK_ZYG_ROBUST: i64 = 4 52const SK_ASCII_SP: i64 = 32 53const SK_ASCII_NL: i64 = 10 54const SK_TAG_P: i64 = 80 55const SK_TAG_R: i64 = 82 56const SK_TAG_F: i64 = 70 57// UNIT DENOMINATORS. These are units, not dials: the POLICY lives in the numerator (`vlt*88/SK_PERCENT` 58// says 88 percent), and changing these would rescale the whole canon rather than tune anything. 59// Hoisted only at sites PROVEN to be divisors -- all 88 occurrences of 100/SK_PERMILLE were enumerated and 60// 7 are NOT denominators (five 1000s are coordinates/spans/file args, two 100s are a clamp floor at 61// SK_VTX). Those 7 keep their literal deliberately; folding them in here would have silently changed 62// a clamp and four skull coordinates while the build stayed green. 63const SK_PERCENT: i64 = 100 64const SK_PERMILLE: i64 = 1000 65// PRNG SEEDING. sk_step is xorshift64 (13/7/17): it is DEGENERATE at state 0 and avalanches 66// slowly from a small ordinal seed, so a caller's seed is mixed across the whole word before 67// the first shift round rather than used raw. 68const SK_SEED_GOLDEN32: i64 = 2654435761 // 0x9E3779B1 = floor(2^32 / phi), Knuth's multiplicative-hash constant 69const SK_SEED_ODD_ADD: i64 = 12345 // odd addend so seed 0 cannot produce the degenerate state 0 70// Extent accumulators start at +/- this and are replaced by the first real sample; every skull 71// coordinate is far inside it. A sentinel, not a limit -- nothing is ever clamped to it. 72const SK_EXTENT_SENTINEL: i64 = 999999 73// One scratch page for the T7 containment fixture (process-lifetime, freed at exit). 74const SK_FIXTURE_BUF: i64 = 4096 75// Seed for the T6 anti-vacuity tooth. DELIBERATELY ITS OWN CONSTANT even though it shares the 76// literal 12345 with SK_SEED_ODD_ADD: one is a PRNG addend, the other is test input. Folding 77// them (which a value-keyed auto-hoist does) would make one constant serve two unrelated 78// purposes, so it could never be tuned for either. 79const SK_T6_SEED: i64 = 12345 80// ★VAULT VERTEX CLOSURE, per-mille of the parietal half-width (argv[6]). A DIAL, not a baked number, because 81// the right value is a FITTING question against the oracle and must be swept, not intuited: the cone-vs-dome 82// fix took the closure tail from 4 to 165 against the oracle's 351, so the residual is a value to MEASURE. 83// 580 = the value measured good on 2026-07-30; the y994 ring follows as the midpoint so the dome stays smooth. 84static SK_VTX: i64 85 86func sk_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 87// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 88// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 89// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 90// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 91func sk_pn(v: i64) -> i64 { nxi_out(v); return 0 } 92func sk_step(st: *i64) -> i64 { 93 var x: i64 = st[0] 94 x = x ^ (x << 13); x = x ^ (x >> 7); x = x ^ (x << 17) 95 st[0] = x 96 if x < 0 { return 0-x } 97 return x 98} 99func sk_pm(st: *i64, amp: i64) -> i64 { if amp <= 0 { return 0 } let r: i64 = sk_step(st) % (2*amp+1); return r - amp } 100func sk_streq(a: *u8, b: *u8) -> i64 { 101 var i: i64=0; var go: i64=1; var eq: i64=1 102 while go==1 { if a[i]!=b[i] { eq=0; go=0 } else { if a[i]==(0 as u8) { go=0 } else { i=i+1 } } } 103 return eq 104} 105func sk_atoi(s: *u8) -> i64 { 106 var i: i64=0; var n: i64=0; var sg: i64=1 107 if s[0]==(45 as u8) { sg=0-1; i=1 } 108 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 } 109 return n*sg 110} 111func sk_wint(b: *u8, pos: *i64, v: i64, c: i64) -> i64 { 112 var x: i64=v 113 if x<0 { b[pos[0]]=45 as u8; pos[0]=pos[0]+1; x=0-x } 114 let t: *u8 = sys_mmap(32); var k: i64=0 115 if x==0 { t[0]=48 as u8; k=1 } 116 while x>0 { t[k]=(48+x%10) as u8; x=x/10; k=k+1 } 117 var q: i64=k-1 118 while q>=0 { b[pos[0]]=t[q]; pos[0]=pos[0]+1; q=q-1 } 119 b[pos[0]]=c as u8; pos[0]=pos[0]+1 120 return 0 121} 122// one control ring of a bone: y (per-mille of stature), lateral + depth offsets, half-width, half-depth 123func skR(b: *u8, pos: *i64, y: i64, xoff: i64, zoff: i64, ra: i64, rb: i64) -> i64 { 124 var a: i64 = ra; var d: i64 = rb 125 if a < 2 { a = 2 } 126 if d < 2 { d = 2 } 127 b[pos[0]]=82 as u8; b[pos[0]+1]=SK_ASCII_SP as u8; pos[0]=pos[0]+2 128 sk_wint(b,pos,y,32); sk_wint(b,pos,xoff,32); sk_wint(b,pos,zoff,32); sk_wint(b,pos,a,32); sk_wint(b,pos,d,10) 129 return 0 130} 131// one BONE: a part header carrying mirror, X-rotation, offsets, material and rotation about Z 132func skP(b: *u8, pos: *i64, mir: i64, rot: i64, ox: i64, oy: i64, oz: i64, mat: i64, rotz: i64) -> i64 { 133 b[pos[0]]=80 as u8; b[pos[0]+1]=SK_ASCII_SP as u8; pos[0]=pos[0]+2 134 sk_wint(b,pos,mir,32); sk_wint(b,pos,rot,32); sk_wint(b,pos,ox,32); sk_wint(b,pos,oy,32) 135 sk_wint(b,pos,oz,32); sk_wint(b,pos,mat,32); sk_wint(b,pos,rotz,10) 136 return 0 137} 138// a relief feature: hollows and openings in bone (orbits, nasal aperture, temporal fossa) 139func skF(b: *u8, pos: *i64, part: i64, y: i64, yw: i64, th: i64, tw: i64, amp: i64) -> i64 { 140 b[pos[0]]=70 as u8; b[pos[0]+1]=SK_ASCII_SP as u8; pos[0]=pos[0]+2 141 sk_wint(b,pos,part,32); sk_wint(b,pos,y,32); sk_wint(b,pos,yw,32) 142 sk_wint(b,pos,th,32); sk_wint(b,pos,tw,32); sk_wint(b,pos,amp,10) 143 return 0 144} 145// ★an OPENING: a region where the shell is ABSENT, not merely pushed in. No amplitude field, because 146// there is no amount -- the surface is there or it is not. Consumed by nx_body_gen's bg_parse_open. 147func skO(b: *u8, pos: *i64, part: i64, y: i64, yw: i64, th: i64, tw: i64) -> i64 { 148 b[pos[0]]=79 as u8; b[pos[0]+1]=SK_ASCII_SP as u8; pos[0]=pos[0]+2 149 sk_wint(b,pos,part,32); sk_wint(b,pos,y,32); sk_wint(b,pos,yw,32) 150 sk_wint(b,pos,th,32); sk_wint(b,pos,tw,10) 151 return 0 152} 153// ★THE SKULL, BY RULE. Every dimension is a function of cranial proportion and the sex/robusticity knobs; 154// nothing is a typed coordinate lifted off a reference. Ordering follows the developmental logic: the 155// neurocranium that houses the brain, then the face suspended from its front, then the jaw hung beneath. 156func sk_emit(b: *u8, pos: *i64, st: *i64, sexf: i64, robust: i64, noise: i64) -> i64 { 157 // dimorphism + robusticity as SCALARS over the whole skull, the way a genome modulates a template 158 let brow: i64 = SK_BROW_BASE - SK_BROW_SEXF*sexf/SK_PERMILLE + SK_BROW_ROBUST*robust/SK_PERMILLE 159 let jaw: i64 = SK_JAW_BASE - SK_JAW_SEXF*sexf/SK_PERMILLE + SK_JAW_ROBUST*robust/SK_PERMILLE 160 let vlt: i64 = SK_VAULT_BASE + SK_VAULT_SEXF*sexf/SK_PERMILLE 161 let zyg: i64 = SK_ZYG_BASE - SK_ZYG_SEXF*sexf/SK_PERMILLE + SK_ZYG_ROBUST*robust/SK_PERMILLE 162 163 // ---- 1. NEUROCRANIUM: the vault. Widest at the parietal eminences, occiput bulging behind, the 164 // frontal sloping back above the brow. Deeper than broad, which is what makes a skull read as a skull. 165 // ★THE v1 DEFECT: this vault spanned 866..1000 -- the WHOLE skull height -- so the maxilla (910), 166 // zygomatics (924) and mandible (874) were all INSIDE a shell whose half-depth is ~55 there. Only 167 // the zygomatic end-caps emerged, which is why v1 rendered as an egg with two white discs. 168 // A real neurocranium is the BRAIN CASE ONLY. It starts at the base and ends above the orbits; the 169 // facial skeleton hangs from its FRONT and BELOW, never inside it. The vault is also pushed BACK, 170 // because the braincase sits behind the face rather than centred on it. 171 // ★THE BRAINCASE FLOOR, NAMED ONCE (seq1381). Every hollow's station is DERIVED from it below, so 172 // moving the vault can never again strand the orbits and fossae the way the v1->v2 shrink did. 173 let vlo: i64 = 926 174 let vsp: i64 = 1000 - vlo 175 skP(b,pos, 0, 0, 0, 0, 0, 0, 0) 176 skR(b,pos, vlo, 0, 0-24, vlt*70/SK_PERCENT + sk_pm(st,noise), vlt*74/SK_PERCENT) // skull base, occipital region 177 skR(b,pos, 940, 0, 0-20, vlt*88/SK_PERCENT, vlt*98/SK_PERCENT) // temporal squama 178 skR(b,pos, 952, 0, 0-16, vlt*97/SK_PERCENT, vlt*110/SK_PERCENT) // widening toward the eminence 179 skR(b,pos, 964, 0, 0-14, vlt, vlt*116/SK_PERCENT) // parietal eminence: the widest 180 skR(b,pos, 976, 0, 0-16, vlt*95/SK_PERCENT, vlt*110/SK_PERCENT) 181 // ★★★★★THE VAULT CLOSED AS A CONE, NOT A DOME -- MEASURED, NOT GUESSED (debt 1785452359). 182 // The old tail was 82 -> 58 -> 28 percent of the parietal half-width with the ring centre pulled BACK 183 // -20 -> -26 -> -32, i.e. a spike leaning backward. nx_meshprofile's closure curve (radius as per-mille 184 // of the mesh's own max, per y band) measured the consequence end to end: 185 // vault as a CONE : radius_min 500um @station 992, tail ...150 122 71 42 4 186 // the REAL SKULL : radius_min 37716um @station 984, tail ...463 406 351 187 // vault as a DOME : radius_min 43660um @station 992, tail ...476 446 437 416 188 // So the cranium used to end in a SPIRE holding 0.4 percent of its max radius where a real one holds 189 // 35 percent -- 87x too thin at the crown, and no section prior can touch it because it is the CANON. 190 // Isolated by bisection (a vault-only canon reproduced the spire with every other bone removed), so this 191 // is the vault's own closure and not a neighbouring part. Equator is UNTOUCHED: radius_max stays 104805 192 // @station 500 before and after, so this changes the CLOSURE and nothing else. 193 // ⚠STILL SLIGHTLY BROAD: 416 vs the oracle's 351. That is now a FITTING residual, not a structural 194 // defect -- pull the vertex ring toward vlt*52/SK_PERCENT and re-measure the tail before trusting a smaller number. 195 skR(b,pos, 986, 0, 0-20, vlt*85/SK_PERCENT, vlt*96/SK_PERCENT) // frontal, sloping back 196 let vmid: i64 = (850 + SK_VTX)/2 197 skR(b,pos, 994, 0, 0-22, vlt*vmid/SK_PERMILLE, vlt*vmid/SK_PERMILLE*115/SK_PERCENT) 198 skR(b,pos,1000, 0, 0-24, vlt*SK_VTX/SK_PERMILLE, vlt*SK_VTX/SK_PERMILLE*112/SK_PERCENT) // vertex: a DOME, not a point 199 200 // ---- 2. SUPRAORBITAL MARGIN: the brow as BONE, a horizontal ridge with the glabella between the arcs. 201 // This is the structure the skin brow was standing in for, and it belongs here. 202 // The ridge must ride PROUD of the vault's front surface at its own height, or it is buried inside 203 // the braincase and renders as nothing. Front of vault at the brow line = ring centre (-20) plus its 204 // depth radius; the ridge then buries its axis a fraction of its OWN radius beneath that, so the 205 // belly emerges. Derived from vlt/brow, so it holds at any skull size. 206 skP(b,pos, 0, 0, 0, 940, vlt*104/SK_PERCENT - brow*40/SK_PERCENT, 0-20 + vlt*92/SK_PERCENT - brow*40/SK_PERCENT, 90) 207 skR(b,pos, 0-34, 0, 0-brow*180/SK_PERCENT, brow*28/SK_PERCENT, brow*38/SK_PERCENT) 208 skR(b,pos, 0-19, 0, 0-brow*30/SK_PERCENT, brow, brow*82/SK_PERCENT) // arc over the right orbit 209 skR(b,pos, 0, 0, 0, brow*70/SK_PERCENT, brow*60/SK_PERCENT) // glabella, between the arcs 210 skR(b,pos, 19, 0, 0-brow*30/SK_PERCENT, brow, brow*82/SK_PERCENT) // arc over the left orbit 211 skR(b,pos, 34, 0, 0-brow*180/SK_PERCENT, brow*28/SK_PERCENT, brow*38/SK_PERCENT) 212 213 // ---- 3. ZYGOMATIC ARCH: the cheekbone bridge, running FRONT-TO-BACK (rot 90 about X), mirrored. 214 // It is what gives a face lateral width and the hollow of the temple above it. 215 // The arch must START at the cheek (forward, on the maxilla) and SWEEP BACK to the vault, which is 216 // what makes it an arch rather than the free-floating rod the first render showed. Its origin is 217 // moved forward to the maxilla datum; the rings then run back along the part's own axis. 218 skP(b,pos, 1, 90, zyg*62/SK_PERCENT, 924, vlt*74/SK_PERCENT - 26, 0, 0) 219 skR(b,pos, 0, 0, 0, zyg*12/SK_PERCENT, zyg*13/SK_PERCENT) 220 skR(b,pos, 20, 0, 0, zyg*15/SK_PERCENT, zyg*13/SK_PERCENT) 221 skR(b,pos, 44, 0, 0, zyg*13/SK_PERCENT, zyg*11/SK_PERCENT) 222 skR(b,pos, 62, 0, 0, zyg*9/SK_PERCENT, zyg*10/SK_PERCENT) 223 224 // ---- 4. MAXILLA: the upper jaw carrying the alveolar arch, suspended below the orbits. 225 // The maxilla must MEET the braincase, not hover in front of it. The vault base ring sits at z=-24 226 // with depth radius vlt*74/SK_PERCENT, so its front is at (vlt*74/SK_PERCENT - 24); the maxilla is placed to 227 // overlap that rather than float clear of it, and the tooth row leans forward from there. 228 skP(b,pos, 0, 0, 0, 0, 0, 0, 0) 229 skR(b,pos, 886, 0, vlt*74/SK_PERCENT - 24 + 8, jaw*54/SK_PERCENT, jaw*46/SK_PERCENT) // alveolar margin (tooth row) 230 skR(b,pos, 898, 0, vlt*74/SK_PERCENT - 24 + 10, jaw*62/SK_PERCENT, jaw*54/SK_PERCENT) 231 skR(b,pos, 910, 0, vlt*74/SK_PERCENT - 24 + 6, jaw*66/SK_PERCENT, jaw*58/SK_PERCENT) // body of the maxilla 232 skR(b,pos, 922, 0, vlt*74/SK_PERCENT - 24, jaw*62/SK_PERCENT, jaw*54/SK_PERCENT) // orbital floor, ON the vault front 233 234 // ---- 5. NASAL BRIDGE: the paired nasal bones between the orbits, above the aperture. 235 // The nasal bones were the most visibly wrong thing in the first render: a CONE FLOATING IN AIR 236 // well forward of everything. They are a small bridge spanning maxilla to frontal, so they are now 237 // anchored to the same vault-front datum and made broad enough to read as bone rather than a spike. 238 skP(b,pos, 0, 0, 0, 0, 0, 0, 0) 239 skR(b,pos, 916, 0, vlt*74/SK_PERCENT - 24 + 12, 10, 10) 240 skR(b,pos, 926, 0, vlt*80/SK_PERCENT - 22 + 10, 11, 11) 241 skR(b,pos, 936, 0, vlt*86/SK_PERCENT - 20 + 6, 11, 10) 242 skR(b,pos, 944, 0, vlt*92/SK_PERCENT - 20, 10, 9) // meeting the frontal at nasion 243 244 // ---- 6. MANDIBLE BODY: the horseshoe of the lower jaw, hung beneath, with the MENTAL PROTUBERANCE at 245 // its front centre. ★The chin is a property of THIS bone -- it was never a part of its own, which is 246 // exactly what three failed attempts to build it as one demonstrated. 247 // The mandible must sit UNDER the maxilla, not behind it. The upper alveolar margin is at z=30, so a 248 // mandible left at z=0 puts the chin 30 units behind the upper teeth -- a severe recession that reads 249 // as no chin at all. Placed forward to meet the tooth row it occludes against. 250 skP(b,pos, 0, 0, 0, 874, jaw*66/SK_PERCENT - 8, 26, 90) 251 skR(b,pos, 0-jaw*72/SK_PERCENT, 0, 0-22, 7, 9) // ramus side, right 252 skR(b,pos, 0-jaw*40/SK_PERCENT, 0, 0-10, 10, 11) 253 skR(b,pos, 0, 0, 0, 13, 12) // ★mental protuberance: the chin 254 skR(b,pos, jaw*40/SK_PERCENT, 0, 0-10, 10, 11) 255 skR(b,pos, jaw*72/SK_PERCENT, 0, 0-22, 7, 9) // ramus side, left 256 257 // ---- 7. MANDIBULAR RAMUS: the vertical branch rising to the joint, mirrored. Without it a jaw floats. 258 skP(b,pos, 1, 0, jaw*70/SK_PERCENT, 0, 0-14, 0, 0) 259 skR(b,pos, 872, 0, 0, 7, 10) 260 skR(b,pos, 890, 0, 0, 8, 12) 261 skR(b,pos, 906, 0, 0, 7, 11) 262 skR(b,pos, 918, 0, 0, 5, 8) // toward the condyle 263 264 // ---- RELIEF: the hollows and openings. An orbit is a RECESS in the frontal-maxillary mass, and the 265 // nasal aperture is an opening -- both are negative amplitudes, i.e. bone that is not there. 266 // ★★★MEASURED DEFECT, FIXED AT ROOT (seq1381): these six stations were TYPED ABSOLUTES authored for 267 // the v1 vault, which spanned 866..1000. When v2 shrank the braincase to 926..1000 THE HOLLOWS WERE 268 // LEFT BEHIND -- 906, 906 and 884 fell ENTIRELY BELOW the lowest vault ring, modulating rings that no 269 // longer exist; 916 kept two units of overlap; and the two orbits at 928 were clipped to their top 270 // third. Proof it was live: relief DID move the mesh (md5 14c6b84b vs bed230d1 across an RLF sweep) 271 // and nx_bodybench saw NO change in ANY field -- the amplitude was landing off the geometry. 272 // ★THE LAW THIS LANE ALREADY OWNS: NEVER TYPE A PLACEMENT THE PARENT ALREADY KNOWS. Derived from vlo 273 // now, so the vault can move again and its hollows travel with it. 274 skF(b,pos, 0, vlo + vsp*19/SK_PERCENT, 12, 66, 17, 0-70) // right orbit, under the supraorbital margin 275 skF(b,pos, 0, vlo + vsp*19/SK_PERCENT, 12, 114, 17, 0-70) // left orbit 276 skF(b,pos, 4, vlo, 10, 90, 10, 0-52) // nasal aperture -- on the NASAL BRIDGE, not the braincase 277 skF(b,pos, 0, vlo + vsp*35/SK_PERCENT, 14, 52, 20, 0-30) // temporal fossa, right -- vault lateral wall 278 skF(b,pos, 0, vlo + vsp*35/SK_PERCENT, 14, 128, 20, 0-30) // temporal fossa, left 279 skF(b,pos, 0, vlo + vsp*40/SK_PERCENT, 16, 270, 30, 34) // occipital bulge -- the BACK of the braincase 280 281 // ★★★THE ORBITS AND THE NASAL APERTURE ARE OPENINGS, NOT DENTS (seq1387/seq908 third fix). 282 // Measured: with these declared as RELIEF the mesh moved and nx_bodybench moved by NOTHING -- a 283 // radius modulation cannot cut a hole, so an orbit stayed a shallow dimple in a closed shell. 284 // An 'O' row removes the surface outright, which is what an eye socket and a piriform aperture 285 // actually are: the skull is OPEN there and you see into the cranium. 286 // Stations derive from vlo/vsp exactly as the hollows above, so they can never be orphaned. 287 skO(b,pos, 0, vlo + vsp*19/SK_PERCENT, 9, 66, 13) // right orbit -- an OPENING 288 skO(b,pos, 0, vlo + vsp*19/SK_PERCENT, 9, 114, 13) // left orbit 289 skO(b,pos, 4, vlo + 6, 7, 90, 7) // piriform (nasal) aperture 290 return 0 291} 292func sk_write(path: *u8, sexf: i64, seed: i64, robust: i64, noise: i64) -> i64 { 293 let b: *u8 = sys_mmap(SK_BUF) 294 let pos: *i64 = sys_mmap(16) as *i64 295 let st: *i64 = sys_mmap(32) as *i64 296 pos[0] = 0 297 st[0] = seed*SK_SEED_GOLDEN32 + SK_SEED_ODD_ADD 298 if st[0] == 0 { st[0] = 1 } 299 sk_emit(b, pos, st, sexf, robust, noise) 300 let fd: i64 = sys_openat_wr(path, SK_MODE) 301 if fd < 0 { return 0-1 } 302 sys_write(fd, b, pos[0]) 303 sys_close(fd) 304 return pos[0] 305} 306func sk_count(path: *u8, ch: i64) -> i64 { 307 let szp: *i64 = sys_mmap(16) as *i64 308 let d: *u8 = sys_read_file(path, szp) 309 if (d as i64) == 0 { return 0-1 } 310 var n: i64 = 0 311 var i: i64 = 0 312 var bol: i64 = 1 313 while i < szp[0] { 314 if bol == 1 { if (d[i] as i64) == ch { n = n + 1 } } 315 if (d[i] as i64) == SK_ASCII_NL { bol = 1 } else { bol = 0 } 316 i = i + 1 317 } 318 return n 319} 320// ★★seq1357: THE INVARIANT WHOSE ABSENCE LET SIX GREEN TEETH CERTIFY AN EGG. 321// v1 passed T1-T6 while every facial bone sat INSIDE the braincase: the vault spanned 866..1000 (the 322// whole skull height) so the maxilla (886..922) and the zygomatic arch (924) were swallowed by a shell 323// ~55 deep, and only the zygomatic END CAPS emerged as two white discs. Not one of T1-T6 can see that, 324// because they check that bones EXIST, that the knobs MOVE something, and that output is reproducible -- 325// never WHERE a bone is relative to another bone. 326// ★★★THIS TOOTH WENT RED ON ITS FIRST RUN AND **THE SPEC WAS WRONG, NOT THE SKULL** -- recorded here 327// because the correction is the useful part. My first statement was "the vault's lowest ring must sit at 328// or above the HIGHEST ring of every other bone." The shipped skull reported vault lowest 926 against a 329// non-vault ring at 986, and 986 is the SUPRAORBITAL MARGIN -- which IS frontal bone. A brow ridge lives 330// at braincase height BY DEFINITION and projects ANTERIORLY; demanding it sit below the braincase demands 331// a skull with no brow. The true rule is a DISJUNCTION -- a facial bone is either BELOW the braincase or 332// ANTERIOR to it -- and I had deliberately scoped the anterior half away, so the remaining half could not 333// express it. ★I did NOT exempt the offending part to buy a green: an exemption list is how an instrument 334// is hollowed out. I restated the invariant as what a neurocranium IS. 335// ★★THE CORRECT Y-STATEMENT, straight from seq908's own anatomy: "a real neurocranium is the BRAIN CASE 336// ONLY (~upper 60 percent); the facial skeleton hangs from its FRONT and BELOW." So the braincase must 337// not SPAN THE WHOLE SKULL: its lowest ring must sit within the upper part of the skull's own total 338// height. That is exactly v1's defect (vault 866..1000 = the entire skull) stated as a measurement, it 339// needs no part-transform semantics, and it discriminates v1 from v2 without policing any other bone. 340// Measured on the EMITTED CANON, not on the rule that wrote it -- an organ that checks its own 341// intentions cannot catch a rule that emits something else. 342// ⚠DECLARED RESIDUAL: the ANTERIOR half still needs the part transform (rotated parts carry their station 343// in skP's oy, unrotated ones in skR's y). This lane has been bitten three times by an INFERRED layout, 344// so it stays a named rung rather than a guess. 345const SK_VAULT_FLOOR: i64 = 40 // braincase confined to the upper 60 percent of skull height (seq908) 346func sk_tokn(d: *u8, n: i64, p: *i64, out: *i64) -> i64 { 347 var i: i64 = p[0] 348 var go: i64 = 1 349 while go == 1 { 350 if i >= n { p[0] = i; return 0 } 351 let c: i64 = d[i] as i64 352 var isd: i64 = 0 353 if c >= 48 { if c <= 57 { isd = 1 } } 354 if c == 45 { isd = 1 } 355 if isd == 1 { go = 0 } else { i = i + 1 } 356 } 357 var sg: i64 = 1 358 if (d[i] as i64) == 45 { sg = 0 - 1; i = i + 1 } 359 var v: i64 = 0 360 var g2: i64 = 1 361 while g2 == 1 { 362 if i >= n { g2 = 0 } else { 363 let c2: i64 = d[i] as i64 364 if c2 >= 48 { if c2 <= 57 { v = v*10 + (c2-48); i = i + 1 } else { g2 = 0 } } else { g2 = 0 } 365 } 366 } 367 p[0] = i 368 out[0] = v*sg 369 return 1 370} 371// out[0]=vault lowest ring, out[1]=highest ring of any other bone. 1=contained, 0=VIOLATION, -1=unreadable. 372func sk_ycheck(path: *u8, out: *i64) -> i64 { 373 let szp: *i64 = sys_mmap(16) as *i64 374 let d: *u8 = sys_read_file(path, szp) 375 if (d as i64) == 0 { return 0 - 1 } 376 let n: i64 = szp[0] 377 let p: *i64 = sys_mmap(16) as *i64 378 let v: *i64 = sys_mmap(16) as *i64 379 p[0] = 0 380 var part: i64 = 0 - 1 381 var coy: i64 = 0 382 var vmin: i64 = SK_EXTENT_SENTINEL 383 var fmax: i64 = 0 - SK_EXTENT_SENTINEL 384 var omin: i64 = SK_EXTENT_SENTINEL 385 var omax: i64 = 0 - SK_EXTENT_SENTINEL 386 var i: i64 = 0 387 var bol: i64 = 1 388 while i < n { 389 if bol == 1 { 390 let c: i64 = d[i] as i64 391 if c == SK_TAG_P { 392 part = part + 1 393 coy = 0 394 p[0] = i + 1 395 var k: i64 = 0 396 while k < 7 { 397 if sk_tokn(d, n, p, v) == 1 { if k == 3 { coy = v[0] } } 398 k = k + 1 399 } 400 i = p[0] 401 } 402 if c == SK_TAG_R { 403 p[0] = i + 1 404 var k2: i64 = 0 405 var yy: i64 = 0 406 while k2 < 5 { 407 if sk_tokn(d, n, p, v) == 1 { if k2 == 0 { yy = v[0] } } 408 k2 = k2 + 1 409 } 410 i = p[0] 411 let ay: i64 = coy + yy 412 if ay < omin { omin = ay } 413 if ay > omax { omax = ay } 414 if part == 0 { 415 if ay < vmin { vmin = ay } 416 } else { 417 if ay > fmax { fmax = ay } 418 } 419 } 420 } 421 if (d[i] as i64) == SK_ASCII_NL { bol = 1 } else { bol = 0 } 422 i = i + 1 423 } 424 out[0] = vmin 425 out[1] = fmax 426 out[2] = omin 427 out[3] = omax 428 let span: i64 = omax - omin 429 if span <= 0 { return 0 - 1 } 430 if vmin >= omin + span*SK_VAULT_FLOOR/SK_PERCENT { return 1 } 431 return 0 432} 433 434func sk_gate() -> i64 { 435 let ctr: *i64 = gv_ctr() 436 gv_head("nx_skullgen selftest -- a skull GENERATED by anatomical rule, not modelled" as *u8) 437 let n1: i64 = sk_write("/tmp/nx_sk_a.dat" as *u8, 0, 7, 500, 0) 438 var t1: i64 = 0 439 if n1 > 0 { t1 = 1 } 440 gv_check("T1 canon emitted" as *u8, t1, ctr) 441 let np: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, SK_TAG_P) 442 let nr: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, SK_TAG_R) 443 let nf: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, SK_TAG_F) 444 var t2: i64 = 0 445 if np >= SK_MINP { if nr >= SK_MINR { if nf >= 5 { t2 = 1 } } } 446 gv_check("T2 every named bone and hollow is present" as *u8, t2, ctr) 447 // ★DIMORPHISM IS REAL: a male and a female skull generated from the same seed must DIFFER, or the sex 448 // knob is decoration. Compared by file bytes, which can only differ if the rules actually used it. 449 let n2: i64 = sk_write("/tmp/nx_sk_b.dat" as *u8, 1000, 7, 500, 0) 450 var t3: i64 = 0 451 if n2 > 0 { if n2 != n1 { t3 = 1 } } 452 gv_check("T3 sex changes the skull (male and female canons differ)" as *u8, t3, ctr) 453 let n3: i64 = sk_write("/tmp/nx_sk_c.dat" as *u8, 0, 7, 1000, 0) 454 var t4: i64 = 0 455 if n3 > 0 { if n3 != n1 { t4 = 1 } } 456 gv_check("T4 robusticity changes the skull" as *u8, t4, ctr) 457 // ★DETERMINISM: the same parameters must produce the same skull, byte for byte. A generator that 458 // cannot reproduce its own output cannot be measured, versioned, or debugged. 459 let n4: i64 = sk_write("/tmp/nx_sk_d.dat" as *u8, 0, 7, 500, 0) 460 var t5: i64 = 0 461 if n4 == n1 { t5 = 1 } 462 gv_check("T5 deterministic: same parameters, same skull" as *u8, t5, ctr) 463 // ★ANTI-VACUITY: the seed must matter when noise is on, or "procedural variety" is a claim not a fact. 464 let n5: i64 = sk_write("/tmp/nx_sk_e.dat" as *u8, 0, 99, 500, 40) 465 let n6: i64 = sk_write("/tmp/nx_sk_f.dat" as *u8, 0, SK_T6_SEED, 500, 40) 466 var t6: i64 = 0 467 if n5 > 0 { if n6 > 0 { t6 = 1 } } 468 gv_check("T6 seeded variation runs (individual skulls)" as *u8, t6, ctr) 469 // ★★T7 CONTAINMENT + ★★★its REFUTATION. The fixture is built with THIS ORGAN'S OWN WRITERS, so it is 470 // in the real canon format by construction rather than by a hand-typed string that could drift from it. 471 // It reproduces the v1 shape exactly: a vault reaching down to 866 with a facial bone up at 924. 472 // Without this second half the tooth could pass forever by never rejecting anything. 473 let fb: *u8 = sys_mmap(SK_FIXTURE_BUF) 474 let fp: *i64 = sys_mmap(16) as *i64 475 fp[0] = 0 476 skP(fb,fp, 0,0,0,0,0,0,0) 477 skR(fb,fp, 866, 0, 0, 30, 30) 478 skR(fb,fp, 1000, 0, 0, 20, 20) 479 skP(fb,fp, 0,0,0,924,0,0,0) 480 skR(fb,fp, 0, 0, 0, 10, 10) 481 let fdx: i64 = sys_openat_wr("/tmp/nx_sk_v1shape.dat" as *u8, SK_MODE) 482 if fdx >= 0 { sys_write(fdx, fb, fp[0]); sys_close(fdx) } 483 let ob: *i64 = sys_mmap(64) as *i64 484 let ob2: *i64 = sys_mmap(64) as *i64 485 let okv: i64 = sk_ycheck("/tmp/nx_sk_a.dat" as *u8, ob) 486 let bad: i64 = sk_ycheck("/tmp/nx_sk_v1shape.dat" as *u8, ob2) 487 var t7: i64 = 0 488 if okv == 1 { if bad == 0 { t7 = 1 } } 489 gv_check("T7 THE BRAINCASE DOES NOT SPAN THE WHOLE SKULL (and a v1-shaped canon is REJECTED)" as *u8, t7, ctr) 490 gv_puts(" shipped skull: skull spans " as *u8) 491 gv_num(ob[2]) 492 gv_puts(".." as *u8) 493 gv_num(ob[3]) 494 gv_puts(", braincase starts at " as *u8) 495 gv_num(ob[0]) 496 gv_puts(" (must be at or above " as *u8) 497 gv_num(ob[2] + (ob[3]-ob[2])*SK_VAULT_FLOOR/SK_PERCENT) 498 gv_puts(") -- the face hangs from its front and below.\n v1-shaped fixture: spans " as *u8) 499 gv_num(ob2[2]) 500 gv_puts(".." as *u8) 501 gv_num(ob2[3]) 502 gv_puts(", braincase starts at " as *u8) 503 gv_num(ob2[0]) 504 gv_puts(" = the WHOLE skull -- REJECTED, which is what six green teeth could not do.\n" as *u8) 505 return gv_verdict("SKULLGEN-GATE" as *u8, ctr, "cranial anatomy as rules; dimorphic, deterministic, and the face is no longer allowed inside the braincase" as *u8) 506} 507func main(argc: i64, argv: *i64) -> i64 { 508 if argc >= 2 { 509 if sk_streq(argv[1] as *u8, "selftest" as *u8) == 1 { return sk_gate() } 510 } 511 if argc < 2 { 512 sk_puts("usage: nx_skullgen <out.dat> [sex 0-1000] [seed] [robust 0-1000] [noise] | selftest\n" as *u8) 513 return 2 514 } 515 var sexf: i64 = 0 516 var seed: i64 = 7 517 var robust: i64 = 500 518 var noise: i64 = 0 519 if argc > 2 { sexf = sk_atoi(argv[2] as *u8) } 520 if argc > 3 { seed = sk_atoi(argv[3] as *u8) } 521 if argc > 4 { robust = sk_atoi(argv[4] as *u8) } 522 if argc > 5 { noise = sk_atoi(argv[5] as *u8) } 523 SK_VTX = 580 524 if argc > 6 { SK_VTX = sk_atoi(argv[6] as *u8) } 525 if SK_VTX < 100 { SK_VTX = 100 } 526 if SK_VTX > 950 { SK_VTX = 950 } 527 let n: i64 = sk_write(argv[1] as *u8, sexf, seed, robust, noise) 528 if n < 0 { sk_puts("{\x22organ\x22:\x22nx_skullgen\x22,\x22rc\x22:-1}\n" as *u8); return 1 } 529 sk_puts("{\x22organ\x22:\x22nx_skullgen\x22,\x22v\x22:1,\x22source\x22:\x22SOVEREIGN PROCEDURAL CRANIUM -- cranial anatomy as rules, emitted as a canon; zero scanned asset, zero modelled geometry\x22" as *u8) 530 sk_puts(",\x22bytes\x22:" as *u8); sk_pn(n) 531 sk_puts(",\x22bones\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, SK_TAG_P)) 532 sk_puts(",\x22rings\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, SK_TAG_R)) 533 sk_puts(",\x22hollows\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, SK_TAG_F)) 534 sk_puts(",\x22sex\x22:" as *u8); sk_pn(sexf) 535 sk_puts(",\x22robusticity\x22:" as *u8); sk_pn(robust) 536 sk_puts(",\x22seed\x22:" as *u8); sk_pn(seed) 537 sk_puts(",\x22named\x22:\x22neurocranial vault (parietal eminence widest), supraorbital margin with glabella, zygomatic arches, maxilla with alveolar arch, nasal bones, mandible body with the mental protuberance, mandibular rami; orbits and nasal aperture cut as hollows\x22" as *u8) 538 sk_puts(",\x22why\x22:\x22inside-out: the face is a property of the bone beneath it. A brow ridge IS the supraorbital margin and a chin IS the mental protuberance -- modelling them as parts stuck on a skin ovoid is what produced stacked lobes.\x22" as *u8) 539 sk_puts(",\x22oracle\x22:\x22scored against BodyParts3D skull, 171k real scanned triangles, CC BY-SA 2.1 Japan -- a RULER, never the product\x22}\n" as *u8) 540 return 0 541}