From 970cf1a20571ba4494cc78f5c9a2cb470154cf7c Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Tue, 9 Sep 2025 21:55:28 -0700 Subject: [PATCH 1/2] fix: include buffer metadata in glb output --- lib/gltf/gltf-builder.ts | 23 +++++++++++++++-------- tests/integration/circuit-to-gltf.test.ts | 14 +++++++++++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/gltf/gltf-builder.ts b/lib/gltf/gltf-builder.ts index 5b579bc..0a6918e 100644 --- a/lib/gltf/gltf-builder.ts +++ b/lib/gltf/gltf-builder.ts @@ -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 { diff --git a/tests/integration/circuit-to-gltf.test.ts b/tests/integration/circuit-to-gltf.test.ts index 81c8abe..335bd85 100644 --- a/tests/integration/circuit-to-gltf.test.ts +++ b/tests/integration/circuit-to-gltf.test.ts @@ -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 () => { From 2d5826c02d815f81d05b0d2bce313598ccc47bcd Mon Sep 17 00:00:00 2001 From: Severin Ibarluzea Date: Tue, 9 Sep 2025 22:11:55 -0700 Subject: [PATCH 2/2] fix: use node svg renderer --- lib/converters/board-renderer.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/converters/board-renderer.ts b/lib/converters/board-renderer.ts index 338d632..27021a5 100644 --- a/lib/converters/board-renderer.ts +++ b/lib/converters/board-renderer.ts @@ -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, @@ -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", @@ -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 } }