-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of support for V1 scripts. test url while in progress https://3d.hrg.hr/jscad/v1-support/ or run locally V1 is not really supported anymore, this is an effort to allow running V1 scripts for many old scripts, but with limited dedication what kind of issues would be fixed. Certainly is very unlikely existing bugs from v1 will be fixed (unless someone is very eager and cotributes a fix) - [ ] export support (not working yet) - [x] 2d shapes (outlines, poly) - [x] colors support (working, but missing default color for partially colored) - [ ] complex projects with include (may or may not be implemented) - [x] drag drop `.jscad` and shim will be added to the script Bonus over old V1 engine - correct line numbers for errors reported - debugger support matching source (jsut write `debugger` in the script somewhere and if dev console is open it will brak on that line) ------------------ it works relatively ok, will need a followup. merging to not have it on the side for too long
- Loading branch information
Showing
8 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function addV1Shim(script) { | ||
if (script.includes('JS V1 SHIM HEADER')) return script | ||
|
||
return `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 --------------------------------------------------------------------------------------- | ||
${script} | ||
// ---------------------------- 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){} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@jscad/csg/api.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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 --------------------------------------------------------------------------------------- | ||
|
||
//https://neorama.de | ||
|
||
let res = 32; | ||
|
||
function main() { | ||
return union( | ||
difference( | ||
cube({size: 3, center: true, fn:res}), | ||
sphere({r:2, center: true, fn:res}) | ||
), | ||
intersection( | ||
sphere({r: 1.3, center: true,fn:res}), | ||
cube({size: 2.1, center: true, fn:res}) | ||
) | ||
).translate([0,0,1.5]).scale(10); | ||
} | ||
|
||
// ---------------------------- 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){} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters