Skip to content

WIP: V1 support feature #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

WIP: V1 support feature #135

wants to merge 10 commits into from

Conversation

hrgdavor
Copy link
Owner

@hrgdavor hrgdavor commented Mar 15, 2025

TODO

  • export
  • colors suppor

demo: https://3d.hrg.hr/jscad/v1-support/#https://raw.githubusercontent.com/jscad/OpenJSCAD.org/refs/heads/V1/packages/examples/logo.jscad

details

it uses a shim, and this intentional. I do not want to hide the fact that those V1 scripts can be be migrated to regular JS, that is not some fancy scripting language.

Header shim

const csg = require('@jscad/csg')
const { OpenJsCad, debug } = csg
const {circle, square, polygon, triangle} = csg.primitives2d
const {cube, sphere, cylinder, geodesicSphere, torus, polyhedron} = csg.primitives3d
const {union, difference, intersection} = csg.booleanOps
const {translate, center, scale, rotate, transform, mirror, expand, contract, minkowski, hull, chain_hull} = csg.transformations
const {extrudeInOrthonormalBasis, extrudeInPlane, extrude, linear_extrude, rotate_extrude, rotateExtrude, rectangular_extrude} = csg.extrusions
const {css2rgb, color, rgb2hsl, hsl2rgb, rgb2hsv, hsv2rgb, html2rgb, rgb2html} = csg.color
const {sin, cos, asin, acos, tan, atan, atan2, ceil, floor, abs, min, max, rands, log, lookup, pow, sign, sqrt, round} = csg.maths
const {vector_char, vector_text, vectorText} = csg.text
const { CSG, CAG } = csg.csg
function echo(){console.warn("echo() will be deprecated in the near future: please use console.log/warn/error instead");for(var e="",t=arguments,n=0;n<t.length;n++)n&&(e+=", "),e+=t[n];console.log(e)}
// lines above are a JS shim, to make .jscad scripts work as regular JS
// ------------------------------ JS V1 SHIM HEADER ---------------------------------------------------------------------------------------
  

footer shim

// ---------------------------- JS V1 SHIM FOOTER -----------------------------------------------------------------------------------------
// this is footer of the JS shim, to export the main and getParameterDefinitions
module.exports = { main }
// some scripts will not have parameters, so we silently ignore the error line below would cause
try{ module.exports.getParameterDefinitions = getParameterDefinitions }catch(e){}

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