2015-04-24 16:12:48 +02:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<title>Doedel Drie Dee || Slice Test</title>
|
|
|
|
<!--<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>-->
|
|
|
|
<script src="library/jquery.js"></script>
|
|
|
|
<script src="library/three.js"></script>
|
|
|
|
|
2015-04-24 21:32:39 +02:00
|
|
|
<script src="src/utils.js"></script>
|
|
|
|
<script src="src/box.js"></script>
|
|
|
|
<script src="src/printer.js"></script>
|
|
|
|
<script src="src/slicer.js"></script>
|
2015-04-24 16:12:48 +02:00
|
|
|
|
|
|
|
<script src="gcode/testgcode.js"></script>
|
|
|
|
<script src="gcode/easterbunny.js"></script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<canvas id="3d-preview" height="480" width="720"></canvas>
|
|
|
|
<canvas id="canvas" width="200" height="200"></canvas>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var localIp = location.hash.substring(1);
|
|
|
|
var doodleBox = new D3D.Box(localIp);
|
|
|
|
|
|
|
|
doodleBox.onload = function () {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var gcode = slicer.getGcode(doodleBox.printer);
|
|
|
|
|
2015-04-28 14:11:41 +02:00
|
|
|
var print = $(document.createElement("a")).html("Print").on("click", function () {
|
2015-04-24 16:12:48 +02:00
|
|
|
doodleBox.print(gcode);
|
|
|
|
});
|
2015-04-28 14:11:41 +02:00
|
|
|
var stop = $(document.createElement("a")).html("Stop").on("click", function () {
|
2015-04-24 16:12:48 +02:00
|
|
|
doodleBox.stop();
|
|
|
|
});
|
2015-04-28 14:11:41 +02:00
|
|
|
var download = $(document.createElement("a")).html("Download").attr({
|
|
|
|
download: "test.gcode",
|
|
|
|
href: "data:text/plain," + encodeURIComponent(gcode.join("\n"))
|
|
|
|
});
|
|
|
|
$("body").append(print, stop, download);
|
2015-04-24 16:12:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var scene = new THREE.Scene();
|
|
|
|
|
|
|
|
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview")});
|
|
|
|
renderer.setClearColor(0xffffff, 1);
|
|
|
|
|
|
|
|
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
|
|
|
|
|
|
|
applyMouseControls(renderer, camera, 1000);
|
|
|
|
|
2015-04-28 14:11:41 +02:00
|
|
|
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
|
|
|
|
var geometry = new THREE.TorusGeometry(20, 10, 4, 6);
|
2015-04-24 16:12:48 +02:00
|
|
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
2015-04-28 14:11:41 +02:00
|
|
|
//var geometry = new THREE.SphereGeometry(40, 10, 10);
|
2015-04-24 16:12:48 +02:00
|
|
|
var mesh = new THREE.Mesh(geometry, material);
|
|
|
|
scene.add(mesh);
|
|
|
|
|
2015-04-28 14:11:41 +02:00
|
|
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
|
|
|
//var slices = slicer.slice(200, 0.2);
|
|
|
|
var slices = slicer.slice(1, 1);
|
2015-04-24 16:12:48 +02:00
|
|
|
|
2015-04-28 14:11:41 +02:00
|
|
|
var canvas = document.getElementById("canvas");
|
2015-04-24 16:12:48 +02:00
|
|
|
var context = canvas.getContext("2d");
|
|
|
|
|
|
|
|
for (var layer = 0; layer < slices.length; layer ++) {
|
|
|
|
var slice = slices[layer];
|
|
|
|
|
|
|
|
for (var i = 0; i < slice.length; i ++) {
|
|
|
|
var shape = slice[i];
|
|
|
|
|
|
|
|
context.beginPath();
|
2015-04-28 14:11:41 +02:00
|
|
|
for (var j = 0; j <= shape.length; j ++) {
|
2015-04-24 16:12:48 +02:00
|
|
|
var point = shape[(j % shape.length)];
|
|
|
|
|
|
|
|
context.lineTo((point.x-100) * 3 + 100, (point.y-100) * 3 + 100);
|
|
|
|
}
|
2015-04-28 14:11:41 +02:00
|
|
|
//context.closePath();
|
2015-04-24 16:12:48 +02:00
|
|
|
context.strokeStyle = "rgb(" + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ")";
|
|
|
|
context.stroke();
|
|
|
|
}
|
2015-04-28 14:11:41 +02:00
|
|
|
}
|
2015-04-24 16:12:48 +02:00
|
|
|
|
|
|
|
(function animate () {
|
|
|
|
requestAnimationFrame(animate);
|
|
|
|
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
})();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|