2015-05-27 12:25:51 +02:00
|
|
|
<!DOCTYPE HTML>
|
2015-06-05 09:56:58 +02:00
|
|
|
<html lang='en'>
|
2015-05-27 12:25:51 +02:00
|
|
|
<head>
|
2015-06-05 09:56:58 +02:00
|
|
|
<script src='library/jquery.js'></script>
|
|
|
|
<script src='library/three.js'></script>
|
|
|
|
<script src='library/stl_loader.js'></script>
|
2015-05-27 12:25:51 +02:00
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
<script src='src/utils.js'></script>
|
|
|
|
<script src='src/box.js'></script>
|
|
|
|
<script src='src/printer.js'></script>
|
|
|
|
<script src='src/slicerworker.js'></script>
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
<title>Doedel Drie Dee || Webworker Test</title>
|
|
|
|
<style>
|
|
|
|
canvas {border: 1px solid black;}
|
2015-05-29 13:51:18 +02:00
|
|
|
#progress {height: 20px; width: 200px; border: 1px solid black; overflow: hidden;}
|
2015-06-05 09:56:58 +02:00
|
|
|
#progress_bar {height: 20px; background-color: lightblue; width: 0%;}
|
|
|
|
.block {border: 1px solid black; width: 400px; height: 400px; display: inline-block;}
|
2015-06-09 11:08:06 +02:00
|
|
|
#start_print, #download {display: none;}
|
2015-05-27 12:25:51 +02:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
<canvas id='3d-preview' height='400' width='400'></canvas>
|
|
|
|
<div class='block'>
|
|
|
|
<p>State: <span id='state'></span></p>
|
|
|
|
<p>Bed Temp: <span id='bed_temp'></span></p>
|
|
|
|
<p>Bed Target Temp: <span id='bed_target_temp'></span></p>
|
|
|
|
<p>Nozzle Temp: <span id='nozzle_temp'></span></p>
|
|
|
|
<p>Nozzle Target Temp: <span id='nozzle_target_temp'></span></p>
|
|
|
|
<p>Current Line: <span id='current_line'></span></p>
|
|
|
|
<p>Buffered Lines: <span id='buffered_lines'></span></p>
|
|
|
|
<p>Total Lines: <span id='total_lines'></span></p>
|
|
|
|
<p>Batches To Send: <span id='print_batches'></span></p>
|
|
|
|
<div id='progress'><div id='progress_bar'></div></div>
|
|
|
|
<button id="stop_print">Stop Print</button>
|
2015-06-09 11:08:06 +02:00
|
|
|
<button id="start_print">Start Print</button>
|
|
|
|
<button id="download">Download Gcode</button>
|
2015-06-05 09:56:58 +02:00
|
|
|
</div>
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker, printer;
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
function init () {
|
2015-06-05 09:56:58 +02:00
|
|
|
'use strict';
|
2015-05-27 12:25:51 +02:00
|
|
|
var scene = createScene();
|
|
|
|
|
|
|
|
var localIp = location.hash.substring(1);
|
2015-06-10 18:25:49 +02:00
|
|
|
doodleBox = new D3D.Box(localIp);
|
2015-06-09 21:58:22 +02:00
|
|
|
|
2015-06-10 18:25:49 +02:00
|
|
|
doodleBox.onupdate = function (data) {
|
|
|
|
document.getElementById('state').innerHTML = data.state;
|
|
|
|
document.getElementById('bed_temp').innerHTML = data.bed;
|
|
|
|
document.getElementById('bed_target_temp').innerHTML = data.bed_target;
|
|
|
|
document.getElementById('nozzle_temp').innerHTML = data.hotend;
|
|
|
|
document.getElementById('nozzle_target_temp').innerHTML = data.hotend_target;
|
|
|
|
document.getElementById('current_line').innerHTML = data.current_line;
|
|
|
|
document.getElementById('buffered_lines').innerHTML = data.buffered_lines;
|
|
|
|
document.getElementById('total_lines').innerHTML = data.total_lines;
|
|
|
|
document.getElementById('print_batches').innerHTML = doodleBox.printBatches.length;
|
|
|
|
};
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-06-09 11:08:06 +02:00
|
|
|
printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
document.getElementById('stop_print').onclick = function () {
|
|
|
|
doodleBox.stopPrint(printer);
|
|
|
|
};
|
|
|
|
|
2015-05-27 12:25:51 +02:00
|
|
|
var slicer = new D3D.SlicerWorker();
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS['ultimaker2go']);
|
|
|
|
|
|
|
|
var progressBar = document.getElementById('progress_bar');
|
|
|
|
slicer.onprogress = function (progress) {
|
|
|
|
progressBar.style.width = progress.procent * 100 + '%';
|
|
|
|
};
|
|
|
|
slicer.onfinish = function (_gcode) {
|
|
|
|
gcode = _gcode;
|
2015-06-09 11:08:06 +02:00
|
|
|
var startPrintButton = document.getElementById('start_print');
|
|
|
|
var downloadButton = document.getElementById('download');
|
|
|
|
|
|
|
|
startPrintButton.style.display = 'initial';
|
|
|
|
startPrintButton.onclick = function () {
|
2015-06-05 09:56:58 +02:00
|
|
|
doodleBox.print(gcode);
|
|
|
|
};
|
2015-06-09 11:08:06 +02:00
|
|
|
|
|
|
|
downloadButton.style.display = 'initial';
|
|
|
|
downloadButton.onclick = function () {
|
|
|
|
downloadFile("gcode.gcode", gcode.join('\n'));
|
|
|
|
};
|
2015-06-05 09:56:58 +02:00
|
|
|
};
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
var loader = new THREE.STLLoader();
|
2015-06-11 10:28:21 +02:00
|
|
|
loader.load('models/pokemon/pikachu.stl', function (geometry) {
|
2015-06-09 11:08:06 +02:00
|
|
|
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
|
|
|
|
|
2015-05-27 12:25:51 +02:00
|
|
|
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});
|
2015-06-09 11:08:06 +02:00
|
|
|
//var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
2015-05-27 12:25:51 +02:00
|
|
|
var mesh = new THREE.Mesh(geometry, material);
|
2015-06-05 09:56:58 +02:00
|
|
|
|
2015-05-27 12:25:51 +02:00
|
|
|
mesh.rotation.x = -Math.PI/2;
|
2015-06-09 11:08:06 +02:00
|
|
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
|
2015-06-05 09:56:58 +02:00
|
|
|
mesh.position.y = -0.1;
|
|
|
|
mesh.position.x = 60;
|
|
|
|
mesh.position.z = 60;
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
scene.add(mesh);
|
|
|
|
|
|
|
|
slicer.setMesh(mesh);
|
|
|
|
slicer.slice();
|
2015-05-29 10:41:44 +02:00
|
|
|
|
|
|
|
slicer.close();
|
2015-05-27 12:25:51 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function createScene () {
|
|
|
|
var scene = new THREE.Scene();
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById('3d-preview'), antialias: true});
|
2015-05-27 12:25:51 +02:00
|
|
|
renderer.setClearColor(0xffffff, 1);
|
|
|
|
|
|
|
|
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
|
|
|
scene.add(camera);
|
|
|
|
|
|
|
|
var light = new THREE.AmbientLight(0x404040);
|
|
|
|
scene.add(light);
|
|
|
|
|
|
|
|
var directionalLight = new THREE.PointLight(0xffffff, 0.5);
|
|
|
|
camera.add(directionalLight);
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
applyMouseControls(renderer, camera, new THREE.Vector3(50, 0, 50), 1000);
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
function applyMouseControls (renderer, camera, center, maxDistance) {
|
|
|
|
var distance = 20;
|
|
|
|
var rotX = 0;
|
|
|
|
var rotY = 0;
|
|
|
|
var moveCamera = false;
|
|
|
|
|
|
|
|
function updateCamera () {
|
|
|
|
camera.position.set(
|
|
|
|
Math.cos(rotY)*Math.sin(rotX)*distance,
|
|
|
|
Math.sin(rotY)*distance,
|
|
|
|
Math.cos(rotY)*Math.cos(rotX)*distance
|
|
|
|
).add(center);
|
|
|
|
camera.lookAt(center);
|
|
|
|
}
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
$(renderer.domElement).on('mousedown', function (e) {
|
2015-05-27 12:25:51 +02:00
|
|
|
moveCamera = true;
|
2015-06-05 09:56:58 +02:00
|
|
|
}).on('wheel', function (e) {
|
2015-05-27 12:25:51 +02:00
|
|
|
var event = e.originalEvent;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
distance = THREE.Math.clamp(distance - event.wheelDelta, 1, maxDistance);
|
|
|
|
|
|
|
|
updateCamera();
|
|
|
|
});
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
$(window).on('mouseup', function (e) {
|
2015-05-27 12:25:51 +02:00
|
|
|
moveCamera = false;
|
2015-06-05 09:56:58 +02:00
|
|
|
}).on('mousemove', function (e) {
|
2015-05-27 12:25:51 +02:00
|
|
|
var event = e.originalEvent;
|
|
|
|
|
|
|
|
if (moveCamera === true) {
|
|
|
|
rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI);
|
|
|
|
rotY = THREE.Math.clamp(rotY + event.webkitMovementY/100, -Math.PI/2, Math.PI/2);
|
|
|
|
|
|
|
|
updateCamera();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
updateCamera();
|
|
|
|
}
|
|
|
|
|
|
|
|
(function animate () {
|
|
|
|
requestAnimationFrame(animate);
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
})();
|
|
|
|
|
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
(function () {
|
2015-06-05 09:56:58 +02:00
|
|
|
'use strict';
|
2015-05-27 12:25:51 +02:00
|
|
|
|
|
|
|
var loadedItems = 0;
|
|
|
|
function loaded () {
|
|
|
|
loadedItems ++;
|
|
|
|
if (loadedItems === 2) {
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 09:56:58 +02:00
|
|
|
loadSettings('settings/user_settings.json', function (data) {
|
2015-05-27 12:25:51 +02:00
|
|
|
USER_SETTINGS = data;
|
|
|
|
loaded();
|
|
|
|
});
|
2015-06-05 09:56:58 +02:00
|
|
|
loadSettings('settings/printer_settings.json', function (data) {
|
2015-05-27 12:25:51 +02:00
|
|
|
PRINTER_SETTINGS = data;
|
|
|
|
loaded();
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|