code wiki / (root) / nx_mesh.nx

nx_mesh.nx

buildroot/runtime/nx_mesh.nx

12640 B336 linesdepth 4pulls 4 transitivereach 90 importersview sourcekind tooltopic mesh
docsdependenciesstructsconstsfunctions

about

nx_mesh.nx -- typed 3D mesh container. L1 canonical primitive. Closes a bits-up gap: graphics stack (nx_raster + nx_zbuf + nx_tex_sample + nx_vertex_pipeline + nx_render_pass) operates on RAW i64 arrays for vertices, UVs, and triangle indices. No typed envelope. Per the bits-up canonical-layer cardinal, that's a missing L1 container -- every graphics consumer should compose against `NxMesh` rather than re-deriving the layout convention each time. Same role for graphics that NxTensor plays for compute and Image plays for pixel buffers. ===== Layout convention ========================================= verts: [n_verts * 4] i64 per-vertex: (x_q14, y_q14, z_q14, packed_color) matches nx_vertex_pipeline + nx_voxel_mesh existing layouts so buffers compose directly. uvs: [n_verts * 2] i64 (NULL if mesh has no texture) per-vertex: (u_q10, v_q10) matches nx_tex_sample's Q10 UV convention. indices: [n_tris * 3] i64 triangle vertex indices per-triangle: (i0, i1, i2), counter-clockwise winding for front-face by convention. All buffers caller-owned or substrate-allocated via mmap; the NxMesh struct owns the LIFETIME of any buffers it alloc'd. ===== Why a struct + not just docs ============================== Two callers (nx_render_pass + nx_voxel_mesh) already work with these layouts. Per the rule-of-three + DRY cardinal: factor at 2-and-a-half (one of the existing callers + the new graphics work that wants meshes). The struct also lets us add verdicts at the boundary -- caller can't accidentally pass a 3-vert mesh as if it were 4-vert.

dependencies 3 imports · 68 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_mesh.nx nx_auto_supports_v2_target_test.nx nx_bvh.nx nx_bvh_test.nx nx_cad.nx nx_cad_exceed.nx nx_cad_page.nx nx_cad_prims2_test.nx nx_cad_test.nx nx_christus_integration_test.nx nx_csg.nx

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

imports: nx_syscalls.nxnx_tier.nxnx_loop.nx

imported by: nx_auto_supports_v2_target_test.nxnx_bvh.nxnx_bvh_test.nxnx_cad.nxnx_cad_exceed.nxnx_cad_page.nxnx_cad_prims2_test.nxnx_cad_test.nxnx_christus_integration_test.nxnx_csg.nxnx_csg_fillet_test.nxnx_csg_rot_gate.nxnx_csg_rotxz_gate.nxnx_csg_scene.nxnx_csg_scene_gate.nxnx_csg_test.nxnx_csg_torus_test.nxnx_cube_to_gcode_test.nxnx_dcc_slice_probe.nxnx_dcc_slice_watertight_gate.nxnx_dcc_to_print_test.nxnx_estimate.nxnx_estimate_test.nxnx_klipper_gcode_validator_test.nxnx_mesh_christus_probe.nxnx_mesh_decimate.nxnx_mesh_decimate_gate.nxnx_mesh_edit.nxnx_mesh_edit_test.nxnx_mesh_print_check.nxnx_mesh_print_check_test.nxnx_mesh_qem.nxnx_mesh_qem_gate.nxnx_mesh_sculpt.nxnx_mesh_sculpt_test.nxnx_mushroom_overhang_test.nxnx_preflight.nxnx_preflight_test.nxnx_print_e2e_gate.nxnx_print_e2e_test.nxnx_print_session.nxnx_print_session_test.nxnx_slice_auto_supports.nxnx_slice_auto_supports_test.nxnx_slice_contour_test.nxnx_slice_layer_probe.nxnx_slice_pipe_v2_real_test.nxnx_slice_pipe_v2_test.nxnx_slice_pipeline.nxnx_slice_pipeline_test.nxnx_slice_plane.nxnx_slice_plane_test.nxnx_slicer_lib.nxnx_stl.nxnx_stl_test.nxnx_stl_to_gcode_real_test.nxnx_stl_write.nxnx_stl_write_mesh_test.nxnx_underridge_cleaner.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.nxnx_vessel_emit.nxnx_vessel_gcode.nx

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

main nx_mesh_alloc sys_mmap nx_mesh_set_vertex nx_mesh_get_vertex_x nx_mesh_get_vertex_y nx_mesh_get_vertex_z nx_mesh_get_color nx_mesh_set_triangle nx_mesh_make_quad nx_mesh_alloc ↻ nx_mesh_set_vertex ↻ nx_mesh_set_uv nx_mesh_set_triangle ↻ nx_mesh_validate nx_mesh_make_cube nx_mesh_alloc ↻ nx_mesh_set_vertex ↻ nx_mesh_set_uv ↻ nx_mesh_set_triangle ↻ nx_mesh_verdict_is_valid

structs

75struct NxMesh

consts

55const NX_MESH_VTX_STRIDE: nx_int = 4
56const NX_MESH_UV_STRIDE: nx_int = 2
57const NX_MESH_IDX_STRIDE: nx_int = 3
61const NX_MESH_OK: nx_int = 0
62const NX_MESH_ERR_BAD_DIMS: nx_int = 1
63const NX_MESH_ERR_NULL_BUFFER: nx_int = 2
64const NX_MESH_ERR_OUT_OF_RANGE: nx_int = 3
65const NX_MESH_N_VERDICTS: nx_int = 4
84const NX_MESH_BYTES: nx_int = 48 // 6 fields * 8

functions

67func nx_mesh_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
92func nx_mesh_alloc(n_verts: nx_int, n_tris: nx_int, with_uvs: nx_int) -> *NxMesh
114func nx_mesh_set_vertex(m: *NxMesh, idx: nx_int,
126func nx_mesh_set_uv(m: *NxMesh, idx: nx_int, u_q10: i64, v_q10: i64) -> nx_int
136func nx_mesh_set_triangle(m: *NxMesh, tri: nx_int,
149func nx_mesh_get_vertex_x(m: *NxMesh, idx: nx_int) -> i64
152func nx_mesh_get_vertex_y(m: *NxMesh, idx: nx_int) -> i64
155func nx_mesh_get_vertex_z(m: *NxMesh, idx: nx_int) -> i64
158func nx_mesh_get_color(m: *NxMesh, idx: nx_int) -> i64
167func nx_mesh_validate(m: *NxMesh) -> nx_int
called by 17: mainmainmainmainmainmain+11
203func nx_mesh_make_quad(x_min_q14: i64, y_min_q14: i64,
231func nx_mesh_make_cube(half_q14: i64, color: i64) -> *NxMesh
291func main() -> i64