-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsg.tests.html
More file actions
161 lines (111 loc) · 2.84 KB
/
csg.tests.html
File metadata and controls
161 lines (111 loc) · 2.84 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="https://rawgithub.com/jashkenas/underscore/master/underscore-min.js" type="text/javascript"></script>
<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
<script src="js/csg.js" ></script>
<script src="js/axCAD.js" ></script>
<script>
function log(txt) {
$('#log').append('<br/>' + txt);
}
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
function send(w,cmd,msg) {
w.postMessage({'cmd':cmd,'msg':msg});
}
$(function() {
var scr = $('#jscad').html();
var blob = new Blob([scr], {type: 'text/javascript'});
var worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = function (e) {
if (e.data.cmd) {
log('cmd:' + e.data.cmd + ', msg:'+e.data.msg);
switch(e.data.cmd) {
case 'import':
// go get the requested file
var txt = httpGet(e.data.msg);
// post it back
send(worker,'imported',txt);
break;
case 'importComplete':
send(worker,'main','');
break;
case 'csg':
log(CSG.fromObject(e.data.msg).toStlString());
}
} else
log(e.data);
};
worker.postMessage();
//worker.terminate();
});
</script>
</head>
<body>
<div id="log"/>
<div id="jscad" style="display:none">
var i=7;
var waitFor = '';
var waitOver = true;
var scrData = '';
function send(cmd,msg) {
postMessage({'cmd':cmd,'msg':msg});
}
function importScript(scr) {
waitFor = 'importComplete';
waitOver = false;
send('import',scr);
setInterval(function() {
if (waitOver) { clearInterval();}
}, 1);
send('log','waitOver');
send('log','Import received, compiling...');
eval(scrData);
send('log',scrData);
send('importComplete','');
}
importScript('js/csg.js');
//importScripts('http://localhost:8888/repos/axCAD/js/csg.js');
function main() {
var cube = CSG.roundedCube({radius: 10, roundradius: 2, resolution: 16});
var sphere = CSG.sphere({radius: 10, resolution: 16}).translate([5, 5, 5]);
return cube.union(sphere);
}
self.onmessage = function(e) {
var data = e.data;
if (data)
if (data.cmd) {
switch (data.cmd) {
case 'start':
send('log','started');
break;
case 'stop':
send('log','stopped');
self.close();
break;
case 'imported':
scrData = data.msg;
break;
case 'main':
send('csg',main());
break;
default:
send('log','Unknown command:' + data.cmd + ', '+data.msg);
}
if (data.cmd == waitFor) {
//waitOver = true;
send('log','waitOver detected');
}
}
}
</div>
</body>
</html>