Skip to content

Add glTF binary (.glb) export format, reusing the viewer's existing encoder #447

Description

@pzfreo

From a comparison with Casys-AI/mcp-build123d: that server exports GLTF binary alongside STEP/STL, specifically so MCP apps with embedded UI can hand the result to a three.js viewer for interactive orbit/pan/zoom inspection.

export() currently supports step, stl, 3mf, dxf, svg (src/build123d_mcp/tools/export.py). glTF/GLB is the natural web-viewer interchange format and would let users drop exported parts straight into three.js, <model-viewer>, Babylon, Blender, etc.

This is cheaper than it looks: src/build123d_mcp/viewer.py already contains a self-contained, zero-dependency glTF 2.0 binary encoder (encode_glb()) used by the live session viewer, fed by the existing tessellation path. Adding glb to _VALID_FORMATS and wiring the tessellate → encode_glb → temp-and-rename write path into export_file() should need no new dependencies.

Suggested scope:

  • export(filename, format="glb") for 3D shapes (2D shapes rejected, same as step/stl/3mf)
  • Reuse the existing tessellation quality settings the viewer uses, or expose a coarse/fine knob if trivial
  • Multi-format export (format="step,glb") should work since it goes through the same list handling

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions