Doodle3D-Slicer/slice_test.html

112 lines
3.0 KiB
HTML
Raw Normal View History

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-28 16:08:56 +02:00
<script src="library/cal.js"></script>
2015-04-24 16:12:48 +02:00
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>
2015-04-28 16:08:56 +02:00
<style>
canvas {border: 1px solid black;}
</style>
2015-04-24 16:12:48 +02:00
</head>
<body>
2015-04-28 16:08:56 +02:00
<canvas id="3d-preview" height="400" width="400"></canvas>
<canvas id="canvas" width="400" height="400"></canvas>
2015-04-24 16:12:48 +02:00
<script>
var localIp = location.hash.substring(1);
var doodleBox = new D3D.Box(localIp);
doodleBox.onload = function () {
"use strict";
2015-04-28 16:08:56 +02:00
/*var gcode = slicer.getGcode(doodleBox.printer);
2015-04-24 16:12:48 +02:00
var print = $(document.createElement("a")).html("Print").on("click", function () {
2015-04-24 16:12:48 +02:00
doodleBox.print(gcode);
});
var stop = $(document.createElement("a")).html("Stop").on("click", function () {
2015-04-24 16:12:48 +02:00
doodleBox.stop();
});
var download = $(document.createElement("a")).html("Download").attr({
download: "test.gcode",
href: "data:text/plain," + encodeURIComponent(gcode.join("\n"))
});
2015-04-28 16:08:56 +02:00
$("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);
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
2015-04-24 16:12:48 +02:00
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
//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 18:10:16 +02:00
(function () {
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 18:10:16 +02:00
CAL.Scene.setCanvas(document.getElementById("canvas"));
2015-04-28 16:08:56 +02:00
2015-04-28 18:10:16 +02:00
//error at layer 0;
//maybe because of geomety
var layer = 4;
2015-04-28 16:08:56 +02:00
2015-04-28 18:10:16 +02:00
var shapes = [];
2015-04-24 16:12:48 +02:00
var slice = slices[layer];
for (var i = 0; i < slice.length; i ++) {
2015-04-28 16:08:56 +02:00
var shape = new CAL.Shape({shapeColor: false});
shapes.push(shape);
2015-04-24 16:12:48 +02:00
2015-04-28 16:08:56 +02:00
for (var j = 0; j < slice[i].length; j ++) {
var point = slice[i][j];
shape.addPoint(new CAL.Vector((point.x-100) * 5 + 200, (point.y-100) * 5 + 200));
2015-04-24 16:12:48 +02:00
}
2015-04-28 16:08:56 +02:00
}
2015-04-28 18:10:16 +02:00
for (var i = 0; i < shapes.length; i ++) {
var shape = shapes[i];
2015-04-28 16:08:56 +02:00
2015-04-28 18:10:16 +02:00
shape.draw(CAL.Scene.context);
CAL.Scene.context.strokeStyle = "#FF0000";
2015-04-28 16:08:56 +02:00
2015-04-28 18:10:16 +02:00
for (var j = 0; j < shape.points.length; j ++) {
var normal = shape.getNormal(j).scale(20);
var point = shape.points[j];
2015-04-28 16:08:56 +02:00
2015-04-28 18:10:16 +02:00
normal.draw(CAL.Scene.context, point.x, point.y);
}
2015-04-24 16:12:48 +02:00
}
2015-04-28 18:10:16 +02:00
})();
2015-04-24 16:12:48 +02:00
(function animate () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
})();
</script>
</body>
</html>