circuit-json-to-gltf 0.0.29 → 0.0.30

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
@@ -118,6 +118,7 @@ interface CircuitTo3DOptions {
118
118
  renderBoardTextures?: boolean;
119
119
  textureResolution?: number;
120
120
  coordinateTransform?: CoordinateTransformConfig;
121
+ showBoundingBoxes?: boolean;
121
122
  }
122
123
  interface BoardRenderOptions {
123
124
  layer: "top" | "bottom";
@@ -165,6 +166,7 @@ declare const COORDINATE_TRANSFORMS: {
165
166
  readonly TEST_FLIP_X: CoordinateTransformConfig;
166
167
  readonly TEST_FLIP_Z: CoordinateTransformConfig;
167
168
  readonly FOOTPRINTER_MODEL_TRANSFORM: CoordinateTransformConfig;
169
+ readonly OBJ_Z_UP_TO_Y_UP: CoordinateTransformConfig;
168
170
  };
169
171
 
170
172
  declare function convertCircuitJsonToGltf(circuitJson: CircuitJson, options?: ConversionOptions): Promise<ArrayBuffer | object>;
package/dist/index.js CHANGED
@@ -13627,6 +13627,10 @@ var COORDINATE_TRANSFORMS = {
13627
13627
  axisMapping: { x: "x", y: "-z", z: "y" },
13628
13628
  flipX: -1,
13629
13629
  rotation: { x: 180, y: 180 }
13630
+ },
13631
+ // OBJ models: Z-up to Y-up with Y→Z (no negation to preserve winding order)
13632
+ OBJ_Z_UP_TO_Y_UP: {
13633
+ axisMapping: { x: "x", y: "z", z: "y" }
13630
13634
  }
13631
13635
  };
13632
13636
 
@@ -14865,7 +14869,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14865
14869
  defaultComponentHeight = DEFAULT_COMPONENT_HEIGHT,
14866
14870
  renderBoardTextures: shouldRenderTextures = true,
14867
14871
  textureResolution = 1024,
14868
- coordinateTransform
14872
+ coordinateTransform,
14873
+ showBoundingBoxes = true
14869
14874
  } = options;
14870
14875
  const db = cju(circuitJson);
14871
14876
  const boxes = [];
@@ -14981,7 +14986,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14981
14986
  }
14982
14987
  }
14983
14988
  const usingGlbCoordinates = Boolean(model_glb_url || model_gltf_url);
14984
- const defaultTransform = coordinateTransform ?? (usingGlbCoordinates ? void 0 : hasFootprinterModel ? COORDINATE_TRANSFORMS.FOOTPRINTER_MODEL_TRANSFORM : COORDINATE_TRANSFORMS.Z_UP_TO_Y_UP_USB_FIX);
14989
+ const usingObjFormat = Boolean(model_obj_url);
14990
+ const defaultTransform = coordinateTransform ?? (usingGlbCoordinates ? void 0 : hasFootprinterModel ? COORDINATE_TRANSFORMS.FOOTPRINTER_MODEL_TRANSFORM : usingObjFormat ? COORDINATE_TRANSFORMS.OBJ_Z_UP_TO_Y_UP : COORDINATE_TRANSFORMS.Z_UP_TO_Y_UP_USB_FIX);
14985
14991
  if (model_stl_url) {
14986
14992
  box.mesh = await loadSTL(model_stl_url, defaultTransform);
14987
14993
  } else if (model_obj_url) {
@@ -14999,36 +15005,42 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14999
15005
  if (box.mesh && modelScaleFactor !== 1) {
15000
15006
  box.mesh = scaleMesh(box.mesh, modelScaleFactor);
15001
15007
  }
15008
+ if (box.mesh && cad.position && usingObjFormat) {
15009
+ const meshBottom = box.mesh.boundingBox.min.y;
15010
+ box.center.y -= meshBottom;
15011
+ }
15002
15012
  if (!box.mesh) {
15003
15013
  box.color = componentColor;
15004
15014
  }
15005
15015
  boxes.push(box);
15006
15016
  }
15007
- for (const component of db.pcb_component.list()) {
15008
- if (pcbComponentIdsWith3D.has(component.pcb_component_id)) continue;
15009
- const sourceComponent = db.source_component.get(
15010
- component.source_component_id
15011
- );
15012
- const compHeight = Math.min(
15013
- Math.min(component.width, component.height),
15014
- defaultComponentHeight
15015
- );
15016
- const isBottomLayer = component.layer === "bottom";
15017
- boxes.push({
15018
- center: {
15019
- x: component.center.x,
15020
- y: isBottomLayer ? -(effectiveBoardThickness + compHeight / 2) : effectiveBoardThickness / 2 + compHeight / 2,
15021
- z: component.center.y
15022
- },
15023
- size: {
15024
- x: component.width,
15025
- y: compHeight,
15026
- z: component.height
15027
- },
15028
- color: componentColor,
15029
- label: sourceComponent?.name ?? "?",
15030
- labelColor: "white"
15031
- });
15017
+ if (showBoundingBoxes) {
15018
+ for (const component of db.pcb_component.list()) {
15019
+ if (pcbComponentIdsWith3D.has(component.pcb_component_id)) continue;
15020
+ const sourceComponent = db.source_component.get(
15021
+ component.source_component_id
15022
+ );
15023
+ const compHeight = Math.min(
15024
+ Math.min(component.width, component.height),
15025
+ defaultComponentHeight
15026
+ );
15027
+ const isBottomLayer = component.layer === "bottom";
15028
+ boxes.push({
15029
+ center: {
15030
+ x: component.center.x,
15031
+ y: isBottomLayer ? -(effectiveBoardThickness + compHeight / 2) : effectiveBoardThickness / 2 + compHeight / 2,
15032
+ z: component.center.y
15033
+ },
15034
+ size: {
15035
+ x: component.width,
15036
+ y: compHeight,
15037
+ z: component.height
15038
+ },
15039
+ color: componentColor,
15040
+ label: sourceComponent?.name ?? "?",
15041
+ labelColor: "white"
15042
+ });
15043
+ }
15032
15044
  }
15033
15045
  let camera;
15034
15046
  if (pcbBoard) {
@@ -16401,7 +16413,8 @@ async function convertCircuitJsonToGltf(circuitJson, options = {}) {
16401
16413
  const scene3D = await convertCircuitJsonTo3D(circuitJson, {
16402
16414
  renderBoardTextures: true,
16403
16415
  textureResolution: boardTextureResolution,
16404
- coordinateTransform: options.coordinateTransform
16416
+ coordinateTransform: options.coordinateTransform,
16417
+ showBoundingBoxes
16405
16418
  });
16406
16419
  const gltfOptions = {
16407
16420
  binary: format === "glb",
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.29",
5
+ "version": "0.0.30",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",