nx_dcc_slice_probe.nx source
↩ module page · 75 lines · 3435 B
1// nx_dcc_slice_probe.nx -- DIAGNOSTIC (not a gate): which DCC-authored geometries
2// does the EXISTING slicer turn into real extrusion? Authors each via our verbs,
3// places on the bed, writes->reads->slices, and reports layers / G1 moves / bytes.
4// Isolates whether the near-empty sphere G-code is our geometry or the slicer's
5// contour-linker on dense curved meshes. Prints a table; always exits 0.
6
7import "nx_syscalls.nx"
8import "nx_mesh.nx"
9import "nx_mesh_edit.nx"
10import "nx_mesh_sculpt.nx"
11import "nx_stl_write.nx"
12import "nx_stl.nx"
13import "nx_machine_graph.nx"
14import "nx_material_profile.nx"
15import "nx_gcode_emit.nx"
16import "nx_slice_pipeline.nx"
17const K_MAGIC_262144: i64 = 262144
18const K_MAGIC_3277: i64 = 3277
19const K_MAGIC_6554: i64 = 6554
20const K_MAGIC_8388608: i64 = 8388608
21const K_MAGIC_163840: i64 = 163840
22const K_MAGIC_327680: i64 = 327680
23
24func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
25func wn(v: i64) -> i64 {
26 let b: *u8 = sys_mmap(28); var m: i64 = v
27 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
28 let t: *u8 = sys_mmap(28); var k: i64 = 0
29 if m == 0 { t[0] = 48 as u8; k = 1 }
30 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
31 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
32 sys_write(1, b, k); return 0
33}
34func smoke_count(buf: *u8, len: i64, needle: *u8) -> i64 {
35 var nlen: i64 = 0; while needle[nlen] != 0 { nlen = nlen + 1 }
36 if len < nlen { return 0 }
37 var count: i64 = 0; var i: i64 = 0; let last: i64 = len - nlen
38 while i <= last {
39 var j: i64 = 0; var matched: i64 = 1
40 while j < nlen { if buf[i + j] != needle[j] { matched = 0; j = nlen } j = j + 1 }
41 if matched == 1 { count = count + 1 }
42 i = i + 1
43 }
44 return count
45}
46
47// author -> bed -> write -> read -> slice; print one row
48func probe(label: *u8, model: *NxMesh) -> i64 {
49 let bb: *i64 = (sys_mmap(48)) as *i64
50 nx_mesh_aabb(model, bb)
51 nx_mesh_translate(model, 0 - bb[0], 0 - bb[1], 0 - bb[2])
52 let stl: *u8 = sys_mmap(K_MAGIC_262144)
53 let n: i64 = nx_stl_write_mesh(stl, model)
54 let r: *NxStlResult = nx_stl_load_binary(stl, n)
55 let qidi: *NxMachineGraph = nx_machine_graph_qidi_xmax3()
56 let pla: *NxMaterialProfile = nx_material_profile_generic_pla()
57 let e: *NxGcodeEmitter = nx_gemit_new(qidi, pla, K_MAGIC_3277, K_MAGIC_6554, K_MAGIC_8388608)
58 nx_gemit_preamble(e)
59 let nl: i64 = nx_slice_pipe_run_v2(e, r.mesh, 20, K_MAGIC_3277)
60 let g1: i64 = smoke_count(e.buf, e.len, "G1 X" as *u8)
61 w(label); w(": tris=" as *u8); wn(model.n_tris)
62 w(" layers=" as *u8); wn(nl); w(" G1=" as *u8); wn(g1); w(" bytes=" as *u8); wn(e.len); w("\n" as *u8)
63 return 0
64}
65
66func main() -> i64 {
67 w("=== DCC slice probe (which authored geometry extrudes?) ===\n" as *u8)
68 probe("cube(make_cube 10mm) " as *u8, nx_mesh_make_cube(K_MAGIC_163840, 0))
69 probe("pyramid(10mm,h20) " as *u8, nx_mesh_make_pyramid(K_MAGIC_163840, K_MAGIC_327680, 0))
70 probe("octahedron(10mm) " as *u8, nx_mesh_make_octahedron(K_MAGIC_163840, 0))
71 probe("icosphere subdiv=0 " as *u8, nx_mesh_make_icosphere(K_MAGIC_163840, 0, 0))
72 probe("icosphere subdiv=1 " as *u8, nx_mesh_make_icosphere(K_MAGIC_163840, 1, 0))
73 probe("icosphere subdiv=2 " as *u8, nx_mesh_make_icosphere(K_MAGIC_163840, 2, 0))
74 return 0
75}