Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Last active May 14, 2017 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaosat-dev/0a2ac2c4e189e27692ea964956a3a2e5 to your computer and use it in GitHub Desktop.
Save kaosat-dev/0a2ac2c4e189e27692ea964956a3a2e5 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
//just change code and hit ctrl + s or cmd+s (Mac) to save & update the visuals
const regl = require('regl')()
const {drawMesh, csgToMeshes} = require('@kaosat-dev/jscad-regl-helpers')
////////////////
//this would be your project/ parts until the next comments line
// import basic api
const scadApi = require('@jscad/scad-api')
const {difference} = scadApi.booleanOps
const {scale} = scadApi.transformations
//LOOK FROM HERE ON !! THE INTERESTING PART IS HERE
//imports parts designed by someone else
const {jscadLogo, coneWithCutouts} = require('@kaosat-dev/jscad-module-example')
//parts are just functions
function someCoolPart(logoSize=2, coneScale=0.3){
return difference(
jscadLogo(logoSize),//reuse of imported parts
scale(coneScale, coneWithCutouts())//combine imported parts with basic transforms
)
}
////////////////////
//create our test CSG part
const testCSG = someCoolPart()
//save CSG to disk
const saveAs = require('file-saver').saveAs
const serializer = require('@jscad/stl-serializer')
const blob = new Blob(serializer.serialize(testCSG))
//uncoment this if you want to save the design to disk (on save)
//saveAs(blob, 'cool.stl')
//draw csg mesh on screen, just boilerplate
const testMesh = csgToMeshes(testCSG)
const drawCSG = drawMesh(regl, testMesh)
regl.frame(() => {
regl.clear({
depth: 1,
color: [1, 1, 1, 1]
})
drawCSG()
})
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"regl": "1.3.0",
"@kaosat-dev/jscad-regl-helpers": "0.0.1",
"@jscad/scad-api": "0.2.1",
"@kaosat-dev/jscad-module-example": "0.0.3",
"file-saver": "1.3.3",
"@jscad/stl-serializer": "0.0.2"
}
}
'use strict';
//just change code and hit ctrl + s or cmd+s (Mac) to save & update the visuals
var regl = require('regl')();
var _require = require('@kaosat-dev/jscad-regl-helpers');
var drawMesh = _require.drawMesh;
var csgToMeshes = _require.csgToMeshes;
////////////////
//this would be your project/ parts until the next comments line
// import basic api
var scadApi = require('@jscad/scad-api');
var difference = scadApi.booleanOps.difference;
var scale = scadApi.transformations.scale;
//LOOK FROM HERE ON !! THE INTERESTING PART IS HERE
//imports parts designed by someone else
var _require2 = require('@kaosat-dev/jscad-module-example');
var jscadLogo = _require2.jscadLogo;
var coneWithCutouts = _require2.coneWithCutouts;
//parts are just functions
function someCoolPart() {
var logoSize = arguments.length <= 0 || arguments[0] === undefined ? 2 : arguments[0];
var coneScale = arguments.length <= 1 || arguments[1] === undefined ? 0.3 : arguments[1];
return difference(jscadLogo(logoSize), //reuse of imported parts
scale(coneScale, coneWithCutouts()) //combine imported parts with basic transforms
);
}
////////////////////
//create our test CSG part
var testCSG = someCoolPart();
//save CSG to disk
var saveAs = require('file-saver').saveAs;
var serializer = require('@jscad/stl-serializer');
var blob = new Blob(serializer.serialize(testCSG));
//uncoment this if you want to save the design to disk (on save)
//saveAs(blob, 'cool.stl')
//draw csg mesh on screen, just boilerplate
var testMesh = csgToMeshes(testCSG);
var drawCSG = drawMesh(regl, testMesh);
regl.frame(function () {
regl.clear({
depth: 1,
color: [1, 1, 1, 1]
});
drawCSG();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment