nx_slice_layer_probe.nx source
↩ module page · 68 lines · 2747 B
1// nx_slice_layer_probe.nx -- DIAGNOSTIC: slice ONE layer of the pyramid and dump
2// segment soup + contour result, to see exactly where contour assembly breaks.
3// Always exits 0.
4
5import "nx_syscalls.nx"
6import "nx_mesh.nx"
7import "nx_mesh_edit.nx"
8import "nx_mesh_sculpt.nx"
9import "nx_bvh.nx"
10import "nx_slice_plane.nx"
11import "nx_slice_contour.nx"
12
13func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func wn(v: i64) -> i64 {
15 let b: *u8 = sys_mmap(28); var m: i64 = v
16 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
17 let t: *u8 = sys_mmap(28); var k: i64 = 0
18 if m == 0 { t[0] = 48 as u8; k = 1 }
19 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
20 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, b, k); return 0
22}
23
24func dump_bvh(bvh: *NxBvh) -> i64 {
25 w(" BVH n_nodes=" as *u8); wn(bvh.n_nodes); w(" n_tris=" as *u8); wn(bvh.n_tris); w(" tri_order=[" as *u8)
26 var k: i64 = 0
27 while k < bvh.n_tris { wn(bvh.tri_order[k]); w(" " as *u8); k = k + 1 }
28 w("]\n" as *u8)
29 var i: i64 = 0
30 while i < bvh.n_nodes {
31 let n: *NxBvhNode = nx_bvh_node_at(bvh, i)
32 w(" node[" as *u8); wn(i); w("] count=" as *u8); wn(n.count)
33 w(" lof=" as *u8); wn(n.left_or_first)
34 w(" z[" as *u8); wn(n.mnz); w("," as *u8); wn(n.mxz); w("]\n" as *u8)
35 i = i + 1
36 }
37 return 0
38}
39
40func dump_layer(model: *NxMesh, plane_z: i64) -> i64 {
41 let bvh: *NxBvh = nx_bvh_build(model)
42 dump_bvh(bvh)
43 let soup: *NxSliceSoup = nx_slice_plane(model, bvh, plane_z)
44 w(" z=" as *u8); wn(plane_z); w(" n_segments=" as *u8); wn(soup.n_segments); w("\n" as *u8)
45 var i: i64 = 0
46 while i < soup.n_segments {
47 let p: *i64 = nx_slice_soup_seg_ptr(soup, i)
48 w(" seg[" as *u8); wn(i); w("] (" as *u8); wn(p[0]); w("," as *u8); wn(p[1])
49 w(")-(" as *u8); wn(p[2]); w("," as *u8); wn(p[3]); w(")\n" as *u8)
50 i = i + 1
51 }
52 let c: *NxSliceContours = nx_slice_contour_build(soup)
53 w(" contours: n_polys=" as *u8); wn(c.n_polys); w(" n_open=" as *u8); wn(c.n_open)
54 w(" verdict=" as *u8); wn(c.verdict); w("\n" as *u8)
55 return 0
56}
57
58func main() -> i64 {
59 w("=== pyramid single-layer slice probe ===\n" as *u8)
60 let py: *NxMesh = nx_mesh_make_pyramid(163840, 327680, 0)
61 // already sits on bed (base z=0)
62 dump_layer(py, 81920) // z = 5mm (quarter height)
63 w("=== octahedron single-layer slice probe (translated to bed) ===\n" as *u8)
64 let oc: *NxMesh = nx_mesh_make_octahedron(163840, 0)
65 nx_mesh_translate(oc, 0, 0, 163840) // bottom apex to z=0, top to 2R
66 dump_layer(oc, 81920) // z = 5mm
67 return 0
68}