brepjs 18.5.3 → 18.6.1
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/blueprints/blueprintOffset.d.ts.map +1 -1
- package/dist/2d/blueprints/intersectionSegments.d.ts.map +1 -1
- package/dist/2d/blueprints/segmentAssembly.d.ts.map +1 -1
- package/dist/2d/lib/curve2D.d.ts.map +1 -1
- package/dist/2d/lib/customCorners.d.ts.map +1 -1
- package/dist/2d/lib/stitching.d.ts.map +1 -1
- package/dist/2d/lib/svgPath.d.ts.map +1 -1
- package/dist/2d.cjs +6 -6
- package/dist/2d.js +6 -6
- package/dist/{blueprint-BKo2Z5P_.cjs → blueprint-C5LxqHCa.cjs} +16 -15
- package/dist/{blueprint-DXNeal2M.js → blueprint-CBairprN.js} +16 -15
- package/dist/{blueprintFns-DLmNAtH4.cjs → blueprintFns-CwbDuLxf.cjs} +3 -3
- package/dist/{blueprintFns-DwKTTALX.js → blueprintFns-D8ST0Cf4.js} +3 -3
- package/dist/{boolean2D-C8DlibdA.js → boolean2D-A5u9tJYl.js} +26 -24
- package/dist/{boolean2D-CvirfeVA.cjs → boolean2D-DxZ3Kwlq.cjs} +26 -24
- package/dist/{booleanFns-BTmOI2IT.cjs → booleanFns-DWQMtFDN.cjs} +9 -9
- package/dist/{booleanFns-BvRK1Oi2.js → booleanFns-DjZF4MJ5.js} +9 -9
- package/dist/brepjs.cjs +51 -41
- package/dist/brepjs.js +51 -41
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core.cjs +6 -6
- package/dist/core.js +6 -6
- package/dist/{cornerFinder-D3eGMa24.cjs → cornerFinder-B2CpcVV9.cjs} +3 -3
- package/dist/{cornerFinder-BwE0co98.js → cornerFinder-DGvOt2ab.js} +3 -3
- package/dist/{curveFns-CkhBj1Ot.cjs → curveFns-B8KJKr8-.cjs} +2 -2
- package/dist/{curveFns-DOtvwQN1.js → curveFns-DZYE3BGO.js} +2 -2
- package/dist/{drawFns-ChZrX59C.js → drawFns-Bl865kUL.js} +21 -20
- package/dist/{drawFns-CFqr2BFZ.cjs → drawFns-h8gJBx-H.cjs} +21 -20
- package/dist/{errors-DboJwVCf.js → errors-0fYW_YnO.js} +2 -1
- package/dist/{errors-CXRNVCec.cjs → errors-Dv6pfNct.cjs} +2 -1
- package/dist/{extrudeFns-sFXnQ0GR.cjs → extrudeFns-BlJKAnW8.cjs} +3 -3
- package/dist/{extrudeFns-9m-r4epC.js → extrudeFns-O2s-SFf-.js} +3 -3
- package/dist/{faceFns-9yuvhlzD.cjs → faceFns-B1H43mZ_.cjs} +3 -3
- package/dist/{faceFns-CoVqCTcx.js → faceFns-acz86gqR.js} +3 -3
- package/dist/{helpers-BPqm4AyF.cjs → helpers-C3smxDtp.cjs} +8 -8
- package/dist/{helpers-thCB-5I7.js → helpers-DL1f3xp0.js} +8 -8
- package/dist/{historyFns-DlyOFijD.js → historyFns-CD9qXw5j.js} +6 -6
- package/dist/{historyFns-C8RKuoZR.cjs → historyFns-DBdWeo7Y.cjs} +6 -6
- package/dist/{importFns-C9KoV6Q2.cjs → importFns-5tcN3-fK.cjs} +11 -19
- package/dist/{importFns-TsXZed73.js → importFns-B1p3FiGS.js} +11 -19
- package/dist/io/gltfExportFns.d.ts.map +1 -1
- package/dist/io/objExportFns.d.ts.map +1 -1
- package/dist/io.cjs +2 -2
- package/dist/io.js +2 -2
- package/dist/kernel/brepkit/booleanOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/constructionOps.d.ts +3 -2
- package/dist/kernel/brepkit/constructionOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/evolutionOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/geometryOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/helpers.d.ts.map +1 -1
- package/dist/kernel/brepkit/internalOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/ioOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/kernel2dOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/measureOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/meshOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/modifierOps.d.ts.map +1 -1
- package/dist/kernel/brepkit/topologyOps.d.ts.map +1 -1
- package/dist/kernel/occt/advancedOps.d.ts.map +1 -1
- package/dist/kernel/occt/booleanOps.d.ts.map +1 -1
- package/dist/kernel/occt/extendedConstructorOps.d.ts.map +1 -1
- package/dist/kernel/occt/kernel2dOps.d.ts.map +1 -1
- package/dist/kernel/occtWasm/adapterShims.d.ts +5 -0
- package/dist/kernel/occtWasm/adapterShims.d.ts.map +1 -0
- package/dist/kernel/occtWasm/booleanOps.d.ts +12 -0
- package/dist/kernel/occtWasm/booleanOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/constructionOps.d.ts +37 -0
- package/dist/kernel/occtWasm/constructionOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/curveOps.d.ts +24 -0
- package/dist/kernel/occtWasm/curveOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/evolutionOps.d.ts +18 -0
- package/dist/kernel/occtWasm/evolutionOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/helpers.d.ts +32 -0
- package/dist/kernel/occtWasm/helpers.d.ts.map +1 -0
- package/dist/kernel/occtWasm/hullOps.d.ts +13 -0
- package/dist/kernel/occtWasm/hullOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/ioOps.d.ts +53 -0
- package/dist/kernel/occtWasm/ioOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/kernel2dOps.d.ts +91 -0
- package/dist/kernel/occtWasm/kernel2dOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/measureOps.d.ts +32 -0
- package/dist/kernel/occtWasm/measureOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/meshOps.d.ts +7 -0
- package/dist/kernel/occtWasm/meshOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/modifierOps.d.ts +15 -0
- package/dist/kernel/occtWasm/modifierOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/occtWasmAdapter.cjs +1 -1
- package/dist/kernel/occtWasm/occtWasmAdapter.d.ts +30 -30
- package/dist/kernel/occtWasm/occtWasmAdapter.d.ts.map +1 -1
- package/dist/kernel/occtWasm/occtWasmAdapter.js +1 -1
- package/dist/kernel/occtWasm/primitiveOps.d.ts +11 -0
- package/dist/kernel/occtWasm/primitiveOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/repairOps.d.ts +11 -0
- package/dist/kernel/occtWasm/repairOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/surfaceOps.d.ts +29 -0
- package/dist/kernel/occtWasm/surfaceOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/sweepOps.d.ts +39 -0
- package/dist/kernel/occtWasm/sweepOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/topologyOps.d.ts +15 -0
- package/dist/kernel/occtWasm/topologyOps.d.ts.map +1 -0
- package/dist/kernel/occtWasm/transformOps.d.ts +28 -0
- package/dist/kernel/occtWasm/transformOps.d.ts.map +1 -0
- package/dist/{measureFns-DXLTUwTN.cjs → measureFns-CHmy_Inq.cjs} +3 -3
- package/dist/{measureFns-CkhDfqzu.js → measureFns-CJi8erDL.js} +3 -3
- package/dist/measurement/interferenceFns.d.ts.map +1 -1
- package/dist/measurement.cjs +1 -1
- package/dist/measurement.js +1 -1
- package/dist/{meshFns-CAUI3r1d.js → meshFns-BkY1RAoC.js} +3 -3
- package/dist/{meshFns-DzGr_wxJ.cjs → meshFns-t2lR4BDS.cjs} +3 -3
- package/dist/occtWasmAdapter--TZGP9DX.js +4606 -0
- package/dist/occtWasmAdapter-C2VW-uYg.cjs +4719 -0
- package/dist/operations/compoundOpsFns.d.ts.map +1 -1
- package/dist/operations.cjs +2 -2
- package/dist/operations.js +2 -2
- package/dist/{planeOps-sTrM3dcQ.js → planeOps-4i2qEraD.js} +4 -4
- package/dist/{planeOps-BJOIbn4K.cjs → planeOps-CH4ruLuj.cjs} +4 -4
- package/dist/{primitiveFns-ClBrBsj6.cjs → primitiveFns-DwhN--zB.cjs} +7 -7
- package/dist/{primitiveFns-DEIibX8G.js → primitiveFns-Emvge_71.js} +7 -7
- package/dist/query.cjs +2 -2
- package/dist/query.js +2 -2
- package/dist/result.cjs +1 -1
- package/dist/result.js +1 -1
- package/dist/{shapeFns-c2eak2sT.cjs → shapeFns-CObBAJoQ.cjs} +4 -4
- package/dist/{shapeFns-Cwt0CMNm.js → shapeFns-DThjHtJI.js} +4 -4
- package/dist/shapeRef.cjs +1 -1
- package/dist/shapeRef.js +1 -1
- package/dist/{shapeRefFns-D-JLpn7D.cjs → shapeRefFns-I0MHjRAq.cjs} +5 -4
- package/dist/{shapeRefFns-Cx61pDhQ.js → shapeRefFns-WMhIFuGW.js} +5 -4
- package/dist/{shapeTypes-Xnk670Cd.cjs → shapeTypes-8vB31RfA.cjs} +290 -418
- package/dist/{shapeTypes-uibK1QHY.js → shapeTypes-AyL8vv_O.js} +290 -418
- package/dist/sketching.cjs +2 -2
- package/dist/sketching.js +2 -2
- package/dist/{solidBuilders-BnTtq4g1.js → solidBuilders-C7Xp_ikW.js} +3 -3
- package/dist/{solidBuilders-23LDxzEn.cjs → solidBuilders-Djwgx2mj.cjs} +3 -3
- package/dist/{surfaceBuilders-CUn-cmah.cjs → surfaceBuilders-BEnsewN9.cjs} +3 -3
- package/dist/{surfaceBuilders-DeNnAJb3.js → surfaceBuilders-Con0IpLf.js} +3 -3
- package/dist/topology/minkowskiFns.d.ts.map +1 -1
- package/dist/topology/shapeRef/shapeRefFns.d.ts.map +1 -1
- package/dist/topology/wrapperFns.d.ts.map +1 -1
- package/dist/topology.cjs +6 -6
- package/dist/topology.js +6 -6
- package/dist/utils/vec3.d.ts +32 -0
- package/dist/utils/vec3.d.ts.map +1 -0
- package/dist/vec3-BRj3eI54.js +25 -0
- package/dist/vec3-S4Oh59IX.cjs +36 -0
- package/dist/vectors.cjs +4 -4
- package/dist/vectors.js +4 -4
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +1 -1
- package/package.json +2 -2
- package/dist/occtWasmAdapter-CuZRRioz.cjs +0 -3947
- package/dist/occtWasmAdapter-DIhUXubY.js +0 -3834
- /package/dist/{arrayAccess-tCIbjLs5.js → arrayAccess-2G0pRoaC.js} +0 -0
- /package/dist/{arrayAccess-DsnQpdSD.cjs → arrayAccess-Br-m2PP7.cjs} +0 -0
- /package/dist/{constants-csSEYddm.js → constants-Ci5CA3aZ.js} +0 -0
- /package/dist/{constants-BNP_xnBN.cjs → constants-DTorLmes.cjs} +0 -0
- /package/dist/{types--GD-LVc6.js → types-BIdk_GJY.js} +0 -0
- /package/dist/{types-gLi9wL0N.cjs → types-CDkxah-M.cjs} +0 -0
- /package/dist/{vecOps-CODplJp3.cjs → vecOps-D7xplSx8.cjs} +0 -0
- /package/dist/{vecOps-B-PCHgyB.js → vecOps-DVROrqTV.js} +0 -0
- /package/dist/{workerHandler-Dm0_0F8Z.js → workerHandler-BndMJVx6.js} +0 -0
- /package/dist/{workerHandler-C-3cFcsQ.cjs → workerHandler-sCf818XJ.cjs} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as wasmIndex, t as vec3At } from "./vec3-BRj3eI54.js";
|
|
2
|
+
import { _ as serializeCurve2d$2, a as curveTypeName, c as intersectCurves2dFn, d as makeEllipse2d$2, f as makeLine2d$2, g as scaleCurve2d$2, h as rotateCurve2d$2, i as curveBounds, l as makeBezier2d$2, m as mirrorAtPoint, n as addCurveToBBox, o as deserializeCurve2d$2, p as mirrorAcrossAxis, r as createBBox2d, s as evaluateCurve2d$2, u as makeCircle2d$2, v as tangentCurve2d, y as translateCurve2d$2 } from "./occtWasmAdapter--TZGP9DX.js";
|
|
3
|
+
import { A as ok, b as err } from "./errors-0fYW_YnO.js";
|
|
3
4
|
//#region src/kernel/kernel2dTypes.ts
|
|
4
5
|
/** Check if the kernel supports 2D geometry operations. */
|
|
5
6
|
function supportsKernel2D(kernel) {
|
|
@@ -812,7 +813,7 @@ function fuseAllNative(oc, shapes, options = {}) {
|
|
|
812
813
|
function fuseAllPairwiseRange(oc, shapes, start, end, options) {
|
|
813
814
|
options.signal?.throwIfAborted();
|
|
814
815
|
const count = end - start;
|
|
815
|
-
if (count === 1) return shapes
|
|
816
|
+
if (count === 1) return wasmIndex(shapes, start);
|
|
816
817
|
if (count === 2) return fuse$1(oc, shapes[start], shapes[start + 1], {
|
|
817
818
|
...options,
|
|
818
819
|
simplify: false
|
|
@@ -842,7 +843,7 @@ function fuseAllPairwise(oc, shapes, options = {}) {
|
|
|
842
843
|
*/
|
|
843
844
|
function fuseAll$1(oc, shapes, options = {}) {
|
|
844
845
|
if (shapes.length === 0) throw new Error("fuseAll requires at least one shape");
|
|
845
|
-
if (shapes.length === 1) return shapes
|
|
846
|
+
if (shapes.length === 1) return wasmIndex(shapes, 0);
|
|
846
847
|
const { strategy = "native" } = options;
|
|
847
848
|
if (strategy === "pairwise") return fuseAllPairwise(oc, shapes, options);
|
|
848
849
|
return fuseAllNative(oc, shapes, options);
|
|
@@ -2841,7 +2842,7 @@ function makeEllipseArc$1(oc, center, normal, majorRadius, minorRadius, startAng
|
|
|
2841
2842
|
function makeBezierEdge$1(oc, points) {
|
|
2842
2843
|
const arr = new oc.TColgp_Array1OfPnt_2(1, points.length);
|
|
2843
2844
|
for (let i = 0; i < points.length; i++) {
|
|
2844
|
-
const p = points
|
|
2845
|
+
const p = wasmIndex(points, i);
|
|
2845
2846
|
const pnt = new oc.gp_Pnt_3(p[0], p[1], p[2]);
|
|
2846
2847
|
arr.SetValue_1(i + 1, pnt);
|
|
2847
2848
|
pnt.delete();
|
|
@@ -3430,7 +3431,7 @@ function createAffinityGTrsf2d$1(ox, oy, dx, dy, ratio) {
|
|
|
3430
3431
|
0,
|
|
3431
3432
|
1
|
|
3432
3433
|
];
|
|
3433
|
-
return _gtrsf$1(m, ox - m
|
|
3434
|
+
return _gtrsf$1(m, ox - wasmIndex(m, 0) * ox - wasmIndex(m, 1) * oy, oy - wasmIndex(m, 3) * ox - wasmIndex(m, 4) * oy);
|
|
3434
3435
|
}
|
|
3435
3436
|
function createTranslationGTrsf2d$1(dx, dy) {
|
|
3436
3437
|
return _gtrsf$1([
|
|
@@ -3461,7 +3462,7 @@ function createMirrorGTrsf2d$1(cx, cy, mode, ox, oy, dx, dy) {
|
|
|
3461
3462
|
1
|
|
3462
3463
|
];
|
|
3463
3464
|
const apx = ox ?? cx, apy = oy ?? cy;
|
|
3464
|
-
return _gtrsf$1(m, apx - m
|
|
3465
|
+
return _gtrsf$1(m, apx - wasmIndex(m, 0) * apx - wasmIndex(m, 1) * apy, apy - wasmIndex(m, 3) * apx - wasmIndex(m, 4) * apy);
|
|
3465
3466
|
}
|
|
3466
3467
|
return _gtrsf$1([
|
|
3467
3468
|
-1,
|
|
@@ -3508,21 +3509,23 @@ function setGTrsf2dTranslationPart$1(gtrsf, dx, dy) {
|
|
|
3508
3509
|
}
|
|
3509
3510
|
function multiplyGTrsf2d$1(base, other) {
|
|
3510
3511
|
const a = base.m, b = other.m;
|
|
3512
|
+
const ai = (i) => wasmIndex(a, i);
|
|
3513
|
+
const bi = (i) => wasmIndex(b, i);
|
|
3511
3514
|
base.m = [
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3515
|
+
ai(0) * bi(0) + ai(1) * bi(3) + ai(2) * bi(6),
|
|
3516
|
+
ai(0) * bi(1) + ai(1) * bi(4) + ai(2) * bi(7),
|
|
3517
|
+
ai(0) * bi(2) + ai(1) * bi(5) + ai(2) * bi(8),
|
|
3518
|
+
ai(3) * bi(0) + ai(4) * bi(3) + ai(5) * bi(6),
|
|
3519
|
+
ai(3) * bi(1) + ai(4) * bi(4) + ai(5) * bi(7),
|
|
3520
|
+
ai(3) * bi(2) + ai(4) * bi(5) + ai(5) * bi(8),
|
|
3521
|
+
ai(6) * bi(0) + ai(7) * bi(3) + ai(8) * bi(6),
|
|
3522
|
+
ai(6) * bi(1) + ai(7) * bi(4) + ai(8) * bi(7),
|
|
3523
|
+
ai(6) * bi(2) + ai(7) * bi(5) + ai(8) * bi(8)
|
|
3521
3524
|
];
|
|
3522
3525
|
const oldTx = base.tx, oldTy = base.ty;
|
|
3523
3526
|
const otx = Number(other.tx) || 0, oty = Number(other.ty) || 0;
|
|
3524
|
-
base.tx =
|
|
3525
|
-
base.ty =
|
|
3527
|
+
base.tx = ai(0) * otx + ai(1) * oty + oldTx;
|
|
3528
|
+
base.ty = ai(3) * otx + ai(4) * oty + oldTy;
|
|
3526
3529
|
}
|
|
3527
3530
|
function transformCurve2dGeneral$1(curve, gtrsf) {
|
|
3528
3531
|
const c = c2d$1(curve);
|
|
@@ -3538,13 +3541,14 @@ function transformCurve2dGeneral$1(curve, gtrsf) {
|
|
|
3538
3541
|
1
|
|
3539
3542
|
];
|
|
3540
3543
|
const tx = Number(gtrsf.tx) || 0, ty = Number(gtrsf.ty) || 0;
|
|
3541
|
-
|
|
3544
|
+
const m0 = wasmIndex(m, 0), m1 = wasmIndex(m, 1), m3 = wasmIndex(m, 3), m4 = wasmIndex(m, 4);
|
|
3545
|
+
if (Math.abs(m0 - 1) < 1e-12 && Math.abs(m4 - 1) < 1e-12 && Math.abs(m1) < 1e-12 && Math.abs(m3) < 1e-12) return translateCurve2d$2(c, tx, ty);
|
|
3542
3546
|
const bounds = curveBounds(c);
|
|
3543
3547
|
const N = 20;
|
|
3544
3548
|
const pts = [];
|
|
3545
3549
|
for (let i = 0; i <= N; i++) {
|
|
3546
3550
|
const [px, py] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / N);
|
|
3547
|
-
pts.push([
|
|
3551
|
+
pts.push([m0 * px + m1 * py + tx, m3 * px + m4 * py + ty]);
|
|
3548
3552
|
}
|
|
3549
3553
|
return makeBezier2d$2(pts);
|
|
3550
3554
|
}
|
|
@@ -3677,8 +3681,8 @@ function approximateCurve2dAsBSpline$1(curve, tol, cont, maxSeg) {
|
|
|
3677
3681
|
maxErr = 0;
|
|
3678
3682
|
for (let i = 0; i < curN; i++) {
|
|
3679
3683
|
const [ex, ey] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * (i + .5) / curN);
|
|
3680
|
-
const p0 = poles
|
|
3681
|
-
const p1 = poles
|
|
3684
|
+
const p0 = wasmIndex(poles, i);
|
|
3685
|
+
const p1 = wasmIndex(poles, i + 1);
|
|
3682
3686
|
const mx = (p0[0] + p1[0]) / 2;
|
|
3683
3687
|
const my = (p0[1] + p1[1]) / 2;
|
|
3684
3688
|
const err = Math.sqrt((ex - mx) ** 2 + (ey - my) ** 2);
|
|
@@ -3704,8 +3708,8 @@ function decomposeBSpline2dToBeziers$1(curve) {
|
|
|
3704
3708
|
];
|
|
3705
3709
|
const result = [];
|
|
3706
3710
|
for (let i = 0; i < breakpoints.length - 1; i++) {
|
|
3707
|
-
const t0 = breakpoints
|
|
3708
|
-
const t1 = breakpoints
|
|
3711
|
+
const t0 = wasmIndex(breakpoints, i);
|
|
3712
|
+
const t1 = wasmIndex(breakpoints, i + 1);
|
|
3709
3713
|
const span = t1 - t0;
|
|
3710
3714
|
if (span < 1e-15) continue;
|
|
3711
3715
|
const p0 = evaluateCurve2d$2(c, t0);
|
|
@@ -3852,7 +3856,7 @@ function interpolatePoints3d(oc, points) {
|
|
|
3852
3856
|
const pnts = new oc.TColgp_Array1OfPnt_2(1, points.length);
|
|
3853
3857
|
const reusePnt = new oc.gp_Pnt_1();
|
|
3854
3858
|
for (let i = 0; i < points.length; i++) {
|
|
3855
|
-
const p = points
|
|
3859
|
+
const p = wasmIndex(points, i);
|
|
3856
3860
|
reusePnt.SetCoord_2(p[0], p[1], p[2]);
|
|
3857
3861
|
pnts.SetValue_1(i + 1, reusePnt);
|
|
3858
3862
|
}
|
|
@@ -3918,7 +3922,7 @@ function liftCurve2dToPlane$1(oc, curve, planeOrigin, planeZ, planeX) {
|
|
|
3918
3922
|
}
|
|
3919
3923
|
if (c.__bk2d === "bezier" || c.__bk2d === "bspline") {
|
|
3920
3924
|
const pts3d = c.poles.map(([u, v]) => lift(u, v));
|
|
3921
|
-
if (pts3d.length === 2) return makeLineEdge3d(oc, pts3d
|
|
3925
|
+
if (pts3d.length === 2) return makeLineEdge3d(oc, wasmIndex(pts3d, 0), wasmIndex(pts3d, 1));
|
|
3922
3926
|
return interpolatePoints3d(oc, pts3d);
|
|
3923
3927
|
}
|
|
3924
3928
|
const bounds = curveBounds(c);
|
|
@@ -4461,7 +4465,7 @@ function makeFaceOnSurface$1(oc, surfaceOrFace, wire) {
|
|
|
4461
4465
|
function bsplineSurface$1(oc, points, rows, cols) {
|
|
4462
4466
|
const arr = new oc.TColgp_Array2OfPnt_2(1, rows, 1, cols);
|
|
4463
4467
|
for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) {
|
|
4464
|
-
const pt = points
|
|
4468
|
+
const pt = wasmIndex(points, r * cols + c);
|
|
4465
4469
|
const pnt = new oc.gp_Pnt_3(pt[0], pt[1], pt[2]);
|
|
4466
4470
|
arr.SetValue_1(r + 1, c + 1, pnt);
|
|
4467
4471
|
pnt.delete();
|
|
@@ -4483,10 +4487,10 @@ function triangulatedSurface$1(oc, points, rows, cols) {
|
|
|
4483
4487
|
const i10 = (r + 1) * cols + c;
|
|
4484
4488
|
const i01 = r * cols + (c + 1);
|
|
4485
4489
|
const i11 = (r + 1) * cols + (c + 1);
|
|
4486
|
-
const p00 = points
|
|
4487
|
-
const p10 = points
|
|
4488
|
-
const p01 = points
|
|
4489
|
-
const p11 = points
|
|
4490
|
+
const p00 = wasmIndex(points, i00);
|
|
4491
|
+
const p10 = wasmIndex(points, i10);
|
|
4492
|
+
const p01 = wasmIndex(points, i01);
|
|
4493
|
+
const p11 = wasmIndex(points, i11);
|
|
4490
4494
|
const face1 = makeTriFace(oc, p00, p10, p01);
|
|
4491
4495
|
sewing.Add(face1);
|
|
4492
4496
|
const face2 = makeTriFace(oc, p10, p11, p01);
|
|
@@ -6161,18 +6165,19 @@ function scaleMatrix(center, factor) {
|
|
|
6161
6165
|
}
|
|
6162
6166
|
/** Build a row-major 4x4 matrix from a 3x3 linear part + translation. */
|
|
6163
6167
|
function affineMatrix(linear, translation) {
|
|
6168
|
+
const li = (i) => wasmIndex(linear, i);
|
|
6164
6169
|
return [
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6170
|
+
li(0),
|
|
6171
|
+
li(1),
|
|
6172
|
+
li(2),
|
|
6168
6173
|
translation[0],
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6174
|
+
li(3),
|
|
6175
|
+
li(4),
|
|
6176
|
+
li(5),
|
|
6172
6177
|
translation[1],
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6178
|
+
li(6),
|
|
6179
|
+
li(7),
|
|
6180
|
+
li(8),
|
|
6176
6181
|
translation[2],
|
|
6177
6182
|
0,
|
|
6178
6183
|
0,
|
|
@@ -6307,13 +6312,13 @@ function iterShapes(bk, shape, type) {
|
|
|
6307
6312
|
for (const eid of edgeIds) {
|
|
6308
6313
|
const verts = bk.getEdgeVertices(eid);
|
|
6309
6314
|
const coords = [[
|
|
6310
|
-
verts
|
|
6311
|
-
verts
|
|
6312
|
-
verts
|
|
6315
|
+
wasmIndex(verts, 0),
|
|
6316
|
+
wasmIndex(verts, 1),
|
|
6317
|
+
wasmIndex(verts, 2)
|
|
6313
6318
|
], [
|
|
6314
|
-
verts
|
|
6315
|
-
verts
|
|
6316
|
-
verts
|
|
6319
|
+
wasmIndex(verts, 3),
|
|
6320
|
+
wasmIndex(verts, 4),
|
|
6321
|
+
wasmIndex(verts, 5)
|
|
6317
6322
|
]];
|
|
6318
6323
|
for (const [x, y, z] of coords) {
|
|
6319
6324
|
const key = `${x},${y},${z}`;
|
|
@@ -6330,8 +6335,8 @@ function iterShapes(bk, shape, type) {
|
|
|
6330
6335
|
if (type === "edge") return [shape];
|
|
6331
6336
|
if (type === "vertex") {
|
|
6332
6337
|
const verts = bk.getEdgeVertices(h);
|
|
6333
|
-
const v1 = bk.makeVertex(verts
|
|
6334
|
-
const v2 = bk.makeVertex(verts
|
|
6338
|
+
const v1 = bk.makeVertex(wasmIndex(verts, 0), wasmIndex(verts, 1), wasmIndex(verts, 2));
|
|
6339
|
+
const v2 = bk.makeVertex(wasmIndex(verts, 3), wasmIndex(verts, 4), wasmIndex(verts, 5));
|
|
6335
6340
|
return [vertexHandle(v1), vertexHandle(v2)];
|
|
6336
6341
|
}
|
|
6337
6342
|
return [];
|
|
@@ -6398,12 +6403,7 @@ function sew(bk, shapes, tolerance) {
|
|
|
6398
6403
|
//#endregion
|
|
6399
6404
|
//#region src/kernel/brepkit/geometryOps.ts
|
|
6400
6405
|
function vertexPosition(bk, vertex) {
|
|
6401
|
-
|
|
6402
|
-
return [
|
|
6403
|
-
pos[0],
|
|
6404
|
-
pos[1],
|
|
6405
|
-
pos[2]
|
|
6406
|
-
];
|
|
6406
|
+
return vec3At(bk.getVertexPosition(unwrap(vertex, "vertex")));
|
|
6407
6407
|
}
|
|
6408
6408
|
function surfaceType(bk, face) {
|
|
6409
6409
|
return bk.getSurfaceType(unwrap(face, "face"));
|
|
@@ -6411,47 +6411,32 @@ function surfaceType(bk, face) {
|
|
|
6411
6411
|
function uvBounds(bk, face) {
|
|
6412
6412
|
const domain = bk.getSurfaceDomain(unwrap(face, "face"));
|
|
6413
6413
|
return {
|
|
6414
|
-
uMin: domain
|
|
6415
|
-
uMax: domain
|
|
6416
|
-
vMin: domain
|
|
6417
|
-
vMax: domain
|
|
6414
|
+
uMin: wasmIndex(domain, 0),
|
|
6415
|
+
uMax: wasmIndex(domain, 1),
|
|
6416
|
+
vMin: wasmIndex(domain, 2),
|
|
6417
|
+
vMax: wasmIndex(domain, 3)
|
|
6418
6418
|
};
|
|
6419
6419
|
}
|
|
6420
6420
|
function outerWire(bk, face) {
|
|
6421
6421
|
return wireHandle(bk.getFaceOuterWire(unwrap(face, "face")));
|
|
6422
6422
|
}
|
|
6423
6423
|
function surfaceNormal(bk, face, u, v) {
|
|
6424
|
-
|
|
6425
|
-
return [
|
|
6426
|
-
n[0],
|
|
6427
|
-
n[1],
|
|
6428
|
-
n[2]
|
|
6429
|
-
];
|
|
6424
|
+
return vec3At(bk.evaluateSurfaceNormal(unwrap(face, "face"), u, v));
|
|
6430
6425
|
}
|
|
6431
6426
|
function pointOnSurface(bk, face, u, v) {
|
|
6432
|
-
|
|
6433
|
-
return [
|
|
6434
|
-
p[0],
|
|
6435
|
-
p[1],
|
|
6436
|
-
p[2]
|
|
6437
|
-
];
|
|
6427
|
+
return vec3At(bk.evaluateSurface(unwrap(face, "face"), u, v));
|
|
6438
6428
|
}
|
|
6439
6429
|
function uvFromPoint(bk, face, point) {
|
|
6440
6430
|
try {
|
|
6441
6431
|
const result = bk.projectPointOnSurface(unwrap(face, "face"), point[0], point[1], point[2]);
|
|
6442
|
-
return [result
|
|
6432
|
+
return [wasmIndex(result, 0), wasmIndex(result, 1)];
|
|
6443
6433
|
} catch (e) {
|
|
6444
6434
|
console.warn("brepkit: uvFromPoint failed:", e);
|
|
6445
6435
|
return null;
|
|
6446
6436
|
}
|
|
6447
6437
|
}
|
|
6448
6438
|
function projectPointOnFace(bk, face, point) {
|
|
6449
|
-
|
|
6450
|
-
return [
|
|
6451
|
-
result[2],
|
|
6452
|
-
result[3],
|
|
6453
|
-
result[4]
|
|
6454
|
-
];
|
|
6439
|
+
return vec3At(bk.projectPointOnSurface(unwrap(face, "face"), point[0], point[1], point[2]), 2);
|
|
6455
6440
|
}
|
|
6456
6441
|
function curveTangent(bk, shape, param) {
|
|
6457
6442
|
const h = shape;
|
|
@@ -6459,14 +6444,14 @@ function curveTangent(bk, shape, param) {
|
|
|
6459
6444
|
let evalParam = param;
|
|
6460
6445
|
if (h.type === "wire") {
|
|
6461
6446
|
const edgeIds = toArray(bk.getWireEdges(h.id));
|
|
6462
|
-
edgeId = edgeIds
|
|
6447
|
+
edgeId = wasmIndex(edgeIds, edgeIds.length - 1);
|
|
6463
6448
|
let cumulative = 0;
|
|
6464
6449
|
for (const eid of edgeIds) {
|
|
6465
6450
|
const p = bk.getEdgeCurveParameters(eid);
|
|
6466
|
-
const span = p
|
|
6451
|
+
const span = wasmIndex(p, 1) - wasmIndex(p, 0);
|
|
6467
6452
|
if (param <= cumulative + span || eid === edgeId) {
|
|
6468
6453
|
edgeId = eid;
|
|
6469
|
-
evalParam = Math.min(p
|
|
6454
|
+
evalParam = Math.min(wasmIndex(p, 0) + (param - cumulative), wasmIndex(p, 1));
|
|
6470
6455
|
break;
|
|
6471
6456
|
}
|
|
6472
6457
|
cumulative += span;
|
|
@@ -6474,16 +6459,8 @@ function curveTangent(bk, shape, param) {
|
|
|
6474
6459
|
} else edgeId = unwrap(shape, "edge");
|
|
6475
6460
|
const result = bk.evaluateEdgeCurveD1(edgeId, evalParam);
|
|
6476
6461
|
return {
|
|
6477
|
-
point:
|
|
6478
|
-
|
|
6479
|
-
result[1],
|
|
6480
|
-
result[2]
|
|
6481
|
-
],
|
|
6482
|
-
tangent: [
|
|
6483
|
-
result[3],
|
|
6484
|
-
result[4],
|
|
6485
|
-
result[5]
|
|
6486
|
-
]
|
|
6462
|
+
point: vec3At(result, 0),
|
|
6463
|
+
tangent: vec3At(result, 3)
|
|
6487
6464
|
};
|
|
6488
6465
|
}
|
|
6489
6466
|
function curveParameters(bk, shape) {
|
|
@@ -6494,13 +6471,12 @@ function curveParameters(bk, shape) {
|
|
|
6494
6471
|
let total = 0;
|
|
6495
6472
|
for (const eid of edgeIds) {
|
|
6496
6473
|
const p = bk.getEdgeCurveParameters(eid);
|
|
6497
|
-
total += p
|
|
6474
|
+
total += wasmIndex(p, 1) - wasmIndex(p, 0);
|
|
6498
6475
|
}
|
|
6499
6476
|
return [0, total];
|
|
6500
6477
|
}
|
|
6501
|
-
const
|
|
6502
|
-
|
|
6503
|
-
return [params[0], params[1]];
|
|
6478
|
+
const params = bk.getEdgeCurveParameters(unwrap(shape, "edge"));
|
|
6479
|
+
return [wasmIndex(params, 0), wasmIndex(params, 1)];
|
|
6504
6480
|
}
|
|
6505
6481
|
function curvePointAtParam(bk, shape, param) {
|
|
6506
6482
|
const h = shape;
|
|
@@ -6509,55 +6485,28 @@ function curvePointAtParam(bk, shape, param) {
|
|
|
6509
6485
|
let cumulative = 0;
|
|
6510
6486
|
for (const eid of edgeIds) {
|
|
6511
6487
|
const p = bk.getEdgeCurveParameters(eid);
|
|
6512
|
-
const span = p
|
|
6488
|
+
const span = wasmIndex(p, 1) - wasmIndex(p, 0);
|
|
6513
6489
|
if (param <= cumulative + span || eid === edgeIds[edgeIds.length - 1]) {
|
|
6514
|
-
const localParam = p
|
|
6515
|
-
|
|
6516
|
-
return [
|
|
6517
|
-
pt[0],
|
|
6518
|
-
pt[1],
|
|
6519
|
-
pt[2]
|
|
6520
|
-
];
|
|
6490
|
+
const localParam = wasmIndex(p, 0) + (param - cumulative);
|
|
6491
|
+
return vec3At(bk.evaluateEdgeCurve(eid, Math.min(localParam, wasmIndex(p, 1))));
|
|
6521
6492
|
}
|
|
6522
6493
|
cumulative += span;
|
|
6523
6494
|
}
|
|
6524
|
-
|
|
6525
|
-
return [
|
|
6526
|
-
pt[0],
|
|
6527
|
-
pt[1],
|
|
6528
|
-
pt[2]
|
|
6529
|
-
];
|
|
6495
|
+
return vec3At(bk.evaluateEdgeCurve(wasmIndex(edgeIds, 0), param));
|
|
6530
6496
|
}
|
|
6531
|
-
|
|
6532
|
-
const p = bk.evaluateEdgeCurve(edgeId, param);
|
|
6533
|
-
return [
|
|
6534
|
-
p[0],
|
|
6535
|
-
p[1],
|
|
6536
|
-
p[2]
|
|
6537
|
-
];
|
|
6497
|
+
return vec3At(bk.evaluateEdgeCurve(unwrap(shape, "edge"), param));
|
|
6538
6498
|
}
|
|
6539
6499
|
function curveIsClosed(bk, shape) {
|
|
6540
6500
|
const h = shape;
|
|
6541
6501
|
if (h.type === "wire") {
|
|
6542
6502
|
const edgeIds = toArray(bk.getWireEdges(h.id));
|
|
6543
6503
|
if (edgeIds.length === 0) return false;
|
|
6544
|
-
if (edgeIds.length === 1)
|
|
6545
|
-
const verts = bk.getEdgeVertices(edgeIds[0]);
|
|
6546
|
-
return dist3(verts[0], verts[1], verts[2], verts[3], verts[4], verts[5]) < 1e-7;
|
|
6547
|
-
}
|
|
6504
|
+
if (edgeIds.length === 1) return edgeIsClosed(bk.getEdgeVertices(wasmIndex(edgeIds, 0)));
|
|
6548
6505
|
const endpoints = [];
|
|
6549
6506
|
for (const eid of edgeIds) {
|
|
6550
6507
|
const verts = bk.getEdgeVertices(eid);
|
|
6551
|
-
endpoints.push(
|
|
6552
|
-
|
|
6553
|
-
verts[1],
|
|
6554
|
-
verts[2]
|
|
6555
|
-
]);
|
|
6556
|
-
endpoints.push([
|
|
6557
|
-
verts[3],
|
|
6558
|
-
verts[4],
|
|
6559
|
-
verts[5]
|
|
6560
|
-
]);
|
|
6508
|
+
endpoints.push(vec3At(verts, 0));
|
|
6509
|
+
endpoints.push(vec3At(verts, 3));
|
|
6561
6510
|
}
|
|
6562
6511
|
const unmatched = [];
|
|
6563
6512
|
for (const pt of endpoints) {
|
|
@@ -6567,8 +6516,10 @@ function curveIsClosed(bk, shape) {
|
|
|
6567
6516
|
}
|
|
6568
6517
|
return unmatched.length === 0;
|
|
6569
6518
|
}
|
|
6570
|
-
|
|
6571
|
-
|
|
6519
|
+
return edgeIsClosed(bk.getEdgeVertices(unwrap(shape, "edge")));
|
|
6520
|
+
}
|
|
6521
|
+
function edgeIsClosed(verts) {
|
|
6522
|
+
return dist3(wasmIndex(verts, 0), wasmIndex(verts, 1), wasmIndex(verts, 2), wasmIndex(verts, 3), wasmIndex(verts, 4), wasmIndex(verts, 5)) < 1e-7;
|
|
6572
6523
|
}
|
|
6573
6524
|
function curveIsPeriodic(bk, shape) {
|
|
6574
6525
|
const h = shape;
|
|
@@ -6612,7 +6563,7 @@ function curveKnotRemove(bk, edge, knot, tolerance) {
|
|
|
6612
6563
|
function curveSplit(bk, edge, param) {
|
|
6613
6564
|
const edgeId = unwrap(edge, "edge");
|
|
6614
6565
|
const result = bk.curveSplit(edgeId, param);
|
|
6615
|
-
return [edgeHandle(result
|
|
6566
|
+
return [edgeHandle(wasmIndex(result, 0)), edgeHandle(wasmIndex(result, 1))];
|
|
6616
6567
|
}
|
|
6617
6568
|
function approximateSurfaceLspia(bk, coords, rows, cols, degreeU, degreeV, numCpsU, numCpsV, tolerance, maxIterations) {
|
|
6618
6569
|
return faceHandle(bk.approximateSurfaceLspia(coords, rows, cols, degreeU, degreeV, numCpsU, numCpsV, tolerance, maxIterations));
|
|
@@ -6627,12 +6578,7 @@ function createCurveAdaptor(_bk, shape) {
|
|
|
6627
6578
|
function getBezierPenultimatePole(bk, edge) {
|
|
6628
6579
|
const nurbsData = extractNurbsFromEdge(bk, edge);
|
|
6629
6580
|
if (!nurbsData || nurbsData.controlPoints.length < 6) return null;
|
|
6630
|
-
|
|
6631
|
-
return [
|
|
6632
|
-
nurbsData.controlPoints[n - 6],
|
|
6633
|
-
nurbsData.controlPoints[n - 5],
|
|
6634
|
-
nurbsData.controlPoints[n - 4]
|
|
6635
|
-
];
|
|
6581
|
+
return vec3At(nurbsData.controlPoints, nurbsData.controlPoints.length - 6);
|
|
6636
6582
|
}
|
|
6637
6583
|
function getSurfaceCylinderData(bk, surface) {
|
|
6638
6584
|
if (isBrepkitHandle(surface) && surface.type === "face") {
|
|
@@ -6652,7 +6598,7 @@ function classifyPointOnFace(bk, face, u, v, tolerance) {
|
|
|
6652
6598
|
if (tolerance !== void 0) warnOnce("classify-tolerance", "classifyPointOnFace() tolerance parameter is not supported; brepkit uses domain-based classification.");
|
|
6653
6599
|
const faceId = unwrap(face, "face");
|
|
6654
6600
|
const domain = bk.getSurfaceDomain(faceId);
|
|
6655
|
-
if (u < domain
|
|
6601
|
+
if (u < wasmIndex(domain, 0) || u > wasmIndex(domain, 1) || v < wasmIndex(domain, 2) || v > wasmIndex(domain, 3)) return "out";
|
|
6656
6602
|
return "in";
|
|
6657
6603
|
}
|
|
6658
6604
|
function classifyPointRobust(bk, shape, point, tolerance) {
|
|
@@ -6845,19 +6791,10 @@ function extractPlaneFromFace(bk, faceShape) {
|
|
|
6845
6791
|
}
|
|
6846
6792
|
faceId = bestId;
|
|
6847
6793
|
} else faceId = unwrap(faceShape, "face");
|
|
6848
|
-
const
|
|
6849
|
-
const normal = [
|
|
6850
|
-
n[0],
|
|
6851
|
-
n[1],
|
|
6852
|
-
n[2]
|
|
6853
|
-
];
|
|
6794
|
+
const normal = vec3At(bk.getFaceNormal(faceId));
|
|
6854
6795
|
const positions = bk.tessellateFace(faceId, 1).positions;
|
|
6855
6796
|
if (positions.length >= 3) return {
|
|
6856
|
-
point:
|
|
6857
|
-
positions[0],
|
|
6858
|
-
positions[1],
|
|
6859
|
-
positions[2]
|
|
6860
|
-
],
|
|
6797
|
+
point: vec3At(positions),
|
|
6861
6798
|
normal
|
|
6862
6799
|
};
|
|
6863
6800
|
return {
|
|
@@ -6897,12 +6834,12 @@ function extractNurbsFromEdge(bk, shape) {
|
|
|
6897
6834
|
1
|
|
6898
6835
|
],
|
|
6899
6836
|
controlPoints: [
|
|
6900
|
-
verts
|
|
6901
|
-
verts
|
|
6902
|
-
verts
|
|
6903
|
-
verts
|
|
6904
|
-
verts
|
|
6905
|
-
verts
|
|
6837
|
+
wasmIndex(verts, 0),
|
|
6838
|
+
wasmIndex(verts, 1),
|
|
6839
|
+
wasmIndex(verts, 2),
|
|
6840
|
+
wasmIndex(verts, 3),
|
|
6841
|
+
wasmIndex(verts, 4),
|
|
6842
|
+
wasmIndex(verts, 5)
|
|
6906
6843
|
],
|
|
6907
6844
|
weights: [1, 1]
|
|
6908
6845
|
};
|
|
@@ -7077,8 +7014,8 @@ function makeBezierEdge(bk, points) {
|
|
|
7077
7014
|
y,
|
|
7078
7015
|
z
|
|
7079
7016
|
]);
|
|
7080
|
-
const startPt = points
|
|
7081
|
-
const endPt = points
|
|
7017
|
+
const startPt = wasmIndex(points, 0);
|
|
7018
|
+
const endPt = wasmIndex(points, n - 1);
|
|
7082
7019
|
return edgeHandle(bk.makeNurbsEdge(startPt[0], startPt[1], startPt[2], endPt[0], endPt[1], endPt[2], degree, knots, flatCp, weights));
|
|
7083
7020
|
}
|
|
7084
7021
|
function makeTangentArc(bk, startPoint, startTangent, endPoint) {
|
|
@@ -7172,31 +7109,21 @@ function triangulatedSurface(bk, points, rows, cols) {
|
|
|
7172
7109
|
const i10 = (r + 1) * cols + c;
|
|
7173
7110
|
const i01 = r * cols + (c + 1);
|
|
7174
7111
|
const i11 = (r + 1) * cols + (c + 1);
|
|
7175
|
-
const f1 = buildTriFace(bk, points
|
|
7112
|
+
const f1 = buildTriFace(bk, wasmIndex(points, i00), wasmIndex(points, i10), wasmIndex(points, i01));
|
|
7176
7113
|
if (f1) faces.push(f1);
|
|
7177
|
-
const f2 = buildTriFace(bk, points
|
|
7114
|
+
const f2 = buildTriFace(bk, wasmIndex(points, i10), wasmIndex(points, i11), wasmIndex(points, i01));
|
|
7178
7115
|
if (f2) faces.push(f2);
|
|
7179
7116
|
}
|
|
7180
7117
|
if (faces.length === 0) throw new Error("brepkit: no valid faces in surface grid");
|
|
7181
7118
|
return sew(bk, faces, 1e-6);
|
|
7182
7119
|
}
|
|
7183
7120
|
function buildTriFace(bk, a, b, c) {
|
|
7184
|
-
const
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
c[0] - a[0],
|
|
7191
|
-
c[1] - a[1],
|
|
7192
|
-
c[2] - a[2]
|
|
7193
|
-
];
|
|
7194
|
-
const cross = [
|
|
7195
|
-
ab[1] * ac[2] - ab[2] * ac[1],
|
|
7196
|
-
ab[2] * ac[0] - ab[0] * ac[2],
|
|
7197
|
-
ab[0] * ac[1] - ab[1] * ac[0]
|
|
7198
|
-
];
|
|
7199
|
-
if (Math.sqrt(cross[0] ** 2 + cross[1] ** 2 + cross[2] ** 2) < 1e-12) return null;
|
|
7121
|
+
const abx = b[0] - a[0], aby = b[1] - a[1], abz = b[2] - a[2];
|
|
7122
|
+
const acx = c[0] - a[0], acy = c[1] - a[1], acz = c[2] - a[2];
|
|
7123
|
+
const cx = aby * acz - abz * acy;
|
|
7124
|
+
const cy = abz * acx - abx * acz;
|
|
7125
|
+
const cz = abx * acy - aby * acx;
|
|
7126
|
+
if (Math.sqrt(cx * cx + cy * cy + cz * cz) < 1e-12) return null;
|
|
7200
7127
|
try {
|
|
7201
7128
|
return makeFace(bk, makeWire(bk, [
|
|
7202
7129
|
makeLineEdge(bk, a, b),
|
|
@@ -7215,7 +7142,7 @@ function sewAndSolidify(bk, faces, tolerance) {
|
|
|
7215
7142
|
function interpolatePoints(bk, points, options) {
|
|
7216
7143
|
if (options?.tolerance !== void 0) warnOnce("interpolate-tolerance", "interpolatePoints() tolerance parameter is not supported; brepkit uses chord-length parameterisation.");
|
|
7217
7144
|
if (points.length < 2) throw new Error("brepkit: need at least 2 points");
|
|
7218
|
-
if (points.length === 2) return makeLineEdge(bk, points
|
|
7145
|
+
if (points.length === 2) return makeLineEdge(bk, wasmIndex(points, 0), wasmIndex(points, 1));
|
|
7219
7146
|
const degree = Math.min(3, points.length - 1);
|
|
7220
7147
|
const coords = points.flatMap(([x, y, z]) => [
|
|
7221
7148
|
x,
|
|
@@ -7307,11 +7234,11 @@ function createAxis3(_bk, ox, oy, oz, zx, zy, zz, xx, xy, xz) {
|
|
|
7307
7234
|
};
|
|
7308
7235
|
}
|
|
7309
7236
|
function makeCircleNurbs(bk, center, normal, radius, startAngle, endAngle) {
|
|
7310
|
-
const
|
|
7237
|
+
const nLen = Math.sqrt(normal[0] ** 2 + normal[1] ** 2 + normal[2] ** 2);
|
|
7311
7238
|
const nz = [
|
|
7312
|
-
normal[0] /
|
|
7313
|
-
normal[1] /
|
|
7314
|
-
normal[2] /
|
|
7239
|
+
normal[0] / nLen,
|
|
7240
|
+
normal[1] / nLen,
|
|
7241
|
+
normal[2] / nLen
|
|
7315
7242
|
];
|
|
7316
7243
|
const ref = Math.abs(nz[0]) < .9 ? [
|
|
7317
7244
|
1,
|
|
@@ -7322,15 +7249,17 @@ function makeCircleNurbs(bk, center, normal, radius, startAngle, endAngle) {
|
|
|
7322
7249
|
1,
|
|
7323
7250
|
0
|
|
7324
7251
|
];
|
|
7325
|
-
const
|
|
7252
|
+
const xRaw = [
|
|
7326
7253
|
nz[1] * ref[2] - nz[2] * ref[1],
|
|
7327
7254
|
nz[2] * ref[0] - nz[0] * ref[2],
|
|
7328
7255
|
nz[0] * ref[1] - nz[1] * ref[0]
|
|
7329
7256
|
];
|
|
7330
|
-
const xLen = Math.sqrt(
|
|
7331
|
-
xAxis
|
|
7332
|
-
|
|
7333
|
-
|
|
7257
|
+
const xLen = Math.sqrt(xRaw[0] ** 2 + xRaw[1] ** 2 + xRaw[2] ** 2);
|
|
7258
|
+
const xAxis = [
|
|
7259
|
+
xRaw[0] / xLen,
|
|
7260
|
+
xRaw[1] / xLen,
|
|
7261
|
+
xRaw[2] / xLen
|
|
7262
|
+
];
|
|
7334
7263
|
const yAxis = [
|
|
7335
7264
|
nz[1] * xAxis[2] - nz[2] * xAxis[1],
|
|
7336
7265
|
nz[2] * xAxis[0] - nz[0] * xAxis[2],
|
|
@@ -7365,18 +7294,22 @@ function makeCircleNurbs(bk, center, normal, radius, startAngle, endAngle) {
|
|
|
7365
7294
|
const knots = Array(degree + 1).fill(0);
|
|
7366
7295
|
for (let i = 1; i < nSegments; i++) knots.push(i, i);
|
|
7367
7296
|
knots.push(...Array(degree + 1).fill(nSegments));
|
|
7368
|
-
const kMax = knots
|
|
7369
|
-
for (let i = 0; i < knots.length; i++) knots[i] = knots
|
|
7370
|
-
const
|
|
7371
|
-
const
|
|
7372
|
-
|
|
7297
|
+
const kMax = wasmIndex(knots, knots.length - 1);
|
|
7298
|
+
for (let i = 0; i < knots.length; i++) knots[i] = wasmIndex(knots, i) / kMax;
|
|
7299
|
+
const sx = wasmIndex(controlPoints, 0);
|
|
7300
|
+
const sy = wasmIndex(controlPoints, 1);
|
|
7301
|
+
const sz = wasmIndex(controlPoints, 2);
|
|
7302
|
+
const ex = wasmIndex(controlPoints, controlPoints.length - 3);
|
|
7303
|
+
const ey = wasmIndex(controlPoints, controlPoints.length - 2);
|
|
7304
|
+
const ez = wasmIndex(controlPoints, controlPoints.length - 1);
|
|
7305
|
+
return edgeHandle(bk.makeNurbsEdge(sx, sy, sz, ex, ey, ez, degree, knots, controlPoints, weights));
|
|
7373
7306
|
}
|
|
7374
7307
|
function makeEllipseNurbs(bk, center, normal, majorRadius, minorRadius, startAngle, endAngle, xDir) {
|
|
7375
|
-
const
|
|
7308
|
+
const nLen = Math.sqrt(normal[0] ** 2 + normal[1] ** 2 + normal[2] ** 2);
|
|
7376
7309
|
const nz = [
|
|
7377
|
-
normal[0] /
|
|
7378
|
-
normal[1] /
|
|
7379
|
-
normal[2] /
|
|
7310
|
+
normal[0] / nLen,
|
|
7311
|
+
normal[1] / nLen,
|
|
7312
|
+
normal[2] / nLen
|
|
7380
7313
|
];
|
|
7381
7314
|
let xAxis;
|
|
7382
7315
|
if (xDir) {
|
|
@@ -7396,15 +7329,17 @@ function makeEllipseNurbs(bk, center, normal, majorRadius, minorRadius, startAng
|
|
|
7396
7329
|
1,
|
|
7397
7330
|
0
|
|
7398
7331
|
];
|
|
7399
|
-
|
|
7332
|
+
const xRaw = [
|
|
7400
7333
|
nz[1] * ref[2] - nz[2] * ref[1],
|
|
7401
7334
|
nz[2] * ref[0] - nz[0] * ref[2],
|
|
7402
7335
|
nz[0] * ref[1] - nz[1] * ref[0]
|
|
7403
7336
|
];
|
|
7404
|
-
const
|
|
7405
|
-
xAxis
|
|
7406
|
-
|
|
7407
|
-
|
|
7337
|
+
const xLen = Math.sqrt(xRaw[0] ** 2 + xRaw[1] ** 2 + xRaw[2] ** 2);
|
|
7338
|
+
xAxis = [
|
|
7339
|
+
xRaw[0] / xLen,
|
|
7340
|
+
xRaw[1] / xLen,
|
|
7341
|
+
xRaw[2] / xLen
|
|
7342
|
+
];
|
|
7408
7343
|
}
|
|
7409
7344
|
const yAxis = [
|
|
7410
7345
|
nz[1] * xAxis[2] - nz[2] * xAxis[1],
|
|
@@ -7440,11 +7375,15 @@ function makeEllipseNurbs(bk, center, normal, majorRadius, minorRadius, startAng
|
|
|
7440
7375
|
const knots = Array(degree + 1).fill(0);
|
|
7441
7376
|
for (let i = 1; i < nSegments; i++) knots.push(i, i);
|
|
7442
7377
|
knots.push(...Array(degree + 1).fill(nSegments));
|
|
7443
|
-
const kMax = knots
|
|
7444
|
-
for (let i = 0; i < knots.length; i++) knots[i] = knots
|
|
7445
|
-
const
|
|
7446
|
-
const
|
|
7447
|
-
|
|
7378
|
+
const kMax = wasmIndex(knots, knots.length - 1);
|
|
7379
|
+
for (let i = 0; i < knots.length; i++) knots[i] = wasmIndex(knots, i) / kMax;
|
|
7380
|
+
const sx = wasmIndex(controlPoints, 0);
|
|
7381
|
+
const sy = wasmIndex(controlPoints, 1);
|
|
7382
|
+
const sz = wasmIndex(controlPoints, 2);
|
|
7383
|
+
const ex = wasmIndex(controlPoints, controlPoints.length - 3);
|
|
7384
|
+
const ey = wasmIndex(controlPoints, controlPoints.length - 2);
|
|
7385
|
+
const ez = wasmIndex(controlPoints, controlPoints.length - 1);
|
|
7386
|
+
return edgeHandle(bk.makeNurbsEdge(sx, sy, sz, ex, ey, ez, degree, knots, controlPoints, weights));
|
|
7448
7387
|
}
|
|
7449
7388
|
//#endregion
|
|
7450
7389
|
//#region src/kernel/brepkit/booleanOps.ts
|
|
@@ -7481,11 +7420,11 @@ function section(bk, shape, plane, _approximation) {
|
|
|
7481
7420
|
const solidId = isBrepkitHandle(shape) && shape.type === "solid" ? shape.id : unwrap(shape, "solid");
|
|
7482
7421
|
const faceIds = toArray(bk.section(solidId, point[0], point[1], point[2], normal[0], normal[1], normal[2]));
|
|
7483
7422
|
if (faceIds.length === 0) return compoundHandle(bk.makeCompound([]));
|
|
7484
|
-
return wireHandle(bk.getFaceOuterWire(faceIds
|
|
7423
|
+
return wireHandle(bk.getFaceOuterWire(wasmIndex(faceIds, 0)));
|
|
7485
7424
|
}
|
|
7486
7425
|
function fuseAll(bk, shapes, options) {
|
|
7487
7426
|
if (shapes.length === 0) throw new Error("brepkit: fuseAll requires at least one shape");
|
|
7488
|
-
if (shapes.length === 1) return shapes
|
|
7427
|
+
if (shapes.length === 1) return wasmIndex(shapes, 0);
|
|
7489
7428
|
if (bk.compoundFuse) {
|
|
7490
7429
|
const solidIds = [];
|
|
7491
7430
|
for (const shape of shapes) {
|
|
@@ -7503,7 +7442,7 @@ function fuseAll(bk, shapes, options) {
|
|
|
7503
7442
|
else next.push(current[i]);
|
|
7504
7443
|
current = next;
|
|
7505
7444
|
}
|
|
7506
|
-
return current
|
|
7445
|
+
return wasmIndex(current, 0);
|
|
7507
7446
|
}
|
|
7508
7447
|
function cutAll(bk, shape, tools, options) {
|
|
7509
7448
|
if (tools.length === 0) return shape;
|
|
@@ -7582,11 +7521,11 @@ function hull(bk, shapes, _tolerance) {
|
|
|
7582
7521
|
const vertIds = toArray(bk.getSolidVertices(h.id));
|
|
7583
7522
|
for (const vid of vertIds) {
|
|
7584
7523
|
const pos = bk.getVertexPosition(vid);
|
|
7585
|
-
coords.push(pos
|
|
7524
|
+
coords.push(wasmIndex(pos, 0), wasmIndex(pos, 1), wasmIndex(pos, 2));
|
|
7586
7525
|
}
|
|
7587
7526
|
} else if (h.type === "vertex") {
|
|
7588
7527
|
const pos = bk.getVertexPosition(h.id);
|
|
7589
|
-
coords.push(pos
|
|
7528
|
+
coords.push(wasmIndex(pos, 0), wasmIndex(pos, 1), wasmIndex(pos, 2));
|
|
7590
7529
|
}
|
|
7591
7530
|
}
|
|
7592
7531
|
if (coords.length < 12) throw new Error("brepkit: hull requires enough points");
|
|
@@ -7601,14 +7540,14 @@ function hullFromPoints(bk, points, _tolerance) {
|
|
|
7601
7540
|
function buildSolidFromFaces(bk, points, faces, _tolerance) {
|
|
7602
7541
|
const positions = new Float64Array(points.length * 3);
|
|
7603
7542
|
for (let i = 0; i < points.length; i++) {
|
|
7604
|
-
const p = points
|
|
7543
|
+
const p = wasmIndex(points, i);
|
|
7605
7544
|
positions[i * 3] = p.x;
|
|
7606
7545
|
positions[i * 3 + 1] = p.y;
|
|
7607
7546
|
positions[i * 3 + 2] = p.z;
|
|
7608
7547
|
}
|
|
7609
7548
|
const indices = new Uint32Array(faces.length * 3);
|
|
7610
7549
|
for (let i = 0; i < faces.length; i++) {
|
|
7611
|
-
const f = faces
|
|
7550
|
+
const f = wasmIndex(faces, i);
|
|
7612
7551
|
indices[i * 3] = f[0];
|
|
7613
7552
|
indices[i * 3 + 1] = f[1];
|
|
7614
7553
|
indices[i * 3 + 2] = f[2];
|
|
@@ -7906,9 +7845,9 @@ function shell(bk, shape, faces, thickness, tolerance) {
|
|
|
7906
7845
|
let ox = 0, oy = 0, oz = 0;
|
|
7907
7846
|
for (const vid of origVerts) {
|
|
7908
7847
|
const pos = bk.getVertexPosition(vid);
|
|
7909
|
-
ox += pos
|
|
7910
|
-
oy += pos
|
|
7911
|
-
oz += pos
|
|
7848
|
+
ox += wasmIndex(pos, 0);
|
|
7849
|
+
oy += wasmIndex(pos, 1);
|
|
7850
|
+
oz += wasmIndex(pos, 2);
|
|
7912
7851
|
}
|
|
7913
7852
|
const n = origVerts.length;
|
|
7914
7853
|
ox /= n;
|
|
@@ -7922,9 +7861,9 @@ function shell(bk, shape, faces, thickness, tolerance) {
|
|
|
7922
7861
|
let sx = 0, sy = 0, sz = 0;
|
|
7923
7862
|
for (const svid of sv) {
|
|
7924
7863
|
const spos = bk.getVertexPosition(svid);
|
|
7925
|
-
sx += spos
|
|
7926
|
-
sy += spos
|
|
7927
|
-
sz += spos
|
|
7864
|
+
sx += wasmIndex(spos, 0);
|
|
7865
|
+
sy += wasmIndex(spos, 1);
|
|
7866
|
+
sz += wasmIndex(spos, 2);
|
|
7928
7867
|
}
|
|
7929
7868
|
const sn = sv.length;
|
|
7930
7869
|
sx /= sn;
|
|
@@ -7975,12 +7914,12 @@ function offsetWire2D(bk, wire, offsetVal, _joinType) {
|
|
|
7975
7914
|
const coords2d = [];
|
|
7976
7915
|
for (const edge of edges) {
|
|
7977
7916
|
const verts = bk.getEdgeVertices(unwrap(edge, "edge"));
|
|
7978
|
-
coords2d.push(verts
|
|
7917
|
+
coords2d.push(wasmIndex(verts, 0), wasmIndex(verts, 1));
|
|
7979
7918
|
}
|
|
7980
7919
|
if (coords2d.length < 6) return wire;
|
|
7981
7920
|
const result = bk.offsetPolygon2d(coords2d, offsetVal, 1e-10);
|
|
7982
7921
|
const coords3d = [];
|
|
7983
|
-
for (let i = 0; i < result.length; i += 2) coords3d.push(result
|
|
7922
|
+
for (let i = 0; i < result.length; i += 2) coords3d.push(wasmIndex(result, i), wasmIndex(result, i + 1), 0);
|
|
7984
7923
|
return wireHandle(bk.makePolygonWire(coords3d));
|
|
7985
7924
|
}
|
|
7986
7925
|
function simplify(bk, shape) {
|
|
@@ -8117,8 +8056,8 @@ function exportSTEP(bk, shapes) {
|
|
|
8117
8056
|
}
|
|
8118
8057
|
function exportSTL(bk, shape, binary) {
|
|
8119
8058
|
const solidIds = unwrapSolidsForExport(bk, shape, "exportSTL");
|
|
8120
|
-
if (binary) return bk.exportStl(solidIds
|
|
8121
|
-
const bytes = bk.exportStlAscii(solidIds
|
|
8059
|
+
if (binary) return bk.exportStl(wasmIndex(solidIds, 0), DEFAULT_DEFLECTION).buffer;
|
|
8060
|
+
const bytes = bk.exportStlAscii(wasmIndex(solidIds, 0), DEFAULT_DEFLECTION);
|
|
8122
8061
|
return new TextDecoder().decode(bytes);
|
|
8123
8062
|
}
|
|
8124
8063
|
function importSTEP(bk, data) {
|
|
@@ -8228,8 +8167,8 @@ function meshEdges(bk, shape, tolerance, angularTolerance) {
|
|
|
8228
8167
|
const edgeCount = edgeLines.edgeCount;
|
|
8229
8168
|
const edgeGroups = [];
|
|
8230
8169
|
for (let i = 0; i < edgeCount; i++) {
|
|
8231
|
-
const startIdx = offsets
|
|
8232
|
-
const pointCount = ((i + 1 < edgeCount ? offsets
|
|
8170
|
+
const startIdx = wasmIndex(offsets, i);
|
|
8171
|
+
const pointCount = ((i + 1 < edgeCount ? wasmIndex(offsets, i + 1) : positions.length) - startIdx) / 3;
|
|
8233
8172
|
edgeGroups.push({
|
|
8234
8173
|
start: startIdx / 3,
|
|
8235
8174
|
count: pointCount,
|
|
@@ -8268,8 +8207,8 @@ function meshSolidGrouped(bk, solidId, deflection, includeUVs) {
|
|
|
8268
8207
|
if (groupCount !== faceIds.length) throw new Error(`faceOffsets/faceIds length mismatch: ${groupCount} groups vs ${faceIds.length} faces`);
|
|
8269
8208
|
const faceGroups = [];
|
|
8270
8209
|
for (let i = 0; i < data.faceOffsets.length - 1; i++) {
|
|
8271
|
-
const start = data.faceOffsets
|
|
8272
|
-
const count = data.faceOffsets
|
|
8210
|
+
const start = wasmIndex(data.faceOffsets, i);
|
|
8211
|
+
const count = wasmIndex(data.faceOffsets, i + 1) - start;
|
|
8273
8212
|
if (count === 0) continue;
|
|
8274
8213
|
faceGroups.push({
|
|
8275
8214
|
start,
|
|
@@ -8388,28 +8327,22 @@ function length(bk, shape) {
|
|
|
8388
8327
|
if (h.type === "wire") return bk.wireLength(h.id);
|
|
8389
8328
|
throw new Error("brepkit: length() requires an edge, wire, or face");
|
|
8390
8329
|
}
|
|
8330
|
+
function edgeMidpoint(bk, edgeId) {
|
|
8331
|
+
const v = bk.getEdgeVertices(edgeId);
|
|
8332
|
+
return [
|
|
8333
|
+
(wasmIndex(v, 0) + wasmIndex(v, 3)) / 2,
|
|
8334
|
+
(wasmIndex(v, 1) + wasmIndex(v, 4)) / 2,
|
|
8335
|
+
(wasmIndex(v, 2) + wasmIndex(v, 5)) / 2
|
|
8336
|
+
];
|
|
8337
|
+
}
|
|
8391
8338
|
function centerOfMass(bk, shape) {
|
|
8392
8339
|
const h = shape;
|
|
8393
|
-
if (h.type === "solid")
|
|
8394
|
-
const result = bk.centerOfMass(unwrap(shape), DEFAULT_DEFLECTION);
|
|
8395
|
-
return [
|
|
8396
|
-
result[0],
|
|
8397
|
-
result[1],
|
|
8398
|
-
result[2]
|
|
8399
|
-
];
|
|
8400
|
-
}
|
|
8340
|
+
if (h.type === "solid") return vec3At(bk.centerOfMass(unwrap(shape), DEFAULT_DEFLECTION));
|
|
8401
8341
|
if (h.type === "face") {
|
|
8402
8342
|
const domain = uvBounds(bk, shape);
|
|
8403
8343
|
return pointOnSurface(bk, shape, (domain.uMin + domain.uMax) / 2, (domain.vMin + domain.vMax) / 2);
|
|
8404
8344
|
}
|
|
8405
|
-
if (h.type === "edge")
|
|
8406
|
-
const verts = bk.getEdgeVertices(h.id);
|
|
8407
|
-
return [
|
|
8408
|
-
(verts[0] + verts[3]) / 2,
|
|
8409
|
-
(verts[1] + verts[4]) / 2,
|
|
8410
|
-
(verts[2] + verts[5]) / 2
|
|
8411
|
-
];
|
|
8412
|
-
}
|
|
8345
|
+
if (h.type === "edge") return edgeMidpoint(bk, h.id);
|
|
8413
8346
|
if (h.type === "vertex") return vertexPosition(bk, shape);
|
|
8414
8347
|
const vertices = iterShapes(bk, shape, "vertex");
|
|
8415
8348
|
if (vertices.length > 0) {
|
|
@@ -8434,14 +8367,7 @@ function centerOfMass(bk, shape) {
|
|
|
8434
8367
|
}
|
|
8435
8368
|
function linearCenterOfMass(bk, shape) {
|
|
8436
8369
|
const h = shape;
|
|
8437
|
-
if (h.type === "edge")
|
|
8438
|
-
const verts = bk.getEdgeVertices(h.id);
|
|
8439
|
-
return [
|
|
8440
|
-
(verts[0] + verts[3]) / 2,
|
|
8441
|
-
(verts[1] + verts[4]) / 2,
|
|
8442
|
-
(verts[2] + verts[5]) / 2
|
|
8443
|
-
];
|
|
8444
|
-
}
|
|
8370
|
+
if (h.type === "edge") return edgeMidpoint(bk, h.id);
|
|
8445
8371
|
return centerOfMass(bk, shape);
|
|
8446
8372
|
}
|
|
8447
8373
|
function boundingBox(bk, shape) {
|
|
@@ -8449,16 +8375,8 @@ function boundingBox(bk, shape) {
|
|
|
8449
8375
|
if (h.type === "solid") {
|
|
8450
8376
|
const bb = bk.boundingBox(unwrap(shape));
|
|
8451
8377
|
return {
|
|
8452
|
-
min:
|
|
8453
|
-
|
|
8454
|
-
bb[1],
|
|
8455
|
-
bb[2]
|
|
8456
|
-
],
|
|
8457
|
-
max: [
|
|
8458
|
-
bb[3],
|
|
8459
|
-
bb[4],
|
|
8460
|
-
bb[5]
|
|
8461
|
-
]
|
|
8378
|
+
min: vec3At(bb, 0),
|
|
8379
|
+
max: vec3At(bb, 3)
|
|
8462
8380
|
};
|
|
8463
8381
|
}
|
|
8464
8382
|
if (h.type === "vertex") {
|
|
@@ -8512,85 +8430,28 @@ function distance(bk, shape1, shape2) {
|
|
|
8512
8430
|
if (h1.type === "solid" && h2.type === "solid") {
|
|
8513
8431
|
const buf = bk.solidToSolidDistance(h1.id, h2.id);
|
|
8514
8432
|
return {
|
|
8515
|
-
value: buf
|
|
8516
|
-
point1:
|
|
8517
|
-
|
|
8518
|
-
buf[2],
|
|
8519
|
-
buf[3]
|
|
8520
|
-
],
|
|
8521
|
-
point2: [
|
|
8522
|
-
buf[4],
|
|
8523
|
-
buf[5],
|
|
8524
|
-
buf[6]
|
|
8525
|
-
]
|
|
8526
|
-
};
|
|
8527
|
-
}
|
|
8528
|
-
if (h1.type === "vertex" && h2.type === "solid") {
|
|
8529
|
-
const pos = bk.getVertexPosition(h1.id);
|
|
8530
|
-
const result = bk.pointToSolidDistance(pos[0], pos[1], pos[2], h2.id);
|
|
8531
|
-
return {
|
|
8532
|
-
value: result[0],
|
|
8533
|
-
point1: [
|
|
8534
|
-
pos[0],
|
|
8535
|
-
pos[1],
|
|
8536
|
-
pos[2]
|
|
8537
|
-
],
|
|
8538
|
-
point2: [
|
|
8539
|
-
result[1],
|
|
8540
|
-
result[2],
|
|
8541
|
-
result[3]
|
|
8542
|
-
]
|
|
8433
|
+
value: wasmIndex(buf, 0),
|
|
8434
|
+
point1: vec3At(buf, 1),
|
|
8435
|
+
point2: vec3At(buf, 4)
|
|
8543
8436
|
};
|
|
8544
8437
|
}
|
|
8545
|
-
if (h1.type === "vertex" && h2.type === "face") {
|
|
8546
|
-
const
|
|
8547
|
-
const result = bk.pointToFaceDistance(
|
|
8438
|
+
if (h1.type === "vertex" && (h2.type === "solid" || h2.type === "face" || h2.type === "edge")) {
|
|
8439
|
+
const point1 = vec3At(bk.getVertexPosition(h1.id));
|
|
8440
|
+
const result = h2.type === "solid" ? bk.pointToSolidDistance(point1[0], point1[1], point1[2], h2.id) : h2.type === "face" ? bk.pointToFaceDistance(point1[0], point1[1], point1[2], h2.id) : bk.pointToEdgeDistance(point1[0], point1[1], point1[2], h2.id);
|
|
8548
8441
|
return {
|
|
8549
|
-
value: result
|
|
8550
|
-
point1
|
|
8551
|
-
|
|
8552
|
-
pos[1],
|
|
8553
|
-
pos[2]
|
|
8554
|
-
],
|
|
8555
|
-
point2: [
|
|
8556
|
-
result[1],
|
|
8557
|
-
result[2],
|
|
8558
|
-
result[3]
|
|
8559
|
-
]
|
|
8560
|
-
};
|
|
8561
|
-
}
|
|
8562
|
-
if (h1.type === "vertex" && h2.type === "edge") {
|
|
8563
|
-
const pos = bk.getVertexPosition(h1.id);
|
|
8564
|
-
const result = bk.pointToEdgeDistance(pos[0], pos[1], pos[2], h2.id);
|
|
8565
|
-
return {
|
|
8566
|
-
value: result[0],
|
|
8567
|
-
point1: [
|
|
8568
|
-
pos[0],
|
|
8569
|
-
pos[1],
|
|
8570
|
-
pos[2]
|
|
8571
|
-
],
|
|
8572
|
-
point2: [
|
|
8573
|
-
result[1],
|
|
8574
|
-
result[2],
|
|
8575
|
-
result[3]
|
|
8576
|
-
]
|
|
8442
|
+
value: wasmIndex(result, 0),
|
|
8443
|
+
point1,
|
|
8444
|
+
point2: vec3At(result, 1)
|
|
8577
8445
|
};
|
|
8578
8446
|
}
|
|
8579
8447
|
const getPos = (s) => {
|
|
8580
|
-
if (s.type === "vertex")
|
|
8581
|
-
const p = bk.getVertexPosition(s.id);
|
|
8582
|
-
return [
|
|
8583
|
-
p[0],
|
|
8584
|
-
p[1],
|
|
8585
|
-
p[2]
|
|
8586
|
-
];
|
|
8587
|
-
}
|
|
8448
|
+
if (s.type === "vertex") return vec3At(bk.getVertexPosition(s.id));
|
|
8588
8449
|
if (s.type === "solid") {
|
|
8589
8450
|
const bb = bk.boundingBox(s.id);
|
|
8590
8451
|
return [
|
|
8591
|
-
(bb
|
|
8592
|
-
(bb
|
|
8593
|
-
(bb
|
|
8452
|
+
(wasmIndex(bb, 0) + wasmIndex(bb, 3)) / 2,
|
|
8453
|
+
(wasmIndex(bb, 1) + wasmIndex(bb, 4)) / 2,
|
|
8454
|
+
(wasmIndex(bb, 2) + wasmIndex(bb, 5)) / 2
|
|
8594
8455
|
];
|
|
8595
8456
|
}
|
|
8596
8457
|
return [
|
|
@@ -8614,23 +8475,15 @@ function surfaceCurvature(bk, face, u, v) {
|
|
|
8614
8475
|
const fid = unwrap(face, "face");
|
|
8615
8476
|
const data = bk.measureCurvatureAtSurface(fid, u, v);
|
|
8616
8477
|
if (data.length < 8) throw new Error(`brepkit: measureCurvatureAtSurface returned ${data.length} values, expected 8`);
|
|
8617
|
-
const k1 = data
|
|
8618
|
-
const k2 = data
|
|
8478
|
+
const k1 = wasmIndex(data, 0);
|
|
8479
|
+
const k2 = wasmIndex(data, 1);
|
|
8619
8480
|
return {
|
|
8620
8481
|
gaussian: k1 * k2,
|
|
8621
8482
|
mean: (k1 + k2) / 2,
|
|
8622
8483
|
max: Math.max(k1, k2),
|
|
8623
8484
|
min: Math.min(k1, k2),
|
|
8624
|
-
maxDirection:
|
|
8625
|
-
|
|
8626
|
-
data[3],
|
|
8627
|
-
data[4]
|
|
8628
|
-
],
|
|
8629
|
-
minDirection: [
|
|
8630
|
-
data[5],
|
|
8631
|
-
data[6],
|
|
8632
|
-
data[7]
|
|
8633
|
-
]
|
|
8485
|
+
maxDirection: vec3At(data, 2),
|
|
8486
|
+
minDirection: vec3At(data, 5)
|
|
8634
8487
|
};
|
|
8635
8488
|
}
|
|
8636
8489
|
function surfaceCenterOfMass(bk, face) {
|
|
@@ -8639,12 +8492,23 @@ function surfaceCenterOfMass(bk, face) {
|
|
|
8639
8492
|
const idx = mesh.indices;
|
|
8640
8493
|
let cx = 0, cy = 0, cz = 0, totalArea = 0;
|
|
8641
8494
|
for (let t = 0; t < idx.length; t += 3) {
|
|
8642
|
-
const i0 = idx
|
|
8643
|
-
const
|
|
8644
|
-
const
|
|
8645
|
-
const
|
|
8646
|
-
const
|
|
8647
|
-
const
|
|
8495
|
+
const i0 = wasmIndex(idx, t) * 3;
|
|
8496
|
+
const i1 = wasmIndex(idx, t + 1) * 3;
|
|
8497
|
+
const i2 = wasmIndex(idx, t + 2) * 3;
|
|
8498
|
+
const p0x = wasmIndex(pos, i0);
|
|
8499
|
+
const p0y = wasmIndex(pos, i0 + 1);
|
|
8500
|
+
const p0z = wasmIndex(pos, i0 + 2);
|
|
8501
|
+
const p1x = wasmIndex(pos, i1);
|
|
8502
|
+
const p1y = wasmIndex(pos, i1 + 1);
|
|
8503
|
+
const p1z = wasmIndex(pos, i1 + 2);
|
|
8504
|
+
const p2x = wasmIndex(pos, i2);
|
|
8505
|
+
const p2y = wasmIndex(pos, i2 + 1);
|
|
8506
|
+
const p2z = wasmIndex(pos, i2 + 2);
|
|
8507
|
+
const tcx = (p0x + p1x + p2x) / 3;
|
|
8508
|
+
const tcy = (p0y + p1y + p2y) / 3;
|
|
8509
|
+
const tcz = (p0z + p1z + p2z) / 3;
|
|
8510
|
+
const ux = p1x - p0x, uy = p1y - p0y, uz = p1z - p0z;
|
|
8511
|
+
const vx = p2x - p0x, vy = p2y - p0y, vz = p2z - p0z;
|
|
8648
8512
|
const faceArea = .5 * Math.sqrt((uy * vz - uz * vy) ** 2 + (uz * vx - ux * vz) ** 2 + (ux * vy - uy * vx) ** 2);
|
|
8649
8513
|
cx += tcx * faceArea;
|
|
8650
8514
|
cy += tcy * faceArea;
|
|
@@ -8732,9 +8596,9 @@ function faceCentroidById(bk, faceId) {
|
|
|
8732
8596
|
let cz = 0;
|
|
8733
8597
|
const nVerts = pos.length / 3;
|
|
8734
8598
|
for (let i = 0; i < pos.length; i += 3) {
|
|
8735
|
-
cx += pos
|
|
8736
|
-
cy += pos
|
|
8737
|
-
cz += pos
|
|
8599
|
+
cx += wasmIndex(pos, i);
|
|
8600
|
+
cy += wasmIndex(pos, i + 1);
|
|
8601
|
+
cz += wasmIndex(pos, i + 2);
|
|
8738
8602
|
}
|
|
8739
8603
|
return [
|
|
8740
8604
|
cx / nVerts,
|
|
@@ -8760,7 +8624,7 @@ function matchFacesGeometrically(bk, originalShape, inputFaceHashes, outputFaceI
|
|
|
8760
8624
|
const hashCount = Math.min(inputFaceIds.length, inputFaceHashes.length);
|
|
8761
8625
|
const inputSigs = [];
|
|
8762
8626
|
for (let i = 0; i < hashCount; i++) {
|
|
8763
|
-
const fid = inputFaceIds
|
|
8627
|
+
const fid = wasmIndex(inputFaceIds, i);
|
|
8764
8628
|
try {
|
|
8765
8629
|
const normal = bk.getFaceNormal(fid);
|
|
8766
8630
|
const centroid = faceCentroidById(bk, fid);
|
|
@@ -8808,7 +8672,7 @@ function matchFacesGeometrically(bk, originalShape, inputFaceHashes, outputFaceI
|
|
|
8808
8672
|
let bestScore = -Infinity;
|
|
8809
8673
|
let bestIdx = -1;
|
|
8810
8674
|
for (let i = 0; i < inputSigs.length; i++) {
|
|
8811
|
-
const inp = inputSigs
|
|
8675
|
+
const inp = wasmIndex(inputSigs, i);
|
|
8812
8676
|
const dot = (out.normal[0] ?? 0) * (inp.normal[0] ?? 0) + (out.normal[1] ?? 0) * (inp.normal[1] ?? 0) + (out.normal[2] ?? 0) * (inp.normal[2] ?? 0);
|
|
8813
8677
|
if (dot < NORMAL_THRESHOLD) continue;
|
|
8814
8678
|
const distSq = centroidDistSq(out.centroid, inp.centroid);
|
|
@@ -8820,7 +8684,7 @@ function matchFacesGeometrically(bk, originalShape, inputFaceHashes, outputFaceI
|
|
|
8820
8684
|
}
|
|
8821
8685
|
}
|
|
8822
8686
|
if (bestIdx >= 0) {
|
|
8823
|
-
const bestInput = inputSigs
|
|
8687
|
+
const bestInput = wasmIndex(inputSigs, bestIdx);
|
|
8824
8688
|
const existing = modified.get(bestInput.hash) ?? [];
|
|
8825
8689
|
existing.push(out.hash);
|
|
8826
8690
|
modified.set(bestInput.hash, existing);
|
|
@@ -8842,7 +8706,7 @@ function matchFacesGeometrically(bk, originalShape, inputFaceHashes, outputFaceI
|
|
|
8842
8706
|
}
|
|
8843
8707
|
}
|
|
8844
8708
|
}
|
|
8845
|
-
for (let i = 0; i < inputSigs.length; i++) if (!matchedInputIndices.has(i)) deleted.add(inputSigs
|
|
8709
|
+
for (let i = 0; i < inputSigs.length; i++) if (!matchedInputIndices.has(i)) deleted.add(wasmIndex(inputSigs, i).hash);
|
|
8846
8710
|
}
|
|
8847
8711
|
/**
|
|
8848
8712
|
* Build a ShapeEvolution by comparing input face hashes to output face hashes.
|
|
@@ -8859,7 +8723,7 @@ function buildEvolution(bk, resultShape, inputFaceHashes, hashUpperBound, isTran
|
|
|
8859
8723
|
if (h.type === "solid") {
|
|
8860
8724
|
const outputFaces = toArray(bk.getSolidFaces(h.id));
|
|
8861
8725
|
const outputHashes = outputFaces.map((fid) => fid % hashUpperBound);
|
|
8862
|
-
if (isTransform) for (let i = 0; i < inputFaceHashes.length && i < outputHashes.length; i++) modified.set(inputFaceHashes
|
|
8726
|
+
if (isTransform) for (let i = 0; i < inputFaceHashes.length && i < outputHashes.length; i++) modified.set(wasmIndex(inputFaceHashes, i), [wasmIndex(outputHashes, i)]);
|
|
8863
8727
|
else {
|
|
8864
8728
|
const inputSet = new Set(inputFaceHashes);
|
|
8865
8729
|
let hasOverlap = false;
|
|
@@ -8871,12 +8735,12 @@ function buildEvolution(bk, resultShape, inputFaceHashes, hashUpperBound, isTran
|
|
|
8871
8735
|
const outputSet = new Set(outputHashes);
|
|
8872
8736
|
for (const hash of outputHashes) if (inputSet.has(hash)) modified.set(hash, [hash]);
|
|
8873
8737
|
const newFaces = outputHashes.filter((fh) => !inputSet.has(fh));
|
|
8874
|
-
if (newFaces.length > 0 && inputFaceHashes.length > 0) generated.set(inputFaceHashes
|
|
8738
|
+
if (newFaces.length > 0 && inputFaceHashes.length > 0) generated.set(wasmIndex(inputFaceHashes, 0), newFaces);
|
|
8875
8739
|
for (const hash of inputFaceHashes) if (!outputSet.has(hash)) deleted.add(hash);
|
|
8876
8740
|
} else if (originalShape) matchFacesGeometrically(bk, originalShape, inputFaceHashes, outputFaces, hashUpperBound, modified, generated, deleted);
|
|
8877
8741
|
else {
|
|
8878
|
-
for (let i = 0; i < inputFaceHashes.length && i < outputHashes.length; i++) modified.set(inputFaceHashes
|
|
8879
|
-
if (outputHashes.length > inputFaceHashes.length && inputFaceHashes.length > 0) generated.set(inputFaceHashes
|
|
8742
|
+
for (let i = 0; i < inputFaceHashes.length && i < outputHashes.length; i++) modified.set(wasmIndex(inputFaceHashes, i), [wasmIndex(outputHashes, i)]);
|
|
8743
|
+
if (outputHashes.length > inputFaceHashes.length && inputFaceHashes.length > 0) generated.set(wasmIndex(inputFaceHashes, 0), outputHashes.slice(inputFaceHashes.length));
|
|
8880
8744
|
}
|
|
8881
8745
|
}
|
|
8882
8746
|
}
|
|
@@ -9278,7 +9142,7 @@ function createAffinityGTrsf2d(ox, oy, dx, dy, ratio) {
|
|
|
9278
9142
|
0,
|
|
9279
9143
|
1
|
|
9280
9144
|
];
|
|
9281
|
-
return _gtrsf(m, ox - m
|
|
9145
|
+
return _gtrsf(m, ox - wasmIndex(m, 0) * ox - wasmIndex(m, 1) * oy, oy - wasmIndex(m, 3) * ox - wasmIndex(m, 4) * oy);
|
|
9282
9146
|
}
|
|
9283
9147
|
function createTranslationGTrsf2d(dx, dy) {
|
|
9284
9148
|
return _gtrsf([
|
|
@@ -9309,7 +9173,7 @@ function createMirrorGTrsf2d(cx, cy, mode, ox, oy, dx, dy) {
|
|
|
9309
9173
|
1
|
|
9310
9174
|
];
|
|
9311
9175
|
const px = ox ?? cx, py = oy ?? cy;
|
|
9312
|
-
return _gtrsf(m, px - m
|
|
9176
|
+
return _gtrsf(m, px - wasmIndex(m, 0) * px - wasmIndex(m, 1) * py, py - wasmIndex(m, 3) * px - wasmIndex(m, 4) * py);
|
|
9313
9177
|
}
|
|
9314
9178
|
return _gtrsf([
|
|
9315
9179
|
-1,
|
|
@@ -9356,21 +9220,23 @@ function setGTrsf2dTranslationPart(gtrsf, dx, dy) {
|
|
|
9356
9220
|
}
|
|
9357
9221
|
function multiplyGTrsf2d(base, other) {
|
|
9358
9222
|
const a = base.m, b = other.m;
|
|
9223
|
+
const ai = (i) => wasmIndex(a, i);
|
|
9224
|
+
const bi = (i) => wasmIndex(b, i);
|
|
9359
9225
|
base.m = [
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9226
|
+
ai(0) * bi(0) + ai(1) * bi(3) + ai(2) * bi(6),
|
|
9227
|
+
ai(0) * bi(1) + ai(1) * bi(4) + ai(2) * bi(7),
|
|
9228
|
+
ai(0) * bi(2) + ai(1) * bi(5) + ai(2) * bi(8),
|
|
9229
|
+
ai(3) * bi(0) + ai(4) * bi(3) + ai(5) * bi(6),
|
|
9230
|
+
ai(3) * bi(1) + ai(4) * bi(4) + ai(5) * bi(7),
|
|
9231
|
+
ai(3) * bi(2) + ai(4) * bi(5) + ai(5) * bi(8),
|
|
9232
|
+
ai(6) * bi(0) + ai(7) * bi(3) + ai(8) * bi(6),
|
|
9233
|
+
ai(6) * bi(1) + ai(7) * bi(4) + ai(8) * bi(7),
|
|
9234
|
+
ai(6) * bi(2) + ai(7) * bi(5) + ai(8) * bi(8)
|
|
9369
9235
|
];
|
|
9370
9236
|
const oldTx = base.tx, oldTy = base.ty;
|
|
9371
9237
|
const otx = Number(other.tx) || 0, oty = Number(other.ty) || 0;
|
|
9372
|
-
base.tx =
|
|
9373
|
-
base.ty =
|
|
9238
|
+
base.tx = ai(0) * otx + ai(1) * oty + oldTx;
|
|
9239
|
+
base.ty = ai(3) * otx + ai(4) * oty + oldTy;
|
|
9374
9240
|
}
|
|
9375
9241
|
function transformCurve2dGeneral(curve, gtrsf) {
|
|
9376
9242
|
const c = c2d(curve);
|
|
@@ -9386,13 +9252,14 @@ function transformCurve2dGeneral(curve, gtrsf) {
|
|
|
9386
9252
|
1
|
|
9387
9253
|
];
|
|
9388
9254
|
const tx = Number(gtrsf.tx) || 0, ty = Number(gtrsf.ty) || 0;
|
|
9389
|
-
|
|
9255
|
+
const m0 = wasmIndex(m, 0), m1 = wasmIndex(m, 1), m3 = wasmIndex(m, 3), m4 = wasmIndex(m, 4);
|
|
9256
|
+
if (Math.abs(m0 - 1) < 1e-12 && Math.abs(m4 - 1) < 1e-12 && Math.abs(m1) < 1e-12 && Math.abs(m3) < 1e-12) return translateCurve2d$2(c, tx, ty);
|
|
9390
9257
|
const bounds = curveBounds(c);
|
|
9391
9258
|
const N = 20;
|
|
9392
9259
|
const pts = [];
|
|
9393
9260
|
for (let i = 0; i <= N; i++) {
|
|
9394
9261
|
const [px, py] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / N);
|
|
9395
|
-
pts.push([
|
|
9262
|
+
pts.push([m0 * px + m1 * py + tx, m3 * px + m4 * py + ty]);
|
|
9396
9263
|
}
|
|
9397
9264
|
return makeBezier2d$2(pts);
|
|
9398
9265
|
}
|
|
@@ -9525,8 +9392,8 @@ function approximateCurve2dAsBSpline(curve, tol, cont, maxSeg) {
|
|
|
9525
9392
|
maxErr = 0;
|
|
9526
9393
|
for (let i = 0; i < N; i++) {
|
|
9527
9394
|
const [ex, ey] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * (i + .5) / N);
|
|
9528
|
-
const p0 = poles
|
|
9529
|
-
const p1 = poles
|
|
9395
|
+
const p0 = wasmIndex(poles, i);
|
|
9396
|
+
const p1 = wasmIndex(poles, i + 1);
|
|
9530
9397
|
const mx = (p0[0] + p1[0]) / 2;
|
|
9531
9398
|
const my = (p0[1] + p1[1]) / 2;
|
|
9532
9399
|
const err = Math.sqrt((ex - mx) ** 2 + (ey - my) ** 2);
|
|
@@ -9552,8 +9419,8 @@ function decomposeBSpline2dToBeziers(curve) {
|
|
|
9552
9419
|
];
|
|
9553
9420
|
const result = [];
|
|
9554
9421
|
for (let i = 0; i < breakpoints.length - 1; i++) {
|
|
9555
|
-
const t0 = breakpoints
|
|
9556
|
-
const t1 = breakpoints
|
|
9422
|
+
const t0 = wasmIndex(breakpoints, i);
|
|
9423
|
+
const t1 = wasmIndex(breakpoints, i + 1);
|
|
9557
9424
|
const span = t1 - t0;
|
|
9558
9425
|
if (span < 1e-15) continue;
|
|
9559
9426
|
const p0 = evaluateCurve2d$2(c, t0);
|
|
@@ -9704,13 +9571,13 @@ function liftCurve2dToPlane(bk, curve, origin, planeZ, planeX) {
|
|
|
9704
9571
|
const [eu, ev] = evaluateCurve2d$2(c, bounds.first + (seg + 1) * segmentSpan);
|
|
9705
9572
|
edgeIds.push(bk.makeCircleArc3d(...lift(su, sv), ...lift(eu, ev), ...center3d, ...axis));
|
|
9706
9573
|
}
|
|
9707
|
-
if (edgeIds.length === 1) return edgeHandle(edgeIds
|
|
9574
|
+
if (edgeIds.length === 1) return edgeHandle(wasmIndex(edgeIds, 0));
|
|
9708
9575
|
return wireHandle(bk.makeWire(edgeIds, false));
|
|
9709
9576
|
}
|
|
9710
9577
|
}
|
|
9711
9578
|
if (c.__bk2d === "bezier" || c.__bk2d === "bspline") {
|
|
9712
9579
|
const points3d = c.poles.map(([u, v]) => lift(u, v));
|
|
9713
|
-
if (points3d.length === 2) return makeLineEdge(bk, points3d
|
|
9580
|
+
if (points3d.length === 2) return makeLineEdge(bk, wasmIndex(points3d, 0), wasmIndex(points3d, 1));
|
|
9714
9581
|
const degree = Math.min(3, points3d.length - 1);
|
|
9715
9582
|
const coords = points3d.flatMap(([px, py, pz]) => [
|
|
9716
9583
|
px,
|
|
@@ -9737,58 +9604,40 @@ function buildEdgeOnSurface(bk, curve, surface) {
|
|
|
9737
9604
|
const points = [];
|
|
9738
9605
|
for (let i = 0; i <= N; i++) {
|
|
9739
9606
|
const [u, v] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / N);
|
|
9740
|
-
|
|
9741
|
-
points.push([
|
|
9742
|
-
p[0],
|
|
9743
|
-
p[1],
|
|
9744
|
-
p[2]
|
|
9745
|
-
]);
|
|
9607
|
+
points.push(vec3At(bk.evaluateSurface(fid, u, v)));
|
|
9746
9608
|
}
|
|
9747
9609
|
return interpolatePoints(bk, points);
|
|
9748
9610
|
}
|
|
9749
9611
|
function extractSurfaceFromFace(face) {
|
|
9750
9612
|
return face;
|
|
9751
9613
|
}
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
const MAX_N = 80;
|
|
9760
|
-
const REFINE_THRESHOLD = .05;
|
|
9761
|
-
const tValues = [];
|
|
9762
|
-
for (let i = 0; i <= BASE_N; i++) tValues.push(tMin + (tMax - tMin) * i / BASE_N);
|
|
9763
|
-
const evaluateUV = (t) => {
|
|
9764
|
-
const pt = bk.evaluateEdgeCurve(eid, t);
|
|
9765
|
-
const uv = bk.projectPointOnSurface(fid, pt[0], pt[1], pt[2]);
|
|
9766
|
-
return [uv[0], uv[1]];
|
|
9767
|
-
};
|
|
9768
|
-
const uvSamples = tValues.map((t) => ({
|
|
9769
|
-
t,
|
|
9770
|
-
uv: evaluateUV(t)
|
|
9771
|
-
}));
|
|
9614
|
+
/**
|
|
9615
|
+
* Adaptively refine a UV sample list by inserting midpoints whenever the
|
|
9616
|
+
* sampled UV midpoint deviates from the linear interpolation of its
|
|
9617
|
+
* neighbors by more than `threshold`. Stops at `maxSamples` or when no
|
|
9618
|
+
* pair exceeds the threshold; cap of 3 refinement passes overall.
|
|
9619
|
+
*/
|
|
9620
|
+
function refineUVSamples(uvSamples, evaluateUV, maxSamples, threshold) {
|
|
9772
9621
|
let refinements = 0;
|
|
9773
|
-
while (uvSamples.length <
|
|
9622
|
+
while (uvSamples.length < maxSamples) {
|
|
9774
9623
|
const insertions = [];
|
|
9775
9624
|
for (let i = 0; i < uvSamples.length - 1; i++) {
|
|
9776
|
-
const a = uvSamples
|
|
9777
|
-
const b = uvSamples
|
|
9625
|
+
const a = wasmIndex(uvSamples, i);
|
|
9626
|
+
const b = wasmIndex(uvSamples, i + 1);
|
|
9778
9627
|
const tMid = (a.t + b.t) / 2;
|
|
9779
9628
|
const uvMid = evaluateUV(tMid);
|
|
9780
9629
|
const interpU = (a.uv[0] + b.uv[0]) / 2;
|
|
9781
9630
|
const interpV = (a.uv[1] + b.uv[1]) / 2;
|
|
9782
|
-
if (Math.sqrt((uvMid[0] - interpU) ** 2 + (uvMid[1] - interpV) ** 2) >
|
|
9631
|
+
if (Math.sqrt((uvMid[0] - interpU) ** 2 + (uvMid[1] - interpV) ** 2) > threshold) insertions.push({
|
|
9783
9632
|
index: i + 1,
|
|
9784
9633
|
t: tMid,
|
|
9785
9634
|
uv: uvMid
|
|
9786
9635
|
});
|
|
9787
9636
|
}
|
|
9788
9637
|
if (insertions.length === 0) break;
|
|
9789
|
-
let budget =
|
|
9638
|
+
let budget = maxSamples - uvSamples.length;
|
|
9790
9639
|
for (let j = insertions.length - 1; j >= 0 && budget > 0; j--) {
|
|
9791
|
-
const ins = insertions
|
|
9640
|
+
const ins = wasmIndex(insertions, j);
|
|
9792
9641
|
uvSamples.splice(ins.index, 0, {
|
|
9793
9642
|
t: ins.t,
|
|
9794
9643
|
uv: ins.uv
|
|
@@ -9798,13 +9647,35 @@ function extractCurve2dFromEdge(bk, edge, face) {
|
|
|
9798
9647
|
refinements++;
|
|
9799
9648
|
if (refinements > 3) break;
|
|
9800
9649
|
}
|
|
9650
|
+
}
|
|
9651
|
+
function extractCurve2dFromEdge(bk, edge, face) {
|
|
9652
|
+
const eid = unwrap(edge, "edge");
|
|
9653
|
+
const fid = unwrap(face, "face");
|
|
9654
|
+
const params = bk.getEdgeCurveParameters(eid);
|
|
9655
|
+
const tMin = params[0] ?? 0;
|
|
9656
|
+
const tMax = params[1] ?? 1;
|
|
9657
|
+
const BASE_N = 20;
|
|
9658
|
+
const MAX_N = 80;
|
|
9659
|
+
const REFINE_THRESHOLD = .05;
|
|
9660
|
+
const tValues = [];
|
|
9661
|
+
for (let i = 0; i <= BASE_N; i++) tValues.push(tMin + (tMax - tMin) * i / BASE_N);
|
|
9662
|
+
const evaluateUV = (t) => {
|
|
9663
|
+
const pt = bk.evaluateEdgeCurve(eid, t);
|
|
9664
|
+
const uv = bk.projectPointOnSurface(fid, wasmIndex(pt, 0), wasmIndex(pt, 1), wasmIndex(pt, 2));
|
|
9665
|
+
return [wasmIndex(uv, 0), wasmIndex(uv, 1)];
|
|
9666
|
+
};
|
|
9667
|
+
const uvSamples = tValues.map((t) => ({
|
|
9668
|
+
t,
|
|
9669
|
+
uv: evaluateUV(t)
|
|
9670
|
+
}));
|
|
9671
|
+
refineUVSamples(uvSamples, evaluateUV, MAX_N, REFINE_THRESHOLD);
|
|
9801
9672
|
const uvPoints = uvSamples.map((s) => s.uv);
|
|
9802
9673
|
if (uvPoints.length >= 2) return makeBSpline2d(uvPoints);
|
|
9803
9674
|
const verts = bk.getEdgeVertices(eid);
|
|
9804
9675
|
if (verts.length >= 6) {
|
|
9805
|
-
const uv1 = bk.projectPointOnSurface(fid, verts
|
|
9806
|
-
const uv2 = bk.projectPointOnSurface(fid, verts
|
|
9807
|
-
return makeLine2d$2(uv1
|
|
9676
|
+
const uv1 = bk.projectPointOnSurface(fid, wasmIndex(verts, 0), wasmIndex(verts, 1), wasmIndex(verts, 2));
|
|
9677
|
+
const uv2 = bk.projectPointOnSurface(fid, wasmIndex(verts, 3), wasmIndex(verts, 4), wasmIndex(verts, 5));
|
|
9678
|
+
return makeLine2d$2(wasmIndex(uv1, 0), wasmIndex(uv1, 1), wasmIndex(uv2, 0), wasmIndex(uv2, 1));
|
|
9808
9679
|
}
|
|
9809
9680
|
throw new Error(`brepkit: extractCurve2dFromEdge: degenerate edge (${verts.length} coords)`);
|
|
9810
9681
|
}
|
|
@@ -9820,13 +9691,14 @@ function fillSurface(bk, wires, _options) {
|
|
|
9820
9691
|
for (const edge of wireEdges) {
|
|
9821
9692
|
const edgeId = unwrap(edge, "edge");
|
|
9822
9693
|
const params = bk.getEdgeCurveParameters(edgeId);
|
|
9823
|
-
const tMin = params
|
|
9694
|
+
const tMin = wasmIndex(params, 0);
|
|
9695
|
+
const tMax = wasmIndex(params, 1);
|
|
9824
9696
|
const N = 10;
|
|
9825
9697
|
const pts = [];
|
|
9826
9698
|
for (let i = 0; i <= N; i++) {
|
|
9827
9699
|
const t = tMin + (tMax - tMin) * i / N;
|
|
9828
9700
|
const p = bk.evaluateEdgeCurve(edgeId, t);
|
|
9829
|
-
pts.push(p
|
|
9701
|
+
pts.push(wasmIndex(p, 0), wasmIndex(p, 1), wasmIndex(p, 2));
|
|
9830
9702
|
}
|
|
9831
9703
|
allCoords.push(...pts);
|
|
9832
9704
|
curveLengths.push(N + 1);
|
|
@@ -10848,7 +10720,7 @@ async function init() {
|
|
|
10848
10720
|
throw new Error("brepjs: no kernel package found. Install one of:\n npm install brepjs-opencascade (recommended)\n npm install brepkit-wasm\n npm install occt-wasm (requires manual registerKernel)");
|
|
10849
10721
|
}
|
|
10850
10722
|
//#endregion
|
|
10851
|
-
//#region \0@oxc-project+runtime@0.
|
|
10723
|
+
//#region \0@oxc-project+runtime@0.128.0/helpers/usingCtx.js
|
|
10852
10724
|
function _usingCtx() {
|
|
10853
10725
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
10854
10726
|
var n = Error();
|