brepjs 8.8.2 → 8.8.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.
- package/dist/2d/curves.d.ts.map +1 -1
- package/dist/2d/lib/Curve2D.d.ts.map +1 -1
- package/dist/2d/lib/approximations.d.ts.map +1 -1
- package/dist/2d/lib/makeCurves.d.ts.map +1 -1
- package/dist/2d/lib/ocWrapper.d.ts.map +1 -1
- package/dist/2d.cjs +2 -2
- package/dist/2d.js +3 -3
- package/dist/Blueprint-BmFJ4caY.cjs +1439 -0
- package/dist/Blueprint-DsoGiJNJ.js +1440 -0
- package/dist/{boolean2D-q5FOdOQW.cjs → boolean2D-BQk8LNmZ.cjs} +212 -127
- package/dist/{boolean2D-Dgnuy63w.js → boolean2D-D5O0F3J8.js} +212 -127
- package/dist/{booleanFns-CFit7JYt.cjs → booleanFns-CVM3dOTP.cjs} +210 -130
- package/dist/{booleanFns--Orezl-b.js → booleanFns-DOyKxL7q.js} +210 -130
- package/dist/brepjs.cjs +457 -304
- package/dist/brepjs.js +551 -398
- package/dist/core/disposal.d.ts +44 -3
- package/dist/core/disposal.d.ts.map +1 -1
- package/dist/core/geometryHelpers.d.ts.map +1 -1
- package/dist/core/kernelCall.d.ts +20 -0
- package/dist/core/kernelCall.d.ts.map +1 -1
- package/dist/core/memory.d.ts +1 -1
- package/dist/core/memory.d.ts.map +1 -1
- package/dist/core.cjs +4 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +11 -8
- package/dist/{cornerFinder-KNTFoGrm.js → cornerFinder-DH6EwYfL.js} +1 -1
- package/dist/{cornerFinder-v4un1Fr9.cjs → cornerFinder-XAV2ywVS.cjs} +1 -1
- package/dist/curveFns-BHRYwxBM.js +281 -0
- package/dist/{curveFns-6ovDM_sR.cjs → curveFns-BsAHC3Qv.cjs} +137 -36
- package/dist/{drawFns-WgXeXHH1.cjs → drawFns-CsmUF97U.cjs} +181 -101
- package/dist/{drawFns-XwroLxdb.js → drawFns-hD05g0ZQ.js} +181 -101
- package/dist/faceFns-DNQss51F.cjs +358 -0
- package/dist/faceFns-q5CR9pOW.js +359 -0
- package/dist/{helpers-CRfqaW0Y.cjs → helpers-aylLv0_I.cjs} +13 -10
- package/dist/{helpers-CtBCzEqs.js → helpers-tNdaX01G.js} +13 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/io/importFns.d.ts.map +1 -1
- package/dist/io.cjs +131 -63
- package/dist/io.js +131 -63
- package/dist/loft-CjEEqz2P.cjs +530 -0
- package/dist/loft-DTRcYrq2.js +531 -0
- package/dist/measurement-B6_cxjpw.cjs +200 -0
- package/dist/measurement-BXqFvcGh.js +201 -0
- package/dist/measurement.cjs +1 -1
- package/dist/measurement.js +1 -1
- package/dist/{meshFns-CPNNlpbw.cjs → meshFns-CTc1CRkF.cjs} +1 -1
- package/dist/{meshFns-DAmWVyEp.js → meshFns-DDFl7gLN.js} +1 -1
- package/dist/operations/exporterFns.d.ts.map +1 -1
- package/dist/operations/exporterUtils.d.ts +3 -3
- package/dist/operations/exporterUtils.d.ts.map +1 -1
- package/dist/operations/exporters.d.ts.map +1 -1
- package/dist/operations/extrude.d.ts.map +1 -1
- package/dist/operations/extrudeFns.d.ts.map +1 -1
- package/dist/operations/loft.d.ts.map +1 -1
- package/dist/operations/multiSweepFns.d.ts.map +1 -1
- package/dist/{operations-vN0tcoaU.js → operations-jRE2QbPo.js} +261 -166
- package/dist/{operations-BQ25CPI8.cjs → operations-pxjbW4Er.cjs} +261 -166
- package/dist/operations.cjs +2 -2
- package/dist/operations.js +2 -2
- package/dist/query/shapeDistanceFilter.d.ts.map +1 -1
- package/dist/query.cjs +66 -14
- package/dist/query.js +67 -15
- package/dist/{shapeFns-C785aeVn.cjs → shapeFns-D4CRxxmF.cjs} +61 -7
- package/dist/{shapeFns-ClpALED4.js → shapeFns-DNnBK8fG.js} +61 -7
- package/dist/{shapeTypes-DnwCo942.js → shapeTypes-Bi_9RZa2.js} +50 -19
- package/dist/{shapeTypes-CIijJxCz.cjs → shapeTypes-CWuX602K.cjs} +32 -1
- package/dist/sketching/CompoundSketch.d.ts.map +1 -1
- package/dist/sketching/Sketch.d.ts.map +1 -1
- package/dist/sketching/Sketcher.d.ts.map +1 -1
- package/dist/sketching/Sketcher2d.d.ts.map +1 -1
- package/dist/sketching/cannedSketches.d.ts.map +1 -1
- package/dist/sketching/draw.d.ts.map +1 -1
- package/dist/sketching.cjs +2 -2
- package/dist/sketching.js +2 -2
- package/dist/surfaceBuilders-CLal3WlK.cjs +429 -0
- package/dist/surfaceBuilders-W9Y25CIb.js +430 -0
- package/dist/topology/curveBuilders.d.ts.map +1 -1
- package/dist/topology/shapeFns.d.ts.map +1 -1
- package/dist/topology/solidBuilders.d.ts.map +1 -1
- package/dist/topology/surfaceBuilders.d.ts.map +1 -1
- package/dist/{topology-CqyxpmEh.js → topology-CMM6vAzx.js} +6 -6
- package/dist/{topology-zG8maSDK.cjs → topology-CNw-wsmG.cjs} +6 -6
- package/dist/topology.cjs +6 -6
- package/dist/topology.js +6 -6
- package/package.json +4 -1
- package/dist/Blueprint-BmbNUnGI.cjs +0 -1185
- package/dist/Blueprint-C-JJkkwL.js +0 -1186
- package/dist/curveFns-BhQECv8e.js +0 -180
- package/dist/faceFns-3PDjBeW7.js +0 -272
- package/dist/faceFns-CxaLWOjc.cjs +0 -271
- package/dist/loft-CVb-IjEI.cjs +0 -372
- package/dist/loft-DMFjK6lk.js +0 -373
- package/dist/measurement-CecYIt3s.cjs +0 -134
- package/dist/measurement-DHDLAH7-.js +0 -135
- package/dist/surfaceBuilders-CC0ZQGix.cjs +0 -289
- package/dist/surfaceBuilders-CrJtFu2a.js +0 -290
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const occtBoundary = require("./occtBoundary-Cqfsau2c.cjs");
|
|
3
|
-
const errors = require("./errors-NNmTtM5u.cjs");
|
|
4
|
-
const shapeTypes = require("./shapeTypes-CIijJxCz.cjs");
|
|
5
|
-
const shapeFns = require("./shapeFns-C785aeVn.cjs");
|
|
6
|
-
const faceFns = require("./faceFns-CxaLWOjc.cjs");
|
|
7
|
-
function range(len) {
|
|
8
|
-
return Array.from(Array(len).keys());
|
|
9
|
-
}
|
|
10
|
-
function zip(arrays) {
|
|
11
|
-
const minLength = Math.min(...arrays.map((arr) => arr.length));
|
|
12
|
-
return range(minLength).map((i) => arrays.map((arr) => arr[i]));
|
|
13
|
-
}
|
|
14
|
-
function makeLine(v1, v2) {
|
|
15
|
-
const oc = occtBoundary.getKernel().oc;
|
|
16
|
-
const r = shapeTypes.gcWithScope();
|
|
17
|
-
const p1 = r(occtBoundary.toOcPnt(v1));
|
|
18
|
-
const p2 = r(occtBoundary.toOcPnt(v2));
|
|
19
|
-
const maker = r(new oc.BRepBuilderAPI_MakeEdge_3(p1, p2));
|
|
20
|
-
return shapeTypes.createEdge(maker.Edge());
|
|
21
|
-
}
|
|
22
|
-
function makeCircle(radius, center = [0, 0, 0], normal = [0, 0, 1]) {
|
|
23
|
-
const oc = occtBoundary.getKernel().oc;
|
|
24
|
-
const r = shapeTypes.gcWithScope();
|
|
25
|
-
const ax = r(occtBoundary.makeOcAx2(center, normal));
|
|
26
|
-
const circleGp = r(new oc.gp_Circ_2(ax, radius));
|
|
27
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_8(circleGp));
|
|
28
|
-
return shapeTypes.createEdge(edgeMaker.Edge());
|
|
29
|
-
}
|
|
30
|
-
function makeEllipse(majorRadius, minorRadius, center = [0, 0, 0], normal = [0, 0, 1], xDir) {
|
|
31
|
-
if (minorRadius > majorRadius) {
|
|
32
|
-
return errors.err(
|
|
33
|
-
errors.validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
const oc = occtBoundary.getKernel().oc;
|
|
37
|
-
const r = shapeTypes.gcWithScope();
|
|
38
|
-
const ax = r(occtBoundary.makeOcAx2(center, normal, xDir));
|
|
39
|
-
const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
|
|
40
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_12(ellipseGp));
|
|
41
|
-
return errors.ok(shapeTypes.createEdge(edgeMaker.Edge()));
|
|
42
|
-
}
|
|
43
|
-
function makeHelix(pitch, height, radius, center = [0, 0, 0], dir = [0, 0, 1], lefthand = false) {
|
|
44
|
-
const oc = occtBoundary.getKernel().oc;
|
|
45
|
-
const r = shapeTypes.gcWithScope();
|
|
46
|
-
const angularStep = lefthand ? -2 * Math.PI : 2 * Math.PI;
|
|
47
|
-
const geomLine = r(
|
|
48
|
-
new oc.Geom2d_Line_3(r(new oc.gp_Pnt2d_3(0, 0)), r(new oc.gp_Dir2d_4(angularStep, pitch)))
|
|
49
|
-
);
|
|
50
|
-
const nTurns = height / pitch;
|
|
51
|
-
const uStart = r(geomLine.Value(0));
|
|
52
|
-
const uStop = r(geomLine.Value(nTurns * Math.sqrt((2 * Math.PI) ** 2 + pitch ** 2)));
|
|
53
|
-
const geomSeg = r(new oc.GCE2d_MakeSegment_1(uStart, uStop));
|
|
54
|
-
const geomSurf = new oc.Geom_CylindricalSurface_1(r(occtBoundary.makeOcAx3(center, dir)), radius);
|
|
55
|
-
const e = r(
|
|
56
|
-
new oc.BRepBuilderAPI_MakeEdge_30(
|
|
57
|
-
r(new oc.Handle_Geom2d_Curve_2(geomSeg.Value().get())),
|
|
58
|
-
r(new oc.Handle_Geom_Surface_2(geomSurf))
|
|
59
|
-
)
|
|
60
|
-
).Edge();
|
|
61
|
-
const w = r(new oc.BRepBuilderAPI_MakeWire_2(e)).Wire();
|
|
62
|
-
oc.BRepLib.BuildCurves3d_2(w);
|
|
63
|
-
return shapeTypes.createWire(w);
|
|
64
|
-
}
|
|
65
|
-
function makeThreePointArc(v1, v2, v3) {
|
|
66
|
-
const oc = occtBoundary.getKernel().oc;
|
|
67
|
-
const r = shapeTypes.gcWithScope();
|
|
68
|
-
const p1 = r(occtBoundary.toOcPnt(v1));
|
|
69
|
-
const p2 = r(occtBoundary.toOcPnt(v2));
|
|
70
|
-
const p3 = r(occtBoundary.toOcPnt(v3));
|
|
71
|
-
const arcMaker = r(new oc.GC_MakeArcOfCircle_4(p1, p2, p3));
|
|
72
|
-
const circleGeom = r(arcMaker.Value());
|
|
73
|
-
const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
|
|
74
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
75
|
-
return shapeTypes.createEdge(edgeMaker.Edge());
|
|
76
|
-
}
|
|
77
|
-
function makeEllipseArc(majorRadius, minorRadius, startAngle, endAngle, center = [0, 0, 0], normal = [0, 0, 1], xDir) {
|
|
78
|
-
if (minorRadius > majorRadius) {
|
|
79
|
-
return errors.err(
|
|
80
|
-
errors.validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
const oc = occtBoundary.getKernel().oc;
|
|
84
|
-
const r = shapeTypes.gcWithScope();
|
|
85
|
-
const ax = r(occtBoundary.makeOcAx2(center, normal, xDir));
|
|
86
|
-
const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
|
|
87
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_13(ellipseGp, startAngle, endAngle));
|
|
88
|
-
return errors.ok(shapeTypes.createEdge(edgeMaker.Edge()));
|
|
89
|
-
}
|
|
90
|
-
function makeBSplineApproximation(points, { tolerance = 1e-3, smoothing = null, degMax = 6, degMin = 1 } = {}) {
|
|
91
|
-
const oc = occtBoundary.getKernel().oc;
|
|
92
|
-
const r = shapeTypes.gcWithScope();
|
|
93
|
-
const pnts = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
|
|
94
|
-
points.forEach((point, index) => {
|
|
95
|
-
pnts.SetValue(index + 1, r(occtBoundary.toOcPnt(point)));
|
|
96
|
-
});
|
|
97
|
-
let splineBuilder;
|
|
98
|
-
if (smoothing) {
|
|
99
|
-
splineBuilder = r(
|
|
100
|
-
new oc.GeomAPI_PointsToBSpline_5(
|
|
101
|
-
pnts,
|
|
102
|
-
smoothing[0],
|
|
103
|
-
smoothing[1],
|
|
104
|
-
smoothing[2],
|
|
105
|
-
degMax,
|
|
106
|
-
oc.GeomAbs_Shape.GeomAbs_C2,
|
|
107
|
-
tolerance
|
|
108
|
-
)
|
|
109
|
-
);
|
|
110
|
-
} else {
|
|
111
|
-
splineBuilder = r(
|
|
112
|
-
new oc.GeomAPI_PointsToBSpline_2(
|
|
113
|
-
pnts,
|
|
114
|
-
degMin,
|
|
115
|
-
degMax,
|
|
116
|
-
oc.GeomAbs_Shape.GeomAbs_C2,
|
|
117
|
-
tolerance
|
|
118
|
-
)
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
if (!splineBuilder.IsDone()) {
|
|
122
|
-
return errors.err(errors.occtError("BSPLINE_FAILED", "B-spline approximation failed"));
|
|
123
|
-
}
|
|
124
|
-
const splineGeom = r(splineBuilder.Curve());
|
|
125
|
-
const curve = r(new oc.Handle_Geom_Curve_2(splineGeom.get()));
|
|
126
|
-
return errors.ok(shapeTypes.createEdge(new oc.BRepBuilderAPI_MakeEdge_24(curve).Edge()));
|
|
127
|
-
}
|
|
128
|
-
function makeBezierCurve(points) {
|
|
129
|
-
if (points.length < 2) {
|
|
130
|
-
return errors.err(
|
|
131
|
-
errors.validationError(
|
|
132
|
-
"BEZIER_MIN_POINTS",
|
|
133
|
-
`Need at least 2 points for a Bezier curve, got ${points.length}`,
|
|
134
|
-
void 0,
|
|
135
|
-
{
|
|
136
|
-
pointCount: points.length
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
const oc = occtBoundary.getKernel().oc;
|
|
142
|
-
const r = shapeTypes.gcWithScope();
|
|
143
|
-
const arrayOfPoints = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
|
|
144
|
-
points.forEach((p, i) => {
|
|
145
|
-
arrayOfPoints.SetValue(i + 1, r(occtBoundary.toOcPnt(p)));
|
|
146
|
-
});
|
|
147
|
-
const bezCurve = new oc.Geom_BezierCurve_1(arrayOfPoints);
|
|
148
|
-
const curve = r(new oc.Handle_Geom_Curve_2(bezCurve));
|
|
149
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
150
|
-
return errors.ok(shapeTypes.createEdge(edgeMaker.Edge()));
|
|
151
|
-
}
|
|
152
|
-
function makeTangentArc(startPoint, startTgt, endPoint) {
|
|
153
|
-
const oc = occtBoundary.getKernel().oc;
|
|
154
|
-
const r = shapeTypes.gcWithScope();
|
|
155
|
-
const circleGeom = r(
|
|
156
|
-
new oc.GC_MakeArcOfCircle_5(
|
|
157
|
-
r(occtBoundary.toOcPnt(startPoint)),
|
|
158
|
-
r(occtBoundary.toOcVec(startTgt)),
|
|
159
|
-
r(occtBoundary.toOcPnt(endPoint))
|
|
160
|
-
).Value()
|
|
161
|
-
);
|
|
162
|
-
const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
|
|
163
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
164
|
-
return shapeTypes.createEdge(edgeMaker.Edge());
|
|
165
|
-
}
|
|
166
|
-
function assembleWire(listOfEdges) {
|
|
167
|
-
const oc = occtBoundary.getKernel().oc;
|
|
168
|
-
const r = shapeTypes.gcWithScope();
|
|
169
|
-
const wireBuilder = r(new oc.BRepBuilderAPI_MakeWire_1());
|
|
170
|
-
listOfEdges.forEach((e) => {
|
|
171
|
-
if (shapeTypes.isEdge(e)) {
|
|
172
|
-
wireBuilder.Add_1(e.wrapped);
|
|
173
|
-
}
|
|
174
|
-
if (shapeTypes.isWire(e)) {
|
|
175
|
-
wireBuilder.Add_2(e.wrapped);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
const progress = r(new oc.Message_ProgressRange_1());
|
|
179
|
-
wireBuilder.Build(progress);
|
|
180
|
-
const res = wireBuilder.Error();
|
|
181
|
-
if (res !== oc.BRepBuilderAPI_WireError.BRepBuilderAPI_WireDone) {
|
|
182
|
-
const errorNames = /* @__PURE__ */ new Map([
|
|
183
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_EmptyWire, "empty wire"],
|
|
184
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_NonManifoldWire, "non manifold wire"],
|
|
185
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_DisconnectedWire, "disconnected wire"]
|
|
186
|
-
]);
|
|
187
|
-
return errors.err(
|
|
188
|
-
errors.occtError(
|
|
189
|
-
"WIRE_BUILD_FAILED",
|
|
190
|
-
`Failed to build the wire, ${errorNames.get(res) || "unknown error"}`
|
|
191
|
-
)
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
return errors.ok(shapeTypes.createWire(wireBuilder.Wire()));
|
|
195
|
-
}
|
|
196
|
-
function makeFace(wire, holes) {
|
|
197
|
-
const oc = occtBoundary.getKernel().oc;
|
|
198
|
-
const faceBuilder = new oc.BRepBuilderAPI_MakeFace_15(wire.wrapped, false);
|
|
199
|
-
holes?.forEach((hole) => {
|
|
200
|
-
faceBuilder.Add(hole.wrapped);
|
|
201
|
-
});
|
|
202
|
-
if (!faceBuilder.IsDone()) {
|
|
203
|
-
faceBuilder.delete();
|
|
204
|
-
return errors.err(
|
|
205
|
-
errors.occtError("FACE_BUILD_FAILED", "Failed to build the face. Your wire might be non planar.")
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
const face = faceBuilder.Face();
|
|
209
|
-
faceBuilder.delete();
|
|
210
|
-
return errors.ok(shapeTypes.createFace(face));
|
|
211
|
-
}
|
|
212
|
-
function fill(face) {
|
|
213
|
-
const outer = faceFns.outerWire(face);
|
|
214
|
-
return makeFace(outer);
|
|
215
|
-
}
|
|
216
|
-
function makeNewFaceWithinFace(originFace, wire) {
|
|
217
|
-
const oc = occtBoundary.getKernel().oc;
|
|
218
|
-
const [r, gc] = shapeTypes.localGC();
|
|
219
|
-
const surface = r(oc.BRep_Tool.Surface_2(originFace.wrapped));
|
|
220
|
-
const faceBuilder = r(new oc.BRepBuilderAPI_MakeFace_21(surface, wire.wrapped, true));
|
|
221
|
-
const face = faceBuilder.Face();
|
|
222
|
-
gc();
|
|
223
|
-
return shapeTypes.createFace(face);
|
|
224
|
-
}
|
|
225
|
-
function makeNonPlanarFace(wire) {
|
|
226
|
-
const oc = occtBoundary.getKernel().oc;
|
|
227
|
-
const [r, gc] = shapeTypes.localGC();
|
|
228
|
-
const faceBuilder = r(
|
|
229
|
-
new oc.BRepOffsetAPI_MakeFilling(3, 15, 2, false, 1e-5, 1e-4, 0.01, 0.1, 8, 9)
|
|
230
|
-
);
|
|
231
|
-
shapeFns.getEdges(wire).forEach((edge) => {
|
|
232
|
-
faceBuilder.Add_1(
|
|
233
|
-
edge.wrapped,
|
|
234
|
-
oc.GeomAbs_Shape.GeomAbs_C0,
|
|
235
|
-
true
|
|
236
|
-
);
|
|
237
|
-
});
|
|
238
|
-
const progress = r(new oc.Message_ProgressRange_1());
|
|
239
|
-
faceBuilder.Build(progress);
|
|
240
|
-
return errors.andThen(faceFns.cast(faceBuilder.Shape()), (newFace) => {
|
|
241
|
-
gc();
|
|
242
|
-
if (!shapeTypes.isFace(newFace)) {
|
|
243
|
-
return errors.err(errors.occtError("FACE_BUILD_FAILED", "Failed to create a face"));
|
|
244
|
-
}
|
|
245
|
-
return errors.ok(newFace);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
function addHolesInFace(face, holes) {
|
|
249
|
-
const oc = occtBoundary.getKernel().oc;
|
|
250
|
-
const [r, gc] = shapeTypes.localGC();
|
|
251
|
-
const faceMaker = r(new oc.BRepBuilderAPI_MakeFace_2(face.wrapped));
|
|
252
|
-
holes.forEach((wire) => {
|
|
253
|
-
faceMaker.Add(wire.wrapped);
|
|
254
|
-
});
|
|
255
|
-
const builtFace = r(faceMaker.Face());
|
|
256
|
-
const fixer = r(new oc.ShapeFix_Face_2(builtFace));
|
|
257
|
-
fixer.FixOrientation_1();
|
|
258
|
-
const newFace = fixer.Face();
|
|
259
|
-
gc();
|
|
260
|
-
return shapeTypes.createFace(newFace);
|
|
261
|
-
}
|
|
262
|
-
function makePolygon(points) {
|
|
263
|
-
if (points.length < 3)
|
|
264
|
-
return errors.err(
|
|
265
|
-
errors.validationError("POLYGON_MIN_POINTS", "You need at least 3 points to make a polygon")
|
|
266
|
-
);
|
|
267
|
-
const edges = zip([points, [...points.slice(1), points[0]]]).map(
|
|
268
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- zip returns untyped pairs
|
|
269
|
-
([p1, p2]) => makeLine(p1, p2)
|
|
270
|
-
);
|
|
271
|
-
return errors.andThen(assembleWire(edges), (wire) => makeFace(wire));
|
|
272
|
-
}
|
|
273
|
-
exports.addHolesInFace = addHolesInFace;
|
|
274
|
-
exports.assembleWire = assembleWire;
|
|
275
|
-
exports.fill = fill;
|
|
276
|
-
exports.makeBSplineApproximation = makeBSplineApproximation;
|
|
277
|
-
exports.makeBezierCurve = makeBezierCurve;
|
|
278
|
-
exports.makeCircle = makeCircle;
|
|
279
|
-
exports.makeEllipse = makeEllipse;
|
|
280
|
-
exports.makeEllipseArc = makeEllipseArc;
|
|
281
|
-
exports.makeFace = makeFace;
|
|
282
|
-
exports.makeHelix = makeHelix;
|
|
283
|
-
exports.makeLine = makeLine;
|
|
284
|
-
exports.makeNewFaceWithinFace = makeNewFaceWithinFace;
|
|
285
|
-
exports.makeNonPlanarFace = makeNonPlanarFace;
|
|
286
|
-
exports.makePolygon = makePolygon;
|
|
287
|
-
exports.makeTangentArc = makeTangentArc;
|
|
288
|
-
exports.makeThreePointArc = makeThreePointArc;
|
|
289
|
-
exports.zip = zip;
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { g as getKernel, d as toOcPnt, b as toOcVec, c as makeOcAx2, e as makeOcAx3 } from "./occtBoundary-DvBywHyU.js";
|
|
2
|
-
import { e as err, o as occtError, l as ok, x as validationError, a as andThen } from "./errors-DJ92ermb.js";
|
|
3
|
-
import { d as isEdge, m as isWire, o as createWire, p as createEdge, n as gcWithScope, q as createFace, r as localGC, e as isFace } from "./shapeTypes-DnwCo942.js";
|
|
4
|
-
import { d as getEdges } from "./shapeFns-ClpALED4.js";
|
|
5
|
-
import { o as outerWire, c as cast } from "./faceFns-3PDjBeW7.js";
|
|
6
|
-
function range(len) {
|
|
7
|
-
return Array.from(Array(len).keys());
|
|
8
|
-
}
|
|
9
|
-
function zip(arrays) {
|
|
10
|
-
const minLength = Math.min(...arrays.map((arr) => arr.length));
|
|
11
|
-
return range(minLength).map((i) => arrays.map((arr) => arr[i]));
|
|
12
|
-
}
|
|
13
|
-
function makeLine(v1, v2) {
|
|
14
|
-
const oc = getKernel().oc;
|
|
15
|
-
const r = gcWithScope();
|
|
16
|
-
const p1 = r(toOcPnt(v1));
|
|
17
|
-
const p2 = r(toOcPnt(v2));
|
|
18
|
-
const maker = r(new oc.BRepBuilderAPI_MakeEdge_3(p1, p2));
|
|
19
|
-
return createEdge(maker.Edge());
|
|
20
|
-
}
|
|
21
|
-
function makeCircle(radius, center = [0, 0, 0], normal = [0, 0, 1]) {
|
|
22
|
-
const oc = getKernel().oc;
|
|
23
|
-
const r = gcWithScope();
|
|
24
|
-
const ax = r(makeOcAx2(center, normal));
|
|
25
|
-
const circleGp = r(new oc.gp_Circ_2(ax, radius));
|
|
26
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_8(circleGp));
|
|
27
|
-
return createEdge(edgeMaker.Edge());
|
|
28
|
-
}
|
|
29
|
-
function makeEllipse(majorRadius, minorRadius, center = [0, 0, 0], normal = [0, 0, 1], xDir) {
|
|
30
|
-
if (minorRadius > majorRadius) {
|
|
31
|
-
return err(
|
|
32
|
-
validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
const oc = getKernel().oc;
|
|
36
|
-
const r = gcWithScope();
|
|
37
|
-
const ax = r(makeOcAx2(center, normal, xDir));
|
|
38
|
-
const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
|
|
39
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_12(ellipseGp));
|
|
40
|
-
return ok(createEdge(edgeMaker.Edge()));
|
|
41
|
-
}
|
|
42
|
-
function makeHelix(pitch, height, radius, center = [0, 0, 0], dir = [0, 0, 1], lefthand = false) {
|
|
43
|
-
const oc = getKernel().oc;
|
|
44
|
-
const r = gcWithScope();
|
|
45
|
-
const angularStep = lefthand ? -2 * Math.PI : 2 * Math.PI;
|
|
46
|
-
const geomLine = r(
|
|
47
|
-
new oc.Geom2d_Line_3(r(new oc.gp_Pnt2d_3(0, 0)), r(new oc.gp_Dir2d_4(angularStep, pitch)))
|
|
48
|
-
);
|
|
49
|
-
const nTurns = height / pitch;
|
|
50
|
-
const uStart = r(geomLine.Value(0));
|
|
51
|
-
const uStop = r(geomLine.Value(nTurns * Math.sqrt((2 * Math.PI) ** 2 + pitch ** 2)));
|
|
52
|
-
const geomSeg = r(new oc.GCE2d_MakeSegment_1(uStart, uStop));
|
|
53
|
-
const geomSurf = new oc.Geom_CylindricalSurface_1(r(makeOcAx3(center, dir)), radius);
|
|
54
|
-
const e = r(
|
|
55
|
-
new oc.BRepBuilderAPI_MakeEdge_30(
|
|
56
|
-
r(new oc.Handle_Geom2d_Curve_2(geomSeg.Value().get())),
|
|
57
|
-
r(new oc.Handle_Geom_Surface_2(geomSurf))
|
|
58
|
-
)
|
|
59
|
-
).Edge();
|
|
60
|
-
const w = r(new oc.BRepBuilderAPI_MakeWire_2(e)).Wire();
|
|
61
|
-
oc.BRepLib.BuildCurves3d_2(w);
|
|
62
|
-
return createWire(w);
|
|
63
|
-
}
|
|
64
|
-
function makeThreePointArc(v1, v2, v3) {
|
|
65
|
-
const oc = getKernel().oc;
|
|
66
|
-
const r = gcWithScope();
|
|
67
|
-
const p1 = r(toOcPnt(v1));
|
|
68
|
-
const p2 = r(toOcPnt(v2));
|
|
69
|
-
const p3 = r(toOcPnt(v3));
|
|
70
|
-
const arcMaker = r(new oc.GC_MakeArcOfCircle_4(p1, p2, p3));
|
|
71
|
-
const circleGeom = r(arcMaker.Value());
|
|
72
|
-
const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
|
|
73
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
74
|
-
return createEdge(edgeMaker.Edge());
|
|
75
|
-
}
|
|
76
|
-
function makeEllipseArc(majorRadius, minorRadius, startAngle, endAngle, center = [0, 0, 0], normal = [0, 0, 1], xDir) {
|
|
77
|
-
if (minorRadius > majorRadius) {
|
|
78
|
-
return err(
|
|
79
|
-
validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
const oc = getKernel().oc;
|
|
83
|
-
const r = gcWithScope();
|
|
84
|
-
const ax = r(makeOcAx2(center, normal, xDir));
|
|
85
|
-
const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
|
|
86
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_13(ellipseGp, startAngle, endAngle));
|
|
87
|
-
return ok(createEdge(edgeMaker.Edge()));
|
|
88
|
-
}
|
|
89
|
-
function makeBSplineApproximation(points, { tolerance = 1e-3, smoothing = null, degMax = 6, degMin = 1 } = {}) {
|
|
90
|
-
const oc = getKernel().oc;
|
|
91
|
-
const r = gcWithScope();
|
|
92
|
-
const pnts = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
|
|
93
|
-
points.forEach((point, index) => {
|
|
94
|
-
pnts.SetValue(index + 1, r(toOcPnt(point)));
|
|
95
|
-
});
|
|
96
|
-
let splineBuilder;
|
|
97
|
-
if (smoothing) {
|
|
98
|
-
splineBuilder = r(
|
|
99
|
-
new oc.GeomAPI_PointsToBSpline_5(
|
|
100
|
-
pnts,
|
|
101
|
-
smoothing[0],
|
|
102
|
-
smoothing[1],
|
|
103
|
-
smoothing[2],
|
|
104
|
-
degMax,
|
|
105
|
-
oc.GeomAbs_Shape.GeomAbs_C2,
|
|
106
|
-
tolerance
|
|
107
|
-
)
|
|
108
|
-
);
|
|
109
|
-
} else {
|
|
110
|
-
splineBuilder = r(
|
|
111
|
-
new oc.GeomAPI_PointsToBSpline_2(
|
|
112
|
-
pnts,
|
|
113
|
-
degMin,
|
|
114
|
-
degMax,
|
|
115
|
-
oc.GeomAbs_Shape.GeomAbs_C2,
|
|
116
|
-
tolerance
|
|
117
|
-
)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
if (!splineBuilder.IsDone()) {
|
|
121
|
-
return err(occtError("BSPLINE_FAILED", "B-spline approximation failed"));
|
|
122
|
-
}
|
|
123
|
-
const splineGeom = r(splineBuilder.Curve());
|
|
124
|
-
const curve = r(new oc.Handle_Geom_Curve_2(splineGeom.get()));
|
|
125
|
-
return ok(createEdge(new oc.BRepBuilderAPI_MakeEdge_24(curve).Edge()));
|
|
126
|
-
}
|
|
127
|
-
function makeBezierCurve(points) {
|
|
128
|
-
if (points.length < 2) {
|
|
129
|
-
return err(
|
|
130
|
-
validationError(
|
|
131
|
-
"BEZIER_MIN_POINTS",
|
|
132
|
-
`Need at least 2 points for a Bezier curve, got ${points.length}`,
|
|
133
|
-
void 0,
|
|
134
|
-
{
|
|
135
|
-
pointCount: points.length
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
const oc = getKernel().oc;
|
|
141
|
-
const r = gcWithScope();
|
|
142
|
-
const arrayOfPoints = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
|
|
143
|
-
points.forEach((p, i) => {
|
|
144
|
-
arrayOfPoints.SetValue(i + 1, r(toOcPnt(p)));
|
|
145
|
-
});
|
|
146
|
-
const bezCurve = new oc.Geom_BezierCurve_1(arrayOfPoints);
|
|
147
|
-
const curve = r(new oc.Handle_Geom_Curve_2(bezCurve));
|
|
148
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
149
|
-
return ok(createEdge(edgeMaker.Edge()));
|
|
150
|
-
}
|
|
151
|
-
function makeTangentArc(startPoint, startTgt, endPoint) {
|
|
152
|
-
const oc = getKernel().oc;
|
|
153
|
-
const r = gcWithScope();
|
|
154
|
-
const circleGeom = r(
|
|
155
|
-
new oc.GC_MakeArcOfCircle_5(
|
|
156
|
-
r(toOcPnt(startPoint)),
|
|
157
|
-
r(toOcVec(startTgt)),
|
|
158
|
-
r(toOcPnt(endPoint))
|
|
159
|
-
).Value()
|
|
160
|
-
);
|
|
161
|
-
const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
|
|
162
|
-
const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
|
|
163
|
-
return createEdge(edgeMaker.Edge());
|
|
164
|
-
}
|
|
165
|
-
function assembleWire(listOfEdges) {
|
|
166
|
-
const oc = getKernel().oc;
|
|
167
|
-
const r = gcWithScope();
|
|
168
|
-
const wireBuilder = r(new oc.BRepBuilderAPI_MakeWire_1());
|
|
169
|
-
listOfEdges.forEach((e) => {
|
|
170
|
-
if (isEdge(e)) {
|
|
171
|
-
wireBuilder.Add_1(e.wrapped);
|
|
172
|
-
}
|
|
173
|
-
if (isWire(e)) {
|
|
174
|
-
wireBuilder.Add_2(e.wrapped);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
const progress = r(new oc.Message_ProgressRange_1());
|
|
178
|
-
wireBuilder.Build(progress);
|
|
179
|
-
const res = wireBuilder.Error();
|
|
180
|
-
if (res !== oc.BRepBuilderAPI_WireError.BRepBuilderAPI_WireDone) {
|
|
181
|
-
const errorNames = /* @__PURE__ */ new Map([
|
|
182
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_EmptyWire, "empty wire"],
|
|
183
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_NonManifoldWire, "non manifold wire"],
|
|
184
|
-
[oc.BRepBuilderAPI_WireError.BRepBuilderAPI_DisconnectedWire, "disconnected wire"]
|
|
185
|
-
]);
|
|
186
|
-
return err(
|
|
187
|
-
occtError(
|
|
188
|
-
"WIRE_BUILD_FAILED",
|
|
189
|
-
`Failed to build the wire, ${errorNames.get(res) || "unknown error"}`
|
|
190
|
-
)
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
return ok(createWire(wireBuilder.Wire()));
|
|
194
|
-
}
|
|
195
|
-
function makeFace(wire, holes) {
|
|
196
|
-
const oc = getKernel().oc;
|
|
197
|
-
const faceBuilder = new oc.BRepBuilderAPI_MakeFace_15(wire.wrapped, false);
|
|
198
|
-
holes?.forEach((hole) => {
|
|
199
|
-
faceBuilder.Add(hole.wrapped);
|
|
200
|
-
});
|
|
201
|
-
if (!faceBuilder.IsDone()) {
|
|
202
|
-
faceBuilder.delete();
|
|
203
|
-
return err(
|
|
204
|
-
occtError("FACE_BUILD_FAILED", "Failed to build the face. Your wire might be non planar.")
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
const face = faceBuilder.Face();
|
|
208
|
-
faceBuilder.delete();
|
|
209
|
-
return ok(createFace(face));
|
|
210
|
-
}
|
|
211
|
-
function fill(face) {
|
|
212
|
-
const outer = outerWire(face);
|
|
213
|
-
return makeFace(outer);
|
|
214
|
-
}
|
|
215
|
-
function makeNewFaceWithinFace(originFace, wire) {
|
|
216
|
-
const oc = getKernel().oc;
|
|
217
|
-
const [r, gc] = localGC();
|
|
218
|
-
const surface = r(oc.BRep_Tool.Surface_2(originFace.wrapped));
|
|
219
|
-
const faceBuilder = r(new oc.BRepBuilderAPI_MakeFace_21(surface, wire.wrapped, true));
|
|
220
|
-
const face = faceBuilder.Face();
|
|
221
|
-
gc();
|
|
222
|
-
return createFace(face);
|
|
223
|
-
}
|
|
224
|
-
function makeNonPlanarFace(wire) {
|
|
225
|
-
const oc = getKernel().oc;
|
|
226
|
-
const [r, gc] = localGC();
|
|
227
|
-
const faceBuilder = r(
|
|
228
|
-
new oc.BRepOffsetAPI_MakeFilling(3, 15, 2, false, 1e-5, 1e-4, 0.01, 0.1, 8, 9)
|
|
229
|
-
);
|
|
230
|
-
getEdges(wire).forEach((edge) => {
|
|
231
|
-
faceBuilder.Add_1(
|
|
232
|
-
edge.wrapped,
|
|
233
|
-
oc.GeomAbs_Shape.GeomAbs_C0,
|
|
234
|
-
true
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
const progress = r(new oc.Message_ProgressRange_1());
|
|
238
|
-
faceBuilder.Build(progress);
|
|
239
|
-
return andThen(cast(faceBuilder.Shape()), (newFace) => {
|
|
240
|
-
gc();
|
|
241
|
-
if (!isFace(newFace)) {
|
|
242
|
-
return err(occtError("FACE_BUILD_FAILED", "Failed to create a face"));
|
|
243
|
-
}
|
|
244
|
-
return ok(newFace);
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
function addHolesInFace(face, holes) {
|
|
248
|
-
const oc = getKernel().oc;
|
|
249
|
-
const [r, gc] = localGC();
|
|
250
|
-
const faceMaker = r(new oc.BRepBuilderAPI_MakeFace_2(face.wrapped));
|
|
251
|
-
holes.forEach((wire) => {
|
|
252
|
-
faceMaker.Add(wire.wrapped);
|
|
253
|
-
});
|
|
254
|
-
const builtFace = r(faceMaker.Face());
|
|
255
|
-
const fixer = r(new oc.ShapeFix_Face_2(builtFace));
|
|
256
|
-
fixer.FixOrientation_1();
|
|
257
|
-
const newFace = fixer.Face();
|
|
258
|
-
gc();
|
|
259
|
-
return createFace(newFace);
|
|
260
|
-
}
|
|
261
|
-
function makePolygon(points) {
|
|
262
|
-
if (points.length < 3)
|
|
263
|
-
return err(
|
|
264
|
-
validationError("POLYGON_MIN_POINTS", "You need at least 3 points to make a polygon")
|
|
265
|
-
);
|
|
266
|
-
const edges = zip([points, [...points.slice(1), points[0]]]).map(
|
|
267
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- zip returns untyped pairs
|
|
268
|
-
([p1, p2]) => makeLine(p1, p2)
|
|
269
|
-
);
|
|
270
|
-
return andThen(assembleWire(edges), (wire) => makeFace(wire));
|
|
271
|
-
}
|
|
272
|
-
export {
|
|
273
|
-
makeLine as a,
|
|
274
|
-
assembleWire as b,
|
|
275
|
-
makeHelix as c,
|
|
276
|
-
makeThreePointArc as d,
|
|
277
|
-
makeTangentArc as e,
|
|
278
|
-
makeEllipseArc as f,
|
|
279
|
-
makeBezierCurve as g,
|
|
280
|
-
addHolesInFace as h,
|
|
281
|
-
makeCircle as i,
|
|
282
|
-
makeEllipse as j,
|
|
283
|
-
makeBSplineApproximation as k,
|
|
284
|
-
makeNewFaceWithinFace as l,
|
|
285
|
-
makeFace as m,
|
|
286
|
-
makeNonPlanarFace as n,
|
|
287
|
-
makePolygon as o,
|
|
288
|
-
fill as p,
|
|
289
|
-
zip as z
|
|
290
|
-
};
|