CM3D-036: Interactive 3D models in the docs, from committed GLB files

Accepted · 2026-11-21 · @mathisloge

Context

CM3D-010 gives the docs PNG pictures and gives the work the OCP CAD Viewer in VS Code. A picture shows one view, so a reader of the docs cannot turn the machine and look at the planning state from all sides. CM3D-014 gives every shape a bd_materials material, and build123d can write these materials as PBR materials into glTF. The docs build on GitHub Pages from main and need no CAD tools, and this must stay so. The show front lives from its light (CM3D-030), so a model without glow shows the wrong machine.

Decision Drivers

  • Turn it yourself: a reader turns the whole machine and each module in the browser, without an install.

  • The docs build stays simple: the docs build without Python, build123d or OCP.

  • Small and stable files: each model loads fast, and a model that did not change does not change in git.

  • The light shows: the light lines and the show columns glow, and a light pulse runs along the light lines.

  • One source for the looks: the docs viewer shows the materials of the model and keeps no own list of parts.

Quality Goals

  • QG-05: the model shows the lit show front in a dark room, as a Guest sees it.

Decision

cm3d render also writes a GLB file for every Model that a module declares as MODELS in its models.py, to docs/modules/ROOT/attachments/models/<folder>/<name>.glb. The export (cm3d.tools.gltf) merges equal materials, stores a repeated mesh once, quantizes the positions and normals (KHR_mesh_quantization) and sorts the data, so the file is byte-identical for the same model. A test keeps every model under 1 MB. The GLB files are committed, and the large-file hook of pre-commit leaves their folder out. cm3d render fails for a page that embeds a model without a GLB file.

The viewer is an Antora attachment, docs/modules/ROOT/attachments/viewer/, with three.js 0.187.0 from jsDelivr. A page embeds it with an iframe as _attachments/viewer/index.html?model=<folder>/<name>. The viewer shows the materials from the file and changes none of them. It makes one switch for each group under the root node, and a group with extras.hidden starts hidden. The only name it knows is the prefix light_line: a node with this prefix carries its path in its extras, and the viewer runs a light pulse along it.

The materials come from bd_materials through cm3d.common.materials, as CM3D-014 decides. The parts that give light get emissive materials in the UI colours of the Station. This is on purpose: CM3D-014 asks for colours that a filament can print, and light is no filament. A see-through part is alpha-blended, because three.js leaves a transparent object out of its transmission pass, and only the glass in the niche transmits. A part that is only an envelope shows as a neutral grey placeholder.

Alternatives Considered

A custom element in the docs UI

A <cm3d-viewer> element that the Antora UI loads on every page.

Rejected: it fits in best, but it needs a change of the UI bundle in cocktail-maker, which is harder to test.

Google model-viewer

The <model-viewer> element shows a GLB file with almost no own code.

Rejected: it has no glow, and the light pulse would need own code anyway.

GLB files from the docs build

The docs build runs cm3d render and does not commit the files.

Rejected: the docs build would need Python, build123d and OCP, and a model change would not show in a review.

The GLB files of build123d as they are

export_gltf of build123d writes a file without our rewrite.

Rejected: the machine model was 5.2 MB, and the bytes changed from run to run.

Consequences

  • Good: a reader turns the machine and each module in the docs, also on a phone, and sees the light in a dark room.

  • Good: a new model needs only a models.py and an iframe, and the viewer needs no change.

  • Bad: the repository grows by the GLB files, about 2 MB now, and by each changed model.

  • Bad: the viewer loads three.js from jsDelivr, so it shows nothing without internet or when jsDelivr is down.

  • Bad: the export uses private helpers of build123d (_create_xde, inject_materials), so an update of build123d can break it.