code wiki / (root) / nx_nxa_play.nx

nx_nxa_play.nx

buildroot/runtime/nx_nxa_play.nx

19843 B403 linesdepth 3pulls 6 transitivereach 0 importersview sourcekind tooltopic nxa
docsdependenciesstructsconstsfunctions

about

nx_nxa_play.nx -- THE NXA POSE PLAYER: apply a POSE-library entry to a rigged NXA and evaluate linear-blend skinning over the WHOLE mesh, at the corpus's real dimensions. WHY THIS EXISTS (measured 2026-08-23). Every rigged asset we own carries SKEL+SKIN with exact weights, and nx_nxa_pose freezes ANIM channel-2 keyframes into a POSE library -- but NOTHING applied them: the only in-engine evaluator (nx_skeleton) was capped at 32 bones / 2048 verts against a corpus of 104-370 joints and 14,164-423,919 verts, so a real character could not be posed at all. That cap is now gone (capacity is declared from the asset); this organ is the consumer that makes the capability reachable. A blocker removed but uncalled is BUILT+UNWIRED. THE MATH IS THE SPEC'S, NOT A NEW ONE. knowledge/nxa_format_spec.md declares the normative runtime form: M x = D (x - bind_t) + bind_t + dt, where D is the world-delta rotation ABOUT THE BIND POSE and dt the world translation delta -- exact LBS with NO hierarchy walk at runtime. Expanded, that is an AFFINE per-joint transform: M x = D x + (bind_t - D bind_t + dt). So the shared-local-position form nx_skeleton already implements (sum_j w_j (R_j v + p_j)) is SUFFICIENT: set R_j = D_j and p_j = bind_t - D bind_t + dt. No second skinning path is created, and nx_skeleton's v1 note ("one local pos, valid when bind poses align") stops being a limit -- the per-joint bind offset is folded into p_j, which is exactly where an affine form puts it. UNITS ARE THE MEASURED TRAP, NAMED IN THE SPEC: VERT/SKEL binds are in 0.01 mm model units while the POSE/ANIM dt lanes are packed in MILLIMETERS to fit i16. A consumer MUST scale dt by 100 or every baked translation renders at 1% (the recorded symptom: forearms pinned at T-pose pivots). WEIGHTS: SKIN carries q12 weights summing 4096 (spec); nx_skeleton blends in fx256 summing 256. The conversion happens HERE, at the boundary, and RENORMALIZES: the truncation residual is added back to the largest influence so every vertex's weights sum to EXACTLY 256. Dropping the residual shrinks a vertex toward the origin -- a silent, uniform volume loss that reads as "the mesh got slightly smaller", which is precisely the kind of defect that never gets attributed. Usage: nx_nxa_play <in.nxa> [pose_id] (no pose_id, or a pose_id absent from the library => the IDENTITY pose, which by construction reproduces bind pose exactly -- the neg-control) Exits: 0 ok | 2 usage | 3 refused-by-name | 5 no rigged sections

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_nxa.nx nx_nxa_fk.nx nx_skeleton.nx nx_nxa_play.nx

imports: nx_syscalls.nxnx_nxa.nxnx_nxa_fk.nxnx_skeleton.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nperr sys_write np_atoi sys_mmap nxa_die sys_write ↻ sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close nxa_find nxa_section_entry nxa_magic nxa_check2 nxa_tag4 nf_qnorm nf_isqrt sk_bytes_for sk_init_cap sk_hdr sk_add_bone sk_hdr ↻ sk_capb sk_hdr ↻

structs

none

consts

38const NP_INF: i64 = 4 // SKIN is 4 influences per vertex (NXA v1 spec, fixed by format)
39const NP_WQ: i64 = 4096 // SKIN weight scale, q12, sum = 4096 (spec)
40const NP_FX: i64 = 256 // nx_skeleton weight scale, fx256, sum = 256
61const NP_DT_MODEL: i64 = 1
62const NP_Q12: i64 = 4096 // quaternion fixed-point unit (spec)
65const NP_WFULL: i64 = 1000
66const NP_MODE: i64 = 0x1a4 // 0644 on the published asset, matching every sibling NXA writer
67const NP_HDR: i64 = 32 // header bytes before the TOC (NXA v1 layout)
68const NP_TOC_W: i64 = 4 // words per TOC entry: tag, byte_off, word_len, check
69const NP_EXIT_USAGE: i64 = 2
70const NP_EXIT_REFUSE: i64 = 3
71const NP_EXIT_NOSEC: i64 = 5

functions

73func npw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
74func nperr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 }
called by 1: main calls 1: sys_write
75func npn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
88func np_atoi(s: *u8) -> i64
called by 1: main
98func np_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
called by 1: main
102func np_quat_to_m(q: *i64, m: *i64, o3: *i64, scr: *i64) -> i64
called by 1: main calls 1: nf_qrotv
112func main(argc: i64, argv: *i64) -> i64