circuit-json-to-gltf 0.0.154 → 0.0.156
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/README.md +23 -4
- package/dist/index.d.ts +7 -0
- package/dist/index.js +22 -12
- package/dist/{svg-to-png-AFPNZW36.js → svg-to-png-NRFWX3UJ.js} +1 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -37,16 +37,16 @@ const circuitJson = {
|
|
|
37
37
|
center: { x: 0, y: 0 },
|
|
38
38
|
width: 80,
|
|
39
39
|
height: 60,
|
|
40
|
-
thickness: 1.6
|
|
40
|
+
thickness: 1.6,
|
|
41
41
|
},
|
|
42
42
|
// ... components, traces, etc.
|
|
43
|
-
]
|
|
43
|
+
],
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Convert to GLTF
|
|
47
47
|
const gltf = await convertCircuitJsonToGltf(circuitJson, {
|
|
48
48
|
format: "gltf", // or "glb" for binary
|
|
49
|
-
boardTextureResolution: 2048
|
|
49
|
+
boardTextureResolution: 2048,
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
// Save the result
|
|
@@ -88,7 +88,6 @@ silkscreen colors. Explicit conversion options take precedence.
|
|
|
88
88
|
## Architecture
|
|
89
89
|
|
|
90
90
|
The converter uses a modular architecture:
|
|
91
|
-
|
|
92
91
|
1. **Circuit to 3D Converter**: Parses circuit JSON and creates a 3D scene representation
|
|
93
92
|
2. **Board Renderer**: Renders PCB layers as textures using circuit-to-svg and resvg
|
|
94
93
|
3. **Model Loaders**: Load STL and OBJ files for component 3D models
|
|
@@ -115,3 +114,23 @@ bun run examples/basic-conversion.ts
|
|
|
115
114
|
- Pure GLTF 2.0 implementation without external 3D library dependencies
|
|
116
115
|
- Supports both JSON (.gltf) and binary (.glb) formats
|
|
117
116
|
- Embeds all assets (textures, buffers) directly in the output
|
|
117
|
+
|
|
118
|
+
### Component metadata
|
|
119
|
+
|
|
120
|
+
Both glTF and GLB exports preserve component names as node `name` values and
|
|
121
|
+
include lightweight identity in component node `extras.tscircuit`:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"cad_component_id": "cad_component_1",
|
|
126
|
+
"source_component_id": "source_component_1",
|
|
127
|
+
"pcb_component_id": "pcb_component_1",
|
|
128
|
+
"componentName": "U1"
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Only available fields are serialized. Each CAD instance keeps its own identity,
|
|
133
|
+
including when instances share a mesh or source component. This allows a viewer
|
|
134
|
+
to show names, hide components, and navigate to a schematic from a pre-rendered
|
|
135
|
+
GLB without embedding the complete Circuit JSON. Existing extras, such as
|
|
136
|
+
`poppygl.showHiddenEdges`, are preserved alongside the metadata.
|
package/dist/index.d.ts
CHANGED
|
@@ -135,6 +135,13 @@ interface OBJMaterial {
|
|
|
135
135
|
}
|
|
136
136
|
type Color = string | [number, number, number, number];
|
|
137
137
|
interface Box3D {
|
|
138
|
+
/** Lightweight identity exported as glTF node extras.tscircuit (no geometry). */
|
|
139
|
+
componentMetadata?: {
|
|
140
|
+
cad_component_id?: string;
|
|
141
|
+
source_component_id?: string;
|
|
142
|
+
pcb_component_id?: string;
|
|
143
|
+
componentName?: string;
|
|
144
|
+
};
|
|
138
145
|
center: Point3;
|
|
139
146
|
size: Size3;
|
|
140
147
|
rotation?: Point3;
|
package/dist/index.js
CHANGED
|
@@ -18400,7 +18400,7 @@ async function convertSvgToPng(svgString, resolution, backgroundColor) {
|
|
|
18400
18400
|
});
|
|
18401
18401
|
} else {
|
|
18402
18402
|
try {
|
|
18403
|
-
const { svgToPngDataUrl } = await import("./svg-to-png-
|
|
18403
|
+
const { svgToPngDataUrl } = await import("./svg-to-png-NRFWX3UJ.js");
|
|
18404
18404
|
return await svgToPngDataUrl(svgString, {
|
|
18405
18405
|
width: resolution,
|
|
18406
18406
|
background: backgroundColor
|
|
@@ -18844,7 +18844,13 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
18844
18844
|
size,
|
|
18845
18845
|
isTranslucent: cad.show_as_translucent_model,
|
|
18846
18846
|
showHiddenEdges: cad.show_hidden_edges,
|
|
18847
|
-
label: sourceComponent?.name
|
|
18847
|
+
label: sourceComponent?.name,
|
|
18848
|
+
componentMetadata: {
|
|
18849
|
+
cad_component_id: cad.cad_component_id,
|
|
18850
|
+
source_component_id: cad.source_component_id,
|
|
18851
|
+
pcb_component_id: cad.pcb_component_id,
|
|
18852
|
+
componentName: sourceComponent?.name
|
|
18853
|
+
}
|
|
18848
18854
|
};
|
|
18849
18855
|
if (model_stl_url || model_obj_url || model_glb_url || model_gltf_url || model_step_url) {
|
|
18850
18856
|
box.meshUrl = model_stl_url || model_obj_url || model_glb_url || model_gltf_url || model_step_url;
|
|
@@ -19013,6 +19019,11 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
19013
19019
|
},
|
|
19014
19020
|
color: componentColor,
|
|
19015
19021
|
label: sourceComponent?.name ?? "?",
|
|
19022
|
+
componentMetadata: {
|
|
19023
|
+
source_component_id: component.source_component_id,
|
|
19024
|
+
pcb_component_id: component.pcb_component_id,
|
|
19025
|
+
componentName: sourceComponent?.name
|
|
19026
|
+
},
|
|
19016
19027
|
labelColor: "white"
|
|
19017
19028
|
};
|
|
19018
19029
|
const result = fold ? tryFoldRigidBox(box, fold, pcbBoard.center, component.center) : void 0;
|
|
@@ -19406,7 +19417,7 @@ var GLTFBuilder = class {
|
|
|
19406
19417
|
name: box.label || `Box${nodeIndex}`,
|
|
19407
19418
|
mesh: meshIndex,
|
|
19408
19419
|
translation: this.toGltfTranslation(box.center),
|
|
19409
|
-
...this.
|
|
19420
|
+
...this.getNodeExtras(box)
|
|
19410
19421
|
});
|
|
19411
19422
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19412
19423
|
}
|
|
@@ -19464,7 +19475,7 @@ var GLTFBuilder = class {
|
|
|
19464
19475
|
name: box.label || `Box${nodeIndex}`,
|
|
19465
19476
|
mesh: meshIndex,
|
|
19466
19477
|
translation: this.toGltfTranslation(box.center),
|
|
19467
|
-
...this.
|
|
19478
|
+
...this.getNodeExtras(box)
|
|
19468
19479
|
});
|
|
19469
19480
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19470
19481
|
}
|
|
@@ -19565,7 +19576,7 @@ var GLTFBuilder = class {
|
|
|
19565
19576
|
name: box.label || `OBJBox${nodeIndex}`,
|
|
19566
19577
|
mesh: meshIndex,
|
|
19567
19578
|
translation: this.toGltfTranslation(box.center),
|
|
19568
|
-
...this.
|
|
19579
|
+
...this.getNodeExtras(box)
|
|
19569
19580
|
});
|
|
19570
19581
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19571
19582
|
}
|
|
@@ -19725,7 +19736,7 @@ var GLTFBuilder = class {
|
|
|
19725
19736
|
name: box.label || `Box${nodeIndex}`,
|
|
19726
19737
|
mesh: meshIndex,
|
|
19727
19738
|
translation: this.toGltfTranslation(box.center),
|
|
19728
|
-
...this.
|
|
19739
|
+
...this.getNodeExtras(box)
|
|
19729
19740
|
});
|
|
19730
19741
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19731
19742
|
}
|
|
@@ -19831,7 +19842,7 @@ var GLTFBuilder = class {
|
|
|
19831
19842
|
name: box.label || `Box${nodeIndex}`,
|
|
19832
19843
|
mesh: meshIndex,
|
|
19833
19844
|
translation: this.toGltfTranslation(box.center),
|
|
19834
|
-
...this.
|
|
19845
|
+
...this.getNodeExtras(box)
|
|
19835
19846
|
});
|
|
19836
19847
|
this.gltf.scenes[0].nodes.push(nodeIndex);
|
|
19837
19848
|
}
|
|
@@ -19887,13 +19898,12 @@ var GLTFBuilder = class {
|
|
|
19887
19898
|
toGltfTranslation(center) {
|
|
19888
19899
|
return [-center.x, center.y, center.z];
|
|
19889
19900
|
}
|
|
19890
|
-
|
|
19891
|
-
if (!box.showHiddenEdges) return {};
|
|
19901
|
+
getNodeExtras(box) {
|
|
19902
|
+
if (!box.showHiddenEdges && !box.componentMetadata) return {};
|
|
19892
19903
|
return {
|
|
19893
19904
|
extras: {
|
|
19894
|
-
poppygl: {
|
|
19895
|
-
|
|
19896
|
-
}
|
|
19905
|
+
...box.showHiddenEdges ? { poppygl: { showHiddenEdges: true } } : {},
|
|
19906
|
+
...box.componentMetadata ? { tscircuit: box.componentMetadata } : {}
|
|
19897
19907
|
}
|
|
19898
19908
|
};
|
|
19899
19909
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "./chunk-QGM4M3NI.js";
|
|
2
2
|
|
|
3
3
|
// lib/utils/svg-to-png.ts
|
|
4
|
-
import { Resvg } from "@resvg/resvg-js";
|
|
5
4
|
import tscircuitFont from "@tscircuit/alphabet/base64font";
|
|
6
5
|
var isNode = typeof process !== "undefined" && process.versions && process.versions.node;
|
|
7
6
|
async function svgToPng(svgString, options = {}) {
|
|
@@ -49,6 +48,7 @@ async function svgToPng(svgString, options = {}) {
|
|
|
49
48
|
sansSerifFamily: "TscircuitAlphabet"
|
|
50
49
|
}
|
|
51
50
|
};
|
|
51
|
+
const { Resvg } = await import("@resvg/resvg-js");
|
|
52
52
|
const resvg = new Resvg(svgString, opts);
|
|
53
53
|
const pngData = resvg.render();
|
|
54
54
|
const pngBuffer = pngData.asPng();
|
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.156",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/tscircuit/circuit-json-to-gltf.git"
|
|
@@ -19,6 +19,12 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
|
+
"browser": {
|
|
23
|
+
"@resvg/resvg-js": false,
|
|
24
|
+
"fs": false,
|
|
25
|
+
"os": false,
|
|
26
|
+
"path": false
|
|
27
|
+
},
|
|
22
28
|
"dependencies": {
|
|
23
29
|
"@jscad/modeling": "^2.12.6",
|
|
24
30
|
"@tscircuit/alphabet": "^0.0.25",
|
|
@@ -40,6 +46,7 @@
|
|
|
40
46
|
"@tscircuit/circuit-json-util": "^0.0.114",
|
|
41
47
|
"@tscircuit/core": "^0.0.1955",
|
|
42
48
|
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.8.tgz",
|
|
49
|
+
"@tscircuit/image-utils": "^0.0.10",
|
|
43
50
|
"@tscircuit/props": "^0.0.664",
|
|
44
51
|
"@types/bun": "latest",
|
|
45
52
|
"@types/earcut": "^3.0.0",
|
|
@@ -50,7 +57,6 @@
|
|
|
50
57
|
"circuit-json": "https://pkg.pr.new/circuit-json@90e54bd",
|
|
51
58
|
"circuit-to-svg": "^0.0.445",
|
|
52
59
|
"graphics-debug": "^0.0.96",
|
|
53
|
-
"looks-same": "^9.0.1",
|
|
54
60
|
"poppygl": "0.0.32",
|
|
55
61
|
"react": "^19.1.1",
|
|
56
62
|
"react-cosmos": "^7.0.0",
|