developer friendly syntax for getParameterDefinitions proposal and interactive demo
-
This is a cross post from https://github.com/jscad/OpenJSCAD.org/discussions/875
this demo also aims to be a template for future jscad tutorials
Here is a presentation of a proposal for a new jscad feature: http://3d.hrg.hr/jscad/three/new_params_proposal/parameters.html#0
It is an additional syntax that can be used instead
getParameterDefinitions
to simplify writing scripts that use parameters.The intention is to keep
getParameterDefinitions
and have also this alternative way of defining parametersthe idea is allow developer to write the source source file like this:
function main({//jscadparams // size radius = 22,// Radius {type:'slider', live:1} // location (initially closed) {initial: 'closed'} x=0, // {type:'slider', live:1} y=0, // {type:'slider', live:1} z=0, // {type:'slider', live:1} }){ return translate([x,y,z],sphere({radius, height:x})) }
and the script does not have to provide
getParameterDefinitions
The parser would internally generate this definition based on the source above
function getParameterDefinitions(){ return [ {"name":"_group_1","type":"group","caption":"size"}, {"caption":"Radius","type":"slider","name":"radius","initial":22,"live":1,"min":0,"max":44}, {"name":"_group_2","type":"group","caption":"location (initially closed)","initial":"closed"}, {"caption":"x","type":"slider","name":"x","initial":0,"live":1,"min":0,"max":100}, {"caption":"y","type":"slider","name":"y","initial":0,"live":1,"min":0,"max":100}, {"caption":"z","type":"slider","name":"z","initial":0,"live":1,"min":0,"max":100}, ] }
and the form would be something like this:
also, this demo uses a new worker implementation (with regl-renderer) that renders to offscreen canvas
transferControlToOffscreen
so both renderer and script execution are in the worker.