nx_bodybind.nx source
↩ module page · 48 lines · 2069 B
1// nx_bodybind.nx -- REGION-TO-BONE BINDING (Elara bar E4): a soft-body region rides a skeleton bone -- the
2// region's anchor = boneWorldPos + boneWorldRot * localOffset, recomputed after every sk_update. A posed or
3// animated skeleton thereby DRIVES its flesh (chest bone -> breast region; pelvis -> glute; the TittyMagic
4// anchoring model), and the region's spring/occlusion dynamics play out around the moving anchor.
5// A BINDING IS DATA: rows {bone, offx, offy, offz, regionArenaOffset} in a bind arena -- a rig ships as data.
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_skeleton.nx"
9import "nx_softbody_region.nx"
10
11// bind table: header [0]=count; rows of 8 slots {bone, ox, oy, oz, region_off (relative to a WORLD base), spare x3}
12const BB_MAXB: i64 = 16
13
14func bb_hdr(base: i64) -> *i64 { return base as *i64 }
15func bb_row(base: i64, i: i64) -> *i64 { return (base + 64 + i * 64) as *i64 }
16func bb_bytes() -> i64 { return 64 + BB_MAXB * 64 }
17
18func bb_init(base: i64) -> i64 {
19 let h: *i64 = bb_hdr(base)
20 h[0] = 0
21 return 0
22}
23func bb_add(base: i64, bone: i64, ox: i64, oy: i64, oz: i64, region_off: i64) -> i64 {
24 let h: *i64 = bb_hdr(base)
25 if h[0] >= BB_MAXB { return 0 - 1 }
26 let r: *i64 = bb_row(base, h[0])
27 r[0] = bone
28 r[1] = ox; r[2] = oy; r[3] = oz
29 r[4] = region_off
30 h[0] = h[0] + 1
31 return h[0] - 1
32}
33
34// drive ALL bindings: for each row, anchor(regionArena) = boneWorld + boneRot*offset. Call after sk_update,
35// before sr_step. world = the base every region_off is relative to (one big scene arena).
36func bb_drive(base: i64, skBase: i64, world: i64) -> i64 {
37 let h: *i64 = bb_hdr(base)
38 let tmp: *i64 = sk_vs(skBase) // reuse the skeleton's in-arena vec scratch
39 var i: i64 = 0
40 while i < h[0] {
41 let r: *i64 = bb_row(base, i)
42 let b: *i64 = sk_bone(skBase, r[0])
43 sk_matvec((b as i64 + 48) as *i64, r[1], r[2], r[3], tmp)
44 sr_anchor(world + r[4], b[15] + tmp[0], b[16] + tmp[1], b[17] + tmp[2])
45 i = i + 1
46 }
47 return 0
48}