Skip to content

Commit 6cbd86b

Browse files
authored
Fix Automatic Model Origin (#146)
* commit repros * fix model origin realignment * fix types
1 parent 3527df7 commit 6cbd86b

8 files changed

Lines changed: 49 additions & 15 deletions

File tree

lib/utils/cad-mesh-placement.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,7 @@ export function getMeshOrigin(
7777
return origin
7878
}
7979

80-
switch (cad.model_origin_alignment) {
81-
case "center":
82-
return getBoundingBoxCenter(meshBounds)
83-
case "center_of_component_on_board_surface":
84-
return {
85-
x: (meshBounds.min.x + meshBounds.max.x) / 2,
86-
y: meshBounds.min.y,
87-
z: (meshBounds.min.z + meshBounds.max.z) / 2,
88-
}
89-
default:
90-
return null
91-
}
80+
return { x: 0, y: 0, z: 0 }
9281
}
9382

9483
export function fitMeshToCadBounds<T extends STLMesh | OBJMesh>(

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@resvg/resvg-js": "^2.6.2",
3131
"@resvg/resvg-wasm": "^2.6.2",
3232
"@tscircuit/alphabet": "^0.0.8",
33-
"@tscircuit/circuit-json-util": "^0.0.72",
33+
"@tscircuit/circuit-json-util": "^0.0.90",
3434
"@types/bun": "latest",
3535
"@types/earcut": "^3.0.0",
3636
"@types/react": "^19.1.9",
@@ -46,7 +46,7 @@
4646
"react-cosmos": "^7.0.0",
4747
"react-cosmos-plugin-vite": "^7.0.0",
4848
"react-dom": "^19.1.1",
49-
"tscircuit": "^0.0.1328",
49+
"tscircuit": "^0.0.1520",
5050
"tsup": "^8.5.0",
5151
"vite": "^7.1.1"
5252
},
-1.15 KB
Loading
4.61 KB
Loading

tests/repro/repro7.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test("repro7: local CAD model should be included in GLTF output", async () => {
1010
<board width="40mm" height="40mm">
1111
<chip
1212
name="U1"
13-
footprint="soic8"
13+
footprint="pinrow1"
1414
cadModel={
1515
<cadassembly>
1616
<cadmodel modelUrl="tests/assets/ExampleModelPin.step" />
-12 Bytes
Loading
-9.54 KB
Loading
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { expect, test } from "bun:test"
2+
import { getMeshOrigin } from "../../lib/utils/cad-mesh-placement"
3+
4+
test("getMeshOrigin ignores inferred alignment without explicit origin position", () => {
5+
const origin = getMeshOrigin(
6+
{
7+
type: "cad_component",
8+
cad_component_id: "cad1",
9+
pcb_component_id: "pcb1",
10+
source_component_id: "source1",
11+
position: { x: 0, y: 0, z: 0 },
12+
model_object_fit: "contain_within_bounds",
13+
anchor_alignment: "center",
14+
model_origin_alignment: "center_of_component_on_board_surface",
15+
},
16+
{
17+
min: { x: -2, y: -3, z: -4 },
18+
max: { x: 6, y: 7, z: 8 },
19+
},
20+
)
21+
22+
expect(origin).toEqual({ x: 0, y: 0, z: 0 })
23+
})
24+
25+
test("getMeshOrigin returns explicit model origin position", () => {
26+
const origin = getMeshOrigin(
27+
{
28+
type: "cad_component",
29+
cad_component_id: "cad1",
30+
pcb_component_id: "pcb1",
31+
source_component_id: "source1",
32+
position: { x: 0, y: 0, z: 0 },
33+
model_object_fit: "contain_within_bounds",
34+
anchor_alignment: "center",
35+
model_origin_alignment: "center_of_component_on_board_surface",
36+
model_origin_position: { x: 1, y: 2, z: 3 },
37+
},
38+
{
39+
min: { x: -2, y: -3, z: -4 },
40+
max: { x: 6, y: 7, z: 8 },
41+
},
42+
)
43+
44+
expect(origin).toEqual({ x: 1, y: 2, z: 3 })
45+
})

0 commit comments

Comments
 (0)