code wiki / _hdl_build / nx_faceanat_hires_gate.nx
nx_faceanat_hires_gate.nx source
↩ module page · 98 lines · 5035 B
1// nx_faceanat_hires_gate.nx -- ★B-R5 RESOLUTION (operator: our own base mesh better than DAZ). Zero-surgery
2// density lift: scale the anatomical face UP to fill the fixed surface-nets grid -> many more cells across the
3// object -> a much DENSER mesh at the SAME meshgen resolution; then scale the verts back to 1x. Gets our base
4// mesh from ~4.5k verts toward DAZ Genesis density (~17k) with NO change to the shared nx_meshgen.
5// T1 density LIFT: the scaled mesh has >=1.7x the base-mesh vert count (finer surface)
6// T2 ★WATERTIGHT preserved at hi-res (Euler V=F/2+2) -- density without holes = the DAZ-quality bar held
7// T3 scale-back restores the 1x size (AABB ~ the base mesh's) = a usable denser base mesh
8// T4 valid glTF export + determinism
9// license_tier: ORIGINAL expect_exit: 0
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12import "nx_faceanat.nx"
13import "nx_meshgen.nx"
14import "nx_gltf_export.nx"
15
16func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
17func 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 }
18func xspan(vbuf: *i64, nv: i64, axis: i64) -> i64 {
19 var mn: i64 = 9999999
20 var mx: i64 = 0 - 9999999
21 var i: i64 = 0
22 while i < nv { let v: i64 = vbuf[i*3+axis]; if v < mn { mn = v } if v > mx { mx = v } i = i + 1 }
23 return mx - mn
24}
25
26const SCALE: i64 = 160 // fill the grid: skull top 880*1.6=1408 < 1500 (fits, no clip)
27
28func main() -> i64 {
29 hw("=== nx_faceanat_hires_gate -- denser base mesh via grid-fill scaling (exceed-DAZ density) ===\n" as *u8)
30 let ctr: *i64 = gv_ctr()
31 let F: *i64 = sys_mmap((MG_N + 1) * (MG_N + 1) * (MG_N + 1) * 8) as *i64
32 let cubevi: *i64 = sys_mmap(MG_N * MG_N * MG_N * 8) as *i64
33 let vbuf: *i64 = sys_mmap(MG_MAXV * 3 * 8) as *i64
34 let fbuf: *i64 = sys_mmap(MG_MAXF * 3 * 8) as *i64
35 let out: *i64 = sys_mmap(16) as *i64
36 let base: i64 = sys_mmap(sdf_bytes()) as i64
37
38 // base-resolution mesh (no hair -> the base face mesh)
39 faceanat_build(base)
40 mg_build(base, F, cubevi, vbuf, fbuf, out)
41 let nv0: i64 = out[0]
42 let nf0: i64 = out[1]
43 hw(" base-res mesh: v="); pn(nv0); hw(" f="); pn(nf0); hw("\n" as *u8)
44
45 // hi-res: scale UP to fill the grid, mesh at the same resolution
46 faceanat_build(base)
47 faceanat_scale(base, SCALE)
48 mg_build(base, F, cubevi, vbuf, fbuf, out)
49 let nv1: i64 = out[0]
50 let nf1: i64 = out[1]
51 let spanY_scaled: i64 = xspan(vbuf, nv1, 1)
52 hw(" hi-res mesh (scaled "); pn(SCALE); hw("%): v="); pn(nv1); hw(" f="); pn(nf1); hw("\n" as *u8)
53
54 // T1 density lift
55 hw(" density lift: "); pn(nv0); hw(" -> "); pn(nv1); hw(" verts ("); pn(nv1*100/nv0); hw("% of base)\n" as *u8)
56 var t1: i64 = 0
57 // cross-multiply, never divide: a truncated bar with > banks a false PASS
58 if nv1 * 10 > nv0 * 17 { t1 = 1 }
59 gv_check("T1 density LIFT >=1.7x (toward DAZ Genesis ~17k), zero meshgen change" as *u8, t1, ctr)
60
61 // T2 watertight at hi-res
62 let expv: i64 = nf1 / 2 + 2
63 var dv: i64 = nv1 - expv
64 if dv < 0 { dv = 0 - dv }
65 hw(" Euler: V="); pn(nv1); hw(" F/2+2="); pn(expv); hw(" delta="); pn(dv); hw(" tol="); pn(nf1/16); hw("\n" as *u8)
66 var t2: i64 = 0
67 // cross-multiply, never divide (was dv < nf1/16 -- truncated bar)
68 if dv * 16 < nf1 { t2 = 1 }
69 gv_check("T2 WATERTIGHT preserved at hi-res (density without holes)" as *u8, t2, ctr)
70
71 // T3 scale the verts back to 1x -> usable denser base mesh; AABB ~ base
72 var vi: i64 = 0
73 while vi < nv1 * 3 { vbuf[vi] = vbuf[vi] * 100 / SCALE; vi = vi + 1 }
74 let spanY_1x: i64 = xspan(vbuf, nv1, 1)
75 hw(" scale-back: hi-res Y-span "); pn(spanY_scaled); hw(" -> "); pn(spanY_1x); hw(" (1x); base mesh Y-span ~"); pn(spanY_scaled*100/SCALE); hw("\n" as *u8)
76 var t3: i64 = 0
77 let want: i64 = spanY_scaled * 100 / SCALE
78 var d3: i64 = spanY_1x - want
79 if d3 < 0 { d3 = 0 - d3 }
80 if d3 < 20 { t3 = 1 }
81 gv_check("T3 scale-back restores 1x size = a usable denser base mesh" as *u8, t3, ctr)
82
83 // T4 export + determinism
84 let glblen: i64 = write_glb(vbuf, fbuf, nv1, nf1, "knowledge/faceanat_hires.glb" as *u8)
85 hw(" wrote knowledge/faceanat_hires.glb ("); pn(glblen); hw(" bytes)\n" as *u8)
86 let out2: *i64 = sys_mmap(16) as *i64
87 faceanat_build(base)
88 faceanat_scale(base, SCALE)
89 mg_build(base, F, cubevi, vbuf, fbuf, out2)
90 var t4: i64 = 0
91 if glblen > 0 { if out2[0] == nv1 { if out2[1] == nf1 { t4 = 1 } } }
92 gv_check("T4 valid glTF + deterministic" as *u8, t4, ctr)
93
94 hw(" denser base mesh verts=" as *u8); pn(nv1); hw(" (toward DAZ ~17k), ZERO meshgen surgery\n" as *u8)
95 let rc: i64 = gv_verdict("FACEANAT-HIRES-GATE" as *u8, ctr, "denser base mesh, watertight, glTF-exported" as *u8)
96 sys_exit(rc)
97 return rc
98}