circuit-json-to-gltf 0.0.52 → 0.0.56

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 CHANGED
@@ -79,6 +79,7 @@ interface Box3D {
79
79
  meshType?: "stl" | "obj" | "glb";
80
80
  label?: string;
81
81
  labelColor?: Color;
82
+ isTranslucent?: boolean;
82
83
  }
83
84
  interface Scene3D {
84
85
  boxes: Box3D[];
package/dist/index.js CHANGED
@@ -14678,7 +14678,7 @@ async function renderBoardLayer(circuitJson, options) {
14678
14678
  }
14679
14679
  async function convertSvgToPng(svgString, resolution, backgroundColor) {
14680
14680
  if (typeof window !== "undefined" && typeof document !== "undefined") {
14681
- const { svgToPngDataUrl } = await import("./svg-to-png-browser-VH734VGT.js");
14681
+ const { svgToPngDataUrl } = await import("./svg-to-png-browser-MXUWCXAZ.js");
14682
14682
  return await svgToPngDataUrl(svgString, {
14683
14683
  width: resolution,
14684
14684
  background: backgroundColor
@@ -15148,7 +15148,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
15148
15148
  const meshType = model_stl_url ? "stl" : model_obj_url ? "obj" : model_gltf_url ? "gltf" : model_glb_url ? "glb" : hasFootprinterModel ? "glb" : void 0;
15149
15149
  const box = {
15150
15150
  center,
15151
- size
15151
+ size,
15152
+ isTranslucent: cad.show_as_translucent_model
15152
15153
  };
15153
15154
  if (model_stl_url || model_obj_url || model_glb_url || model_gltf_url) {
15154
15155
  box.meshUrl = model_stl_url || model_obj_url || model_glb_url || model_gltf_url;
@@ -15936,16 +15937,22 @@ var GLTFBuilder = class {
15936
15937
  meshData = convertMeshToGLTFOrientation(meshData);
15937
15938
  let materialIndex = defaultMaterialIndex;
15938
15939
  if (box.color) {
15939
- materialIndex = this.addMaterialFromColor(box.color, !box.mesh);
15940
+ materialIndex = this.addMaterialFromColor({
15941
+ color: box.color,
15942
+ makeTransparent: !box.mesh,
15943
+ isTranslucent: box.isTranslucent
15944
+ });
15940
15945
  } else if (box.mesh) {
15946
+ const opacity = box.isTranslucent ? 0.5 : 1;
15941
15947
  materialIndex = this.addMaterial({
15942
15948
  name: `MeshMaterial_${this.materials.length}`,
15943
15949
  pbrMetallicRoughness: {
15944
- baseColorFactor: [0.7, 0.7, 0.7, 1],
15950
+ baseColorFactor: [0.7, 0.7, 0.7, opacity],
15945
15951
  metallicFactor: 0.1,
15946
15952
  roughnessFactor: 0.9
15947
15953
  },
15948
- alphaMode: "OPAQUE"
15954
+ alphaMode: box.isTranslucent ? "BLEND" : "OPAQUE",
15955
+ doubleSided: box.isTranslucent ? true : void 0
15949
15956
  });
15950
15957
  }
15951
15958
  const meshIndex = this.addMesh(meshData, materialIndex, box.label);
@@ -15971,7 +15978,10 @@ var GLTFBuilder = class {
15971
15978
  ];
15972
15979
  baseColor = [color[0], color[1], color[2], color[3]];
15973
15980
  }
15974
- const alpha = objMaterial.dissolve !== void 0 ? 1 - objMaterial.dissolve : baseColor[3];
15981
+ let alpha = objMaterial.dissolve !== void 0 ? 1 - objMaterial.dissolve : baseColor[3];
15982
+ if (box.isTranslucent) {
15983
+ alpha = 0.5;
15984
+ }
15975
15985
  baseColor[3] = alpha;
15976
15986
  const gltfMaterialIndex = this.addMaterial({
15977
15987
  name: `OBJ_${name}`,
@@ -15980,7 +15990,8 @@ var GLTFBuilder = class {
15980
15990
  metallicFactor: 0.05,
15981
15991
  roughnessFactor: 0.95
15982
15992
  },
15983
- alphaMode: alpha < 1 ? "BLEND" : "OPAQUE"
15993
+ alphaMode: alpha < 1 ? "BLEND" : "OPAQUE",
15994
+ doubleSided: box.isTranslucent ? true : void 0
15984
15995
  });
15985
15996
  const materialIndex = objMesh.materialIndexMap?.get(name) ?? -1;
15986
15997
  objMaterialIndices.set(materialIndex, gltfMaterialIndex);
@@ -16426,7 +16437,8 @@ var GLTFBuilder = class {
16426
16437
  this.materials.push(material);
16427
16438
  return index;
16428
16439
  }
16429
- addMaterialFromColor(color, makeTransparent = false) {
16440
+ addMaterialFromColor(opts) {
16441
+ const { color, makeTransparent = false, isTranslucent = false } = opts;
16430
16442
  const baseColor = typeof color === "string" ? this.parseColorString(color) : [color[0] / 255, color[1] / 255, color[2] / 255, color[3]];
16431
16443
  if (makeTransparent) {
16432
16444
  baseColor[3] = 0.5;
@@ -16438,7 +16450,8 @@ var GLTFBuilder = class {
16438
16450
  metallicFactor: 0.05,
16439
16451
  roughnessFactor: 0.95
16440
16452
  },
16441
- alphaMode: makeTransparent ? "BLEND" : "OPAQUE"
16453
+ alphaMode: makeTransparent || isTranslucent ? "BLEND" : "OPAQUE",
16454
+ doubleSided: isTranslucent ? true : void 0
16442
16455
  });
16443
16456
  }
16444
16457
  parseColorString(color) {
@@ -6,14 +6,18 @@ import {
6
6
  } from "./chunk-QGM4M3NI.js";
7
7
 
8
8
  // lib/utils/svg-to-png-browser.ts
9
- import { Resvg, initWasm } from "@resvg/resvg-wasm";
10
9
  var wasmInitialized = false;
10
+ var Resvg;
11
+ var initWasm;
11
12
  async function ensureWasmInitialized() {
12
13
  if (!wasmInitialized) {
13
14
  try {
14
15
  if (typeof process !== "undefined" && process.versions?.node) {
15
16
  const { readFileSync } = await import("fs");
16
17
  const { dirname, join } = await import("path");
18
+ const resvgModule = await import("@resvg/resvg-wasm");
19
+ Resvg = resvgModule.Resvg;
20
+ initWasm = resvgModule.initWasm;
17
21
  try {
18
22
  const packagePath = __require.resolve("@resvg/resvg-wasm/package.json");
19
23
  const wasmPath = join(dirname(packagePath), "index_bg.wasm");
@@ -33,12 +37,28 @@ async function ensureWasmInitialized() {
33
37
  }
34
38
  } else {
35
39
  try {
40
+ const resvgModule = await import("@resvg/resvg-wasm");
41
+ Resvg = resvgModule.Resvg;
42
+ initWasm = resvgModule.initWasm;
36
43
  const wasmUrl = await import("@resvg/resvg-wasm/index_bg.wasm?url");
37
44
  await initWasm(fetch(wasmUrl.default));
38
45
  } catch {
39
- await initWasm(
40
- fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
41
- );
46
+ try {
47
+ const cdnUrl = "https://cdn.jsdelivr.net/npm/@resvg/resvg-wasm@2.6.2/+esm";
48
+ const resvgModule = await import(
49
+ /* @vite-ignore */
50
+ cdnUrl
51
+ );
52
+ Resvg = resvgModule.Resvg;
53
+ initWasm = resvgModule.initWasm;
54
+ await initWasm(
55
+ fetch("https://unpkg.com/@resvg/resvg-wasm@2.6.2/index_bg.wasm")
56
+ );
57
+ } catch (cdnError) {
58
+ throw new Error(
59
+ `Failed to load resvg-wasm from CDN: ${cdnError.message}`
60
+ );
61
+ }
42
62
  }
43
63
  }
44
64
  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.52",
5
+ "version": "0.0.56",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",
@@ -32,7 +32,7 @@
32
32
  "@types/react-dom": "^19.1.7",
33
33
  "@vitejs/plugin-react": "^5.0.0",
34
34
  "bun-match-svg": "^0.0.12",
35
- "circuit-json": "^0.0.312",
35
+ "circuit-json": "^0.0.327",
36
36
  "circuit-to-svg": "0.0.283",
37
37
  "graphics-debug": "^0.0.65",
38
38
  "looks-same": "^9.0.1",
@@ -41,7 +41,7 @@
41
41
  "react-cosmos": "^7.0.0",
42
42
  "react-cosmos-plugin-vite": "^7.0.0",
43
43
  "react-dom": "^19.1.1",
44
- "tscircuit": "^0.0.800",
44
+ "tscircuit": "^0.0.1020",
45
45
  "tsup": "^8.5.0",
46
46
  "vite": "^7.1.1"
47
47
  },