openscad-playground/README.md

149 lines
6.3 KiB
Markdown
Raw Normal View History

2023-03-24 01:02:41 +00:00
# OpenSCAD Playground
2023-03-24 00:50:43 +00:00
2023-03-25 19:39:22 +00:00
[Open the Demo](https://ochafik.com/openscad2)
2023-03-24 00:50:43 +00:00
2024-12-25 12:27:19 +00:00
<a href="https://ochafik.com/openscad2" target="_blank">
<img width="694" alt="image" src="https://github.com/user-attachments/assets/58305f27-7e95-4c56-9cd7-0d766e0a21ae" />
</a>
2023-03-26 08:56:38 +01:00
2024-12-27 12:03:43 +00:00
This is a limited port of [OpenSCAD](https://openscad.org) to WebAssembly, using at its core a headless WASM build of OpenSCAD ([done by @DSchroer](https://github.com/DSchroer/openscad-wasm)), wrapped in a UI made of pretty [PrimeReact](https://github.com/primefaces/primereact) components, a [React Monaco editor](https://github.com/react-monaco-editor/react-monaco-editor) (VS Codesque power!), and an interactive [model-viewer](https://modelviewer.dev/) renderer.
It defaults to the [Manifold backend](https://github.com/openscad/openscad/pull/4533) so it's **super** fast.
2023-03-26 08:56:38 +01:00
Enjoy!
2023-03-25 19:39:22 +00:00
Licenses: see [LICENSES](./LICENSE).
2023-03-25 19:30:34 +00:00
2023-03-26 08:39:41 +01:00
## Features
2023-03-25 19:39:22 +00:00
2023-03-26 08:39:41 +01:00
- Automatic preview on edit (F5), and full rendering on Ctrl+Enter (or F6). Using a trick to force $preview=true.
2024-07-08 02:38:52 +01:00
- [Customizer](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Customizer) support
2023-03-25 19:30:34 +00:00
- Syntax highlighting
2023-03-26 08:39:41 +01:00
- Ships with many standard SCAD libraries (can browse through them in the UI)
2023-03-25 19:30:34 +00:00
- Autocomplete of imports
- Autocomplete of symbols / function calls (pseudo-parses file and its transitive imports)
- Responsive layout. On small screens editor and viewer are stacked onto each other, while on larger screens they can be side-by-side
- Installable as a PWA (then persists edits in localStorage instead of the hash fragment). On iOS just open the sharing panel and tap "Add to Home Screen". *Should not* require any internet connectivity once cached.
2023-03-25 19:30:34 +00:00
2023-03-26 08:39:41 +01:00
## Roadmap
2023-03-25 19:30:34 +00:00
- [x] Add tests!
- [x] Persist camera state
- [x] Support 2D somehow? (e.g. add option in OpenSCAD to output 2D geometry as non-closed polysets, or to auto-extrude by some height)
- [x] Proper Preview rendering: have OpenSCAD export the preview scene to a rich format (e.g. glTF, with some parts being translucent when prefixed w/ % modifier) and display it using https://modelviewer.dev/ maybe)
- ~~Rebuild w/ (and sync) ochafik@'s filtered kernel (https://github.com/openscad/openscad/pull/4160) to fix(ish) 2D operations~~
- [x] Bundle more examples (ask users to contribute)
- Animation rendering (And other formats than STL)
- [x] Compress URL fragment
- [x] Mobile (iOS) editing support: switch to https://www.npmjs.com/package/react-codemirror ?
- [x] Replace Makefile w/ something that reads the libs metadata
- [ ] Merge modifiers rendering code to openscad
2023-03-26 21:16:00 +01:00
- Model /home fs in shared state. have two clear paths: /libraries for builtins, and /home for user data. State pointing to /libraries paths needs not store the data except if there's overrides (flagged as modifications in the file picker)
2023-03-26 08:39:41 +01:00
- Drag and drop of files (SCAD, STL, etc) and Zip archives. For assets, auto insert the corresponding import.
- Fuller PWA support w/ link Sharing, File opening / association to *.scad files...
2023-03-27 23:31:21 +01:00
- Look into accessibility
2023-03-27 23:29:18 +01:00
- Setup [OPENSCADPATH](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries#Setting_OPENSCADPATH) env var w/ Emscripten to ensure examples that include assets / import local files will run fine.
- Detect which bundled libraries are included / used in the sources and only download these rather than wait for all of the zips. Means the file explorer would need to be more lazy or have some prebuilt hierarchy.
- Preparse builtin libraries definitions at compile time, ship the JSON.
2023-03-26 08:39:41 +01:00
## Building
Prerequisites:
* wget or curl
* Node.js (>=18.12.0)
* npm
* git
* zip
* Docker able to run amd64 containers (only needed if building WASM from source). If running on a different platform (including Silicon Mac), you can add support for amd64 images through QEMU with:
🌈 Colorful Playground (#37) * glb (color-assimp2 branch) + model-viewer * color support + customizable output format * cleanup * disable monaco on iOS * reinstate STL viewer when output is stl * default to stl * fix iOS editor * script to build openscad-wasm from a branch / local repo * update fork link + build instructions * Update build-openscad-wasm.sh * Update initial-state.ts * update openscad3 refs * update wasm build script * Update Dockerfile.wasm * add jszip dep * multimaterial: color conversion + 3MF face painting * ignore ts error about compression apis * Update tsconfig.json * multimaterial support w/ extruder colors input component * fix wasm build script * symlinks for openscad.{js,wasm} under src * fix error line shift for bundled files * remove obsolete build script * set OPENSCADPATH env var * render-colors feature renamed * Customizer + prepare Multi-asset support * hide customizer button if unselected, hide it if no params, * Create build-openscad-wasm.sh * update build script * complete sound * fetchSource util * wider rotation allowance * use CSG-modules.scad as default * Update CustomizerPanel.tsx * Update index.html * capture save, allow Ctrl+Shift+Save to save project * customizer: fieldsets are better than accordion * expand customizer tabs by default * tooltip for reset buttons * pretty c++ exceptions * Delete inline-openscad-worker.ts * shuffle ux * use uzip instead of jszip for 3mf materialization * handle legacy links * update links to fork * use render-modifiers feature from color-assimp2 in preview mode * include NopSCADlib's STL files in archive * bind global f5 / f6 * update homepage back to openscad2 * styling fixes (editor alpha, customizer margins) * Add help link for customizer * fix customizer sliders (also need to show value input) * fix vector customizer component * style fallback editor * shorter logs button * customizer: rm reset button tooltip * customizer: allow dnd on viewer below, tweak background * add lights to modelviewer using an env image (gltf lights hard to plug across assimp for now) * update customizer styles * Update .gitignore * add license for UZIP.js (MIT) * Update skybox-lights.jpg * Update actions.ts * include NopSCADlib's STLs * Update LICENSE.md * include YAPP_Box examples * limit customizer height * Update skybox-lights.jpg * Update skybox-lights.jpg * Update openscad-worker.ts * build-openscad-wasm.sh fix: docker won't mount files outside home directory * Use Google CDN instead of unpkg for modelviewer * tmp updates before merge * Add ccache support to build-openscad-wasm.sh * Fix makefile * Update README.md * Fix ts imports * Delete build-openscad-wasm.sh * Crude off -> glb converter * Remove assimp related code * gltf diffs * Build using head openscad * readme: Update build prerequisites * make: attempt to build wasm binary in parallel first * Remove 3mf extruder color mapping & fix render / export flows (render all 3d to off) * off2glb: triangulate faces + add default color * Add simple e2e puppeteer test * ci: update pinned build to master output artefact * Update Makefile * Update test.yml * Update test.yml * Update test.yml * Update test.yml * ci: use relative node version names * Update test.yml * state: Remove renderFormat, introduce is2D * disable service worker in devel mode * remove dead code * build: fix NODE_ENV define * ci: simplify env vars * cleanups * Update README.md
2024-12-22 22:41:35 +00:00
```bash
docker run --privileged --rm tonistiigi/binfmt --install all
```
2023-03-25 19:30:34 +00:00
Local dev:
2023-03-25 19:30:34 +00:00
```bash
npm run build:libs # Download WASM and build all OpenSCAD libraries
🌈 Colorful Playground (#37) * glb (color-assimp2 branch) + model-viewer * color support + customizable output format * cleanup * disable monaco on iOS * reinstate STL viewer when output is stl * default to stl * fix iOS editor * script to build openscad-wasm from a branch / local repo * update fork link + build instructions * Update build-openscad-wasm.sh * Update initial-state.ts * update openscad3 refs * update wasm build script * Update Dockerfile.wasm * add jszip dep * multimaterial: color conversion + 3MF face painting * ignore ts error about compression apis * Update tsconfig.json * multimaterial support w/ extruder colors input component * fix wasm build script * symlinks for openscad.{js,wasm} under src * fix error line shift for bundled files * remove obsolete build script * set OPENSCADPATH env var * render-colors feature renamed * Customizer + prepare Multi-asset support * hide customizer button if unselected, hide it if no params, * Create build-openscad-wasm.sh * update build script * complete sound * fetchSource util * wider rotation allowance * use CSG-modules.scad as default * Update CustomizerPanel.tsx * Update index.html * capture save, allow Ctrl+Shift+Save to save project * customizer: fieldsets are better than accordion * expand customizer tabs by default * tooltip for reset buttons * pretty c++ exceptions * Delete inline-openscad-worker.ts * shuffle ux * use uzip instead of jszip for 3mf materialization * handle legacy links * update links to fork * use render-modifiers feature from color-assimp2 in preview mode * include NopSCADlib's STL files in archive * bind global f5 / f6 * update homepage back to openscad2 * styling fixes (editor alpha, customizer margins) * Add help link for customizer * fix customizer sliders (also need to show value input) * fix vector customizer component * style fallback editor * shorter logs button * customizer: rm reset button tooltip * customizer: allow dnd on viewer below, tweak background * add lights to modelviewer using an env image (gltf lights hard to plug across assimp for now) * update customizer styles * Update .gitignore * add license for UZIP.js (MIT) * Update skybox-lights.jpg * Update actions.ts * include NopSCADlib's STLs * Update LICENSE.md * include YAPP_Box examples * limit customizer height * Update skybox-lights.jpg * Update skybox-lights.jpg * Update openscad-worker.ts * build-openscad-wasm.sh fix: docker won't mount files outside home directory * Use Google CDN instead of unpkg for modelviewer * tmp updates before merge * Add ccache support to build-openscad-wasm.sh * Fix makefile * Update README.md * Fix ts imports * Delete build-openscad-wasm.sh * Crude off -> glb converter * Remove assimp related code * gltf diffs * Build using head openscad * readme: Update build prerequisites * make: attempt to build wasm binary in parallel first * Remove 3mf extruder color mapping & fix render / export flows (render all 3d to off) * off2glb: triangulate faces + add default color * Add simple e2e puppeteer test * ci: update pinned build to master output artefact * Update Makefile * Update test.yml * Update test.yml * Update test.yml * Update test.yml * ci: use relative node version names * Update test.yml * state: Remove renderFormat, introduce is2D * disable service worker in devel mode * remove dead code * build: fix NODE_ENV define * ci: simplify env vars * cleanups * Update README.md
2024-12-22 22:41:35 +00:00
npm install
npm run start
2023-03-25 19:30:34 +00:00
# http://localhost:4000/
```
2023-03-25 19:34:07 +00:00
Local prod (test both the different inlining and serving under a prefix):
```bash
npm run build:libs # Download WASM and build all OpenSCAD libraries
🌈 Colorful Playground (#37) * glb (color-assimp2 branch) + model-viewer * color support + customizable output format * cleanup * disable monaco on iOS * reinstate STL viewer when output is stl * default to stl * fix iOS editor * script to build openscad-wasm from a branch / local repo * update fork link + build instructions * Update build-openscad-wasm.sh * Update initial-state.ts * update openscad3 refs * update wasm build script * Update Dockerfile.wasm * add jszip dep * multimaterial: color conversion + 3MF face painting * ignore ts error about compression apis * Update tsconfig.json * multimaterial support w/ extruder colors input component * fix wasm build script * symlinks for openscad.{js,wasm} under src * fix error line shift for bundled files * remove obsolete build script * set OPENSCADPATH env var * render-colors feature renamed * Customizer + prepare Multi-asset support * hide customizer button if unselected, hide it if no params, * Create build-openscad-wasm.sh * update build script * complete sound * fetchSource util * wider rotation allowance * use CSG-modules.scad as default * Update CustomizerPanel.tsx * Update index.html * capture save, allow Ctrl+Shift+Save to save project * customizer: fieldsets are better than accordion * expand customizer tabs by default * tooltip for reset buttons * pretty c++ exceptions * Delete inline-openscad-worker.ts * shuffle ux * use uzip instead of jszip for 3mf materialization * handle legacy links * update links to fork * use render-modifiers feature from color-assimp2 in preview mode * include NopSCADlib's STL files in archive * bind global f5 / f6 * update homepage back to openscad2 * styling fixes (editor alpha, customizer margins) * Add help link for customizer * fix customizer sliders (also need to show value input) * fix vector customizer component * style fallback editor * shorter logs button * customizer: rm reset button tooltip * customizer: allow dnd on viewer below, tweak background * add lights to modelviewer using an env image (gltf lights hard to plug across assimp for now) * update customizer styles * Update .gitignore * add license for UZIP.js (MIT) * Update skybox-lights.jpg * Update actions.ts * include NopSCADlib's STLs * Update LICENSE.md * include YAPP_Box examples * limit customizer height * Update skybox-lights.jpg * Update skybox-lights.jpg * Update openscad-worker.ts * build-openscad-wasm.sh fix: docker won't mount files outside home directory * Use Google CDN instead of unpkg for modelviewer * tmp updates before merge * Add ccache support to build-openscad-wasm.sh * Fix makefile * Update README.md * Fix ts imports * Delete build-openscad-wasm.sh * Crude off -> glb converter * Remove assimp related code * gltf diffs * Build using head openscad * readme: Update build prerequisites * make: attempt to build wasm binary in parallel first * Remove 3mf extruder color mapping & fix render / export flows (render all 3d to off) * off2glb: triangulate faces + add default color * Add simple e2e puppeteer test * ci: update pinned build to master output artefact * Update Makefile * Update test.yml * Update test.yml * Update test.yml * Update test.yml * ci: use relative node version names * Update test.yml * state: Remove renderFormat, introduce is2D * disable service worker in devel mode * remove dead code * build: fix NODE_ENV define * ci: simplify env vars * cleanups * Update README.md
2024-12-22 22:41:35 +00:00
npm install
npm run start:production
2023-03-25 19:30:34 +00:00
# http://localhost:3000/dist/
2023-03-27 10:30:29 -04:00
```
2023-03-25 19:30:34 +00:00
Deployment (edit "homepage" in `package.json` to match your deployment root!):
```bash
npm run build:all # Build libraries and compile the application
🌈 Colorful Playground (#37) * glb (color-assimp2 branch) + model-viewer * color support + customizable output format * cleanup * disable monaco on iOS * reinstate STL viewer when output is stl * default to stl * fix iOS editor * script to build openscad-wasm from a branch / local repo * update fork link + build instructions * Update build-openscad-wasm.sh * Update initial-state.ts * update openscad3 refs * update wasm build script * Update Dockerfile.wasm * add jszip dep * multimaterial: color conversion + 3MF face painting * ignore ts error about compression apis * Update tsconfig.json * multimaterial support w/ extruder colors input component * fix wasm build script * symlinks for openscad.{js,wasm} under src * fix error line shift for bundled files * remove obsolete build script * set OPENSCADPATH env var * render-colors feature renamed * Customizer + prepare Multi-asset support * hide customizer button if unselected, hide it if no params, * Create build-openscad-wasm.sh * update build script * complete sound * fetchSource util * wider rotation allowance * use CSG-modules.scad as default * Update CustomizerPanel.tsx * Update index.html * capture save, allow Ctrl+Shift+Save to save project * customizer: fieldsets are better than accordion * expand customizer tabs by default * tooltip for reset buttons * pretty c++ exceptions * Delete inline-openscad-worker.ts * shuffle ux * use uzip instead of jszip for 3mf materialization * handle legacy links * update links to fork * use render-modifiers feature from color-assimp2 in preview mode * include NopSCADlib's STL files in archive * bind global f5 / f6 * update homepage back to openscad2 * styling fixes (editor alpha, customizer margins) * Add help link for customizer * fix customizer sliders (also need to show value input) * fix vector customizer component * style fallback editor * shorter logs button * customizer: rm reset button tooltip * customizer: allow dnd on viewer below, tweak background * add lights to modelviewer using an env image (gltf lights hard to plug across assimp for now) * update customizer styles * Update .gitignore * add license for UZIP.js (MIT) * Update skybox-lights.jpg * Update actions.ts * include NopSCADlib's STLs * Update LICENSE.md * include YAPP_Box examples * limit customizer height * Update skybox-lights.jpg * Update skybox-lights.jpg * Update openscad-worker.ts * build-openscad-wasm.sh fix: docker won't mount files outside home directory * Use Google CDN instead of unpkg for modelviewer * tmp updates before merge * Add ccache support to build-openscad-wasm.sh * Fix makefile * Update README.md * Fix ts imports * Delete build-openscad-wasm.sh * Crude off -> glb converter * Remove assimp related code * gltf diffs * Build using head openscad * readme: Update build prerequisites * make: attempt to build wasm binary in parallel first * Remove 3mf extruder color mapping & fix render / export flows (render all 3d to off) * off2glb: triangulate faces + add default color * Add simple e2e puppeteer test * ci: update pinned build to master output artefact * Update Makefile * Update test.yml * Update test.yml * Update test.yml * Update test.yml * ci: use relative node version names * Update test.yml * state: Remove renderFormat, introduce is2D * disable service worker in devel mode * remove dead code * build: fix NODE_ENV define * ci: simplify env vars * cleanups * Update README.md
2024-12-22 22:41:35 +00:00
npm install
2023-03-25 19:30:34 +00:00
rm -fR ../ochafik.github.io/openscad2 && cp -R dist ../ochafik.github.io/openscad2
# Now commit and push changes, wait for site update and enjoy!
```
## Build your own WASM binary
[Makefile](./Makefile) fetches a prebuilt OpenSCAD web WASM binary, but you can build your own in a couple of minutes:
- **Optional**: use your own openscad fork / branch:
```bash
rm -fR libs/openscad
ln -s $PWD/../absolute/path/to/your/openscad libs/openscad
# If you had a native build directory, delete it.
rm -fR libs/openscad/build
```
- Build WASM binary (add `WASM_BUILD=Debug` argument if you'd like to debug any cryptic crashes):
```bash
npm run build:libs:wasm
```
- Then continue the build:
```bash
npm run build:libs
npm run start
```
## Adding OpenSCAD libraries
You'll need to update 3 files (search for BOSL2 for an example):
- [libs-config.json](./libs-config.json): to add the library's metadata including repository URL, branch, and files to include/exclude in the zip archive
- [src/fs/zip-archives.ts](./src/fs/zip-archives.ts): to use the `.zip` archive in the UI (both for file explorer and automatic imports mounting)
- [LICENSE.md](./LICENSE.md): most libraries require proper disclosure of their usage and of their license. If a license is unique, paste it in full, otherwise, link to one of the standard ones already there.
### Library Configuration Format
In `libs-config.json`, add an entry like this:
```json
{
"name": "LibraryName",
"repo": "https://github.com/user/repo.git",
"branch": "main",
"zipIncludes": ["*.scad", "LICENSE", "examples"],
"zipExcludes": ["**/tests/**"],
"workingDir": "."
}
```
Available build commands:
- `npm run build:libs` - Build all libraries
- `npm run build:libs:clean` - Clean all build artifacts
- `npm run build:libs:wasm` - Download/build just the WASM binary
- `npm run build:libs:fonts` - Download/build just the fonts
Send us a PR, then once it's merged request an update to the hosted https://ochafik.com/openscad2 demo.