circuit-json-to-gltf 0.0.24 → 0.0.25

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.
Files changed (2) hide show
  1. package/dist/index.js +41 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14614,6 +14614,38 @@ async function renderBoardTextures(circuitJson, resolution = 1024) {
14614
14614
  return { top, bottom };
14615
14615
  }
14616
14616
 
14617
+ // lib/utils/mesh-scale.ts
14618
+ function scalePoint(point, scale) {
14619
+ return {
14620
+ x: point.x * scale,
14621
+ y: point.y * scale,
14622
+ z: point.z * scale
14623
+ };
14624
+ }
14625
+ function scaleTriangle(triangle, scale) {
14626
+ return {
14627
+ ...triangle,
14628
+ vertices: triangle.vertices.map((vertex) => scalePoint(vertex, scale))
14629
+ };
14630
+ }
14631
+ function scaleMesh(mesh, scale) {
14632
+ if (!Number.isFinite(scale) || scale === 1) {
14633
+ return mesh;
14634
+ }
14635
+ const scaledTriangles = mesh.triangles.map(
14636
+ (triangle) => scaleTriangle(triangle, scale)
14637
+ );
14638
+ const scaledBoundingBox = {
14639
+ min: scalePoint(mesh.boundingBox.min, scale),
14640
+ max: scalePoint(mesh.boundingBox.max, scale)
14641
+ };
14642
+ return {
14643
+ ...mesh,
14644
+ triangles: scaledTriangles,
14645
+ boundingBox: scaledBoundingBox
14646
+ };
14647
+ }
14648
+
14617
14649
  // lib/utils/pcb-board-geometry.ts
14618
14650
  var import_extrusions = __toESM(require_extrusions(), 1);
14619
14651
  var import_primitives = __toESM(require_primitives(), 1);
@@ -14860,7 +14892,12 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14860
14892
  pcbComponentIdsWith3D.add(cad.pcb_component_id);
14861
14893
  const pcbComponent = db.pcb_component.get(cad.pcb_component_id);
14862
14894
  const isBottomLayer = pcbComponent?.layer === "bottom";
14863
- const size = cad.size ?? {
14895
+ const modelScaleFactor = cad.model_unit_to_mm_scale_factor ?? 1;
14896
+ const size = cad.size ? {
14897
+ x: cad.size.x * modelScaleFactor,
14898
+ y: cad.size.y * modelScaleFactor,
14899
+ z: cad.size.z * modelScaleFactor
14900
+ } : {
14864
14901
  x: pcbComponent?.width ?? 2,
14865
14902
  y: defaultComponentHeight,
14866
14903
  z: pcbComponent?.height ?? 2
@@ -14930,6 +14967,9 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
14930
14967
  defaultTransform
14931
14968
  );
14932
14969
  }
14970
+ if (box.mesh && modelScaleFactor !== 1) {
14971
+ box.mesh = scaleMesh(box.mesh, modelScaleFactor);
14972
+ }
14933
14973
  if (!box.mesh) {
14934
14974
  box.color = componentColor;
14935
14975
  }
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.24",
5
+ "version": "0.0.25",
6
6
  "scripts": {
7
7
  "test": "bun test tests/",
8
8
  "format": "biome format --write .",