Doodle3D-Slicer/webworker_test.html

218 lines
6.1 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML>
<html lang='en'>
<head>
<script src='library/jquery.js'></script>
<script src='library/three.js'></script>
2015-06-13 20:09:44 +02:00
<script src='three.js-master/examples/js/loaders/STLLoader.js'></script>
<script src='src/utils.js'></script>
<script src='src/box.js'></script>
<script src='src/printer.js'></script>
<script src='src/slicerworker.js'></script>
<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;}
#progress_bar {height: 20px; background-color: lightblue; width: 0%; transition: width 0.5s;}
.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;}
</style>
</head>
<body>
<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>
</div>
<script>
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker, printer;
function init () {
'use strict';
var scene = createScene();
var localIp = location.hash.substring(1);
2015-06-16 10:28:26 +02:00
doodleBox = new D3D.Box(localIp).init();
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-16 10:28:26 +02:00
};
2015-06-09 11:08:06 +02:00
printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);
document.getElementById('stop_print').onclick = function () {
doodleBox.stopPrint(printer);
};
var slicer = new D3D.SlicerWorker();
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 () {
doodleBox.print(gcode);
};
2015-06-09 11:08:06 +02:00
downloadButton.style.display = 'initial';
downloadButton.onclick = function () {
2015-06-11 14:34:30 +02:00
downloadFile("gcode.gcode", gcode);
2015-06-09 11:08:06 +02:00
};
};
var loader = new THREE.STLLoader();
2015-06-13 20:09:44 +02:00
loader.load('models/dom.stl', function (geometry) {
2015-06-09 11:08:06 +02:00
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
2015-07-10 12:59:50 +02:00
//var geometry = new THREE.TorusKnotGeometry( 100, 43, 64, 8 );
2015-06-17 21:26:49 +02:00
2015-06-09 11:08:06 +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});
var mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI/2;
//mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.7;
mesh.position.x = 60;
mesh.position.z = 60;
scene.add(mesh);
slicer.setMesh(mesh);
slicer.slice();
2015-05-29 10:41:44 +02:00
slicer.close();
});
}
function createScene () {
'use strict';
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById('3d-preview'), antialias: true});
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);
applyMouseControls(renderer, camera, new THREE.Vector3(50, 0, 50), 1000);
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);
}
$(renderer.domElement).on('mousedown', function (e) {
moveCamera = true;
}).on('wheel', function (e) {
var event = e.originalEvent;
event.preventDefault();
distance = THREE.Math.clamp(distance - event.wheelDelta, 1, maxDistance);
updateCamera();
});
$(window).on('mouseup', function (e) {
moveCamera = false;
}).on('mousemove', function (e) {
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 () {
2015-07-10 12:59:50 +02:00
requestAnimationFrame(animate);
renderer.render(scene, camera);
})();
return scene;
}
(function () {
'use strict';
var loadedItems = 0;
function loaded () {
loadedItems ++;
if (loadedItems === 2) {
init();
}
}
$.ajax({
url: 'settings/user_settings.json',
dataType: 'json',
success: function (response) {
USER_SETTINGS = response;
loaded();
}
});
$.ajax({
url: 'settings/printer_settings.json',
dataType: 'json',
success: function (response) {
PRINTER_SETTINGS = response;
loaded();
}
});
})();
</script>
</body>
</html>