code wiki / _hdl_build / nx_faceanat_morph_gate.nx
nx_faceanat_morph_gate.nx source
↩ module page · 135 lines · 6795 B
1// nx_faceanat_morph_gate.nx -- ★B-R6 PARAMETRIC MORPH BASIS (operator: our own base mesh better than DAZ). Prove
2// distinct IDENTITIES from ONE anatomical base by DELTAS on the canon/tissue-depth numbers -- a parametric
3// morphable model (the census's 'learned shape basis' gap) built from anatomy. DAZ ships fixed artist-sculpt
4// morphs; ours are adjustable anthropometric axes (width/length/jaw/eyes/lips/cheek), MEASURED.
5// T1 pct=100 morph is IDENTITY (no geometry change) -- additive, zero regression
6// T2 a morph MEASURABLY changes geometry (width 120 grows the face x-extent ~20%; symmetry preserved)
7// T3 ★3 distinct IDENTITIES render as 3 different faces (pairwise render-diff), each a valid figure
8// T4 morphs COMPOSE + a morphed identity still MESHES WATERTIGHT (Euler) + determinism + 3-up PNG
9// license_tier: ORIGINAL expect_exit: 0
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12import "nx_sdfrender_mt.nx"
13import "nx_faceanat.nx"
14import "nx_makeup.nx"
15import "nx_meshgen.nx"
16import "nx_png.nx"
17
18func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
19func 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 }
20func fbdiff(a: *i64, b: *i64, n: i64) -> i64 { var d: i64=0; var i: i64=0; while i<n { if a[i]!=b[i] { d=d+1 } i=i+1 } return d }
21// max |cx| over the face parts 0..26 (the silhouette half-width proxy)
22func xextent(base: i64) -> i64 {
23 let p: *i64 = (base + O_PARTS) as *i64
24 var m: i64 = 0
25 var i: i64 = 0
26 while i < 27 { var a: i64 = p[i*6]; if a < 0 { a = 0 - a } a = a + p[i*6+3]; if a > m { m = a } i = i + 1 }
27 return m
28}
29// build styled identity (hair + makeup) then apply an identity's morph combo (id: 0=A neutral,1=B soft,2=C angular)
30func build_id(base: i64, id: i64) -> i64 {
31 faceanat_build(base)
32 let nf: i64 = sdf_face_hairstyle(base, HS_LONG)
33 makeup_style2(base, nf, MKUP_GLAM)
34 if id == 1 { faceanat_morph_width(base,116); faceanat_morph_eyes(base,120); faceanat_morph_lips(base,132); faceanat_morph_cheek(base,88) }
35 if id == 2 { faceanat_morph_width(base,90); faceanat_morph_length(base,110); faceanat_morph_jaw(base,118); faceanat_morph_lips(base,84); faceanat_morph_cheek(base,122) }
36 return 0
37}
38
39func main() -> i64 {
40 hw("=== nx_faceanat_morph_gate -- parametric IDENTITIES from one anatomical base (exceed-DAZ morphs) ===\n" as *u8)
41 let ctr: *i64 = gv_ctr()
42 let npx: i64 = ww() * hh()
43 let base: i64 = sys_mmap(sdf_bytes()) as i64
44 let fb: *i64 = (base + fb_off()) as *i64
45
46 // T1 pct=100 identity
47 faceanat_build(base)
48 let x0: i64 = xextent(base)
49 faceanat_morph_width(base, 100)
50 faceanat_morph_length(base, 100)
51 let x1: i64 = xextent(base)
52 hw(" x-extent neutral="); pn(x0); hw(" after pct=100 morphs="); pn(x1); hw("\n" as *u8)
53 var t1: i64 = 0
54 if x0 == x1 { t1 = 1 }
55 gv_check("T1 pct=100 morph is IDENTITY (additive, zero regression)" as *u8, t1, ctr)
56
57 // T2 width 120 grows extent ~20%
58 faceanat_build(base)
59 let xa: i64 = xextent(base)
60 faceanat_morph_width(base, 120)
61 let xb: i64 = xextent(base)
62 hw(" width120: extent "); pn(xa); hw(" -> "); pn(xb); hw(" (expect ~"); pn(xa*120/100); hw(")\n" as *u8)
63 var t2: i64 = 0
64 // cross-multiply, never divide: y*N/M truncates the bar BEFORE comparing (silent shift; with > it banks a false PASS)
65 if xb * 100 > xa * 117 { if xb * 100 < xa * 123 { t2 = 1 } }
66 gv_check("T2 width morph measurably scales the face (real anthropometric axis)" as *u8, t2, ctr)
67
68 // T3 three distinct identities (no projection -> pure geometry+shading difference)
69 let A: *i64 = sys_mmap(npx*8) as *i64
70 let B: *i64 = sys_mmap(npx*8) as *i64
71 let C: *i64 = sys_mmap(npx*8) as *i64
72 build_id(base, 0)
73 sdfmt_render(base, 0, 4, 236, 180, 156, 0)
74 var k: i64 = 0
75 while k < npx { A[k] = fb[k]; k = k + 1 }
76 build_id(base, 1)
77 sdfmt_render(base, 0, 4, 236, 180, 156, 0)
78 k = 0
79 while k < npx { B[k] = fb[k]; k = k + 1 }
80 build_id(base, 2)
81 sdfmt_render(base, 0, 4, 236, 180, 156, 0)
82 k = 0
83 while k < npx { C[k] = fb[k]; k = k + 1 }
84 let dAB: i64 = fbdiff(A, B, npx)
85 let dAC: i64 = fbdiff(A, C, npx)
86 let dBC: i64 = fbdiff(B, C, npx)
87 hw(" identity render-diffs: A-B="); pn(dAB); hw(" A-C="); pn(dAC); hw(" B-C="); pn(dBC); hw("\n" as *u8)
88 var t3: i64 = 0
89 if dAB > 4000 { if dAC > 4000 { if dBC > 4000 { t3 = 1 } } }
90 gv_check("T3 3 DISTINCT identities from ONE parametric base (each a different face)" as *u8, t3, ctr)
91
92 // T4 a morphed identity still MESHES watertight + determinism + 3-up PNG
93 let Fg: *i64 = sys_mmap((MG_N + 1) * (MG_N + 1) * (MG_N + 1) * 8) as *i64
94 let cubevi: *i64 = sys_mmap(MG_N * MG_N * MG_N * 8) as *i64
95 let vbuf: *i64 = sys_mmap(MG_MAXV * 3 * 8) as *i64
96 let fbuf: *i64 = sys_mmap(MG_MAXF * 3 * 8) as *i64
97 let mo: *i64 = sys_mmap(16) as *i64
98 faceanat_build(base)
99 faceanat_morph_width(base, 90); faceanat_morph_jaw(base, 118) // identity C's face morphs (no hair/makeup for mesh)
100 mg_build(base, Fg, cubevi, vbuf, fbuf, mo)
101 let nv: i64 = mo[0]
102 let nf: i64 = mo[1]
103 let expv: i64 = nf / 2 + 2
104 var dv: i64 = nv - expv
105 if dv < 0 { dv = 0 - dv }
106 hw(" morphed identity C mesh: v="); pn(nv); hw(" f="); pn(nf); hw(" Euler-delta="); pn(dv); hw("\n" as *u8)
107 // determinism of an identity render
108 build_id(base, 1)
109 sdfmt_render(base, 0, 4, 236, 180, 156, 0)
110 let dDet: i64 = fbdiff(B, fb, npx)
111 // 3-up PNG
112 let W3: i64 = ww() * 3
113 let combo: *i64 = sys_mmap(W3 * hh() * 8) as *i64
114 var yy: i64 = 0
115 while yy < hh() {
116 var xx: i64 = 0
117 while xx < ww() {
118 combo[yy*W3 + xx] = A[yy*ww()+xx]
119 combo[yy*W3 + ww() + xx] = B[yy*ww()+xx]
120 combo[yy*W3 + ww()*2 + xx] = C[yy*ww()+xx]
121 xx = xx + 1
122 }
123 yy = yy + 1
124 }
125 write_png(combo, W3, hh(), "knowledge/nx_faceanat_ids.png" as *u8)
126 var t4: i64 = 0
127 // cross-multiply, never divide (was dv < nf/16 and dDet < npx/300 -- truncated bars)
128 if dv * 16 < nf { if dDet * 300 < npx { t4 = 1 } } // watertight + deterministic within mt floor
129 gv_check("T4 morphed identity meshes WATERTIGHT + deterministic + 3-up PNG" as *u8, t4, ctr)
130
131 hw(" parametric morphable model: distinct identities from one anatomical base = the exceed-DAZ character system\n" as *u8)
132 let rc: i64 = gv_verdict("FACEANAT-MORPH-GATE" as *u8, ctr, "parametric identities, watertight-meshable" as *u8)
133 sys_exit(rc)
134 return rc
135}