code wiki / _hdl_build / nx_ng_avatar_rig.nx
nx_ng_avatar_rig.nx
buildroot/runtime/_hdl_build/nx_ng_avatar_rig.nx
about
nx_ng_avatar_rig.nx -- CAP-NEURAL-AVATAR RUNG-2: the SKELETAL RIG. Extends nx_ng_avatar's 1-DOF single-
gaussian deform to a multi-gaussian character driven by a multi-BONE skeleton via LINEAR BLEND SKINNING
(LBS) -- the exact deformation math a DAZ Genesis figure / Unreal MetaHuman rig uses: each gaussian k's
posed center = mu0[k] + SUM_b w[k][b]*pose[b] (a learned per-gaussian skinning weight w binds it to the
bones). The KEY S-class rung toward beating DAZ/Unreal characters (shared primitive behind offline + real-
time). Honest gated proof, Q16 no-float, reuses the gaussian-splat + GD-fit spine from nx_ng_avatar:
T1 LEARNED-RIG: fit the skinning weights from posed frames -> loss->~0 AND w recovers the true binding.
T2 NOVEL-POSE: an untrained skeleton pose renders correctly (LBS is linear = generalizes, not memorized).
T3 NEG-CONTROL: a RIGID rig (all gaussians share one bone) CANNOT match a pose where the bones differ =
the skeleton is load-bearing. T4 BIT-EXACT.
HONEST: 1D positions, 2 bones, 2 gaussians, translation-LBS (no rotation), linear skinning. Full production
= 3D + rotational LBS + blendshapes (expression) + many bones/gaussians = the follow-on rungs. Sovereign:
nx_nofloat_autograd + syscalls. license_tier: ORIGINAL expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_nofloat_autograd.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 16 | const K_MAGIC_1500: i64 = 1500 |
| 17 | const K_MAGIC_22938: i64 = 22938 |
| 18 | const K_MAGIC_42598: i64 = 42598 |
| 19 | const K_MAGIC_19661: i64 = 19661 |
| 20 | const K_MAGIC_32768: i64 = 32768 |
| 21 | const K_MAGIC_8192: i64 = 8192 |
| 22 | const K_MAGIC_26214: i64 = 26214 |
| 23 | const K_MAGIC_3000: i64 = 3000 |
| 25 | const RLOG: *u8 = "knowledge/status/ng_avatar_rig.log" |
| 26 | const Q16: i64 = 65536 |
| 27 | const NP: i64 = 16 |
| 28 | const INV2S2: i64 = 2275555 // 1/(2 sigma^2) Q16, sigma=0.12 |
| 29 | const EPOCHS: i64 = 6000 |
| 30 | const LRQ: i64 = 48 |
| 31 | const NB: i64 = 2 // bones |
| 32 | const NK: i64 = 2 // gaussians (character parts) |
| 33 | const NPOSE: i64 = 4 // training skeleton poses |
functions
| 35 | func ap(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 36 | func apn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;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 } |
| 37 | func a_abs(v: i64) -> i64 { if v<0 { return 0-v } return v } called by 1: main |
| 38 | func aqm(a: i64, b: i64) -> i64 { return (a*b)>>16 } |
| 39 | func rl_ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 40 | func rl_wn(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 } |
| 43 | func gval(center: i64, p: i64) -> i64 |
| 50 | func rig_center(mu0: *i64, w: *i64, pose: *i64, k: i64) -> i64 |
| 57 | func render_rig(mu0: *i64, w: *i64, pose: *i64, out: *i64) -> i64 |
| 69 | func sse(a: *i64, b: *i64) -> i64 { var s: i64=0; var p: i64=0; while p<NP { let d: i64=a[p]-b[p]; s=s+aqm(d,d); p=p+1 } return s } |
| 73 | func fit_skin(mu0: *i64, poses: *i64, frames: *i64, w: *i64, lf: *i64, ll: *i64) -> i64 |
| 114 | func main() -> i64 |