circuit-json-to-gltf 0.0.29 → 0.0.31

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
 
@@ -14759,9 +14763,11 @@ var createHoleGeoms = (boardCenter, thickness, holes = [], platedHoles = []) =>
14759
14763
  holeGeoms.push(createCircularHole(relX, relY, radius, thickness));
14760
14764
  }
14761
14765
  for (const plated of platedHoles) {
14762
- const relX = plated.x - boardCenter.x;
14763
- const relY = -(plated.y - boardCenter.y);
14764
14766
  const platedRecord = plated;
14767
+ const holeOffsetX = getNumberProperty(platedRecord, "hole_offset_x") ?? 0;
14768
+ const holeOffsetY = getNumberProperty(platedRecord, "hole_offset_y") ?? 0;
14769
+ const relX = plated.x - boardCenter.x + holeOffsetX;
14770
+ const relY = -(plated.y - boardCenter.y + holeOffsetY);
14765
14771
  if (plated.shape === "pill" || plated.shape === "pill_hole_with_rect_pad") {
14766
14772
  const holeWidth = getNumberProperty(platedRecord, "hole_width") ?? getNumberProperty(platedRecord, "outer_diameter") ?? 0;
14767
14773
  const holeHeight = getNumberProperty(platedRecord, "hole_height") ?? getNumberProperty(platedRecord, "hole_diameter") ?? 0;
@@ -14865,7 +14871,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14865
14871
  defaultComponentHeight = DEFAULT_COMPONENT_HEIGHT,
14866
14872
  renderBoardTextures: shouldRenderTextures = true,
14867
14873
  textureResolution = 1024,
14868
- coordinateTransform
14874
+ coordinateTransform,
14875
+ showBoundingBoxes = true
14869
14876
  } = options;
14870
14877
  const db = cju(circuitJson);
14871
14878
  const boxes = [];
@@ -14981,7 +14988,8 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14981
14988
  }
14982
14989
  }
14983
14990
  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);
14991
+ const usingObjFormat = Boolean(model_obj_url);
14992
+ 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
14993
  if (model_stl_url) {
14986
14994
  box.mesh = await loadSTL(model_stl_url, defaultTransform);
14987
14995
  } else if (model_obj_url) {
@@ -14999,36 +15007,42 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14999
15007
  if (box.mesh && modelScaleFactor !== 1) {
15000
15008
  box.mesh = scaleMesh(box.mesh, modelScaleFactor);
15001
15009
  }
15010
+ if (box.mesh && cad.position && usingObjFormat) {
15011
+ const meshBottom = box.mesh.boundingBox.min.y;
15012
+ box.center.y -= meshBottom;
15013
+ }
15002
15014
  if (!box.mesh) {
15003
15015
  box.color = componentColor;
15004
15016
  }
15005
15017
  boxes.push(box);
15006
15018
  }
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
- });
15019
+ if (showBoundingBoxes) {
15020
+ for (const component of db.pcb_component.list()) {
15021
+ if (pcbComponentIdsWith3D.has(component.pcb_component_id)) continue;
15022
+ const sourceComponent = db.source_component.get(
15023
+ component.source_component_id
15024
+ );
15025
+ const compHeight = Math.min(
15026
+ Math.min(component.width, component.height),
15027
+ defaultComponentHeight
15028
+ );
15029
+ const isBottomLayer = component.layer === "bottom";
15030
+ boxes.push({
15031
+ center: {
15032
+ x: component.center.x,
15033
+ y: isBottomLayer ? -(effectiveBoardThickness + compHeight / 2) : effectiveBoardThickness / 2 + compHeight / 2,
15034
+ z: component.center.y
15035
+ },
15036
+ size: {
15037
+ x: component.width,
15038
+ y: compHeight,
15039
+ z: component.height
15040
+ },
15041
+ color: componentColor,
15042
+ label: sourceComponent?.name ?? "?",
15043
+ labelColor: "white"
15044
+ });
15045
+ }
15032
15046
  }
15033
15047
  let camera;
15034
15048
  if (pcbBoard) {
@@ -16401,7 +16415,8 @@ async function convertCircuitJsonToGltf(circuitJson, options = {}) {
16401
16415
  const scene3D = await convertCircuitJsonTo3D(circuitJson, {
16402
16416
  renderBoardTextures: true,
16403
16417
  textureResolution: boardTextureResolution,
16404
- coordinateTransform: options.coordinateTransform
16418
+ coordinateTransform: options.coordinateTransform,
16419
+ showBoundingBoxes
16405
16420
  });
16406
16421
  const gltfOptions = {
16407
16422
  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.31",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",