-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (70 loc) · 2.53 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<form name="form" class="navbar-form form-inline">
<div class="col-lg-8">
<input id="stl" type="text" class="form-control" placeholder="The URL of the STL file" autofocus>
</div>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-cloud"></span> Load</button>
<button id="download" class="pull-right btn btn-success hide"><span class="glyphicon glyphicon-cloud-download"></span> GCode</button>
</form>
</div>
</div>
<div class="container" style>
<div id="viewer" style="width:100%;height:500px"></div>
<div id="log"></div>
<div id="gcode"></div>
</div><!-- /.container -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var Module = {
'noInitialRun': true,
'noExitRuntime': true,
'print': function(text) {
$( "<div/>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
};
$( document ).ready(function() {
$("form[name=form]").bind('submit',function(){
thingiurlbase = "js";
thingiview = new Thingiview("viewer", 100, 100);
thingiview.initScene();
thingiview.setBackgroundColor('#FFFFFF');
thingiview.setObjectColor('#C0D8F0');
$.get($('#stl').val(), function(stl) {
thingiview.loadSTLString(stl);
// setup the gcode download button
$('#download').removeClass("hide");
$('#download').click( function() {
var gcode = runCuraEngine(stl);
var blob = new Blob([gcode], {type: 'text/plain'});
var url = window.URL.createObjectURL(blob);
// trigger the download
var a = document.createElement('a');
a.href = url;
a.download = 'file.gcode';
a.click();
});
});
return false;
});
});
function runCuraEngine(stl) {
shouldRunNow = true;
FS.createDataFile('/', 'foo.stl', stl, true, true);
FS.createDataFile('/', 'foo.gcode', '', true, true);
run(['-o', '/foo.gcode', '/foo.stl']);
return FS.readFile('/foo.gcode');
}
</script>
<script src="CuraEngine.js" type="text/javascript"></script>
<script src="js/three.min.js"></script>
<script src="js/thingiview.js"></script>
</body>
</html>