circuit-json-to-gltf 0.0.138 → 0.0.140
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.d.ts +50 -2
- package/dist/index.js +306 -94
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PcbStiffener, CircuitJson, PcbBoard } from 'circuit-json';
|
|
2
|
+
import { mat4 } from 'gl-matrix';
|
|
2
3
|
|
|
3
4
|
/** Circuit JSON bend geometry, board-local +Z up, millimeters. */
|
|
4
5
|
interface PcbBendRecord {
|
|
@@ -36,6 +37,8 @@ interface ConversionOptions {
|
|
|
36
37
|
format?: "gltf" | "glb";
|
|
37
38
|
boardTextureResolution?: number;
|
|
38
39
|
showPcbNotes?: boolean;
|
|
40
|
+
/** Include full Circuit JSON error messages for screen overlay renderers. Defaults to false. */
|
|
41
|
+
showErrors?: boolean;
|
|
39
42
|
boardDrillQuality?: "high" | "fast";
|
|
40
43
|
drawFauxBoard?: boolean;
|
|
41
44
|
includeModels?: boolean;
|
|
@@ -146,6 +149,8 @@ interface Scene3D {
|
|
|
146
149
|
boxes: Box3D[];
|
|
147
150
|
camera?: Camera3D;
|
|
148
151
|
lights?: Light3D[];
|
|
152
|
+
/** Full Circuit JSON error messages, independent of geometry and camera. */
|
|
153
|
+
errorMessages?: string[];
|
|
149
154
|
}
|
|
150
155
|
interface Camera3D {
|
|
151
156
|
position: Point3;
|
|
@@ -173,7 +178,7 @@ interface GLTFExportOptions {
|
|
|
173
178
|
includeCustomExtensions?: boolean;
|
|
174
179
|
}
|
|
175
180
|
interface CircuitTo3DOptions {
|
|
176
|
-
/** Override folding for
|
|
181
|
+
/** Override folding for supported PCB bend regions. Undefined follows CAD is_on_folded_board. */
|
|
177
182
|
foldPcbs?: boolean;
|
|
178
183
|
pcbColor?: Color;
|
|
179
184
|
boardSideColor?: Color;
|
|
@@ -189,6 +194,8 @@ interface CircuitTo3DOptions {
|
|
|
189
194
|
renderBoardTextures?: boolean;
|
|
190
195
|
textureResolution?: number;
|
|
191
196
|
showPcbNotes?: boolean;
|
|
197
|
+
/** Include full Circuit JSON error messages for screen overlay renderers. Defaults to false. */
|
|
198
|
+
showErrors?: boolean;
|
|
192
199
|
coordinateTransform?: CoordinateTransformConfig;
|
|
193
200
|
showBoundingBoxes?: boolean;
|
|
194
201
|
projectBaseUrl?: string;
|
|
@@ -206,6 +213,47 @@ interface BoardRenderOptions {
|
|
|
206
213
|
showPcbNotes?: boolean;
|
|
207
214
|
}
|
|
208
215
|
|
|
216
|
+
interface PoppyglErrorOverlayOptions {
|
|
217
|
+
/** Final image dimensions in pixels, before PoppyGL supersampling. */
|
|
218
|
+
width: number;
|
|
219
|
+
height: number;
|
|
220
|
+
supersampling?: number;
|
|
221
|
+
/** Font height in final image pixels. Default: 16. */
|
|
222
|
+
debugFontSize?: number;
|
|
223
|
+
}
|
|
224
|
+
interface PoppyglErrorOverlay {
|
|
225
|
+
debugPoints: Array<{
|
|
226
|
+
label: string;
|
|
227
|
+
/** Layout anchor in the exported glTF world frame: +Y up, millimeters.
|
|
228
|
+
* This is a point, so camera translation applies. It is not an error's
|
|
229
|
+
* physical position on the circuit. */
|
|
230
|
+
position: {
|
|
231
|
+
x: number;
|
|
232
|
+
y: number;
|
|
233
|
+
z: number;
|
|
234
|
+
};
|
|
235
|
+
}>;
|
|
236
|
+
debugFontSize: number;
|
|
237
|
+
}
|
|
238
|
+
/** Adapt Circuit JSON error metadata to stock PoppyGL's existing debug labels.
|
|
239
|
+
*
|
|
240
|
+
* Supply the camera built from the same draw calls and render options used by
|
|
241
|
+
* PoppyGL. Each label's screen layout anchor is unprojected through the inverse
|
|
242
|
+
* of camera.proj * camera.view (the paired reference is PoppyGL's
|
|
243
|
+
* drawDebugPoints/projectWorldToScreen). The resulting point is in the final
|
|
244
|
+
* glTF world frame, +Y up and millimeters; it does not locate a circuit error.
|
|
245
|
+
* Recompute these options whenever the camera or image dimensions change.
|
|
246
|
+
*
|
|
247
|
+
* Width, height and the requested font size are final image pixels. Stock
|
|
248
|
+
* PoppyGL draws debug labels before downsampling, so the returned font size
|
|
249
|
+
* and pixel anchors account for its supersampling factor. No geometry, camera
|
|
250
|
+
* matrices or metadata are modified. Returns undefined when no errors exist.
|
|
251
|
+
*/
|
|
252
|
+
declare function getPoppyglErrorOverlayOptions(gltf: unknown, camera: {
|
|
253
|
+
view: mat4;
|
|
254
|
+
proj: mat4;
|
|
255
|
+
}, options: PoppyglErrorOverlayOptions): PoppyglErrorOverlay | undefined;
|
|
256
|
+
|
|
209
257
|
declare function renderBoardLayer(circuitJson: CircuitJson, options: BoardRenderOptions): Promise<string>;
|
|
210
258
|
declare function renderBoardTextures(circuitJson: CircuitJson, { resolution, backgroundColor, copperColor, silkscreenColor, solderMaskWithCopperColor, drillColor, showPcbNotes, }: Omit<BoardRenderOptions, "layer">): Promise<{
|
|
211
259
|
top: string;
|
|
@@ -330,4 +378,4 @@ interface BRepShape {
|
|
|
330
378
|
is_negative?: boolean;
|
|
331
379
|
}
|
|
332
380
|
|
|
333
|
-
export { type BRepShape, type BoardRenderOptions, type BoundingBox, type Box3D, CAMERA_PRESET_DIRECTIONS, COORDINATE_TRANSFORMS, type Camera3D, type CameraFitOptions, type CameraPreset, type CircuitJsonWithPcbFlex, type CircuitTo3DOptions, type Color, type ConversionOptions, type CoordinateTransformConfig, type GLTFExportOptions, type LayerRef, type Light3D, type OBJMaterial, type OBJMesh, type PcbBendRecord, type PcbStiffenerRecord, type Point, type Point3, type STLMesh, type Scene3D, type Size3, type Triangle, applyCoordinateTransform, clearGLBCache, clearOBJCache, clearSTLCache, convertCircuitJsonTo3D, convertCircuitJsonToGltf, convertSceneToGLTF, getBestCameraPosition, loadGLB, loadJscadPlan, loadOBJ, loadSTL, renderBoardLayer, renderBoardTextures, transformTriangles };
|
|
381
|
+
export { type BRepShape, type BoardRenderOptions, type BoundingBox, type Box3D, CAMERA_PRESET_DIRECTIONS, COORDINATE_TRANSFORMS, type Camera3D, type CameraFitOptions, type CameraPreset, type CircuitJsonWithPcbFlex, type CircuitTo3DOptions, type Color, type ConversionOptions, type CoordinateTransformConfig, type GLTFExportOptions, type LayerRef, type Light3D, type OBJMaterial, type OBJMesh, type PcbBendRecord, type PcbStiffenerRecord, type Point, type Point3, type PoppyglErrorOverlay, type PoppyglErrorOverlayOptions, type STLMesh, type Scene3D, type Size3, type Triangle, applyCoordinateTransform, clearGLBCache, clearOBJCache, clearSTLCache, convertCircuitJsonTo3D, convertCircuitJsonToGltf, convertSceneToGLTF, getBestCameraPosition, getPoppyglErrorOverlayOptions, loadGLB, loadJscadPlan, loadOBJ, loadSTL, renderBoardLayer, renderBoardTextures, transformTriangles };
|
package/dist/index.js
CHANGED
|
@@ -1542,14 +1542,14 @@ var require_mat4 = __commonJS({
|
|
|
1542
1542
|
var require_create3 = __commonJS({
|
|
1543
1543
|
"node_modules/@jscad/modeling/src/geometries/geom2/create.js"(exports, module) {
|
|
1544
1544
|
"use strict";
|
|
1545
|
-
var
|
|
1545
|
+
var mat42 = require_mat4();
|
|
1546
1546
|
var create = (sides) => {
|
|
1547
1547
|
if (sides === void 0) {
|
|
1548
1548
|
sides = [];
|
|
1549
1549
|
}
|
|
1550
1550
|
return {
|
|
1551
1551
|
sides,
|
|
1552
|
-
transforms:
|
|
1552
|
+
transforms: mat42.create()
|
|
1553
1553
|
};
|
|
1554
1554
|
};
|
|
1555
1555
|
module.exports = create;
|
|
@@ -2043,13 +2043,13 @@ var require_fromPoints = __commonJS({
|
|
|
2043
2043
|
var require_fromCompactBinary = __commonJS({
|
|
2044
2044
|
"node_modules/@jscad/modeling/src/geometries/geom2/fromCompactBinary.js"(exports, module) {
|
|
2045
2045
|
"use strict";
|
|
2046
|
-
var
|
|
2046
|
+
var mat42 = require_mat4();
|
|
2047
2047
|
var vec2 = require_vec2();
|
|
2048
2048
|
var create = require_create3();
|
|
2049
2049
|
var fromCompactBinary = (data) => {
|
|
2050
2050
|
if (data[0] !== 0) throw new Error("invalid compact binary data");
|
|
2051
2051
|
const created = create();
|
|
2052
|
-
created.transforms =
|
|
2052
|
+
created.transforms = mat42.clone(data.slice(1, 17));
|
|
2053
2053
|
for (let i = 21; i < data.length; i += 4) {
|
|
2054
2054
|
const point0 = vec2.fromValues(data[i + 0], data[i + 1]);
|
|
2055
2055
|
const point1 = vec2.fromValues(data[i + 2], data[i + 3]);
|
|
@@ -2086,16 +2086,16 @@ var require_isA = __commonJS({
|
|
|
2086
2086
|
var require_applyTransforms = __commonJS({
|
|
2087
2087
|
"node_modules/@jscad/modeling/src/geometries/geom2/applyTransforms.js"(exports, module) {
|
|
2088
2088
|
"use strict";
|
|
2089
|
-
var
|
|
2089
|
+
var mat42 = require_mat4();
|
|
2090
2090
|
var vec2 = require_vec2();
|
|
2091
2091
|
var applyTransforms = (geometry) => {
|
|
2092
|
-
if (
|
|
2092
|
+
if (mat42.isIdentity(geometry.transforms)) return geometry;
|
|
2093
2093
|
geometry.sides = geometry.sides.map((side) => {
|
|
2094
2094
|
const p0 = vec2.transform(vec2.create(), side[0], geometry.transforms);
|
|
2095
2095
|
const p1 = vec2.transform(vec2.create(), side[1], geometry.transforms);
|
|
2096
2096
|
return [p0, p1];
|
|
2097
2097
|
});
|
|
2098
|
-
geometry.transforms =
|
|
2098
|
+
geometry.transforms = mat42.create();
|
|
2099
2099
|
return geometry;
|
|
2100
2100
|
};
|
|
2101
2101
|
module.exports = applyTransforms;
|
|
@@ -2309,10 +2309,10 @@ var require_toCompactBinary = __commonJS({
|
|
|
2309
2309
|
var require_transform3 = __commonJS({
|
|
2310
2310
|
"node_modules/@jscad/modeling/src/geometries/geom2/transform.js"(exports, module) {
|
|
2311
2311
|
"use strict";
|
|
2312
|
-
var
|
|
2312
|
+
var mat42 = require_mat4();
|
|
2313
2313
|
var reverse = require_reverse();
|
|
2314
2314
|
var transform = (matrix, geometry) => {
|
|
2315
|
-
const transforms =
|
|
2315
|
+
const transforms = mat42.multiply(mat42.create(), matrix, geometry.transforms);
|
|
2316
2316
|
const transformed = Object.assign({}, geometry, { transforms });
|
|
2317
2317
|
if (matrix[0] * matrix[5] - matrix[4] * matrix[1] < 0) {
|
|
2318
2318
|
return reverse(transformed);
|
|
@@ -2383,14 +2383,14 @@ var require_clone5 = __commonJS({
|
|
|
2383
2383
|
var require_create5 = __commonJS({
|
|
2384
2384
|
"node_modules/@jscad/modeling/src/geometries/geom3/create.js"(exports, module) {
|
|
2385
2385
|
"use strict";
|
|
2386
|
-
var
|
|
2386
|
+
var mat42 = require_mat4();
|
|
2387
2387
|
var create = (polygons) => {
|
|
2388
2388
|
if (polygons === void 0) {
|
|
2389
2389
|
polygons = [];
|
|
2390
2390
|
}
|
|
2391
2391
|
return {
|
|
2392
2392
|
polygons,
|
|
2393
|
-
transforms:
|
|
2393
|
+
transforms: mat42.create()
|
|
2394
2394
|
};
|
|
2395
2395
|
};
|
|
2396
2396
|
module.exports = create;
|
|
@@ -3754,12 +3754,12 @@ var require_toString5 = __commonJS({
|
|
|
3754
3754
|
var require_transform4 = __commonJS({
|
|
3755
3755
|
"node_modules/@jscad/modeling/src/maths/plane/transform.js"(exports, module) {
|
|
3756
3756
|
"use strict";
|
|
3757
|
-
var
|
|
3757
|
+
var mat42 = require_mat4();
|
|
3758
3758
|
var vec3 = require_vec3();
|
|
3759
3759
|
var fromPoints = require_fromPoints3();
|
|
3760
3760
|
var flip = require_flip();
|
|
3761
3761
|
var transform = (out, plane, matrix) => {
|
|
3762
|
-
const ismirror =
|
|
3762
|
+
const ismirror = mat42.isMirroring(matrix);
|
|
3763
3763
|
const r = vec3.orthogonal(vec3.create(), plane);
|
|
3764
3764
|
const u = vec3.cross(r, plane, r);
|
|
3765
3765
|
const v = vec3.cross(vec3.create(), plane, u);
|
|
@@ -4062,13 +4062,13 @@ var require_vec4 = __commonJS({
|
|
|
4062
4062
|
var require_measureBoundingSphere = __commonJS({
|
|
4063
4063
|
"node_modules/@jscad/modeling/src/geometries/poly3/measureBoundingSphere.js"(exports, module) {
|
|
4064
4064
|
"use strict";
|
|
4065
|
-
var
|
|
4065
|
+
var vec42 = require_vec4();
|
|
4066
4066
|
var cache = /* @__PURE__ */ new WeakMap();
|
|
4067
4067
|
var measureBoundingSphere = (polygon3) => {
|
|
4068
4068
|
const boundingSphere = cache.get(polygon3);
|
|
4069
4069
|
if (boundingSphere) return boundingSphere;
|
|
4070
4070
|
const vertices = polygon3.vertices;
|
|
4071
|
-
const out =
|
|
4071
|
+
const out = vec42.create();
|
|
4072
4072
|
if (vertices.length === 0) {
|
|
4073
4073
|
out[0] = 0;
|
|
4074
4074
|
out[1] = 0;
|
|
@@ -4154,12 +4154,12 @@ var require_toString6 = __commonJS({
|
|
|
4154
4154
|
var require_transform6 = __commonJS({
|
|
4155
4155
|
"node_modules/@jscad/modeling/src/geometries/poly3/transform.js"(exports, module) {
|
|
4156
4156
|
"use strict";
|
|
4157
|
-
var
|
|
4157
|
+
var mat42 = require_mat4();
|
|
4158
4158
|
var vec3 = require_vec3();
|
|
4159
4159
|
var create = require_create6();
|
|
4160
4160
|
var transform = (matrix, polygon3) => {
|
|
4161
4161
|
const vertices = polygon3.vertices.map((vertex) => vec3.transform(vec3.create(), vertex, matrix));
|
|
4162
|
-
if (
|
|
4162
|
+
if (mat42.isMirroring(matrix)) {
|
|
4163
4163
|
vertices.reverse();
|
|
4164
4164
|
}
|
|
4165
4165
|
return create(vertices);
|
|
@@ -4289,13 +4289,13 @@ var require_fromCompactBinary2 = __commonJS({
|
|
|
4289
4289
|
"node_modules/@jscad/modeling/src/geometries/geom3/fromCompactBinary.js"(exports, module) {
|
|
4290
4290
|
"use strict";
|
|
4291
4291
|
var vec3 = require_vec3();
|
|
4292
|
-
var
|
|
4292
|
+
var mat42 = require_mat4();
|
|
4293
4293
|
var poly3 = require_poly3();
|
|
4294
4294
|
var create = require_create5();
|
|
4295
4295
|
var fromCompactBinary = (data) => {
|
|
4296
4296
|
if (data[0] !== 1) throw new Error("invalid compact binary data");
|
|
4297
4297
|
const created = create();
|
|
4298
|
-
created.transforms =
|
|
4298
|
+
created.transforms = mat42.clone(data.slice(1, 17));
|
|
4299
4299
|
const numberOfVertices = data[21];
|
|
4300
4300
|
let ci = 22;
|
|
4301
4301
|
let vi = data.length - numberOfVertices * 3;
|
|
@@ -4322,12 +4322,12 @@ var require_fromCompactBinary2 = __commonJS({
|
|
|
4322
4322
|
var require_applyTransforms2 = __commonJS({
|
|
4323
4323
|
"node_modules/@jscad/modeling/src/geometries/geom3/applyTransforms.js"(exports, module) {
|
|
4324
4324
|
"use strict";
|
|
4325
|
-
var
|
|
4325
|
+
var mat42 = require_mat4();
|
|
4326
4326
|
var poly3 = require_poly3();
|
|
4327
4327
|
var applyTransforms = (geometry) => {
|
|
4328
|
-
if (
|
|
4328
|
+
if (mat42.isIdentity(geometry.transforms)) return geometry;
|
|
4329
4329
|
geometry.polygons = geometry.polygons.map((polygon3) => poly3.transform(geometry.transforms, polygon3));
|
|
4330
|
-
geometry.transforms =
|
|
4330
|
+
geometry.transforms = mat42.create();
|
|
4331
4331
|
return geometry;
|
|
4332
4332
|
};
|
|
4333
4333
|
module.exports = applyTransforms;
|
|
@@ -4516,9 +4516,9 @@ var require_toCompactBinary2 = __commonJS({
|
|
|
4516
4516
|
var require_transform7 = __commonJS({
|
|
4517
4517
|
"node_modules/@jscad/modeling/src/geometries/geom3/transform.js"(exports, module) {
|
|
4518
4518
|
"use strict";
|
|
4519
|
-
var
|
|
4519
|
+
var mat42 = require_mat4();
|
|
4520
4520
|
var transform = (matrix, geometry) => {
|
|
4521
|
-
const transforms =
|
|
4521
|
+
const transforms = mat42.multiply(mat42.create(), matrix, geometry.transforms);
|
|
4522
4522
|
return Object.assign({}, geometry, { transforms });
|
|
4523
4523
|
};
|
|
4524
4524
|
module.exports = transform;
|
|
@@ -4632,7 +4632,7 @@ var require_close = __commonJS({
|
|
|
4632
4632
|
var require_create8 = __commonJS({
|
|
4633
4633
|
"node_modules/@jscad/modeling/src/geometries/path2/create.js"(exports, module) {
|
|
4634
4634
|
"use strict";
|
|
4635
|
-
var
|
|
4635
|
+
var mat42 = require_mat4();
|
|
4636
4636
|
var create = (points) => {
|
|
4637
4637
|
if (points === void 0) {
|
|
4638
4638
|
points = [];
|
|
@@ -4640,7 +4640,7 @@ var require_create8 = __commonJS({
|
|
|
4640
4640
|
return {
|
|
4641
4641
|
points,
|
|
4642
4642
|
isClosed: false,
|
|
4643
|
-
transforms:
|
|
4643
|
+
transforms: mat42.create()
|
|
4644
4644
|
};
|
|
4645
4645
|
};
|
|
4646
4646
|
module.exports = create;
|
|
@@ -4678,12 +4678,12 @@ var require_fromPoints5 = __commonJS({
|
|
|
4678
4678
|
var require_applyTransforms3 = __commonJS({
|
|
4679
4679
|
"node_modules/@jscad/modeling/src/geometries/path2/applyTransforms.js"(exports, module) {
|
|
4680
4680
|
"use strict";
|
|
4681
|
-
var
|
|
4681
|
+
var mat42 = require_mat4();
|
|
4682
4682
|
var vec2 = require_vec2();
|
|
4683
4683
|
var applyTransforms = (geometry) => {
|
|
4684
|
-
if (
|
|
4684
|
+
if (mat42.isIdentity(geometry.transforms)) return geometry;
|
|
4685
4685
|
geometry.points = geometry.points.map((point) => vec2.transform(vec2.create(), point, geometry.transforms));
|
|
4686
|
-
geometry.transforms =
|
|
4686
|
+
geometry.transforms = mat42.create();
|
|
4687
4687
|
return geometry;
|
|
4688
4688
|
};
|
|
4689
4689
|
module.exports = applyTransforms;
|
|
@@ -4990,13 +4990,13 @@ var require_equals5 = __commonJS({
|
|
|
4990
4990
|
var require_fromCompactBinary3 = __commonJS({
|
|
4991
4991
|
"node_modules/@jscad/modeling/src/geometries/path2/fromCompactBinary.js"(exports, module) {
|
|
4992
4992
|
"use strict";
|
|
4993
|
-
var
|
|
4993
|
+
var mat42 = require_mat4();
|
|
4994
4994
|
var vec2 = require_vec2();
|
|
4995
4995
|
var create = require_create8();
|
|
4996
4996
|
var fromCompactBinary = (data) => {
|
|
4997
4997
|
if (data[0] !== 2) throw new Error("invalid compact binary data");
|
|
4998
4998
|
const created = create();
|
|
4999
|
-
created.transforms =
|
|
4999
|
+
created.transforms = mat42.clone(data.slice(1, 17));
|
|
5000
5000
|
created.isClosed = !!data[17];
|
|
5001
5001
|
for (let i = 22; i < data.length; i += 2) {
|
|
5002
5002
|
const point = vec2.fromValues(data[i], data[i + 1]);
|
|
@@ -5110,9 +5110,9 @@ var require_toCompactBinary3 = __commonJS({
|
|
|
5110
5110
|
var require_transform8 = __commonJS({
|
|
5111
5111
|
"node_modules/@jscad/modeling/src/geometries/path2/transform.js"(exports, module) {
|
|
5112
5112
|
"use strict";
|
|
5113
|
-
var
|
|
5113
|
+
var mat42 = require_mat4();
|
|
5114
5114
|
var transform = (matrix, geometry) => {
|
|
5115
|
-
const transforms =
|
|
5115
|
+
const transforms = mat42.multiply(mat42.create(), matrix, geometry.transforms);
|
|
5116
5116
|
return Object.assign({}, geometry, { transforms });
|
|
5117
5117
|
};
|
|
5118
5118
|
module.exports = transform;
|
|
@@ -7683,7 +7683,7 @@ var require_polyhedron = __commonJS({
|
|
|
7683
7683
|
var require_geodesicSphere = __commonJS({
|
|
7684
7684
|
"node_modules/@jscad/modeling/src/primitives/geodesicSphere.js"(exports, module) {
|
|
7685
7685
|
"use strict";
|
|
7686
|
-
var
|
|
7686
|
+
var mat42 = require_mat4();
|
|
7687
7687
|
var vec3 = require_vec3();
|
|
7688
7688
|
var geom35 = require_geom3();
|
|
7689
7689
|
var polyhedron = require_polyhedron();
|
|
@@ -7799,7 +7799,7 @@ var require_geodesicSphere = __commonJS({
|
|
|
7799
7799
|
offset = g.offset;
|
|
7800
7800
|
}
|
|
7801
7801
|
let geometry = polyhedron({ points, faces, orientation: "inward" });
|
|
7802
|
-
if (radius !== 1) geometry = geom35.transform(
|
|
7802
|
+
if (radius !== 1) geometry = geom35.transform(mat42.fromScaling(mat42.create(), [radius, radius, radius]), geometry);
|
|
7803
7803
|
return geometry;
|
|
7804
7804
|
};
|
|
7805
7805
|
module.exports = geodesicSphere;
|
|
@@ -8327,7 +8327,7 @@ var require_mirror = __commonJS({
|
|
|
8327
8327
|
"node_modules/@jscad/modeling/src/operations/transforms/mirror.js"(exports, module) {
|
|
8328
8328
|
"use strict";
|
|
8329
8329
|
var flatten = require_flatten();
|
|
8330
|
-
var
|
|
8330
|
+
var mat42 = require_mat4();
|
|
8331
8331
|
var plane = require_plane();
|
|
8332
8332
|
var geom2 = require_geom2();
|
|
8333
8333
|
var geom35 = require_geom3();
|
|
@@ -8345,7 +8345,7 @@ var require_mirror = __commonJS({
|
|
|
8345
8345
|
if (Number.isNaN(planeOfMirror[0])) {
|
|
8346
8346
|
throw new Error("the given origin and normal do not define a proper plane");
|
|
8347
8347
|
}
|
|
8348
|
-
const matrix =
|
|
8348
|
+
const matrix = mat42.mirrorByPlane(mat42.create(), planeOfMirror);
|
|
8349
8349
|
const results = objects.map((object) => {
|
|
8350
8350
|
if (path2.isA(object)) return path2.transform(matrix, object);
|
|
8351
8351
|
if (geom2.isA(object)) return geom2.transform(matrix, object);
|
|
@@ -9324,7 +9324,7 @@ var require_extrudeWalls = __commonJS({
|
|
|
9324
9324
|
var require_extrudeFromSlices = __commonJS({
|
|
9325
9325
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeFromSlices.js"(exports, module) {
|
|
9326
9326
|
"use strict";
|
|
9327
|
-
var
|
|
9327
|
+
var mat42 = require_mat4();
|
|
9328
9328
|
var geom2 = require_geom2();
|
|
9329
9329
|
var geom35 = require_geom3();
|
|
9330
9330
|
var poly3 = require_poly3();
|
|
@@ -9335,7 +9335,7 @@ var require_extrudeFromSlices = __commonJS({
|
|
|
9335
9335
|
let baseSlice = null;
|
|
9336
9336
|
if (geom2.isA(base)) baseSlice = slice.fromSides(geom2.toSides(base));
|
|
9337
9337
|
if (poly3.isA(base)) baseSlice = slice.fromPoints(poly3.toPoints(base));
|
|
9338
|
-
return progress === 0 || progress === 1 ? slice.transform(
|
|
9338
|
+
return progress === 0 || progress === 1 ? slice.transform(mat42.fromTranslation(mat42.create(), [0, 0, progress]), baseSlice) : null;
|
|
9339
9339
|
};
|
|
9340
9340
|
var extrudeFromSlices = (options, base) => {
|
|
9341
9341
|
const defaults = {
|
|
@@ -9404,7 +9404,7 @@ var require_extrudeRotate = __commonJS({
|
|
|
9404
9404
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeRotate.js"(exports, module) {
|
|
9405
9405
|
"use strict";
|
|
9406
9406
|
var { TAU } = require_constants();
|
|
9407
|
-
var
|
|
9407
|
+
var mat42 = require_mat4();
|
|
9408
9408
|
var { mirrorX } = require_mirror();
|
|
9409
9409
|
var geom2 = require_geom2();
|
|
9410
9410
|
var slice = require_slice();
|
|
@@ -9465,16 +9465,16 @@ var require_extrudeRotate = __commonJS({
|
|
|
9465
9465
|
const isCapped = Math.abs(totalRotation) < TAU;
|
|
9466
9466
|
const baseSlice = slice.fromSides(geom2.toSides(geometry));
|
|
9467
9467
|
slice.reverse(baseSlice, baseSlice);
|
|
9468
|
-
const matrix =
|
|
9469
|
-
const xRotationMatrix =
|
|
9470
|
-
const zRotationMatrix =
|
|
9468
|
+
const matrix = mat42.create();
|
|
9469
|
+
const xRotationMatrix = mat42.fromXRotation(mat42.create(), TAU / 4);
|
|
9470
|
+
const zRotationMatrix = mat42.create();
|
|
9471
9471
|
const createSlice = (progress, index, base) => {
|
|
9472
9472
|
let Zrotation = rotationPerSlice * index + startAngle;
|
|
9473
9473
|
if (totalRotation === TAU && index === segments) {
|
|
9474
9474
|
Zrotation = startAngle;
|
|
9475
9475
|
}
|
|
9476
|
-
|
|
9477
|
-
|
|
9476
|
+
mat42.fromZRotation(zRotationMatrix, Zrotation);
|
|
9477
|
+
mat42.multiply(matrix, zRotationMatrix, xRotationMatrix);
|
|
9478
9478
|
return slice.transform(matrix, base);
|
|
9479
9479
|
};
|
|
9480
9480
|
options = {
|
|
@@ -9495,7 +9495,7 @@ var require_rotate3 = __commonJS({
|
|
|
9495
9495
|
"node_modules/@jscad/modeling/src/operations/transforms/rotate.js"(exports, module) {
|
|
9496
9496
|
"use strict";
|
|
9497
9497
|
var flatten = require_flatten();
|
|
9498
|
-
var
|
|
9498
|
+
var mat42 = require_mat4();
|
|
9499
9499
|
var geom2 = require_geom2();
|
|
9500
9500
|
var geom35 = require_geom3();
|
|
9501
9501
|
var path2 = require_path2();
|
|
@@ -9508,7 +9508,7 @@ var require_rotate3 = __commonJS({
|
|
|
9508
9508
|
const yaw = angles[2];
|
|
9509
9509
|
const pitch = angles[1];
|
|
9510
9510
|
const roll = angles[0];
|
|
9511
|
-
const matrix =
|
|
9511
|
+
const matrix = mat42.fromTaitBryanRotation(mat42.create(), yaw, pitch, roll);
|
|
9512
9512
|
const results = objects.map((object) => {
|
|
9513
9513
|
if (path2.isA(object)) return path2.transform(matrix, object);
|
|
9514
9514
|
if (geom2.isA(object)) return geom2.transform(matrix, object);
|
|
@@ -9534,7 +9534,7 @@ var require_translate2 = __commonJS({
|
|
|
9534
9534
|
"node_modules/@jscad/modeling/src/operations/transforms/translate.js"(exports, module) {
|
|
9535
9535
|
"use strict";
|
|
9536
9536
|
var flatten = require_flatten();
|
|
9537
|
-
var
|
|
9537
|
+
var mat42 = require_mat4();
|
|
9538
9538
|
var geom2 = require_geom2();
|
|
9539
9539
|
var geom35 = require_geom3();
|
|
9540
9540
|
var path2 = require_path2();
|
|
@@ -9544,7 +9544,7 @@ var require_translate2 = __commonJS({
|
|
|
9544
9544
|
if (objects.length === 0) throw new Error("wrong number of arguments");
|
|
9545
9545
|
offset = offset.slice();
|
|
9546
9546
|
while (offset.length < 3) offset.push(0);
|
|
9547
|
-
const matrix =
|
|
9547
|
+
const matrix = mat42.fromTranslation(mat42.create(), offset);
|
|
9548
9548
|
const results = objects.map((object) => {
|
|
9549
9549
|
if (path2.isA(object)) return path2.transform(matrix, object);
|
|
9550
9550
|
if (geom2.isA(object)) return geom2.transform(matrix, object);
|
|
@@ -10205,7 +10205,7 @@ var require_to3DWalls = __commonJS({
|
|
|
10205
10205
|
var require_OrthoNormalBasis = __commonJS({
|
|
10206
10206
|
"node_modules/@jscad/modeling/src/maths/OrthoNormalBasis.js"(exports, module) {
|
|
10207
10207
|
"use strict";
|
|
10208
|
-
var
|
|
10208
|
+
var mat42 = require_mat4();
|
|
10209
10209
|
var vec2 = require_vec2();
|
|
10210
10210
|
var vec3 = require_vec3();
|
|
10211
10211
|
var OrthoNormalBasis = function(plane, rightvector) {
|
|
@@ -10219,7 +10219,7 @@ var require_OrthoNormalBasis = __commonJS({
|
|
|
10219
10219
|
};
|
|
10220
10220
|
OrthoNormalBasis.prototype = {
|
|
10221
10221
|
getProjectionMatrix: function() {
|
|
10222
|
-
return
|
|
10222
|
+
return mat42.fromValues(
|
|
10223
10223
|
this.u[0],
|
|
10224
10224
|
this.v[0],
|
|
10225
10225
|
this.plane[0],
|
|
@@ -10240,7 +10240,7 @@ var require_OrthoNormalBasis = __commonJS({
|
|
|
10240
10240
|
},
|
|
10241
10241
|
getInverseProjectionMatrix: function() {
|
|
10242
10242
|
const p = vec3.scale(vec3.create(), this.plane, this.plane[3]);
|
|
10243
|
-
return
|
|
10243
|
+
return mat42.fromValues(
|
|
10244
10244
|
this.u[0],
|
|
10245
10245
|
this.u[1],
|
|
10246
10246
|
this.u[2],
|
|
@@ -11898,7 +11898,7 @@ var require_expandGeom2 = __commonJS({
|
|
|
11898
11898
|
var require_extrudePolygon = __commonJS({
|
|
11899
11899
|
"node_modules/@jscad/modeling/src/operations/expansions/extrudePolygon.js"(exports, module) {
|
|
11900
11900
|
"use strict";
|
|
11901
|
-
var
|
|
11901
|
+
var mat42 = require_mat4();
|
|
11902
11902
|
var vec3 = require_vec3();
|
|
11903
11903
|
var geom35 = require_geom3();
|
|
11904
11904
|
var poly3 = require_poly3();
|
|
@@ -11908,7 +11908,7 @@ var require_extrudePolygon = __commonJS({
|
|
|
11908
11908
|
polygon1 = poly3.invert(polygon1);
|
|
11909
11909
|
}
|
|
11910
11910
|
const newpolygons = [polygon1];
|
|
11911
|
-
const polygon22 = poly3.transform(
|
|
11911
|
+
const polygon22 = poly3.transform(mat42.fromTranslation(mat42.create(), offsetvector), polygon1);
|
|
11912
11912
|
const numvertices = polygon1.vertices.length;
|
|
11913
11913
|
for (let i = 0; i < numvertices; i++) {
|
|
11914
11914
|
const nexti = i < numvertices - 1 ? i + 1 : 0;
|
|
@@ -11932,7 +11932,7 @@ var require_expandShell = __commonJS({
|
|
|
11932
11932
|
"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(exports, module) {
|
|
11933
11933
|
"use strict";
|
|
11934
11934
|
var { EPS: EPS4, TAU } = require_constants();
|
|
11935
|
-
var
|
|
11935
|
+
var mat42 = require_mat4();
|
|
11936
11936
|
var vec3 = require_vec3();
|
|
11937
11937
|
var fnNumberSort = require_fnNumberSort();
|
|
11938
11938
|
var geom35 = require_geom3();
|
|
@@ -11983,7 +11983,7 @@ var require_expandShell = __commonJS({
|
|
|
11983
11983
|
const polygons = geom35.toPolygons(geometry);
|
|
11984
11984
|
polygons.forEach((polygon3, index) => {
|
|
11985
11985
|
const extrudevector = vec3.scale(vec3.create(), poly3.plane(polygon3), 2 * delta);
|
|
11986
|
-
const translatedpolygon = poly3.transform(
|
|
11986
|
+
const translatedpolygon = poly3.transform(mat42.fromTranslation(mat42.create(), vec3.scale(vec3.create(), extrudevector, -0.5)), polygon3);
|
|
11987
11987
|
const extrudedface = extrudePolygon2(extrudevector, translatedpolygon);
|
|
11988
11988
|
result = unionGeom3Sub(result, extrudedface);
|
|
11989
11989
|
const vertices = polygon3.vertices;
|
|
@@ -12328,7 +12328,7 @@ var require_expansions = __commonJS({
|
|
|
12328
12328
|
var require_extrudeLinearGeom2 = __commonJS({
|
|
12329
12329
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeLinearGeom2.js"(exports, module) {
|
|
12330
12330
|
"use strict";
|
|
12331
|
-
var
|
|
12331
|
+
var mat42 = require_mat4();
|
|
12332
12332
|
var vec3 = require_vec3();
|
|
12333
12333
|
var geom2 = require_geom2();
|
|
12334
12334
|
var slice = require_slice();
|
|
@@ -12350,11 +12350,11 @@ var require_extrudeLinearGeom2 = __commonJS({
|
|
|
12350
12350
|
if (baseSides.length === 0) throw new Error("the given geometry cannot be empty");
|
|
12351
12351
|
const baseSlice = slice.fromSides(baseSides);
|
|
12352
12352
|
if (offsetv[2] < 0) slice.reverse(baseSlice, baseSlice);
|
|
12353
|
-
const matrix =
|
|
12353
|
+
const matrix = mat42.create();
|
|
12354
12354
|
const createTwist = (progress, index, base) => {
|
|
12355
12355
|
const Zrotation = index / twistSteps * twistAngle;
|
|
12356
12356
|
const Zoffset = vec3.scale(vec3.create(), offsetv, index / twistSteps);
|
|
12357
|
-
|
|
12357
|
+
mat42.multiply(matrix, mat42.fromZRotation(matrix, Zrotation), mat42.fromTranslation(mat42.create(), Zoffset));
|
|
12358
12358
|
return slice.transform(matrix, base);
|
|
12359
12359
|
};
|
|
12360
12360
|
options = {
|
|
@@ -12508,7 +12508,7 @@ var require_extrudeHelical = __commonJS({
|
|
|
12508
12508
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeHelical.js"(exports, module) {
|
|
12509
12509
|
"use strict";
|
|
12510
12510
|
var { TAU } = require_constants();
|
|
12511
|
-
var
|
|
12511
|
+
var mat42 = require_mat4();
|
|
12512
12512
|
var geom2 = require_geom2();
|
|
12513
12513
|
var extrudeFromSlices = require_extrudeFromSlices();
|
|
12514
12514
|
var slice = require_slice();
|
|
@@ -12538,24 +12538,24 @@ var require_extrudeHelical = __commonJS({
|
|
|
12538
12538
|
}
|
|
12539
12539
|
const calculatedSegments = Math.round(segmentsPerRotation / TAU * Math.abs(angle));
|
|
12540
12540
|
const segments = calculatedSegments >= 2 ? calculatedSegments : 2;
|
|
12541
|
-
const step1 =
|
|
12542
|
-
const step2 =
|
|
12541
|
+
const step1 = mat42.create();
|
|
12542
|
+
const step2 = mat42.create();
|
|
12543
12543
|
const sliceCallback = (progress, index, base) => {
|
|
12544
12544
|
const zRotation = startAngle + angle / segments * index;
|
|
12545
12545
|
const xOffset = endOffset / segments * index;
|
|
12546
12546
|
const zOffset = (zRotation - startAngle) / TAU * pitch;
|
|
12547
|
-
|
|
12547
|
+
mat42.multiply(
|
|
12548
12548
|
step1,
|
|
12549
12549
|
// then apply offsets
|
|
12550
|
-
|
|
12550
|
+
mat42.fromTranslation(mat42.create(), [xOffset, 0, zOffset * Math.sign(angle)]),
|
|
12551
12551
|
// first rotate "flat" 2D shape from XY to XZ plane
|
|
12552
|
-
|
|
12552
|
+
mat42.fromXRotation(mat42.create(), -TAU / 4 * Math.sign(angle))
|
|
12553
12553
|
// rotate the slice correctly to not create inside-out polygon
|
|
12554
12554
|
);
|
|
12555
|
-
|
|
12555
|
+
mat42.multiply(
|
|
12556
12556
|
step2,
|
|
12557
12557
|
// finally rotate around Z axis
|
|
12558
|
-
|
|
12558
|
+
mat42.fromZRotation(mat42.create(), zRotation),
|
|
12559
12559
|
step1
|
|
12560
12560
|
);
|
|
12561
12561
|
return slice.transform(step2, base);
|
|
@@ -12580,7 +12580,7 @@ var require_project = __commonJS({
|
|
|
12580
12580
|
var flatten = require_flatten();
|
|
12581
12581
|
var aboutEqualNormals = require_aboutEqualNormals();
|
|
12582
12582
|
var plane = require_plane();
|
|
12583
|
-
var
|
|
12583
|
+
var mat42 = require_mat4();
|
|
12584
12584
|
var geom2 = require_geom2();
|
|
12585
12585
|
var geom35 = require_geom3();
|
|
12586
12586
|
var poly3 = require_poly3();
|
|
@@ -12605,7 +12605,7 @@ var require_project = __commonJS({
|
|
|
12605
12605
|
projpolys.push(newpoly);
|
|
12606
12606
|
}
|
|
12607
12607
|
if (!aboutEqualNormals(projplane, [0, 0, 1])) {
|
|
12608
|
-
const rotation =
|
|
12608
|
+
const rotation = mat42.fromVectorRotation(mat42.create(), projplane, [0, 0, 1]);
|
|
12609
12609
|
projpolys = projpolys.map((p) => poly3.transform(rotation, p));
|
|
12610
12610
|
}
|
|
12611
12611
|
projpolys = projpolys.sort((a, b) => poly3.measureArea(b) - poly3.measureArea(a));
|
|
@@ -13586,7 +13586,7 @@ var require_scale4 = __commonJS({
|
|
|
13586
13586
|
"node_modules/@jscad/modeling/src/operations/transforms/scale.js"(exports, module) {
|
|
13587
13587
|
"use strict";
|
|
13588
13588
|
var flatten = require_flatten();
|
|
13589
|
-
var
|
|
13589
|
+
var mat42 = require_mat4();
|
|
13590
13590
|
var geom2 = require_geom2();
|
|
13591
13591
|
var geom35 = require_geom3();
|
|
13592
13592
|
var path2 = require_path2();
|
|
@@ -13597,7 +13597,7 @@ var require_scale4 = __commonJS({
|
|
|
13597
13597
|
factors = factors.slice();
|
|
13598
13598
|
while (factors.length < 3) factors.push(1);
|
|
13599
13599
|
if (factors[0] <= 0 || factors[1] <= 0 || factors[2] <= 0) throw new Error("factors must be positive");
|
|
13600
|
-
const matrix =
|
|
13600
|
+
const matrix = mat42.fromScaling(mat42.create(), factors);
|
|
13601
13601
|
const results = objects.map((object) => {
|
|
13602
13602
|
if (path2.isA(object)) return path2.transform(matrix, object);
|
|
13603
13603
|
if (geom2.isA(object)) return geom2.transform(matrix, object);
|
|
@@ -13847,7 +13847,93 @@ function polygonsTouch(a, b) {
|
|
|
13847
13847
|
}
|
|
13848
13848
|
return false;
|
|
13849
13849
|
}
|
|
13850
|
+
function polygonContainsPolygon(boundary, polygon3) {
|
|
13851
|
+
if (polygon3.some((p) => !pointInPolygon(p, boundary))) return false;
|
|
13852
|
+
for (let i = 0; i < polygon3.length; i++) {
|
|
13853
|
+
const a = polygon3[i], b = polygon3[(i + 1) % polygon3.length];
|
|
13854
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
13855
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
13856
|
+
if (lengthSquared < EPS * EPS) continue;
|
|
13857
|
+
const crossings = [0, 1];
|
|
13858
|
+
for (let j = 0; j < boundary.length; j++) {
|
|
13859
|
+
const c = boundary[j], d = boundary[(j + 1) % boundary.length];
|
|
13860
|
+
const ex = d.x - c.x, ey = d.y - c.y;
|
|
13861
|
+
const denominator = dx * ey - dy * ex;
|
|
13862
|
+
const cx = c.x - a.x, cy = c.y - a.y;
|
|
13863
|
+
if (Math.abs(denominator) < EPS) {
|
|
13864
|
+
if (Math.abs(cx * dy - cy * dx) > EPS) continue;
|
|
13865
|
+
for (const p of [c, d]) {
|
|
13866
|
+
const t = ((p.x - a.x) * dx + (p.y - a.y) * dy) / lengthSquared;
|
|
13867
|
+
if (t > 0 && t < 1) crossings.push(t);
|
|
13868
|
+
}
|
|
13869
|
+
} else {
|
|
13870
|
+
const t = (cx * ey - cy * ex) / denominator;
|
|
13871
|
+
const u = (cx * dy - cy * dx) / denominator;
|
|
13872
|
+
if (t > 0 && t < 1 && u >= -EPS && u <= 1 + EPS) crossings.push(t);
|
|
13873
|
+
}
|
|
13874
|
+
}
|
|
13875
|
+
crossings.sort((a2, b2) => a2 - b2);
|
|
13876
|
+
for (let j = 1; j < crossings.length; j++) {
|
|
13877
|
+
const t = (crossings[j - 1] + crossings[j]) / 2;
|
|
13878
|
+
if (!pointInPolygon({ x: a.x + t * dx, y: a.y + t * dy }, boundary))
|
|
13879
|
+
return false;
|
|
13880
|
+
}
|
|
13881
|
+
}
|
|
13882
|
+
return true;
|
|
13883
|
+
}
|
|
13850
13884
|
var EPS2 = 1e-7;
|
|
13885
|
+
function orderPcbBends(bends) {
|
|
13886
|
+
const sorted = [...bends].sort(
|
|
13887
|
+
(a, b) => a.start - b.start || a.nx - b.nx || a.ny - b.ny || a.id.localeCompare(b.id)
|
|
13888
|
+
);
|
|
13889
|
+
const parents = /* @__PURE__ */ new Map();
|
|
13890
|
+
const overlap = (bend) => {
|
|
13891
|
+
throw new PcbFoldError({
|
|
13892
|
+
code: "overlapping_bend_zones",
|
|
13893
|
+
message: "Overlapping PCB bend zones or incompatible moving regions are not supported",
|
|
13894
|
+
bendId: bend.id
|
|
13895
|
+
});
|
|
13896
|
+
};
|
|
13897
|
+
for (let i = 0; i < sorted.length; i++)
|
|
13898
|
+
for (let j = i + 1; j < sorted.length; j++) {
|
|
13899
|
+
const a = sorted[i], b = sorted[j];
|
|
13900
|
+
if (a.movingOutline && b.movingOutline) {
|
|
13901
|
+
if (!polygonsTouch(a.movingOutline, b.movingOutline)) continue;
|
|
13902
|
+
const aContainsB = polygonContainsPolygon(
|
|
13903
|
+
a.movingOutline,
|
|
13904
|
+
b.movingOutline
|
|
13905
|
+
);
|
|
13906
|
+
const bContainsA = polygonContainsPolygon(
|
|
13907
|
+
b.movingOutline,
|
|
13908
|
+
a.movingOutline
|
|
13909
|
+
);
|
|
13910
|
+
if (aContainsB === bContainsA) overlap(b);
|
|
13911
|
+
const parent = aContainsB ? a : b, child = aContainsB ? b : a;
|
|
13912
|
+
if (child.movingOutline.some(
|
|
13913
|
+
(p) => p.x * parent.nx + p.y * parent.ny < parent.end - EPS2
|
|
13914
|
+
))
|
|
13915
|
+
overlap(child);
|
|
13916
|
+
parents.set(child, [...parents.get(child) ?? [], parent]);
|
|
13917
|
+
} else {
|
|
13918
|
+
if (Math.abs(a.nx - b.nx) > EPS2 || Math.abs(a.ny - b.ny) > EPS2)
|
|
13919
|
+
throw new PcbFoldError({
|
|
13920
|
+
code: "nonparallel_bends",
|
|
13921
|
+
message: "Nonparallel PCB bends or bends with opposite moving directions require a board outline to resolve their moving regions"
|
|
13922
|
+
});
|
|
13923
|
+
if (b.start < a.end - EPS2) overlap(b);
|
|
13924
|
+
parents.set(b, [...parents.get(b) ?? [], a]);
|
|
13925
|
+
}
|
|
13926
|
+
}
|
|
13927
|
+
const ordered = [], visited = /* @__PURE__ */ new Set();
|
|
13928
|
+
const visit = (bend) => {
|
|
13929
|
+
if (visited.has(bend)) return;
|
|
13930
|
+
for (const parent of parents.get(bend) ?? []) visit(parent);
|
|
13931
|
+
visited.add(bend);
|
|
13932
|
+
ordered.push(bend);
|
|
13933
|
+
};
|
|
13934
|
+
for (const bend of sorted) visit(bend);
|
|
13935
|
+
return ordered;
|
|
13936
|
+
}
|
|
13851
13937
|
function createPcbFold(records, thickness, { outline } = {}) {
|
|
13852
13938
|
if (!Number.isFinite(thickness) || thickness < 0)
|
|
13853
13939
|
throw new Error("Board thickness must be finite and nonnegative");
|
|
@@ -13908,27 +13994,8 @@ function createPcbFold(records, thickness, { outline } = {}) {
|
|
|
13908
13994
|
});
|
|
13909
13995
|
return geometry;
|
|
13910
13996
|
}).filter((b) => Math.abs(b.angle) > EPS2);
|
|
13911
|
-
const
|
|
13912
|
-
|
|
13913
|
-
(b) => Math.abs(b.nx - first.nx) > EPS2 || Math.abs(b.ny - first.ny) > EPS2
|
|
13914
|
-
)) {
|
|
13915
|
-
throw new PcbFoldError({
|
|
13916
|
-
code: "nonparallel_bends",
|
|
13917
|
-
message: "Folded PCB rendering currently requires parallel bends with the same moving direction"
|
|
13918
|
-
});
|
|
13919
|
-
}
|
|
13920
|
-
bends.sort((a, b) => a.start - b.start);
|
|
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
|
-
}
|
|
13931
|
-
const distalFirst = [...bends].reverse();
|
|
13997
|
+
const proximalFirst = orderPcbBends(bends);
|
|
13998
|
+
const distalFirst = [...proximalFirst].reverse();
|
|
13932
13999
|
const transform = ({
|
|
13933
14000
|
p,
|
|
13934
14001
|
anchor,
|
|
@@ -13977,7 +14044,7 @@ function createPcbFold(records, thickness, { outline } = {}) {
|
|
|
13977
14044
|
return { x: dot2(axes2[0]), y: dot2(axes2[1]), z: dot2(axes2[2]) };
|
|
13978
14045
|
};
|
|
13979
14046
|
return {
|
|
13980
|
-
bends,
|
|
14047
|
+
bends: proximalFirst,
|
|
13981
14048
|
inversePoint: (p, anchor) => inverse({ p, anchor, direction: false }),
|
|
13982
14049
|
inverseDirection: (p, anchor) => inverse({ p, anchor, direction: true }),
|
|
13983
14050
|
point: (p, anchor = p) => transform({ p, anchor, direction: false }),
|
|
@@ -14969,6 +15036,14 @@ function tryFoldRigidBox(box, fold, boardCenter, mount) {
|
|
|
14969
15036
|
};
|
|
14970
15037
|
}
|
|
14971
15038
|
|
|
15039
|
+
// lib/utils/circuit-json-errors.ts
|
|
15040
|
+
function withCircuitJsonErrors(scene, circuitJson) {
|
|
15041
|
+
const errorMessages = circuitJson.flatMap(
|
|
15042
|
+
(element) => "error_type" in element && typeof element.error_type === "string" && "message" in element && typeof element.message === "string" ? [element.message] : []
|
|
15043
|
+
);
|
|
15044
|
+
return errorMessages.length ? { ...scene, errorMessages } : scene;
|
|
15045
|
+
}
|
|
15046
|
+
|
|
14972
15047
|
// lib/converters/circuit-to-3d.ts
|
|
14973
15048
|
import { cju, findBoundsAndCenter } from "@tscircuit/circuit-json-util";
|
|
14974
15049
|
|
|
@@ -18607,11 +18682,12 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
18607
18682
|
direction: { x: -1, y: -1, z: -1 }
|
|
18608
18683
|
}
|
|
18609
18684
|
];
|
|
18610
|
-
|
|
18685
|
+
const scene = {
|
|
18611
18686
|
boxes,
|
|
18612
18687
|
camera,
|
|
18613
18688
|
lights
|
|
18614
18689
|
};
|
|
18690
|
+
return options.showErrors ? withCircuitJsonErrors(scene, inputCircuitJson) : scene;
|
|
18615
18691
|
}
|
|
18616
18692
|
|
|
18617
18693
|
// lib/gltf/gltf-types.ts
|
|
@@ -18780,6 +18856,13 @@ var GLTFBuilder = class {
|
|
|
18780
18856
|
this.materialCache = /* @__PURE__ */ new Map();
|
|
18781
18857
|
}
|
|
18782
18858
|
async buildFromScene3D(scene3D) {
|
|
18859
|
+
if (scene3D.errorMessages?.length) {
|
|
18860
|
+
this.gltf.scenes[0].extras = {
|
|
18861
|
+
tscircuit: {
|
|
18862
|
+
errorMessages: [...scene3D.errorMessages]
|
|
18863
|
+
}
|
|
18864
|
+
};
|
|
18865
|
+
}
|
|
18783
18866
|
const defaultMaterialIndex = this.addMaterial({
|
|
18784
18867
|
name: "Default",
|
|
18785
18868
|
pbrMetallicRoughness: {
|
|
@@ -19601,6 +19684,133 @@ async function convertSceneToGLTF(scene, options = {}) {
|
|
|
19601
19684
|
return result;
|
|
19602
19685
|
}
|
|
19603
19686
|
|
|
19687
|
+
// lib/utils/poppygl-error-overlay.ts
|
|
19688
|
+
import {
|
|
19689
|
+
glyphAdvanceRatio,
|
|
19690
|
+
glyphLineAlphabet,
|
|
19691
|
+
textMetrics
|
|
19692
|
+
} from "@tscircuit/alphabet";
|
|
19693
|
+
import { mat4, vec4 } from "gl-matrix";
|
|
19694
|
+
function readErrorMessages(gltf) {
|
|
19695
|
+
if (!gltf || typeof gltf !== "object") return;
|
|
19696
|
+
const document2 = gltf;
|
|
19697
|
+
const scene = document2.scenes?.[document2.scene ?? 0];
|
|
19698
|
+
const messages = scene?.extras?.tscircuit?.errorMessages;
|
|
19699
|
+
if (!Array.isArray(messages) || messages.length === 0 || !messages.every((message) => typeof message === "string"))
|
|
19700
|
+
return;
|
|
19701
|
+
return messages;
|
|
19702
|
+
}
|
|
19703
|
+
function displayText(message) {
|
|
19704
|
+
return Array.from(message, (character) => {
|
|
19705
|
+
if (character === ":") return " - ";
|
|
19706
|
+
if (character === ";") return ",";
|
|
19707
|
+
if (character === "?") return ".";
|
|
19708
|
+
if (character === " " || character === "\n" || glyphLineAlphabet[character] || glyphLineAlphabet[character.toUpperCase()])
|
|
19709
|
+
return character;
|
|
19710
|
+
if (character === "\r") return "";
|
|
19711
|
+
if (character === " ") return " ";
|
|
19712
|
+
return `[U+${character.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}]`;
|
|
19713
|
+
}).join("").replace(/ +/g, " ");
|
|
19714
|
+
}
|
|
19715
|
+
function characterWidth(character, fontSize) {
|
|
19716
|
+
const resolved = glyphLineAlphabet[character] ? character : character.toUpperCase();
|
|
19717
|
+
return (glyphAdvanceRatio[resolved] ?? (character === " " ? textMetrics.spaceWidthRatio : textMetrics.glyphWidthRatio)) * fontSize * 0.62;
|
|
19718
|
+
}
|
|
19719
|
+
function wrapText(text, width, fontSize) {
|
|
19720
|
+
const lines = [];
|
|
19721
|
+
for (const paragraph of text.split("\n")) {
|
|
19722
|
+
let remaining = paragraph;
|
|
19723
|
+
do {
|
|
19724
|
+
let end = 0;
|
|
19725
|
+
let lineWidth = 0;
|
|
19726
|
+
while (end < remaining.length) {
|
|
19727
|
+
const nextWidth = characterWidth(remaining[end], fontSize);
|
|
19728
|
+
if (end > 0 && lineWidth + nextWidth > width) break;
|
|
19729
|
+
lineWidth += nextWidth;
|
|
19730
|
+
end++;
|
|
19731
|
+
}
|
|
19732
|
+
if (end < remaining.length) {
|
|
19733
|
+
const space = remaining.lastIndexOf(" ", end);
|
|
19734
|
+
if (space > 0) end = space;
|
|
19735
|
+
}
|
|
19736
|
+
lines.push(remaining.slice(0, end).trimEnd());
|
|
19737
|
+
remaining = remaining.slice(end).trimStart();
|
|
19738
|
+
} while (remaining.length);
|
|
19739
|
+
}
|
|
19740
|
+
return lines;
|
|
19741
|
+
}
|
|
19742
|
+
function getPoppyglErrorOverlayOptions(gltf, camera, options) {
|
|
19743
|
+
const messages = readErrorMessages(gltf);
|
|
19744
|
+
if (!messages) return;
|
|
19745
|
+
const { width, height } = options;
|
|
19746
|
+
const fontSize = options.debugFontSize ?? 16;
|
|
19747
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || !Number.isFinite(fontSize) || width < 2 || height < 2 || fontSize < 1)
|
|
19748
|
+
throw new RangeError("Error overlay requires positive image and font sizes");
|
|
19749
|
+
const supersampling = Number.isFinite(options.supersampling) ? Math.max(1, Math.floor(options.supersampling)) : 1;
|
|
19750
|
+
const scaledFont = Math.max(1, Math.round(fontSize * supersampling));
|
|
19751
|
+
const finalFont = scaledFont / supersampling;
|
|
19752
|
+
const margin = 16;
|
|
19753
|
+
const labelWidth = Math.max(1, width - margin * 2 - finalFont * 0.6 - 2);
|
|
19754
|
+
const lines = [
|
|
19755
|
+
...wrapText(
|
|
19756
|
+
`Circuit JSON errors (${messages.length})`,
|
|
19757
|
+
labelWidth,
|
|
19758
|
+
finalFont
|
|
19759
|
+
),
|
|
19760
|
+
...messages.flatMap(
|
|
19761
|
+
(message, index) => wrapText(`${index + 1}. ${displayText(message)}`, labelWidth, finalFont)
|
|
19762
|
+
)
|
|
19763
|
+
];
|
|
19764
|
+
const rowHeight = finalFont * 1.4;
|
|
19765
|
+
const availableRows = Math.max(
|
|
19766
|
+
1,
|
|
19767
|
+
1 + Math.floor((height - margin * 2 - finalFont * 1.1) / rowHeight)
|
|
19768
|
+
);
|
|
19769
|
+
if (lines.length > availableRows) {
|
|
19770
|
+
let keptRows = availableRows - 1;
|
|
19771
|
+
let disclosure;
|
|
19772
|
+
for (; ; ) {
|
|
19773
|
+
disclosure = wrapText(
|
|
19774
|
+
`${lines.length - keptRows} more lines`,
|
|
19775
|
+
labelWidth,
|
|
19776
|
+
finalFont
|
|
19777
|
+
);
|
|
19778
|
+
const nextKeptRows = Math.max(0, availableRows - disclosure.length);
|
|
19779
|
+
if (nextKeptRows === keptRows) break;
|
|
19780
|
+
keptRows = nextKeptRows;
|
|
19781
|
+
}
|
|
19782
|
+
lines.splice(keptRows);
|
|
19783
|
+
lines.push(...disclosure.slice(0, availableRows - keptRows));
|
|
19784
|
+
}
|
|
19785
|
+
const firstTextY = margin;
|
|
19786
|
+
const viewProjection = mat4.multiply(mat4.create(), camera.proj, camera.view);
|
|
19787
|
+
const inverse = mat4.invert(mat4.create(), viewProjection);
|
|
19788
|
+
if (!inverse || !Array.from(inverse).every(Number.isFinite))
|
|
19789
|
+
throw new Error("Cannot unproject error labels with this camera");
|
|
19790
|
+
const renderWidth = width * supersampling;
|
|
19791
|
+
const renderHeight = height * supersampling;
|
|
19792
|
+
const debugPoints = lines.map((label, row) => {
|
|
19793
|
+
const pixelX = margin * supersampling;
|
|
19794
|
+
const pixelY = (firstTextY + row * rowHeight + finalFont * 1.1) * supersampling;
|
|
19795
|
+
const point = vec4.fromValues(
|
|
19796
|
+
pixelX / (renderWidth - 1) * 2 - 1,
|
|
19797
|
+
1 - pixelY / (renderHeight - 1) * 2,
|
|
19798
|
+
0,
|
|
19799
|
+
1
|
|
19800
|
+
);
|
|
19801
|
+
vec4.transformMat4(point, point, inverse);
|
|
19802
|
+
return {
|
|
19803
|
+
label,
|
|
19804
|
+
position: {
|
|
19805
|
+
x: point[0] / point[3],
|
|
19806
|
+
y: point[1] / point[3],
|
|
19807
|
+
z: point[2] / point[3]
|
|
19808
|
+
}
|
|
19809
|
+
};
|
|
19810
|
+
});
|
|
19811
|
+
return { debugPoints, debugFontSize: scaledFont };
|
|
19812
|
+
}
|
|
19813
|
+
|
|
19604
19814
|
// lib/utils/camera-position.ts
|
|
19605
19815
|
var DEFAULT_CAMERA_DIRECTION = [-0.7, 1.2, -0.8];
|
|
19606
19816
|
var TOP_DOWN_TILT = 1e-3;
|
|
@@ -19762,6 +19972,7 @@ async function convertCircuitJsonToGltf(circuitJson, options = {}) {
|
|
|
19762
19972
|
foldPcbs: options.foldPcbs,
|
|
19763
19973
|
textureResolution: boardTextureResolution,
|
|
19764
19974
|
showPcbNotes,
|
|
19975
|
+
showErrors: options.showErrors,
|
|
19765
19976
|
boardDrillQuality,
|
|
19766
19977
|
drawFauxBoard,
|
|
19767
19978
|
pcbColor: backgroundColor,
|
|
@@ -19794,6 +20005,7 @@ export {
|
|
|
19794
20005
|
convertCircuitJsonToGltf,
|
|
19795
20006
|
convertSceneToGLTF,
|
|
19796
20007
|
getBestCameraPosition,
|
|
20008
|
+
getPoppyglErrorOverlayOptions,
|
|
19797
20009
|
loadGLB,
|
|
19798
20010
|
loadJscadPlan,
|
|
19799
20011
|
loadOBJ,
|
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.140",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/tscircuit/circuit-json-to-gltf.git"
|
|
@@ -23,13 +23,14 @@
|
|
|
23
23
|
"@jscad/modeling": "^2.12.6",
|
|
24
24
|
"@tscircuit/alphabet": "^0.0.25",
|
|
25
25
|
"earcut": "^3.0.2",
|
|
26
|
+
"gl-matrix": "^3.4.4",
|
|
26
27
|
"jscad-electronics": "^0.0.178",
|
|
27
28
|
"jscad-planner": "^0.0.14",
|
|
28
29
|
"jscad-to-gltf": "^0.0.5",
|
|
29
30
|
"occt-import-js": "^0.0.23"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.
|
|
33
|
+
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.8.tgz",
|
|
33
34
|
"@biomejs/biome": "^2.1.4",
|
|
34
35
|
"@google/model-viewer": "^4.1.0",
|
|
35
36
|
"@napi-rs/canvas": "^1.0.9",
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"circuit-to-svg": "^0.0.429",
|
|
50
51
|
"graphics-debug": "^0.0.96",
|
|
51
52
|
"looks-same": "^9.0.1",
|
|
52
|
-
"poppygl": "
|
|
53
|
+
"poppygl": "0.0.29",
|
|
53
54
|
"react": "^19.1.1",
|
|
54
55
|
"react-cosmos": "^7.0.0",
|
|
55
56
|
"react-cosmos-plugin-vite": "^7.0.0",
|