mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 11:33:49 +01:00
cleaned up code
This commit is contained in:
parent
b6884b6266
commit
5015d31bce
@ -61,21 +61,23 @@ var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
|
|||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
|
(function () {
|
||||||
var slicer = new D3D.Slicer().setGeometry(geometry);
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||||
//var slices = slicer.slice(200, 0.2);
|
var slices = slicer.slice(200, 0.2);
|
||||||
var slices = slicer.slice(1, 1);
|
//var slices = slicer.slice(1, 1);
|
||||||
|
|
||||||
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
||||||
|
|
||||||
|
//error at layer 0;
|
||||||
|
//maybe because of geomety
|
||||||
|
var layer = 4;
|
||||||
|
|
||||||
var shapes = [];
|
var shapes = [];
|
||||||
|
|
||||||
for (var layer = 0; layer < slices.length; layer ++) {
|
|
||||||
var slice = slices[layer];
|
var slice = slices[layer];
|
||||||
|
|
||||||
for (var i = 0; i < slice.length; i ++) {
|
for (var i = 0; i < slice.length; i ++) {
|
||||||
var shape = new CAL.Shape({shapeColor: false});
|
var shape = new CAL.Shape({shapeColor: false});
|
||||||
CAL.Scene.add(shape);
|
|
||||||
shapes.push(shape);
|
shapes.push(shape);
|
||||||
|
|
||||||
for (var j = 0; j < slice[i].length; j ++) {
|
for (var j = 0; j < slice[i].length; j ++) {
|
||||||
@ -83,15 +85,13 @@ for (var layer = 0; layer < slices.length; layer ++) {
|
|||||||
shape.addPoint(new CAL.Vector((point.x-100) * 5 + 200, (point.y-100) * 5 + 200));
|
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 ++) {
|
for (var i = 0; i < shapes.length; i ++) {
|
||||||
var shape = shapes[i];
|
var shape = shapes[i];
|
||||||
|
|
||||||
|
shape.draw(CAL.Scene.context);
|
||||||
|
CAL.Scene.context.strokeStyle = "#FF0000";
|
||||||
|
|
||||||
for (var j = 0; j < shape.points.length; j ++) {
|
for (var j = 0; j < shape.points.length; j ++) {
|
||||||
var normal = shape.getNormal(j).scale(20);
|
var normal = shape.getNormal(j).scale(20);
|
||||||
var point = shape.points[j];
|
var point = shape.points[j];
|
||||||
@ -99,6 +99,7 @@ for (var i = 0; i < shapes.length; i ++) {
|
|||||||
normal.draw(CAL.Scene.context, point.x, point.y);
|
normal.draw(CAL.Scene.context, point.x, point.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
(function animate () {
|
(function animate () {
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
@ -87,7 +87,6 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var plane = new THREE.Plane();
|
var plane = new THREE.Plane();
|
||||||
|
|
||||||
for (var z = 0; z < height; z += step) {
|
for (var z = 0; z < height; z += step) {
|
||||||
z += 1;
|
|
||||||
plane.set(new THREE.Vector3(0, -1, 0), z);
|
plane.set(new THREE.Vector3(0, -1, 0), z);
|
||||||
|
|
||||||
var slice = [];
|
var slice = [];
|
||||||
@ -133,7 +132,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var normal = new THREE.Vector2().copy(intersection).sub(intersections[index]).normal().normalize();
|
var normal = new THREE.Vector2().copy(intersection).sub(intersections[index]).normal().normalize();
|
||||||
var faceNormal = faceNormals[j];
|
var faceNormal = faceNormals[j];
|
||||||
|
|
||||||
if (normal.dot(faceNormal) < 0) {
|
if (normal.dot(faceNormal) > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user