circuit-json-to-gltf 0.0.3 → 0.0.5

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Converts circuit JSON to 3D GLTF files. Used for exporting circuits as 3D models.
4
4
 
5
+ [Online Playground](https://circuit-json-to-gltf.vercel.app/renderer.html?fixtureId=%7B%22path%22%3A%22CircuitToGltfDemo.fixture.tsx%22%7D&locked=true)
6
+
5
7
  <img width="2424" height="1854" alt="image" src="https://github.com/user-attachments/assets/4ad8b607-e496-449c-88a3-8875b16c0a53" />
6
8
 
7
9
  ## Features
package/dist/index.js CHANGED
@@ -520,7 +520,7 @@ async function convertSvgToPng(svgString, resolution, backgroundColor) {
520
520
  if (typeof window !== "undefined" && typeof document !== "undefined") {
521
521
  return convertSvgToCanvasBrowser(svgString, resolution, backgroundColor);
522
522
  } else {
523
- const { svgToPngDataUrl } = await import("./svg-to-png-browser-2JB6D5DD.js");
523
+ const { svgToPngDataUrl } = await import("./svg-to-png-browser-ZI5PXAWS.js");
524
524
  return await svgToPngDataUrl(svgString, {
525
525
  width: resolution,
526
526
  background: backgroundColor
@@ -1139,7 +1139,11 @@ function createMeshFromOBJ(objMesh) {
1139
1139
  const baseIndex = targetMesh.positions.length / 3;
1140
1140
  for (const vertex of triangle.vertices) {
1141
1141
  targetMesh.positions.push(vertex.x, vertex.y, vertex.z);
1142
- targetMesh.normals.push(triangle.normal.x, triangle.normal.y, triangle.normal.z);
1142
+ targetMesh.normals.push(
1143
+ triangle.normal.x,
1144
+ triangle.normal.y,
1145
+ triangle.normal.z
1146
+ );
1143
1147
  targetMesh.texcoords.push(vertex.x, vertex.z);
1144
1148
  }
1145
1149
  targetMesh.indices.push(baseIndex, baseIndex + 2, baseIndex + 1);
@@ -1332,7 +1336,12 @@ var GLTFBuilder = class {
1332
1336
  const alpha = 1 - dissolve;
1333
1337
  let baseColor = [0.3, 0.3, 0.3, alpha];
1334
1338
  if (objMaterial.color) {
1335
- const color = typeof objMaterial.color === "string" ? this.parseColorString(objMaterial.color) : [objMaterial.color[0] / 255, objMaterial.color[1] / 255, objMaterial.color[2] / 255, alpha];
1339
+ const color = typeof objMaterial.color === "string" ? this.parseColorString(objMaterial.color) : [
1340
+ objMaterial.color[0] / 255,
1341
+ objMaterial.color[1] / 255,
1342
+ objMaterial.color[2] / 255,
1343
+ alpha
1344
+ ];
1336
1345
  baseColor = [color[0], color[1], color[2], alpha];
1337
1346
  }
1338
1347
  const gltfMaterialIndex = this.addMaterial({
@@ -1349,7 +1358,11 @@ var GLTFBuilder = class {
1349
1358
  }
1350
1359
  const primitives = [];
1351
1360
  for (const { meshData, materialIndex } of meshDataArray) {
1352
- const transformedMeshData = transformMesh(meshData, box.center, box.rotation);
1361
+ const transformedMeshData = transformMesh(
1362
+ meshData,
1363
+ box.center,
1364
+ box.rotation
1365
+ );
1353
1366
  const positionAccessorIndex = this.addAccessor(
1354
1367
  transformedMeshData.positions,
1355
1368
  "VEC3",
@@ -1464,7 +1477,11 @@ var GLTFBuilder = class {
1464
1477
  const meshIndex = this.meshes.length;
1465
1478
  const primitives = [];
1466
1479
  for (const [faceName, faceData] of Object.entries(faceMeshes)) {
1467
- const transformedFaceData = transformMesh(faceData, box.center, box.rotation);
1480
+ const transformedFaceData = transformMesh(
1481
+ faceData,
1482
+ box.center,
1483
+ box.rotation
1484
+ );
1468
1485
  const positionAccessorIndex = this.addAccessor(
1469
1486
  transformedFaceData.positions,
1470
1487
  "VEC3",
@@ -6,10 +6,7 @@ async function ensureWasmInitialized() {
6
6
  try {
7
7
  if (typeof process !== "undefined" && process.versions?.node) {
8
8
  const { readFileSync } = await import("fs");
9
- const { fileURLToPath } = await import("url");
10
- const { dirname, join } = await import("path");
11
- const currentDir = dirname(fileURLToPath(import.meta.url));
12
- const wasmPath = join(currentDir, "../../node_modules/@resvg/resvg-wasm/index_bg.wasm");
9
+ const wasmPath = await import("@resvg/resvg-wasm/index_bg.wasm");
13
10
  const wasmBuffer = readFileSync(wasmPath);
14
11
  await initWasm(wasmBuffer);
15
12
  } else {
@@ -17,7 +14,9 @@ async function ensureWasmInitialized() {
17
14
  const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
18
15
  await initWasm(fetch(wasmUrl.default));
19
16
  } catch {
20
- await initWasm(fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm"));
17
+ await initWasm(
18
+ fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
19
+ );
21
20
  }
22
21
  }
23
22
  wasmInitialized = true;
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.3",
5
+ "version": "0.0.5",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",
@@ -35,7 +35,17 @@
35
35
  "vite": "^7.1.1"
36
36
  },
37
37
  "peerDependencies": {
38
- "typescript": "^5"
38
+ "typescript": "^5",
39
+ "@resvg/resvg-wasm": "2",
40
+ "@resvg/resvg-js": "2",
41
+ "circuit-to-svg": "*",
42
+ "@tscircuit/circuit-json-util": "*",
43
+ "circuit-json": "*"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@resvg/resvg-wasm": {
47
+ "optional": true
48
+ }
39
49
  },
40
50
  "dependencies": {}
41
51
  }