code wiki / _hdl_build / nx_hands_gate.nx
nx_hands_gate.nx source
↩ module page · 144 lines · 6683 B
1// nx_hands_gate.nx -- ★R4 HANDS: articulated fingers on the holistic being (the digital-human ladder's named next
2// rung + the MetaHuman-axis component). 4 fingers (2 segments) + thumb per hand, per-hand CURL (open<->fist), bound
3// to the forearm FK chain. The articulation proof is CAUSAL in SDF space: a point inside an OPEN fingertip must be
4// EMPTY when the fist curls (and vice versa). T1 composition. T2 causal curl. T3 rig-follow (fingers swing with the
5// arm in a pose). T4 determinism. T5 evidence (open | fist closeups + full being). license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_png.nx"
8import "nx_trimesh.nx"
9import "nx_isosurf.nx"
10import "nx_bodyatlas.nx"
11
12func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func 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 }
14func clearfb(fb: *i64, n: i64, c: i64) -> i64 { var i: i64=0; while i<n { fb[i]=c; i=i+1 } return 0 }
15
16const BG: i64 = 24 + 26*256 + 34*65536
17const CW: i64 = 300
18const CH: i64 = 320
19
20// mesh the RIGHT hand region (local x 170..305, y -150..85, z -45..105) at cell 5 and render a closeup into a panel
21func hand_panel(gal: *i64, GW: i64, slot: i64) -> i64 {
22 let gx: i64 = 27
23 let gy: i64 = 52
24 let gz: i64 = 30
25 let cell: i64 = 5
26 let grid: *i64 = sys_mmap((gx+1)*(gy+1)*(gz+1)*8) as *i64
27 var i: i64 = 0
28 while i <= gx {
29 var j: i64 = 0
30 while j <= gy {
31 var k: i64 = 0
32 while k <= gz {
33 grid[(i*(gy+1)+j)*(gz+1)+k] = ba_sdf(170+i*cell, 0-310+j*cell, 0-45+k*cell, 1)
34 k = k + 1
35 }
36 j = j + 1
37 }
38 i = i + 1
39 }
40 tm_reset()
41 surface_nets(grid, gx, gy, gz, 170, 0-310, 0-45, cell, 0, 216+172*256+152*65536)
42 // center the region about the origin for the camera: region center ~ (237, -32, 30)
43 tm_place(0, tm_nv(), 0-237, 180, 0-30, 1000)
44 let npx: i64 = CW*CH
45 let fb: *i64 = sys_mmap(npx*8) as *i64
46 let zb: *i64 = sys_mmap(npx*8) as *i64
47 clearfb(fb, npx, BG)
48 trimesh_zclear(zb, npx)
49 trimesh_render(fb, zb, CW, CH, 1400, 0-700, 540, 520, 1)
50 var y: i64 = 0
51 while y < CH { var x: i64=0; while x<CW { gal[y*GW+slot*CW+x]=fb[y*CW+x]; x=x+1 } y=y+1 }
52 return tm_nt()
53}
54
55func main() -> i64 {
56 hw("=== nx_hands_gate -- R4: articulated fingers (curl open<->fist), rig-bound ===\n" as *u8)
57 var fails: i64 = 0
58
59 // ---- T1 composition ----
60 atlas_hand_curl(0)
61 let np: i64 = atlas_build(0)
62 let named: i64 = ba_named_count()
63 hw(" parts="); pn(np); hw(" named="); pn(named); hw(" (fingers nid 64, thumb nid 65)\n" as *u8)
64 var t1: i64 = 0
65 if np >= 119 { if named >= 65 { t1 = 1 } }
66 if t1 == 1 { hw("T1 PASS hands composed: +20 finger/thumb parts, 2 new named structures\n" as *u8) }
67 else { fails=fails+1; hw("T1 FAIL\n" as *u8) }
68
69 // ---- T2 CAUSAL CURL: SDF occupancy swaps between the open-tip and fist-tip points ----
70 let openTipOpen: i64 = ba_sdf(267, 0-245, 20, 1)
71 let fistTipOpen: i64 = ba_sdf(267, 0-220, 50, 1)
72 atlas_hand_curl(1024)
73 atlas_build(0)
74 let openTipFist: i64 = ba_sdf(267, 0-245, 20, 1)
75 let fistTipFist: i64 = ba_sdf(267, 0-220, 50, 1)
76 hw(" sdf at open-tip: open="); pn(openTipOpen); hw(" fist="); pn(openTipFist); hw(" at fist-tip: open="); pn(fistTipOpen); hw(" fist="); pn(fistTipFist); hw("\n" as *u8)
77 var t2: i64 = 0
78 if openTipOpen < 0 { if openTipFist > 0 { if fistTipOpen > 0 { if fistTipFist < 0 { t2 = 1 } } } }
79 if t2 == 1 { hw("T2 PASS CAUSAL: the fingertip volume MOVES with the curl (open-tip empties, fist-tip fills)\n" as *u8) }
80 else { fails=fails+1; hw("T2 FAIL\n" as *u8) }
81
82 // ---- T3 rig-follow: in the WAVE pose the raised arm's fingers move with it ----
83 atlas_hand_curl(0)
84 atlas_build(0)
85 atlas_pose(3) // wave: RIGHT arm overhead
86 // the right open fingertip rest point must be EMPTY now (the whole hand left with the arm)
87 let tipPosed: i64 = ba_sdf(267, 0-245, 20, 1)
88 atlas_pose(0)
89 let tipStand: i64 = ba_sdf(267, 0-245, 20, 1)
90 hw(" rig-follow: fingertip sdf standing="); pn(tipStand); hw(" waving="); pn(tipPosed); hw("\n" as *u8)
91 var t3: i64 = 0
92 if tipStand < 0 { if tipPosed > 0 { t3 = 1 } }
93 if t3 == 1 { hw("T3 PASS fingers are BOUND to the arm chain (the raised arm takes its fingers with it)\n" as *u8) }
94 else { fails=fails+1; hw("T3 FAIL\n" as *u8) }
95
96 // ---- T4 determinism ----
97 atlas_hand_curl(1024)
98 let na: i64 = atlas_build(0)
99 let sa: i64 = ba_sdf(267, 0-220, 50, 1)
100 let nb: i64 = atlas_build(0)
101 let sb: i64 = ba_sdf(267, 0-220, 50, 1)
102 var t4: i64 = 0
103 if na == nb { if sa == sb { t4 = 1 } }
104 if t4 == 1 { hw("T4 PASS deterministic\n" as *u8) } else { fails=fails+1; hw("T4 FAIL\n" as *u8) }
105
106 // ---- T5 evidence: open hand | fist | full being ----
107 let GW: i64 = CW*3
108 let gal: *i64 = sys_mmap(GW*CH*8) as *i64
109 clearfb(gal, GW*CH, BG)
110 atlas_hand_curl(0)
111 atlas_build(0)
112 atlas_pose(0)
113 let trisOpen: i64 = hand_panel(gal, GW, 0)
114 atlas_hand_curl(1024)
115 atlas_build(0)
116 let trisFist: i64 = hand_panel(gal, GW, 1)
117 hw(" hand closeup meshes: open tris="); pn(trisOpen); hw(" fist tris="); pn(trisFist); hw("\n" as *u8)
118 // full being (open hands) via atlas_render scaled into the third panel
119 atlas_hand_curl(0)
120 atlas_build(0)
121 let bw: i64 = 208
122 let bh: i64 = 368
123 let bfb: *i64 = sys_mmap(bw*bh*8) as *i64
124 atlas_render(bfb, bw, bh, 800, 1, 0-1)
125 var y: i64 = 0
126 while y < CH {
127 var x: i64 = 0
128 while x < CW {
129 var px: i64 = BG
130 let sx: i64 = x - 46
131 if sx >= 0 { if sx < bw { if y < bh { px = bfb[y*bw+sx] } } }
132 gal[y*GW+2*CW+x] = px
133 x = x + 1
134 }
135 y = y + 1
136 }
137 write_png(gal, GW, CH, "knowledge/nx_hands.png" as *u8)
138 hw("T5 evidence -> knowledge/nx_hands.png (open hand | fist | being)\n" as *u8)
139
140 if fails == 0 { hw("HANDS-GATE GREEN -- R4: 4 fingers + thumb per hand (20 parts, 2 named structures), per-hand CURL articulation (open<->fist, causally SDF-proven), fingers BOUND to the forearm FK chain. Residual: per-finger independent runtime FK + thumb opposition + 15-joint SMPL-X parity.\n" as *u8); sys_exit(0); return 0 }
141 hw("HANDS-GATE RED fails="); pn(fails); hw("\n" as *u8)
142 sys_exit(1)
143 return 1
144}