@gui-chat-plugin/brep 0.0.0-stage → 0.1.0
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.
- package/CHANGELOG.md +28 -0
- package/README.md +181 -2
- package/dist/core/definition.d.ts +24 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/mesh.d.ts +34 -0
- package/dist/core/packed.d.ts +4 -0
- package/dist/core/paths.d.ts +15 -0
- package/dist/core/plugin.d.ts +12 -0
- package/dist/core/types.d.ts +68 -0
- package/dist/errors-BANLyHzz.js +27 -0
- package/dist/errors-BgFaRg0j.cjs +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +136 -0
- package/dist/kernel/errors.d.ts +33 -0
- package/dist/kernel/index.d.ts +26 -0
- package/dist/kernel/load.d.ts +9 -0
- package/dist/kernel/output.d.ts +15 -0
- package/dist/kernel/record.d.ts +32 -0
- package/dist/kernel/report.d.ts +52 -0
- package/dist/kernel/script.d.ts +9 -0
- package/dist/kernel-75dHFfjx.js +565 -0
- package/dist/kernel-BA8zZi78.cjs +2 -0
- package/dist/lang/en.d.ts +3 -0
- package/dist/lang/index.d.ts +5 -0
- package/dist/lang/ja.d.ts +3 -0
- package/dist/lang/messages.d.ts +41 -0
- package/dist/mesh-Cmm66x_I.js +128 -0
- package/dist/mesh-DLZoiBza.cjs +1 -0
- package/dist/style.css +3 -0
- package/dist/vue/Preview.vue.d.ts +8 -0
- package/dist/vue/View.vue.d.ts +8 -0
- package/dist/vue/index.d.ts +23 -0
- package/dist/vue/scene.d.ts +24 -0
- package/dist/vue/split.d.ts +26 -0
- package/dist/vue.cjs +1 -0
- package/dist/vue.js +938 -0
- package/package.json +72 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Shape3D } from "replicad";
|
|
2
|
+
import { type BrepMesh } from "../core/mesh";
|
|
3
|
+
import type { Kernel } from "./load";
|
|
4
|
+
import type { ModelPart } from "./script";
|
|
5
|
+
/** STEP, in millimetres: the exact surfaces, one named product per part. */
|
|
6
|
+
export declare function toStep(kernel: Kernel, parts: ModelPart[]): Promise<Uint8Array>;
|
|
7
|
+
/** Binary STL, in millimetres. */
|
|
8
|
+
export declare function toStl(whole: Shape3D): Promise<Uint8Array>;
|
|
9
|
+
/** The faces as triangles and the edges as line segments, for a View. Call
|
|
10
|
+
* it BEFORE `toStl`: the kernel keeps a shape's finest triangulation, and
|
|
11
|
+
* meshing coarse after fine returns the fine one. */
|
|
12
|
+
export declare function toDisplayMesh(whole: Shape3D): BrepMesh;
|
|
13
|
+
/** A sheet of four line drawings, hidden edges dashed: what the model's
|
|
14
|
+
* author looks at to see the shape, with no renderer and no browser. */
|
|
15
|
+
export declare function toViewsSvg(kernel: Kernel, whole: Shape3D): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { AnyShape } from "replicad";
|
|
2
|
+
import type { Kernel } from "./load";
|
|
3
|
+
export type OperationName = "fillet" | "chamfer" | "shell" | "fuse" | "cut" | "intersect";
|
|
4
|
+
export interface OperationRecord {
|
|
5
|
+
op: OperationName;
|
|
6
|
+
/** 1-based script line of the call. */
|
|
7
|
+
line?: number;
|
|
8
|
+
/** The radius, chamfer distance or wall thickness, when it is one number. */
|
|
9
|
+
size?: number;
|
|
10
|
+
/** Edges (fillet, chamfer) or faces (shell) the selector picked. */
|
|
11
|
+
selected?: number;
|
|
12
|
+
/** How many edges or faces the solid had to pick from. */
|
|
13
|
+
available?: number;
|
|
14
|
+
/** mm³ before and after; NaN where the shape has no volume to measure. */
|
|
15
|
+
volumeBefore: number;
|
|
16
|
+
volumeAfter: number;
|
|
17
|
+
}
|
|
18
|
+
export interface Recorder {
|
|
19
|
+
operations: OperationRecord[];
|
|
20
|
+
warnings: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare function startRecording(): Recorder;
|
|
23
|
+
export declare function stopRecording(): void;
|
|
24
|
+
/** Volume in mm³, or NaN for a shape that has none to measure. */
|
|
25
|
+
export declare function volumeOf(kernel: Kernel, shape: unknown): number;
|
|
26
|
+
/** The kernel's own check of a shape: topology and geometry. */
|
|
27
|
+
export declare function isValidShape(kernel: Kernel, shape: AnyShape): boolean;
|
|
28
|
+
/** `40 x 20 x 5 mm` */
|
|
29
|
+
export declare function sizeOf(shape: AnyShape): [number, number, number];
|
|
30
|
+
/** Wrap the operations on replicad's 3D shape class. Once per copy of
|
|
31
|
+
* replicad: a second call finds the mark and leaves the wrappers alone. */
|
|
32
|
+
export declare function instrument(kernel: Kernel): void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Shape3D } from "replicad";
|
|
2
|
+
import type { Kernel } from "./load";
|
|
3
|
+
import { type OperationName, type OperationRecord, type Recorder } from "./record";
|
|
4
|
+
import type { ModelPart } from "./script";
|
|
5
|
+
/** One line of the report: the calls one script line made, added up. A loop
|
|
6
|
+
* that cuts six holes is one entry with `count: 6`. */
|
|
7
|
+
export interface OperationSummary {
|
|
8
|
+
op: OperationName;
|
|
9
|
+
line?: number;
|
|
10
|
+
count: number;
|
|
11
|
+
size?: number;
|
|
12
|
+
/** Edges or faces picked, over all the calls. */
|
|
13
|
+
selected?: number;
|
|
14
|
+
/** Edges or faces the solid had at the first call. */
|
|
15
|
+
available?: number;
|
|
16
|
+
/** mm³ added (positive) or removed, over all the calls. */
|
|
17
|
+
volumeChange?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface PartReport {
|
|
20
|
+
name?: string;
|
|
21
|
+
volume: number;
|
|
22
|
+
size: [number, number, number];
|
|
23
|
+
}
|
|
24
|
+
export interface ModelReport {
|
|
25
|
+
/** mm³. */
|
|
26
|
+
volume: number;
|
|
27
|
+
/** mm², the whole surface. */
|
|
28
|
+
area: number;
|
|
29
|
+
/** Bounding box, mm: X, Y, Z. */
|
|
30
|
+
size: [number, number, number];
|
|
31
|
+
/** Bounding box corners, mm. */
|
|
32
|
+
bounds: [[number, number, number], [number, number, number]];
|
|
33
|
+
/** Separate solids. More than one in a single part means pieces that do
|
|
34
|
+
* not touch. */
|
|
35
|
+
solids: number;
|
|
36
|
+
/** Faces by surface kind: `{ plane: 6, cylinder: 9, cone: 5, torus: 1 }`. */
|
|
37
|
+
faces: Record<string, number>;
|
|
38
|
+
/** Edges by curve kind: `{ line: 21, circle: 25 }`. */
|
|
39
|
+
edges: Record<string, number>;
|
|
40
|
+
operations: OperationSummary[];
|
|
41
|
+
warnings: string[];
|
|
42
|
+
/** Present when `main` returned more than one part. */
|
|
43
|
+
parts?: PartReport[];
|
|
44
|
+
}
|
|
45
|
+
/** The whole model as one shape: the part itself, or a compound of them. */
|
|
46
|
+
export declare function wholeOf(kernel: Kernel, parts: ModelPart[]): Shape3D;
|
|
47
|
+
export declare function buildReport(kernel: Kernel, parts: ModelPart[], whole: Shape3D, recorder: Recorder): ModelReport;
|
|
48
|
+
/** The operations a build got through, one line each: what an error result
|
|
49
|
+
* shows of the work before the failure. */
|
|
50
|
+
export declare const formatOperations: (records: OperationRecord[]) => string[];
|
|
51
|
+
/** The report as the text the model reads. */
|
|
52
|
+
export declare function formatReport(report: ModelReport): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Shape3D } from "replicad";
|
|
2
|
+
import type { Kernel } from "./load";
|
|
3
|
+
/** A solid `main` returned, with the name it was given, if any. */
|
|
4
|
+
export interface ModelPart {
|
|
5
|
+
shape: Shape3D;
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Run the script and return the parts `main` built. Throws `BrepError`. */
|
|
9
|
+
export declare function runScript(kernel: Kernel, script: string, timeoutMs: number): Promise<ModelPart[]>;
|
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
import { a as e, i as t, n, r, t as i } from "./errors-BANLyHzz.js";
|
|
2
|
+
import { n as a } from "./mesh-Cmm66x_I.js";
|
|
3
|
+
import { Script as o, compileFunction as s } from "node:vm";
|
|
4
|
+
// src/kernel/record.ts
|
|
5
|
+
var c, l = 0;
|
|
6
|
+
function u() {
|
|
7
|
+
return c = {
|
|
8
|
+
operations: [],
|
|
9
|
+
warnings: []
|
|
10
|
+
}, l = 0, c;
|
|
11
|
+
}
|
|
12
|
+
function d() {
|
|
13
|
+
c = void 0, l = 0;
|
|
14
|
+
}
|
|
15
|
+
var f = (e, t = 2) => Number.isFinite(e) ? Number(e.toFixed(t)) : e;
|
|
16
|
+
function p(e, t) {
|
|
17
|
+
try {
|
|
18
|
+
return e.replicad.measureVolume(t);
|
|
19
|
+
} catch {
|
|
20
|
+
return NaN;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function m(e, t) {
|
|
24
|
+
let n = new e.oc.BRepCheck_Analyzer(t.wrapped, !0);
|
|
25
|
+
try {
|
|
26
|
+
return n.IsValid.call(n);
|
|
27
|
+
} finally {
|
|
28
|
+
n.delete();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function h(e) {
|
|
32
|
+
let t = e.boundingBox;
|
|
33
|
+
return [
|
|
34
|
+
f(t.width),
|
|
35
|
+
f(t.height),
|
|
36
|
+
f(t.depth)
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
var g = (e) => `${e.join(" x ")} mm`, _ = (e) => typeof e == "object" && !!e;
|
|
40
|
+
function v(e, t, n) {
|
|
41
|
+
t.selected = (t.selected ?? 0) + 1;
|
|
42
|
+
let r = f(e.replicad.measureLength(n));
|
|
43
|
+
t.shortest = Math.min(t.shortest ?? r, r);
|
|
44
|
+
}
|
|
45
|
+
function y(e, t, n) {
|
|
46
|
+
if (!_(n) || typeof n.shouldKeep != "function") return n;
|
|
47
|
+
let r = n.shouldKeep;
|
|
48
|
+
return t.selected = 0, n.shouldKeep = (i) => {
|
|
49
|
+
let a = r.call(n, i);
|
|
50
|
+
return a && v(e, t, i), a;
|
|
51
|
+
}, n;
|
|
52
|
+
}
|
|
53
|
+
function b(e, t) {
|
|
54
|
+
if (!_(t) || typeof t.find != "function") return t;
|
|
55
|
+
let n = t.find;
|
|
56
|
+
return t.find = (...r) => {
|
|
57
|
+
let i = n.apply(t, r);
|
|
58
|
+
return Array.isArray(i) && (e.selected = i.length), i;
|
|
59
|
+
}, t;
|
|
60
|
+
}
|
|
61
|
+
function x(e, t, n) {
|
|
62
|
+
let [r, i, ...a] = n, o = t.edges, s = { available: o.length };
|
|
63
|
+
if (typeof r == "function") {
|
|
64
|
+
let t = r;
|
|
65
|
+
return s.selected = 0, {
|
|
66
|
+
args: [
|
|
67
|
+
(n) => {
|
|
68
|
+
let r = t(n);
|
|
69
|
+
return r && v(e, s, n), r;
|
|
70
|
+
},
|
|
71
|
+
i,
|
|
72
|
+
...a
|
|
73
|
+
],
|
|
74
|
+
selection: s
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (_(r) && "filter" in r) return typeof r.radius == "number" && (s.size = r.radius), y(e, s, r.filter), {
|
|
78
|
+
args: n,
|
|
79
|
+
selection: s
|
|
80
|
+
};
|
|
81
|
+
if (typeof r == "number" && (s.size = r), typeof i == "function") {
|
|
82
|
+
let t = i;
|
|
83
|
+
return {
|
|
84
|
+
args: [
|
|
85
|
+
r,
|
|
86
|
+
(n, r) => y(e, s, t(n, r)),
|
|
87
|
+
...a
|
|
88
|
+
],
|
|
89
|
+
selection: s
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
let c = o.map((t) => e.replicad.measureLength(t));
|
|
93
|
+
return s.selected = o.length, c.length && (s.shortest = f(Math.min(...c))), {
|
|
94
|
+
args: n,
|
|
95
|
+
selection: s
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function ee(e, t, n) {
|
|
99
|
+
let [r, i, ...a] = n, o = {
|
|
100
|
+
selected: 0,
|
|
101
|
+
available: t.faces.length
|
|
102
|
+
};
|
|
103
|
+
if (_(r) && "filter" in r) return typeof r.thickness == "number" && (o.size = r.thickness), b(o, r.filter), {
|
|
104
|
+
args: n,
|
|
105
|
+
selection: o
|
|
106
|
+
};
|
|
107
|
+
if (typeof r == "number" && (o.size = r), typeof i == "function") {
|
|
108
|
+
let e = i;
|
|
109
|
+
return {
|
|
110
|
+
args: [
|
|
111
|
+
r,
|
|
112
|
+
(t, n) => b(o, e(t, n)),
|
|
113
|
+
...a
|
|
114
|
+
],
|
|
115
|
+
selection: o
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
args: n,
|
|
120
|
+
selection: o
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var S = (e, t, n) => ({
|
|
124
|
+
args: n,
|
|
125
|
+
selection: {}
|
|
126
|
+
}), C = {
|
|
127
|
+
fillet: x,
|
|
128
|
+
chamfer: x,
|
|
129
|
+
shell: ee,
|
|
130
|
+
fuse: S,
|
|
131
|
+
cut: S,
|
|
132
|
+
intersect: S
|
|
133
|
+
}, te = {
|
|
134
|
+
fillet: "edges",
|
|
135
|
+
chamfer: "edges",
|
|
136
|
+
shell: "faces"
|
|
137
|
+
};
|
|
138
|
+
function w(e, t, n) {
|
|
139
|
+
return `${e}(${t.size === void 0 ? "" : `${t.size}`})${n === void 0 ? "" : ` at line ${n}`}`;
|
|
140
|
+
}
|
|
141
|
+
function T(e, t, n) {
|
|
142
|
+
let r = [], i = te[e];
|
|
143
|
+
return i && t.selected !== void 0 && r.push(`it selected ${t.selected} of ${t.available} ${i}`), t.shortest !== void 0 && r.push(`the shortest selected edge is ${t.shortest} mm`), r.push(`the solid is ${g(h(n))}`), r.join("; ");
|
|
144
|
+
}
|
|
145
|
+
var E = {
|
|
146
|
+
fillet: "A fillet fails when its radius does not fit: larger than a neighbouring face is wide, or meeting another fillet. Use a smaller radius, or select fewer edges.",
|
|
147
|
+
chamfer: "A chamfer fails when its distance does not fit on a neighbouring face. Use a smaller distance, or select fewer edges.",
|
|
148
|
+
shell: "A shell fails when an inside corner would get a radius of zero or less: every outside fillet must be larger than the wall thickness. Fillet with a larger radius, use a thinner wall, or shell before filleting."
|
|
149
|
+
}, D = 1e-9;
|
|
150
|
+
function ne(e, t) {
|
|
151
|
+
let { op: n, volumeBefore: r, volumeAfter: i } = t;
|
|
152
|
+
if (!Number.isFinite(r) || !Number.isFinite(i)) return;
|
|
153
|
+
let a = t.line === void 0 ? "" : ` at line ${t.line}`;
|
|
154
|
+
n === "cut" && Math.abs(r - i) <= D * r && e.warnings.push(`cut${a} removed nothing: the tool does not overlap the solid.`), n === "intersect" && i <= D * r && e.warnings.push(`intersect${a} left nothing: the two shapes do not overlap.`);
|
|
155
|
+
}
|
|
156
|
+
function re(e, n, a) {
|
|
157
|
+
return function(...o) {
|
|
158
|
+
let s = c;
|
|
159
|
+
if (!s || l > 0) return a.apply(this, o);
|
|
160
|
+
let u = r(), d = {
|
|
161
|
+
args: o,
|
|
162
|
+
selection: {}
|
|
163
|
+
};
|
|
164
|
+
try {
|
|
165
|
+
d = C[n](e, this, o);
|
|
166
|
+
} catch {}
|
|
167
|
+
let { selection: h } = d, g = p(e, this), v;
|
|
168
|
+
l += 1;
|
|
169
|
+
try {
|
|
170
|
+
v = a.apply(this, d.args);
|
|
171
|
+
} catch (r) {
|
|
172
|
+
if (r instanceof i) throw r;
|
|
173
|
+
let a = h.selected === 0 ? void 0 : E[n];
|
|
174
|
+
throw new i("OPERATION_FAILED", `${w(n, h, u)} failed: ${t(e.oc, r)}. When it ran, ${T(n, h, this)}.` + (a ? ` ${a}` : ""), u);
|
|
175
|
+
} finally {
|
|
176
|
+
--l;
|
|
177
|
+
}
|
|
178
|
+
let y = p(e, v);
|
|
179
|
+
if (_(v) && "wrapped" in v && !m(e, v)) {
|
|
180
|
+
let e = E[n];
|
|
181
|
+
throw new i("INVALID_RESULT", `${w(n, h, u)} returned a shape that is not a valid solid (volume ${f(g)} -> ${f(y)} mm3). When it ran, ${T(n, h, this)}.` + (e ? ` ${e}` : ""), u);
|
|
182
|
+
}
|
|
183
|
+
let b = {
|
|
184
|
+
op: n,
|
|
185
|
+
...u === void 0 ? {} : { line: u },
|
|
186
|
+
...h.size === void 0 ? {} : { size: h.size },
|
|
187
|
+
...h.selected === void 0 ? {} : { selected: h.selected },
|
|
188
|
+
...h.available === void 0 ? {} : { available: h.available },
|
|
189
|
+
volumeBefore: g,
|
|
190
|
+
volumeAfter: y
|
|
191
|
+
};
|
|
192
|
+
return s.operations.push(b), ne(s, b), v;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function O(e, t) {
|
|
196
|
+
let n = (e) => typeof e == "number" ? `${f(e, 3)}` : typeof e == "string" ? JSON.stringify(e) : typeof e == "function" ? "fn" : Array.isArray(e) ? `[${e.map(n).join(", ")}]` : _(e) ? "{...}" : String(e), r = t.map(n).join(", ");
|
|
197
|
+
return `${e}(${r.length > 80 ? `${r.slice(0, 77)}...` : r})`;
|
|
198
|
+
}
|
|
199
|
+
var ie = /* @__PURE__ */ new Set([
|
|
200
|
+
"extrude",
|
|
201
|
+
"revolve",
|
|
202
|
+
"loftWith",
|
|
203
|
+
"sweepSketch"
|
|
204
|
+
]);
|
|
205
|
+
function ae(e, n, a, o) {
|
|
206
|
+
return function(...s) {
|
|
207
|
+
if (!c || l > 0) return a.apply(this, s);
|
|
208
|
+
if (o && Array.isArray(s[0])) {
|
|
209
|
+
let e = r();
|
|
210
|
+
throw new i("SCRIPT_ERROR", `${O(n, s)}${e === void 0 ? "" : ` at line ${e}`}: ${n} takes numbers, distances from where the pen is. For points, as here, use ${o}.`, e);
|
|
211
|
+
}
|
|
212
|
+
let u;
|
|
213
|
+
l += 1;
|
|
214
|
+
try {
|
|
215
|
+
u = a.apply(this, s);
|
|
216
|
+
} catch (a) {
|
|
217
|
+
if (a instanceof Error) throw a;
|
|
218
|
+
let o = r();
|
|
219
|
+
throw new i("OPERATION_FAILED", `${O(n, s)}${o === void 0 ? "" : ` at line ${o}`} failed: ${t(e.oc, a)}.`, o);
|
|
220
|
+
} finally {
|
|
221
|
+
--l;
|
|
222
|
+
}
|
|
223
|
+
if (ie.has(n) && _(u) && "wrapped" in u && !m(e, u)) {
|
|
224
|
+
let e = r();
|
|
225
|
+
throw new i("INVALID_RESULT", `${O(n, s)}${e === void 0 ? "" : ` at line ${e}`} returned a shape that is not a valid solid, ${g(h(u))}. Its profile probably crosses itself: check each point, and that an arc given numbers (threePointsArc) was meant as distances from the pen, not as points (threePointsArcTo).`, e);
|
|
226
|
+
}
|
|
227
|
+
return u;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
var oe = [
|
|
231
|
+
"BaseSketcher2d",
|
|
232
|
+
"DrawingPen",
|
|
233
|
+
"Sketcher",
|
|
234
|
+
"Drawing",
|
|
235
|
+
"Blueprint",
|
|
236
|
+
"Blueprints",
|
|
237
|
+
"CompoundBlueprint",
|
|
238
|
+
"Sketch",
|
|
239
|
+
"Sketches",
|
|
240
|
+
"CompoundSketch",
|
|
241
|
+
"Shape",
|
|
242
|
+
"_3DShape"
|
|
243
|
+
];
|
|
244
|
+
function se(e, t) {
|
|
245
|
+
for (let n of Object.getOwnPropertyNames(t)) {
|
|
246
|
+
if (n === "constructor" || n.startsWith("_") || k.includes(n)) continue;
|
|
247
|
+
let r = Object.getOwnPropertyDescriptor(t, n);
|
|
248
|
+
if (typeof r?.value != "function") continue;
|
|
249
|
+
let i = `${n}To`;
|
|
250
|
+
t[n] = ae(e, n, r.value, typeof t[i] == "function" ? i : void 0);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
var k = [
|
|
254
|
+
"fillet",
|
|
255
|
+
"chamfer",
|
|
256
|
+
"shell",
|
|
257
|
+
"fuse",
|
|
258
|
+
"cut",
|
|
259
|
+
"intersect"
|
|
260
|
+
], A = Symbol.for("@gui-chat-plugin/brep:instrumented");
|
|
261
|
+
function ce(e) {
|
|
262
|
+
let t = e.replicad._3DShape.prototype;
|
|
263
|
+
if (t[A]) return;
|
|
264
|
+
t[A] = !0;
|
|
265
|
+
for (let n of k) {
|
|
266
|
+
let r = t[n];
|
|
267
|
+
typeof r == "function" && (t[n] = re(e, n, r));
|
|
268
|
+
}
|
|
269
|
+
let n = e.replicad;
|
|
270
|
+
for (let t of oe) {
|
|
271
|
+
let r = n[t]?.prototype;
|
|
272
|
+
r && se(e, r);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// src/kernel/load.ts
|
|
276
|
+
var j;
|
|
277
|
+
async function le() {
|
|
278
|
+
let [e, { default: t }] = await Promise.all([import("replicad"), import("replicad-opencascadejs")]), n = await t({
|
|
279
|
+
print: () => {},
|
|
280
|
+
printErr: () => {}
|
|
281
|
+
});
|
|
282
|
+
e.setOC(n);
|
|
283
|
+
let r = {
|
|
284
|
+
oc: n,
|
|
285
|
+
replicad: e
|
|
286
|
+
};
|
|
287
|
+
return ce(r), r;
|
|
288
|
+
}
|
|
289
|
+
function ue() {
|
|
290
|
+
return j ??= le().catch((e) => {
|
|
291
|
+
throw j = void 0, e;
|
|
292
|
+
}), j;
|
|
293
|
+
}
|
|
294
|
+
// src/kernel/output.ts
|
|
295
|
+
var M = async (e) => new Uint8Array(await e.arrayBuffer());
|
|
296
|
+
function de(e, t) {
|
|
297
|
+
return M(e.replicad.exportSTEP(t.map((e, n) => ({
|
|
298
|
+
shape: e.shape,
|
|
299
|
+
name: e.name ?? (t.length > 1 ? `part ${n + 1}` : "model")
|
|
300
|
+
})), {
|
|
301
|
+
unit: "MM",
|
|
302
|
+
modelUnit: "MM"
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
var N = .05, P = .25;
|
|
306
|
+
function F(e) {
|
|
307
|
+
return M(e.blobSTL({
|
|
308
|
+
tolerance: N,
|
|
309
|
+
angularTolerance: P,
|
|
310
|
+
binary: !0
|
|
311
|
+
}));
|
|
312
|
+
}
|
|
313
|
+
var I = .1, L = .3;
|
|
314
|
+
function R(e) {
|
|
315
|
+
let t = {
|
|
316
|
+
tolerance: I,
|
|
317
|
+
angularTolerance: L
|
|
318
|
+
}, n = e.mesh(t), r = e.meshEdges(t);
|
|
319
|
+
return a({
|
|
320
|
+
vertices: n.vertices,
|
|
321
|
+
normals: n.normals,
|
|
322
|
+
triangles: n.triangles,
|
|
323
|
+
lines: r.lines
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
var z = [
|
|
327
|
+
{
|
|
328
|
+
label: "Top",
|
|
329
|
+
from: [
|
|
330
|
+
0,
|
|
331
|
+
0,
|
|
332
|
+
1
|
|
333
|
+
],
|
|
334
|
+
right: [
|
|
335
|
+
1,
|
|
336
|
+
0,
|
|
337
|
+
0
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
label: "From above, front right",
|
|
342
|
+
from: [
|
|
343
|
+
1,
|
|
344
|
+
-1.2,
|
|
345
|
+
.9
|
|
346
|
+
],
|
|
347
|
+
right: [
|
|
348
|
+
1.2,
|
|
349
|
+
1,
|
|
350
|
+
0
|
|
351
|
+
]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
label: "Front",
|
|
355
|
+
from: [
|
|
356
|
+
0,
|
|
357
|
+
-1,
|
|
358
|
+
0
|
|
359
|
+
],
|
|
360
|
+
right: [
|
|
361
|
+
1,
|
|
362
|
+
0,
|
|
363
|
+
0
|
|
364
|
+
]
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
label: "Right",
|
|
368
|
+
from: [
|
|
369
|
+
1,
|
|
370
|
+
0,
|
|
371
|
+
0
|
|
372
|
+
],
|
|
373
|
+
right: [
|
|
374
|
+
0,
|
|
375
|
+
1,
|
|
376
|
+
0
|
|
377
|
+
]
|
|
378
|
+
}
|
|
379
|
+
], B = 600, V = 28;
|
|
380
|
+
function H(e, t, n) {
|
|
381
|
+
let [r, i, a] = t.boundingBox.center, o = t.boundingBox, s = Math.max(o.width, o.height, o.depth, 1) * 4, c = Math.hypot(...n.from), l = [
|
|
382
|
+
r + n.from[0] / c * s,
|
|
383
|
+
i + n.from[1] / c * s,
|
|
384
|
+
a + n.from[2] / c * s
|
|
385
|
+
], u = [
|
|
386
|
+
n.from[0],
|
|
387
|
+
n.from[1],
|
|
388
|
+
n.from[2]
|
|
389
|
+
];
|
|
390
|
+
return new e.replicad.ProjectionCamera(l, u, n.right);
|
|
391
|
+
}
|
|
392
|
+
var U = (e) => e.toSVGPaths().flat().map((e) => `<path d="${e}"/>`).join("");
|
|
393
|
+
function fe(e, t) {
|
|
394
|
+
let n = z.map((n, r) => {
|
|
395
|
+
let { visible: i, hidden: a } = e.replicad.drawProjection(t, H(e, t, n)), o = r % 2 * B, s = Math.floor(r / 2) * B;
|
|
396
|
+
return `<text x="${o + 16}" y="${s + 22}" font-family="sans-serif" font-size="16" fill="#555">${n.label}</text><svg x="${o}" y="${s + V}" width="${B}" height="572" viewBox="${i.toSVGViewBox(6)}" preserveAspectRatio="xMidYMid meet" fill="none" stroke-linecap="round" stroke-linejoin="round"><g stroke="#b0b0b0" stroke-width="1" stroke-dasharray="5 4" vector-effect="non-scaling-stroke">${U(a).replace(/<path /g, "<path vector-effect=\"non-scaling-stroke\" ")}</g><g stroke="#111" stroke-width="1.8">${U(i).replace(/<path /g, "<path vector-effect=\"non-scaling-stroke\" ")}</g></svg>`;
|
|
397
|
+
}), r = B * 2;
|
|
398
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${r} ${r}" width="${r}" height="${r}"><rect width="${r}" height="${r}" fill="#fff"/><path d="M${B} 0V${r}M0 ${B}H${r}" stroke="#e5e5e5"/>` + n.join("") + "</svg>";
|
|
399
|
+
}
|
|
400
|
+
// src/kernel/report.ts
|
|
401
|
+
var W = (e, t = 2) => Number.isFinite(e) ? Number(e.toFixed(t)) : e, pe = (e) => e === "CYLINDRE" ? "cylinder" : e.toLowerCase().replace(/_/g, " ");
|
|
402
|
+
function G(e) {
|
|
403
|
+
let t = {};
|
|
404
|
+
for (let n of e) {
|
|
405
|
+
let e = "other";
|
|
406
|
+
try {
|
|
407
|
+
e = pe(n.geomType);
|
|
408
|
+
} catch {}
|
|
409
|
+
t[e] = (t[e] ?? 0) + 1;
|
|
410
|
+
}
|
|
411
|
+
return t;
|
|
412
|
+
}
|
|
413
|
+
function K(e) {
|
|
414
|
+
let t = [], n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
|
|
415
|
+
for (let i of e) {
|
|
416
|
+
let e = `${i.op}:${i.line ?? "?"}:${i.size ?? ""}`, a = n.get(e);
|
|
417
|
+
a || (a = {
|
|
418
|
+
op: i.op,
|
|
419
|
+
...i.line === void 0 ? {} : { line: i.line },
|
|
420
|
+
count: 0,
|
|
421
|
+
...i.size === void 0 ? {} : { size: i.size },
|
|
422
|
+
...i.available === void 0 ? {} : { available: i.available }
|
|
423
|
+
}, n.set(e, a), t.push(a), r.set(a, 0)), a.count += 1, i.selected !== void 0 && (a.selected = (a.selected ?? 0) + i.selected);
|
|
424
|
+
let o = i.volumeAfter - i.volumeBefore;
|
|
425
|
+
r.set(a, (r.get(a) ?? 0) + o);
|
|
426
|
+
}
|
|
427
|
+
for (let e of t) {
|
|
428
|
+
let t = r.get(e);
|
|
429
|
+
t !== void 0 && Number.isFinite(t) && (e.volumeChange = W(t));
|
|
430
|
+
}
|
|
431
|
+
return t;
|
|
432
|
+
}
|
|
433
|
+
function q(e, t) {
|
|
434
|
+
let n = [...e.replicad.iterTopo(t.wrapped, "solid")];
|
|
435
|
+
for (let e of n) e.delete();
|
|
436
|
+
return n.length;
|
|
437
|
+
}
|
|
438
|
+
function me(e, t) {
|
|
439
|
+
try {
|
|
440
|
+
return e.replicad.measureArea(t);
|
|
441
|
+
} catch {
|
|
442
|
+
return NaN;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function he(e, t) {
|
|
446
|
+
let [n] = t;
|
|
447
|
+
return t.length === 1 && n ? n.shape : e.replicad.makeCompound(t.map((e) => e.shape.clone()));
|
|
448
|
+
}
|
|
449
|
+
function ge(e, t, n, r) {
|
|
450
|
+
let i = [...r.warnings];
|
|
451
|
+
t.forEach((n, r) => {
|
|
452
|
+
let a = n.name ?? (t.length > 1 ? `part ${r + 1}` : ""), o = a ? `"${a}"` : "The model";
|
|
453
|
+
m(e, n.shape) || i.push(`${o} is not a valid solid.`);
|
|
454
|
+
let s = q(e, n.shape);
|
|
455
|
+
s > 1 && i.push(`${o} is ${s} separate solids: pieces that were fused do not touch. If it is one piece, make them overlap and build again; if they are separate on purpose, tell the user it is ${s} loose pieces.`), s === 0 && i.push(`${o} is not a solid: it has no enclosed volume.`);
|
|
456
|
+
});
|
|
457
|
+
let a = n.boundingBox.bounds, o = (e) => [
|
|
458
|
+
W(e[0], 3),
|
|
459
|
+
W(e[1], 3),
|
|
460
|
+
W(e[2], 3)
|
|
461
|
+
];
|
|
462
|
+
return {
|
|
463
|
+
volume: W(p(e, n)),
|
|
464
|
+
area: W(me(e, n)),
|
|
465
|
+
size: h(n),
|
|
466
|
+
bounds: [o(a[0]), o(a[1])],
|
|
467
|
+
solids: q(e, n),
|
|
468
|
+
faces: G(n.faces),
|
|
469
|
+
edges: G(n.edges),
|
|
470
|
+
operations: K(r.operations),
|
|
471
|
+
warnings: i,
|
|
472
|
+
...t.length > 1 ? { parts: t.map((t) => ({
|
|
473
|
+
...t.name ? { name: t.name } : {},
|
|
474
|
+
volume: W(p(e, t.shape)),
|
|
475
|
+
size: h(t.shape)
|
|
476
|
+
})) } : {}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
var _e = {
|
|
480
|
+
fillet: "edges",
|
|
481
|
+
chamfer: "edges",
|
|
482
|
+
shell: "faces"
|
|
483
|
+
}, J = (e) => Object.entries(e).sort(([, e], [, t]) => t - e).map(([e, t]) => `${t} ${e}`).join(", "), ve = (e) => `${e > 0 ? "+" : ""}${e} mm3`;
|
|
484
|
+
function Y(e) {
|
|
485
|
+
let t = e.line === void 0 ? "" : `line ${e.line}: `, n = e.size === void 0 ? "" : `${e.size}`, r = e.count > 1 ? ` x${e.count}` : "", i = _e[e.op], a = i && e.selected !== void 0 ? ` selected ${e.selected}${e.count === 1 && e.available !== void 0 ? ` of ${e.available}` : ""} ${i},` : "", o = e.volumeChange === void 0 ? "" : ` volume ${ve(e.volumeChange)}`;
|
|
486
|
+
return ` ${t}${e.op}(${n})${r}${a}${o}`;
|
|
487
|
+
}
|
|
488
|
+
var ye = (e) => K(e).map((e) => Y(e).trim());
|
|
489
|
+
function be(e) {
|
|
490
|
+
let t = [`${e.size.join(" x ")} mm, volume ${e.volume} mm3, surface ${e.area} mm2, ${e.solids} solid${e.solids === 1 ? "" : "s"}.`];
|
|
491
|
+
return e.warnings.length && t.push(`Warnings (${e.warnings.length}):`, ...e.warnings.map((e) => ` ${e}`)), t.push(`Faces: ${J(e.faces)}.`, `Edges: ${J(e.edges)}.`), e.parts && t.push("Parts: " + e.parts.map((e, t) => `${e.name ?? `part ${t + 1}`} ${e.size.join(" x ")} mm, ${e.volume} mm3`).join("; ") + "."), e.operations.length && t.push("Operations:", ...e.operations.map(Y)), t.join("\n");
|
|
492
|
+
}
|
|
493
|
+
// src/kernel/script.ts
|
|
494
|
+
var xe = " A model script is not a module: write `const { draw, makeCylinder } = replicad;` in place of an import, and define `main` without `export`.";
|
|
495
|
+
function Se(t) {
|
|
496
|
+
try {
|
|
497
|
+
return s(`${t}\n;return typeof main === "function" ? main : undefined;`, ["replicad"], { filename: n });
|
|
498
|
+
} catch (t) {
|
|
499
|
+
let n = t instanceof Error ? t.message : String(t), r = t instanceof Error ? t.stack : void 0, a = /\b(import|export)\b/.test(n);
|
|
500
|
+
throw new i("SYNTAX_ERROR", `${n}.${a ? xe : ""}`, e(r));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
var Ce = 0;
|
|
504
|
+
function X(e, t) {
|
|
505
|
+
let n = `__guiChatPluginBrepRun${++Ce}`, r = globalThis;
|
|
506
|
+
r[n] = e;
|
|
507
|
+
try {
|
|
508
|
+
return new o(`globalThis[${JSON.stringify(n)}]()`).runInThisContext({ timeout: t });
|
|
509
|
+
} finally {
|
|
510
|
+
Reflect.deleteProperty(r, n);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
var Z = "main() must be an ordinary function that returns the solid, not an async one: the time limit cannot stop a script once it has awaited. Build the solid without `await`.", we = (e) => typeof e == "function" && e.constructor?.name === "AsyncFunction", Q = (e) => typeof e == "object" && !!e, Te = (e) => Q(e) ? e.constructor?.name ?? "an object" : typeof e;
|
|
514
|
+
function Ee(e, t) {
|
|
515
|
+
let n = Q(t) && "shape" in t, r = n ? t.shape : t, a = n && typeof t.name == "string" ? t.name : void 0;
|
|
516
|
+
if (!(Q(r) && "wrapped" in r && e.replicad.isShape3D(r))) throw new i("SCRIPT_ERROR", `main() must return a solid, an array of solids, or { shape, name } objects; it returned ${Te(r)}. A drawing or sketch has to be extruded or revolved first.`);
|
|
517
|
+
return {
|
|
518
|
+
shape: r,
|
|
519
|
+
...a ? { name: a } : {}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
async function De(n, r, a) {
|
|
523
|
+
let o = Se(r), s;
|
|
524
|
+
try {
|
|
525
|
+
if (s = X(() => {
|
|
526
|
+
let e = o(n.replicad);
|
|
527
|
+
if (!e) throw new i("SCRIPT_ERROR", "The script must define a function named `main` that returns the solid.");
|
|
528
|
+
if (we(e)) throw new i("SCRIPT_ERROR", Z);
|
|
529
|
+
return e();
|
|
530
|
+
}, a), s instanceof Promise) throw s.catch(() => void 0), new i("SCRIPT_ERROR", Z);
|
|
531
|
+
} catch (r) {
|
|
532
|
+
throw r instanceof i ? r : Q(r) && r.code === "ERR_SCRIPT_EXECUTION_TIMEOUT" ? new i("TIMEOUT", `The script ran for more than ${a / 1e3} s and was stopped.`) : new i("SCRIPT_ERROR", t(n.oc, r), e(r instanceof Error ? r.stack : void 0));
|
|
533
|
+
}
|
|
534
|
+
let c = Array.isArray(s) ? s : [s];
|
|
535
|
+
if (c.length === 0) throw new i("SCRIPT_ERROR", "main() returned an empty array.");
|
|
536
|
+
return c.map((e) => Ee(n, e));
|
|
537
|
+
}
|
|
538
|
+
var $ = Promise.resolve();
|
|
539
|
+
async function Oe(e, n) {
|
|
540
|
+
let r = await ue(), a = u();
|
|
541
|
+
try {
|
|
542
|
+
let o = await De(r, e, n.timeoutMs ?? 6e4);
|
|
543
|
+
try {
|
|
544
|
+
let e = he(r, o);
|
|
545
|
+
return {
|
|
546
|
+
report: ge(r, o, e, a),
|
|
547
|
+
mesh: R(e),
|
|
548
|
+
step: await de(r, o),
|
|
549
|
+
stl: await F(e),
|
|
550
|
+
views: fe(r, e)
|
|
551
|
+
};
|
|
552
|
+
} catch (e) {
|
|
553
|
+
throw e instanceof i ? e : new i("INVALID_RESULT", `The script ran, but what main() returned could not be measured or exported: ${t(r.oc, e)}. That is a shape which is not a valid solid: look at the last operations, and at any profile that may cross itself.`);
|
|
554
|
+
}
|
|
555
|
+
} catch (e) {
|
|
556
|
+
throw e instanceof i && (e.completed = ye(a.operations)), e;
|
|
557
|
+
} finally {
|
|
558
|
+
d();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function ke(e, t = {}) {
|
|
562
|
+
let n = $.then(() => Oe(e, t));
|
|
563
|
+
return $ = n.catch(() => void 0), n;
|
|
564
|
+
}
|
|
565
|
+
export { ke as buildModel, be as formatReport };
|