code wiki / _hdl_build / nx_skin_gate.nx
nx_skin_gate.nx source
↩ module page · 78 lines · 4986 B
1// nx_skin_gate.nx -- GATE for CAP-SKELETAL-ANIM rung-1 (linear blend skinning, mr_skin2 over nx_render_core).
2// Proves with HARD numbers: (T1) full-weight identity bone leaves the vertex EXACTLY at rest, (T2) a 90deg bone
3// rotation moves (1,0,0)->(0,0,-1) exactly, (T3) a 50/50 blend of two bones lands at the MIDPOINT, (T4) a 25/75
4// blend lands proportionally (weights are real, not hardcoded), (T5) skinning actually MOVES the vertex, (T6 teeth)
5// zero weights => origin (weights gate the contribution; no hallucinated position). All Q14 no-float. expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_render_core.nx"
8import "nx_meshrender.nx"
9
10func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45 as u8;sys_write(1,b,1);x=0-x} if x==0{b[0]=48 as u8;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 }
12func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
13func setrest(r: *i64, x: i64, y: i64, z: i64) -> i64 { r[0]=x; r[1]=y; r[2]=z; r[3]=16384; return 0 }
14
15func main() -> i64 {
16 g_puts("nx_skin_gate (CAP-SKELETAL-ANIM rung-1: linear blend skinning, measured no-float)\n" as *u8)
17 let Q: i64 = 16384
18 let idm: *i64 = sys_mmap(16*8) as *i64
19 let rot: *i64 = sys_mmap(16*8) as *i64
20 let tr: *i64 = sys_mmap(16*8) as *i64
21 let rest: *i64 = sys_mmap(4*8) as *i64
22 let tmp: *i64 = sys_mmap(4*8) as *i64
23 let out: *i64 = sys_mmap(4*8) as *i64
24 rc_identity_4x4(idm)
25 mr_roty(90, rot) // 90deg about Y: (1,0,0) -> (0,0,-1)
26 rc_translation_4x4(2*Q, 0, 0, tr) // translate +2 in x
27
28 // T1: full-weight identity bone -> vertex stays at rest (Q,0,0)
29 setrest(rest, Q, 0, 0)
30 mr_skin2(rest, idm, Q, idm, 0, tmp, out)
31 let t1x: i64=out[0]; let t1y: i64=out[1]; let t1z: i64=out[2]
32
33 // T2: full-weight 90deg rotation bone on (1,0,0) -> (0,0,-1)
34 setrest(rest, Q, 0, 0)
35 mr_skin2(rest, rot, Q, idm, 0, tmp, out)
36 let t2x: i64=out[0]; let t2z: i64=out[2]
37 let t2moved: i64=out[0] // for T5
38
39 // T3: 50/50 blend of identity + translate(+2) on the ORIGIN -> midpoint (1,0,0)
40 setrest(rest, 0, 0, 0)
41 mr_skin2(rest, idm, Q/2, tr, Q/2, tmp, out)
42 let t3x: i64=out[0]; let t3y: i64=out[1]
43
44 // T4: 25/75 blend -> 0.75*2 = 1.5 -> (1.5,0,0) = (24576,0,0) (weights are real, not 50/50-hardcoded)
45 setrest(rest, 0, 0, 0)
46 mr_skin2(rest, idm, Q/4, tr, 3*Q/4, tmp, out)
47 let t4x: i64=out[0]
48
49 // T6 teeth: zero weights -> origin (no contribution, no hallucinated position)
50 setrest(rest, Q, 0, 0)
51 mr_skin2(rest, idm, 0, idm, 0, tmp, out)
52 let t6x: i64=out[0]; let t6y: i64=out[1]; let t6z: i64=out[2]
53
54 g_puts(" T1_rest=("); g_pn(t1x); g_puts(","); g_pn(t1y); g_puts(","); g_pn(t1z); g_puts(") T2_rot=("); g_pn(t2x); g_puts(",_,"); g_pn(t2z); g_puts(") T3_mid="); g_pn(t3x); g_puts(" T4_25/75="); g_pn(t4x); g_puts(" T6_zero="); g_pn(t6x); g_puts("\n" as *u8)
55
56 var pass: i64=0; var t: i64=0
57 var c1: i64=0; if t1x==Q { if t1y==0 { if t1z==0 { c1=1 } } }
58 pass=pass+ck("T1: full-weight identity bone leaves the vertex EXACTLY at rest (Q,0,0)" as *u8, c1); t=t+1
59 var c2: i64=0; if t2x==0 { if t2z==(0-Q) { c2=1 } }
60 pass=pass+ck("T2: 90deg bone rotation moves (1,0,0) -> (0,0,-1) exactly" as *u8, c2); t=t+1
61 var c3: i64=0; if t3x==Q { if t3y==0 { c3=1 } }
62 pass=pass+ck("T3 (MEASURED): 50/50 two-bone blend lands at the MIDPOINT (1,0,0)" as *u8, c3); t=t+1
63 var c4: i64=0; if t4x==24576 { c4=1 }
64 pass=pass+ck("T4 (MEASURED): 25/75 blend lands at 1.5 (24576) -- weights are real, not hardcoded" as *u8, c4); t=t+1
65 var c5: i64=0; if t2moved!=Q { c5=1 }
66 pass=pass+ck("T5: skinning actually MOVES the vertex (rotated != rest)" as *u8, c5); t=t+1
67 var c6: i64=0; if t6x==0 { if t6y==0 { if t6z==0 { c6=1 } } }
68 pass=pass+ck("T6 (teeth): zero weights -> origin (weights gate the contribution; no hallucinated position)" as *u8, c6); t=t+1
69
70 var okall: i64=0; if pass==t { okall=1 }
71 g_puts("---- nx_skin_gate: passed "); g_pn(pass); g_puts(" / "); g_pn(t); g_puts(" ----\n" as *u8)
72 if okall==1 {
73 let logf: i64=sys_openat_append("knowledge/status/skin_gate.log" as *u8, 420)
74 if logf>=0 { let msg: *u8="SKIN GREEN: CAP-SKELETAL-ANIM rung-1 linear blend skinning -- identity/rotation exact + blend midpoint + weight-proportional + teeth, no-float\n" as *u8; var ml: i64=0; while msg[ml]!=(0 as u8){ml=ml+1} let z: i64=sys_write(logf,msg,ml); sys_close(logf) }
75 g_puts("verdict=GREEN (bones deform a mesh -- the skinning core toward an animatable human)\n" as *u8); sys_exit(0); return 0
76 }
77 g_puts("verdict=RED\n" as *u8); sys_exit(1); return 1
78}