jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.69k stars 517 forks source link

Move render to worker and use offscreen-canvas (transferControlToOffscreen) #818

Open hrgdavor opened 3 years ago

hrgdavor commented 3 years ago

Expected Behavior

both render and model executor to be in the same space (preferably worker) then there is no need to convert to compactbinary

Actual Behavior

render is in main thread, model executor is in worker

Steps to Reproduce the Problem

it's just how it is right now

Specifications

https://caniuse.com/offscreencanvas browser support for this will only get better

https://developers.google.com/web/updates/2018/08/offscreen-canvas

Example I found was in three.js https://threejsfundamentals.org/threejs/lessons/threejs-offscreencanvas.html

z3dev commented 3 years ago

FYI, there’s requirement for transferring the solids to the main thread, as the front end also ‘exports’ the solids to external formats.

hrgdavor commented 3 years ago

I have looked into that previously, and I think that export can be done in the worker as well. The file is transferable. I will keep it in mind to test it too.

hrgdavor commented 3 years ago

I have succeded in moving render to worker by making a new version of demo.html in regl-renderer package. I have some code cleanup to do, but will add an PR so there will be both simple demo and demo with workers.

I will also try to implement export in worker, and this way all 3 parts: model-gen, render, export will be in same scope and will not need postMessage