Skip to content
Draft
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
12 changes: 2 additions & 10 deletions lib/converters/board-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ async function convertSvgToPng(
// Browser: Use Canvas API (works better for complex SVGs)
return convertSvgToCanvasBrowser(svgString, resolution, backgroundColor)
} else {
// Node.js/Bun: Use WASM for high-quality rendering
const { svgToPngDataUrl } = await import("../utils/svg-to-png-browser")
// Node.js/Bun: Use JS implementation for stability
const { svgToPngDataUrl } = await import("../utils/svg-to-png")
return await svgToPngDataUrl(svgString, {
width: resolution,
background: backgroundColor,
Expand Down Expand Up @@ -109,8 +109,6 @@ export async function renderBoardTextures(
top: string
bottom: string
}> {
console.log("Generating PCB texture...")

const [top, bottom] = await Promise.all([
renderBoardLayer(circuitJson, {
layer: "top",
Expand All @@ -123,11 +121,5 @@ export async function renderBoardTextures(
backgroundColor: "#006600", // Darker green for bottom layer
}),
])

console.log("PCB texture generated:", {
topLength: top.length,
bottomLength: bottom.length,
})

return { top, bottom }
}
23 changes: 15 additions & 8 deletions lib/gltf/gltf-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,20 +674,27 @@ export class GLTFBuilder {
const bufferData = this.bufferBuilder.getBuffer()

if (binary) {
// Create GLB
return this.createGLB(this.gltf, bufferData)
} else {
// Create GLTF with embedded buffer
// Include buffer reference for GLB
this.gltf.buffers = [
{
byteLength: bufferData.byteLength,
uri: `data:application/octet-stream;base64,${this.arrayBufferToBase64(
bufferData,
)}`,
},
]
return this.gltf

// Create GLB
return this.createGLB(this.gltf, bufferData)
}

// Create GLTF with embedded buffer
this.gltf.buffers = [
{
byteLength: bufferData.byteLength,
uri: `data:application/octet-stream;base64,${this.arrayBufferToBase64(
bufferData,
)}`,
},
]
return this.gltf
}

private createGLB(gltf: GLTF, bufferData: ArrayBuffer): ArrayBuffer {
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/circuit-to-gltf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ test("convertCircuitJsonToGltf should convert circuit to GLB", async () => {

// GLB format returns an ArrayBuffer
expect(result).toBeInstanceOf(ArrayBuffer)
expect((result as ArrayBuffer).byteLength).toBeGreaterThan(0)
const arrayBuffer = result as ArrayBuffer
expect(arrayBuffer.byteLength).toBeGreaterThan(0)

// Parse JSON chunk to ensure buffer reference exists
const view = new DataView(arrayBuffer)
const jsonChunkLength = view.getUint32(12, true)
const jsonBytes = new Uint8Array(arrayBuffer, 20, jsonChunkLength)
const jsonText = new TextDecoder().decode(jsonBytes).replace(/\u0000+$/, "")
const gltf = JSON.parse(jsonText)

expect(Array.isArray(gltf.buffers)).toBe(true)
expect(gltf.buffers.length).toBe(1)
expect(gltf.buffers[0].byteLength).toBeGreaterThan(0)
})

test("convertCircuitJsonTo3D should create 3D scene", async () => {
Expand Down
Loading