Doodle3D-Slicer/slice_test.html

231 lines
7.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-05-06 15:06:04 +02:00
<script src="library/stl_loader.js"></script>
2015-04-30 18:26:34 +02:00
<script src="library/clipper.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>
2015-05-13 12:12:15 +02:00
<script src="src/paths.js"></script>
2015-04-24 21:32:39 +02:00
<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>
2015-05-01 11:03:07 +02:00
//nieuwe config
//geimplimenteerd worden in de doodlebox?
2015-04-30 20:34:57 +02:00
var printerConfig = {
2015-05-01 11:03:07 +02:00
"printer.baudrate": "115200", //wat is dit?
2015-04-30 20:34:57 +02:00
"printer.bed.temperature": 70,
"printer.bottomFlowRate": 1.0,
"printer.bottomLayerSpeed": 35,
"printer.dimensions.x": 200,
"printer.dimensions.y": 200,
"printer.dimensions.z": 200,
"printer.enableTraveling": true, //wat is dit?
2015-04-30 20:34:57 +02:00
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
"printer.filamentThickness": 2.89,
"printer.firstLayerSlow": true,
"printer.heatedbed": false,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.retraction.amount": 3,
2015-05-12 11:29:01 +02:00
"printer.retraction.enabled": false,
2015-04-30 20:34:57 +02:00
"printer.retraction.minDistance": 5,
"printer.retraction.speed": 50,
2015-05-06 15:06:04 +02:00
"printer.screenToMillimeterScale": 0.3, //????
2015-04-30 20:34:57 +02:00
"printer.speed": 70,
"printer.startcode": ";Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.temperature": 230,
"printer.travelSpeed": 200,
"printer.type": "ultimaker",
2015-05-01 11:03:07 +02:00
"printer.useSubLayers": true, //wat is dit?
2015-05-12 11:29:01 +02:00
"printer.wallThickness": 0.4, //nozzle
"printer.layerHeight": 0.3,
2015-05-01 11:03:07 +02:00
//variabele toevoegen;
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
2015-05-12 11:29:01 +02:00
"printer.shellThickness": 0.4,
2015-05-01 11:03:07 +02:00
"printer.fillSize": 5, //dit is het raster aan de binnen kant van de geometry
2015-05-12 11:29:01 +02:00
"printer.brimOffset": 5,
"printer.bottomTopThickness": 0.8
2015-04-30 20:34:57 +02:00
};
2015-05-01 10:06:52 +02:00
var printer = new D3D.Printer(printerConfig);
2015-04-30 18:26:34 +02:00
var localIp = location.hash.substring(1);
2015-05-13 13:18:37 +02:00
var doodleBox = new D3D.Box(localIp);
2015-05-01 14:59:39 +02:00
//var printer = doodleBox.printer;
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, new THREE.Vector3(100, 0, 100), 1000);
2015-04-24 16:12:48 +02:00
2015-04-30 18:26:34 +02:00
var geometry = (function () {
2015-05-01 10:06:52 +02:00
"use strict";
2015-04-30 18:26:34 +02:00
var circle = new THREE.Shape();
circle.absarc(0, 0, 100, 0, Math.PI*2, false);
2015-04-30 18:26:34 +02:00
var hole = new THREE.Path();
hole.absarc(0, 0, 15, 0, Math.PI*2, true );
2015-04-30 18:26:34 +02:00
circle.holes.push(hole);
2015-04-30 18:26:34 +02:00
var matrix = new THREE.Matrix4();
matrix.makeRotationX(Math.PI*1.5);
var geometry = new THREE.ExtrudeGeometry(circle, {
amount: 3,
2015-04-30 18:26:34 +02:00
bevelEnabled: false,
steps: 1
});
geometry.applyMatrix(matrix);
return geometry;
})();
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
2015-05-15 11:14:44 +02:00
var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
2015-05-12 11:29:01 +02:00
var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(10, 10, 10);
2015-04-24 16:12:48 +02:00
var mesh = new THREE.Mesh(geometry, material);
mesh.position.x = 100;
mesh.position.z = 100;
2015-05-12 11:29:01 +02:00
//scene.add(mesh);
2015-04-28 16:08:56 +02:00
var loader = new THREE.STLLoader();
loader.load("models/stanford_bunny.stl", function (geometry) {
2015-05-15 15:07:47 +02:00
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
2015-05-15 11:14:44 +02:00
//var geometry = new THREE.SphereGeometry(10, 10, 10);
2015-05-13 13:18:37 +02:00
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
2015-05-13 17:37:52 +02:00
2015-05-15 15:07:47 +02:00
/*
2015-05-13 17:37:52 +02:00
var geometry = (function () {
"use strict";
var circle = new THREE.Shape();
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
var hole = new THREE.Path();
hole.absarc(0, 0, 5, 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, {
2015-05-15 15:07:47 +02:00
amount: 10,
2015-05-13 17:37:52 +02:00
bevelEnabled: false,
steps: 1
});
geometry.applyMatrix(matrix);
return geometry;
})();
2015-05-15 15:07:47 +02:00
*/
2015-05-13 17:37:52 +02:00
2015-05-06 15:06:04 +02:00
var mesh = new THREE.Mesh(geometry, material);
2015-05-12 11:29:01 +02:00
mesh.rotation.x = -Math.PI/2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
2015-05-12 11:29:01 +02:00
mesh.position.x = 100;
mesh.position.z = 100;
//mesh.position.y = -2;
2015-05-13 13:18:37 +02:00
2015-05-15 15:07:47 +02:00
///*
//mesh.rotation.x = -Math.PI/2;
2015-05-12 11:29:01 +02:00
//mesh is lifted a little bit...
2015-05-15 15:07:47 +02:00
//mesh.position.y = 26.5;
//*/
2015-05-12 11:29:01 +02:00
scene.add(mesh);
2015-05-06 15:06:04 +02:00
2015-05-12 11:29:01 +02:00
var slicer = new D3D.Slicer().setMesh(mesh);
2015-05-13 12:12:15 +02:00
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
2015-05-15 15:07:47 +02:00
var img = slicer.drawPaths(printer, 7, 8);
context.drawImage(img, 0, 0);
2015-05-13 12:12:15 +02:00
2015-05-12 11:29:01 +02:00
gcode = slicer.getGcode(printer);
});
2015-05-06 15:06:04 +02:00
2015-04-24 16:12:48 +02:00
(function animate () {
2015-05-01 10:06:52 +02:00
"use strict";
2015-04-24 16:12:48 +02:00
requestAnimationFrame(animate);
renderer.render(scene, camera);
})();
2015-05-12 11:29:01 +02:00
function applyMouseControls (renderer, camera, center, maxDistance) {
"use strict";
//TODO
//impliment touch controls
//windows mouse wheel fix
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();
}
2015-04-24 16:12:48 +02:00
</script>
</body>
</html>