circuit-json-to-gltf 0.0.15 → 0.0.17
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 +96 -48
- package/package.json +7 -3
package/dist/index.js
CHANGED
|
@@ -1100,37 +1100,39 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
|
|
|
1100
1100
|
} = options;
|
|
1101
1101
|
const db = cju(circuitJson);
|
|
1102
1102
|
const boxes = [];
|
|
1103
|
-
const pcbBoard = db.pcb_board
|
|
1104
|
-
if (
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1103
|
+
const pcbBoard = db.pcb_board?.list?.()[0];
|
|
1104
|
+
if (pcbBoard) {
|
|
1105
|
+
const boardBox = {
|
|
1106
|
+
center: {
|
|
1107
|
+
x: pcbBoard.center.x,
|
|
1108
|
+
y: 0,
|
|
1109
|
+
z: pcbBoard.center.y
|
|
1110
|
+
},
|
|
1111
|
+
size: {
|
|
1112
|
+
x: pcbBoard.width,
|
|
1113
|
+
y: boardThickness,
|
|
1114
|
+
z: pcbBoard.height
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
if (shouldRenderTextures && textureResolution > 0) {
|
|
1118
|
+
try {
|
|
1119
|
+
const textures = await renderBoardTextures(
|
|
1120
|
+
circuitJson,
|
|
1121
|
+
textureResolution
|
|
1122
|
+
);
|
|
1123
|
+
boardBox.texture = {
|
|
1124
|
+
top: textures.top,
|
|
1125
|
+
bottom: textures.bottom
|
|
1126
|
+
};
|
|
1127
|
+
} catch (error) {
|
|
1128
|
+
console.warn("Failed to render board textures:", error);
|
|
1129
|
+
boardBox.color = pcbColor;
|
|
1130
|
+
}
|
|
1131
|
+
} else {
|
|
1128
1132
|
boardBox.color = pcbColor;
|
|
1129
1133
|
}
|
|
1130
|
-
|
|
1131
|
-
boardBox.color = pcbColor;
|
|
1134
|
+
boxes.push(boardBox);
|
|
1132
1135
|
}
|
|
1133
|
-
boxes.push(boardBox);
|
|
1134
1136
|
const cadComponents = db.cad_component?.list?.() ?? [];
|
|
1135
1137
|
const pcbComponentIdsWith3D = /* @__PURE__ */ new Set();
|
|
1136
1138
|
for (const cad of cadComponents) {
|
|
@@ -1239,26 +1241,72 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
|
|
|
1239
1241
|
labelColor: "white"
|
|
1240
1242
|
});
|
|
1241
1243
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1244
|
+
let camera;
|
|
1245
|
+
if (pcbBoard) {
|
|
1246
|
+
const boardDiagonal = Math.sqrt(
|
|
1247
|
+
pcbBoard.width * pcbBoard.width + pcbBoard.height * pcbBoard.height
|
|
1248
|
+
);
|
|
1249
|
+
const cameraDistance = boardDiagonal * 1.5;
|
|
1250
|
+
camera = {
|
|
1251
|
+
position: {
|
|
1252
|
+
x: pcbBoard.center.x + cameraDistance * 0.5,
|
|
1253
|
+
y: cameraDistance * 0.7,
|
|
1254
|
+
z: pcbBoard.center.y + cameraDistance * 0.5
|
|
1255
|
+
},
|
|
1256
|
+
target: {
|
|
1257
|
+
x: pcbBoard.center.x,
|
|
1258
|
+
y: 0,
|
|
1259
|
+
z: pcbBoard.center.y
|
|
1260
|
+
},
|
|
1261
|
+
up: { x: 0, y: 1, z: 0 },
|
|
1262
|
+
fov: 50,
|
|
1263
|
+
near: 0.1,
|
|
1264
|
+
far: cameraDistance * 4
|
|
1265
|
+
};
|
|
1266
|
+
} else {
|
|
1267
|
+
const hasBoxes = boxes.length > 0;
|
|
1268
|
+
if (hasBoxes) {
|
|
1269
|
+
let minX = Infinity;
|
|
1270
|
+
let minZ = Infinity;
|
|
1271
|
+
let maxX = -Infinity;
|
|
1272
|
+
let maxZ = -Infinity;
|
|
1273
|
+
for (const box of boxes) {
|
|
1274
|
+
const halfX = (box.size?.x ?? 0) / 2;
|
|
1275
|
+
const halfZ = (box.size?.z ?? 0) / 2;
|
|
1276
|
+
minX = Math.min(minX, box.center.x - halfX);
|
|
1277
|
+
maxX = Math.max(maxX, box.center.x + halfX);
|
|
1278
|
+
minZ = Math.min(minZ, box.center.z - halfZ);
|
|
1279
|
+
maxZ = Math.max(maxZ, box.center.z + halfZ);
|
|
1280
|
+
}
|
|
1281
|
+
const width = Math.max(maxX - minX, 1);
|
|
1282
|
+
const height = Math.max(maxZ - minZ, 1);
|
|
1283
|
+
const diagonal = Math.sqrt(width * width + height * height);
|
|
1284
|
+
const distance = diagonal * 1.5;
|
|
1285
|
+
const centerX = (minX + maxX) / 2;
|
|
1286
|
+
const centerZ = (minZ + maxZ) / 2;
|
|
1287
|
+
camera = {
|
|
1288
|
+
position: {
|
|
1289
|
+
x: centerX + distance * 0.5,
|
|
1290
|
+
y: distance * 0.7,
|
|
1291
|
+
z: centerZ + distance * 0.5
|
|
1292
|
+
},
|
|
1293
|
+
target: { x: centerX, y: 0, z: centerZ },
|
|
1294
|
+
up: { x: 0, y: 1, z: 0 },
|
|
1295
|
+
fov: 50,
|
|
1296
|
+
near: 0.1,
|
|
1297
|
+
far: distance * 4
|
|
1298
|
+
};
|
|
1299
|
+
} else {
|
|
1300
|
+
camera = {
|
|
1301
|
+
position: { x: 30, y: 30, z: 25 },
|
|
1302
|
+
target: { x: 0, y: 0, z: 0 },
|
|
1303
|
+
up: { x: 0, y: 1, z: 0 },
|
|
1304
|
+
fov: 50,
|
|
1305
|
+
near: 0.1,
|
|
1306
|
+
far: 120
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1262
1310
|
const lights = [
|
|
1263
1311
|
{
|
|
1264
1312
|
type: "ambient",
|
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.17",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "bun test tests/",
|
|
8
8
|
"format": "biome format --write .",
|
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
"bun-match-svg": "^0.0.12",
|
|
28
28
|
"circuit-json": "^0.0.267",
|
|
29
29
|
"circuit-to-svg": "^0.0.175",
|
|
30
|
+
"graphics-debug": "^0.0.65",
|
|
30
31
|
"looks-same": "^9.0.1",
|
|
31
32
|
"poppygl": "^0.0.9",
|
|
32
33
|
"react": "^19.1.1",
|
|
33
34
|
"react-cosmos": "^7.0.0",
|
|
34
35
|
"react-cosmos-plugin-vite": "^7.0.0",
|
|
35
36
|
"react-dom": "^19.1.1",
|
|
37
|
+
"tscircuit": "^0.0.701",
|
|
36
38
|
"tsup": "^8.5.0",
|
|
37
|
-
"vite": "^7.1.1"
|
|
38
|
-
"tscircuit": "^0.0.701"
|
|
39
|
+
"vite": "^7.1.1"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"typescript": "^5",
|
|
@@ -48,6 +49,9 @@
|
|
|
48
49
|
"peerDependenciesMeta": {
|
|
49
50
|
"@resvg/resvg-wasm": {
|
|
50
51
|
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@resvg/resvg-js": {
|
|
54
|
+
"optional": true
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
}
|