code wiki / (root) / nx_stl.nx

nx_stl.nx

buildroot/runtime/nx_stl.nx

9260 B246 linesdepth 5pulls 9 transitivereach 31 importersview sourcekind librarytopic stl
docsdependenciesstructsconstsfunctions

about

nx_stl.nx -- binary STL mesh reader (1980s 3D Systems format, public domain). Per cardinal NISHI_3D_PRINT_ROADMAP scope: STL spec is public domain since 1980s; reading it is not a license entanglement (Cardinal 0). Composes nx_le + nx_fp32_q14 + nx_hash + nx_mesh. Binary STL on-disk layout: bytes 0..79 header (ignored; ASCII STL detection: starts with "solid"; we refuse ASCII for P0.2a) bytes 80..83 little-endian uint32 = n_tris bytes 84.. per-triangle records, 50 bytes each: 0..11 normal vector (3 × f32) IGNORED -- we trust mesh winding, normals are often wrong in user-exported STL 12..47 3 vertices × 3 × f32 = 9 floats 48..49 attribute byte count (IGNORED) Total file size = 84 + 50 * n_tris. Vertex dedup strategy: Raw STL has 3 verts per tri with massive duplication (closed mesh of n tris has ~n/2 unique vertices, ~50% saving). We hash each (x_q14, y_q14, z_q14) triple via nx_hash_fnv1a_bytes into nx_hash; collisions are resolved by direct (x,y,z) verification against the existing mesh vertex. False matches from hash collisions allocate a new vertex (slight over-alloc; correctness preserved). Capacity heuristic: Worst case (no dedup): 3 * n_tris vertices. We size nx_hash to the next power of 2 above n_tris * 4 to keep load factor < 0.75. Manifold-check expectation: a well-formed closed STL produces a mesh that nx_mesh_is_manifold accepts. Real-world STL from scanners (Christus from Scan The World) sometimes has minor non-manifold artefacts (T-junctions, near-duplicate verts at quantization boundaries); those are the slicer's problem, not the parser's.

dependencies 5 imports · 28 importers

nx_syscalls.nx nx_le.nx nx_hash.nx nx_mesh.nx nx_fp32_q14.nx nx_stl.nx nx_cad_exceed.nx nx_cad_page.nx nx_cad_prims2_test.nx nx_cad_test.nx nx_csg_fillet_test.nx nx_csg_rot_gate.nx nx_csg_rotxz_gate.nx nx_csg_scene_gate.nx nx_csg_test.nx nx_csg_torus_test.nx

diagram shows first 10 each side; +0 more imports, +18 more importers in the complete lists below.

imports: nx_syscalls.nxnx_le.nxnx_hash.nxnx_mesh.nxnx_fp32_q14.nx

imported by: nx_cad_exceed.nxnx_cad_page.nxnx_cad_prims2_test.nxnx_cad_test.nxnx_csg_fillet_test.nxnx_csg_rot_gate.nxnx_csg_rotxz_gate.nxnx_csg_scene_gate.nxnx_csg_test.nxnx_csg_torus_test.nxnx_cube_to_gcode_test.nxnx_dcc_slice_probe.nxnx_dcc_to_print_test.nxnx_mesh_decimate_gate.nxnx_print_e2e_gate.nxnx_slicer_lib.nxnx_stl_adversarial_test.nxnx_stl_test.nxnx_stl_to_gcode_real_test.nxnx_stl_write_mesh_test.nxnx_stl_write_test.nxnx_underridge_cleaner_gate.nxnx_underridge_gcode_gate.nxnx_underridge_gel_gate.nxnx_underridge_hook_gate.nxnx_underridge_hook_gcode_gate.nxnx_underridge_hook_petg_gate.nxnx_underridge_master_gate.nx

structs

67struct NxStlResult

consts

52const NX_STL_OK: i64 = 0
53const NX_STL_ERR_TOO_SHORT: i64 = 1
54const NX_STL_ERR_TRUNCATED: i64 = 2
55const NX_STL_ERR_BAD_FLOAT: i64 = 3 // Inf/NaN coord
56const NX_STL_ERR_ASCII_REFUSED: i64 = 4 // ASCII STL parser deferred
57const NX_STL_ERR_ALLOC_FAILED: i64 = 5
58const NX_STL_ERR_DEDUP_OVERFLOW: i64 = 6
63const NX_STL_ERR_EMPTY: i64 = 7
75const NX_STL_RES_BYTES: i64 = 40

functions

79func nx_stl_is_ascii(buf: *u8, buf_len: i64) -> i64
called by 1: nx_stl_load_binary
97func nx_stl_pack_xyz(x: i64, y: i64, z: i64, scratch: *u8) -> i64
106func nx_stl_intern_vertex(m: *NxMesh, dedup: *NxHash, scratch: *u8,
135func nx_stl_next_pow2(n: i64) -> i64
called by 1: nx_stl_load_binary
153func nx_stl_load_binary(buf: *u8, buf_len: i64) -> *NxStlResult