-
Notifications
You must be signed in to change notification settings - Fork 282
/
Copy pathindex.html
42 lines (34 loc) · 1.26 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MakerJs / Jscad / STL example</title>
<script src="csg.js"></script>
<script src="stl-serializer.js"></script>
<script src="../../target/js/browser.maker.js"></script>
</head>
<body>
<script>
const makerjs = require('makerjs');
const { CAG } = require('@jscad/csg');
const stlSerializer = require('@jscad/stl-serializer');
const star = new makerjs.models.Star(7, 100, 50);
const svg = makerjs.exporter.toSVG(star);
document.body.innerHTML = svg;
//add a button to the page
const button = document.createElement('button');
button.innerHTML = 'STL';
document.body.appendChild(button);
//when the button is clicked, export an STL
button.onclick = () => {
const stl = makerjs.exporter.toJscadSTL(CAG, stlSerializer, star, { extrude: 50 });
//download the STL file, using the hyperlink trick
const link = document.createElement('a');
link.download = 'star.stl';
link.href = 'data:text/plain,' + stl;
link.click();
}
</script>
</body>
</html>