code wiki / _hdl_build / nx_mesh2glb.nx

nx_mesh2glb.nx

buildroot/runtime/_hdl_build/nx_mesh2glb.nx

50748 B909 linesdepth 6pulls 12 transitivereach 3 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_mesh2glb.nx -- NXMSH2 -> INTERACTIVE .glb (operator 2026-08-05: "a picture vs the other files' full interactivity panel -- that's dumb"). The measurement organs emit NXMSH2 (per-tri colour = the deviation heatmap lives there); the showcase viewer consumes .glb. This organ closes that seam, so a FITTED body and a PAINTED HEATMAP both become drag-to-rotate panels, not screenshots -- an interactive deviation map is a capability the reference industrial tools ship as static report pages. Positions PASS THROUGH as raw f32 bits (zero re-quantisation); per-tri colour is replicated to the tri's 3 vertices as normalized u8 VEC4; per-vertex normals are {VEC3, FLOAT} and UNIT. CORRECTED 2026-08-25. That last clause used to read "normals transcode to normalized i16 -- the exact accessor types our proven nishi_walk.glb already uses, so the viewer needs nothing new". nishi_walk.glb was NOT proven; it was simply never checked against the specification. KhronosGroup/glTF-Validator rejects {VEC3, SHORT normalized} for NORMAL outright (MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT) and rejects its 6-byte element as unaligned (MESH_PRIMITIVE_ACCESSOR_UNALIGNED). So this exporter inherited a defect BY CITING ANOTHER OF OUR FILES AS THE STANDARD -- which is how a house style becomes indistinguishable from a specification. The bounds were wrong for the same reason: see the JSON below. nx_mesh2glb <in.nxmesh> <out.glb> | selftest license_tier: ORIGINAL expect_exit: 0

dependencies 5 imports · 3 importers

nx_syscalls.nx nx_nxa.nx nx_glbnorm_lib.nx nx_nxmesh_lib.nx nx_asset_prov_lib.nx nx_mesh2glb.nx nx_mesh_neutral_baseline_gate_t346 nx_meshview_projection_canonical_g nx_meshview_projection_gate_t332.n

imports: nx_syscalls.nxnx_nxa.nxnx_glbnorm_lib.nxnx_nxmesh_lib.nxnx_asset_prov_lib.nx

imported by: nx_mesh_neutral_baseline_gate_t346.nxnx_meshview_projection_canonical_gate_t332.nxnx_meshview_projection_gate_t332.nx

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

main hw sys_write sys_exit mg_is_selftest mg_selftest st_fix 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 ↻ mg_w32 st_enc1000 mg_f32_frac sys_openat_wr sys_write ↻ sys_close hw ↻ mg_convert sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close ↻ mg_refuse hw ↻

structs

none

consts

24const MG_KEY_ABOVE_ALL: i64 = 4294967296 // one past the largest key gn_f32_key can return
25const MG_KEY_BELOW_ALL: i64 = 0 - 1 // one below the smallest; keys are never negative
26const MG_NRM_GAIN: i64 = 4 // permille x 4 = 4000 for a unit component: the largest
29const MG_VEC3_F32_BYTES: i64 = 12
30const MG_V3: i64 = 3
58const MG_CONTAINER_NXMSH2: i64 = 1
59const MG_CONTAINER_NXA: i64 = 2
60const MG_NXA_HDR_BYTES: i64 = 32 // magic, version, nsect, toccheck
61const MG_NXA_TOC_WORDS: i64 = 4 // tag, byte_off, word_len, check
62const MG_NXA_UNITS_PER_M: i64 = 100000 // VERT/SKEL are 0.01 mm; 100000 of them per metre
63const MG_Q12: i64 = 4096 // SKIN weights are q12
64const MG_SKEL_REC_WORDS: i64 = 8
65const MG_SKIN_REC_WORDS: i64 = 8
66const MG_SKEL_PARENT: i64 = 0
67const MG_SKEL_TX: i64 = 1
68const MG_SKEL_ROOT: i64 = 0 - 1 // parent = -1 marks a root joint (spec)
69const MG_SKIN_W0: i64 = 4 // weights follow the four joint slots
70const MG_GL_UNSIGNED_BYTE: i64 = 5121 // glTF componentType enum, named for what it is
71const MG_GL_UNSIGNED_SHORT: i64 = 5123
72const MG_GL_UNSIGNED_INT: i64 = 5125
73const MG_GL_FLOAT: i64 = 5126
77const MG_GL_ARRAY_BUFFER: i64 = 34962 // vertex attribute data
78const MG_GL_ELEMENT_ARRAY_BUFFER: i64 = 34963 // index data
79const MG_U8_MAX: i64 = 255 // JOINTS_0 may be UNSIGNED_BYTE only while every index fits
80const MG_U16_MAX: i64 = 65535 // UNSIGNED_SHORT ceiling: more joints REFUSES, never wraps
81const MG_F32_EXP_BIAS: i64 = 127
82const MG_F32_MANT_BITS: i64 = 23
83const MG_F32_SIGN_SHIFT: i64 = 31
84const MG_VEC3: i64 = 3
85const MG_VEC4: i64 = 4
86const MG_F32_BYTES: i64 = 4
87const MG_U32_BYTES: i64 = 4
88const MG_U16_BYTES: i64 = 2
89const MG_U8_BYTES: i64 = 1
90const MG_MAT4_BYTES: i64 = 64
91const MG_GLB_HDR_BYTES: i64 = 12
92const MG_CHUNK_HDR_BYTES: i64 = 8
93const MG_GLB_VERSION: i64 = 2
94const MG_JSON_BASE: i64 = 4096 // the JSON that does not scale with joint count
95const MG_JSON_PER_JOINT: i64 = 128 // worst case measured 105 B: a node (name + 3 translations of
98const MG_PERMILLE: i64 = 1000
99const MG_ASCII_ZERO: i64 = 48
100const MG_ASCII_MINUS: i64 = 45
101const MG_ASCII_DOT: i64 = 46
102const MG_ASCII_SPACE: i64 = 32
103const MG_DECIMAL: i64 = 10
104const MG_EXIT_REFUSE: i64 = 3 // the exit the NXMSH2 path already uses for a refused input
105const MG_EXIT_BUDGET: i64 = 4
106const MG_EXIT_IO: i64 = 6
107const MG_MAGIC_32767: i64 = 32767
108const MG_MAGIC_65535: i64 = 65535
109const MG_MAGIC_100000: i64 = 100000
121const MG_MSH_FIXED_HDR_BYTES: i64 = 16 // magic[8] + u32 nlay + u32 ntri: the bytes needed to read the counts
122const MG_MSH_LAYROW_BYTES: i64 = 24
123const MG_MSH_TRIREC_BYTES: i64 = 84 // 9 position + 9 normal + 3 colour float32
128const MG_COL_DARK_SUM: i64 = 12 // at or below this the source carried no colour at all
129const MG_BONE_R: i64 = 216 // the meshview bone fallback, inherited deliberately so that
130const MG_BONE_G: i64 = 210 // a genuinely uncoloured mesh is never rendered invisible
131const MG_BONE_B: i64 = 198
132const MG_ALLOC_SLACK_BYTES: i64 = 64 // mmap headroom past a DERIVED length; not a budget, not a cap
133const MG_M8388607: i64 = 8388607
134const MG_M8388608: i64 = 8388608
135const MG_BIG: i64 = 4611686018427387903

functions

137func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
138func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
139func mg_u32(b: *u8, o: i64) -> i64 { return (b[o] as i64) + ((b[o+1] as i64)<<8) + ((b[o+2] as i64)<<16) + ((b[o+3] as i64)<<24) }
140func mg_w8(b: *u8, o: i64, v: i64) -> i64 { b[o] = (v&255) as u8; return o+1 }
141func mg_w16(b: *u8, o: i64, v: i64) -> i64 { b[o]=(v&255) as u8; b[o+1]=((v>>8)&255) as u8; return o+2 }
called by 1: mg_convert_nxa
142func mg_w32(b: *u8, o: i64, v: i64) -> i64 { b[o]=(v&255) as u8; b[o+1]=((v>>8)&255) as u8; b[o+2]=((v>>16)&255) as u8; b[o+3]=((v>>24)&255) as u8; return o+4 }
143func mg_align4(x: i64) -> i64 { return (x+3)/4*4 }
144func mg_cat(o: *u8, at: i64, s: *u8) -> i64 { var i: i64=0; var a: i64=at; while s[i]!=(0 as u8){o[a]=s[i]; a=a+1; i=i+1} return a }
145func mg_num(o: *u8, at: i64, v: i64) -> i64
160func mg_f32i(w: i64, scale: i64) -> i64
called by 1: mg_convert_msh
185func mg_col_u8(w: i64) -> i64 { return nm_col_u8_of(w) }
called by 1: mg_convert_msh calls 1: nm_col_u8_of
186func mg_refuse(reason: *u8) -> i64 { hw("MESH2GLB REFUSED: " as *u8); hw(reason); hw("\n" as *u8); return 0 }
187func mg_nxa_refuse(reason: *u8) -> i64 { hw("MESH2GLB REFUSED (NXANIM01): " as *u8); hw(reason); hw("\n" as *u8); return 0 }
called by 1: mg_convert_nxa calls 1: hw
192func mg_f32_frac(v: i64, den: i64) -> i64
209func mg_dec(o: *u8, at: i64, num: i64, den: i64) -> i64
called by 1: mg_convert_nxa calls 1: mg_num
233func mg_container(b: *u8, n: i64) -> i64
called by 1: mg_dispatch calls 1: nxa_magic
238func mg_nxa_wl(b: *u8, tag: i64) -> i64
called by 1: mg_convert_nxa
246func mg_ibm_translate(bin: *u8, at0: i64, tx: i64, ty: i64, tz: i64) -> i64
called by 1: mg_convert_nxa calls 2: mg_f32_fracmg_w32
259func mg_convert_nxa(b: *u8, n: i64, outp: *u8) -> i64
588func mg_provenance(b: *u8, n: i64, jrnl: *u8) -> i64
604func mg_dispatch(inp: *u8, outp: *u8, jrnl: *u8) -> i64
614func mg_convert(inp: *u8, outp: *u8) -> i64
623func mg_convert_msh(b: *u8, n: i64, outp: *u8) -> i64
820func st_enc1000(v: i64) -> i64 { return mg_f32_frac(v, MG_PERMILLE) } // the /1000 case of the ONE encoder
called by 1: st_fix calls 1: mg_f32_frac
821func st_fix(path: *u8) -> i64
846func mg_hasstr(b: *u8, n: i64, lit: *u8) -> i64
called by 1: mg_selftest
859func mg_selftest() -> i64
887func mg_is_selftest(a: *u8) -> i64
called by 1: main
894func main(argc: i64, argv: *i64) -> i64