code wiki / _hdl_build / nx_slice_bridge.nx

nx_slice_bridge.nx source

↩ module page · 32 lines · 1442 B

1// nx_slice_bridge.nx -- LIB: R1-FULL. The JOIN between the mature slice pipeline and the multi-material 2// emitter. The slicer (nx_slice_plane -> nx_slice_contour) produces `NxPolygon` contours in Q14 fixed-point 3// (1 unit = 1/16384 mm); this bridges an NxPolygon into the (xs,ys mm) contour `cp_emit_prism` consumes -- so 4// ANY sliced 3D model prints in ANY material. The bridge is a pure Q14->mm conversion; no new geometry, no 5// float, never-brick inherited. license_tier: ORIGINAL 6import "nx_polygon.nx" 7import "nx_contour_print.nx" 8import "nx_print_material.nx" 9import "nx_food_science.nx" 10import "nx_seg_store.nx" 11import "nx_syscalls.nx" 12 13// convert a slicer NxPolygon (Q14) into an (xs,ys) mm contour; returns vertex count. 14func cb_polygon_to_contour(p: *NxPolygon, xs: *i64, ys: *i64) -> i64 { 15 let nv: i64 = p.n_verts 16 var i: i64 = 0 17 while i < nv { 18 xs[i] = nx_polygon_get_x(p, i) / NX_POLYGON_Q14_ONE 19 ys[i] = nx_polygon_get_y(p, i) / NX_POLYGON_Q14_ONE 20 i = i + 1 21 } 22 return nv 23} 24 25// bridge a slicer polygon and emit it `h`-tall in `mat_id`; returns G-code byte length. 26func cb_emit_polygon(prefix: *u8, mat_id: *u8, p: *NxPolygon, h: i64, out: *u8) -> i64 { 27 let xs: *i64 = sys_mmap(8 * 512) as *i64 28 let ys: *i64 = sys_mmap(8 * 512) as *i64 29 let nv: i64 = cb_polygon_to_contour(p, xs, ys) 30 if nv < 3 { return 0 } 31 return cp_emit_prism(prefix, mat_id, xs, ys, nv, h, out) 32}