Skip to content

Set $preview=true for live preview and add extra args escape hatch#55

Open
CraigHutchinson wants to merge 5 commits into
thijsdaniels:mainfrom
CraigHutchinson:feature/preview-render-mode
Open

Set $preview=true for live preview and add extra args escape hatch#55
CraigHutchinson wants to merge 5 commits into
thijsdaniels:mainfrom
CraigHutchinson:feature/preview-render-mode

Conversation

@CraigHutchinson

@CraigHutchinson CraigHutchinson commented Jun 11, 2026

Copy link
Copy Markdown

OpenSCAD's $preview special variable is the idiomatic way designs self-optimise — $fn = $preview ? 12 : 72 is a common pattern to keep the live preview snappy while producing full-quality geometry on export. The problem: OpenSCAD's CLI only sets $preview=true automatically for PNG output. For geometry formats like 3MF and STL, it is always false — regardless of any render mode flag — because canPreview() in the OpenSCAD source explicitly excludes them. So every live preview rendered by this extension was silently running at full export quality on every keystroke, making previews slow and $preview-based detail switches invisible.

This PR injects -D $preview=true explicitly when rendering the live preview panel, and leaves it unset (defaulting to false) for slicer exports. That single change makes $preview work as users expect with no design changes required. A new openscad.preview setting (default true) lets users opt out if they want to see full render quality in the preview panel.

Three extraArgs settings are also added as a general escape hatch, so users can inject any additional OpenSCAD CLI flags without waiting for an extension update — useful for workarounds like this one and for enabling experimental features.

// .vscode/settings.json
"openscad.preview":          true,  // inject $preview=true for the live preview (default on)
"openscad.extraArgs":        [],    // applied to every render
"openscad.extraArgsPreview": [],    // preview only, appended after extraArgs
"openscad.extraArgsExport":  []     // slicer export only, appended after extraArgs

Closes #54.

CraigHutchinson and others added 2 commits June 11, 2026 10:16
Use OpenSCAD's native --preview / --preview=throwntogether / --render
flags instead of injecting -D $preview=..., so $preview is set correctly
by OpenSCAD itself. Live preview defaults to --preview (OpenCSG, fast);
exporting to the slicer always uses --render (full CGAL geometry).

Adds four new settings:
- openscad.previewRenderMode: choose preview (default) or throwntogether
- openscad.extraArgs: extra CLI args for every invocation
- openscad.previewExtraArgs: extra args for preview only
- openscad.renderExtraArgs: extra args for export/render only

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows users to explicitly opt back into full CGAL rendering for the
preview panel, matching the behaviour prior to this setting being added.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CraigHutchinson

Copy link
Copy Markdown
Author

as a bonus - I tested the fix and can also set --backend=manifold to ensure its using the newest backend (assuming a semi-recent nightly build of openscad)

@CraigHutchinson

CraigHutchinson commented Jun 11, 2026

Copy link
Copy Markdown
Author

I need to verify - its possible --preview doesn't work as I had expected with exporting iirc it should do though...
CONFIRMED: --preview actually only works for image exports so we just need to mirror the -D $preview=true as the native OpenSCAD editor

CraigHutchinson and others added 3 commits June 11, 2026 11:04
OpenSCAD's canPreview() only returns true for PNG — not 3MF, STL or any
other geometry format — so --preview alone never sets \$preview=true on
those formats. Pair each preview render mode flag with -D \$preview=true
so designs using \$preview for detail control behave correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
--preview/--preview=throwntogether do not set $preview=true for geometry
formats (3mf, stl, etc.) — OpenSCAD's canPreview() only allows it for
PNG. The flags also have no effect on geometry evaluation, which always
uses CGAL. The whole RenderMode enum, previewRenderMode setting, and
renderModeArgs() were complexity with no real effect.

Replace with a plain preview boolean: preview renders inject
-D \$preview=true, exports omit it (OpenSCAD defaults to false).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- openscad.preview (boolean, default true): controls whether $preview=true
  is injected for live preview renders; disable to match export quality
- Rename previewExtraArgs/renderExtraArgs to extraArgsPreview/extraArgsExport
  so all three extraArgs settings sort adjacent in the VS Code settings UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CraigHutchinson CraigHutchinson changed the title Native render mode control and per-mode extra args Set $preview=true for live preview and add extra args escape hatch Jun 11, 2026
@CraigHutchinson CraigHutchinson marked this pull request as draft June 11, 2026 10:36
@CraigHutchinson

Copy link
Copy Markdown
Author

Looks like OpenSCAD isn't playing nice with this - should have been simple - moving to DRAFT as looks like the $preview is overriden so not so simple to set for how this extension uses export for preview.

@CraigHutchinson CraigHutchinson marked this pull request as ready for review June 11, 2026 11:01
@CraigHutchinson

Copy link
Copy Markdown
Author

The issues in setting $preview have been raised as an OpenmSCAD bug: openscad/openscad#6867

The pr as it stands is still valuable to support supplying extra arguments and the upstream issue isn't necessarily a blocker for this being added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support $preview special variable

1 participant