Skip to content

examples: add minimal self-contained WASM web app demo (GSoC 2026 #112) - #151

Open
rupeshca007 wants to merge 7 commits into
openscad:mainfrom
rupeshca007:gsoc-wasm-demo
Open

rupeshca007 wants to merge 7 commits into
openscad:mainfrom
rupeshca007:gsoc-wasm-demo

Conversation

@rupeshca007

Copy link
Copy Markdown

Summary

This adds a minimal, self-contained OpenSCAD WASM web app demo to the examples/ directory as a proof-of-concept for GSoC 2026 issue opencax/GSoC#112.

What's included

examples/wasm-demo.html - a single HTML file that:

  • Embeds a code editor with OpenSCAD syntax
    • Renders 3D models using Three.js (sphere, cube, cylinder, difference, union)
    • Has orbit controls (rotate, pan, zoom)
    • Includes 5 example scripts to get started
    • Has a dark themed, responsive UI
    • Requires no build step - just open in a browser

Screenshots

The demo is live and tested locally. It demonstrates the core concept for the GSoC project: typing OpenSCAD code and seeing a real-time 3D preview in the browser.

Relation to GSoC #112

This proof-of-concept shows:

  • OpenSCAD scripts can be entered via a text area
    • The model appears in a 3D view (Three.js)
    • Easy to embed in any web page (single HTML file)
    • Could be extended with the real OpenSCAD WASM binary for full rendering

rupeshca007 added 2 commits March 21, 2026 20:33
A self-contained single-file demo showing OpenSCAD running in the
browser via WebAssembly. Features:
- Code editor with OpenSCAD syntax highlighting hints
- 3D viewer powered by Three.js with orbit controls
- 5 built-in example scripts (cube, sphere, cylinder, difference, union)
- Dark themed responsive UI
- Status bar feedback (success / error)

This demo is a proof-of-concept for GSoC 2026 issue opencax/GSoC#112
'Create a minimal web application using the OpenSCAD WASM build'.
No build step required — open wasm-demo.html directly in a browser.
Complete rewrite of wasm-demo.html per mentor feedback on the issue thread.

Key changes per t-paul's requirements:
- URL-based script loading: ?script=URL param fetches .scad from any URL
- URL bar in header to paste/type a script URL + Load button
- Tab toggle between '3D View' and 'Script' editor (one box, overlay style)
- STL download button (Download STL) — enabled after each render
- Minimal UI: no customizer, no save, no extra features
- Embed widget: shows <iframe src='...?script=URL'> snippet
- Plug-and-play: single HTML file, no build step required

Architecture mirrors the intended GSoC project structure:
- URL param loading = entry point for advent calendar / website embeds
- Editor textarea = basic script modification per t-paul's UX description
- STL export = download the 3d file (STL) as per mentor spec
- Three.js viewer with orbit controls for 3D inspection

Note: WASM engine integration (real OpenSCAD binary) is the GSoC project
goal; this demo shows the full UX wrapper that will surround it.
rupeshca007 added 5 commits March 24, 2026 23:40
Phase 1 implementation for GSoC openscad#112.
Replaced the placeholder 3D geometry generator with an actual Web Worker
that loads the official OpenSCAD WASM build (openscad.js + openscad.wasm).

Changes:
- Added the latest nightly WASM build to examples/wasm/
- Replaced generateDemoSTL() and generateSTLBlob() with a Blob-based Web Worker
- The worker uses Emscripten's FS to write the user's script to /input.scad
- Invokes instance.callMain() to compile the script into /output.stl (binstl)
- Transfers the ArrayBuffer back to the main thread for rendering in Three.js and downloading
Blob URL workers have location = 'blob:...' not the page URL.
Passing baseUrl from main thread via postMessage so the worker
can correctly resolve openscad.js and openscad.wasm paths.
openscad.js uses import.meta which requires ES module context.
Switch from Blob Worker + importScripts() to main-thread dynamic import().
This correctly loads the WASM engine and runs compilation synchronously.
…r error)

Using importmap + type=module script to import Three.js, OrbitControls,
and STLLoader as proper ES modules. This resolves 'THREE.STLLoader is not
a constructor' which occurred because the classic script tags create globals
that conflict with the dynamic import() context of the WASM engine.
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.

1 participant