nx_tissuefield_lib.nx
buildroot/runtime/nx_tissuefield_lib.nx
about
nx_tissuefield_lib.nx -- THE SKULL-BOUND TISSUE-DEPTH SKIN SURFACE (aesthetictwin AT46, 2026-09-18).
Operator 2026-09-18: "we were trying to render a skull then every layer up ... controllable every layer up generative
capabilities". Today's faces are blended SDF blobs on a frame; nx_faceanat never reads the skull it was meant to sit on
(`nxmesh` count 0 in that file). This library builds the FIRST layer ON the generated skull: the skin is an OFFSET SURFACE of
the skull mesh, offset along the skull's own vertex normals by a tissue-depth FIELD interpolated from the forensic
tissue-depth table at anatomical landmarks that are LOCATED ON THE SKULL ITSELF (midline profile extrema, support
directions, canon ratios of the bony span), plus controllable fat compartments and named patches for the features that have
no bone behind them (globes and lids over the orbits, the nose over the empty aperture, the vermilion band).
EVERY NUMBER IS DATA OR IS DERIVED FROM THE RESOURCE IT DESCRIBES: depths, compartment magnitudes and construction ratios come
from knowledge/tissue_depth.conf (each row names its source; rows the research lane has not pinned say PENDING-REF), the
interpolation kernel width is the median nearest-landmark spacing of the located landmarks, grid steps are the mesh's own
mean edge length, the units are the skull's own (NXMSH2 float32 millimetres read as tenths of a millimetre, so one
tissue-depth unit mm10 IS one model unit u10), and the camera distance is derived from the head height and a declared frame
fraction. Nothing here reads nx_faceanat, nx_sdfrender or nx_skullsdf as code: the skull is consumed as the MESH those organs
emit, and the depth values nx_faceanat typed inline were carried into the conf with their source named.
FRAME: the skull mesh is anterior +z, superior +y, the subject's left +x (nx_meshview front view = camera on +z). The
rasteriser (nx_trimesh) looks down +z with the camera at -camz, so every vertex is pushed through a rotation of half a turn
about y (x -> -x, z -> -z): a proper rotation, never a mirror, so the subject's right eye lands on the image left as in a
photograph (the photo ruler's side convention).
LIB, no main. Composes nx_nxmesh_lib (the ONE NXMSH2 layout), nx_vecmath (isqrt, float32 codec), nx_trimesh (the
rasteriser), nx_png (the encoder), nx_itoa_lib (zero-alloc decimal). license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 6 imports · 4 importers
imports: nx_syscalls.nxnx_vecmath.nxnx_nxmesh_lib.nxnx_trimesh.nxnx_png.nxnx_itoa_lib.nx
imported by: nx_skull_canon_lib.nxnx_skullskin.nxnx_skullskin_gate.nxnx_tfl_decimate_gate.nx
structs
| none |
consts
| 34 | const TFL_I64: i64 = 8 |
| 35 | const TFL_Q16: i64 = 256 * 256 // the kernel's fixed point (weights and exp) |
| 36 | const TFL_NQ: i64 = 64 * 64 // the normal scale surface_nets emits and NXMSH2 stores (4096) |
| 37 | const TFL_ZNONE: i64 = 0 - 1000 * 1000 * 1000 // "no surface in this cell" for the frontal depth maps |
| 38 | const TFL_FAR: i64 = 1000 * 1000 * 1000 |
| 39 | const TFL_PERMIL: i64 = 1000 |
| 40 | const TFL_MODE644: i64 = 420 |
| 41 | const TFL_MODE755: i64 = 493 |
| 42 | const TFL_PATHB: i64 = 512 |
| 43 | const TFL_STDOUT: i64 = 1 |
| 44 | const TFL_PIPE: i64 = 124 |
| 45 | const TFL_NL: i64 = 10 |
| 46 | const TFL_HASH: i64 = 35 |
| 47 | const TFL_MINUS: i64 = 45 |
| 48 | const TFL_COMMA: i64 = 44 |
| 49 | const TFL_ZERO: i64 = 48 |
| 50 | const TFL_NINE: i64 = 57 |
| 51 | const TFL_BYTE: i64 = 255 |
| 53 | const TFL_EXP_TERMS: i64 = 12 // Taylor terms for e^-1; the 12th term is below one Q16 unit |
| 54 | const TFL_EXP_MAX_INT: i64 = 24 // exp(-24) is below one Q16 unit: the weight is zero past this |
| 55 | const TFL_SUPPORT_SIGMAS: i64 = 3 // a Gaussian compartment's support for the partition tooth: 3 sigma |
| 56 | const TFL_RIM_SAMPLES: i64 = 16 // boundary samples of the lid ellipse for the rim depth |
| 57 | const TFL_SPHERE_RINGS: i64 = 12 |
| 58 | const TFL_SPHERE_SEGS: i64 = 16 |
| 59 | const TFL_LID_SUBDIV: i64 = 2 // lid and nose patches are gridded at half the mesh edge |
| 60 | const TFL_COL_WHITE: i64 = 255 + 255 * 256 + 255 * 256 * 256 |
| 61 | const TFL_COL_IRIS: i64 = 60 + 90 * 256 + 110 * 256 * 256 // a blue-grey iris: hue is a later layer's data |
| 62 | const TFL_COL_PUPIL: i64 = 8 + 8 * 256 + 8 * 256 * 256 |
| 63 | const TFL_COL_BROW: i64 = 60 + 45 * 256 + 35 * 256 * 256 |
| 64 | const TFL_COL_SEAM: i64 = 70 + 40 * 256 + 40 * 256 * 256 |
| 65 | const TFL_COL_BONE: i64 = 232 + 224 * 256 + 216 * 256 * 256 // the bone tint nx_skullsdf stores (910,890,845 permil) |
| 66 | const TFL_BG: i64 = 20 + 28 * 256 + 40 * 256 * 256 // the dark slate every mesh render uses (nx_meshview MV_BG) |
| 69 | const TFL_M_NV: i64 = 0 |
| 70 | const TFL_M_NT: i64 = 1 |
| 71 | const TFL_M_VX: i64 = 2 |
| 72 | const TFL_M_VY: i64 = 3 |
| 73 | const TFL_M_VZ: i64 = 4 |
| 74 | const TFL_M_NX: i64 = 5 |
| 75 | const TFL_M_NY: i64 = 6 |
| 76 | const TFL_M_NZ: i64 = 7 |
| 77 | const TFL_M_TA: i64 = 8 |
| 78 | const TFL_M_TB: i64 = 9 |
| 79 | const TFL_M_TC: i64 = 10 |
| 80 | const TFL_M_X0: i64 = 11 |
| 81 | const TFL_M_X1: i64 = 12 |
| 82 | const TFL_M_Y0: i64 = 13 |
| 83 | const TFL_M_Y1: i64 = 14 |
| 84 | const TFL_M_Z0: i64 = 15 |
| 85 | const TFL_M_Z1: i64 = 16 |
| 86 | const TFL_M_EDGE: i64 = 17 // mean triangle edge length, u10 (the mesh's own resolution) |
| 87 | const TFL_M_FM: i64 = 18 // frontal depth map ptr (max z per (x,y) cell), or 0 |
| 88 | const TFL_M_FMW: i64 = 19 |
| 89 | const TFL_M_FMH: i64 = 20 |
| 90 | const TFL_M_FMCELL: i64 = 21 |
| 91 | const TFL_M_RAW: i64 = 22 // triangle-soup vertex count before welding |
| 92 | const TFL_M_N: i64 = 24 |
| 95 | const TFL_T_NROWS: i64 = 0 |
| 96 | const TFL_T_NFAT: i64 = 1 |
| 97 | const TFL_T_NPATCH: i64 = 2 |
| 98 | const TFL_T_NPENDING: i64 = 3 |
| 99 | const TFL_T_MALFORMED: i64 = 4 |
| 100 | const TFL_T_HDR: i64 = 8 |
| 101 | const TFL_R_FIELDS: i64 = 16 |
| 102 | const TFL_R_NAME: i64 = 0 |
| 103 | const TFL_R_DEPTH: i64 = 1 // mm10, or -1 for a row that is located but does not vote |
| 104 | const TFL_R_SRC: i64 = 2 |
| 105 | const TFL_R_NOTE: i64 = 3 |
| 106 | const TFL_R_X: i64 = 4 |
| 107 | const TFL_R_Y: i64 = 5 |
| 108 | const TFL_R_Z: i64 = 6 |
| 109 | const TFL_R_AX: i64 = 7 // anchor: the skull vertex nearest the located point |
| 110 | const TFL_R_AY: i64 = 8 |
| 111 | const TFL_R_AZ: i64 = 9 |
| 112 | const TFL_R_AIDX: i64 = 10 |
| 113 | const TFL_R_ADIST: i64 = 11 |
| 114 | const TFL_R_STATE: i64 = 12 // 0 not located, 1 located, 2 located by a named fallback |
| 115 | const TFL_R_PENDING: i64 = 13 |
| 116 | const TFL_ROWS_CAP: i64 = 64 |
| 117 | const TFL_FAT_CAP: i64 = 16 |
| 118 | const TFL_PATCH_CAP: i64 = 64 |
| 119 | const TFL_T_I64S: i64 = TFL_T_HDR + (TFL_ROWS_CAP + TFL_FAT_CAP + TFL_PATCH_CAP) * TFL_R_FIELDS |
| 120 | const TFL_ST_NONE: i64 = 0 |
| 121 | const TFL_ST_LOCATED: i64 = 1 |
| 122 | const TFL_ST_FALLBACK: i64 = 2 |
| 125 | const TFL_K_SIGMA: i64 = 0 |
| 126 | const TFL_K_DMIN: i64 = 1 |
| 127 | const TFL_K_DMED: i64 = 2 |
| 128 | const TFL_K_DMAX: i64 = 3 |
| 129 | const TFL_K_LOCATED: i64 = 4 |
| 130 | const TFL_K_FALLBACK: i64 = 5 |
| 131 | const TFL_K_UNLOCATED: i64 = 6 |
| 132 | const TFL_K_ANCHOR_MAX: i64 = 7 |
| 133 | const TFL_K_VOTERS: i64 = 8 |
| 134 | const TFL_K_N: i64 = 16 |
| 553 | const TFL_DECIM_MAX_CELLS: i64 = 6000000 |
functions
| 138 | func tfl_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(TFL_STDOUT, s, n); return 0 } called by 16: skc_densifyskc_midline_locateskc_dump_profileskc_bandsskc_holdoutskc_print_line+10 calls 1: sys_write |
| 139 | func tfl_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 140 | func tfl_kv(k: *u8, v: i64) -> i64 { tfl_puts(k); tfl_pn(v); return 0 } called by 12: skc_densifyskc_midline_locateskc_dump_profileskc_bandsskc_holdoutskn_kv+6 calls 2: tfl_putstfl_pn |
| 141 | func tfl_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 142 | func tfl_streq(a: *u8, b: *u8) -> i64 |
| 149 | func tfl_atoi(s: *u8) -> i64 |
| 157 | func tfl_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } |
| 158 | func tfl_min(a: i64, b: i64) -> i64 { if a < b { return a } return b } called by 1: main |
| 159 | func tfl_max(a: i64, b: i64) -> i64 { if a > b { return a } return b } |
| 161 | func tfl_has(s: *u8, lit: *u8) -> i64 |
| 174 | func tfl_cat(d: *u8, o: i64, s: *u8) -> i64 { var p: i64 = o; var i: i64 = 0; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } d[p] = 0 as u8; return p } |
| 175 | func tfl_catn(d: *u8, o: i64, v: i64) -> i64 { let p: i64 = nxi_buf(d, o, v); d[p] = 0 as u8; return p } |
| 178 | func tfl_exp_init() -> i64 called by 1: tfl_exp_q16 |
| 189 | func tfl_exp_q16(t: i64) -> i64 |
| 206 | func tfl_gauss_q16(d2: i64, sigma: i64) -> i64 |
| 216 | func tfl_tab_new() -> *i64 |
| 222 | func tfl_row(T: *i64, i: i64) -> *i64 { return ((T as i64) + (TFL_T_HDR + i * TFL_R_FIELDS) * TFL_I64) as *i64 } |
| 223 | func tfl_fatrow(T: *i64, i: i64) -> *i64 { return ((T as i64) + (TFL_T_HDR + (TFL_ROWS_CAP + i) * TFL_R_FIELDS) * TFL_I64) as *i64 } |
| 224 | func tfl_patchrow(T: *i64, i: i64) -> *i64 { return ((T as i64) + (TFL_T_HDR + (TFL_ROWS_CAP + TFL_FAT_CAP + i) * TFL_R_FIELDS) * TFL_I64) as *i64 } |
| 226 | func tfl_split(line: *u8, f: *i64, cap: i64) -> i64 |
| 242 | func tfl_conf_load(path: *u8, T: *i64) -> i64 |
| 315 | func tfl_row_find(T: *i64, name: *u8) -> i64 |
| 320 | func tfl_fat_find(T: *i64, name: *u8) -> i64 |
| 326 | func tfl_patch(T: *i64, key: *u8) -> i64 called by 10: skc_midline_locateskc_locate_passmainmaintfl_material_applytfl_locate+4 calls 3: tfl_patchrowtfl_streqtfl_puts |
| 332 | func tfl_patch_set(T: *i64, key: *u8, v: i64) -> i64 |
| 338 | func tfl_material_apply(T: *i64) -> i64 |
| 345 | func tfl_fat_set(T: *i64, name: *u8, v: i64) -> i64 |
| 353 | func tfl_depths_scale(T: *i64, permil: i64) -> i64 |
| 362 | func tfl_mesh_new() -> *i64 |
| 368 | func tfl_hash3(x: i64, y: i64, z: i64) -> i64 called by 1: tfl_mesh_load |
| 376 | func tfl_mesh_load(path: *u8, M: *i64) -> i64 called by 4: skc_loadmainmainsks_surface calls 11: sys_mmapsys_read_filenm_ntrisnm_tri_basenm_coordvm_f32_to_int+5 |
| 478 | func tfl_mesh_clone_positions(M: *i64) -> *i64 |
| 490 | func tfl_mesh_bbox_refresh(M: *i64) -> i64 |
| 506 | func tfl_mesh_write(M: *i64, path: *u8, col_r_permil: i64, col_g_permil: i64, col_b_permil: i64) -> i64 called by 3: mainmainmain calls 10: nm_file_bytessys_mmapnm_put_u32nm_tri_basenm_put_trivm_int_to_f32+4 |
| 554 | func tfl_mesh_decimate(M: *i64, cell: i64) -> *i64 |
| 624 | func tfl_frontmap(M: *i64) -> i64 |
| 644 | func tfl_front_at(M: *i64, x: i64, y: i64, reach: i64) -> i64 |
| 675 | func tfl_profile(M: *i64, prof: *i64, pidx: *i64, cap: i64) -> i64 |
| 695 | func tfl_noisefloor(prof: *i64, nb: i64, edge: i64) -> i64 |
| 722 | func tfl_extrema(prof: *i64, nb: i64, swing: i64, ex: *i64, ty: *i64, cap: i64) -> i64 |
| 754 | func tfl_support(M: *i64, dx: i64, dy: i64, dz: i64, ylo: i64, yhi: i64, zlo: i64, xside: i64) -> i64 |
| 776 | func tfl_support_lat(M: *i64, dx: i64, dy: i64, dz: i64, ylo: i64, yhi: i64, zlo: i64, xside: i64, xmin: i64) -> i64 |
| 799 | func tfl_crest(M: *i64, x: i64, y: i64, dx: i64, dy: i64, reach: i64, out: *i64) -> i64 called by 4: skc_midline_locateskc_locate_passtfl_locatetfl_push_eyes calls 3: tfl_frontmaptfl_maxtfl_front_at |
| 815 | func tfl_nearest(M: *i64, x: i64, y: i64, z: i64, out: *i64) -> i64 |
| 831 | func tfl_place(T: *i64, name: *u8, x: i64, y: i64, z: i64, state: i64) -> i64 |
| 838 | func tfl_place_v(T: *i64, name: *u8, M: *i64, v: i64, state: i64) -> i64 |
| 843 | func tfl_get(T: *i64, name: *u8, out3: *i64) -> i64 called by 10: skc_midline_locateskc_locate_passmainskg_skin_thirdsmaintfl_locate+4 calls 2: tfl_row_findtfl_row |
| 853 | func tfl_locate(M: *i64, T: *i64, K: *i64) -> i64 called by 2: mainsks_surface calls 17: sys_mmaptfl_profiletfl_noisefloortfl_extrematfl_kvtfl_puts+11 |
| 1053 | func tfl_print_rows(T: *i64) -> i64 |
| 1072 | func tfl_sigma(T: *i64) -> i64 |
| 1110 | func tfl_depth_median(T: *i64) -> i64 |
| 1130 | func tfl_fat_place(T: *i64) -> i64 |
| 1188 | func tfl_depth_field(M: *i64, T: *i64, D: *i64, K: *i64) -> i64 called by 2: mainsks_surface calls 6: tfl_sigmatfl_depth_mediantfl_gauss_q16tfl_rowtfl_fatrowsys_mmap |
| 1247 | func tfl_offset(M: *i64, D: *i64, S: *i64) -> i64 |
| 1263 | func tfl_max_displacement(A: *i64, B: *i64) -> i64 |
| 1278 | func tfl_moved_partition(M: *i64, D0: *i64, D1: *i64, cx: i64, cy: i64, cz: i64, rad: i64, out: *i64) -> i64 called by 1: main |
| 1295 | func tfl_push(x: i64, y: i64, z: i64, nx: i64, ny: i64, nz: i64, col: i64) -> i64 |
| 1301 | func tfl_push_mesh(M: *i64, col: i64, keep_side: i64) -> i64 |
| 1326 | func tfl_paint_skin(S: *i64, T: *i64, base: i64, skin_col: i64) -> i64 |
| 1380 | func tfl_push_globe(cx: i64, cy: i64, cz: i64, r: i64, iris: i64, pupil: i64, lid: i64) -> i64 |
| 1447 | func tfl_push_lid(S: *i64, T: *i64, cx: i64, cy: i64, cz: i64, r: i64, semx: i64, semy: i64, flen: i64, fh: i64, tilt10: i64, col: i64) -> i64 |
| 1547 | func tfl_push_eyes(M: *i64, S: *i64, T: *i64, tilt10: i64, skin_col: i64, out: *i64) -> i64 |
| 1615 | func tfl_push_nose(S: *i64, T: *i64, col: i64, out: *i64) -> i64 |
| 1714 | func tfl_smooth_skin(M: *i64, S: *i64, D: *i64, dmed: i64) -> i64 |
| 1794 | func tfl_scene_normals() -> i64 { return tm_compute_normals() } calls 1: tm_compute_normals |
| 1797 | func tfl_render(fb: *i64, W: i64, H: i64, yaw: i64, head_u10: i64, frame_permil: i64) -> i64 |
| 1811 | func tfl_recentre(cx: i64, cy: i64, cz: i64) -> i64 |
| 1818 | func tfl_scene_to_mesh() -> *i64 |
| 1852 | func tfl_pair(a: *i64, b: *i64, W: i64, H: i64, out: *i64) -> i64 called by 1: main |
| 1865 | func sks_surface(skull_path: *u8, T: *i64, Mout: *i64, Dout: *i64, K: *i64) -> *i64 |
| 1894 | func tfl_peak_rss_kb() -> i64 |
| 1919 | func tfl_run_skullsdf(out: *u8, sex: i64, robust: i64, cell_um: i64) -> i64 |