CM3D-010: Export, doc pictures and viewer: registries in Python

Accepted · 2026-11-12 · @mathisloge

Since CM3D-036 cm3d render also writes the GLB files of the 3D models in the docs, and the docs show them in a three.js viewer. The pictures and the OCP CAD Viewer of this ADR stay in effect.

Context

The former OpenSCAD runner found exports and pictures through comment lines in the model files and called OpenSCAD for each one. With build123d the same jobs can be plain Python data next to the models. CM3D-006 describes the old runner cm3d test|export|render, its tests in tests/python/ and the picture pipeline.

Decision

  • Print registry: each module declares its printable parts in prints.py as PrintJob(name, build, …​), where build returns the part in print orientation (one part per material for multi-material parts). cm3d export [pattern] finds every prints module below cm3d and writes build/stl/<name>[_<material>].stl and build/3mf/<name>.3mf, with all materials as separate bodies in one file for INDX. Job names are unique across the repository.

  • STL tessellation is set in one place (linear tolerance 0.01 mm, angular 0.1 rad), and every STL goes through the mesh check from CM3D-009: Verification: geometry tests in pytest, mesh check on every export, fit coupons.

  • Scene registry and pictures: each module declares its doc scenes in scenes.py as Scene(name, build, camera, …​). cm3d render [pattern] renders them headless with pyvista to docs/modules/ROOT/images/<module>/<name>.png at 1200 × 900 on white, with mounted parts grey and the parts of the step orange. It then fails for every image:: reference in the pages without a file. The pictures are committed, so the docs build without CAD tools.

  • Viewer: each module has a show.py that shows its parts and assembly in the OCP CAD Viewer in VS Code. ocp_vscode is a dev dependency, and no model or tool imports it at module level.

  • Bill of materials: cm3d bom writes the pages and CSV files from the bom.py modules, which are found the same way as the other registries.

  • Amendment of CM3D-006: the commands are cm3d test|export|render|mesh|bom for the build123d models, and the legacy OpenSCAD runner is removed. The unit tests of the tools are in tests/tools/ and those of the models in tests/common/ and later tests/<asm>/<module>/. The folder tests/python/ no longer exists. The rest of CM3D-006 (uv, pre-commit, commitizen, the Antora preview) stays, and pre-commit also runs cm3d bom --check.

Alternatives considered

  • Comment lines in the model files: They work for SCAD, but Python data is checked on import and can carry typed fields.

  • Naming each module in the runner: Every new module would need a change in the tools, but walking the packages with pkgutil does not.

  • STL only: It cannot carry units or several materials, but 3MF can.

  • Pictures from the viewer: They need a display and a person, but pyvista runs headless.

Consequences

  • Good: A new module needs no change in the tools. It declares jobs, scenes and a BOM and is found.

  • Good: Export and pictures run without a display or a CAD application.

  • Bad: The pyvista pictures look slightly different from the old ones (lighting), so the first render restyles every picture.