circuit-json-to-gltf 0.0.146 → 0.0.148
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 +211 -398
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -263,29 +263,29 @@ var require_fromRotation = __commonJS({
|
|
|
263
263
|
var { sin, cos } = require_trigonometry();
|
|
264
264
|
var identity = require_identity();
|
|
265
265
|
var fromRotation = (out, rad, axis) => {
|
|
266
|
-
let [x, y,
|
|
267
|
-
const lengthSquared = x * x + y * y +
|
|
266
|
+
let [x, y, z] = axis;
|
|
267
|
+
const lengthSquared = x * x + y * y + z * z;
|
|
268
268
|
if (Math.abs(lengthSquared) < EPS4) {
|
|
269
269
|
return identity(out);
|
|
270
270
|
}
|
|
271
271
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
272
272
|
x *= len;
|
|
273
273
|
y *= len;
|
|
274
|
-
|
|
274
|
+
z *= len;
|
|
275
275
|
const s = sin(rad);
|
|
276
276
|
const c = cos(rad);
|
|
277
277
|
const t = 1 - c;
|
|
278
278
|
out[0] = x * x * t + c;
|
|
279
|
-
out[1] = y * x * t +
|
|
280
|
-
out[2] =
|
|
279
|
+
out[1] = y * x * t + z * s;
|
|
280
|
+
out[2] = z * x * t - y * s;
|
|
281
281
|
out[3] = 0;
|
|
282
|
-
out[4] = x * y * t -
|
|
282
|
+
out[4] = x * y * t - z * s;
|
|
283
283
|
out[5] = y * y * t + c;
|
|
284
|
-
out[6] =
|
|
284
|
+
out[6] = z * y * t + x * s;
|
|
285
285
|
out[7] = 0;
|
|
286
|
-
out[8] = x *
|
|
287
|
-
out[9] = y *
|
|
288
|
-
out[10] =
|
|
286
|
+
out[8] = x * z * t + y * s;
|
|
287
|
+
out[9] = y * z * t - x * s;
|
|
288
|
+
out[10] = z * z * t + c;
|
|
289
289
|
out[11] = 0;
|
|
290
290
|
out[12] = 0;
|
|
291
291
|
out[13] = 0;
|
|
@@ -539,8 +539,8 @@ var require_distance = __commonJS({
|
|
|
539
539
|
var distance = (a, b) => {
|
|
540
540
|
const x = b[0] - a[0];
|
|
541
541
|
const y = b[1] - a[1];
|
|
542
|
-
const
|
|
543
|
-
return Math.sqrt(x * x + y * y +
|
|
542
|
+
const z = b[2] - a[2];
|
|
543
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
544
544
|
};
|
|
545
545
|
module.exports = distance;
|
|
546
546
|
}
|
|
@@ -588,11 +588,11 @@ var require_fromValues2 = __commonJS({
|
|
|
588
588
|
"node_modules/@jscad/modeling/src/maths/vec3/fromValues.js"(exports, module) {
|
|
589
589
|
"use strict";
|
|
590
590
|
var create = require_create2();
|
|
591
|
-
var fromValues = (x, y,
|
|
591
|
+
var fromValues = (x, y, z) => {
|
|
592
592
|
const out = create();
|
|
593
593
|
out[0] = x;
|
|
594
594
|
out[1] = y;
|
|
595
|
-
out[2] =
|
|
595
|
+
out[2] = z;
|
|
596
596
|
return out;
|
|
597
597
|
};
|
|
598
598
|
module.exports = fromValues;
|
|
@@ -603,10 +603,10 @@ var require_fromValues2 = __commonJS({
|
|
|
603
603
|
var require_fromVec2 = __commonJS({
|
|
604
604
|
"node_modules/@jscad/modeling/src/maths/vec3/fromVec2.js"(exports, module) {
|
|
605
605
|
"use strict";
|
|
606
|
-
var fromVector2 = (out, vector,
|
|
606
|
+
var fromVector2 = (out, vector, z = 0) => {
|
|
607
607
|
out[0] = vector[0];
|
|
608
608
|
out[1] = vector[1];
|
|
609
|
-
out[2] =
|
|
609
|
+
out[2] = z;
|
|
610
610
|
return out;
|
|
611
611
|
};
|
|
612
612
|
module.exports = fromVector2;
|
|
@@ -620,8 +620,8 @@ var require_length = __commonJS({
|
|
|
620
620
|
var length = (vector) => {
|
|
621
621
|
const x = vector[0];
|
|
622
622
|
const y = vector[1];
|
|
623
|
-
const
|
|
624
|
-
return Math.sqrt(x * x + y * y +
|
|
623
|
+
const z = vector[2];
|
|
624
|
+
return Math.sqrt(x * x + y * y + z * z);
|
|
625
625
|
};
|
|
626
626
|
module.exports = length;
|
|
627
627
|
}
|
|
@@ -704,14 +704,14 @@ var require_normalize = __commonJS({
|
|
|
704
704
|
var normalize = (out, vector) => {
|
|
705
705
|
const x = vector[0];
|
|
706
706
|
const y = vector[1];
|
|
707
|
-
const
|
|
708
|
-
let len = x * x + y * y +
|
|
707
|
+
const z = vector[2];
|
|
708
|
+
let len = x * x + y * y + z * z;
|
|
709
709
|
if (len > 0) {
|
|
710
710
|
len = 1 / Math.sqrt(len);
|
|
711
711
|
}
|
|
712
712
|
out[0] = x * len;
|
|
713
713
|
out[1] = y * len;
|
|
714
|
-
out[2] =
|
|
714
|
+
out[2] = z * len;
|
|
715
715
|
return out;
|
|
716
716
|
};
|
|
717
717
|
module.exports = normalize;
|
|
@@ -835,8 +835,8 @@ var require_squaredDistance = __commonJS({
|
|
|
835
835
|
var squaredDistance = (a, b) => {
|
|
836
836
|
const x = b[0] - a[0];
|
|
837
837
|
const y = b[1] - a[1];
|
|
838
|
-
const
|
|
839
|
-
return x * x + y * y +
|
|
838
|
+
const z = b[2] - a[2];
|
|
839
|
+
return x * x + y * y + z * z;
|
|
840
840
|
};
|
|
841
841
|
module.exports = squaredDistance;
|
|
842
842
|
}
|
|
@@ -849,8 +849,8 @@ var require_squaredLength = __commonJS({
|
|
|
849
849
|
var squaredLength = (vector) => {
|
|
850
850
|
const x = vector[0];
|
|
851
851
|
const y = vector[1];
|
|
852
|
-
const
|
|
853
|
-
return x * x + y * y +
|
|
852
|
+
const z = vector[2];
|
|
853
|
+
return x * x + y * y + z * z;
|
|
854
854
|
};
|
|
855
855
|
module.exports = squaredLength;
|
|
856
856
|
}
|
|
@@ -886,12 +886,12 @@ var require_transform = __commonJS({
|
|
|
886
886
|
var transform = (out, vector, matrix) => {
|
|
887
887
|
const x = vector[0];
|
|
888
888
|
const y = vector[1];
|
|
889
|
-
const
|
|
890
|
-
let w = matrix[3] * x + matrix[7] * y + matrix[11] *
|
|
889
|
+
const z = vector[2];
|
|
890
|
+
let w = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
|
|
891
891
|
w = w || 1;
|
|
892
|
-
out[0] = (matrix[0] * x + matrix[4] * y + matrix[8] *
|
|
893
|
-
out[1] = (matrix[1] * x + matrix[5] * y + matrix[9] *
|
|
894
|
-
out[2] = (matrix[2] * x + matrix[6] * y + matrix[10] *
|
|
892
|
+
out[0] = (matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]) / w;
|
|
893
|
+
out[1] = (matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]) / w;
|
|
894
|
+
out[2] = (matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]) / w;
|
|
895
895
|
return out;
|
|
896
896
|
};
|
|
897
897
|
module.exports = transform;
|
|
@@ -1093,8 +1093,8 @@ var require_isMirroring = __commonJS({
|
|
|
1093
1093
|
var isMirroring = (matrix) => {
|
|
1094
1094
|
const x = matrix[4] * matrix[9] - matrix[8] * matrix[5];
|
|
1095
1095
|
const y = matrix[8] * matrix[1] - matrix[0] * matrix[9];
|
|
1096
|
-
const
|
|
1097
|
-
const d = x * matrix[2] + y * matrix[6] +
|
|
1096
|
+
const z = matrix[0] * matrix[5] - matrix[4] * matrix[1];
|
|
1097
|
+
const d = x * matrix[2] + y * matrix[6] + z * matrix[10];
|
|
1098
1098
|
return d < 0;
|
|
1099
1099
|
};
|
|
1100
1100
|
module.exports = isMirroring;
|
|
@@ -1196,15 +1196,15 @@ var require_rotate = __commonJS({
|
|
|
1196
1196
|
var { sin, cos } = require_trigonometry();
|
|
1197
1197
|
var copy = require_copy();
|
|
1198
1198
|
var rotate = (out, matrix, radians, axis) => {
|
|
1199
|
-
let [x, y,
|
|
1200
|
-
const lengthSquared = x * x + y * y +
|
|
1199
|
+
let [x, y, z] = axis;
|
|
1200
|
+
const lengthSquared = x * x + y * y + z * z;
|
|
1201
1201
|
if (Math.abs(lengthSquared) < EPS4) {
|
|
1202
1202
|
return copy(out, matrix);
|
|
1203
1203
|
}
|
|
1204
1204
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
1205
1205
|
x *= len;
|
|
1206
1206
|
y *= len;
|
|
1207
|
-
|
|
1207
|
+
z *= len;
|
|
1208
1208
|
const s = sin(radians);
|
|
1209
1209
|
const c = cos(radians);
|
|
1210
1210
|
const t = 1 - c;
|
|
@@ -1221,14 +1221,14 @@ var require_rotate = __commonJS({
|
|
|
1221
1221
|
const a22 = matrix[10];
|
|
1222
1222
|
const a23 = matrix[11];
|
|
1223
1223
|
const b00 = x * x * t + c;
|
|
1224
|
-
const b01 = y * x * t +
|
|
1225
|
-
const b02 =
|
|
1226
|
-
const b10 = x * y * t -
|
|
1224
|
+
const b01 = y * x * t + z * s;
|
|
1225
|
+
const b02 = z * x * t - y * s;
|
|
1226
|
+
const b10 = x * y * t - z * s;
|
|
1227
1227
|
const b11 = y * y * t + c;
|
|
1228
|
-
const b12 =
|
|
1229
|
-
const b20 = x *
|
|
1230
|
-
const b21 = y *
|
|
1231
|
-
const b22 =
|
|
1228
|
+
const b12 = z * y * t + x * s;
|
|
1229
|
+
const b20 = x * z * t + y * s;
|
|
1230
|
+
const b21 = y * z * t - x * s;
|
|
1231
|
+
const b22 = z * z * t + c;
|
|
1232
1232
|
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
1233
1233
|
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
1234
1234
|
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
@@ -1380,7 +1380,7 @@ var require_scale2 = __commonJS({
|
|
|
1380
1380
|
var scale = (out, matrix, dimensions) => {
|
|
1381
1381
|
const x = dimensions[0];
|
|
1382
1382
|
const y = dimensions[1];
|
|
1383
|
-
const
|
|
1383
|
+
const z = dimensions[2];
|
|
1384
1384
|
out[0] = matrix[0] * x;
|
|
1385
1385
|
out[1] = matrix[1] * x;
|
|
1386
1386
|
out[2] = matrix[2] * x;
|
|
@@ -1389,10 +1389,10 @@ var require_scale2 = __commonJS({
|
|
|
1389
1389
|
out[5] = matrix[5] * y;
|
|
1390
1390
|
out[6] = matrix[6] * y;
|
|
1391
1391
|
out[7] = matrix[7] * y;
|
|
1392
|
-
out[8] = matrix[8] *
|
|
1393
|
-
out[9] = matrix[9] *
|
|
1394
|
-
out[10] = matrix[10] *
|
|
1395
|
-
out[11] = matrix[11] *
|
|
1392
|
+
out[8] = matrix[8] * z;
|
|
1393
|
+
out[9] = matrix[9] * z;
|
|
1394
|
+
out[10] = matrix[10] * z;
|
|
1395
|
+
out[11] = matrix[11] * z;
|
|
1396
1396
|
out[12] = matrix[12];
|
|
1397
1397
|
out[13] = matrix[13];
|
|
1398
1398
|
out[14] = matrix[14];
|
|
@@ -1446,7 +1446,7 @@ var require_translate = __commonJS({
|
|
|
1446
1446
|
var translate3 = (out, matrix, offsets) => {
|
|
1447
1447
|
const x = offsets[0];
|
|
1448
1448
|
const y = offsets[1];
|
|
1449
|
-
const
|
|
1449
|
+
const z = offsets[2];
|
|
1450
1450
|
let a00;
|
|
1451
1451
|
let a01;
|
|
1452
1452
|
let a02;
|
|
@@ -1460,10 +1460,10 @@ var require_translate = __commonJS({
|
|
|
1460
1460
|
let a22;
|
|
1461
1461
|
let a23;
|
|
1462
1462
|
if (matrix === out) {
|
|
1463
|
-
out[12] = matrix[0] * x + matrix[4] * y + matrix[8] *
|
|
1464
|
-
out[13] = matrix[1] * x + matrix[5] * y + matrix[9] *
|
|
1465
|
-
out[14] = matrix[2] * x + matrix[6] * y + matrix[10] *
|
|
1466
|
-
out[15] = matrix[3] * x + matrix[7] * y + matrix[11] *
|
|
1463
|
+
out[12] = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12];
|
|
1464
|
+
out[13] = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13];
|
|
1465
|
+
out[14] = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14];
|
|
1466
|
+
out[15] = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15];
|
|
1467
1467
|
} else {
|
|
1468
1468
|
a00 = matrix[0];
|
|
1469
1469
|
a01 = matrix[1];
|
|
@@ -1489,10 +1489,10 @@ var require_translate = __commonJS({
|
|
|
1489
1489
|
out[9] = a21;
|
|
1490
1490
|
out[10] = a22;
|
|
1491
1491
|
out[11] = a23;
|
|
1492
|
-
out[12] = a00 * x + a10 * y + a20 *
|
|
1493
|
-
out[13] = a01 * x + a11 * y + a21 *
|
|
1494
|
-
out[14] = a02 * x + a12 * y + a22 *
|
|
1495
|
-
out[15] = a03 * x + a13 * y + a23 *
|
|
1492
|
+
out[12] = a00 * x + a10 * y + a20 * z + matrix[12];
|
|
1493
|
+
out[13] = a01 * x + a11 * y + a21 * z + matrix[13];
|
|
1494
|
+
out[14] = a02 * x + a12 * y + a22 * z + matrix[14];
|
|
1495
|
+
out[15] = a03 * x + a13 * y + a23 * z + matrix[15];
|
|
1496
1496
|
}
|
|
1497
1497
|
return out;
|
|
1498
1498
|
};
|
|
@@ -2266,8 +2266,8 @@ var require_toCompactBinary = __commonJS({
|
|
|
2266
2266
|
var toCompactBinary = (geometry) => {
|
|
2267
2267
|
const sides = geometry.sides;
|
|
2268
2268
|
const transforms = geometry.transforms;
|
|
2269
|
-
let
|
|
2270
|
-
if (geometry.color)
|
|
2269
|
+
let color = [-1, -1, -1, -1];
|
|
2270
|
+
if (geometry.color) color = geometry.color;
|
|
2271
2271
|
const compacted = new Float32Array(1 + 16 + 4 + sides.length * 4);
|
|
2272
2272
|
compacted[0] = 0;
|
|
2273
2273
|
compacted[1] = transforms[0];
|
|
@@ -2286,10 +2286,10 @@ var require_toCompactBinary = __commonJS({
|
|
|
2286
2286
|
compacted[14] = transforms[13];
|
|
2287
2287
|
compacted[15] = transforms[14];
|
|
2288
2288
|
compacted[16] = transforms[15];
|
|
2289
|
-
compacted[17] =
|
|
2290
|
-
compacted[18] =
|
|
2291
|
-
compacted[19] =
|
|
2292
|
-
compacted[20] =
|
|
2289
|
+
compacted[17] = color[0];
|
|
2290
|
+
compacted[18] = color[1];
|
|
2291
|
+
compacted[19] = color[2];
|
|
2292
|
+
compacted[20] = color[3];
|
|
2293
2293
|
for (let i = 0; i < sides.length; i++) {
|
|
2294
2294
|
const ci = i * 4 + 21;
|
|
2295
2295
|
const point0 = sides[i][0];
|
|
@@ -3562,11 +3562,11 @@ var require_fromValues4 = __commonJS({
|
|
|
3562
3562
|
"node_modules/@jscad/modeling/src/maths/vec4/fromValues.js"(exports, module) {
|
|
3563
3563
|
"use strict";
|
|
3564
3564
|
var create = require_create7();
|
|
3565
|
-
var fromValues = (x, y,
|
|
3565
|
+
var fromValues = (x, y, z, w) => {
|
|
3566
3566
|
const out = create();
|
|
3567
3567
|
out[0] = x;
|
|
3568
3568
|
out[1] = y;
|
|
3569
|
-
out[2] =
|
|
3569
|
+
out[2] = z;
|
|
3570
3570
|
out[3] = w;
|
|
3571
3571
|
return out;
|
|
3572
3572
|
};
|
|
@@ -3724,8 +3724,8 @@ var require_projectionOfPoint = __commonJS({
|
|
|
3724
3724
|
const a = point[0] * plane[0] + point[1] * plane[1] + point[2] * plane[2] - plane[3];
|
|
3725
3725
|
const x = point[0] - a * plane[0];
|
|
3726
3726
|
const y = point[1] - a * plane[1];
|
|
3727
|
-
const
|
|
3728
|
-
return vec32.fromValues(x, y,
|
|
3727
|
+
const z = point[2] - a * plane[2];
|
|
3728
|
+
return vec32.fromValues(x, y, z);
|
|
3729
3729
|
};
|
|
3730
3730
|
module.exports = projectionOfPoint;
|
|
3731
3731
|
}
|
|
@@ -4029,11 +4029,11 @@ var require_transform5 = __commonJS({
|
|
|
4029
4029
|
"node_modules/@jscad/modeling/src/maths/vec4/transform.js"(exports, module) {
|
|
4030
4030
|
"use strict";
|
|
4031
4031
|
var transform = (out, vector, matrix) => {
|
|
4032
|
-
const [x, y,
|
|
4033
|
-
out[0] = matrix[0] * x + matrix[4] * y + matrix[8] *
|
|
4034
|
-
out[1] = matrix[1] * x + matrix[5] * y + matrix[9] *
|
|
4035
|
-
out[2] = matrix[2] * x + matrix[6] * y + matrix[10] *
|
|
4036
|
-
out[3] = matrix[3] * x + matrix[7] * y + matrix[11] *
|
|
4032
|
+
const [x, y, z, w] = vector;
|
|
4033
|
+
out[0] = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12] * w;
|
|
4034
|
+
out[1] = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13] * w;
|
|
4035
|
+
out[2] = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14] * w;
|
|
4036
|
+
out[3] = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15] * w;
|
|
4037
4037
|
return out;
|
|
4038
4038
|
};
|
|
4039
4039
|
module.exports = transform;
|
|
@@ -4095,8 +4095,8 @@ var require_measureBoundingSphere = __commonJS({
|
|
|
4095
4095
|
out[2] = (minz[2] + maxz[2]) * 0.5;
|
|
4096
4096
|
const x = out[0] - maxx[0];
|
|
4097
4097
|
const y = out[1] - maxy[1];
|
|
4098
|
-
const
|
|
4099
|
-
out[3] = Math.sqrt(x * x + y * y +
|
|
4098
|
+
const z = out[2] - maxz[2];
|
|
4099
|
+
out[3] = Math.sqrt(x * x + y * y + z * z);
|
|
4100
4100
|
cache.set(polygon3, out);
|
|
4101
4101
|
return out;
|
|
4102
4102
|
};
|
|
@@ -4467,8 +4467,8 @@ var require_toCompactBinary2 = __commonJS({
|
|
|
4467
4467
|
const transforms = geometry.transforms;
|
|
4468
4468
|
const numberOfPolygons = polygons.length;
|
|
4469
4469
|
const numberOfVertices = polygons.reduce((count, polygon3) => count + polygon3.vertices.length, 0);
|
|
4470
|
-
let
|
|
4471
|
-
if (geometry.color)
|
|
4470
|
+
let color = [-1, -1, -1, -1];
|
|
4471
|
+
if (geometry.color) color = geometry.color;
|
|
4472
4472
|
const compacted = new Float32Array(1 + 16 + 4 + 1 + numberOfPolygons + numberOfVertices * 3);
|
|
4473
4473
|
compacted[0] = 1;
|
|
4474
4474
|
compacted[1] = transforms[0];
|
|
@@ -4487,10 +4487,10 @@ var require_toCompactBinary2 = __commonJS({
|
|
|
4487
4487
|
compacted[14] = transforms[13];
|
|
4488
4488
|
compacted[15] = transforms[14];
|
|
4489
4489
|
compacted[16] = transforms[15];
|
|
4490
|
-
compacted[17] =
|
|
4491
|
-
compacted[18] =
|
|
4492
|
-
compacted[19] =
|
|
4493
|
-
compacted[20] =
|
|
4490
|
+
compacted[17] = color[0];
|
|
4491
|
+
compacted[18] = color[1];
|
|
4492
|
+
compacted[19] = color[2];
|
|
4493
|
+
compacted[20] = color[3];
|
|
4494
4494
|
compacted[21] = numberOfVertices;
|
|
4495
4495
|
let ci = 22;
|
|
4496
4496
|
let vi = ci + numberOfPolygons;
|
|
@@ -5069,8 +5069,8 @@ var require_toCompactBinary3 = __commonJS({
|
|
|
5069
5069
|
var toCompactBinary = (geometry) => {
|
|
5070
5070
|
const points = geometry.points;
|
|
5071
5071
|
const transforms = geometry.transforms;
|
|
5072
|
-
let
|
|
5073
|
-
if (geometry.color)
|
|
5072
|
+
let color = [-1, -1, -1, -1];
|
|
5073
|
+
if (geometry.color) color = geometry.color;
|
|
5074
5074
|
const compacted = new Float32Array(1 + 16 + 1 + 4 + points.length * 2);
|
|
5075
5075
|
compacted[0] = 2;
|
|
5076
5076
|
compacted[1] = transforms[0];
|
|
@@ -5090,10 +5090,10 @@ var require_toCompactBinary3 = __commonJS({
|
|
|
5090
5090
|
compacted[15] = transforms[14];
|
|
5091
5091
|
compacted[16] = transforms[15];
|
|
5092
5092
|
compacted[17] = geometry.isClosed ? 1 : 0;
|
|
5093
|
-
compacted[18] =
|
|
5094
|
-
compacted[19] =
|
|
5095
|
-
compacted[20] =
|
|
5096
|
-
compacted[21] =
|
|
5093
|
+
compacted[18] = color[0];
|
|
5094
|
+
compacted[19] = color[1];
|
|
5095
|
+
compacted[20] = color[2];
|
|
5096
|
+
compacted[21] = color[3];
|
|
5097
5097
|
for (let j = 0; j < points.length; j++) {
|
|
5098
5098
|
const ci = j * 2 + 22;
|
|
5099
5099
|
const point = points[j];
|
|
@@ -5184,38 +5184,38 @@ var require_colorize = __commonJS({
|
|
|
5184
5184
|
var geom35 = require_geom3();
|
|
5185
5185
|
var path2 = require_path2();
|
|
5186
5186
|
var poly3 = require_poly3();
|
|
5187
|
-
var colorGeom2 = (
|
|
5187
|
+
var colorGeom2 = (color, object) => {
|
|
5188
5188
|
const newgeom2 = geom2.clone(object);
|
|
5189
|
-
newgeom2.color =
|
|
5189
|
+
newgeom2.color = color;
|
|
5190
5190
|
return newgeom2;
|
|
5191
5191
|
};
|
|
5192
|
-
var colorGeom3 = (
|
|
5192
|
+
var colorGeom3 = (color, object) => {
|
|
5193
5193
|
const newgeom3 = geom35.clone(object);
|
|
5194
|
-
newgeom3.color =
|
|
5194
|
+
newgeom3.color = color;
|
|
5195
5195
|
return newgeom3;
|
|
5196
5196
|
};
|
|
5197
|
-
var colorPath2 = (
|
|
5197
|
+
var colorPath2 = (color, object) => {
|
|
5198
5198
|
const newpath2 = path2.clone(object);
|
|
5199
|
-
newpath2.color =
|
|
5199
|
+
newpath2.color = color;
|
|
5200
5200
|
return newpath2;
|
|
5201
5201
|
};
|
|
5202
|
-
var colorPoly3 = (
|
|
5202
|
+
var colorPoly3 = (color, object) => {
|
|
5203
5203
|
const newpoly = poly3.clone(object);
|
|
5204
|
-
newpoly.color =
|
|
5204
|
+
newpoly.color = color;
|
|
5205
5205
|
return newpoly;
|
|
5206
5206
|
};
|
|
5207
|
-
var colorize = (
|
|
5208
|
-
if (!Array.isArray(
|
|
5209
|
-
if (
|
|
5210
|
-
if (
|
|
5207
|
+
var colorize = (color, ...objects) => {
|
|
5208
|
+
if (!Array.isArray(color)) throw new Error("color must be an array");
|
|
5209
|
+
if (color.length < 3) throw new Error("color must contain R, G and B values");
|
|
5210
|
+
if (color.length === 3) color = [color[0], color[1], color[2], 1];
|
|
5211
5211
|
objects = flatten(objects);
|
|
5212
5212
|
if (objects.length === 0) throw new Error("wrong number of arguments");
|
|
5213
5213
|
const results = objects.map((object) => {
|
|
5214
|
-
if (geom2.isA(object)) return colorGeom2(
|
|
5215
|
-
if (geom35.isA(object)) return colorGeom3(
|
|
5216
|
-
if (path2.isA(object)) return colorPath2(
|
|
5217
|
-
if (poly3.isA(object)) return colorPoly3(
|
|
5218
|
-
object.color =
|
|
5214
|
+
if (geom2.isA(object)) return colorGeom2(color, object);
|
|
5215
|
+
if (geom35.isA(object)) return colorGeom3(color, object);
|
|
5216
|
+
if (path2.isA(object)) return colorPath2(color, object);
|
|
5217
|
+
if (poly3.isA(object)) return colorPoly3(color, object);
|
|
5218
|
+
object.color = color;
|
|
5219
5219
|
return object;
|
|
5220
5220
|
});
|
|
5221
5221
|
return results.length === 1 ? results[0] : results;
|
|
@@ -7189,8 +7189,8 @@ var require_measurements = __commonJS({
|
|
|
7189
7189
|
var require_commonChecks = __commonJS({
|
|
7190
7190
|
"node_modules/@jscad/modeling/src/primitives/commonChecks.js"(exports, module) {
|
|
7191
7191
|
"use strict";
|
|
7192
|
-
var isNumberArray = (array,
|
|
7193
|
-
if (Array.isArray(array) && array.length >=
|
|
7192
|
+
var isNumberArray = (array, dimension) => {
|
|
7193
|
+
if (Array.isArray(array) && array.length >= dimension) {
|
|
7194
7194
|
return array.every((n) => Number.isFinite(n));
|
|
7195
7195
|
}
|
|
7196
7196
|
return false;
|
|
@@ -14190,12 +14190,12 @@ var axes = [
|
|
|
14190
14190
|
{ x: 0, y: 0, z: 1 }
|
|
14191
14191
|
];
|
|
14192
14192
|
function rotateVector(v, degrees) {
|
|
14193
|
-
const [x, y,
|
|
14193
|
+
const [x, y, z] = [degrees.x, degrees.y, degrees.z].map(
|
|
14194
14194
|
(a2) => a2 * Math.PI / 180
|
|
14195
14195
|
);
|
|
14196
14196
|
const a = {
|
|
14197
|
-
x: Math.cos(
|
|
14198
|
-
y: Math.sin(
|
|
14197
|
+
x: Math.cos(z) * v.x - Math.sin(z) * v.y,
|
|
14198
|
+
y: Math.sin(z) * v.x + Math.cos(z) * v.y,
|
|
14199
14199
|
z: v.z
|
|
14200
14200
|
};
|
|
14201
14201
|
const b = {
|
|
@@ -14494,17 +14494,17 @@ var createBoundsAccumulator = () => {
|
|
|
14494
14494
|
let maxZ = Number.NEGATIVE_INFINITY;
|
|
14495
14495
|
let isEmpty = true;
|
|
14496
14496
|
return {
|
|
14497
|
-
add(x, y,
|
|
14498
|
-
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(
|
|
14497
|
+
add(x, y, z) {
|
|
14498
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) {
|
|
14499
14499
|
return;
|
|
14500
14500
|
}
|
|
14501
14501
|
isEmpty = false;
|
|
14502
14502
|
if (x < minX) minX = x;
|
|
14503
14503
|
if (y < minY) minY = y;
|
|
14504
|
-
if (
|
|
14504
|
+
if (z < minZ) minZ = z;
|
|
14505
14505
|
if (x > maxX) maxX = x;
|
|
14506
14506
|
if (y > maxY) maxY = y;
|
|
14507
|
-
if (
|
|
14507
|
+
if (z > maxZ) maxZ = z;
|
|
14508
14508
|
},
|
|
14509
14509
|
result() {
|
|
14510
14510
|
if (isEmpty) return ZERO_BOX();
|
|
@@ -14848,19 +14848,19 @@ function transformMesh(mesh, translation, rotation, scale) {
|
|
|
14848
14848
|
for (let i = 0; i < result.positions.length; i += 3) {
|
|
14849
14849
|
let x = result.positions[i];
|
|
14850
14850
|
let y = result.positions[i + 1];
|
|
14851
|
-
let
|
|
14851
|
+
let z = result.positions[i + 2];
|
|
14852
14852
|
if (scale) {
|
|
14853
14853
|
x *= scale.x;
|
|
14854
14854
|
y *= scale.y;
|
|
14855
|
-
|
|
14855
|
+
z *= scale.z;
|
|
14856
14856
|
}
|
|
14857
14857
|
if (rotation) {
|
|
14858
14858
|
const cosY = Math.cos(rotation.y);
|
|
14859
14859
|
const sinY = Math.sin(rotation.y);
|
|
14860
|
-
const rx = x * cosY -
|
|
14861
|
-
const rz = x * sinY +
|
|
14860
|
+
const rx = x * cosY - z * sinY;
|
|
14861
|
+
const rz = x * sinY + z * cosY;
|
|
14862
14862
|
x = rx;
|
|
14863
|
-
|
|
14863
|
+
z = rz;
|
|
14864
14864
|
const cosZ = Math.cos(rotation.z);
|
|
14865
14865
|
const sinZ = Math.sin(rotation.z);
|
|
14866
14866
|
const rx2 = x * cosZ + y * sinZ;
|
|
@@ -14869,14 +14869,14 @@ function transformMesh(mesh, translation, rotation, scale) {
|
|
|
14869
14869
|
y = ry2;
|
|
14870
14870
|
const cosX = Math.cos(rotation.x);
|
|
14871
14871
|
const sinX = Math.sin(rotation.x);
|
|
14872
|
-
const ry = y * cosX +
|
|
14873
|
-
const rz2 = -y * sinX +
|
|
14872
|
+
const ry = y * cosX + z * sinX;
|
|
14873
|
+
const rz2 = -y * sinX + z * cosX;
|
|
14874
14874
|
y = ry;
|
|
14875
|
-
|
|
14875
|
+
z = rz2;
|
|
14876
14876
|
}
|
|
14877
14877
|
result.positions[i] = x + translation.x;
|
|
14878
14878
|
result.positions[i + 1] = y + translation.y;
|
|
14879
|
-
result.positions[i + 2] =
|
|
14879
|
+
result.positions[i + 2] = z + translation.z;
|
|
14880
14880
|
}
|
|
14881
14881
|
if (rotation) {
|
|
14882
14882
|
for (let i = 0; i < result.normals.length; i += 3) {
|
|
@@ -15054,9 +15054,9 @@ import { convertJscadModelToGltf } from "jscad-to-gltf";
|
|
|
15054
15054
|
|
|
15055
15055
|
// lib/utils/coordinate-transform.ts
|
|
15056
15056
|
function applyCoordinateTransform(point, config) {
|
|
15057
|
-
let { x, y, z
|
|
15057
|
+
let { x, y, z } = point;
|
|
15058
15058
|
if (config.axisMapping) {
|
|
15059
|
-
const original = { x, y, z
|
|
15059
|
+
const original = { x, y, z };
|
|
15060
15060
|
if (config.axisMapping.x) {
|
|
15061
15061
|
x = getAxisValue(original, config.axisMapping.x);
|
|
15062
15062
|
}
|
|
@@ -15064,30 +15064,30 @@ function applyCoordinateTransform(point, config) {
|
|
|
15064
15064
|
y = getAxisValue(original, config.axisMapping.y);
|
|
15065
15065
|
}
|
|
15066
15066
|
if (config.axisMapping.z) {
|
|
15067
|
-
|
|
15067
|
+
z = getAxisValue(original, config.axisMapping.z);
|
|
15068
15068
|
}
|
|
15069
15069
|
}
|
|
15070
15070
|
x *= config.flipX ?? 1;
|
|
15071
15071
|
y *= config.flipY ?? 1;
|
|
15072
|
-
|
|
15072
|
+
z *= config.flipZ ?? 1;
|
|
15073
15073
|
if (config.rotation) {
|
|
15074
15074
|
if (config.rotation.x) {
|
|
15075
15075
|
const rad = config.rotation.x * Math.PI / 180;
|
|
15076
15076
|
const cos = Math.cos(rad);
|
|
15077
15077
|
const sin = Math.sin(rad);
|
|
15078
|
-
const newY = y * cos -
|
|
15079
|
-
const newZ = y * sin +
|
|
15078
|
+
const newY = y * cos - z * sin;
|
|
15079
|
+
const newZ = y * sin + z * cos;
|
|
15080
15080
|
y = newY;
|
|
15081
|
-
|
|
15081
|
+
z = newZ;
|
|
15082
15082
|
}
|
|
15083
15083
|
if (config.rotation.y) {
|
|
15084
15084
|
const rad = config.rotation.y * Math.PI / 180;
|
|
15085
15085
|
const cos = Math.cos(rad);
|
|
15086
15086
|
const sin = Math.sin(rad);
|
|
15087
|
-
const newX = x * cos +
|
|
15088
|
-
const newZ = -x * sin +
|
|
15087
|
+
const newX = x * cos + z * sin;
|
|
15088
|
+
const newZ = -x * sin + z * cos;
|
|
15089
15089
|
x = newX;
|
|
15090
|
-
|
|
15090
|
+
z = newZ;
|
|
15091
15091
|
}
|
|
15092
15092
|
if (config.rotation.z) {
|
|
15093
15093
|
const rad = config.rotation.z * Math.PI / 180;
|
|
@@ -15099,7 +15099,7 @@ function applyCoordinateTransform(point, config) {
|
|
|
15099
15099
|
y = newY;
|
|
15100
15100
|
}
|
|
15101
15101
|
}
|
|
15102
|
-
return { x, y, z
|
|
15102
|
+
return { x, y, z };
|
|
15103
15103
|
}
|
|
15104
15104
|
function getAxisValue(original, mapping) {
|
|
15105
15105
|
switch (mapping) {
|
|
@@ -15216,11 +15216,11 @@ var COORDINATE_TRANSFORMS = {
|
|
|
15216
15216
|
// lib/utils/gltf-node-transforms.ts
|
|
15217
15217
|
function applyQuaternion(p, q) {
|
|
15218
15218
|
const [qx, qy, qz, qw] = q;
|
|
15219
|
-
const { x, y, z
|
|
15220
|
-
const ix = qw * x + qy *
|
|
15221
|
-
const iy = qw * y + qz * x - qx *
|
|
15222
|
-
const iz = qw *
|
|
15223
|
-
const iw = -qx * x - qy * y - qz *
|
|
15219
|
+
const { x, y, z } = p;
|
|
15220
|
+
const ix = qw * x + qy * z - qz * y;
|
|
15221
|
+
const iy = qw * y + qz * x - qx * z;
|
|
15222
|
+
const iz = qw * z + qx * y - qy * x;
|
|
15223
|
+
const iw = -qx * x - qy * y - qz * z;
|
|
15224
15224
|
return {
|
|
15225
15225
|
x: ix * qw + iw * -qx + iy * -qz - iz * -qy,
|
|
15226
15226
|
y: iy * qw + iw * -qy + iz * -qx - ix * -qz,
|
|
@@ -15500,10 +15500,10 @@ function convertToOBJMesh(triangles) {
|
|
|
15500
15500
|
// 0.7 * 255 = 179
|
|
15501
15501
|
});
|
|
15502
15502
|
} else {
|
|
15503
|
-
const
|
|
15503
|
+
const color = JSON.parse(colorKey);
|
|
15504
15504
|
materials.set(materialName, {
|
|
15505
15505
|
name: materialName,
|
|
15506
|
-
color
|
|
15506
|
+
color
|
|
15507
15507
|
});
|
|
15508
15508
|
}
|
|
15509
15509
|
for (const triangle of groupTriangles) {
|
|
@@ -15946,217 +15946,8 @@ async function loadGLTF({
|
|
|
15946
15946
|
return parseGLB(glb_buffer, transform);
|
|
15947
15947
|
}
|
|
15948
15948
|
|
|
15949
|
-
// node_modules/@tscircuit/cableprinter/dist/index.js
|
|
15950
|
-
import { z } from "zod";
|
|
15951
|
-
import { z as z2 } from "zod";
|
|
15952
|
-
var cableStandardSchema = z.enum([
|
|
15953
|
-
"usb_c",
|
|
15954
|
-
"jst_sh",
|
|
15955
|
-
"jst_ph",
|
|
15956
|
-
"us_mains"
|
|
15957
|
-
]);
|
|
15958
|
-
var color = z.string().regex(/^#[0-9a-fA-F]{6}$/);
|
|
15959
|
-
var jacket = {
|
|
15960
|
-
jacketDiameter: z.number().finite().positive().default(4),
|
|
15961
|
-
color: color.default("#263449")
|
|
15962
|
-
};
|
|
15963
|
-
var cableInputSchema = z.discriminatedUnion("standard", [
|
|
15964
|
-
z.object({ standard: z.literal("usb_c"), ...jacket }).strict(),
|
|
15965
|
-
z.object({
|
|
15966
|
-
standard: z.literal("jst_sh"),
|
|
15967
|
-
pinCount: z.number().int().min(2).max(15).default(4),
|
|
15968
|
-
wireDiameter: z.number().finite().min(0.4).max(0.8).default(0.6)
|
|
15969
|
-
}).strict(),
|
|
15970
|
-
z.object({
|
|
15971
|
-
standard: z.literal("jst_ph"),
|
|
15972
|
-
pinCount: z.number().int().min(2).max(16).default(2),
|
|
15973
|
-
wireDiameter: z.number().finite().min(0.8).max(1.5).default(1.2)
|
|
15974
|
-
}).strict(),
|
|
15975
|
-
z.object({
|
|
15976
|
-
standard: z.literal("us_mains"),
|
|
15977
|
-
...jacket,
|
|
15978
|
-
jacketDiameter: jacket.jacketDiameter.default(6.2)
|
|
15979
|
-
}).strict()
|
|
15980
|
-
]);
|
|
15981
|
-
var dimension = z2.number().finite().positive();
|
|
15982
|
-
var color2 = z2.string().regex(/^#[0-9a-fA-F]{6}$/);
|
|
15983
|
-
var body = {
|
|
15984
|
-
bodyWidth: dimension,
|
|
15985
|
-
bodyHeight: dimension,
|
|
15986
|
-
bodyDepth: dimension
|
|
15987
|
-
};
|
|
15988
|
-
var cableConnectorSchema = z2.discriminatedUnion("kind", [
|
|
15989
|
-
z2.object({
|
|
15990
|
-
kind: z2.literal("usb_c_plug"),
|
|
15991
|
-
...body,
|
|
15992
|
-
shellWidth: dimension,
|
|
15993
|
-
shellHeight: dimension,
|
|
15994
|
-
shellDepth: dimension
|
|
15995
|
-
}).strict(),
|
|
15996
|
-
z2.object({
|
|
15997
|
-
kind: z2.literal("jst_sh_housing"),
|
|
15998
|
-
...body,
|
|
15999
|
-
pinCount: z2.number().int().min(2).max(15),
|
|
16000
|
-
pitch: z2.literal(1)
|
|
16001
|
-
}).strict(),
|
|
16002
|
-
z2.object({
|
|
16003
|
-
kind: z2.literal("jst_ph_housing"),
|
|
16004
|
-
...body,
|
|
16005
|
-
pinCount: z2.number().int().min(2).max(16),
|
|
16006
|
-
pitch: z2.literal(2)
|
|
16007
|
-
}).strict(),
|
|
16008
|
-
z2.object({ kind: z2.literal("nema_5_15p"), ...body }).strict(),
|
|
16009
|
-
z2.object({ kind: z2.literal("iec_c13"), ...body }).strict()
|
|
16010
|
-
]);
|
|
16011
|
-
var cableCrossSectionSchema = z2.discriminatedUnion("kind", [
|
|
16012
|
-
z2.object({
|
|
16013
|
-
kind: z2.literal("round_jacket"),
|
|
16014
|
-
diameter: dimension,
|
|
16015
|
-
color: color2
|
|
16016
|
-
}).strict(),
|
|
16017
|
-
z2.object({
|
|
16018
|
-
kind: z2.literal("wire_bundle"),
|
|
16019
|
-
wires: z2.array(z2.object({ diameter: dimension, color: color2 }).strict()).min(2),
|
|
16020
|
-
wirePitch: dimension
|
|
16021
|
-
}).strict()
|
|
16022
|
-
]);
|
|
16023
|
-
var cableDefinitionSchema = z2.object({
|
|
16024
|
-
standard: cableStandardSchema,
|
|
16025
|
-
connectorA: cableConnectorSchema,
|
|
16026
|
-
connectorB: cableConnectorSchema,
|
|
16027
|
-
crossSection: cableCrossSectionSchema
|
|
16028
|
-
}).strict().superRefine((cable, ctx) => {
|
|
16029
|
-
const { connectorA, connectorB, crossSection } = cable;
|
|
16030
|
-
const expected = {
|
|
16031
|
-
usb_c: ["usb_c_plug", "usb_c_plug"],
|
|
16032
|
-
jst_sh: ["jst_sh_housing", "jst_sh_housing"],
|
|
16033
|
-
jst_ph: ["jst_ph_housing", "jst_ph_housing"],
|
|
16034
|
-
us_mains: ["nema_5_15p", "iec_c13"]
|
|
16035
|
-
}[cable.standard];
|
|
16036
|
-
if (connectorA.kind !== expected[0] || connectorB.kind !== expected[1]) {
|
|
16037
|
-
ctx.addIssue({
|
|
16038
|
-
code: z2.ZodIssueCode.custom,
|
|
16039
|
-
message: "Connector kinds must match the cable standard"
|
|
16040
|
-
});
|
|
16041
|
-
}
|
|
16042
|
-
if (crossSection.kind === "wire_bundle") {
|
|
16043
|
-
for (const connector of [connectorA, connectorB]) {
|
|
16044
|
-
if (!("pinCount" in connector) || connector.pinCount !== crossSection.wires.length) {
|
|
16045
|
-
ctx.addIssue({
|
|
16046
|
-
code: z2.ZodIssueCode.custom,
|
|
16047
|
-
message: "Bundle wire count must match each connector pin count"
|
|
16048
|
-
});
|
|
16049
|
-
}
|
|
16050
|
-
}
|
|
16051
|
-
if (crossSection.wires.some(
|
|
16052
|
-
(wire) => wire.diameter > crossSection.wirePitch
|
|
16053
|
-
)) {
|
|
16054
|
-
ctx.addIssue({
|
|
16055
|
-
code: z2.ZodIssueCode.custom,
|
|
16056
|
-
message: "Bundle wires must not overlap in the cross section"
|
|
16057
|
-
});
|
|
16058
|
-
}
|
|
16059
|
-
} else if (cable.standard === "jst_sh" || cable.standard === "jst_ph") {
|
|
16060
|
-
ctx.addIssue({
|
|
16061
|
-
code: z2.ZodIssueCode.custom,
|
|
16062
|
-
message: "JST cables require a wire bundle"
|
|
16063
|
-
});
|
|
16064
|
-
}
|
|
16065
|
-
});
|
|
16066
|
-
var wireColors = [
|
|
16067
|
-
"#df4049",
|
|
16068
|
-
"#263449",
|
|
16069
|
-
"#e1b13c",
|
|
16070
|
-
"#347dc9",
|
|
16071
|
-
"#27a782",
|
|
16072
|
-
"#af62bd"
|
|
16073
|
-
];
|
|
16074
|
-
function getCableDefinition(cableInput) {
|
|
16075
|
-
const cable = cableInputSchema.parse(cableInput);
|
|
16076
|
-
if (cable.standard === "usb_c") {
|
|
16077
|
-
const connector2 = {
|
|
16078
|
-
kind: "usb_c_plug",
|
|
16079
|
-
bodyWidth: 12,
|
|
16080
|
-
bodyHeight: 6,
|
|
16081
|
-
bodyDepth: 18,
|
|
16082
|
-
shellWidth: 8.25,
|
|
16083
|
-
shellHeight: 2.4,
|
|
16084
|
-
shellDepth: 6.5
|
|
16085
|
-
};
|
|
16086
|
-
return cableDefinitionSchema.parse({
|
|
16087
|
-
standard: cable.standard,
|
|
16088
|
-
connectorA: connector2,
|
|
16089
|
-
connectorB: { ...connector2 },
|
|
16090
|
-
crossSection: {
|
|
16091
|
-
kind: "round_jacket",
|
|
16092
|
-
diameter: cable.jacketDiameter,
|
|
16093
|
-
color: cable.color
|
|
16094
|
-
}
|
|
16095
|
-
});
|
|
16096
|
-
}
|
|
16097
|
-
if (cable.standard === "us_mains") {
|
|
16098
|
-
return cableDefinitionSchema.parse({
|
|
16099
|
-
standard: cable.standard,
|
|
16100
|
-
connectorA: {
|
|
16101
|
-
kind: "nema_5_15p",
|
|
16102
|
-
bodyWidth: 32,
|
|
16103
|
-
bodyHeight: 28,
|
|
16104
|
-
bodyDepth: 35
|
|
16105
|
-
},
|
|
16106
|
-
connectorB: {
|
|
16107
|
-
kind: "iec_c13",
|
|
16108
|
-
bodyWidth: 24,
|
|
16109
|
-
bodyHeight: 18,
|
|
16110
|
-
bodyDepth: 30
|
|
16111
|
-
},
|
|
16112
|
-
crossSection: {
|
|
16113
|
-
kind: "round_jacket",
|
|
16114
|
-
diameter: cable.jacketDiameter,
|
|
16115
|
-
color: cable.color
|
|
16116
|
-
}
|
|
16117
|
-
});
|
|
16118
|
-
}
|
|
16119
|
-
const isSh = cable.standard === "jst_sh";
|
|
16120
|
-
const connector = {
|
|
16121
|
-
kind: isSh ? "jst_sh_housing" : "jst_ph_housing",
|
|
16122
|
-
pinCount: cable.pinCount,
|
|
16123
|
-
pitch: isSh ? 1 : 2,
|
|
16124
|
-
bodyWidth: isSh ? cable.pinCount + 1 : (cable.pinCount - 1) * 2 + 3.8,
|
|
16125
|
-
bodyHeight: isSh ? 2.8 : 4.5,
|
|
16126
|
-
bodyDepth: isSh ? 5 : 6.85
|
|
16127
|
-
};
|
|
16128
|
-
return cableDefinitionSchema.parse({
|
|
16129
|
-
standard: cable.standard,
|
|
16130
|
-
connectorA: connector,
|
|
16131
|
-
connectorB: { ...connector },
|
|
16132
|
-
crossSection: {
|
|
16133
|
-
kind: "wire_bundle",
|
|
16134
|
-
wirePitch: connector.pitch,
|
|
16135
|
-
wires: Array.from({ length: cable.pinCount }, (_, index) => ({
|
|
16136
|
-
diameter: cable.wireDiameter,
|
|
16137
|
-
color: wireColors[index % wireColors.length]
|
|
16138
|
-
}))
|
|
16139
|
-
}
|
|
16140
|
-
});
|
|
16141
|
-
}
|
|
16142
|
-
function parseCableString(cableString) {
|
|
16143
|
-
const cableName = cableString.trim().toLowerCase();
|
|
16144
|
-
if (cableName === "usb_c" || cableName === "us_mains") {
|
|
16145
|
-
return getCableDefinition({ standard: cableName });
|
|
16146
|
-
}
|
|
16147
|
-
const jstMatch = /^(jst_sh|jst_ph)(?:_pins([0-9]+))?$/.exec(cableName);
|
|
16148
|
-
if (jstMatch) {
|
|
16149
|
-
return getCableDefinition({
|
|
16150
|
-
standard: jstMatch[1] === "jst_sh" ? "jst_sh" : "jst_ph",
|
|
16151
|
-
...jstMatch[2] ? { pinCount: Number(jstMatch[2]) } : {}
|
|
16152
|
-
});
|
|
16153
|
-
}
|
|
16154
|
-
throw new Error(
|
|
16155
|
-
`Unsupported cable string: "${cableString}". Expected usb_c, jst_sh[_pinsN], jst_ph[_pinsN], or us_mains.`
|
|
16156
|
-
);
|
|
16157
|
-
}
|
|
16158
|
-
|
|
16159
15949
|
// lib/loaders/cable.ts
|
|
15950
|
+
import { parseCableString } from "@tscircuit/cableprinter";
|
|
16160
15951
|
import { createCableMeshes } from "jscad-electronics/cables";
|
|
16161
15952
|
import { vec3 } from "gl-matrix";
|
|
16162
15953
|
|
|
@@ -16176,24 +15967,24 @@ function scalePointByAxis(point, scale) {
|
|
|
16176
15967
|
};
|
|
16177
15968
|
}
|
|
16178
15969
|
function rotatePoint(point, rotationDeg) {
|
|
16179
|
-
let { x, y, z
|
|
15970
|
+
let { x, y, z } = point;
|
|
16180
15971
|
if (rotationDeg.x !== 0) {
|
|
16181
15972
|
const rad = rotationDeg.x * Math.PI / 180;
|
|
16182
15973
|
const cos = Math.cos(rad);
|
|
16183
15974
|
const sin = Math.sin(rad);
|
|
16184
|
-
const newY = y * cos -
|
|
16185
|
-
const newZ = y * sin +
|
|
15975
|
+
const newY = y * cos - z * sin;
|
|
15976
|
+
const newZ = y * sin + z * cos;
|
|
16186
15977
|
y = newY;
|
|
16187
|
-
|
|
15978
|
+
z = newZ;
|
|
16188
15979
|
}
|
|
16189
15980
|
if (rotationDeg.y !== 0) {
|
|
16190
15981
|
const rad = rotationDeg.y * Math.PI / 180;
|
|
16191
15982
|
const cos = Math.cos(rad);
|
|
16192
15983
|
const sin = Math.sin(rad);
|
|
16193
|
-
const newX = x * cos +
|
|
16194
|
-
const newZ = -x * sin +
|
|
15984
|
+
const newX = x * cos + z * sin;
|
|
15985
|
+
const newZ = -x * sin + z * cos;
|
|
16195
15986
|
x = newX;
|
|
16196
|
-
|
|
15987
|
+
z = newZ;
|
|
16197
15988
|
}
|
|
16198
15989
|
if (rotationDeg.z !== 0) {
|
|
16199
15990
|
const rad = rotationDeg.z * Math.PI / 180;
|
|
@@ -16204,7 +15995,7 @@ function rotatePoint(point, rotationDeg) {
|
|
|
16204
15995
|
x = newX;
|
|
16205
15996
|
y = newY;
|
|
16206
15997
|
}
|
|
16207
|
-
return { x, y, z
|
|
15998
|
+
return { x, y, z };
|
|
16208
15999
|
}
|
|
16209
16000
|
function scaleTriangle(triangle, scale) {
|
|
16210
16001
|
return {
|
|
@@ -16308,9 +16099,31 @@ function getBoundingBoxCenter(bounds) {
|
|
|
16308
16099
|
|
|
16309
16100
|
// lib/loaders/cable.ts
|
|
16310
16101
|
function loadCable(cable) {
|
|
16102
|
+
const pin1Side = (position, end) => {
|
|
16103
|
+
if (!position || cable.path.length < 2) return void 0;
|
|
16104
|
+
const tip = end === "from" ? cable.path[0] : cable.path.at(-1);
|
|
16105
|
+
const next = end === "from" ? cable.path[1] : cable.path.at(-2);
|
|
16106
|
+
const axis = vec3.normalize(vec3.create(), [
|
|
16107
|
+
next.x - tip.x,
|
|
16108
|
+
next.y - tip.y,
|
|
16109
|
+
next.z - tip.z
|
|
16110
|
+
]);
|
|
16111
|
+
const side = vec3.fromValues(
|
|
16112
|
+
position.x - tip.x,
|
|
16113
|
+
position.y - tip.y,
|
|
16114
|
+
position.z - tip.z
|
|
16115
|
+
);
|
|
16116
|
+
vec3.scaleAndAdd(side, side, axis, -vec3.dot(side, axis));
|
|
16117
|
+
if (vec3.length(side) < 1e-6) return void 0;
|
|
16118
|
+
vec3.normalize(side, side);
|
|
16119
|
+
return [side[0], side[1], side[2]];
|
|
16120
|
+
};
|
|
16311
16121
|
const meshes = createCableMeshes({
|
|
16312
16122
|
definition: parseCableString(cable.cableprinter_string),
|
|
16313
|
-
path: cable.path.map(({ x, y, z
|
|
16123
|
+
path: cable.path.map(({ x, y, z }) => [x, y, z]),
|
|
16124
|
+
// Orient in circuit Z-up before the paired mesh transform to scene Y-up.
|
|
16125
|
+
startPin1Side: pin1Side(cable.from_connector_pin1_position, "from"),
|
|
16126
|
+
endPin1Side: pin1Side(cable.to_connector_pin1_position, "to")
|
|
16314
16127
|
});
|
|
16315
16128
|
return meshes.map((mesh) => {
|
|
16316
16129
|
const circuitTriangles = [];
|
|
@@ -17037,10 +16850,10 @@ var pushLoop = (flattenedVertices, loop) => {
|
|
|
17037
16850
|
var toScenePoint = ({
|
|
17038
16851
|
x,
|
|
17039
16852
|
y,
|
|
17040
|
-
z
|
|
16853
|
+
z
|
|
17041
16854
|
}) => ({
|
|
17042
16855
|
x,
|
|
17043
|
-
y:
|
|
16856
|
+
y: z,
|
|
17044
16857
|
z: -y
|
|
17045
16858
|
});
|
|
17046
16859
|
var makeTriangle = ({
|
|
@@ -17406,11 +17219,11 @@ var loadJscadPlan = (plan) => {
|
|
|
17406
17219
|
const sourceTriangles = geometries.flatMap((geometry) => {
|
|
17407
17220
|
const polygons = geom33.toPolygons(geometry);
|
|
17408
17221
|
return polygons.flatMap((polygon3) => {
|
|
17409
|
-
const
|
|
17410
|
-
const material = geometry.material ||
|
|
17411
|
-
...
|
|
17412
|
-
color:
|
|
17413
|
-
opacity:
|
|
17222
|
+
const color = polygon3.color ?? geometry.color;
|
|
17223
|
+
const material = geometry.material || color ? {
|
|
17224
|
+
...color ? {
|
|
17225
|
+
color: color.slice(0, 3),
|
|
17226
|
+
opacity: color[3] ?? 1
|
|
17414
17227
|
} : {},
|
|
17415
17228
|
...geometry.material
|
|
17416
17229
|
} : void 0;
|
|
@@ -17462,8 +17275,8 @@ function parseOBJ(text, transform) {
|
|
|
17462
17275
|
const parts = trimmed.split(/\s+/);
|
|
17463
17276
|
const x = parts[1];
|
|
17464
17277
|
const y = parts[2];
|
|
17465
|
-
const
|
|
17466
|
-
vertices.push({ x: parseFloat(x), y: parseFloat(y), z: parseFloat(
|
|
17278
|
+
const z = parts[3];
|
|
17279
|
+
vertices.push({ x: parseFloat(x), y: parseFloat(y), z: parseFloat(z) });
|
|
17467
17280
|
if (parts.length >= 7) {
|
|
17468
17281
|
const [rStr, gStr, bStr] = parts.slice(4, 7);
|
|
17469
17282
|
let r = Number(rStr);
|
|
@@ -17482,8 +17295,8 @@ function parseOBJ(text, transform) {
|
|
|
17482
17295
|
const parts = trimmed.split(/\s+/);
|
|
17483
17296
|
const x = parts[1];
|
|
17484
17297
|
const y = parts[2];
|
|
17485
|
-
const
|
|
17486
|
-
normals.push({ x: parseFloat(x), y: parseFloat(y), z: parseFloat(
|
|
17298
|
+
const z = parts[3];
|
|
17299
|
+
normals.push({ x: parseFloat(x), y: parseFloat(y), z: parseFloat(z) });
|
|
17487
17300
|
} else if (trimmed.startsWith("newmtl ")) {
|
|
17488
17301
|
const name = trimmed.split(/\s+/)[1];
|
|
17489
17302
|
materials.set(name, { name });
|
|
@@ -17770,10 +17583,10 @@ function convertToOBJMesh2(triangles) {
|
|
|
17770
17583
|
color: [179, 179, 179, 1]
|
|
17771
17584
|
});
|
|
17772
17585
|
} else {
|
|
17773
|
-
const
|
|
17586
|
+
const color = JSON.parse(colorKey);
|
|
17774
17587
|
materials.set(materialName, {
|
|
17775
17588
|
name: materialName,
|
|
17776
|
-
color
|
|
17589
|
+
color
|
|
17777
17590
|
});
|
|
17778
17591
|
}
|
|
17779
17592
|
for (const triangle of groupTriangles) {
|
|
@@ -18154,13 +17967,13 @@ var normalizeColor = (value) => {
|
|
|
18154
17967
|
const parsed = parseColor(specified);
|
|
18155
17968
|
return parsed ? toHex(parsed) : specified.trim();
|
|
18156
17969
|
};
|
|
18157
|
-
var mix = (
|
|
17970
|
+
var mix = (color, target, amount) => color.map(
|
|
18158
17971
|
(channel, index) => clampByte(channel + (target[index] - channel) * amount)
|
|
18159
17972
|
);
|
|
18160
17973
|
var getPerceivedBrightness = ([red, green, blue]) => (red * 0.299 + green * 0.587 + blue * 0.114) / 255;
|
|
18161
|
-
var colorToCssString = (
|
|
18162
|
-
if (typeof
|
|
18163
|
-
return toHex([
|
|
17974
|
+
var colorToCssString = (color) => {
|
|
17975
|
+
if (typeof color === "string") return color;
|
|
17976
|
+
return toHex([color[0], color[1], color[2]]);
|
|
18164
17977
|
};
|
|
18165
17978
|
function deriveBoardColorPalette(solderMaskColor, silkscreenColor) {
|
|
18166
17979
|
const backgroundColor = normalizeColor(solderMaskColor);
|
|
@@ -19292,18 +19105,18 @@ var GLTFBuilder = class {
|
|
|
19292
19105
|
});
|
|
19293
19106
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19294
19107
|
}
|
|
19295
|
-
jscadColor(
|
|
19296
|
-
if (
|
|
19297
|
-
if (Array.isArray(
|
|
19108
|
+
jscadColor(color, fallback) {
|
|
19109
|
+
if (color === void 0) return fallback;
|
|
19110
|
+
if (Array.isArray(color)) return [...color];
|
|
19298
19111
|
let rgb;
|
|
19299
|
-
if (typeof
|
|
19112
|
+
if (typeof color === "number")
|
|
19300
19113
|
rgb = [
|
|
19301
|
-
(
|
|
19302
|
-
(
|
|
19303
|
-
(
|
|
19114
|
+
(color >> 16 & 255) / 255,
|
|
19115
|
+
(color >> 8 & 255) / 255,
|
|
19116
|
+
(color & 255) / 255
|
|
19304
19117
|
];
|
|
19305
19118
|
else {
|
|
19306
|
-
const css =
|
|
19119
|
+
const css = color.trim().toLowerCase();
|
|
19307
19120
|
if (css.startsWith("#")) {
|
|
19308
19121
|
const hex = css.slice(1);
|
|
19309
19122
|
rgb = import_modeling.colors.hexToRgb(
|
|
@@ -19322,7 +19135,7 @@ var GLTFBuilder = class {
|
|
|
19322
19135
|
);
|
|
19323
19136
|
} else rgb = import_modeling.colors.colorNameToRgb(css);
|
|
19324
19137
|
if (!rgb || rgb.length < 3 || rgb.some((value) => !Number.isFinite(value))) {
|
|
19325
|
-
throw new Error(`Unsupported JSCAD material color: ${
|
|
19138
|
+
throw new Error(`Unsupported JSCAD material color: ${color}`);
|
|
19326
19139
|
}
|
|
19327
19140
|
}
|
|
19328
19141
|
return rgb.slice(0, 3).map(
|
|
@@ -19335,14 +19148,14 @@ var GLTFBuilder = class {
|
|
|
19335
19148
|
for (const [name, objMaterial] of objMesh.materials) {
|
|
19336
19149
|
let baseColor = [0.3, 0.3, 0.3, 1];
|
|
19337
19150
|
if (objMaterial.color) {
|
|
19338
|
-
const
|
|
19151
|
+
const color = typeof objMaterial.color === "string" ? this.parseColorString(objMaterial.color) : [
|
|
19339
19152
|
objMaterial.color[0] / 255,
|
|
19340
19153
|
objMaterial.color[1] / 255,
|
|
19341
19154
|
objMaterial.color[2] / 255,
|
|
19342
19155
|
objMaterial.color[3]
|
|
19343
19156
|
// Use the alpha from the color
|
|
19344
19157
|
];
|
|
19345
|
-
baseColor = [
|
|
19158
|
+
baseColor = [color[0], color[1], color[2], color[3]];
|
|
19346
19159
|
}
|
|
19347
19160
|
let alpha = baseColor[3];
|
|
19348
19161
|
if (objMaterial.dissolve !== void 0) {
|
|
@@ -19868,8 +19681,8 @@ var GLTFBuilder = class {
|
|
|
19868
19681
|
return index;
|
|
19869
19682
|
}
|
|
19870
19683
|
addMaterialFromColor(opts) {
|
|
19871
|
-
const { color
|
|
19872
|
-
const baseColor = typeof
|
|
19684
|
+
const { color, makeTransparent = false, isTranslucent = false } = opts;
|
|
19685
|
+
const baseColor = typeof color === "string" ? this.parseColorString(color) : [color[0] / 255, color[1] / 255, color[2] / 255, color[3]];
|
|
19873
19686
|
if (makeTransparent) {
|
|
19874
19687
|
baseColor[3] = 0.5;
|
|
19875
19688
|
}
|
|
@@ -19884,16 +19697,16 @@ var GLTFBuilder = class {
|
|
|
19884
19697
|
doubleSided: isTranslucent ? true : void 0
|
|
19885
19698
|
});
|
|
19886
19699
|
}
|
|
19887
|
-
parseColorString(
|
|
19888
|
-
if (
|
|
19889
|
-
const hex =
|
|
19700
|
+
parseColorString(color) {
|
|
19701
|
+
if (color.startsWith("#")) {
|
|
19702
|
+
const hex = color.slice(1);
|
|
19890
19703
|
const r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
19891
19704
|
const g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
19892
19705
|
const b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
19893
19706
|
const a = hex.length > 6 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
|
|
19894
19707
|
return [r, g, b, a];
|
|
19895
|
-
} else if (
|
|
19896
|
-
const match =
|
|
19708
|
+
} else if (color.startsWith("rgba(")) {
|
|
19709
|
+
const match = color.match(/rgba\(([^)]+)\)/);
|
|
19897
19710
|
if (match) {
|
|
19898
19711
|
const parts = match[1].split(",").map((s) => s.trim());
|
|
19899
19712
|
return [
|
|
@@ -19903,8 +19716,8 @@ var GLTFBuilder = class {
|
|
|
19903
19716
|
parseFloat(parts[3])
|
|
19904
19717
|
];
|
|
19905
19718
|
}
|
|
19906
|
-
} else if (
|
|
19907
|
-
const match =
|
|
19719
|
+
} else if (color.startsWith("rgb(")) {
|
|
19720
|
+
const match = color.match(/rgb\(([^)]+)\)/);
|
|
19908
19721
|
if (match) {
|
|
19909
19722
|
const parts = match[1].split(",").map((s) => s.trim());
|
|
19910
19723
|
return [
|
|
@@ -19924,7 +19737,7 @@ var GLTFBuilder = class {
|
|
|
19924
19737
|
gray: [0.5, 0.5, 0.5, 1],
|
|
19925
19738
|
grey: [0.5, 0.5, 0.5, 1]
|
|
19926
19739
|
};
|
|
19927
|
-
return namedColors[
|
|
19740
|
+
return namedColors[color.toLowerCase()] || [0.5, 0.5, 0.5, 1];
|
|
19928
19741
|
}
|
|
19929
19742
|
async addTextureFromDataUrl(dataUrl) {
|
|
19930
19743
|
try {
|
|
@@ -20201,12 +20014,12 @@ var CAMERA_PRESET_DIRECTIONS = {
|
|
|
20201
20014
|
front: [0, 0, 1],
|
|
20202
20015
|
back: [0, 0, -1]
|
|
20203
20016
|
};
|
|
20204
|
-
function normalizeVector([x, y,
|
|
20205
|
-
const length = Math.hypot(x, y,
|
|
20017
|
+
function normalizeVector([x, y, z]) {
|
|
20018
|
+
const length = Math.hypot(x, y, z);
|
|
20206
20019
|
if (length === 0) {
|
|
20207
20020
|
return [0, 1, 0];
|
|
20208
20021
|
}
|
|
20209
|
-
return [x / length, y / length,
|
|
20022
|
+
return [x / length, y / length, z / length];
|
|
20210
20023
|
}
|
|
20211
20024
|
function dot([ax, ay, az], [bx, by, bz]) {
|
|
20212
20025
|
return ax * bx + ay * by + az * bz;
|
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.148",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/tscircuit/circuit-json-to-gltf.git"
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@jscad/modeling": "^2.12.6",
|
|
24
24
|
"@tscircuit/alphabet": "^0.0.25",
|
|
25
|
-
"@tscircuit/cableprinter": "^0.0.
|
|
25
|
+
"@tscircuit/cableprinter": "^0.0.6",
|
|
26
26
|
"earcut": "^3.0.2",
|
|
27
27
|
"gl-matrix": "^3.4.4",
|
|
28
|
-
"jscad-electronics": "^0.0.
|
|
28
|
+
"jscad-electronics": "^0.0.210",
|
|
29
29
|
"jscad-planner": "^0.0.19",
|
|
30
30
|
"jscad-to-gltf": "^0.0.5",
|
|
31
31
|
"occt-import-js": "^0.0.23"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@types/react-dom": "^19.1.7",
|
|
48
48
|
"@vitejs/plugin-react": "^5.0.0",
|
|
49
49
|
"bun-match-svg": "^0.0.12",
|
|
50
|
-
"circuit-json": "^0.0.
|
|
50
|
+
"circuit-json": "^0.0.519",
|
|
51
51
|
"circuit-to-svg": "^0.0.429",
|
|
52
52
|
"graphics-debug": "^0.0.96",
|
|
53
53
|
"looks-same": "^9.0.1",
|
|
@@ -78,6 +78,6 @@
|
|
|
78
78
|
},
|
|
79
79
|
"overrides": {
|
|
80
80
|
"@tscircuit/core": "^0.0.1955",
|
|
81
|
-
"circuit-json": "^0.0.
|
|
81
|
+
"circuit-json": "^0.0.519"
|
|
82
82
|
}
|
|
83
83
|
}
|