Add GLB and GLTF 3D Export Formats

/claim #329

Overview

This update introduces two new export formats for 3D circuit visualization:

  • GLB – Binary format
  • GLTF – JSON format

Usage

# Export to GLB
tsci export circuit.tsx -f glb
# Export to GLTF
tsci export circuit.tsx -f gltf
# Check files were created
ls -la test-circuit.glb test-circuit.gltf
file test-circuit.glb # Should show "glTF binary model"

View in 3D

Implementation

Extended existing export system in lib/shared/export-snippet.ts. GLTF uses circuit-json-to-gltf directly while GLB uses two-step conversion (GLTF to GLB) with gltf-import-export due to buffer reference issues in direct GLB output. Added both formats to ALLOWED_FORMATS and OUTPUT_EXTENSIONS.

Issues We Found and Fixed

Problem: Direct GLB export from circuit-json-to-gltf with format: "glb" created files that failed in 3D viewers with errors like:

  • “Unable to load from file: /bufferViews/3/buffer: Failed to find index (0)”
  • “Invalid JSON data. Parser output: FormatException: SyntaxError: JSON Parse error: Unrecognized token”

Root Cause: Buffer reference issues in the GLB file structure - viewers couldn’t properly parse the binary buffer sections.

Solution: Two-step process:

  1. Generate GLTF using circuit-json-to-gltf (works perfectly)
  2. Convert GLTF to GLB using gltf-import-export (creates buffer structure)
  3. Clean up temporary files

Result: GLB files now work correctly in Babylon.js Sandbox, Three.js viewers, and other 3D applications.

Dependencies

  • circuit-json-to-gltf@^0.0.6 - 3D conversion
  • gltf-import-export@^1.0.22 - GLB conversion (resolves buffer issues)

Files Changed

  • package.json - Added dependencies
  • lib/shared/export-snippet.ts - Added GLB/GLTF export cases
  • tests/cli/export/export-glb.test.ts - Tests for both formats
  • bun.lock - Lock file update

Notes

Web interface GLB export requires separate PR to @tscircuit/runframe package @seveibar

Resolves

Implements the GLB export functionality requested in issue #333. Uses circuit-json-to-gltf for GLTF generation, then converts to GLB with gltf-import-export to resolve buffer compatibility issues.

Scherm­afbeelding 2025-09-12 om 12 20 46

Claim

Total prize pool $100
Total paid $0
Status Pending
Submitted September 12, 2025
Last updated September 12, 2025

Contributors

MO

Mohamed Mathari

@nocodeventure

100%

Sponsors

TS

tscircuit

@tscircuit

$100