updated slicing

moved add line to create lines; makes line lookup private
This commit is contained in:
casperlamboo 2015-05-01 16:44:05 +02:00
parent 3d34c59514
commit 948865fc07
2 changed files with 32 additions and 30 deletions

View File

@ -81,18 +81,18 @@ var geometry = (function () {
"use strict";
var circle = new THREE.Shape();
circle.absarc(0, 0, 20, 0, Math.PI*2, false);
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
var hole = new THREE.Path();
hole.absarc(0, 0, 10, 0, Math.PI*2, true );
hole.absarc(0, 0, 5, 0, Math.PI*2, true );
circle.holes.push(hole);
//circle.holes.push(hole);
var matrix = new THREE.Matrix4();
matrix.makeRotationX(Math.PI*1.5);
var geometry = new THREE.ExtrudeGeometry(circle, {
amount: 10,
amount: 3,
bevelEnabled: false,
steps: 1
});
@ -102,7 +102,7 @@ var geometry = (function () {
})();
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
//var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
//var geometry = new THREE.BoxGeometry(20, 5, 20, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(10, 10, 10);
var mesh = new THREE.Mesh(geometry, material);
@ -120,7 +120,7 @@ var gcode = slicer.getGcode(printer);
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var layer = 90;
var layer = 9;
var img = slicer.drawPaths(printer, layer, layer + 1);
context.drawImage(img, 0, 0);

View File

@ -18,7 +18,6 @@ D3D.Slicer = function () {
this.geometry;
this.lines = [];
this.lineLookup = {};
};
D3D.Slicer.prototype.setGeometry = function (geometry) {
"use strict";
@ -30,18 +29,25 @@ D3D.Slicer.prototype.setGeometry = function (geometry) {
return this;
};
D3D.Slicer.prototype.addLine = function (a, b) {
D3D.Slicer.prototype.createLines = function () {
"use strict";
this.lines = [];
var lineLookup = {};
var self = this;
function addLine (a, b) {
"use strict";
//think lookup can only be b_a, a_b is only possible when face is flipped
var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a];
var index = lineLookup[a + "_" + b] || lineLookup[b + "_" + a];
if (index === undefined) {
index = this.lines.length;
this.lineLookup[a + "_" + b] = index;
index = self.lines.length;
lineLookup[a + "_" + b] = index;
this.lines.push({
line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]),
self.lines.push({
line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]),
connects: [],
normals: []
});
@ -49,11 +55,6 @@ D3D.Slicer.prototype.addLine = function (a, b) {
return index;
};
D3D.Slicer.prototype.createLines = function () {
"use strict";
this.lines = [];
this.lineLookup = {};
for (var i = 0; i < this.geometry.faces.length; i ++) {
var face = this.geometry.faces[i];
@ -61,9 +62,9 @@ D3D.Slicer.prototype.createLines = function () {
//check for only adding unique lines
//returns index of said line
var a = this.addLine(face.a, face.b);
var b = this.addLine(face.b, face.c);
var c = this.addLine(face.c, face.a);
var a = addLine(face.a, face.b);
var b = addLine(face.b, face.c);
var c = addLine(face.c, face.a);
//set connecting lines (based on face)
@ -228,6 +229,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
innerLayer = innerLayer.concat(inset);
}
//moet fillArea wel kleiner?
var fillArea = this.getInset((inset || outerLayer), wallThickness);
var fillAbove = false;