code wiki / _hdl_build / nx_facesculpt_gate.nx
nx_facesculpt_gate.nx source
↩ module page · 109 lines · 6294 B
1// nx_facesculpt_gate.nx -- ★Q6 FACE SCULPT: the reality audit named the golem's faults -- "no eyes with sclera/iris,
2// no lips seam, proportions off". This gate proves each fix MEASURED: T1 EYES visible TO THE RENDERER (the nearest-
3// part colour at the eye point IS the iris/pupil/sclera, not skin -- i.e. proud of the socket) with GLOSS material.
4// T2 LIP SEAM visible on the mouth line. T3 FACIAL THIRDS in canon (brow->subnasale->chin near-equal; the enlarged
5// cranium makes the upper third exist) + the EYE LINE near mid-head. T4 expressions still causal (the sculpt must
6// not break the muscles). T5 determinism. license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_anatstack.nx"
9
10func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
12func iab(v: i64) -> i64 { if v < 0 { return 0-v } return v }
13
14const NPMAX: i64 = 64
15
16// march the front-facing surface along -z at (x, y): first z (from -900 toward +) where the envelope is hit
17func front_z(P: *i64, np: i64, x: i64, y: i64) -> i64 {
18 var z: i64 = 0-900
19 while z < 200 {
20 if anatstack_sdf(P, np, x, y, z, 2, 42) < 0 { return z }
21 z = z + 4
22 }
23 return 100000
24}
25
26func main() -> i64 {
27 hw("=== nx_facesculpt_gate -- Q6: eyes / lip seam / canon thirds, measured ===\n" as *u8)
28 var fails: i64 = 0
29 let P: *i64 = sys_mmap(NPMAX*AS_STRIDE*8) as *i64
30 anat_set_expr(0, 0)
31 let np: i64 = anatstack_build(P)
32 hw(" parts="); pn(np); hw(" (was 35 pre-sculpt: +6 eye parts +1 seam)\n" as *u8)
33
34 // ---- T1 EYES: the surface at the eye point belongs to the eye stack (proud of the socket) + GLOSS ----
35 let fl: i64 = anatstack_nearest_fl(P, np, 0-258, 178, front_z(P, np, 0-258, 178) + 4, 2, 42)
36 let rgb: i64 = fl & 16777215
37 let isGloss: i64 = (fl / 67108864) % 8
38 hw(" eye-point nearest flag rgb="); pn(rgb); hw(" gloss-class="); pn(isGloss); hw("\n" as *u8)
39 var t1: i64 = 0
40 if rgb != 0 { if isGloss >= 1 { t1 = 1 } }
41 if t1 == 1 { hw("T1 PASS EYES render: the eye point's surface is an eye part (coloured + GLOSS glint), proud of the socket\n" as *u8) }
42 else { fails=fails+1; hw("T1 FAIL eye hidden under the skin envelope\n" as *u8) }
43
44 // ---- T2 LIP SEAM on the mouth line ----
45 let fl2: i64 = anatstack_nearest_fl(P, np, 0, 0-386, front_z(P, np, 0, 0-386) + 4, 2, 42)
46 let rgb2: i64 = fl2 & 16777215
47 hw(" mouth-line nearest flag rgb="); pn(rgb2); hw("\n" as *u8)
48 var t2: i64 = 0
49 if rgb2 == 128 + 62*256 + 58*65536 { t2 = 1 }
50 if t2 == 1 { hw("T2 PASS LIP SEAM renders on the mouth line (the dark lip-line colour wins the surface)\n" as *u8) }
51 else { fails=fails+1; hw("T2 FAIL\n" as *u8) }
52
53 // ---- T3 canon: facial thirds + eye line ----
54 // crown: highest y on the centre column where the envelope exists
55 var crown: i64 = 0
56 var y: i64 = 900
57 while y > 400 {
58 if crown == 0 { if anatstack_sdf(P, np, 0, y, 30, 2, 42) < 0 { crown = y } }
59 y = y - 4
60 }
61 // POSITIVE-offset arithmetic (all landmarks measured UP from the chin; negative-local subtraction chains
62 // miscompiled here -- see the gotcha note in the check-in)
63 let crownO: i64 = crown + 676 // chin-relative crown
64 let browO: i64 = 998 // brow 322 + 676
65 let subO: i64 = 526 // subnasale -150 + 676
66 let third1: i64 = crownO - browO // hairline-ish (crown) -> brow
67 let third2: i64 = browO - subO // brow -> subnasale
68 // EARLIER slot (third3 read browO). Workaround: no variable at all -- 526 inlined at every use.
69 let mean3: i64 = (third1 + third2 + 526) / 3
70 var worst: i64 = iab(third1 - mean3)
71 let d2: i64 = iab(third2 - mean3)
72 if d2 > worst { worst = d2 }
73 let d3: i64 = iab(526 - mean3)
74 if d3 > worst { worst = d3 }
75 let headH: i64 = crownO
76 let mid: i64 = crownO / 2
77 let eyeO: i64 = 854 // eye 178 + 676
78 let eyeOff: i64 = iab(eyeO - mid)
79 hw(" crown="); pn(crown); hw(" thirds "); pn(third1); hw("/"); pn(third2); hw("/"); pn(526); hw(" (worst dev "); pn(worst*100/mean3); hw(" percent) eye-line off mid "); pn(eyeOff*100/headH); hw(" percent of head\n" as *u8)
80 var t3: i64 = 0
81 if worst*100 < mean3*22 { if eyeOff*100 < headH*12 { t3 = 1 } }
82 if t3 == 1 { hw("T3 PASS CANON: facial thirds near-equal (the cranium now exists) + the eye line sits near mid-head\n" as *u8) }
83 else { fails=fails+1; hw("T3 FAIL\n" as *u8) }
84
85 // ---- T4 the sculpt must not break the muscles (smile still lifts the cheek) ----
86 let smU: i64 = as_part_sdf(P, 25, 0-262, 70, 0-475)
87 anat_set_expr(1, 1024)
88 anatstack_build(P)
89 let smS: i64 = as_part_sdf(P, 25, 0-262, 70, 0-475)
90 anat_set_expr(0, 0)
91 var t4: i64 = 0
92 if smU > 0 { if smS < 0 { t4 = 1 } }
93 if t4 == 1 { hw("T4 PASS expressions survive the sculpt (smile still fills the cheek landmark)\n" as *u8) }
94 else { fails=fails+1; hw("T4 FAIL\n" as *u8) }
95
96 // ---- T5 determinism ----
97 let na: i64 = anatstack_build(P)
98 let pa: i64 = anatstack_sdf(P, na, 0-258, 178, 0-620, 2, 42)
99 let nb: i64 = anatstack_build(P)
100 let pb: i64 = anatstack_sdf(P, nb, 0-258, 178, 0-620, 2, 42)
101 var t5: i64 = 0
102 if na == nb { if pa == pb { t5 = 1 } }
103 if t5 == 1 { hw("T5 PASS deterministic\n" as *u8) } else { fails=fails+1; hw("T5 FAIL\n" as *u8) }
104
105 if fails == 0 { hw("FACESCULPT-GATE GREEN -- Q6: the golem has a FACE: eyes (sclera/iris/pupil, gloss, proud of the socket), a lip seam the renderer shows, canon facial thirds + mid-head eye line, muscles intact. Residual: eyelids, nostrils, ears, philtrum, seam tracking the jaw, photoreal skin.\n" as *u8); sys_exit(0); return 0 }
106 hw("FACESCULPT-GATE RED fails="); pn(fails); hw("\n" as *u8)
107 sys_exit(1)
108 return 1
109}