forked from triffid/WebSkein
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebskein2.html
358 lines (329 loc) · 11.6 KB
/
webskein2.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<!DOCTYPE html>
<html>
<head>
<title>WebSkein</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<script type="text/javascript" src="sylvester/sylvester.src.js"></script>
<script type="text/javascript" src="jsc3d.js"></script>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="boundvalue.js"></script>
<script type="text/javascript" src="sylvester/sylvester_ext.js"></script>
<script type="text/javascript" src="webskein2.js"></script>
<style type="text/css">
input, textarea {
margin: 0 0.1em;
padding: 0 0.1em;
border: 1px solid #CCF;
color: black;
background-color: white;
}
input[type=text] {
width: 2.5em;
}
input[type=button] {
border: 1px outset #CCF;
}
input[disabled] {
color: #CCC;
}
input[type=text].long {
width: 80%;
}
.settings h3 {
color: #88C;
border-bottom: 1px solid #CCF;
font-weight: bold;
font-size: 100%;
margin: 0;
}
.setting {
white-space: nowrap;
width: 100%;
clear: both;
border-bottom: 1px solid #F0F0FF;
height: 1.3em;
padding-left: 1em;
}
.setting .label {
float: left;
}
.setting .field {
float: right;
width: 5em;
}
.setting .field input {
width: 2.5em;
}
input.right {
clear: both;
float: right;
text-align: center;
width: 5em;
}
</style>
</head>
<body>
<div style="width: 455px; padding: 0; margin: 0; float: left;">
<form id="skeinform" action="" method="get">
<input id="stl_uri" class="long" type="file" size="35" value="x-end-motor_M6.stl" />
</form>
<canvas id="stlview" style="border: 1px inset;" width="450" height="337"></canvas>
</div>
<form id="settingsform" action="">
<div style="width: 455px; padding: 0; margin: 0; float: left;">
<input id="slice_btn" type="button" value="Skein Model" style="width: 7em;" /><input id="stop_btn" type="button" value="Stop" style="color: red; margin-right: 0.5em;" />
<span style="white-space: nowrap;">Layer <input id="layer_txt" type="text" size="4" value="0" /> of <input id="layer_count_txt" type="text" size="4" value="" readonly="readonly" /></span>
<input id="slice_layer_btn" type="button" value="Slice" />
<input id="draw_layer_btn" type="button" value="Draw" />
<canvas id="sliceview" style="border: 1px inset;" width="450" height="337"></canvas>
</div>
<div class="settings" style="width: 300px; padding: 0; margin: 0; float: left;">
<div class="setting"><span class="label">Layer Height</span><span class="field"><input id="layer_height_txt" type="text" value="0.3" />mm</span></div>
<h3>Segment Combining Options</h3>
<!-- <div class="setting"><span class="label">Segment Co-linear Distance</span><span class="field"><input id="collinear_distance_txt" type="text" value="0.15" />mm</span></div> -->
<div class="setting"><span class="label">Segment Co-linear Angle</span><span class="field"><input id="collinear_angle_txt" type="text" value="0.15" />rθ</span></div>
<!-- <div class="setting"><span class="label">Segment Combine Length</span><span class="field"><input id="combine_length_txt" type="text" value="0.5" />mm</span></div> -->
<div class="setting"><span class="label">Mininum Segment Length</span><span class="field"><input id="min_length_txt" type="text" value="0.4" />mm</span></div>
<h3>Toolpath Options</h3>
<div class="setting"><span class="label">Extrusion Width</span><span class="field"><input id="extrusion_width_txt" type="text" value="0.6" />mm</span></div>
<div class="setting"><span class="label">Shell Count</span><span class="field"><input id="shell_count_txt" type="text" value="1" />#</span></div>
<hr>
<textarea id="pointinfo" rows="12" cols="30" style="width: 100%;">blah</textarea>
</div>
<textarea id="debug" rows="10" cols="81" style="width: 100%;"></textarea>
<textarea id="dout" rows="10" cols="81" style="width: 100%;"></textarea>
</form>
<script type="text/javascript">
var slice_btn = $('slice_btn');
var stl_uri = $('stl_uri');
var stop_btn = $('stop_btn');
var slice_layer_btn = $('slice_layer_btn');
var draw_layer_btn = $('draw_layer_btn');
var skeincanvas = $('sliceview');
skeincanvas.translationX = 0;
skeincanvas.translationY = 0;
skeincanvas.scale = 0;
skeincanvas.scaleF = 1;
var debug = $('debug');
var dout = $('dout');
var getopt = [];
var getopt_hash = [];
var reader = new FileReader();
var stloader;
var layer = new boundValue('layer_txt', 0, 0, undefined, true);
var layer_height = new boundValue('layer_height_txt', 0.3, 0.05);
var layer_count = new boundValue('layer_count_txt', 0, 0, undefined, true);
// var collinear_distance = new boundValue('collinear_distance_txt', 0.065, 0);
var collinear_angle = new boundValue('collinear_angle_txt', 0.1, 0);
// var combine_length = new boundValue('combine_length_txt', 0.5, 0);
var min_length = new boundValue('min_length_txt', 0.4, 0);
var extrusion_width = new boundValue('extrusion_width_txt', 0.6, 0.1);
var shell_count = new boundValue('shell_count_txt', 1, 1, undefined, true);
Object.extend(Event, {
wheel:function (event){
var delta = 0;
if (!event) event = window.event;
if (event.wheelDelta) {
delta = event.wheelDelta/120;
if (window.opera) delta = -delta;
} else if (event.detail) { delta = -event.detail/3; }
return Math.round(delta); //Safari Round
}
});
function gotstl(e) {
try {
var stloader = e.element().stloader;
//debugWrite(dump(e.element()));
var scene = new JSC3D.Scene();
debugWrite(" OK. Parsing...");
stloader.parseStl(scene, e.element().result);
viewer.afterupdate = checkModel;
viewer.replaceScene(scene);
viewer.update();
}
catch (err) {
// debugWrite(dump(e) + '\n');
alert(err);
}
}
reader.onload = gotstl;
document.observe("dom:loaded", function() {
stloader = new JSC3D.StlLoader();
reader.stloader = stloader;
slice_btn.disabled = true;
slice_layer_btn.disabled = true;
stl_uri.clear();
stl_uri.observe("change", function(e) {
var f = e.element().files[0];
if (f) {
debugWrite("Loading " + f.name + "...");
var sMimeType = f.type;
reader.readAsBinaryString(f);
}
});
slice_btn.reset = function() {
this.disabled = false;
this.value = "Skein Model";
}
slice_btn.onclick = function() {
try {
this.disabled = true;
this.value = "Skein";
sliceModel();
}
catch (err) {
this.reset()
}
return false;
};
stop_btn.onclick = function() {
window.clearTimeout(sliceTimer);
slice_btn.reset();
};
slice_layer_btn.onclick = function() {
calcLayers();
updateHash();
sliceLayer();
drawLayer(layer.value);
if (dout) {
var r = "[";
var paths = layers[layer.value].outline;
for (var i = 0, l = paths.length; i < l; i++) { //>
r += "[ ";
var path = paths[i];
for (var j = 0, m = path.length; j < m; j++) { //>
var point = path[j];
r += point.toString() + ",";
}
r = r.substr(r, r.length - 1) + "],";
}
r = r.substr(r, r.length - 1) + "]";
dout.value = r;
}
}
draw_layer_btn.onclick = function() {
calcLayers();
drawLayer(layer.value);
}
skeincanvas.observe("mousedown", function(e) {
if (e.isLeftClick()) {
e.elementX = e.pointerX() - e.element().offsetLeft;
e.elementY = e.pointerY() - e.element().offsetTop;
this.mousedownX = e.elementX;
this.mousedownY = e.elementY;
this.translation_startX = e.elementX;
this.translation_startY = e.elementY;
this.mousedown = 1;
}
});
skeincanvas.observe("mouseup", function(e) {
e.elementX = e.pointerX() - e.element().offsetLeft;
e.elementY = e.pointerY() - e.element().offsetTop;
if (this.mousedown) {
this.mousedown = 0;
if ((e.elementX == this.mousedownX) && (e.elementY == this.mousedownY)) {
if ((e.elementX < 20) && (e.elementY < 20)) { //>
skeincanvas.translationX = 0;
skeincanvas.translationY = 0;
skeincanvas.scale = 0;
skeincanvas.scaleF = 1;
if (layers[layer.value])
drawLayer(layer.value);
}
}
}
});
skeincanvas.observe("mousemove", function(e) {
e.elementX = e.pointerX() - e.element().offsetLeft;
e.elementY = e.pointerY() - e.element().offsetTop;
var dX = e.elementX - this.mousemoveX;
var dY = e.elementY - this.mousemoveY;
this.mousemoveX = e.elementX;
this.mousemoveY = e.elementY;
if (this.mousedown) {
skeincanvas.translationX += dX;
skeincanvas.translationY += dY;
if (layers.length) {
// panning, draw
drawLayer(layer.value);
}
}
else if (layers.length) {
if (this.pointInfoTimer)
window.clearTimeout(this.pointInfoTimer);
this.pointInfoTimer = window.setTimeout(function () { pointInfo(e.elementX, e.elementY); }, 100);
}
});
skeincanvas.mousewheelhandler = function(e) {
if (layers[layer.value]) {
e.stop();
var x_start = xscale_invert(this.mousemoveX);
var y_start = yscale_invert(this.mousemoveY);
skeincanvas.scale += Event.wheel(e);
skeincanvas.scaleF = Math.pow(Math.E, skeincanvas.scale / 10);
// translate, so we scale as if mousecursor is origin for nice zoom effect
skeincanvas.translationX += this.mousemoveX - xscale(x_start);
skeincanvas.translationY += this.mousemoveY - yscale(y_start);
drawLayer(layer.value);
}
}
skeincanvas.observe("mousewheel", skeincanvas.mousewheelhandler);
skeincanvas.observe("DOMMouseScroll", skeincanvas.mousewheelhandler);
});
function updateHash() {
window.location.hash =
"lh=" + layer_height.value +
// ",scd=" + collinear_distance.value +
",sca=" + collinear_angle.value +
// ",scl=" + combine_length.value +
",msl=" + min_length.value +
",ew=" + extrusion_width.value +
",ns=" + shell_count.value +
"";
}
function debugWrite(data) {
debug.value += data;
debug.scrollTop = debug.scrollHeight;
}
window.onload = function() {
debug.value = '';
if (window.location.search.length > 1) {
var iCouple, aCouples = window.location.search.substr(1).split("&");
for (var iCouplId = 0; iCouplId < aCouples.length; iCouplId++) { //>
iCouple = aCouples[iCouplId].split("=");
getopt[unescape(iCouple[0]).toLowerCase()] = iCouple.length > 1 ? unescape(iCouple[1]) : null;
}
}
if (window.location.hash.length > 1) {
var lh = window.location.hash.match(/lh=(-?[\d\.]+)/i);
if (lh) {
layer_height.set(lh[1]);
}
// var scd = window.location.hash.match(/scd=(-?[\d\.]+)/i);
// if (scd)
// collinear_distance.set(scd[1]);
var sca = window.location.hash.match(/sca=(-?[\d\.]+)/i);
if (sca)
collinear_angle.set(sca[1]);
// var scl = window.location.hash.match(/scl=(-?[\d\.]+)/i);
// if (scl)
// combine_length.set(scl[1]);
var msl = window.location.hash.match(/msl=(-?[\d\.]+)/i);
if (msl)
min_length.set(msl[1]);
var ew = window.location.hash.match(/ew=(-?[\d\.]+)/i);
if (ew)
extrusion_width.set(ew[1]);
var ns = window.location.hash.match(/ns=(-?[\d\.]+)/i);
if (ns)
shell_count.set(ns[1]);
}
//if (getopt['stl']) {
// stl_uri.value = getopt['stl'];
//}
canvasInit();
// canvasLoadSTL(stl_uri.value);
}
</script>
</body>
</html>