Embedding Models
This template can show your OpenSCAD models in the documentation — served from your own site, no external host. See Example 2 for a live one.
By default an embed is lightweight: a pre-rendered image you click to load a ~0.6 MB rotatable 3D view (no in-browser compiler). You can also offer a live customizer that compiles the model in the browser.
Add a model
-
Put the
.scadinmodels/at the repo root (e.g.models/widget.scad). -
Declare it in
openscad-publish.yml. Astaticsurface is pre-rendered; acustomizersurface is live:targets: - surface: static # lightweight, pre-rendered geometry: ./rendered/widget.off poster: ./rendered/widget.png mountPath: /models/widget/ - surface: customizer # live, in-browser compile source: ./models/widget.scad mountPath: /models/widget-live/ -
For a
staticsurface, pre-render the geometry in.github/workflows/pages.ymlwith the OpenSCAD CLI (a PNG poster needs a display, hencexvfb-run):openscad models/widget.scad -o rendered/widget.off xvfb-run -a openscad models/widget.scad -o rendered/widget.png \ --imgsize=1000,750 --viewall --autocenterThe poster deliberately uses preview mode (no
--render) — a full CGAL render discards the model’scolor()information. -
Embed it in any page:
{% include openscad.html model="widget" live="widget-live" title="Widget" %}
Multi-file models
A model that spans several files — use <…> / include <…> of siblings, or a library — publishes with projectRoot + entry instead of source:
targets:
- surface: customizer
projectRoot: ./models/assembly # everything under here becomes public
entry: ./main.scad # entry file inside projectRoot
mountPath: /models/assembly-live/
The whole tree is published and hydrated into the in-browser compiler, so relative references between project files resolve exactly as they do locally. Two rules:
- Dependencies must live inside
projectRoot. An external library goes in via a staging step inpages.yml— copy the library beside the entry (e.g.lib/) soinclude <lib/…>resolves relative to the including file. See iLOX’s workflow for a worked example (its examples depend on the tessella library). - File names must be portable — a name containing
:or\fails the publish. Spaces,#, and%are fine.
Include parameters
| Parameter | Meaning |
|---|---|
model | required — the mount name (mountPath: /models/<model>/) |
surface | static (default) · viewer · customizer — how it’s published |
live | optional mount of a live surface, for a “Customize” upgrade |
height | view height in px (default 480) |
title | accessible label (default: the model name) |
The models are assembled at deploy time by the openscad-web GitHub Action (pinned @v0), which needs v0.5+ for the static surface and v0.6+ for multi-file (projectRoot) live surfaces.