CM3D-010: Export, doc pictures and viewer: registries in Python
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.pyasPrintJob(name, build, …), wherebuildreturns the part in print orientation (one part per material for multi-material parts).cm3d export [pattern]finds everyprintsmodule belowcm3dand writesbuild/stl/<name>[_<material>].stlandbuild/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.pyasScene(name, build, camera, …).cm3d render [pattern]renders them headless with pyvista todocs/modules/ROOT/images/<module>/<name>.pngat 1200 × 900 on white, with mounted parts grey and the parts of the step orange. It then fails for everyimage::reference in the pages without a file. The pictures are committed, so the docs build without CAD tools. -
Viewer: each module has a
show.pythat shows its parts and assembly in the OCP CAD Viewer in VS Code.ocp_vscodeis a dev dependency, and no model or tool imports it at module level. -
Bill of materials:
cm3d bomwrites the pages and CSV files from thebom.pymodules, which are found the same way as the other registries. -
Amendment of CM3D-006: the commands are
cm3d test|export|render|mesh|bomfor the build123d models, and the legacy OpenSCAD runner is removed. The unit tests of the tools are intests/tools/and those of the models intests/common/and latertests/<asm>/<module>/. The foldertests/python/no longer exists. The rest of CM3D-006 (uv, pre-commit, commitizen, the Antora preview) stays, and pre-commit also runscm3d 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
pkgutildoes 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.