Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions lib/mesh-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,44 +327,44 @@ export async function generateComponentMeshes(
renderBoardTextures: false,
})

// Extract or generate triangles from component boxes
const allTriangles: GLTFTriangle[] = []
// Create one ManifoldSolidBrep per component box so each box forms a valid
// closed manifold surface. A ClosedShell requires a single connected closed
// surface — merging all boxes into one ClosedShell produces invalid STEP
// topology that viewers silently discard.
for (const box of scene3d.boxes) {
if (box.mesh && "triangles" in box.mesh) {
allTriangles.push(...box.mesh.triangles)
} else {
// Generate simple box mesh for this component
const boxTriangles = createBoxTriangles(box)
allTriangles.push(...boxTriangles)
}
}
const boxTriangles =
box.mesh && "triangles" in box.mesh
? box.mesh.triangles
: createBoxTriangles(box)

if (boxTriangles.length === 0) continue

// Create STEP faces from triangles if we have any
if (allTriangles.length > 0) {
// Transform triangles from GLTF XZ plane (Y=up) to STEP XY plane (Z=up)
const transformedTriangles = allTriangles.map((tri) => ({
vertices: tri.vertices.map((v) => ({
x: v.x,
y: v.z, // GLTF Z becomes STEP Y
z: v.y, // GLTF Y becomes STEP Z
})),
const transformedTriangles = boxTriangles.map((tri: GLTFTriangle) => ({
vertices: tri.vertices.map(
(v: { x: number; y: number; z: number }) => ({
x: v.x,
y: v.z, // GLTF Z becomes STEP Y
z: v.y, // GLTF Y becomes STEP Z
}),
),
normal: {
x: tri.normal.x,
y: tri.normal.z, // GLTF Z becomes STEP Y
z: tri.normal.y, // GLTF Y becomes STEP Z
},
}))

const componentFaces = createStepFacesFromTriangles(
repo,
transformedTriangles as any,
)

// Create closed shell and solid for components
const componentShell = repo.add(
new ClosedShell("", componentFaces as any),
)
const componentSolid = repo.add(
new ManifoldSolidBrep("Components", componentShell),
new ManifoldSolidBrep("Component", componentShell),
)
solids.push(componentSolid)
}
Expand Down
6 changes: 4 additions & 2 deletions test/basics/basics04/basics04.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ test("basics04: convert circuit json with components to STEP", async () => {
expect(stepText).toContain("CIRCLE")
expect(stepText).toContain("CYLINDRICAL_SURFACE")

// Verify we have multiple solids (board + components)
// Verify we have one solid per element: 1 board + 2 component boxes = 3 total.
// Each component box must be its own ManifoldSolidBrep (issue #6: merging all
// boxes into a single ClosedShell creates invalid STEP topology that viewers discard).
const solidCount = (stepText.match(/MANIFOLD_SOLID_BREP/g) || []).length
expect(solidCount).toBeGreaterThanOrEqual(1)
expect(solidCount).toBe(3)

// Write STEP file to debug-output
const outputPath = "debug-output/basics04.step"
Expand Down
Loading