code wiki / (root) / nx_softtissue.nx

nx_softtissue.nx

buildroot/runtime/nx_softtissue.nx

45507 B1022 linesdepth 5pulls 5 transitivereach 4 importersview sourcekind librarytopic softtissue
docsdependenciesstructsconstsfunctions

about

nx_softtissue.nx -- SOVEREIGN soft-tissue solver: XPBD over a tetrahedral physics cage with per-layer compliance. THE tier our body physics did not have. WHY THIS EXISTS (measured, 2026-07-30): the rigmesh viewer drives breasts with a 2-mass EMA spring (a damped oscillator with a calibrated gain). An oscillator has no VOLUME, no LAYERS and no relationship to gravity DIRECTION -- so it physically cannot reproduce the one behavior a human notices instantly: when a woman lies down, soft heavy tissue FLATTENS and spreads toward the chest wall, and firm tissue does so much less. Our own ecosystem already MEASURES that behavior -- nx_breast_drape_pose.nx bands LAYING_BACK at aspect 716..921 / centroid 410..614 against STANDING_FACING 1024..1331 / 614..768 -- so a ruler existed for a simulator that did not. This organ is the simulator; that validator is its oracle (see nx_softtissue_gate.nx). Same solver serves buttocks, thigh and abdomen: the tissue differs only by PROFILE ROWS, never by code (rule 11, rule 25). METHOD (XPBD, Macklin et al. -- position-based, so it cannot blow up like a force solver): per substep: predict -> solve constraints N times -> derive velocity -> damp constraints: distance (edges) | volume (Neo-Hookean incompressibility, C = 6V - 6V0) | contact (sphere/capsule = a finger or a surgical instrument) | attachment (chest-wall particles pinned, inverse mass 0) compliance: alpha_tilde = alpha / dt^2, per LAYER, from data rows. alpha 0 = rigid (muscle, Cooper's ligament), alpha large = soft (adipose). WHY IT CANNOT INVERT: the volume constraint's correction magnitude scales as 1/(6V) as the element collapses, so resistance rises without bound as det F -> 0. Tissue gets HARDER the harder it is pressed -- the same qualitative guarantee the Neo-Hookean strain-energy barrier gives, which is why a deep press dimples instead of exploding. Proven by tooth, not asserted: the gate presses a capsule 60% into the cage and asserts every 6V stays > 0. UNITS: positions in cmm (0.01 mm) -- the NXA VERT unit, so cage and mesh share a frame. H=171530 cmm = 1.7153 m. Scalars q12 (4096=1.0), compliance q20 (1048576=1.0). Velocity cmm/s. dt in microseconds. Frame: +x lateral, +y cranial, +z anterior. Gravity is a UNIT VECTOR in that body frame -- standing (0,-1,0), supine (0,0,-1). That single input is what makes lying-down flattening emergent, not scripted. QUANTIZATION (honest): positions are integer cmm, so one substep's displacement carries ~1 cmm of rounding. st_div_r rounds to NEAREST (not toward zero) so the error does not bias into fake damping -- a truncating divide would silently drain energy and read as viscosity we did not model. license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 2 imports · 4 importers

nx_syscalls.nx nx_proportion_guard.nx nx_softtissue.nx nx_proportion_guard_gate.nx nx_softtissue_diss_gate.nx nx_softtissue_gate.nx nx_softtissue_rot_gate.nx

imports: nx_syscalls.nxnx_proportion_guard.nx

imported by: nx_proportion_guard_gate.nxnx_softtissue_diss_gate.nxnx_softtissue_gate.nxnx_softtissue_rot_gate.nx

structs

none

consts

41const ST_MAGIC_1229: i64 = 1229
42const ST_MAGIC_12288: i64 = 12288
43const ST_MAGIC_20972: i64 = 20972
44const ST_MAGIC_1434: i64 = 1434
45const ST_MAGIC_2654435761: i64 = 2654435761
46const ST_MAGIC_1013904223: i64 = 1013904223
47const ST_MAGIC_1442695040888963407: i64 = 1442695040888963407
48const ST_MAGIC_2246822519: i64 = 2246822519
49const ST_MAGIC_288230376151711743: i64 = 288230376151711743
50const ST_MAGIC_1050: i64 = 1050
51const ST_MAGIC_9216: i64 = 9216
52const ST_MAGIC_1024: i64 = 1024
53const ST_MAGIC_4096: i64 = 4096
54const ST_MAGIC_22528: i64 = 22528
55const ST_MAGIC_2048: i64 = 2048
56const ST_MAGIC_8192: i64 = 8192
57const ST_MAGIC_24576: i64 = 24576
58const ST_MAGIC_20480: i64 = 20480
59const ST_MAGIC_1000000: i64 = 1000000
60const ST_MAGIC_999999999: i64 = 999999999
61const ST_MAGIC_999999999999999: i64 = 999999999999999
64const ST_MAXP: i64 = 8192
65const ST_MAXT: i64 = 16384
66const ST_MAXE: i64 = 49152
69const ST_LAY_MUSCLE: i64 = 0
70const ST_LAY_GLAND: i64 = 1
71const ST_LAY_ADIPOSE: i64 = 2
72const ST_LAY_SKIN: i64 = 3
73const ST_LAY_LIGAMENT: i64 = 4
74const ST_LAY_N: i64 = 5
77const ST_W_NP: i64 = 0
78const ST_W_NT: i64 = 1
79const ST_W_NE: i64 = 2
80const ST_W_PX: i64 = 3
81const ST_W_PY: i64 = 4
82const ST_W_PZ: i64 = 5
83const ST_W_QX: i64 = 6
84const ST_W_QY: i64 = 7
85const ST_W_QZ: i64 = 8
86const ST_W_VX: i64 = 9
87const ST_W_VY: i64 = 10
88const ST_W_VZ: i64 = 11
89const ST_W_IW: i64 = 12
90const ST_W_LAY: i64 = 13
91const ST_W_TET: i64 = 14
92const ST_W_TRV: i64 = 15
93const ST_W_TLA: i64 = 16
94const ST_W_TLM: i64 = 17
95const ST_W_EDG: i64 = 18
96const ST_W_ERL: i64 = 19
97const ST_W_ELA: i64 = 20
98const ST_W_ELM: i64 = 21
99const ST_W_SRF: i64 = 22
100const ST_W_TON: i64 = 23
101const ST_W_TCX: i64 = 24
102const ST_W_TCY: i64 = 25
103const ST_W_TCZ: i64 = 26
104const ST_W_TR: i64 = 27
105const ST_W_PROF:i64 = 28
106const ST_W_SLOTS: i64 = 40
109const ST_PF_A_MM: i64 = 0
110const ST_PF_B_MM: i64 = 1
111const ST_PF_C_MM: i64 = 2
112const ST_PF_GLAND_PCT: i64 = 3
113const ST_PF_LIG_ALPHA: i64 = 4
114const ST_PF_FAT_ALPHA: i64 = 5
115const ST_PF_FAT_DAMP: i64 = 6
116const ST_PF_RIB_R_MM: i64 = 7
125const ST_PF_SKIN_ALPHA: i64 = 8
126const ST_PF_N: i64 = 9
128const ST_PROF_LARGE_SOFT: i64 = 0
129const ST_PROF_SMALL_FIRM: i64 = 1
130const ST_PROF_GLUTE: i64 = 2
133const ST_PROF_SOFT_TAUT: i64 = 3
140const ST_PROF_SEED_BASE: i64 = 1000
142const ST_Q12: i64 = 4096
143const ST_Q20: i64 = 1048576
144const ST_GRAV_CMM: i64 = 981000
150const ST_GRAD_SHIFT: i64 = 1
154const ST_DT_REF_US: i64 = 4167
950const ST_M_ASPECT: i64 = 0
951const ST_M_CENTROID: i64 = 1
952const ST_M_MINVOL: i64 = 2
953const ST_M_SUMVOL: i64 = 3
954const ST_M_KIN: i64 = 4
955const ST_M_NSURF: i64 = 5
956const ST_M_PROJ: i64 = 6
957const ST_M_N: i64 = 8

functions

157func st_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
158func st_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 2: st_measuremain
159func st_max(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 2: st_measuremain
163func st_div_r(a: i64, b: i64) -> i64
169func st_isqrt(n: i64) -> i64
189func st_layer_alpha_dist(l: i64) -> i64
200func st_layer_alpha_vol(l: i64) -> i64
called by 1: st_new
210func st_layer_damp(l: i64) -> i64
called by 1: st_eff_damp
228func st_hash(seed: i64, salt: i64) -> i64
238func st_span(seed: i64, salt: i64, lo: i64, hi: i64) -> i64
called by 1: st_profile_seeded calls 1: st_hash
251func st_profile_seeded(seed: i64, field: i64) -> i64
called by 1: st_profile calls 3: st_hashpg_samplest_span
277func st_profile(prof: i64, field: i64) -> i64
324func st_wall_drop(xm: i64, rib_r: i64) -> i64
called by 1: st_new calls 2: st_absst_isqrt
333func st_eff_alpha_dist(W: *i64, layer: i64) -> i64
340func st_eff_damp(W: *i64, layer: i64) -> i64
called by 1: st_substep calls 2: st_profilest_layer_damp
353func st_alpha_tilde(alpha_q12: i64, dsum: i64, dt_us: i64) -> i64
called by 1: st_substep calls 1: st_div_r
365func st_inside(xm: i64, ym: i64, zm: i64, a: i64, b: i64, c: i64) -> i64
called by 1: st_new
373func st_six_vol(W: *i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
called by 2: st_newst_measure calls 1: st_div_r
390func st_six_vol_q(W: *i64, i0: i64, i1: i64, i2: i64, i3: i64) -> i64
calls 1: st_div_r
406func st_add_edge(W: *i64, htab: *i64, hidx: *i64, hmask: i64,
called by 1: st_new calls 2: st_isqrtst_layer_alpha_dist
453func st_new(prof: i64, h_mm: i64) -> *i64
716func st_reset_state(W: *i64) -> i64
725func st_set_touch(W: *i64, on: i64, cx: i64, cy: i64, cz: i64, r: i64) -> i64
called by 1: main
735func st_substep(W: *i64, gx: i64, gy: i64, gz: i64, dt_us: i64, iters: i64) -> i64
943func st_run(W: *i64, gx: i64, gy: i64, gz: i64, steps: i64, dt_us: i64, iters: i64) -> i64
called by 4: mainsg_settlemainmain calls 1: st_substep
963func st_measure(W: *i64, out: *i64) -> i64