circuit-json-to-gltf 0.0.136 → 0.0.138
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/index.js +460 -177
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -204,11 +204,11 @@ var require_constants = __commonJS({
|
|
|
204
204
|
"node_modules/@jscad/modeling/src/maths/constants.js"(exports, module) {
|
|
205
205
|
"use strict";
|
|
206
206
|
var spatialResolution = 1e5;
|
|
207
|
-
var
|
|
207
|
+
var EPS4 = 1e-5;
|
|
208
208
|
var NEPS = 1e-13;
|
|
209
209
|
var TAU = Math.PI * 2;
|
|
210
210
|
module.exports = {
|
|
211
|
-
EPS:
|
|
211
|
+
EPS: EPS4,
|
|
212
212
|
NEPS,
|
|
213
213
|
TAU,
|
|
214
214
|
spatialResolution
|
|
@@ -259,13 +259,13 @@ var require_identity = __commonJS({
|
|
|
259
259
|
var require_fromRotation = __commonJS({
|
|
260
260
|
"node_modules/@jscad/modeling/src/maths/mat4/fromRotation.js"(exports, module) {
|
|
261
261
|
"use strict";
|
|
262
|
-
var { EPS:
|
|
262
|
+
var { EPS: EPS4 } = require_constants();
|
|
263
263
|
var { sin, cos } = require_trigonometry();
|
|
264
264
|
var identity = require_identity();
|
|
265
265
|
var fromRotation = (out, rad, axis) => {
|
|
266
266
|
let [x, y, z] = axis;
|
|
267
267
|
const lengthSquared = x * x + y * y + z * z;
|
|
268
|
-
if (Math.abs(lengthSquared) <
|
|
268
|
+
if (Math.abs(lengthSquared) < EPS4) {
|
|
269
269
|
return identity(out);
|
|
270
270
|
}
|
|
271
271
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
@@ -1192,13 +1192,13 @@ var require_multiply2 = __commonJS({
|
|
|
1192
1192
|
var require_rotate = __commonJS({
|
|
1193
1193
|
"node_modules/@jscad/modeling/src/maths/mat4/rotate.js"(exports, module) {
|
|
1194
1194
|
"use strict";
|
|
1195
|
-
var { EPS:
|
|
1195
|
+
var { EPS: EPS4 } = require_constants();
|
|
1196
1196
|
var { sin, cos } = require_trigonometry();
|
|
1197
1197
|
var copy = require_copy();
|
|
1198
1198
|
var rotate = (out, matrix, radians, axis) => {
|
|
1199
1199
|
let [x, y, z] = axis;
|
|
1200
1200
|
const lengthSquared = x * x + y * y + z * z;
|
|
1201
|
-
if (Math.abs(lengthSquared) <
|
|
1201
|
+
if (Math.abs(lengthSquared) < EPS4) {
|
|
1202
1202
|
return copy(out, matrix);
|
|
1203
1203
|
}
|
|
1204
1204
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
@@ -3687,19 +3687,19 @@ var require_fromPoints3 = __commonJS({
|
|
|
3687
3687
|
var require_fromPointsRandom = __commonJS({
|
|
3688
3688
|
"node_modules/@jscad/modeling/src/maths/plane/fromPointsRandom.js"(exports, module) {
|
|
3689
3689
|
"use strict";
|
|
3690
|
-
var { EPS:
|
|
3690
|
+
var { EPS: EPS4 } = require_constants();
|
|
3691
3691
|
var vec3 = require_vec3();
|
|
3692
3692
|
var fromPointsRandom = (out, a, b, c) => {
|
|
3693
3693
|
let ba = vec3.subtract(vec3.create(), b, a);
|
|
3694
3694
|
let ca = vec3.subtract(vec3.create(), c, a);
|
|
3695
|
-
if (vec3.length(ba) <
|
|
3695
|
+
if (vec3.length(ba) < EPS4) {
|
|
3696
3696
|
ba = vec3.orthogonal(ba, ca);
|
|
3697
3697
|
}
|
|
3698
|
-
if (vec3.length(ca) <
|
|
3698
|
+
if (vec3.length(ca) < EPS4) {
|
|
3699
3699
|
ca = vec3.orthogonal(ca, ba);
|
|
3700
3700
|
}
|
|
3701
3701
|
let normal = vec3.cross(vec3.create(), ba, ca);
|
|
3702
|
-
if (vec3.length(normal) <
|
|
3702
|
+
if (vec3.length(normal) < EPS4) {
|
|
3703
3703
|
ca = vec3.orthogonal(ca, ba);
|
|
3704
3704
|
normal = vec3.cross(normal, ba, ca);
|
|
3705
3705
|
}
|
|
@@ -4382,7 +4382,7 @@ var require_isA3 = __commonJS({
|
|
|
4382
4382
|
var require_isConvex2 = __commonJS({
|
|
4383
4383
|
"node_modules/@jscad/modeling/src/geometries/geom3/isConvex.js"(exports, module) {
|
|
4384
4384
|
"use strict";
|
|
4385
|
-
var { EPS:
|
|
4385
|
+
var { EPS: EPS4 } = require_constants();
|
|
4386
4386
|
var vec3 = require_vec3();
|
|
4387
4387
|
var geom35 = require_isA3();
|
|
4388
4388
|
var toPolygons5 = require_toPolygons();
|
|
@@ -4413,7 +4413,7 @@ var require_isConvex2 = __commonJS({
|
|
|
4413
4413
|
for (let j = 0; j < vertices.length; j++) {
|
|
4414
4414
|
const v = vertices[j];
|
|
4415
4415
|
const distance = vec3.dot(plane, v) - plane[3];
|
|
4416
|
-
if (distance >
|
|
4416
|
+
if (distance > EPS4) {
|
|
4417
4417
|
return false;
|
|
4418
4418
|
}
|
|
4419
4419
|
}
|
|
@@ -4605,7 +4605,7 @@ var require_clone8 = __commonJS({
|
|
|
4605
4605
|
var require_close = __commonJS({
|
|
4606
4606
|
"node_modules/@jscad/modeling/src/geometries/path2/close.js"(exports, module) {
|
|
4607
4607
|
"use strict";
|
|
4608
|
-
var { EPS:
|
|
4608
|
+
var { EPS: EPS4 } = require_constants();
|
|
4609
4609
|
var vec2 = require_vec2();
|
|
4610
4610
|
var clone = require_clone8();
|
|
4611
4611
|
var close = (geometry) => {
|
|
@@ -4616,7 +4616,7 @@ var require_close = __commonJS({
|
|
|
4616
4616
|
const points = cloned.points;
|
|
4617
4617
|
const p0 = points[0];
|
|
4618
4618
|
let pn = points[points.length - 1];
|
|
4619
|
-
while (vec2.distance(p0, pn) <
|
|
4619
|
+
while (vec2.distance(p0, pn) < EPS4 * EPS4) {
|
|
4620
4620
|
points.pop();
|
|
4621
4621
|
if (points.length === 1) break;
|
|
4622
4622
|
pn = points[points.length - 1];
|
|
@@ -4651,7 +4651,7 @@ var require_create8 = __commonJS({
|
|
|
4651
4651
|
var require_fromPoints5 = __commonJS({
|
|
4652
4652
|
"node_modules/@jscad/modeling/src/geometries/path2/fromPoints.js"(exports, module) {
|
|
4653
4653
|
"use strict";
|
|
4654
|
-
var { EPS:
|
|
4654
|
+
var { EPS: EPS4 } = require_constants();
|
|
4655
4655
|
var vec2 = require_vec2();
|
|
4656
4656
|
var close = require_close();
|
|
4657
4657
|
var create = require_create8();
|
|
@@ -4663,7 +4663,7 @@ var require_fromPoints5 = __commonJS({
|
|
|
4663
4663
|
if (created.points.length > 1) {
|
|
4664
4664
|
const p0 = created.points[0];
|
|
4665
4665
|
const pn = created.points[created.points.length - 1];
|
|
4666
|
-
if (vec2.distance(p0, pn) <
|
|
4666
|
+
if (vec2.distance(p0, pn) < EPS4 * EPS4) {
|
|
4667
4667
|
closed = true;
|
|
4668
4668
|
}
|
|
4669
4669
|
}
|
|
@@ -6490,12 +6490,12 @@ var require_fromPlanes = __commonJS({
|
|
|
6490
6490
|
"use strict";
|
|
6491
6491
|
var vec3 = require_vec3();
|
|
6492
6492
|
var { solve2Linear } = require_utils();
|
|
6493
|
-
var { EPS:
|
|
6493
|
+
var { EPS: EPS4 } = require_constants();
|
|
6494
6494
|
var fromPointAndDirection = require_fromPointAndDirection();
|
|
6495
6495
|
var fromPlanes = (out, plane1, plane2) => {
|
|
6496
6496
|
let direction = vec3.cross(vec3.create(), plane1, plane2);
|
|
6497
6497
|
let length = vec3.length(direction);
|
|
6498
|
-
if (length <
|
|
6498
|
+
if (length < EPS4) {
|
|
6499
6499
|
throw new Error("parallel planes do not intersect");
|
|
6500
6500
|
}
|
|
6501
6501
|
length = 1 / length;
|
|
@@ -6834,13 +6834,13 @@ var require_measureAggregateBoundingBox = __commonJS({
|
|
|
6834
6834
|
var require_calculateEpsilonFromBounds = __commonJS({
|
|
6835
6835
|
"node_modules/@jscad/modeling/src/measurements/calculateEpsilonFromBounds.js"(exports, module) {
|
|
6836
6836
|
"use strict";
|
|
6837
|
-
var { EPS:
|
|
6837
|
+
var { EPS: EPS4 } = require_constants();
|
|
6838
6838
|
var calculateEpsilonFromBounds = (bounds, dimensions) => {
|
|
6839
6839
|
let total = 0;
|
|
6840
6840
|
for (let i = 0; i < dimensions; i++) {
|
|
6841
6841
|
total += bounds[1][i] - bounds[0][i];
|
|
6842
6842
|
}
|
|
6843
|
-
return
|
|
6843
|
+
return EPS4 * total / dimensions;
|
|
6844
6844
|
};
|
|
6845
6845
|
module.exports = calculateEpsilonFromBounds;
|
|
6846
6846
|
}
|
|
@@ -7209,7 +7209,7 @@ var require_commonChecks = __commonJS({
|
|
|
7209
7209
|
var require_arc = __commonJS({
|
|
7210
7210
|
"node_modules/@jscad/modeling/src/primitives/arc.js"(exports, module) {
|
|
7211
7211
|
"use strict";
|
|
7212
|
-
var { EPS:
|
|
7212
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7213
7213
|
var vec2 = require_vec2();
|
|
7214
7214
|
var path2 = require_path2();
|
|
7215
7215
|
var { isGT, isGTE, isNumberArray } = require_commonChecks();
|
|
@@ -7237,7 +7237,7 @@ var require_arc = __commonJS({
|
|
|
7237
7237
|
if (startAngle > endAngle) {
|
|
7238
7238
|
rotation = endAngle + (TAU - startAngle);
|
|
7239
7239
|
}
|
|
7240
|
-
const minangle = Math.acos((radius * radius + radius * radius -
|
|
7240
|
+
const minangle = Math.acos((radius * radius + radius * radius - EPS4 * EPS4) / (2 * radius * radius));
|
|
7241
7241
|
const centerv = vec2.clone(center);
|
|
7242
7242
|
let point;
|
|
7243
7243
|
const pointArray = [];
|
|
@@ -7275,7 +7275,7 @@ var require_arc = __commonJS({
|
|
|
7275
7275
|
var require_ellipse = __commonJS({
|
|
7276
7276
|
"node_modules/@jscad/modeling/src/primitives/ellipse.js"(exports, module) {
|
|
7277
7277
|
"use strict";
|
|
7278
|
-
var { EPS:
|
|
7278
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7279
7279
|
var vec2 = require_vec2();
|
|
7280
7280
|
var geom2 = require_geom2();
|
|
7281
7281
|
var { sin, cos } = require_trigonometry();
|
|
@@ -7306,7 +7306,7 @@ var require_ellipse = __commonJS({
|
|
|
7306
7306
|
rotation = endAngle + (TAU - startAngle);
|
|
7307
7307
|
}
|
|
7308
7308
|
const minradius = Math.min(radius[0], radius[1]);
|
|
7309
|
-
const minangle = Math.acos((minradius * minradius + minradius * minradius -
|
|
7309
|
+
const minangle = Math.acos((minradius * minradius + minradius * minradius - EPS4 * EPS4) / (2 * minradius * minradius));
|
|
7310
7310
|
if (rotation < minangle) throw new Error("startAngle and endAngle do not define a significant rotation");
|
|
7311
7311
|
segments = Math.floor(segments * (rotation / TAU));
|
|
7312
7312
|
const centerv = vec2.clone(center);
|
|
@@ -7418,7 +7418,7 @@ var require_cube = __commonJS({
|
|
|
7418
7418
|
var require_cylinderElliptic = __commonJS({
|
|
7419
7419
|
"node_modules/@jscad/modeling/src/primitives/cylinderElliptic.js"(exports, module) {
|
|
7420
7420
|
"use strict";
|
|
7421
|
-
var { EPS:
|
|
7421
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7422
7422
|
var vec3 = require_vec3();
|
|
7423
7423
|
var geom35 = require_geom3();
|
|
7424
7424
|
var poly3 = require_poly3();
|
|
@@ -7455,7 +7455,7 @@ var require_cylinderElliptic = __commonJS({
|
|
|
7455
7455
|
rotation = endAngle + (TAU - startAngle);
|
|
7456
7456
|
}
|
|
7457
7457
|
const minradius = Math.min(startRadius[0], startRadius[1], endRadius[0], endRadius[1]);
|
|
7458
|
-
const minangle = Math.acos((minradius * minradius + minradius * minradius -
|
|
7458
|
+
const minangle = Math.acos((minradius * minradius + minradius * minradius - EPS4 * EPS4) / (2 * minradius * minradius));
|
|
7459
7459
|
if (rotation < minangle) throw new Error("startAngle and endAngle do not define a significant rotation");
|
|
7460
7460
|
const slices = Math.floor(segments * (rotation / TAU));
|
|
7461
7461
|
const start = vec3.fromValues(0, 0, -(height / 2));
|
|
@@ -7904,7 +7904,7 @@ var require_rectangle = __commonJS({
|
|
|
7904
7904
|
var require_roundedCuboid = __commonJS({
|
|
7905
7905
|
"node_modules/@jscad/modeling/src/primitives/roundedCuboid.js"(exports, module) {
|
|
7906
7906
|
"use strict";
|
|
7907
|
-
var { EPS:
|
|
7907
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7908
7908
|
var vec2 = require_vec2();
|
|
7909
7909
|
var vec3 = require_vec3();
|
|
7910
7910
|
var geom35 = require_geom3();
|
|
@@ -7920,7 +7920,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
7920
7920
|
let layerradius = radius * cospitch;
|
|
7921
7921
|
let layeroffset = size[2] - (radius - radius * sinpitch);
|
|
7922
7922
|
if (!positive) layeroffset = radius - radius * sinpitch - size[2];
|
|
7923
|
-
layerradius = layerradius >
|
|
7923
|
+
layerradius = layerradius > EPS4 ? layerradius : 0;
|
|
7924
7924
|
const corner0 = vec3.add(vec3.create(), center, [size[0] - radius, size[1] - radius, layeroffset]);
|
|
7925
7925
|
const corner1 = vec3.add(vec3.create(), center, [radius - size[0], size[1] - radius, layeroffset]);
|
|
7926
7926
|
const corner2 = vec3.add(vec3.create(), center, [radius - size[0], radius - size[1], layeroffset]);
|
|
@@ -8015,7 +8015,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
8015
8015
|
if (size[0] === 0 || size[1] === 0 || size[2] === 0) return geom35.create();
|
|
8016
8016
|
if (roundRadius === 0) return cuboid({ center, size });
|
|
8017
8017
|
size = size.map((v) => v / 2);
|
|
8018
|
-
if (roundRadius > size[0] -
|
|
8018
|
+
if (roundRadius > size[0] - EPS4 || roundRadius > size[1] - EPS4 || roundRadius > size[2] - EPS4) throw new Error("roundRadius must be smaller than the radius of all dimensions");
|
|
8019
8019
|
segments = Math.floor(segments / 4);
|
|
8020
8020
|
let prevCornersPos = null;
|
|
8021
8021
|
let prevCornersNeg = null;
|
|
@@ -8057,7 +8057,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
8057
8057
|
var require_roundedCylinder = __commonJS({
|
|
8058
8058
|
"node_modules/@jscad/modeling/src/primitives/roundedCylinder.js"(exports, module) {
|
|
8059
8059
|
"use strict";
|
|
8060
|
-
var { EPS:
|
|
8060
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
8061
8061
|
var vec3 = require_vec3();
|
|
8062
8062
|
var geom35 = require_geom3();
|
|
8063
8063
|
var poly3 = require_poly3();
|
|
@@ -8085,7 +8085,7 @@ var require_roundedCylinder = __commonJS({
|
|
|
8085
8085
|
const end = [0, 0, height / 2];
|
|
8086
8086
|
const direction = vec3.subtract(vec3.create(), end, start);
|
|
8087
8087
|
const length = vec3.length(direction);
|
|
8088
|
-
if (2 * roundRadius > length -
|
|
8088
|
+
if (2 * roundRadius > length - EPS4) throw new Error("height must be larger than twice roundRadius");
|
|
8089
8089
|
let defaultnormal;
|
|
8090
8090
|
if (Math.abs(direction[0]) > Math.abs(direction[1])) {
|
|
8091
8091
|
defaultnormal = vec3.fromValues(0, 1, 0);
|
|
@@ -8170,7 +8170,7 @@ var require_roundedCylinder = __commonJS({
|
|
|
8170
8170
|
var require_roundedRectangle = __commonJS({
|
|
8171
8171
|
"node_modules/@jscad/modeling/src/primitives/roundedRectangle.js"(exports, module) {
|
|
8172
8172
|
"use strict";
|
|
8173
|
-
var { EPS:
|
|
8173
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
8174
8174
|
var vec2 = require_vec2();
|
|
8175
8175
|
var geom2 = require_geom2();
|
|
8176
8176
|
var { isGTE, isNumberArray } = require_commonChecks();
|
|
@@ -8191,7 +8191,7 @@ var require_roundedRectangle = __commonJS({
|
|
|
8191
8191
|
if (size[0] === 0 || size[1] === 0) return geom2.create();
|
|
8192
8192
|
if (roundRadius === 0) return rectangle3({ center, size });
|
|
8193
8193
|
size = size.map((v) => v / 2);
|
|
8194
|
-
if (roundRadius > size[0] -
|
|
8194
|
+
if (roundRadius > size[0] - EPS4 || roundRadius > size[1] - EPS4) throw new Error("roundRadius must be smaller than the radius of all dimensions");
|
|
8195
8195
|
const cornersegments = Math.floor(segments / 4);
|
|
8196
8196
|
const corner0 = vec2.add(vec2.create(), center, [size[0] - roundRadius, size[1] - roundRadius]);
|
|
8197
8197
|
const corner1 = vec2.add(vec2.create(), center, [roundRadius - size[0], size[1] - roundRadius]);
|
|
@@ -9255,7 +9255,7 @@ var require_repair = __commonJS({
|
|
|
9255
9255
|
var require_extrudeWalls = __commonJS({
|
|
9256
9256
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeWalls.js"(exports, module) {
|
|
9257
9257
|
"use strict";
|
|
9258
|
-
var { EPS:
|
|
9258
|
+
var { EPS: EPS4 } = require_constants();
|
|
9259
9259
|
var vec3 = require_vec3();
|
|
9260
9260
|
var poly3 = require_poly3();
|
|
9261
9261
|
var slice = require_slice();
|
|
@@ -9295,7 +9295,7 @@ var require_extrudeWalls = __commonJS({
|
|
|
9295
9295
|
});
|
|
9296
9296
|
return newEdges;
|
|
9297
9297
|
};
|
|
9298
|
-
var EPSAREA =
|
|
9298
|
+
var EPSAREA = EPS4 * EPS4 / 2 * Math.sin(Math.PI / 3);
|
|
9299
9299
|
var extrudeWalls = (slice0, slice1) => {
|
|
9300
9300
|
let edges0 = slice.toEdges(slice0);
|
|
9301
9301
|
let edges1 = slice.toEdges(slice1);
|
|
@@ -10278,7 +10278,7 @@ var require_OrthoNormalBasis = __commonJS({
|
|
|
10278
10278
|
var require_reTesselateCoplanarPolygons = __commonJS({
|
|
10279
10279
|
"node_modules/@jscad/modeling/src/operations/modifiers/reTesselateCoplanarPolygons.js"(exports, module) {
|
|
10280
10280
|
"use strict";
|
|
10281
|
-
var { EPS:
|
|
10281
|
+
var { EPS: EPS4 } = require_constants();
|
|
10282
10282
|
var line2 = require_line2();
|
|
10283
10283
|
var vec2 = require_vec2();
|
|
10284
10284
|
var OrthoNormalBasis = require_OrthoNormalBasis();
|
|
@@ -10296,7 +10296,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10296
10296
|
const topy2polygonindexes = /* @__PURE__ */ new Map();
|
|
10297
10297
|
const ycoordinatetopolygonindexes = /* @__PURE__ */ new Map();
|
|
10298
10298
|
const ycoordinatebins = /* @__PURE__ */ new Map();
|
|
10299
|
-
const ycoordinateBinningFactor = 10 /
|
|
10299
|
+
const ycoordinateBinningFactor = 10 / EPS4;
|
|
10300
10300
|
for (let polygonindex = 0; polygonindex < numpolygons; polygonindex++) {
|
|
10301
10301
|
const poly3d = sourcepolygons[polygonindex];
|
|
10302
10302
|
let vertices2d = [];
|
|
@@ -10476,7 +10476,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10476
10476
|
const prevoutpolygon = newoutpolygonrow[newoutpolygonrow.length - 1];
|
|
10477
10477
|
const d1 = vec2.distance(outpolygon.topleft, prevoutpolygon.topright);
|
|
10478
10478
|
const d2 = vec2.distance(outpolygon.bottomleft, prevoutpolygon.bottomright);
|
|
10479
|
-
if (d1 <
|
|
10479
|
+
if (d1 < EPS4 && d2 < EPS4) {
|
|
10480
10480
|
outpolygon.topleft = prevoutpolygon.topleft;
|
|
10481
10481
|
outpolygon.leftline = prevoutpolygon.leftline;
|
|
10482
10482
|
outpolygon.bottomleft = prevoutpolygon.bottomleft;
|
|
@@ -10493,8 +10493,8 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10493
10493
|
for (let ii = 0; ii < prevoutpolygonrow.length; ii++) {
|
|
10494
10494
|
if (!matchedindexes.has(ii)) {
|
|
10495
10495
|
const prevpolygon = prevoutpolygonrow[ii];
|
|
10496
|
-
if (vec2.distance(prevpolygon.bottomleft, thispolygon.topleft) <
|
|
10497
|
-
if (vec2.distance(prevpolygon.bottomright, thispolygon.topright) <
|
|
10496
|
+
if (vec2.distance(prevpolygon.bottomleft, thispolygon.topleft) < EPS4) {
|
|
10497
|
+
if (vec2.distance(prevpolygon.bottomright, thispolygon.topright) < EPS4) {
|
|
10498
10498
|
matchedindexes.add(ii);
|
|
10499
10499
|
const v1 = line2.direction(thispolygon.leftline);
|
|
10500
10500
|
const v2 = line2.direction(prevpolygon.leftline);
|
|
@@ -10502,8 +10502,8 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10502
10502
|
const v3 = line2.direction(thispolygon.rightline);
|
|
10503
10503
|
const v4 = line2.direction(prevpolygon.rightline);
|
|
10504
10504
|
const d2 = v3[0] - v4[0];
|
|
10505
|
-
const leftlinecontinues = Math.abs(d1) <
|
|
10506
|
-
const rightlinecontinues = Math.abs(d2) <
|
|
10505
|
+
const leftlinecontinues = Math.abs(d1) < EPS4;
|
|
10506
|
+
const rightlinecontinues = Math.abs(d2) < EPS4;
|
|
10507
10507
|
const leftlineisconvex = leftlinecontinues || d1 >= 0;
|
|
10508
10508
|
const rightlineisconvex = rightlinecontinues || d2 >= 0;
|
|
10509
10509
|
if (leftlineisconvex && rightlineisconvex) {
|
|
@@ -10522,7 +10522,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10522
10522
|
if (!prevcontinuedindexes.has(ii)) {
|
|
10523
10523
|
const prevpolygon = prevoutpolygonrow[ii];
|
|
10524
10524
|
prevpolygon.outpolygon.rightpoints.push(prevpolygon.bottomright);
|
|
10525
|
-
if (vec2.distance(prevpolygon.bottomright, prevpolygon.bottomleft) >
|
|
10525
|
+
if (vec2.distance(prevpolygon.bottomright, prevpolygon.bottomleft) > EPS4) {
|
|
10526
10526
|
prevpolygon.outpolygon.leftpoints.push(prevpolygon.bottomleft);
|
|
10527
10527
|
}
|
|
10528
10528
|
prevpolygon.outpolygon.leftpoints.reverse();
|
|
@@ -10541,7 +10541,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10541
10541
|
rightpoints: []
|
|
10542
10542
|
};
|
|
10543
10543
|
thispolygon.outpolygon.leftpoints.push(thispolygon.topleft);
|
|
10544
|
-
if (vec2.distance(thispolygon.topleft, thispolygon.topright) >
|
|
10544
|
+
if (vec2.distance(thispolygon.topleft, thispolygon.topright) > EPS4) {
|
|
10545
10545
|
thispolygon.outpolygon.rightpoints.push(thispolygon.topright);
|
|
10546
10546
|
}
|
|
10547
10547
|
} else {
|
|
@@ -10642,7 +10642,7 @@ var require_retessellate = __commonJS({
|
|
|
10642
10642
|
var require_mayOverlap = __commonJS({
|
|
10643
10643
|
"node_modules/@jscad/modeling/src/operations/booleans/mayOverlap.js"(exports, module) {
|
|
10644
10644
|
"use strict";
|
|
10645
|
-
var { EPS:
|
|
10645
|
+
var { EPS: EPS4 } = require_constants();
|
|
10646
10646
|
var measureBoundingBox3 = require_measureBoundingBox2();
|
|
10647
10647
|
var mayOverlap = (geometry1, geometry2) => {
|
|
10648
10648
|
if (geometry1.polygons.length === 0 || geometry2.polygons.length === 0) {
|
|
@@ -10654,12 +10654,12 @@ var require_mayOverlap = __commonJS({
|
|
|
10654
10654
|
const bounds2 = measureBoundingBox3(geometry2);
|
|
10655
10655
|
const min2 = bounds2[0];
|
|
10656
10656
|
const max2 = bounds2[1];
|
|
10657
|
-
if (min2[0] - max1[0] >
|
|
10658
|
-
if (min1[0] - max2[0] >
|
|
10659
|
-
if (min2[1] - max1[1] >
|
|
10660
|
-
if (min1[1] - max2[1] >
|
|
10661
|
-
if (min2[2] - max1[2] >
|
|
10662
|
-
if (min1[2] - max2[2] >
|
|
10657
|
+
if (min2[0] - max1[0] > EPS4) return false;
|
|
10658
|
+
if (min1[0] - max2[0] > EPS4) return false;
|
|
10659
|
+
if (min2[1] - max1[1] > EPS4) return false;
|
|
10660
|
+
if (min1[1] - max2[1] > EPS4) return false;
|
|
10661
|
+
if (min2[2] - max1[2] > EPS4) return false;
|
|
10662
|
+
if (min1[2] - max2[2] > EPS4) return false;
|
|
10663
10663
|
return true;
|
|
10664
10664
|
};
|
|
10665
10665
|
module.exports = mayOverlap;
|
|
@@ -10809,12 +10809,12 @@ var require_splitLineSegmentByPlane = __commonJS({
|
|
|
10809
10809
|
var require_splitPolygonByPlane = __commonJS({
|
|
10810
10810
|
"node_modules/@jscad/modeling/src/operations/booleans/trees/splitPolygonByPlane.js"(exports, module) {
|
|
10811
10811
|
"use strict";
|
|
10812
|
-
var { EPS:
|
|
10812
|
+
var { EPS: EPS4 } = require_constants();
|
|
10813
10813
|
var plane = require_plane();
|
|
10814
10814
|
var vec3 = require_vec3();
|
|
10815
10815
|
var poly3 = require_poly3();
|
|
10816
10816
|
var splitLineSegmentByPlane = require_splitLineSegmentByPlane();
|
|
10817
|
-
var EPS_SQUARED =
|
|
10817
|
+
var EPS_SQUARED = EPS4 * EPS4;
|
|
10818
10818
|
var removeConsecutiveDuplicates = (vertices) => {
|
|
10819
10819
|
const result = [];
|
|
10820
10820
|
let prevvertex = vertices[vertices.length - 1];
|
|
@@ -10842,12 +10842,12 @@ var require_splitPolygonByPlane = __commonJS({
|
|
|
10842
10842
|
let hasfront = false;
|
|
10843
10843
|
let hasback = false;
|
|
10844
10844
|
const vertexIsBack = [];
|
|
10845
|
-
const MINEPS = -
|
|
10845
|
+
const MINEPS = -EPS4;
|
|
10846
10846
|
for (let i = 0; i < numvertices; i++) {
|
|
10847
10847
|
const t = vec3.dot(splane, vertices[i]) - splane[3];
|
|
10848
10848
|
const isback = t < MINEPS;
|
|
10849
10849
|
vertexIsBack.push(isback);
|
|
10850
|
-
if (t >
|
|
10850
|
+
if (t > EPS4) hasfront = true;
|
|
10851
10851
|
if (t < MINEPS) hasback = true;
|
|
10852
10852
|
}
|
|
10853
10853
|
if (!hasfront && !hasback) {
|
|
@@ -10912,7 +10912,7 @@ var require_splitPolygonByPlane = __commonJS({
|
|
|
10912
10912
|
var require_PolygonTreeNode = __commonJS({
|
|
10913
10913
|
"node_modules/@jscad/modeling/src/operations/booleans/trees/PolygonTreeNode.js"(exports, module) {
|
|
10914
10914
|
"use strict";
|
|
10915
|
-
var { EPS:
|
|
10915
|
+
var { EPS: EPS4 } = require_constants();
|
|
10916
10916
|
var vec3 = require_vec3();
|
|
10917
10917
|
var poly3 = require_poly3();
|
|
10918
10918
|
var splitPolygonByPlane = require_splitPolygonByPlane();
|
|
@@ -11015,7 +11015,7 @@ var require_PolygonTreeNode = __commonJS({
|
|
|
11015
11015
|
const polygon3 = this.polygon;
|
|
11016
11016
|
if (polygon3) {
|
|
11017
11017
|
const bound = poly3.measureBoundingSphere(polygon3);
|
|
11018
|
-
const sphereradius = bound[3] +
|
|
11018
|
+
const sphereradius = bound[3] + EPS4;
|
|
11019
11019
|
const spherecenter = bound;
|
|
11020
11020
|
const d = vec3.dot(splane, spherecenter) - splane[3];
|
|
11021
11021
|
if (d > sphereradius) {
|
|
@@ -11731,7 +11731,7 @@ var require_booleans = __commonJS({
|
|
|
11731
11731
|
var require_offsetFromPoints = __commonJS({
|
|
11732
11732
|
"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(exports, module) {
|
|
11733
11733
|
"use strict";
|
|
11734
|
-
var { EPS:
|
|
11734
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
11735
11735
|
var intersect = require_intersect();
|
|
11736
11736
|
var line2 = require_line2();
|
|
11737
11737
|
var vec2 = require_vec2();
|
|
@@ -11744,7 +11744,7 @@ var require_offsetFromPoints = __commonJS({
|
|
|
11744
11744
|
segments: 16
|
|
11745
11745
|
};
|
|
11746
11746
|
let { delta, corners, closed, segments } = Object.assign({}, defaults, options);
|
|
11747
|
-
if (Math.abs(delta) <
|
|
11747
|
+
if (Math.abs(delta) < EPS4) return points;
|
|
11748
11748
|
let rotation = options.closed ? area(points) : 1;
|
|
11749
11749
|
if (rotation === 0) rotation = 1;
|
|
11750
11750
|
const orientation = rotation > 0 && delta >= 0 || rotation < 0 && delta < 0;
|
|
@@ -11931,7 +11931,7 @@ var require_extrudePolygon = __commonJS({
|
|
|
11931
11931
|
var require_expandShell = __commonJS({
|
|
11932
11932
|
"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(exports, module) {
|
|
11933
11933
|
"use strict";
|
|
11934
|
-
var { EPS:
|
|
11934
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
11935
11935
|
var mat4 = require_mat4();
|
|
11936
11936
|
var vec3 = require_vec3();
|
|
11937
11937
|
var fnNumberSort = require_fnNumberSort();
|
|
@@ -12036,7 +12036,7 @@ var require_expandShell = __commonJS({
|
|
|
12036
12036
|
const p2 = vec3.add(vec3.create(), endpoint, v1);
|
|
12037
12037
|
let skip = false;
|
|
12038
12038
|
if (i >= 0) {
|
|
12039
|
-
if (vec3.distance(p1, prevp1) <
|
|
12039
|
+
if (vec3.distance(p1, prevp1) < EPS4) {
|
|
12040
12040
|
skip = true;
|
|
12041
12041
|
}
|
|
12042
12042
|
}
|
|
@@ -13698,30 +13698,187 @@ var require_src = __commonJS({
|
|
|
13698
13698
|
|
|
13699
13699
|
// node_modules/@tscircuit/flex-utils/dist/index.js
|
|
13700
13700
|
import earcut from "earcut";
|
|
13701
|
+
var PcbFoldError = class extends Error {
|
|
13702
|
+
constructor(issue) {
|
|
13703
|
+
super(issue.message);
|
|
13704
|
+
this.issue = issue;
|
|
13705
|
+
this.name = "PcbFoldError";
|
|
13706
|
+
}
|
|
13707
|
+
issue;
|
|
13708
|
+
};
|
|
13709
|
+
function capturePcbFoldResult(fold) {
|
|
13710
|
+
try {
|
|
13711
|
+
return { ok: true, value: fold() };
|
|
13712
|
+
} catch (error) {
|
|
13713
|
+
if (!(error instanceof PcbFoldError)) throw error;
|
|
13714
|
+
return { ok: false, issue: error.issue };
|
|
13715
|
+
}
|
|
13716
|
+
}
|
|
13701
13717
|
var EPS = 1e-7;
|
|
13702
|
-
|
|
13718
|
+
var samePoint = (a, b) => Math.hypot(a.x - b.x, a.y - b.y) < EPS;
|
|
13719
|
+
function pointInPolygon(point, polygon3, includeBoundary = true) {
|
|
13720
|
+
let inside = false;
|
|
13721
|
+
for (let i = 0; i < polygon3.length; i++) {
|
|
13722
|
+
const a = polygon3[i], b = polygon3[(i + 1) % polygon3.length];
|
|
13723
|
+
const cross2 = (point.x - a.x) * (b.y - a.y) - (point.y - a.y) * (b.x - a.x);
|
|
13724
|
+
if (Math.abs(cross2) < EPS * Math.max(1, Math.hypot(b.x - a.x, b.y - a.y)) && point.x >= Math.min(a.x, b.x) - EPS && point.x <= Math.max(a.x, b.x) + EPS && point.y >= Math.min(a.y, b.y) - EPS && point.y <= Math.max(a.y, b.y) + EPS)
|
|
13725
|
+
return includeBoundary;
|
|
13726
|
+
if (a.y > point.y !== b.y > point.y && point.x < a.x + (b.x - a.x) * (point.y - a.y) / (b.y - a.y))
|
|
13727
|
+
inside = !inside;
|
|
13728
|
+
}
|
|
13729
|
+
return inside;
|
|
13730
|
+
}
|
|
13731
|
+
function lineCrossings(outline, nx, ny, d) {
|
|
13732
|
+
const crossings = [];
|
|
13733
|
+
for (let edge = 0; edge < outline.length; edge++) {
|
|
13734
|
+
const a = outline[edge], b = outline[(edge + 1) % outline.length];
|
|
13735
|
+
const da = a.x * nx + a.y * ny - d, db = b.x * nx + b.y * ny - d;
|
|
13736
|
+
if (Math.abs(da) < EPS && Math.abs(db) < EPS) continue;
|
|
13737
|
+
if (da > EPS && db > EPS || da < -EPS && db < -EPS) continue;
|
|
13738
|
+
if (Math.abs(da - db) < EPS) continue;
|
|
13739
|
+
const fraction = Math.max(0, Math.min(1, da / (da - db)));
|
|
13740
|
+
const point = {
|
|
13741
|
+
x: a.x + (b.x - a.x) * fraction,
|
|
13742
|
+
y: a.y + (b.y - a.y) * fraction
|
|
13743
|
+
};
|
|
13744
|
+
if (crossings.some((crossing) => samePoint(crossing.point, point))) continue;
|
|
13745
|
+
crossings.push(
|
|
13746
|
+
fraction > 1 - EPS ? { point: b, edge: (edge + 1) % outline.length, fraction: 0 } : { point, edge, fraction }
|
|
13747
|
+
);
|
|
13748
|
+
}
|
|
13749
|
+
return crossings.sort(
|
|
13750
|
+
(a, b) => -ny * a.point.x + nx * a.point.y - (-ny * b.point.x + nx * b.point.y)
|
|
13751
|
+
);
|
|
13752
|
+
}
|
|
13753
|
+
function movingPolygon(outline, a, b, nx, ny) {
|
|
13754
|
+
const polygon3 = [];
|
|
13755
|
+
for (let edge = 0; edge < outline.length; edge++) {
|
|
13756
|
+
polygon3.push(outline[edge]);
|
|
13757
|
+
for (const crossing of [a, b].filter((c) => c.edge === edge).sort((a2, b2) => a2.fraction - b2.fraction))
|
|
13758
|
+
if (crossing.fraction > EPS) polygon3.push(crossing.point);
|
|
13759
|
+
}
|
|
13760
|
+
const start = polygon3.findIndex((p) => samePoint(p, a.point));
|
|
13761
|
+
const end = polygon3.findIndex((p) => samePoint(p, b.point));
|
|
13762
|
+
if (start < 0 || end < 0)
|
|
13763
|
+
throw new Error("Cannot resolve PCB bend boundary crossings");
|
|
13764
|
+
const path = (from, to) => {
|
|
13765
|
+
const points = [polygon3[from]];
|
|
13766
|
+
while (from !== to) {
|
|
13767
|
+
from = (from + 1) % polygon3.length;
|
|
13768
|
+
points.push(polygon3[from]);
|
|
13769
|
+
}
|
|
13770
|
+
return points;
|
|
13771
|
+
};
|
|
13772
|
+
const area = outline.reduce((sum, p, i) => {
|
|
13773
|
+
const next = outline[(i + 1) % outline.length];
|
|
13774
|
+
return sum + p.x * next.y - next.x * p.y;
|
|
13775
|
+
}, 0);
|
|
13776
|
+
const side = Math.sign(area) * ((b.point.y - a.point.y) * nx - (b.point.x - a.point.x) * ny);
|
|
13777
|
+
return side > 0 ? path(start, end) : path(end, start);
|
|
13778
|
+
}
|
|
13779
|
+
function getFiniteBendRegion({
|
|
13780
|
+
bendId,
|
|
13781
|
+
outline,
|
|
13782
|
+
nx,
|
|
13783
|
+
ny,
|
|
13784
|
+
center,
|
|
13785
|
+
proximal,
|
|
13786
|
+
axisMin,
|
|
13787
|
+
axisMax
|
|
13788
|
+
}) {
|
|
13789
|
+
const finiteCrossings = lineCrossings(outline, nx, ny, center).filter(
|
|
13790
|
+
({ point }) => {
|
|
13791
|
+
const along = -ny * point.x + nx * point.y;
|
|
13792
|
+
return along >= axisMin - EPS && along <= axisMax + EPS;
|
|
13793
|
+
}
|
|
13794
|
+
);
|
|
13795
|
+
if (finiteCrossings.length !== 2)
|
|
13796
|
+
throw new PcbFoldError({
|
|
13797
|
+
code: "invalid_finite_bend_region",
|
|
13798
|
+
message: "A finite PCB bend must cut one board cross-section from boundary to boundary",
|
|
13799
|
+
bendId
|
|
13800
|
+
});
|
|
13801
|
+
const [a, b] = finiteCrossings;
|
|
13802
|
+
const middle = {
|
|
13803
|
+
x: (a.point.x + b.point.x) / 2,
|
|
13804
|
+
y: (a.point.y + b.point.y) / 2
|
|
13805
|
+
};
|
|
13806
|
+
if (!pointInPolygon(middle, outline, false))
|
|
13807
|
+
throw new PcbFoldError({
|
|
13808
|
+
code: "invalid_finite_bend_region",
|
|
13809
|
+
message: "A finite PCB bend must pass through the board interior",
|
|
13810
|
+
bendId
|
|
13811
|
+
});
|
|
13812
|
+
const centerRegion = movingPolygon(outline, a, b, nx, ny);
|
|
13813
|
+
const alongMiddle = -ny * middle.x + nx * middle.y;
|
|
13814
|
+
const proximalCrossings = lineCrossings(outline, nx, ny, proximal);
|
|
13815
|
+
for (let i = 0; i + 1 < proximalCrossings.length; i++) {
|
|
13816
|
+
const left = proximalCrossings[i], right = proximalCrossings[i + 1];
|
|
13817
|
+
const lo = -ny * left.point.x + nx * left.point.y;
|
|
13818
|
+
const hi = -ny * right.point.x + nx * right.point.y;
|
|
13819
|
+
if (alongMiddle <= lo + EPS || alongMiddle >= hi - EPS) continue;
|
|
13820
|
+
const midpoint = {
|
|
13821
|
+
x: (left.point.x + right.point.x) / 2,
|
|
13822
|
+
y: (left.point.y + right.point.y) / 2
|
|
13823
|
+
};
|
|
13824
|
+
if (!pointInPolygon(midpoint, outline, false)) continue;
|
|
13825
|
+
const region = movingPolygon(outline, left, right, nx, ny);
|
|
13826
|
+
if (region.some((p) => p.x * nx + p.y * ny < proximal - EPS) || centerRegion.some((p) => !pointInPolygon(p, region)) || region.some(
|
|
13827
|
+
(p) => p.x * nx + p.y * ny >= center - EPS && !pointInPolygon(p, centerRegion)
|
|
13828
|
+
))
|
|
13829
|
+
break;
|
|
13830
|
+
return region;
|
|
13831
|
+
}
|
|
13832
|
+
throw new PcbFoldError({
|
|
13833
|
+
code: "invalid_finite_bend_region",
|
|
13834
|
+
message: "The finite PCB bend zone must remain in one connected board cross-section",
|
|
13835
|
+
bendId
|
|
13836
|
+
});
|
|
13837
|
+
}
|
|
13838
|
+
function polygonsTouch(a, b) {
|
|
13839
|
+
if (a.some((p) => pointInPolygon(p, b)) || b.some((p) => pointInPolygon(p, a)))
|
|
13840
|
+
return true;
|
|
13841
|
+
const cross2 = (p, q, r) => (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
|
|
13842
|
+
for (let i = 0; i < a.length; i++)
|
|
13843
|
+
for (let j = 0; j < b.length; j++) {
|
|
13844
|
+
const p = a[i], q = a[(i + 1) % a.length], r = b[j], s = b[(j + 1) % b.length];
|
|
13845
|
+
if (cross2(p, q, r) * cross2(p, q, s) < -EPS && cross2(r, s, p) * cross2(r, s, q) < -EPS)
|
|
13846
|
+
return true;
|
|
13847
|
+
}
|
|
13848
|
+
return false;
|
|
13849
|
+
}
|
|
13850
|
+
var EPS2 = 1e-7;
|
|
13851
|
+
function createPcbFold(records, thickness, { outline } = {}) {
|
|
13703
13852
|
if (!Number.isFinite(thickness) || thickness < 0)
|
|
13704
13853
|
throw new Error("Board thickness must be finite and nonnegative");
|
|
13854
|
+
if (outline && (outline.length < 3 || outline.some((p) => !Number.isFinite(p.x) || !Number.isFinite(p.y))))
|
|
13855
|
+
throw new Error(
|
|
13856
|
+
"A finite board outline with at least three points is required"
|
|
13857
|
+
);
|
|
13705
13858
|
const bends = records.map((b) => {
|
|
13706
13859
|
const { start, end, bend_angle: degrees, bend_radius: radius } = b;
|
|
13707
13860
|
const values = [start?.x, start?.y, end?.x, end?.y, degrees, radius];
|
|
13708
13861
|
if (values.some((v) => !Number.isFinite(v)) || radius <= thickness / 2 || !["left", "right"].includes(b.bend_side)) {
|
|
13709
|
-
throw new
|
|
13710
|
-
|
|
13711
|
-
|
|
13862
|
+
throw new PcbFoldError({
|
|
13863
|
+
code: "invalid_bend_geometry",
|
|
13864
|
+
message: `Invalid PCB bend ${b.pcb_bend_id}: finite geometry and radius greater than half the board thickness are required`,
|
|
13865
|
+
bendId: b.pcb_bend_id
|
|
13866
|
+
});
|
|
13712
13867
|
}
|
|
13713
13868
|
const length = Math.hypot(end.x - start.x, end.y - start.y);
|
|
13714
|
-
if (length <
|
|
13715
|
-
throw new
|
|
13716
|
-
|
|
13717
|
-
|
|
13869
|
+
if (length < EPS2 || Math.abs(degrees) > 180)
|
|
13870
|
+
throw new PcbFoldError({
|
|
13871
|
+
code: "unsupported_bend_geometry",
|
|
13872
|
+
message: `Unsupported PCB bend ${b.pcb_bend_id}: distinct endpoints and angles within \xB1180 degrees are required`,
|
|
13873
|
+
bendId: b.pcb_bend_id
|
|
13874
|
+
});
|
|
13718
13875
|
const sign = b.bend_side === "right" ? 1 : -1;
|
|
13719
13876
|
const nx = sign * (end.y - start.y) / length;
|
|
13720
13877
|
const ny = -sign * (end.x - start.x) / length;
|
|
13721
13878
|
const angle = degrees * Math.PI / 180;
|
|
13722
13879
|
const width = radius * Math.abs(angle);
|
|
13723
13880
|
const center = start.x * nx + start.y * ny;
|
|
13724
|
-
|
|
13881
|
+
const geometry = {
|
|
13725
13882
|
id: b.pcb_bend_id,
|
|
13726
13883
|
nx,
|
|
13727
13884
|
ny,
|
|
@@ -13738,20 +13895,39 @@ function createPcbFold(records, thickness) {
|
|
|
13738
13895
|
-ny * end.x + nx * end.y
|
|
13739
13896
|
)
|
|
13740
13897
|
};
|
|
13741
|
-
|
|
13898
|
+
if (outline && Math.abs(angle) > EPS2)
|
|
13899
|
+
geometry.movingOutline = getFiniteBendRegion({
|
|
13900
|
+
bendId: b.pcb_bend_id,
|
|
13901
|
+
outline,
|
|
13902
|
+
nx,
|
|
13903
|
+
ny,
|
|
13904
|
+
center,
|
|
13905
|
+
proximal: geometry.start,
|
|
13906
|
+
axisMin: geometry.axisMin,
|
|
13907
|
+
axisMax: geometry.axisMax
|
|
13908
|
+
});
|
|
13909
|
+
return geometry;
|
|
13910
|
+
}).filter((b) => Math.abs(b.angle) > EPS2);
|
|
13742
13911
|
const first = bends[0];
|
|
13743
13912
|
if (first && bends.some(
|
|
13744
|
-
(b) => Math.abs(b.nx - first.nx) >
|
|
13913
|
+
(b) => Math.abs(b.nx - first.nx) > EPS2 || Math.abs(b.ny - first.ny) > EPS2
|
|
13745
13914
|
)) {
|
|
13746
|
-
throw new
|
|
13747
|
-
|
|
13748
|
-
|
|
13915
|
+
throw new PcbFoldError({
|
|
13916
|
+
code: "nonparallel_bends",
|
|
13917
|
+
message: "Folded PCB rendering currently requires parallel bends with the same moving direction"
|
|
13918
|
+
});
|
|
13749
13919
|
}
|
|
13750
13920
|
bends.sort((a, b) => a.start - b.start);
|
|
13751
|
-
for (let i =
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13921
|
+
for (let i = 0; i < bends.length; i++)
|
|
13922
|
+
for (let j = i + 1; j < bends.length; j++) {
|
|
13923
|
+
const a = bends[i], b = bends[j];
|
|
13924
|
+
if (b.start < a.end - EPS2 && (!a.movingOutline || !b.movingOutline || polygonsTouch(a.movingOutline, b.movingOutline)))
|
|
13925
|
+
throw new PcbFoldError({
|
|
13926
|
+
code: "overlapping_bend_zones",
|
|
13927
|
+
message: "Overlapping PCB bend zones are not supported",
|
|
13928
|
+
bendId: b.id
|
|
13929
|
+
});
|
|
13930
|
+
}
|
|
13755
13931
|
const distalFirst = [...bends].reverse();
|
|
13756
13932
|
const transform = ({
|
|
13757
13933
|
p,
|
|
@@ -13760,6 +13936,7 @@ function createPcbFold(records, thickness) {
|
|
|
13760
13936
|
}) => {
|
|
13761
13937
|
let result = { ...p };
|
|
13762
13938
|
for (const b of distalFirst) {
|
|
13939
|
+
if (b.movingOutline && !pointInPolygon(anchor, b.movingOutline)) continue;
|
|
13763
13940
|
const width = b.end - b.start;
|
|
13764
13941
|
const s = anchor.x * b.nx + anchor.y * b.ny - b.start;
|
|
13765
13942
|
const q = Math.max(0, Math.min(width, s));
|
|
@@ -13807,14 +13984,24 @@ function createPcbFold(records, thickness) {
|
|
|
13807
13984
|
direction: (p, anchor) => transform({ p, anchor, direction: true }),
|
|
13808
13985
|
assertRigid(points, label) {
|
|
13809
13986
|
for (const b of bends) {
|
|
13810
|
-
const
|
|
13811
|
-
|
|
13812
|
-
|
|
13987
|
+
const width = b.end - b.start;
|
|
13988
|
+
const progress = points.map(
|
|
13989
|
+
(p) => b.movingOutline && !pointInPolygon(p, b.movingOutline) ? 0 : Math.max(0, Math.min(width, p.x * b.nx + p.y * b.ny - b.start))
|
|
13990
|
+
);
|
|
13991
|
+
if (Math.max(...progress) > EPS2 && Math.min(...progress) < width - EPS2)
|
|
13992
|
+
throw new PcbFoldError({
|
|
13993
|
+
code: "rigid_bend_zone_intersection",
|
|
13994
|
+
message: `${label} intersects PCB bend zone ${b.id}`,
|
|
13995
|
+
bendId: b.id
|
|
13996
|
+
});
|
|
13813
13997
|
}
|
|
13814
13998
|
}
|
|
13815
13999
|
};
|
|
13816
14000
|
}
|
|
13817
|
-
|
|
14001
|
+
function tryCreatePcbFold(records, thickness, options = {}) {
|
|
14002
|
+
return capturePcbFoldResult(() => createPcbFold(records, thickness, options));
|
|
14003
|
+
}
|
|
14004
|
+
var EPS3 = 1e-7;
|
|
13818
14005
|
function boundsOfTriangles(triangles) {
|
|
13819
14006
|
const points = triangles.flatMap((t) => t.vertices);
|
|
13820
14007
|
if (!points.length)
|
|
@@ -13844,7 +14031,7 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13844
14031
|
d
|
|
13845
14032
|
}) => {
|
|
13846
14033
|
const distances = polygon3.map(({ p }) => nx * p.x + ny * p.y - d);
|
|
13847
|
-
if (Math.min(...distances) >= -
|
|
14034
|
+
if (Math.min(...distances) >= -EPS3 || Math.max(...distances) <= EPS3)
|
|
13848
14035
|
return [polygon3];
|
|
13849
14036
|
const halves = [[], []];
|
|
13850
14037
|
for (let side = 0; side < 2; side++) {
|
|
@@ -13852,8 +14039,8 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13852
14039
|
for (let i = 0; i < polygon3.length; i++) {
|
|
13853
14040
|
const a = polygon3[i], next = (i + 1) % polygon3.length, b = polygon3[next];
|
|
13854
14041
|
const da = distances[i] * sign, db = distances[next] * sign;
|
|
13855
|
-
if (da >= -
|
|
13856
|
-
if (da >
|
|
14042
|
+
if (da >= -EPS3) halves[side].push(a);
|
|
14043
|
+
if (da > EPS3 && db < -EPS3 || da < -EPS3 && db > EPS3) {
|
|
13857
14044
|
const t = da / (da - db);
|
|
13858
14045
|
halves[side].push({
|
|
13859
14046
|
p: {
|
|
@@ -13889,14 +14076,17 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13889
14076
|
);
|
|
13890
14077
|
for (const polygon3 of polygons) {
|
|
13891
14078
|
for (const b of fold.bends) {
|
|
14079
|
+
if (b.movingOutline) continue;
|
|
13892
14080
|
const mid = polygon3.reduce((sum, { p }) => sum + p.x * b.nx + p.y * b.ny, 0) / polygon3.length;
|
|
13893
|
-
if (mid > b.start +
|
|
14081
|
+
if (mid > b.start + EPS3 && mid < b.end - EPS3 && polygon3.some(({ p }) => {
|
|
13894
14082
|
const along = -b.ny * p.x + b.nx * p.y;
|
|
13895
|
-
return along < b.axisMin -
|
|
14083
|
+
return along < b.axisMin - EPS3 || along > b.axisMax + EPS3;
|
|
13896
14084
|
}))
|
|
13897
|
-
throw new
|
|
13898
|
-
|
|
13899
|
-
|
|
14085
|
+
throw new PcbFoldError({
|
|
14086
|
+
code: "incomplete_bend_cross_section",
|
|
14087
|
+
message: `PCB bend ${b.id} must span the full board cross-section through its bend zone`,
|
|
14088
|
+
bendId: b.id
|
|
14089
|
+
});
|
|
13900
14090
|
}
|
|
13901
14091
|
for (let i = 1; i + 1 < polygon3.length; i++) {
|
|
13902
14092
|
const verts = [polygon3[0], polygon3[i], polygon3[i + 1]];
|
|
@@ -13924,6 +14114,9 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13924
14114
|
}
|
|
13925
14115
|
return { ...mesh, triangles, boundingBox: boundsOfTriangles(triangles) };
|
|
13926
14116
|
}
|
|
14117
|
+
function tryFoldSurfaceMesh(mesh, fold) {
|
|
14118
|
+
return capturePcbFoldResult(() => foldSurfaceMesh(mesh, fold));
|
|
14119
|
+
}
|
|
13927
14120
|
var axes = [
|
|
13928
14121
|
{ x: 1, y: 0, z: 0 },
|
|
13929
14122
|
{ x: 0, y: 1, z: 0 },
|
|
@@ -14022,7 +14215,12 @@ function getCadFoldContext(cadComponent, json) {
|
|
|
14022
14215
|
(e) => e.type === "pcb_bend" && e.pcb_board_id === board.pcb_board_id
|
|
14023
14216
|
);
|
|
14024
14217
|
return {
|
|
14025
|
-
fold: createPcbFold(bends, board.thickness ?? 1.6
|
|
14218
|
+
fold: createPcbFold(bends, board.thickness ?? 1.6, {
|
|
14219
|
+
outline: board.outline?.map((p) => ({
|
|
14220
|
+
x: p.x - board.center.x,
|
|
14221
|
+
y: p.y - board.center.y
|
|
14222
|
+
}))
|
|
14223
|
+
}),
|
|
14026
14224
|
boardCenter: board.center,
|
|
14027
14225
|
flatMount: pcb.center,
|
|
14028
14226
|
defaultRotation: {
|
|
@@ -14119,6 +14317,46 @@ function extrudePolygon({
|
|
|
14119
14317
|
}
|
|
14120
14318
|
return { triangles, boundingBox: boundsOfTriangles(triangles) };
|
|
14121
14319
|
}
|
|
14320
|
+
function foldRigidMesh(mesh, fold, { flatAnchor, label = "Rigid mesh", mount }) {
|
|
14321
|
+
if (mount) fold.assertRigid([mount], `${label} mount`);
|
|
14322
|
+
fold.assertRigid(
|
|
14323
|
+
mesh.triangles.flatMap((t) => t.vertices),
|
|
14324
|
+
label
|
|
14325
|
+
);
|
|
14326
|
+
const triangles = mesh.triangles.map((t) => ({
|
|
14327
|
+
...t,
|
|
14328
|
+
vertices: t.vertices.map(
|
|
14329
|
+
(p) => fold.point(p, flatAnchor)
|
|
14330
|
+
),
|
|
14331
|
+
normal: fold.direction(t.normal, flatAnchor)
|
|
14332
|
+
}));
|
|
14333
|
+
return { ...mesh, triangles, boundingBox: boundsOfTriangles(triangles) };
|
|
14334
|
+
}
|
|
14335
|
+
function tryFoldRigidMesh(mesh, fold, options) {
|
|
14336
|
+
return capturePcbFoldResult(() => foldRigidMesh(mesh, fold, options));
|
|
14337
|
+
}
|
|
14338
|
+
function getStiffenerOutline(stiffener) {
|
|
14339
|
+
if (stiffener.shape === "polygon") return stiffener.outline;
|
|
14340
|
+
if (!(stiffener.width > 0 && stiffener.height > 0))
|
|
14341
|
+
throw new Error("Invalid stiffener dimensions");
|
|
14342
|
+
const a = (stiffener.rotation ?? 0) * Math.PI / 180;
|
|
14343
|
+
return [
|
|
14344
|
+
[-1, -1],
|
|
14345
|
+
[1, -1],
|
|
14346
|
+
[1, 1],
|
|
14347
|
+
[-1, 1]
|
|
14348
|
+
].map(([x, y]) => ({
|
|
14349
|
+
x: stiffener.center.x + x * stiffener.width / 2 * Math.cos(a) - y * stiffener.height / 2 * Math.sin(a),
|
|
14350
|
+
y: stiffener.center.y + x * stiffener.width / 2 * Math.sin(a) + y * stiffener.height / 2 * Math.cos(a)
|
|
14351
|
+
}));
|
|
14352
|
+
}
|
|
14353
|
+
function getStiffenerAnchor(outline) {
|
|
14354
|
+
return {
|
|
14355
|
+
x: outline.reduce((s, p) => s + p.x, 0) / outline.length,
|
|
14356
|
+
y: outline.reduce((s, p) => s + p.y, 0) / outline.length,
|
|
14357
|
+
z: 0
|
|
14358
|
+
};
|
|
14359
|
+
}
|
|
14122
14360
|
function createStiffenerMesh({
|
|
14123
14361
|
stiffener,
|
|
14124
14362
|
boardThickness,
|
|
@@ -14127,20 +14365,7 @@ function createStiffenerMesh({
|
|
|
14127
14365
|
const adhesive = stiffener.adhesive_thickness ?? 0;
|
|
14128
14366
|
if (!Number.isFinite(adhesive) || adhesive < 0 || !Number.isFinite(stiffener.thickness) || stiffener.thickness <= 0 || !["top", "bottom"].includes(stiffener.layer))
|
|
14129
14367
|
throw new Error(`Invalid PCB stiffener ${stiffener.pcb_stiffener_id}`);
|
|
14130
|
-
const outline = stiffener
|
|
14131
|
-
if (!(stiffener.width > 0 && stiffener.height > 0))
|
|
14132
|
-
throw new Error("Invalid stiffener dimensions");
|
|
14133
|
-
const a = (stiffener.rotation ?? 0) * Math.PI / 180;
|
|
14134
|
-
return [
|
|
14135
|
-
[-1, -1],
|
|
14136
|
-
[1, -1],
|
|
14137
|
-
[1, 1],
|
|
14138
|
-
[-1, 1]
|
|
14139
|
-
].map(([x, y]) => ({
|
|
14140
|
-
x: stiffener.center.x + x * stiffener.width / 2 * Math.cos(a) - y * stiffener.height / 2 * Math.sin(a),
|
|
14141
|
-
y: stiffener.center.y + x * stiffener.width / 2 * Math.sin(a) + y * stiffener.height / 2 * Math.cos(a)
|
|
14142
|
-
}));
|
|
14143
|
-
})();
|
|
14368
|
+
const outline = getStiffenerOutline(stiffener);
|
|
14144
14369
|
const near = boardThickness / 2 + adhesive, far = near + stiffener.thickness;
|
|
14145
14370
|
const mesh = extrudePolygon({
|
|
14146
14371
|
outline,
|
|
@@ -14148,21 +14373,16 @@ function createStiffenerMesh({
|
|
|
14148
14373
|
top: stiffener.layer === "top" ? far : -near
|
|
14149
14374
|
});
|
|
14150
14375
|
if (!fold) return mesh;
|
|
14151
|
-
fold
|
|
14152
|
-
|
|
14153
|
-
stiffener.pcb_stiffener_id
|
|
14154
|
-
);
|
|
14155
|
-
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
...t,
|
|
14162
|
-
vertices: t.vertices.map((p) => fold.point(p, anchor)),
|
|
14163
|
-
normal: fold.direction(t.normal, anchor)
|
|
14164
|
-
}));
|
|
14165
|
-
return { ...mesh, triangles, boundingBox: boundsOfTriangles(triangles) };
|
|
14376
|
+
return foldRigidMesh(mesh, fold, {
|
|
14377
|
+
flatAnchor: getStiffenerAnchor(outline),
|
|
14378
|
+
label: stiffener.pcb_stiffener_id
|
|
14379
|
+
});
|
|
14380
|
+
}
|
|
14381
|
+
function tryFoldStiffenerMesh(mesh, stiffener, fold) {
|
|
14382
|
+
return tryFoldRigidMesh(mesh, fold, {
|
|
14383
|
+
flatAnchor: getStiffenerAnchor(getStiffenerOutline(stiffener)),
|
|
14384
|
+
label: stiffener.pcb_stiffener_id
|
|
14385
|
+
});
|
|
14166
14386
|
}
|
|
14167
14387
|
|
|
14168
14388
|
// lib/utils/pcb-fold.ts
|
|
@@ -14188,8 +14408,9 @@ function swapMeshFrame(mesh) {
|
|
|
14188
14408
|
}))
|
|
14189
14409
|
};
|
|
14190
14410
|
}
|
|
14191
|
-
function
|
|
14192
|
-
|
|
14411
|
+
function tryFoldBoardMesh(mesh, fold) {
|
|
14412
|
+
const result = tryFoldSurfaceMesh(swapMeshFrame(mesh), fold);
|
|
14413
|
+
return result.ok ? { ok: true, value: swapMeshFrame(result.value) } : result;
|
|
14193
14414
|
}
|
|
14194
14415
|
|
|
14195
14416
|
// lib/utils/bounding-box.ts
|
|
@@ -14657,7 +14878,7 @@ function getBounds(positions) {
|
|
|
14657
14878
|
}
|
|
14658
14879
|
|
|
14659
14880
|
// lib/utils/fold-rigid-box.ts
|
|
14660
|
-
function
|
|
14881
|
+
function tryFoldRigidBox(box, fold, boardCenter, mount) {
|
|
14661
14882
|
const source = box.mesh ? createMeshFromSTL(box.mesh) : createBoxMesh(box.size);
|
|
14662
14883
|
const rotated = transformMesh(source, { x: 0, y: 0, z: 0 }, box.rotation);
|
|
14663
14884
|
const center = {
|
|
@@ -14675,53 +14896,76 @@ function foldRigidBox(box, fold, boardCenter, mount) {
|
|
|
14675
14896
|
z: rotated.positions[i + 2]
|
|
14676
14897
|
})
|
|
14677
14898
|
);
|
|
14678
|
-
|
|
14679
|
-
points.map((p) => ({
|
|
14680
|
-
x: p.x + center.x,
|
|
14681
|
-
y: p.y + center.y,
|
|
14682
|
-
z: p.z + center.z
|
|
14683
|
-
})),
|
|
14684
|
-
box.label ?? "CAD component or stiffener"
|
|
14685
|
-
);
|
|
14686
|
-
const movedCenter = fold.point(center, anchor);
|
|
14687
|
-
const triangles = [];
|
|
14899
|
+
const boardLocalTriangles = [];
|
|
14688
14900
|
for (let i = 0; i < rotated.indices.length; i += 3) {
|
|
14689
14901
|
const indices = [
|
|
14690
14902
|
rotated.indices[i],
|
|
14691
14903
|
rotated.indices[i + 2],
|
|
14692
14904
|
rotated.indices[i + 1]
|
|
14693
14905
|
];
|
|
14694
|
-
const vertices = indices.map(
|
|
14695
|
-
|
|
14696
|
-
|
|
14906
|
+
const vertices = indices.map((index) => ({
|
|
14907
|
+
x: points[index].x + center.x,
|
|
14908
|
+
y: points[index].y + center.y,
|
|
14909
|
+
z: points[index].z + center.z
|
|
14910
|
+
}));
|
|
14697
14911
|
const j = indices[0] * 3;
|
|
14698
|
-
const normal = swapPcbSceneAxes(
|
|
14699
|
-
|
|
14700
|
-
|
|
14701
|
-
|
|
14702
|
-
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
|
|
14707
|
-
);
|
|
14708
|
-
triangles.push({ ...box.mesh?.triangles[i / 3], vertices, normal });
|
|
14912
|
+
const normal = swapPcbSceneAxes({
|
|
14913
|
+
x: rotated.normals[j],
|
|
14914
|
+
y: rotated.normals[j + 1],
|
|
14915
|
+
z: rotated.normals[j + 2]
|
|
14916
|
+
});
|
|
14917
|
+
boardLocalTriangles.push({
|
|
14918
|
+
...box.mesh?.triangles[i / 3],
|
|
14919
|
+
vertices,
|
|
14920
|
+
normal
|
|
14921
|
+
});
|
|
14709
14922
|
}
|
|
14923
|
+
const result = tryFoldRigidMesh(
|
|
14924
|
+
{
|
|
14925
|
+
...box.mesh,
|
|
14926
|
+
triangles: boardLocalTriangles,
|
|
14927
|
+
boundingBox: boundsOfTriangles2(boardLocalTriangles)
|
|
14928
|
+
},
|
|
14929
|
+
fold,
|
|
14930
|
+
{
|
|
14931
|
+
flatAnchor: anchor,
|
|
14932
|
+
// Validate the PCB mount independently of an offset model's extents,
|
|
14933
|
+
// matching flex-utils' transformCadComponentPlacement.
|
|
14934
|
+
mount: anchor,
|
|
14935
|
+
label: box.label ?? "CAD component"
|
|
14936
|
+
}
|
|
14937
|
+
);
|
|
14938
|
+
if (!result.ok) return result;
|
|
14939
|
+
const movedCenter = fold.point(center, anchor);
|
|
14940
|
+
const triangles = result.value.triangles.map((triangle) => ({
|
|
14941
|
+
...triangle,
|
|
14942
|
+
vertices: triangle.vertices.map(
|
|
14943
|
+
(p) => swapPcbSceneAxes({
|
|
14944
|
+
x: p.x - movedCenter.x,
|
|
14945
|
+
y: p.y - movedCenter.y,
|
|
14946
|
+
z: p.z - movedCenter.z
|
|
14947
|
+
})
|
|
14948
|
+
),
|
|
14949
|
+
normal: swapPcbSceneAxes(triangle.normal)
|
|
14950
|
+
}));
|
|
14710
14951
|
const boundingBox = boundsOfTriangles2(triangles);
|
|
14711
14952
|
return {
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
|
|
14717
|
-
|
|
14718
|
-
|
|
14719
|
-
|
|
14720
|
-
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
|
|
14724
|
-
|
|
14953
|
+
ok: true,
|
|
14954
|
+
value: {
|
|
14955
|
+
...box,
|
|
14956
|
+
size: {
|
|
14957
|
+
x: boundingBox.max.x - boundingBox.min.x,
|
|
14958
|
+
y: boundingBox.max.y - boundingBox.min.y,
|
|
14959
|
+
z: boundingBox.max.z - boundingBox.min.z
|
|
14960
|
+
},
|
|
14961
|
+
center: {
|
|
14962
|
+
x: movedCenter.x + boardCenter.x,
|
|
14963
|
+
y: movedCenter.z,
|
|
14964
|
+
z: movedCenter.y + boardCenter.y
|
|
14965
|
+
},
|
|
14966
|
+
rotation: void 0,
|
|
14967
|
+
mesh: { ...box.mesh, triangles, boundingBox }
|
|
14968
|
+
}
|
|
14725
14969
|
};
|
|
14726
14970
|
}
|
|
14727
14971
|
|
|
@@ -17824,7 +18068,12 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
17824
18068
|
"PCB flex rendering requires exactly one board, matching board references, and no panel"
|
|
17825
18069
|
);
|
|
17826
18070
|
}
|
|
17827
|
-
|
|
18071
|
+
let fold;
|
|
18072
|
+
const reportFoldIssue = (label, issue) => {
|
|
18073
|
+
console.warn(
|
|
18074
|
+
`Unable to fold ${label}; keeping flat geometry: ${issue.message}`
|
|
18075
|
+
);
|
|
18076
|
+
};
|
|
17828
18077
|
const effectiveBoardThickness = pcbBoard?.thickness ?? boardThickness;
|
|
17829
18078
|
if (pcbPanel) {
|
|
17830
18079
|
const pcbHoles = db.pcb_hole?.list?.() ?? [];
|
|
@@ -17888,6 +18137,31 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
17888
18137
|
});
|
|
17889
18138
|
const meshWidth = boardMesh.boundingBox.max.x - boardMesh.boundingBox.min.x;
|
|
17890
18139
|
const meshHeight = boardMesh.boundingBox.max.z - boardMesh.boundingBox.min.z;
|
|
18140
|
+
let foldedBoardMesh = boardMesh;
|
|
18141
|
+
if (foldPcbs && bends.length) {
|
|
18142
|
+
const foldResult = tryCreatePcbFold(bends, effectiveBoardThickness, {
|
|
18143
|
+
// Match flex-utils' getCadFoldContext: translate circuit-world XY mm
|
|
18144
|
+
// into board-local +Z-up points before the shared surface deformation.
|
|
18145
|
+
outline: pcbBoard.outline?.map((point) => ({
|
|
18146
|
+
x: point.x - pcbBoard.center.x,
|
|
18147
|
+
y: point.y - pcbBoard.center.y
|
|
18148
|
+
}))
|
|
18149
|
+
});
|
|
18150
|
+
if (foldResult.ok) {
|
|
18151
|
+
const meshResult = tryFoldBoardMesh(boardMesh, foldResult.value);
|
|
18152
|
+
if (meshResult.ok) {
|
|
18153
|
+
fold = foldResult.value;
|
|
18154
|
+
foldedBoardMesh = meshResult.value;
|
|
18155
|
+
} else {
|
|
18156
|
+
reportFoldIssue(
|
|
18157
|
+
`PCB board ${pcbBoard.pcb_board_id}`,
|
|
18158
|
+
meshResult.issue
|
|
18159
|
+
);
|
|
18160
|
+
}
|
|
18161
|
+
} else {
|
|
18162
|
+
reportFoldIssue(`PCB board ${pcbBoard.pcb_board_id}`, foldResult.issue);
|
|
18163
|
+
}
|
|
18164
|
+
}
|
|
17891
18165
|
const boardBox = {
|
|
17892
18166
|
center: {
|
|
17893
18167
|
x: pcbBoard.center.x,
|
|
@@ -17899,7 +18173,7 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
17899
18173
|
y: effectiveBoardThickness,
|
|
17900
18174
|
z: Number.isFinite(meshHeight) ? meshHeight : pcbBoard.height
|
|
17901
18175
|
},
|
|
17902
|
-
mesh:
|
|
18176
|
+
mesh: foldedBoardMesh,
|
|
17903
18177
|
color: resolvedPcbColor,
|
|
17904
18178
|
sideColor: resolvedBoardSideColor
|
|
17905
18179
|
};
|
|
@@ -18040,7 +18314,7 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
18040
18314
|
box.meshUrl = model_stl_url || model_obj_url || model_glb_url || model_gltf_url || model_step_url;
|
|
18041
18315
|
box.meshType = meshType;
|
|
18042
18316
|
}
|
|
18043
|
-
const cadRotation = cad.rotation ?? (bends.length ?
|
|
18317
|
+
const cadRotation = cad.rotation ?? (bends.length && pcbComponent ? { x: isBottomLayer ? 180 : 0, y: 0, z: 0 } : void 0);
|
|
18044
18318
|
if (cadRotation) {
|
|
18045
18319
|
box.rotation = convertRotationFromCadRotation({
|
|
18046
18320
|
x: cadRotation.x,
|
|
@@ -18159,9 +18433,10 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
18159
18433
|
if (hasFootprinterModel && !showBoundingBoxes) continue;
|
|
18160
18434
|
box.color = componentColor;
|
|
18161
18435
|
}
|
|
18162
|
-
|
|
18163
|
-
|
|
18164
|
-
|
|
18436
|
+
const result = fold && pcbComponent ? tryFoldRigidBox(box, fold, pcbBoard.center, pcbComponent.center) : void 0;
|
|
18437
|
+
if (result && !result.ok)
|
|
18438
|
+
reportFoldIssue(`CAD component ${cad.cad_component_id}`, result.issue);
|
|
18439
|
+
boxes.push(result?.ok ? result.value : box);
|
|
18165
18440
|
}
|
|
18166
18441
|
if (showBoundingBoxes) {
|
|
18167
18442
|
for (const component of pcbComponents) {
|
|
@@ -18191,19 +18466,27 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
18191
18466
|
label: sourceComponent?.name ?? "?",
|
|
18192
18467
|
labelColor: "white"
|
|
18193
18468
|
};
|
|
18194
|
-
|
|
18195
|
-
|
|
18196
|
-
|
|
18469
|
+
const result = fold ? tryFoldRigidBox(box, fold, pcbBoard.center, component.center) : void 0;
|
|
18470
|
+
if (result && !result.ok)
|
|
18471
|
+
reportFoldIssue(
|
|
18472
|
+
`PCB component ${component.pcb_component_id}`,
|
|
18473
|
+
result.issue
|
|
18474
|
+
);
|
|
18475
|
+
boxes.push(result?.ok ? result.value : box);
|
|
18197
18476
|
}
|
|
18198
18477
|
}
|
|
18199
18478
|
for (const stiffener of stiffeners) {
|
|
18200
|
-
const
|
|
18201
|
-
|
|
18202
|
-
|
|
18203
|
-
|
|
18204
|
-
|
|
18205
|
-
|
|
18206
|
-
|
|
18479
|
+
const flatMesh = createStiffenerMesh({
|
|
18480
|
+
stiffener,
|
|
18481
|
+
boardThickness: effectiveBoardThickness
|
|
18482
|
+
});
|
|
18483
|
+
const result = fold ? tryFoldStiffenerMesh(flatMesh, stiffener, fold) : void 0;
|
|
18484
|
+
if (result && !result.ok)
|
|
18485
|
+
reportFoldIssue(
|
|
18486
|
+
`PCB stiffener ${stiffener.pcb_stiffener_id}`,
|
|
18487
|
+
result.issue
|
|
18488
|
+
);
|
|
18489
|
+
const mesh = swapMeshFrame(result?.ok ? result.value : flatMesh);
|
|
18207
18490
|
boxes.push({
|
|
18208
18491
|
center: { x: pcbBoard.center.x, y: 0, z: pcbBoard.center.y },
|
|
18209
18492
|
size: getBoundingBoxSize(mesh.boundingBox),
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "circuit-json-to-gltf",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.138",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/tscircuit/circuit-json-to-gltf.git"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"occt-import-js": "^0.0.23"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.
|
|
32
|
+
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.7.tgz",
|
|
33
33
|
"@biomejs/biome": "^2.1.4",
|
|
34
34
|
"@google/model-viewer": "^4.1.0",
|
|
35
35
|
"@napi-rs/canvas": "^1.0.9",
|