circuit-json-to-gltf 0.0.24 → 0.0.26
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.js +85 -3
- package/package.json +2 -2
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);
|
|
@@ -14683,11 +14715,53 @@ var createHoleGeoms = (boardCenter, thickness, holes = [], platedHoles = []) =>
|
|
|
14683
14715
|
const holeGeoms = [];
|
|
14684
14716
|
for (const hole of holes) {
|
|
14685
14717
|
const holeRecord = hole;
|
|
14718
|
+
const relX = hole.x - boardCenter.x;
|
|
14719
|
+
const relY = -(hole.y - boardCenter.y);
|
|
14720
|
+
const holeShape = holeRecord.hole_shape;
|
|
14721
|
+
if (holeShape === "pill") {
|
|
14722
|
+
const holeWidth = getNumberProperty(holeRecord, "hole_width");
|
|
14723
|
+
const holeHeight = getNumberProperty(holeRecord, "hole_height");
|
|
14724
|
+
if (!holeWidth || !holeHeight) continue;
|
|
14725
|
+
const rotate = holeHeight > holeWidth;
|
|
14726
|
+
const width = rotate ? holeHeight : holeWidth;
|
|
14727
|
+
const height = rotate ? holeWidth : holeHeight;
|
|
14728
|
+
const pillHole = createPillHole(
|
|
14729
|
+
relX,
|
|
14730
|
+
relY,
|
|
14731
|
+
width,
|
|
14732
|
+
height,
|
|
14733
|
+
thickness,
|
|
14734
|
+
rotate
|
|
14735
|
+
);
|
|
14736
|
+
holeGeoms.push(pillHole);
|
|
14737
|
+
continue;
|
|
14738
|
+
}
|
|
14739
|
+
if (holeShape === "rotated_pill") {
|
|
14740
|
+
const holeWidth = getNumberProperty(holeRecord, "hole_width");
|
|
14741
|
+
const holeHeight = getNumberProperty(holeRecord, "hole_height");
|
|
14742
|
+
if (!holeWidth || !holeHeight) continue;
|
|
14743
|
+
const rotation = getNumberProperty(holeRecord, "ccw_rotation") ?? 0;
|
|
14744
|
+
const rotationRad = -(rotation * Math.PI) / 180;
|
|
14745
|
+
const minDimension = Math.min(holeWidth, holeHeight);
|
|
14746
|
+
const maxAllowedRadius = Math.max(0, minDimension / 2 - RADIUS_EPSILON);
|
|
14747
|
+
const roundRadius = maxAllowedRadius <= 0 ? 0 : Math.min(holeHeight / 2, maxAllowedRadius);
|
|
14748
|
+
const hole2d = (0, import_primitives.roundedRectangle)({
|
|
14749
|
+
size: [holeWidth, holeHeight],
|
|
14750
|
+
roundRadius,
|
|
14751
|
+
segments: DEFAULT_SEGMENTS
|
|
14752
|
+
});
|
|
14753
|
+
let hole3d = (0, import_extrusions.extrudeLinear)({ height: thickness + 1 }, hole2d);
|
|
14754
|
+
hole3d = (0, import_transforms.translate)([0, 0, -(thickness + 1) / 2], hole3d);
|
|
14755
|
+
if (rotationRad !== 0) {
|
|
14756
|
+
hole3d = (0, import_transforms.rotateZ)(rotationRad, hole3d);
|
|
14757
|
+
}
|
|
14758
|
+
hole3d = (0, import_transforms.translate)([relX, relY, 0], hole3d);
|
|
14759
|
+
holeGeoms.push(hole3d);
|
|
14760
|
+
continue;
|
|
14761
|
+
}
|
|
14686
14762
|
const diameter = getNumberProperty(holeRecord, "hole_diameter") ?? getNumberProperty(holeRecord, "diameter");
|
|
14687
14763
|
if (!diameter) continue;
|
|
14688
14764
|
const radius = diameter / 2;
|
|
14689
|
-
const relX = hole.x - boardCenter.x;
|
|
14690
|
-
const relY = -(hole.y - boardCenter.y);
|
|
14691
14765
|
holeGeoms.push(createCircularHole(relX, relY, radius, thickness));
|
|
14692
14766
|
}
|
|
14693
14767
|
for (const plated of platedHoles) {
|
|
@@ -14860,7 +14934,12 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
|
|
|
14860
14934
|
pcbComponentIdsWith3D.add(cad.pcb_component_id);
|
|
14861
14935
|
const pcbComponent = db.pcb_component.get(cad.pcb_component_id);
|
|
14862
14936
|
const isBottomLayer = pcbComponent?.layer === "bottom";
|
|
14863
|
-
const
|
|
14937
|
+
const modelScaleFactor = cad.model_unit_to_mm_scale_factor ?? 1;
|
|
14938
|
+
const size = cad.size ? {
|
|
14939
|
+
x: cad.size.x * modelScaleFactor,
|
|
14940
|
+
y: cad.size.y * modelScaleFactor,
|
|
14941
|
+
z: cad.size.z * modelScaleFactor
|
|
14942
|
+
} : {
|
|
14864
14943
|
x: pcbComponent?.width ?? 2,
|
|
14865
14944
|
y: defaultComponentHeight,
|
|
14866
14945
|
z: pcbComponent?.height ?? 2
|
|
@@ -14930,6 +15009,9 @@ async function convertCircuitJsonTo3D(circuitJson, options = {}) {
|
|
|
14930
15009
|
defaultTransform
|
|
14931
15010
|
);
|
|
14932
15011
|
}
|
|
15012
|
+
if (box.mesh && modelScaleFactor !== 1) {
|
|
15013
|
+
box.mesh = scaleMesh(box.mesh, modelScaleFactor);
|
|
15014
|
+
}
|
|
14933
15015
|
if (!box.mesh) {
|
|
14934
15016
|
box.color = componentColor;
|
|
14935
15017
|
}
|
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.
|
|
5
|
+
"version": "0.0.26",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "bun test tests/",
|
|
8
8
|
"format": "biome format --write .",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@vitejs/plugin-react": "^5.0.0",
|
|
32
32
|
"bun-match-svg": "^0.0.12",
|
|
33
33
|
"circuit-json": "^0.0.278",
|
|
34
|
-
"circuit-to-svg": "^0.0.
|
|
34
|
+
"circuit-to-svg": "^0.0.240",
|
|
35
35
|
"graphics-debug": "^0.0.65",
|
|
36
36
|
"looks-same": "^9.0.1",
|
|
37
37
|
"poppygl": "^0.0.16",
|