mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2025-01-20 16:15:11 +01:00
changest converting (x, y z) to (z, x) instead of (x, z)
see https://github.com/Doodle3D/Doodle3D-Slicer/issues/2
This commit is contained in:
parent
a2e7bf4d85
commit
26f13eb998
@ -2876,8 +2876,8 @@
|
|||||||
};
|
};
|
||||||
ClipperLib.ClipperBase.prototype.AddPaths = function (ppg, polyType, closed)
|
ClipperLib.ClipperBase.prototype.AddPaths = function (ppg, polyType, closed)
|
||||||
{
|
{
|
||||||
// console.warn("-------------------------------------------");
|
// console.log("-------------------------------------------");
|
||||||
// console.warn(JSON.stringify(ppg));
|
// console.log(JSON.stringify(ppg));
|
||||||
var result = false;
|
var result = false;
|
||||||
for (var i = 0, ilen = ppg.length; i < ilen; ++i)
|
for (var i = 0, ilen = ppg.length; i < ilen; ++i)
|
||||||
if (this.AddPath(ppg[i], polyType, closed))
|
if (this.AddPath(ppg[i], polyType, closed))
|
||||||
@ -3100,7 +3100,7 @@
|
|||||||
if (this.m_ExecuteLocked)
|
if (this.m_ExecuteLocked)
|
||||||
return false;
|
return false;
|
||||||
if (this.m_HasOpenPaths)
|
if (this.m_HasOpenPaths)
|
||||||
//ClipperLib.Error("Error: PolyTree struct is need for open path clipping.");
|
ClipperLib.Error("Error: PolyTree struct is need for open path clipping.");
|
||||||
this.m_ExecuteLocked = true;
|
this.m_ExecuteLocked = true;
|
||||||
ClipperLib.Clear(solution);
|
ClipperLib.Clear(solution);
|
||||||
this.m_SubjFillType = subjFillType;
|
this.m_SubjFillType = subjFillType;
|
||||||
@ -3185,7 +3185,7 @@
|
|||||||
if (this.m_Scanbeam === null)
|
if (this.m_Scanbeam === null)
|
||||||
break;
|
break;
|
||||||
var topY = this.PopScanbeam();
|
var topY = this.PopScanbeam();
|
||||||
//console.warn("botY:" + botY + ", topY:" + topY);
|
//console.log("botY:" + botY + ", topY:" + topY);
|
||||||
if (!this.ProcessIntersections(botY, topY))
|
if (!this.ProcessIntersections(botY, topY))
|
||||||
return false;
|
return false;
|
||||||
this.ProcessEdgesAtTopOfScanbeam(topY);
|
this.ProcessEdgesAtTopOfScanbeam(topY);
|
||||||
@ -4747,7 +4747,7 @@
|
|||||||
return;
|
return;
|
||||||
//prepare for sorting ...
|
//prepare for sorting ...
|
||||||
var e = this.m_ActiveEdges;
|
var e = this.m_ActiveEdges;
|
||||||
//console.warn(JSON.stringify(JSON.decycle( e )));
|
//console.log(JSON.stringify(JSON.decycle( e )));
|
||||||
this.m_SortedEdges = e;
|
this.m_SortedEdges = e;
|
||||||
while (e !== null)
|
while (e !== null)
|
||||||
{
|
{
|
||||||
@ -4766,13 +4766,13 @@
|
|||||||
{
|
{
|
||||||
var eNext = e.NextInSEL;
|
var eNext = e.NextInSEL;
|
||||||
var pt = new ClipperLib.IntPoint();
|
var pt = new ClipperLib.IntPoint();
|
||||||
//console.warn("e.Curr.X: " + e.Curr.X + " eNext.Curr.X" + eNext.Curr.X);
|
//console.log("e.Curr.X: " + e.Curr.X + " eNext.Curr.X" + eNext.Curr.X);
|
||||||
if (e.Curr.X > eNext.Curr.X)
|
if (e.Curr.X > eNext.Curr.X)
|
||||||
{
|
{
|
||||||
if (!this.IntersectPoint(e, eNext, pt) && e.Curr.X > eNext.Curr.X + 1)
|
if (!this.IntersectPoint(e, eNext, pt) && e.Curr.X > eNext.Curr.X + 1)
|
||||||
{
|
{
|
||||||
//console.warn("e.Curr.X: "+JSON.stringify(JSON.decycle( e.Curr.X )));
|
//console.log("e.Curr.X: "+JSON.stringify(JSON.decycle( e.Curr.X )));
|
||||||
//console.warn("eNext.Curr.X+1: "+JSON.stringify(JSON.decycle( eNext.Curr.X+1)));
|
//console.log("eNext.Curr.X+1: "+JSON.stringify(JSON.decycle( eNext.Curr.X+1)));
|
||||||
ClipperLib.Error("Intersection error");
|
ClipperLib.Error("Intersection error");
|
||||||
}
|
}
|
||||||
if (pt.Y > botY)
|
if (pt.Y > botY)
|
||||||
@ -6469,7 +6469,7 @@
|
|||||||
if (solution.length > 0)
|
if (solution.length > 0)
|
||||||
solution.splice(0, 1);
|
solution.splice(0, 1);
|
||||||
}
|
}
|
||||||
//console.warn(JSON.stringify(solution));
|
//console.log(JSON.stringify(solution));
|
||||||
}
|
}
|
||||||
else // function (polytree, delta)
|
else // function (polytree, delta)
|
||||||
{
|
{
|
||||||
|
BIN
models/d20.stl
Normal file
BIN
models/d20.stl
Normal file
Binary file not shown.
BIN
models/pikachu.stl
Normal file
BIN
models/pikachu.stl
Normal file
Binary file not shown.
@ -30,7 +30,6 @@ canvas {border: 1px solid black;}
|
|||||||
//geimplimenteerd worden in de doodlebox?
|
//geimplimenteerd worden in de doodlebox?
|
||||||
var printerConfig = {
|
var printerConfig = {
|
||||||
"printer.baudrate": "115200", //wat is dit?
|
"printer.baudrate": "115200", //wat is dit?
|
||||||
"printer.bed.temperature": 70,
|
|
||||||
"printer.bottomFlowRate": 1.0,
|
"printer.bottomFlowRate": 1.0,
|
||||||
"printer.bottomLayerSpeed": 35,
|
"printer.bottomLayerSpeed": 35,
|
||||||
"printer.dimensions.x": 200,
|
"printer.dimensions.x": 200,
|
||||||
@ -69,7 +68,7 @@ var printerConfig = {
|
|||||||
var printer = new D3D.Printer(printerConfig);
|
var printer = new D3D.Printer(printerConfig);
|
||||||
|
|
||||||
var localIp = location.hash.substring(1);
|
var localIp = location.hash.substring(1);
|
||||||
var doodleBox = new D3D.Box(localIp);
|
//var doodleBox = new D3D.Box(localIp);
|
||||||
//var printer = doodleBox.printer;
|
//var printer = doodleBox.printer;
|
||||||
|
|
||||||
var scene = new THREE.Scene();
|
var scene = new THREE.Scene();
|
||||||
@ -79,47 +78,20 @@ renderer.setClearColor(0xffffff, 1);
|
|||||||
|
|
||||||
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
||||||
|
|
||||||
|
var light = new THREE.AmbientLight(0x404040);
|
||||||
|
scene.add(light );
|
||||||
|
|
||||||
|
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
||||||
|
directionalLight.position.set(0, 1, 1);
|
||||||
|
scene.add(directionalLight);
|
||||||
|
|
||||||
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
||||||
|
|
||||||
var geometry = (function () {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var circle = new THREE.Shape();
|
|
||||||
circle.absarc(0, 0, 100, 0, Math.PI*2, false);
|
|
||||||
|
|
||||||
var hole = new THREE.Path();
|
|
||||||
hole.absarc(0, 0, 15, 0, Math.PI*2, true );
|
|
||||||
|
|
||||||
circle.holes.push(hole);
|
|
||||||
|
|
||||||
var matrix = new THREE.Matrix4();
|
|
||||||
matrix.makeRotationX(Math.PI*1.5);
|
|
||||||
|
|
||||||
var geometry = new THREE.ExtrudeGeometry(circle, {
|
|
||||||
amount: 3,
|
|
||||||
bevelEnabled: false,
|
|
||||||
steps: 1
|
|
||||||
});
|
|
||||||
geometry.applyMatrix(matrix);
|
|
||||||
|
|
||||||
return geometry;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
|
||||||
var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
|
||||||
var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
|
||||||
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
|
||||||
mesh.position.x = 100;
|
|
||||||
mesh.position.z = 100;
|
|
||||||
//scene.add(mesh);
|
|
||||||
|
|
||||||
var loader = new THREE.STLLoader();
|
var loader = new THREE.STLLoader();
|
||||||
loader.load("models/stanford_bunny.stl", function (geometry) {
|
loader.load("models/stanford_bunny.stl", function (geometry) {
|
||||||
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||||
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var geometry = (function () {
|
var geometry = (function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -146,6 +118,7 @@ loader.load("models/stanford_bunny.stl", function (geometry) {
|
|||||||
})();
|
})();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
|
|
||||||
mesh.rotation.x = -Math.PI/2;
|
mesh.rotation.x = -Math.PI/2;
|
||||||
@ -154,11 +127,6 @@ loader.load("models/stanford_bunny.stl", function (geometry) {
|
|||||||
mesh.position.z = 100;
|
mesh.position.z = 100;
|
||||||
//mesh.position.y = -2;
|
//mesh.position.y = -2;
|
||||||
|
|
||||||
///*
|
|
||||||
//mesh.rotation.x = -Math.PI/2;
|
|
||||||
//mesh is lifted a little bit...
|
|
||||||
//mesh.position.y = 26.5;
|
|
||||||
//*/
|
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
var slicer = new D3D.Slicer().setMesh(mesh);
|
||||||
@ -166,7 +134,7 @@ loader.load("models/stanford_bunny.stl", function (geometry) {
|
|||||||
var canvas = document.getElementById("canvas");
|
var canvas = document.getElementById("canvas");
|
||||||
var context = canvas.getContext("2d");
|
var context = canvas.getContext("2d");
|
||||||
|
|
||||||
var img = slicer.drawPaths(printer, 7, 8);
|
var img = slicer.drawPaths(printer, 0, 1);
|
||||||
context.drawImage(img, 0, 0);
|
context.drawImage(img, 0, 0);
|
||||||
|
|
||||||
gcode = slicer.getGcode(printer);
|
gcode = slicer.getGcode(printer);
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
D3D.Slicer = function () {
|
D3D.Slicer = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.lines = [];
|
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype.setMesh = function (mesh) {
|
D3D.Slicer.prototype.setMesh = function (mesh) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -44,6 +42,7 @@ D3D.Slicer.prototype.setMesh = function (mesh) {
|
|||||||
mesh.updateMatrix();
|
mesh.updateMatrix();
|
||||||
geometry.applyMatrix(mesh.matrix);
|
geometry.applyMatrix(mesh.matrix);
|
||||||
geometry.computeFaceNormals();
|
geometry.computeFaceNormals();
|
||||||
|
geometry.computeBoundingBox();
|
||||||
|
|
||||||
this.geometry = geometry;
|
this.geometry = geometry;
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
function addLine (a, b) {
|
function addLine (a, b) {
|
||||||
|
|
||||||
//think lookup can only be b_a, a_b is only possible when face is flipped
|
//think lookup can only be b_a, a_b is only possible when face is flipped
|
||||||
var index = lineLookup[a + "_" + b] || lineLookup[b + "_" + a];
|
var index = lineLookup[b + "_" + a] || lineLookup[a + "_" + b];
|
||||||
|
|
||||||
if (index === undefined) {
|
if (index === undefined) {
|
||||||
index = self.lines.length;
|
index = self.lines.length;
|
||||||
@ -82,8 +81,8 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
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];
|
||||||
|
|
||||||
//if (face.normal.y !== 1 && face.normal.y !== -1) {
|
if (face.normal.y !== 1 && face.normal.y !== -1) {
|
||||||
var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize();
|
var normal = new THREE.Vector2().set(face.normal.z, face.normal.x).normalize();
|
||||||
|
|
||||||
//check for only adding unique lines
|
//check for only adding unique lines
|
||||||
//returns index of said line
|
//returns index of said line
|
||||||
@ -99,7 +98,7 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
this.lines[a].normals.push(normal);
|
this.lines[a].normals.push(normal);
|
||||||
this.lines[b].normals.push(normal);
|
this.lines[b].normals.push(normal);
|
||||||
this.lines[c].normals.push(normal);
|
this.lines[c].normals.push(normal);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype.slice = function (height, step) {
|
D3D.Slicer.prototype.slice = function (height, step) {
|
||||||
@ -126,6 +125,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var slices = [];
|
var slices = [];
|
||||||
|
|
||||||
for (var layer = 1; layer < layersIntersections.length-1; layer ++) {
|
for (var layer = 1; layer < layersIntersections.length-1; layer ++) {
|
||||||
|
//for (var layer = 0; layer < layersIntersections.length; layer ++) {
|
||||||
var layerIntersections = layersIntersections[layer];
|
var layerIntersections = layersIntersections[layer];
|
||||||
var y = layer*step;
|
var y = layer*step;
|
||||||
|
|
||||||
@ -138,11 +138,11 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var x = line.end.x * alpha + line.start.x * (1 - alpha);
|
var x = line.end.x * alpha + line.start.x * (1 - alpha);
|
||||||
var z = line.end.z * alpha + line.start.z * (1 - alpha);
|
var z = line.end.z * alpha + line.start.z * (1 - alpha);
|
||||||
|
|
||||||
intersections[index] = new THREE.Vector2(x, z);
|
intersections[index] = new THREE.Vector2(z, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
var done = [];
|
var done = [];
|
||||||
var slice = new D3D.Paths([], true);
|
var slice = [];
|
||||||
for (var i = 0; i < layerIntersections.length; i ++) {
|
for (var i = 0; i < layerIntersections.length; i ++) {
|
||||||
var index = layerIntersections[i];
|
var index = layerIntersections[i];
|
||||||
|
|
||||||
@ -327,6 +327,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
|||||||
else {
|
else {
|
||||||
fill = fill.optimizePath(outerLayer.lastPoint());
|
fill = fill.optimizePath(outerLayer.lastPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fill.length > 0) {
|
if (fill.length > 0) {
|
||||||
start = fill.lastPoint();
|
start = fill.lastPoint();
|
||||||
}
|
}
|
||||||
@ -353,12 +354,12 @@ D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) {
|
|||||||
var paths = new D3D.Paths([], false);
|
var paths = new D3D.Paths([], false);
|
||||||
|
|
||||||
if (even) {
|
if (even) {
|
||||||
for (var length = Math.floor(bounds.left); length <= Math.ceil(bounds.right); length += size) {
|
for (var length = Math.floor(bounds.left/size)*size; length <= Math.ceil(bounds.right/size)*size; length += size) {
|
||||||
paths.push([{X: length, Y: bounds.top}, {X: length, Y: bounds.bottom}]);
|
paths.push([{X: length, Y: bounds.top}, {X: length, Y: bounds.bottom}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uneven) {
|
if (uneven) {
|
||||||
for (var length = Math.floor(bounds.top); length <= Math.floor(bounds.bottom); length += size) {
|
for (var length = Math.floor(bounds.top/size)*size; length <= Math.floor(bounds.bottom/size)*size; length += size) {
|
||||||
paths.push([{X: bounds.left, Y: length}, {X: bounds.right, Y: length}]);
|
paths.push([{X: bounds.left, Y: length}, {X: bounds.right, Y: length}]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,13 +526,6 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
|
|
||||||
console.log("Data: " + (end - start) + "ms");
|
console.log("Data: " + (end - start) + "ms");
|
||||||
|
|
||||||
//return data;
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
//make the path more optimized for 3d printers
|
|
||||||
//make the printer follow the shortest path from line to line
|
|
||||||
//see https://github.com/Ultimaker/CuraEngine#gcode-generation
|
|
||||||
|
|
||||||
var start = new Date().getTime();
|
var start = new Date().getTime();
|
||||||
var gcode = this.dataToGcode(data, printer);
|
var gcode = this.dataToGcode(data, printer);
|
||||||
var end = new Date().getTime();
|
var end = new Date().getTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user