nx_garment_gen_gate.nx source
↩ module page · 147 lines · 8005 B
1// nx_garment_gen_gate.nx -- THE GATE FOR THE GARMENT MESH GENERATOR (2026-08-30). In-process: it imports
2// nx_garment_gen_lib and grows every garment on the SERVED NPC asset, so there is no stale artifact between
3// the rule and the subject and a mutation of the lib reaches every tooth. Teeth per kind: triangles present
4// . hems closed and manifold . one hem strip per boundary edge . shell clear of the skin by the fabric
5// thickness . straps present and ending on their landmarks; then determinism (a second build folds to the
6// same checksum), the served GARM (when shipped) identical to a fresh build, and two bite-proven controls:
7// zero thickness is REFUSED, and the clearance tooth FIRES on an un-pushed shell (so it is not vacuous).
8//
9// nx_garment_gen_gate [asset.nxa] [served.nxa] defaults: sites/nishifamily/world/ref9d.nxa, ref9e.nxa
10// EXIT: 0 GREEN . 1 RED . 3 SKIP (the asset could not be read -- no evidence about the generator)
11// license_tier: ORIGINAL. No hw writes (Rule 26). No fixture written anywhere.
12import "nx_syscalls.nx"
13import "nx_nxa.nx"
14import "nx_gate_verdict.nx"
15import "nx_garment_gen_lib.nx"
16
17const GGG_ASSET_DEFAULT: *u8 = "sites/nishifamily/world/ref9d.nxa"
18const GGG_SERVED_DEFAULT: *u8 = "sites/nishifamily/world/ref9e.nxa"
19const GGG_STRAP_TOL_DM: i64 = 700 // the strap sampler's own search band: an end inside it is ON the landmark
20
21func ggg_name(buf: *u8, k: i64, tail: *u8) -> *u8 {
22 var p: i64 = 0
23 buf[p] = 107 as u8; p = p + 1
24 buf[p] = (48 + k) as u8; p = p + 1
25 buf[p] = 45 as u8; p = p + 1
26 var i: i64 = 0
27 while tail[i] != (0 as u8) { buf[p] = tail[i]; p = p + 1; i = i + 1 }
28 buf[p] = 0 as u8
29 return buf
30}
31
32func main(argc: i64, argv: *i64) -> i64 {
33 gv_head("NX-GARMENT-GEN GATE -- conforming garment meshes grown from the served body, checked in-process" as *u8)
34 let ctr: *i64 = gv_ctr()
35 var apath: *u8 = GGG_ASSET_DEFAULT
36 var spath: *u8 = GGG_SERVED_DEFAULT
37 if argc >= 2 { apath = argv[1] as *u8 }
38 if argc >= 3 { spath = argv[2] as *u8 }
39 let lp: *i64 = sys_mmap(16) as *i64
40 let b: *u8 = sys_map_file(apath, lp)
41 let flen: i64 = lp[0]
42 var have: i64 = 0
43 if (b as i64) != 0 { if flen > 32 { have = 1 } }
44 if gv_need("npc asset readable" as *u8, have, ctr) == 0 { return gv_verdict("garment_gen_gate" as *u8, ctr, "no asset, nothing measured" as *u8) }
45 let G: *i64 = gmg_load(b, flen)
46 var loaded: i64 = 0
47 if (G as i64) != 0 { loaded = 1 }
48 if gv_need("npc asset parses (VERT/TRIS/SKEL/SKIN)" as *u8, loaded, ctr) == 0 { return gv_verdict("garment_gen_gate" as *u8, ctr, "asset unparsable" as *u8) }
49 gv_subjects("body vertices" as *u8, G[GMG_C_NV], ctr)
50 let secA: *i64 = sys_mmap(GMG_SEC_CAP * 8 + 64) as *i64
51 let stA: *i64 = sys_mmap(GMG_KINDS * GMG_STAT_N * 8 + 64) as *i64
52 let nwA: i64 = gmg_gen_all(G, secA, stA)
53 gv_puts(" build A words=" as *u8); gv_num(nwA); gv_puts("\n" as *u8)
54 gv_check("all-nine-ids-built" as *u8, (nwA > 0) as i64, ctr)
55 if nwA <= 0 { return gv_verdict("garment_gen_gate" as *u8, ctr, "the generator refused; teeth below cannot run" as *u8) }
56 let nm: *u8 = sys_mmap(64) as *u8
57 var k: i64 = 1
58 while k <= GMG_KINDS {
59 let st: *i64 = ((stA as i64) + (k - 1) * GMG_STAT_N * 8) as *i64
60 gmg_print_stat(st)
61 gv_check(ggg_name(nm, k, "tris-present" as *u8), (st[GMG_S_NT] > 0) as i64, ctr)
62 var closed: i64 = 0
63 if st[GMG_S_OPEN] == 0 { if st[GMG_S_LOOPS] >= 1 { if st[GMG_S_NBROVER] == 0 { closed = 1 } } }
64 gv_check(ggg_name(nm, k, "hems-closed-manifold-loops" as *u8), closed, ctr)
65 gv_check(ggg_name(nm, k, "one-hem-strip-per-boundary-edge" as *u8), (st[GMG_S_HEM] == st[GMG_S_BEDGES]) as i64, ctr)
66 gv_check(ggg_name(nm, k, "shell-clear-of-skin-by-09-thickness" as *u8), (st[GMG_S_WITHIN] == 0) as i64, ctr)
67 var strapped: i64 = 0
68 if k == 1 { strapped = 1 }
69 if k == 3 { strapped = 1 }
70 if k == 5 { strapped = 1 }
71 if k == 9 { strapped = 1 }
72 if strapped == 1 {
73 gv_check(ggg_name(nm, k, "two-straps" as *u8), (st[GMG_S_STRAPS] == 2) as i64, ctr)
74 var hF: i64 = GMG_ONEPIECE_NECK_F
75 var hB: i64 = GMG_ONEPIECE_NECK_B
76 if k == 1 { hF = G[GMG_C_NIP] + 500; hB = G[GMG_C_NIP] - GMG_BUST_HALF_DM }
77 var on: i64 = 1
78 if gmg_abs(st[GMG_S_SLF] - hF) > GGG_STRAP_TOL_DM { on = 0 }
79 if gmg_abs(st[GMG_S_SRF] - hF) > GGG_STRAP_TOL_DM { on = 0 }
80 if gmg_abs(st[GMG_S_SLB] - hB) > GGG_STRAP_TOL_DM { on = 0 }
81 if gmg_abs(st[GMG_S_SRB] - hB) > GGG_STRAP_TOL_DM { on = 0 }
82 gv_check(ggg_name(nm, k, "strap-ends-on-front-and-back-landmarks" as *u8), on, ctr)
83 }
84 k = k + 1
85 }
86 // determinism: the same body, the same integer arithmetic, the same words
87 let secB: *i64 = sys_mmap(GMG_SEC_CAP * 8 + 64) as *i64
88 let stB: *i64 = sys_mmap(GMG_KINDS * GMG_STAT_N * 8 + 64) as *i64
89 let nwB: i64 = gmg_gen_all(G, secB, stB)
90 let ckA: i64 = nxa_check2(1, secA, nwA)
91 var same: i64 = 0
92 if nwB == nwA { if nxa_check2(1, secB, nwB) == ckA { same = 1 } }
93 gv_puts(" checksum A=" as *u8); gv_num(ckA); gv_puts(" words=" as *u8); gv_num(nwA); gv_puts("\n" as *u8)
94 gv_check("deterministic-second-build-identical-words" as *u8, same, ctr)
95 // the served asset (when shipped) carries exactly this section -- a cross-process determinism witness
96 let lp2: *i64 = sys_mmap(16) as *i64
97 let sb: *u8 = sys_map_file(spath, lp2)
98 var served: i64 = 0
99 if (sb as i64) != 0 { if lp2[0] > 32 { served = 1 } }
100 if served == 1 {
101 let gwo: i64 = nxa_find(sb, lp2[0], nxa_tag4("GARM" as *u8))
102 var ident: i64 = 0
103 if gwo >= 0 {
104 let sh: *i64 = sb as *i64
105 let ons: i64 = sh[2]
106 let toc: *i64 = ((sb as i64) + 32) as *i64
107 var ti: i64 = 0
108 while ti < ons {
109 if toc[ti * 4] == nxa_tag4("GARM" as *u8) { if toc[ti * 4 + 2] == nwA { if toc[ti * 4 + 3] == ckA { ident = 1 } } }
110 ti = ti + 1
111 }
112 }
113 gv_check("served-asset-GARM-identical-to-fresh-build" as *u8, ident, ctr)
114 } else {
115 gv_puts(" served asset absent (" as *u8); gv_puts(spath); gv_puts(") -- the identity tooth is not run; SHIP IT and this line becomes a tooth\n" as *u8)
116 }
117 // neg-control 1: zero thickness must be REFUSED, never emitted as a coincident shell
118 G[GMG_C_THICK_PERMIL] = 0
119 let secZ: *i64 = sys_mmap(GMG_SEC_CAP * 8 + 64) as *i64
120 let stZ: *i64 = sys_mmap(GMG_KINDS * GMG_STAT_N * 8 + 64) as *i64
121 let nwZ: i64 = gmg_gen_all(G, secZ, stZ)
122 G[GMG_C_THICK_PERMIL] = 1000
123 // gv_bite reads its third argument as "the detector FIRED on the good input" -- the good build must
124 // NOT have been refused (the first cut passed "the good build succeeded" and read as a false positive)
125 gv_bite("neg-control-zero-thickness-REFUSED" as *u8, (nwZ == GMG_ERR_REFUSED_THICK) as i64, (nwA <= 0) as i64, ctr)
126 // neg-control 2: the clearance tooth must FIRE on an un-pushed shell (a fold drops the raw offset inside
127 // the skin on the bikini bottom and the one-piece) and stay silent on the pushed one
128 G[GMG_C_NOPUSH] = 1
129 let stN: *i64 = sys_mmap(GMG_STAT_N * 8 + 64) as *i64
130 var fires: i64 = 0
131 var kk: i64 = 1
132 while kk <= GMG_KINDS {
133 let rN: i64 = gmg_build(G, kk, stN)
134 if rN > 0 { if stN[GMG_S_WITHIN] > 0 { fires = 1 } }
135 kk = kk + 1
136 }
137 G[GMG_C_NOPUSH] = 0
138 var silent: i64 = 1
139 kk = 1
140 while kk <= GMG_KINDS {
141 let st: *i64 = ((stA as i64) + (kk - 1) * GMG_STAT_N * 8) as *i64
142 if st[GMG_S_WITHIN] > 0 { silent = 0 }
143 kk = kk + 1
144 }
145 gv_bite("neg-control-clearance-tooth-fires-without-push-out" as *u8, fires, (1 - silent) as i64, ctr)
146 return gv_verdict("garment_gen_gate" as *u8, ctr, "every tooth above states itself" as *u8)
147}