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

View File

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