Doodle3D-Slicer/slice_test.html

211 lines
5.2 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-06-13 20:09:44 +02:00
<script src='three.js-master/examples/js/loaders/STLLoader.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>
<script src="src/gcode.js"></script>
2015-04-24 21:32:39 +02:00
<script src="src/slicer.js"></script>
2015-06-11 14:34:30 +02:00
<script src="src/slice.js"></script>
2015-04-24 16:12:48 +02:00
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-07-10 18:04:10 +02:00
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, scene;
2015-05-13 17:37:52 +02:00
2015-05-19 19:58:13 +02:00
function init () {
"use strict";
2015-07-10 18:04:10 +02:00
scene = createScene();
2015-05-13 17:37:52 +02:00
2015-05-19 19:58:13 +02:00
var localIp = location.hash.substring(1);
2015-07-10 18:04:10 +02:00
doodleBox = new D3D.Box(localIp).init();
2015-05-13 17:37:52 +02:00
2015-07-10 18:04:10 +02:00
var printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS["ultimaker2go"]);
2015-05-13 17:37:52 +02:00
2015-05-19 19:58:13 +02:00
var loader = new THREE.STLLoader();
2015-06-12 15:58:26 +02:00
loader.load('models/pokemon/pikachu.stl', function (geometry) {
2015-06-09 11:08:06 +02:00
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
2015-05-26 11:44:15 +02:00
//var geometry = new THREE.SphereGeometry(10, 20, 10);
2015-07-26 15:24:35 +02:00
var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
2015-05-19 19:58:13 +02:00
/*
var geometry = (function () {
"use strict";
2015-05-13 17:37:52 +02:00
2015-05-19 19:58:13 +02:00
var circle = new THREE.Shape();
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
2015-05-13 17:37:52 +02:00
2015-05-19 19:58:13 +02:00
var hole = new THREE.Path();
hole.absarc(0, 0, 5, 0, Math.PI*2, true );
2015-05-13 13:18:37 +02:00
2015-05-19 19:58:13 +02:00
circle.holes.push(hole);
2015-05-06 15:06:04 +02:00
2015-05-19 19:58:13 +02:00
var matrix = new THREE.Matrix4();
matrix.makeRotationX(Math.PI*1.5);
2015-05-19 19:58:13 +02:00
var geometry = new THREE.ExtrudeGeometry(circle, {
amount: 10,
bevelEnabled: false,
steps: 1
});
geometry.applyMatrix(matrix);
2015-05-13 12:12:15 +02:00
2015-05-19 19:58:13 +02:00
return geometry;
})();
*/
2015-07-10 18:04:10 +02:00
2015-07-26 15:24:35 +02:00
/*var path = [{x: 60, y: 40}, {x: 60, y: 50}, {x: 60, y: 60}, {x: 80, y: 60}, {x: 40, y: 40}, {x: 50, y: 40}, {x: 10, y: 60}];
2015-07-10 18:04:10 +02:00
var geometry = new THREE.Geometry();
for (var i = 0; i < path.length; i ++) {
var point = path[i];
geometry.vertices.push(new THREE.Vector3(point.x, 0, point.y));
geometry.vertices.push(new THREE.Vector3(point.x, 50, point.y));
}
for (var i = 0; i < path.length - 1; i ++) {
var base = i * 2;
geometry.faces.push(new THREE.Face3(base, base + 1, base + 2));
geometry.faces.push(new THREE.Face3(base + 3, base + 2, base + 1));
2015-07-26 15:24:35 +02:00
}*/
2015-07-10 18:04:10 +02:00
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false, side: THREE.DoubleSide});
2015-05-19 19:58:13 +02:00
var mesh = new THREE.Mesh(geometry, material);
2015-07-26 15:24:35 +02:00
//mesh.rotation.x = -Math.PI/2;
2015-07-10 18:04:10 +02:00
//mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
mesh.position.x = 60;
mesh.position.z = 60;
mesh.updateMatrix();
2015-05-13 12:12:15 +02:00
2015-05-29 13:51:18 +02:00
scene.add(mesh);
2015-05-06 15:06:04 +02:00
2015-07-10 12:59:50 +02:00
var slicer = new D3D.Slicer().setMesh(mesh);
2015-05-01 10:06:52 +02:00
//var canvas = document.getElementById("canvas");
//var context = canvas.getContext("2d");
2015-05-12 11:29:01 +02:00
//var img = slicer.drawPaths(printer, 0, 1);
//context.drawImage(img, 0, 0);
2015-05-12 11:29:01 +02:00
2015-06-09 21:58:22 +02:00
gcode = slicer.getGCode(printer);
2015-05-19 19:58:13 +02:00
});
}
2015-05-12 11:29:01 +02:00
2015-05-19 19:58:13 +02:00
function createScene () {
var scene = new THREE.Scene();
2015-05-12 11:29:01 +02:00
2015-05-19 19:58:13 +02:00
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
renderer.setClearColor(0xffffff, 1);
2015-07-10 12:59:50 +02:00
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width / renderer.domElement.height, 1, 10000);
2015-05-19 19:58:13 +02:00
scene.add(camera);
2015-05-12 11:29:01 +02:00
2015-05-19 19:58:13 +02:00
var light = new THREE.AmbientLight(0x404040);
scene.add(light);
2015-05-12 11:29:01 +02:00
2015-05-19 19:58:13 +02:00
var directionalLight = new THREE.PointLight(0xffffff, 0.5);
camera.add(directionalLight);
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 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);
2015-05-12 11:29:01 +02:00
updateCamera();
2015-05-19 19:58:13 +02:00
});
$(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-05-20 19:10:18 +02:00
(function animate () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
})();
2015-05-19 19:58:13 +02:00
return scene;
}
//loadSettings;
(function () {
2015-06-11 14:34:30 +02:00
'use strict';
2015-05-19 19:58:13 +02:00
var loadedItems = 0;
function loaded () {
loadedItems ++;
if (loadedItems === 2) {
2015-05-26 11:44:15 +02:00
init();
2015-05-12 11:29:01 +02:00
}
2015-05-19 19:58:13 +02:00
}
2015-06-11 14:34:30 +02:00
$.ajax({
url: 'settings/user_settings.json',
dataType: 'json',
success: function (response) {
USER_SETTINGS = response;
loaded();
}
2015-05-12 11:29:01 +02:00
});
2015-06-11 14:34:30 +02:00
$.ajax({
url: 'settings/printer_settings.json',
dataType: 'json',
success: function (response) {
PRINTER_SETTINGS = response;
loaded();
}
2015-05-19 19:58:13 +02:00
});
})();
2015-04-24 16:12:48 +02:00
</script>
</body>
</html>