code wiki / (root) / nx_autorig_mesh_gate.nx

nx_autorig_mesh_gate.nx source

↩ module page · 216 lines · 9835 B

1// nx_autorig_mesh_gate.nx -- proves the one-call auto-rig is FAITHFUL, not a new arithmetic. A bare prism goes 2// through nx_autorig_mesh in one call and, SEPARATELY, through cs_run then bh_run by hand; the two skeletons and 3// the two skinned rigs must be BYTE-IDENTICAL, so this organ only adds an entry point. It also proves the one 4// call actually produced a rig (VERT+TRIS+SKEL+SKIN, weights summing to the NXA 4096 at every vertex -- the 5// anti-vacuity tooth: a no-op that copied the mesh would carry no SKIN) and that a volumeless sheet is refused 6// by name at the skeleton stage. SUBJECT: nx_autorig_mesh via amesh_run, in-process. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_gate_verdict.nx" 10import "nx_nxa.nx" 11import "nx_autorig_mesh.nx" 12 13const MG_DIR: *u8 = "/tmp/nx_autorig_mesh_gate" 14const MG_MODE_DIR: i64 = 493 15const MG_AROUND: i64 = 4 16const MG_LEN: i64 = 6000 17const MG_RINGS: i64 = 61 18const MG_R: i64 = 300 19const MG_CELLS: i64 = 64 20const MG_VCAP: i64 = 2048 21const MG_TCAP: i64 = 8192 22const MG_SKIN_SUM: i64 = 4096 23const MG_SHEET_N: i64 = 8 // an 8x8 flat grid in z=0: triangulated, zero volume, cs must refuse it 24 25func mgw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 26func mg_ring_xy(k: i64, r: i64, out: *i64) -> i64 { 27 if k == 0 { out[0] = r; out[1] = 0 - r } 28 if k == 1 { out[0] = r; out[1] = r } 29 if k == 2 { out[0] = 0 - r; out[1] = r } 30 if k == 3 { out[0] = 0 - r; out[1] = 0 - r } 31 return 0 32} 33func mg_tri(tris: *i64, st: *i64, a: i64, b: i64, c: i64) -> i64 { 34 let t: i64 = st[1] 35 tris[1 + t*3] = a; tris[1 + t*3 + 1] = b; tris[1 + t*3 + 2] = c 36 st[1] = t + 1 37 return 0 38} 39func mg_prism(vert: *i64, tris: *i64, st: *i64) -> i64 { 40 let xy: *i64 = sys_mmap(16) as *i64 41 var rr: i64 = 0 42 while rr < MG_RINGS { 43 var k: i64 = 0 44 while k < MG_AROUND { 45 mg_ring_xy(k, MG_R, xy) 46 let idx: i64 = rr*MG_AROUND + k 47 vert[1 + idx*3] = xy[0]; vert[1 + idx*3 + 1] = xy[1] 48 vert[1 + idx*3 + 2] = MG_LEN * rr / (MG_RINGS - 1) 49 k = k + 1 50 } 51 rr = rr + 1 52 } 53 st[0] = MG_RINGS * MG_AROUND 54 rr = 0 55 while rr < MG_RINGS - 1 { 56 var k: i64 = 0 57 while k < MG_AROUND { 58 let a: i64 = rr*MG_AROUND + k 59 let b: i64 = rr*MG_AROUND + (k+1) % MG_AROUND 60 let c: i64 = (rr+1)*MG_AROUND + (k+1) % MG_AROUND 61 let d: i64 = (rr+1)*MG_AROUND + k 62 mg_tri(tris, st, a, b, c); mg_tri(tris, st, a, c, d) 63 k = k + 1 64 } 65 rr = rr + 1 66 } 67 let cb: i64 = st[0] 68 vert[1 + cb*3] = 0; vert[1 + cb*3 + 1] = 0; vert[1 + cb*3 + 2] = 0 69 let ct: i64 = st[0] + 1 70 vert[1 + ct*3] = 0; vert[1 + ct*3 + 1] = 0; vert[1 + ct*3 + 2] = MG_LEN 71 st[0] = st[0] + 2 72 var k: i64 = 0 73 while k < MG_AROUND { 74 mg_tri(tris, st, cb, (k+1) % MG_AROUND, k) 75 let top: i64 = (MG_RINGS - 1)*MG_AROUND 76 mg_tri(tris, st, ct, top + k, top + (k+1) % MG_AROUND) 77 k = k + 1 78 } 79 return 0 80} 81// a flat NxN grid in the z=0 plane: no volume, cs_run must refuse it (interior 0) 82func mg_sheet(vert: *i64, tris: *i64, st: *i64) -> i64 { 83 var r: i64 = 0 84 while r < MG_SHEET_N { 85 var c: i64 = 0 86 while c < MG_SHEET_N { 87 let idx: i64 = r*MG_SHEET_N + c 88 vert[1 + idx*3] = c * MG_R; vert[1 + idx*3 + 1] = r * MG_R; vert[1 + idx*3 + 2] = 0 89 c = c + 1 90 } 91 r = r + 1 92 } 93 st[0] = MG_SHEET_N * MG_SHEET_N 94 r = 0 95 while r < MG_SHEET_N - 1 { 96 var c: i64 = 0 97 while c < MG_SHEET_N - 1 { 98 let a: i64 = r*MG_SHEET_N + c 99 let b: i64 = r*MG_SHEET_N + c + 1 100 let cc: i64 = (r+1)*MG_SHEET_N + c + 1 101 let d: i64 = (r+1)*MG_SHEET_N + c 102 mg_tri(tris, st, a, b, cc); mg_tri(tris, st, a, cc, d) 103 c = c + 1 104 } 105 r = r + 1 106 } 107 return 0 108} 109func mg_write(path: *u8, vert: *i64, tris: *i64, st: *i64) -> i64 { 110 vert[0] = st[0]; tris[0] = st[1] 111 let tags: *i64 = sys_mmap(64) as *i64 112 let ptrs: *i64 = sys_mmap(64) as *i64 113 let wls: *i64 = sys_mmap(64) as *i64 114 tags[0] = nxa_tag4("VERT" as *u8); ptrs[0] = vert as i64; wls[0] = 1 + st[0]*3 115 tags[1] = nxa_tag4("TRIS" as *u8); ptrs[1] = tris as i64; wls[1] = 1 + st[1]*3 116 return bh_nxa_write(path, 2, tags, ptrs, wls) 117} 118func mg_open(path: *u8, lp: *i64) -> i64 { 119 let b: *u8 = sys_read_file(path, lp) 120 if (b as i64) == 0 { return 0 } 121 return b as i64 122} 123func mg_files_equal(pa: *u8, pb: *u8) -> i64 { 124 let la: *i64 = sys_mmap(16) as *i64 125 let lb: *i64 = sys_mmap(16) as *i64 126 let a: *u8 = sys_read_file(pa, la) 127 let b: *u8 = sys_read_file(pb, lb) 128 if (a as i64) == 0 { return 0 } 129 if (b as i64) == 0 { return 0 } 130 if la[0] != lb[0] { return 0 } 131 var i: i64 = 0 132 while i < la[0] { if a[i] != b[i] { return 0 } i = i + 1 } 133 return 1 134} 135// every vertex's four SKIN weights sum to exactly 4096; returns bad-vertex count (0 = all sound) 136func mg_skin_badsum(b: *u8, flen: i64) -> i64 { 137 let w: *i64 = b as *i64 138 let kwo: i64 = nxa_find(b, flen, nxa_tag4("SKIN" as *u8)) 139 let vwo: i64 = nxa_find(b, flen, nxa_tag4("VERT" as *u8)) 140 if kwo < 0 { return 0 - 1 } 141 if vwo < 0 { return 0 - 1 } 142 let nv: i64 = w[vwo] 143 var bad: i64 = 0 144 var i: i64 = 0 145 while i < nv { 146 let ko: i64 = kwo + 1 + i*8 147 let s: i64 = w[ko+4] + w[ko+5] + w[ko+6] + w[ko+7] 148 if s != MG_SKIN_SUM { bad = bad + 1 } 149 i = i + 1 150 } 151 return bad 152} 153func mg_has(b: *u8, flen: i64, tag: *u8) -> i64 { if nxa_find(b, flen, nxa_tag4(tag)) >= 0 { return 1 } return 0 } 154 155func main() -> i64 { 156 let ctr: *i64 = gv_ctr() 157 gv_head("nx_autorig_mesh_gate -- the one-call auto-rig is byte-identical to cs_run then bh_run run separately, it produces a real rig (SKEL+SKIN, weights summing to 4096 at every vertex), and a volumeless sheet is refused by name" as *u8) 158 sys_mkdir(MG_DIR, MG_MODE_DIR) 159 let vert: *i64 = sys_mmap((1 + MG_VCAP*3)*8) as *i64 160 let tris: *i64 = sys_mmap((1 + MG_TCAP*3)*8) as *i64 161 let st: *i64 = sys_mmap(16) as *i64 162 let crep: *i64 = sys_mmap(CR_WORDS*8) as *i64 163 let brep: *i64 = sys_mmap(BR_WORDS*8) as *i64 164 let lp: *i64 = sys_mmap(16) as *i64 165 let p_bare: *u8 = "/tmp/nx_autorig_mesh_gate/bare.nxa" 166 let p_skelA: *u8 = "/tmp/nx_autorig_mesh_gate/skelA.nxa" 167 let p_skinA: *u8 = "/tmp/nx_autorig_mesh_gate/skinA.nxa" 168 let p_skelB: *u8 = "/tmp/nx_autorig_mesh_gate/skelB.nxa" 169 let p_skinB: *u8 = "/tmp/nx_autorig_mesh_gate/skinB.nxa" 170 let p_sheet: *u8 = "/tmp/nx_autorig_mesh_gate/sheet.nxa" 171 let p_sheelsk: *u8 = "/tmp/nx_autorig_mesh_gate/sheet_skel.nxa" 172 let p_sheelskin: *u8 = "/tmp/nx_autorig_mesh_gate/sheet_skin.nxa" 173 174 // one call 175 st[0] = 0; st[1] = 0 176 mg_prism(vert, tris, st) 177 let wr: i64 = mg_write(p_bare, vert, tris, st) 178 let rcA: i64 = amesh_run(p_bare, p_skelA, p_skinA, MG_CELLS, crep, brep) 179 let limbsA: i64 = crep[CR_LIMBS] 180 let bskin: i64 = mg_open(p_skinA, lp) 181 let fskin: i64 = lp[0] 182 gv_check("T1 the one call produced a rig: nx_autorig_mesh on a bare 60 mm prism returns OK, its skeleton stage found two limbs, and the skinned output carries VERT, TRIS, SKEL and SKIN" as *u8, ((wr > 0) as i64) * ((rcA == AM_EXIT_OK) as i64) * ((limbsA == 2) as i64) * ((bskin != 0) as i64) * mg_has(bskin as *u8, fskin, "VERT" as *u8) * mg_has(bskin as *u8, fskin, "TRIS" as *u8) * mg_has(bskin as *u8, fskin, "SKEL" as *u8) * mg_has(bskin as *u8, fskin, "SKIN" as *u8), ctr) 183 let bad: i64 = mg_skin_badsum(bskin as *u8, fskin) 184 hw_num_line(bad) 185 gv_check("T2 ANTI-VACUITY: every vertex's four SKIN weights sum to exactly 4096 -- a no-op that merely copied the mesh would carry no SKIN and fail this" as *u8, ((bad == 0) as i64), ctr) 186 187 // separate, by hand 188 var k: i64 = 0 189 while k < CR_WORDS { crep[k] = 0; k = k + 1 } 190 let rcS: i64 = cs_run(p_bare, p_skelB, crep) 191 k = 0 192 while k < BR_WORDS { brep[k] = 0; k = k + 1 } 193 let rcB: i64 = bh_run(p_skelB, p_skinB, BH_MODE_GEODESIC, MG_CELLS, brep) 194 gv_check("T3 FAITHFUL COMPOSITION: the one-call skeleton and skinned rig are BYTE-IDENTICAL to cs_run then bh_run run separately -- the organ adds an entry point and changes no arithmetic" as *u8, ((rcS == CS_EXIT_OK) as i64) * ((rcB == BH_EXIT_OK) as i64) * mg_files_equal(p_skelA, p_skelB) * mg_files_equal(p_skinA, p_skinB), ctr) 195 196 // neg-control: a volumeless sheet is refused at the skeleton stage 197 st[0] = 0; st[1] = 0 198 mg_sheet(vert, tris, st) 199 mg_write(p_sheet, vert, tris, st) 200 var k2: i64 = 0 201 while k2 < CR_WORDS { crep[k2] = 0; k2 = k2 + 1 } 202 let rcSheet: i64 = amesh_run(p_sheet, p_sheelsk, p_sheelskin, MG_CELLS, crep, brep) 203 hw_num_line(rcSheet) 204 gv_check("T4 neg-control-sheet-refused: a volumeless flat sheet is refused by name at the skeleton stage (AM_EXIT_SKEL), never silently mis-rigged -- a confidently wrong rig is worse than a refusal the caller can see" as *u8, ((rcSheet == AM_EXIT_SKEL) as i64), ctr) 205 206 gv_values_head() 207 gv_kv("limbs" as *u8, limbsA) 208 gv_kv("joints" as *u8, crep[CR_JOINTS]) 209 gv_kv("skin_bad_sum_verts" as *u8, bad) 210 gv_kv("onecall_rc" as *u8, rcA) 211 gv_kv("sheet_rc" as *u8, rcSheet) 212 gv_kv("skel_bytes_identical" as *u8, mg_files_equal(p_skelA, p_skelB)) 213 gv_kv("skin_bytes_identical" as *u8, mg_files_equal(p_skinA, p_skinB)) 214 return gv_verdict("nx_autorig_mesh_gate" as *u8, ctr, "one-call auto-rig proven byte-identical to the two-step composition, producing a real SKEL+SKIN rig, refusing a volumeless sheet by name" as *u8) 215} 216func hw_num_line(v: i64) -> i64 { mgw(" value=" as *u8); gv_num(v); mgw("\n" as *u8); return 0 }