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
39 changes: 23 additions & 16 deletions lib/mesh-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,44 +327,51 @@ export async function generateComponentMeshes(
renderBoardTextures: false,
})

// Extract or generate triangles from component boxes
const allTriangles: GLTFTriangle[] = []
// Create a separate STEP solid for each component box.
// Mesh triangles from convertCircuitJsonTo3D are in local coordinates
// relative to each box center, so we translate them to world coordinates.
for (const box of scene3d.boxes) {
let boxTriangles: GLTFTriangle[]
if (box.mesh && "triangles" in box.mesh) {
allTriangles.push(...box.mesh.triangles)
const cx = box.center.x
const cy = box.center.y
const cz = box.center.z
boxTriangles = box.mesh.triangles.map((tri: GLTFTriangle) => ({
vertices: tri.vertices.map((v) => ({
x: v.x + cx,
y: v.y + cy,
z: v.z + cz,
})),
normal: tri.normal,
}))
} else {
// Generate simple box mesh for this component
const boxTriangles = createBoxTriangles(box)
allTriangles.push(...boxTriangles)
boxTriangles = createBoxTriangles(box)
}
}

// 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) => ({
if (boxTriangles.length === 0) continue

// Transform from GLTF XZ plane (Y=up) to STEP XY plane (Z=up)
const transformedTriangles = boxTriangles.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
})),
normal: {
x: tri.normal.x,
y: tri.normal.z, // GLTF Z becomes STEP Y
z: tri.normal.y, // GLTF Y becomes STEP Z
y: tri.normal.z,
z: tri.normal.y,
},
}))
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
Binary file modified test/repros/repro01/__snapshots__/repro01.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.