@coloopx/colocad 0.0.0-stage → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +5 -0
  3. package/README.md +131 -2
  4. package/README.zh-CN.md +100 -0
  5. package/bin/colocad.mjs +32 -0
  6. package/examples/manifold.json +11 -0
  7. package/examples/sensor-rail.json +9 -0
  8. package/kernel/LICENSE +21 -0
  9. package/kernel/dist/artifacts.d.ts +3 -0
  10. package/kernel/dist/artifacts.js +19 -0
  11. package/kernel/dist/assets.d.ts +3 -0
  12. package/kernel/dist/assets.js +11 -0
  13. package/kernel/dist/binary.d.ts +2 -0
  14. package/kernel/dist/binary.js +14 -0
  15. package/kernel/dist/client.d.ts +22 -0
  16. package/kernel/dist/client.js +99 -0
  17. package/kernel/dist/files.d.ts +19 -0
  18. package/kernel/dist/files.js +103 -0
  19. package/kernel/dist/generated.d.ts +707 -0
  20. package/kernel/dist/generated.js +1 -0
  21. package/kernel/dist/helpers.d.ts +9 -0
  22. package/kernel/dist/helpers.js +23 -0
  23. package/kernel/dist/index.d.ts +8 -0
  24. package/kernel/dist/index.js +6 -0
  25. package/kernel/dist/preview-cache.d.ts +19 -0
  26. package/kernel/dist/preview-cache.js +29 -0
  27. package/kernel/dist/process.d.ts +12 -0
  28. package/kernel/dist/process.js +41 -0
  29. package/kernel/dist/tools.d.ts +67 -0
  30. package/kernel/dist/tools.js +20 -0
  31. package/kernel/dist/types.d.ts +26 -0
  32. package/kernel/dist/types.js +1 -0
  33. package/kernel/licenses/adler2-2.0.1-LICENSE-0BSD +12 -0
  34. package/kernel/licenses/adler2-2.0.1-LICENSE-APACHE +201 -0
  35. package/kernel/licenses/adler2-2.0.1-LICENSE-MIT +23 -0
  36. package/kernel/licenses/allocator-api2-0.2.21-LICENSE-APACHE +176 -0
  37. package/kernel/licenses/allocator-api2-0.2.21-LICENSE-MIT +23 -0
  38. package/kernel/licenses/autocfg-1.5.1-LICENSE-APACHE +201 -0
  39. package/kernel/licenses/autocfg-1.5.1-LICENSE-MIT +25 -0
  40. package/kernel/licenses/bitflags-1.3.2-LICENSE-APACHE +201 -0
  41. package/kernel/licenses/bitflags-1.3.2-LICENSE-MIT +25 -0
  42. package/kernel/licenses/block-buffer-0.10.4-LICENSE-APACHE +201 -0
  43. package/kernel/licenses/block-buffer-0.10.4-LICENSE-MIT +25 -0
  44. package/kernel/licenses/cfg-if-1.0.5-LICENSE-APACHE +201 -0
  45. package/kernel/licenses/cfg-if-1.0.5-LICENSE-MIT +25 -0
  46. package/kernel/licenses/cpufeatures-0.2.17-LICENSE-APACHE +201 -0
  47. package/kernel/licenses/cpufeatures-0.2.17-LICENSE-MIT +25 -0
  48. package/kernel/licenses/crc32fast-1.5.4-LICENSE-APACHE +202 -0
  49. package/kernel/licenses/crc32fast-1.5.4-LICENSE-MIT +21 -0
  50. package/kernel/licenses/crossbeam-deque-0.8.8-LICENSE-APACHE +201 -0
  51. package/kernel/licenses/crossbeam-deque-0.8.8-LICENSE-MIT +27 -0
  52. package/kernel/licenses/crossbeam-epoch-0.9.21-LICENSE-APACHE +201 -0
  53. package/kernel/licenses/crossbeam-epoch-0.9.21-LICENSE-MIT +27 -0
  54. package/kernel/licenses/crossbeam-utils-0.8.23-LICENSE-APACHE +201 -0
  55. package/kernel/licenses/crossbeam-utils-0.8.23-LICENSE-MIT +27 -0
  56. package/kernel/licenses/crypto-common-0.1.7-LICENSE-APACHE +201 -0
  57. package/kernel/licenses/crypto-common-0.1.7-LICENSE-MIT +25 -0
  58. package/kernel/licenses/dependencies.json +618 -0
  59. package/kernel/licenses/digest-0.10.7-LICENSE-APACHE +201 -0
  60. package/kernel/licenses/digest-0.10.7-LICENSE-MIT +25 -0
  61. package/kernel/licenses/dyn-clone-1.0.20-LICENSE-APACHE +176 -0
  62. package/kernel/licenses/dyn-clone-1.0.20-LICENSE-MIT +23 -0
  63. package/kernel/licenses/either-1.19.0-LICENSE-APACHE +201 -0
  64. package/kernel/licenses/either-1.19.0-LICENSE-MIT +25 -0
  65. package/kernel/licenses/equivalent-1.0.3-LICENSE-APACHE +201 -0
  66. package/kernel/licenses/equivalent-1.0.3-LICENSE-MIT +25 -0
  67. package/kernel/licenses/fdeflate-0.3.7-LICENSE-APACHE +177 -0
  68. package/kernel/licenses/fdeflate-0.3.7-LICENSE-MIT +25 -0
  69. package/kernel/licenses/flate2-1.1.10-LICENSE-APACHE +201 -0
  70. package/kernel/licenses/flate2-1.1.10-LICENSE-MIT +25 -0
  71. package/kernel/licenses/foldhash-0.2.0-LICENSE +19 -0
  72. package/kernel/licenses/generic-array-0.14.7-LICENSE +21 -0
  73. package/kernel/licenses/hashbrown-0.16.1-LICENSE-APACHE +201 -0
  74. package/kernel/licenses/hashbrown-0.16.1-LICENSE-MIT +25 -0
  75. package/kernel/licenses/itoa-1.0.18-LICENSE-APACHE +176 -0
  76. package/kernel/licenses/itoa-1.0.18-LICENSE-MIT +23 -0
  77. package/kernel/licenses/libc-0.2.191-LICENSE-APACHE +176 -0
  78. package/kernel/licenses/libc-0.2.191-LICENSE-MIT +25 -0
  79. package/kernel/licenses/memchr-2.8.3-COPYING +3 -0
  80. package/kernel/licenses/memchr-2.8.3-LICENSE-MIT +21 -0
  81. package/kernel/licenses/miniz_oxide-0.8.9-LICENSE +25 -0
  82. package/kernel/licenses/miniz_oxide-0.8.9-LICENSE-APACHE.md +177 -0
  83. package/kernel/licenses/miniz_oxide-0.8.9-LICENSE-MIT.md +24 -0
  84. package/kernel/licenses/miniz_oxide-0.8.9-LICENSE-ZLIB.md +14 -0
  85. package/kernel/licenses/miniz_oxide-0.9.1-LICENSE +25 -0
  86. package/kernel/licenses/miniz_oxide-0.9.1-LICENSE-APACHE.md +177 -0
  87. package/kernel/licenses/miniz_oxide-0.9.1-LICENSE-MIT.md +24 -0
  88. package/kernel/licenses/miniz_oxide-0.9.1-LICENSE-ZLIB.md +14 -0
  89. package/kernel/licenses/num-traits-0.2.19-LICENSE-APACHE +201 -0
  90. package/kernel/licenses/num-traits-0.2.19-LICENSE-MIT +25 -0
  91. package/kernel/licenses/png-0.17.16-LICENSE-APACHE +201 -0
  92. package/kernel/licenses/png-0.17.16-LICENSE-MIT +25 -0
  93. package/kernel/licenses/proc-macro2-1.0.107-LICENSE-APACHE +176 -0
  94. package/kernel/licenses/proc-macro2-1.0.107-LICENSE-MIT +23 -0
  95. package/kernel/licenses/quote-1.0.47-LICENSE-APACHE +176 -0
  96. package/kernel/licenses/quote-1.0.47-LICENSE-MIT +23 -0
  97. package/kernel/licenses/rayon-1.12.0-LICENSE-APACHE +201 -0
  98. package/kernel/licenses/rayon-1.12.0-LICENSE-MIT +25 -0
  99. package/kernel/licenses/rayon-core-1.13.0-LICENSE-APACHE +201 -0
  100. package/kernel/licenses/rayon-core-1.13.0-LICENSE-MIT +25 -0
  101. package/kernel/licenses/ref-cast-1.0.27-LICENSE-APACHE +176 -0
  102. package/kernel/licenses/ref-cast-1.0.27-LICENSE-MIT +23 -0
  103. package/kernel/licenses/ref-cast-impl-1.0.27-LICENSE-APACHE +176 -0
  104. package/kernel/licenses/ref-cast-impl-1.0.27-LICENSE-MIT +23 -0
  105. package/kernel/licenses/robust-1.2.0-LICENSE-APACHE +201 -0
  106. package/kernel/licenses/robust-1.2.0-LICENSE-MIT +26 -0
  107. package/kernel/licenses/schemars-1.2.3-LICENSE +21 -0
  108. package/kernel/licenses/schemars_derive-1.2.3-LICENSE +21 -0
  109. package/kernel/licenses/serde-1.0.229-LICENSE-APACHE +176 -0
  110. package/kernel/licenses/serde-1.0.229-LICENSE-MIT +23 -0
  111. package/kernel/licenses/serde_core-1.0.229-LICENSE-APACHE +176 -0
  112. package/kernel/licenses/serde_core-1.0.229-LICENSE-MIT +23 -0
  113. package/kernel/licenses/serde_derive-1.0.229-LICENSE-APACHE +176 -0
  114. package/kernel/licenses/serde_derive-1.0.229-LICENSE-MIT +23 -0
  115. package/kernel/licenses/serde_derive_internals-0.30.0-LICENSE-APACHE +176 -0
  116. package/kernel/licenses/serde_derive_internals-0.30.0-LICENSE-MIT +23 -0
  117. package/kernel/licenses/serde_json-1.0.154-LICENSE-APACHE +176 -0
  118. package/kernel/licenses/serde_json-1.0.154-LICENSE-MIT +23 -0
  119. package/kernel/licenses/sha2-0.10.9-LICENSE-APACHE +201 -0
  120. package/kernel/licenses/sha2-0.10.9-LICENSE-MIT +27 -0
  121. package/kernel/licenses/simd-adler32-0.3.10-LICENSE.md +21 -0
  122. package/kernel/licenses/smallvec-1.16.4-LICENSE-APACHE +201 -0
  123. package/kernel/licenses/smallvec-1.16.4-LICENSE-MIT +25 -0
  124. package/kernel/licenses/solidcore-1.0.1-LICENSE +203 -0
  125. package/kernel/licenses/solidcore-1.0.1-NOTICE +30 -0
  126. package/kernel/licenses/solidcore-ATTRIBUTION.md +92 -0
  127. package/kernel/licenses/solidcore-LICENSE +203 -0
  128. package/kernel/licenses/solidcore-NOTICE +30 -0
  129. package/kernel/licenses/solidcore-convert-0.1.0-ATTRIBUTION.md +92 -0
  130. package/kernel/licenses/solidcore-convert-0.1.0-LICENSE +203 -0
  131. package/kernel/licenses/solidcore-convert-0.1.0-NOTICE +30 -0
  132. package/kernel/licenses/solidcore-record-0.1.0-ATTRIBUTION.md +92 -0
  133. package/kernel/licenses/solidcore-record-0.1.0-LICENSE +203 -0
  134. package/kernel/licenses/solidcore-record-0.1.0-NOTICE +30 -0
  135. package/kernel/licenses/solidcore-tess-0.1.0-ATTRIBUTION.md +92 -0
  136. package/kernel/licenses/solidcore-tess-0.1.0-LICENSE +203 -0
  137. package/kernel/licenses/solidcore-tess-0.1.0-NOTICE +30 -0
  138. package/kernel/licenses/spade-2.15.1-LICENSE-APACHE +202 -0
  139. package/kernel/licenses/spade-2.15.1-LICENSE-MIT +25 -0
  140. package/kernel/licenses/step-brep-0.1.0-ATTRIBUTION.md +92 -0
  141. package/kernel/licenses/step-brep-0.1.0-LICENSE +203 -0
  142. package/kernel/licenses/step-brep-0.1.0-NOTICE +30 -0
  143. package/kernel/licenses/step-export-0.1.0-ATTRIBUTION.md +92 -0
  144. package/kernel/licenses/step-export-0.1.0-LICENSE +203 -0
  145. package/kernel/licenses/step-export-0.1.0-NOTICE +30 -0
  146. package/kernel/licenses/step-import-0.1.0-ATTRIBUTION.md +92 -0
  147. package/kernel/licenses/step-import-0.1.0-LICENSE +203 -0
  148. package/kernel/licenses/step-import-0.1.0-NOTICE +30 -0
  149. package/kernel/licenses/syn-3.0.9-LICENSE-APACHE +176 -0
  150. package/kernel/licenses/syn-3.0.9-LICENSE-MIT +23 -0
  151. package/kernel/licenses/thiserror-2.0.21-LICENSE-APACHE +176 -0
  152. package/kernel/licenses/thiserror-2.0.21-LICENSE-MIT +23 -0
  153. package/kernel/licenses/thiserror-impl-2.0.21-LICENSE-APACHE +176 -0
  154. package/kernel/licenses/thiserror-impl-2.0.21-LICENSE-MIT +23 -0
  155. package/kernel/licenses/typenum-1.20.1-LICENSE +1 -0
  156. package/kernel/licenses/typenum-1.20.1-LICENSE-APACHE +201 -0
  157. package/kernel/licenses/typenum-1.20.1-LICENSE-MIT +21 -0
  158. package/kernel/licenses/unicode-ident-1.0.27-LICENSE-APACHE +176 -0
  159. package/kernel/licenses/unicode-ident-1.0.27-LICENSE-MIT +23 -0
  160. package/kernel/licenses/unicode-ident-1.0.27-LICENSE-UNICODE +39 -0
  161. package/kernel/licenses/version_check-0.9.5-LICENSE-APACHE +201 -0
  162. package/kernel/licenses/version_check-0.9.5-LICENSE-MIT +19 -0
  163. package/kernel/licenses/zlib-rs-0.6.8-LICENSE +19 -0
  164. package/kernel/licenses/zmij-1.0.23-LICENSE-MIT +23 -0
  165. package/kernel/native/darwin-arm64/agent-cad +4 -0
  166. package/kernel/native/darwin-arm64/manifest.json +6 -0
  167. package/kernel/native/linux-arm64/agent-cad +4 -0
  168. package/kernel/native/linux-arm64/manifest.json +6 -0
  169. package/kernel/native/linux-x64/agent-cad +4 -0
  170. package/kernel/native/linux-x64/manifest.json +6 -0
  171. package/kernel/release.json +8 -0
  172. package/kernel/schemas/model.schema.json +4080 -0
  173. package/package.json +59 -4
  174. package/scripts/check-release.mjs +24 -0
  175. package/skills/colocad/SKILL.md +17 -0
  176. package/skills/colocad/assets/angle-bracket.json +39 -0
  177. package/skills/colocad/assets/ball.json +16 -0
  178. package/skills/colocad/assets/block.json +18 -0
  179. package/skills/colocad/assets/open-housing.json +35 -0
  180. package/skills/colocad/assets/pin.json +18 -0
  181. package/skills/colocad/assets/plate-grid.json +34 -0
  182. package/skills/colocad/assets/sleeve.json +19 -0
  183. package/skills/colocad/assets/taper.json +20 -0
  184. package/skills/colocad/references/quick-build.md +44 -0
  185. package/skills/colocad/scripts/assembly.mjs +3 -0
  186. package/skills/colocad/scripts/build.mjs +54 -0
  187. package/solidworks/managed/Colocad.SolidWorks.deps.json +23 -0
  188. package/solidworks/managed/Colocad.SolidWorks.dll +0 -0
  189. package/solidworks/managed/Colocad.SolidWorks.runtimeconfig.json +13 -0
  190. package/src/build.mjs +69 -0
  191. package/src/index.d.mts +67 -0
  192. package/src/index.mjs +4 -0
  193. package/src/solidworks.mjs +65 -0
  194. package/src/tree.mjs +199 -0
@@ -0,0 +1,65 @@
1
+ import { mkdtemp, writeFile, link, rm, mkdir, stat } from "node:fs/promises";
2
+ import { dirname, join, resolve, extname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { execFile } from "node:child_process";
5
+ import { promisify } from "node:util";
6
+ import { compileTree } from "./tree.mjs";
7
+ import { build } from "./build.mjs";
8
+ const run = promisify(execFile);
9
+
10
+ // A failed or unavailable author never publishes an output part.
11
+ export async function writeSolidWorks(input, destination) {
12
+ if (process.platform !== "win32") {
13
+ const error = new Error(
14
+ "NATIVE_AUTHOR_UNAVAILABLE: direct SLDPRT feature serialization on Linux/macOS is experimental; this release only activates the native author on a Windows host with local SOLIDWORKS.",
15
+ );
16
+ error.code = "NATIVE_AUTHOR_UNAVAILABLE";
17
+ throw error;
18
+ }
19
+ const out = resolve(destination);
20
+ if (extname(out).toLowerCase() !== ".sldprt")
21
+ throw Error("Expected a new .SLDPRT file");
22
+ await mkdir(dirname(out), { recursive: true });
23
+ const stage = await mkdtemp(join(dirname(out), ".colocad-native-"));
24
+ try {
25
+ let jobPath;
26
+ if (input?.format === "colocad/1") {
27
+ jobPath = (await build(input, join(stage, "geometry"))).nativeJob;
28
+ } else {
29
+ if (
30
+ input?.format !== "colocad/native-job/1" ||
31
+ !Number.isFinite(input.expected?.volumeMM3) ||
32
+ input.expected.volumeMM3 <= 0
33
+ )
34
+ throw Error("Invalid native job");
35
+ const features = compileTree({
36
+ format: "colocad/1",
37
+ units: "mm",
38
+ parameters: {},
39
+ features: input.features,
40
+ });
41
+ jobPath = join(stage, "job.json");
42
+ await writeFile(jobPath, JSON.stringify({ ...input, features }));
43
+ }
44
+ const temp = join(stage, "part.SLDPRT");
45
+ const assembly = fileURLToPath(
46
+ new URL("../solidworks/managed/Colocad.SolidWorks.dll", import.meta.url),
47
+ );
48
+ const { stdout } = await run("dotnet", [assembly, jobPath, temp], {
49
+ timeout: 120000,
50
+ maxBuffer: 1024 * 1024,
51
+ windowsHide: true,
52
+ });
53
+ const receipt = JSON.parse(stdout);
54
+ if (
55
+ !receipt.reopened ||
56
+ !receipt.editRebuildVerified ||
57
+ !(await stat(temp)).size
58
+ )
59
+ throw Error("Missing native edit/reopen evidence");
60
+ await link(temp, out);
61
+ return { ...receipt, file: out };
62
+ } finally {
63
+ await rm(stage, { recursive: true, force: true });
64
+ }
65
+ }
package/src/tree.mjs ADDED
@@ -0,0 +1,199 @@
1
+ // Parametric feature order is the order of edits on a single solid.
2
+ // Stable IDs refer to the operation, not to the most recent output body.
3
+ function fail(message) {
4
+ throw new Error(message);
5
+ }
6
+ function object(v) {
7
+ return v !== null && typeof v === "object" && !Array.isArray(v);
8
+ }
9
+ function fields(value, allowed, where) {
10
+ if (!object(value) || Object.keys(value).some((k) => !allowed.includes(k)))
11
+ fail("Unexpected fields in " + where);
12
+ }
13
+ function id(value) {
14
+ if (typeof value !== "string" || !/^[A-Za-z][A-Za-z0-9_]{0,47}$/.test(value))
15
+ fail("Invalid identifier");
16
+ return value;
17
+ }
18
+ function number(value) {
19
+ if (!Number.isFinite(value) || Math.abs(value) > 100000)
20
+ fail("Expected a finite millimetre value within ±100000");
21
+ return value;
22
+ }
23
+ function positive(n) {
24
+ if (n <= 0) fail("Expected a positive value");
25
+ return n;
26
+ }
27
+ function count(v, limit) {
28
+ if (!Number.isInteger(v) || v < 1 || v > limit) fail("Invalid count");
29
+ return v;
30
+ }
31
+
32
+ export function compileTree(tree) {
33
+ fields(tree, ["format", "units", "parameters", "features"], "document");
34
+ if (
35
+ tree.format !== "colocad/1" ||
36
+ tree.units !== "mm" ||
37
+ !object(tree.parameters) ||
38
+ !Array.isArray(tree.features) ||
39
+ !tree.features.length ||
40
+ tree.features.length > 128
41
+ )
42
+ fail("Expected colocad/1 feature tree in mm");
43
+ for (const [key, v] of Object.entries(tree.parameters)) {
44
+ id(key);
45
+ number(v);
46
+ }
47
+ const dim = (v) => {
48
+ if (typeof v === "number") return number(v);
49
+ fields(v, ["param"], "dimension");
50
+ if (!Object.hasOwn(tree.parameters, id(v.param)))
51
+ fail("Unknown parameter " + v.param);
52
+ return tree.parameters[v.param];
53
+ };
54
+ const point = (v, n) => {
55
+ if (!Array.isArray(v) || v.length !== n) fail("Invalid coordinate");
56
+ return v.map(dim);
57
+ };
58
+ const profile = (p) => {
59
+ if (p?.kind === "circle") {
60
+ fields(p, ["kind", "center", "radius"], "circle");
61
+ return {
62
+ kind: "circle",
63
+ center: point(p.center, 2),
64
+ radius: positive(dim(p.radius)),
65
+ };
66
+ }
67
+ if (p?.kind === "rectangle") {
68
+ fields(p, ["kind", "center", "size"], "rectangle");
69
+ return {
70
+ kind: "rectangle",
71
+ center: point(p.center, 2),
72
+ size: point(p.size, 2).map(positive),
73
+ };
74
+ }
75
+ if (p?.kind === "polygon") {
76
+ fields(p, ["kind", "points"], "polygon");
77
+ if (
78
+ !Array.isArray(p.points) ||
79
+ p.points.length < 3 ||
80
+ p.points.length > 128
81
+ )
82
+ fail("Polygon needs 3–128 vertices");
83
+ return { kind: "polygon", points: p.points.map((q) => point(q, 2)) };
84
+ }
85
+ fail("Unsupported sketch profile");
86
+ };
87
+ const plan = [],
88
+ seeds = new Map(),
89
+ ids = new Set();
90
+ for (const raw of tree.features) {
91
+ if (!object(raw)) fail("Invalid feature");
92
+ const name = id(raw.id),
93
+ op = raw.op;
94
+ if (ids.has(name.toLowerCase())) fail("Duplicate feature " + name);
95
+ if (!plan.length && op !== "extrude")
96
+ fail("First feature must create material");
97
+ let f = { id: name, op };
98
+ if (op === "extrude" || op === "cut") {
99
+ fields(raw, ["id", "op", "profile", "startZ", "depth"], name);
100
+ f = {
101
+ ...f,
102
+ profile: profile(raw.profile),
103
+ startZ: dim(raw.startZ ?? 0),
104
+ depth: positive(dim(raw.depth)),
105
+ };
106
+ seeds.set(name, f);
107
+ } else if (op === "fillet") {
108
+ fields(raw, ["id", "op", "radius", "edges"], name);
109
+ fields(raw.edges, ["z", "count"], "edge selection");
110
+ f = {
111
+ ...f,
112
+ radius: positive(dim(raw.radius)),
113
+ edges: { z: dim(raw.edges.z), count: count(dim(raw.edges.count), 256) },
114
+ };
115
+ } else if (op === "linearPattern") {
116
+ fields(raw, ["id", "op", "seed", "axis", "pitch", "count"], name);
117
+ if (!seeds.has(raw.seed) || !["x", "y"].includes(raw.axis))
118
+ fail("Pattern needs an earlier extrude/cut seed and X or Y direction");
119
+ const n = count(dim(raw.count), 128);
120
+ if (n < 2) fail("Pattern count includes seed and must be at least two");
121
+ f = {
122
+ ...f,
123
+ seed: raw.seed,
124
+ axis: raw.axis,
125
+ pitch: positive(dim(raw.pitch)),
126
+ count: n,
127
+ };
128
+ } else fail("Unsupported operation " + op);
129
+ ids.add(name.toLowerCase());
130
+ plan.push(f);
131
+ }
132
+ return plan;
133
+ }
134
+
135
+ // Resolve a feature into a world XY profile plus frame. Instance offsets move
136
+ // the seed sketch without moving its original material or an unrelated feature.
137
+ export function kernelModel(tree) {
138
+ const plan = compileTree(tree),
139
+ features = [],
140
+ seeds = new Map();
141
+ let result;
142
+ function prism(f, offset = [0, 0]) {
143
+ const p = f.profile,
144
+ c = p.center ?? [0, 0];
145
+ const profile =
146
+ p.kind === "polygon"
147
+ ? { kind: "polygon", points: p.points }
148
+ : p.kind === "circle"
149
+ ? { kind: "circle", radius: p.radius }
150
+ : { kind: "rectangle", width: p.size[0], depth: p.size[1] };
151
+ const frame = {
152
+ origin: [c[0] + offset[0], c[1] + offset[1], f.startZ],
153
+ x_axis: [1, 0, 0],
154
+ y_axis: [0, 1, 0],
155
+ };
156
+ const tool = "F" + features.length;
157
+ features.push({ id: tool, op: "extrude", profile, frame, height: f.depth });
158
+ if (result) {
159
+ const next = "F" + features.length;
160
+ features.push({
161
+ id: next,
162
+ op: f.op === "cut" ? "cut" : "union",
163
+ left: result,
164
+ right: tool,
165
+ });
166
+ result = next;
167
+ } else result = tool;
168
+ }
169
+ for (const f of plan) {
170
+ if (f.op === "extrude" || f.op === "cut") {
171
+ prism(f);
172
+ seeds.set(f.id, f);
173
+ } else if (f.op === "fillet") {
174
+ const next = "F" + features.length;
175
+ features.push({
176
+ id: next,
177
+ op: "fillet",
178
+ input: result,
179
+ radius: f.radius,
180
+ select: {
181
+ kind: "on_plane",
182
+ axis: "z",
183
+ value: f.edges.z,
184
+ tolerance: 0.001,
185
+ expected_count: f.edges.count,
186
+ },
187
+ });
188
+ result = next;
189
+ } else {
190
+ for (let i = 1; i < f.count; i++)
191
+ prism(
192
+ seeds.get(f.seed),
193
+ f.axis === "x" ? [i * f.pitch, 0] : [0, i * f.pitch],
194
+ );
195
+ }
196
+ if (features.length > 1024) fail("Expanded feature limit exceeded");
197
+ }
198
+ return { version: 1, units: "mm", parameters: {}, features, output: result };
199
+ }