mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 11:33:49 +01:00
9d188bb0de
only dot product is supposed to be > 0 in my code it’s < 0. some where mathmatical problem maybe fix some where in the future (it works just ugly)
111 lines
2.9 KiB
HTML
111 lines
2.9 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="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);
|
|
|
|
doodleBox.onload = function () {
|
|
"use strict";
|
|
|
|
/*var gcode = slicer.getGcode(doodleBox.printer);
|
|
|
|
var print = $(document.createElement("a")).html("Print").on("click", function () {
|
|
doodleBox.print(gcode);
|
|
});
|
|
var stop = $(document.createElement("a")).html("Stop").on("click", function () {
|
|
doodleBox.stop();
|
|
});
|
|
var download = $(document.createElement("a")).html("Download").attr({
|
|
download: "test.gcode",
|
|
href: "data:text/plain," + encodeURIComponent(gcode.join("\n"))
|
|
});
|
|
$("body").append(print, stop, download);*/
|
|
};
|
|
|
|
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);
|
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
|
//var geometry = new THREE.SphereGeometry(40, 10, 10);
|
|
var mesh = new THREE.Mesh(geometry, material);
|
|
scene.add(mesh);
|
|
|
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
|
//var slices = slicer.slice(200, 0.2);
|
|
var slices = slicer.slice(1, 1);
|
|
|
|
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
|
|
|
|
|
var shapes = [];
|
|
|
|
for (var layer = 0; layer < slices.length; layer ++) {
|
|
var slice = slices[layer];
|
|
|
|
for (var i = 0; i < slice.length; i ++) {
|
|
var shape = new CAL.Shape({shapeColor: false});
|
|
CAL.Scene.add(shape);
|
|
shapes.push(shape);
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
|
|
CAL.Scene.draw();
|
|
|
|
CAL.Scene.context.strokeStyle = "#FF0000";
|
|
|
|
for (var i = 0; i < shapes.length; i ++) {
|
|
var shape = shapes[i];
|
|
|
|
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> |