nx_mmdev_lib.nx
buildroot/runtime/nx_mmdev_lib.nx
about
nx_mmdev_lib.nx -- THE MILLIMETRE SURFACE-DEVIATION RULER (PG4, procgen.plan, 2026-08-24).
WHY: every realism claim on the human lane is graded by nx_bodybench in PERMIL of silhouette and normal
agreement. A cosmetic surgeon buys none of that. The clinical unit is millimetres of predicted-vs-actual
surface deviation, and the published soft-tissue prediction bar sits near 1-2 mm mean error. Without a
ruler in that unit every fidelity claim after this is aesthetic opinion wearing a number.
WHAT IT MEASURES: for EVERY vertex of mesh A, the exact Euclidean distance to the nearest point on the
SURFACE of mesh B (point-to-triangle, Ericson 5.1.5, all integer), then mean, p95 and max. Full
population, never a sample: `verts` is printed and the gate binds every assertion to it.
UNIT DERIVED, NOT PICKED: coordinates are held in tenths of a millimetre. The barycentric test forms
products of two dot products; each dot is bounded by 3 * extent^2. For an extent of 2.5 m at 0.1 mm
that is 3 * 25000^2 = 1.9e9 per dot and 3.5e18 per product, under the 9.2e18 i64 ceiling. A finer unit
overflows a whole-body subject; a coarser one is too blunt for a 1 mm bar. The extent bound is CHECKED
at load and the ruler REFUSES by name above it -- wrong in the direction of doing nothing.
ACCELERATION WITHOUT SAMPLING: B's triangles go into a uniform grid whose resolution is derived from the
triangle count (about four triangles per cell). A query walks expanding rings of cells and stops when
the ring's inner face is provably farther than the best hit so far. Exact, never approximate.
DECLARED IMPRECISIONS: (1) A's vertices are visited per triangle-vertex, so a vertex shared by k faces
weighs k times -- the mean is valence-weighted, which favours dense regions; printed as `tri_verts`.
(2) p95 is read from a histogram with 0.1 mm bins, so it is exact to the bin. (3) One-sided A->B;
the gate runs both directions and reports both. license_tier: ORIGINAL
dependencies 3 imports · 9 importers
imports: nx_syscalls.nxnx_vecmath.nxnx_nxmesh_lib.nx
imported by: nx_autorig_pose_gate.nxnx_devpaint_gate.nxnx_devpaint_lib.nxnx_mmdev.nxnx_mmdev_gate.nxnx_rigbench_lib.nxnx_rigbench_lib_t21.nxnx_xport_gate.nxnx_xport_lib.nx
structs
| none |
consts
| 32 | const MD_EXTENT_MAX: i64 = 25000 |
| 35 | const MD_HIST_BINS: i64 = 5000 |
| 36 | const MD_TARGET_TRIS_PER_CELL: i64 = 4 |
| 37 | const MD_P95_NUM: i64 = 95 |
| 38 | const MD_P95_DEN: i64 = 100 |
| 41 | const MD_R_VERTS: i64 = 0 |
| 42 | const MD_R_TRIS_B: i64 = 1 |
| 43 | const MD_R_SUM: i64 = 2 |
| 44 | const MD_R_MAX: i64 = 3 |
| 45 | const MD_R_P95: i64 = 4 |
| 46 | const MD_R_CELLS_AXIS: i64 = 5 |
| 47 | const MD_R_OVERFLOW_BIN: i64 = 6 |
| 48 | const MD_R_REFUSED: i64 = 7 // 0 ok, 1 extent bound, 2 unreadable, 3 empty |
| 49 | const MD_R_N: i64 = 8 |
| 131 | const MD_G_MIN: i64 = 0 |
| 132 | const MD_G_CS: i64 = 3 |
| 133 | const MD_G_N: i64 = 4 |
| 134 | const MD_G_HEAD: i64 = 5 |
| 135 | const MD_G_NEXT: i64 = 6 |
| 136 | const MD_G_TRI: i64 = 7 |
| 137 | const MD_G_NTRI: i64 = 8 |
| 138 | const MD_G_ENTRIES: i64 = 9 |
| 149 | const MD_G_COORD: i64 = 10 |
| 150 | const MD_G_WORDS: i64 = 11 |
functions
| 51 | func md_res() -> *i64 |
| 59 | func md_dist2_pt_tri(px: i64, py: i64, pz: i64, |
| 152 | func md_cell_of(v: i64, mn: i64, cs: i64, n: i64) -> i64 |
| 160 | func md_grid_build(mb: *u8, gp: *i64) -> i64 |
| 269 | func md_query(mb: *u8, gp: *i64, px: i64, py: i64, pz: i64) -> i64 |
| 329 | func md_measure(ma: *u8, mb: *u8, res: *i64) -> i64 |
| 380 | func md_mean(res: *i64) -> i64 { if res[MD_R_VERTS] == 0 { return 0 } return res[MD_R_SUM] / res[MD_R_VERTS] } |