mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 03:23:48 +01:00
172 lines
4.3 KiB
HTML
172 lines
4.3 KiB
HTML
<!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>
|
|
<script src="library/cal.js"></script>
|
|
<script src="library/clipper.js"></script>
|
|
|
|
<script src="src/utils.js"></script>
|
|
<script src="src/box.js"></script>
|
|
<script src="src/printer.js"></script>
|
|
<script src="src/slicer.js"></script>
|
|
|
|
<script src="gcode/testgcode.js"></script>
|
|
<script src="gcode/easterbunny.js"></script>
|
|
|
|
<style>
|
|
canvas {border: 1px solid black;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="3d-preview" height="400" width="400"></canvas>
|
|
<canvas id="canvas" width="400" height="400"></canvas>
|
|
|
|
<script>
|
|
var localIp = location.hash.substring(1);
|
|
var doodleBox = new D3D.Box(localIp);
|
|
|
|
var gcode;
|
|
doodleBox.onload = function () {
|
|
doodleBox.printer.config["printer.bottomFlowRate"] = 1.0;
|
|
doodleBox.printer.config["printer.layerHeight"] = 0.3;
|
|
doodleBox.printer.config["printer.retraction.enabled"] = false;
|
|
|
|
gcode = slicer.getGcode(doodleBox.printer.config);
|
|
|
|
var canvas = document.getElementById("canvas");
|
|
var context = canvas.getContext("2d");
|
|
|
|
function drawPolygons (paths, color) {
|
|
context.fillStyle = color;
|
|
context.strokeStyle = color;
|
|
context.beginPath();
|
|
|
|
for (var i = 0; i < paths.length; i ++) {
|
|
var path = paths[i];
|
|
|
|
context.moveTo((path[0].X- 100) * 8.0 + 200, (path[0].Y- 100) * 8.0 + 200);
|
|
|
|
for (var j = 0; j < path.length; j ++) {
|
|
var point = path[j];
|
|
context.lineTo((point.X- 100) * 8.0 + 200, (point.Y- 100) * 8.0 + 200);
|
|
}
|
|
context.closePath();
|
|
}
|
|
context.stroke();
|
|
}
|
|
|
|
//for (var layer = 0; layer < gcode.length; layer ++) {
|
|
var layer = 0;
|
|
var slice = gcode[layer];
|
|
|
|
console.log(gcode.length);
|
|
|
|
drawPolygons(slice.outerLayer, "red");
|
|
drawPolygons(slice.innerLayer, "green");
|
|
drawPolygons(slice.fill, "blue");
|
|
//}*/
|
|
};
|
|
|
|
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 geometry = (function () {
|
|
var circle = new THREE.Shape();
|
|
circle.absarc(0, 0, 20, 0, Math.PI*2, false);
|
|
|
|
var hole = new THREE.Path();
|
|
hole.absarc(0, 0, 10, 0, Math.PI*2, true );
|
|
|
|
circle.holes.push(hole);
|
|
|
|
var matrix = new THREE.Matrix4();
|
|
matrix.makeRotationX(Math.PI*1.5);
|
|
|
|
var geometry = new THREE.ExtrudeGeometry(circle, {
|
|
amount: 1,
|
|
bevelEnabled: false,
|
|
steps: 1
|
|
});
|
|
geometry.applyMatrix(matrix);
|
|
|
|
return geometry;
|
|
})();
|
|
|
|
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
|
|
//var geometry = new THREE.TorusGeometry(40, 20, 10, 10);
|
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
|
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
|
var mesh = new THREE.Mesh(geometry, material);
|
|
scene.add(mesh);
|
|
|
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
|
|
|
var canvas = document.getElementById("canvas");
|
|
var context = canvas.getContext("2d");
|
|
|
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
|
//slicer.draw(1, context);
|
|
|
|
/*
|
|
(function () {
|
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
|
var slices = slicer.slice(200, 0.2);
|
|
slices.shift();
|
|
//var slices = slicer.slice(1, 1);
|
|
|
|
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
|
|
|
//error at layer 0;
|
|
//maybe because of geomety
|
|
var layer = 0;
|
|
|
|
var shapes = [];
|
|
|
|
var slice = slices[layer];
|
|
|
|
//downloadFile("slice.json", JSON.stringify(slice));
|
|
|
|
for (var i = 0; i < slice.length; i ++) {
|
|
var shape = new CAL.Shape({shapeColor: false});
|
|
shapes.push(shape);
|
|
|
|
for (var j = 0; j < slice[i].length; j ++) {
|
|
var point = slice[i][j];
|
|
shape.addPoint(new CAL.Vector(point.X, point.Y));
|
|
}
|
|
}
|
|
|
|
for (var i = 0; i < shapes.length; i ++) {
|
|
var shape = shapes[i];
|
|
|
|
shape.draw(CAL.Scene.context);
|
|
CAL.Scene.context.strokeStyle = "#FF0000";
|
|
|
|
for (var j = 0; j < shape.points.length; j ++) {
|
|
var normal = shape.getNormal(j).scale(20);
|
|
var point = shape.points[j];
|
|
|
|
normal.draw(CAL.Scene.context, point.x, point.y);
|
|
}
|
|
}
|
|
})();
|
|
*/
|
|
|
|
(function animate () {
|
|
requestAnimationFrame(animate);
|
|
|
|
renderer.render(scene, camera);
|
|
})();
|
|
</script>
|
|
|
|
</body>
|
|
</html> |