mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-19 04:27:55 +01:00
Implemented new layer part structure
This commit is contained in:
parent
9740c254c2
commit
3a41b73c75
@ -10,6 +10,7 @@ var files = [
|
|||||||
"src/utils.js",
|
"src/utils.js",
|
||||||
"src/box.js",
|
"src/box.js",
|
||||||
"src/printer.js",
|
"src/printer.js",
|
||||||
|
"src/paths.js",
|
||||||
"src/path.js",
|
"src/path.js",
|
||||||
"src/slicer.js"
|
"src/slicer.js"
|
||||||
];
|
];
|
||||||
|
@ -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;
|
||||||
@ -4884,8 +4884,8 @@
|
|||||||
else ClipperLib.Clipper.Round = R2; // eg. browser.chrome || browser.firefox || browser.opera
|
else ClipperLib.Clipper.Round = R2; // eg. browser.chrome || browser.firefox || browser.opera
|
||||||
ClipperLib.Clipper.TopX = function (edge, currentY)
|
ClipperLib.Clipper.TopX = function (edge, currentY)
|
||||||
{
|
{
|
||||||
//if (edge.Bot == edge.Curr) alert ("edge.Bot = edge.Curr");
|
//if (edge.Bot == edge.Curr) console.log ("edge.Bot = edge.Curr");
|
||||||
//if (edge.Bot == edge.Top) alert ("edge.Bot = edge.Top");
|
//if (edge.Bot == edge.Top) console.log ("edge.Bot = edge.Top");
|
||||||
if (currentY == edge.Top.Y)
|
if (currentY == edge.Top.Y)
|
||||||
return edge.Top.X;
|
return edge.Top.X;
|
||||||
return edge.Bot.X + ClipperLib.Clipper.Round(edge.Dx * (currentY - edge.Bot.Y));
|
return edge.Bot.X + ClipperLib.Clipper.Round(edge.Dx * (currentY - edge.Bot.Y));
|
||||||
@ -6596,7 +6596,7 @@
|
|||||||
}
|
}
|
||||||
catch (err)
|
catch (err)
|
||||||
{
|
{
|
||||||
alert(err.message);
|
console.log(err.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
BIN
models/cube.stl
Normal file
BIN
models/cube.stl
Normal file
Binary file not shown.
@ -11,6 +11,7 @@
|
|||||||
<script src="src/utils.js"></script>
|
<script src="src/utils.js"></script>
|
||||||
<script src="src/box.js"></script>
|
<script src="src/box.js"></script>
|
||||||
<script src="src/printer.js"></script>
|
<script src="src/printer.js"></script>
|
||||||
|
<script src="src/paths.js"></script>
|
||||||
<script src="src/path.js"></script>
|
<script src="src/path.js"></script>
|
||||||
<script src="src/slicer.js"></script>
|
<script src="src/slicer.js"></script>
|
||||||
|
|
||||||
@ -69,7 +70,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();
|
||||||
@ -115,20 +116,29 @@ mesh.position.z = 100;
|
|||||||
//scene.add(mesh);
|
//scene.add(mesh);
|
||||||
|
|
||||||
var loader = new THREE.STLLoader();
|
var loader = new THREE.STLLoader();
|
||||||
loader.load("models/cubes.stl", function (geometry) {
|
loader.load("models/cube.stl", function (geometry) {
|
||||||
|
var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||||
|
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
|
|
||||||
mesh.position.x = 100;
|
mesh.position.x = 100;
|
||||||
mesh.position.z = 100;
|
mesh.position.z = 100;
|
||||||
|
/*
|
||||||
mesh.rotation.x = -Math.PI/2;
|
mesh.rotation.x = -Math.PI/2;
|
||||||
mesh.scale.x = mesh.scale.y = mesh.scale.z = 3;
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 3;
|
||||||
//mesh is lifted a little bit...
|
//mesh is lifted a little bit...
|
||||||
mesh.position.y = -0.6552429199218741;
|
mesh.position.y = -0.6552429199218741;
|
||||||
|
*/
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
var slicer = new D3D.Slicer().setMesh(mesh);
|
||||||
|
|
||||||
|
var canvas = document.getElementById("canvas");
|
||||||
|
var context = canvas.getContext("2d");
|
||||||
|
|
||||||
|
var img = slicer.drawPaths(printer, 0, 1);
|
||||||
|
context.drawImage(img, 0, 0);
|
||||||
|
|
||||||
gcode = slicer.getGcode(printer);
|
gcode = slicer.getGcode(printer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
99
src/path.js
99
src/path.js
@ -9,98 +9,93 @@
|
|||||||
D3D.Path = function (path, closed) {
|
D3D.Path = function (path, closed) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.path = path || [];
|
Array.call(this);
|
||||||
|
|
||||||
|
this.setPath(path || []);
|
||||||
|
|
||||||
this.closed = (closed !== undefined) ? closed : true;
|
this.closed = (closed !== undefined) ? closed : true;
|
||||||
};
|
};
|
||||||
|
D3D.Path.prototype = Object.create(Array.prototype);
|
||||||
D3D.Path.prototype.setPath = function (path) {
|
D3D.Path.prototype.setPath = function (path) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.path = path;
|
for (var i = 0; i < path.length; i ++) {
|
||||||
|
this.push(path[i]);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
D3D.Path.prototype.clip = function (path, type) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var solution = new ClipperLib.Paths();
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
clipper.AddPath(this, ClipperLib.PolyType.ptSubject, true);
|
||||||
|
if (path instanceof D3D.Path) {
|
||||||
|
clipper.AddPath(path, ClipperLib.PolyType.ptClip, true);
|
||||||
|
}
|
||||||
|
else if (path instanceof D3D.Paths) {
|
||||||
|
clipper.AddPaths(path, ClipperLib.PolyType.ptClip, true);
|
||||||
|
}
|
||||||
|
clipper.Execute(type, solution);
|
||||||
|
|
||||||
|
return new D3D.Paths(solution, this.closed);
|
||||||
|
};
|
||||||
D3D.Path.prototype.union = function (path) {
|
D3D.Path.prototype.union = function (path) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var solution = new ClipperLib.Paths();
|
return this.clip(path, ClipperLib.ClipType.ctUnion);
|
||||||
|
|
||||||
var clipper = new ClipperLib.Clipper();
|
|
||||||
clipper.AddPaths(this.path, ClipperLib.PolyType.ptSubject, this.closed);
|
|
||||||
clipper.AddPaths(path.path, ClipperLib.PolyType.ptClip, path.closed);
|
|
||||||
clipper.Execute(ClipperLib.ClipType.ctUnion, solution);
|
|
||||||
|
|
||||||
return new D3D.Path(solution, this.closed);
|
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.difference = function (path) {
|
D3D.Path.prototype.difference = function (path) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var solution = new ClipperLib.Paths();
|
return this.clip(path, ClipperLib.ClipType.ctDifference);
|
||||||
|
|
||||||
var clipper = new ClipperLib.Clipper();
|
|
||||||
clipper.AddPaths(this.path, ClipperLib.PolyType.ptSubject, this.closed);
|
|
||||||
clipper.AddPaths(path.path, ClipperLib.PolyType.ptClip, path.closed);
|
|
||||||
clipper.Execute(ClipperLib.ClipType.ctDifference, solution);
|
|
||||||
|
|
||||||
return new D3D.Path(solution, this.closed);
|
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.intersect = function (path) {
|
D3D.Path.prototype.intersect = function (path) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var solution = new ClipperLib.Paths();
|
return this.clip(path, ClipperLib.ClipType.ctIntersection);
|
||||||
|
|
||||||
var clipper = new ClipperLib.Clipper();
|
|
||||||
clipper.AddPaths(this.path, ClipperLib.PolyType.ptSubject, this.closed);
|
|
||||||
clipper.AddPaths(path.path, ClipperLib.PolyType.ptClip, path.closed);
|
|
||||||
clipper.Execute(ClipperLib.ClipType.ctIntersection, solution);
|
|
||||||
|
|
||||||
return new D3D.Path(solution, this.closed);
|
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.xor = function () {
|
D3D.Path.prototype.xor = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var solution = new ClipperLib.Paths();
|
return this.clip(path, ClipperLib.ClipType.ctXor);
|
||||||
|
|
||||||
var clipper = new ClipperLib.Clipper();
|
|
||||||
clipper.AddPaths(this.path, ClipperLib.PolyType.ptSubject, this.closed);
|
|
||||||
clipper.AddPaths(path.path, ClipperLib.PolyType.ptClip, path.closed);
|
|
||||||
clipper.Execute(ClipperLib.ClipType.ctXor, solution);
|
|
||||||
|
|
||||||
return new D3D.Path(solution, this.closed);
|
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.offset = function (offset) {
|
D3D.Path.prototype.offset = function (offset) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var solution = new ClipperLib.Paths();
|
var solution = new ClipperLib.Path();
|
||||||
var co = new ClipperLib.ClipperOffset(1, 1);
|
var co = new ClipperLib.ClipperOffset(2, 0.25);
|
||||||
co.AddPaths(this.path, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon);
|
co.AddPath(this, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon);
|
||||||
co.Execute(solution, offset);
|
co.Execute(solution, offset);
|
||||||
|
|
||||||
return new D3D.Path(solution, this.closed);
|
return new D3D.Path(solution[0], this.closed);
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.scaleUp = function (factor) {
|
D3D.Path.prototype.scaleUp = function (factor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var path = ClipperLib.JS.ScaleUpPaths(this.path, factor);
|
ClipperLib.JS.ScaleUpPath(this, factor);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.scaleDown = function (factor) {
|
D3D.Path.prototype.scaleDown = function (factor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var path = ClipperLib.JS.ScaleDownPaths(this.path, factor);
|
var path = ClipperLib.JS.ScaleDownPath(this, factor);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.tresholdArea = function (minArea) {
|
D3D.Path.prototype.tresholdArea = function (minArea) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
for (var i = 0; i < this.path.length; i ++) {
|
for (var i = 0; i < this.length; i ++) {
|
||||||
var shape = this.path[i];
|
var shape = this[i];
|
||||||
|
|
||||||
var area = ClipperLib.Clipper.Area(shape);
|
var area = ClipperLib.Clipper.Area(shape);
|
||||||
|
|
||||||
if (area < minArea) {
|
if (area < minArea) {
|
||||||
this.path.splice(i, 1);
|
this.splice(i, 1);
|
||||||
i --;
|
i --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,27 +105,19 @@ D3D.Path.prototype.tresholdArea = function (minArea) {
|
|||||||
D3D.Path.prototype.area = function () {
|
D3D.Path.prototype.area = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var areas = [];
|
return ClipperLib.Clipper.Area(this);
|
||||||
|
|
||||||
for (var i = 0; i < this.path.length; i ++) {
|
|
||||||
var shape = this.path[i];
|
|
||||||
|
|
||||||
areas.push(ClipperLib.Clipper.Area(shape))
|
|
||||||
}
|
|
||||||
|
|
||||||
return areas;
|
|
||||||
};
|
};
|
||||||
D3D.Path.prototype.join = function (path) {
|
D3D.Path.prototype.join = function (path) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.path = this.path.concat(path.path);
|
this.setPath(this.concat(path));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
D3D.Path.prototype.clone = function () {
|
D3D.Path.prototype.clone = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var path = ClipperLib.JS.Clone(this.path);
|
var path = ClipperLib.JS.Clone(this);
|
||||||
|
|
||||||
return new D3D.Path(path, this.closed);
|
return new D3D.Path(path, this.closed);
|
||||||
}
|
}
|
||||||
@ -138,8 +125,8 @@ D3D.Path.prototype.draw = function (context, color) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
context.strokeStyle = color;
|
context.strokeStyle = color;
|
||||||
for (var i = 0; i < this.path.length; i ++) {
|
for (var i = 0; i < this.length; i ++) {
|
||||||
var shape = this.path[i];
|
var shape = this[i];
|
||||||
|
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
var length = this.closed ? (shape.length + 1) : shape.length;
|
var length = this.closed ? (shape.length + 1) : shape.length;
|
||||||
|
151
src/paths.js
Normal file
151
src/paths.js
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
/******************************************************
|
||||||
|
*
|
||||||
|
* Path
|
||||||
|
*
|
||||||
|
* Abstraction layer for annoying clipper js
|
||||||
|
*
|
||||||
|
******************************************************/
|
||||||
|
|
||||||
|
D3D.Paths = function (paths) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Array.call(this);
|
||||||
|
|
||||||
|
this.setPaths(paths || []);
|
||||||
|
|
||||||
|
this.closed = (this[0] !== undefined) ? this[0].closed : true;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype = Object.create(Array.prototype);
|
||||||
|
D3D.Paths.prototype.setPaths = function (paths) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
for (var i = 0; i < paths.length; i ++) {
|
||||||
|
var path = paths[i];
|
||||||
|
if (!(path instanceof D3D.Path)) {
|
||||||
|
//console.log("Path not instance of D3D.Path, converting path to D3D.Path");
|
||||||
|
path = new D3D.Path(path, true);
|
||||||
|
}
|
||||||
|
this.push(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.clip = function (path, type) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var solution = new ClipperLib.Paths();
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
clipper.AddPaths(this, ClipperLib.PolyType.ptSubject, this.closed);
|
||||||
|
if (path instanceof D3D.Paths) {
|
||||||
|
clipper.AddPaths(path, ClipperLib.PolyType.ptClip, path.closed);
|
||||||
|
}
|
||||||
|
else if (path instanceof D3D.Path) {
|
||||||
|
clipper.AddPath(path, ClipperLib.PolyType.ptClip, path.closed);
|
||||||
|
}
|
||||||
|
clipper.Execute(type, solution);
|
||||||
|
|
||||||
|
return new D3D.Paths(solution);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.union = function (path) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return this.clip(path, ClipperLib.ClipType.ctUnion);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.difference = function (path) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return this.clip(path, ClipperLib.ClipType.ctDifference);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.intersect = function (path) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return this.clip(path, ClipperLib.ClipType.ctIntersection);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.xor = function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return this.clip(path, ClipperLib.ClipType.ctXor);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.offset = function (offset) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var solution = new ClipperLib.Paths();
|
||||||
|
var co = new ClipperLib.ClipperOffset(1, 1);
|
||||||
|
co.AddPaths(this, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon);
|
||||||
|
co.Execute(solution, offset);
|
||||||
|
|
||||||
|
return new D3D.Paths(solution);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.scaleUp = function (factor) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var path = ClipperLib.JS.ScaleUpPaths(this, factor);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.scaleDown = function (factor) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var path = ClipperLib.JS.ScaleDownPaths(this, factor);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.tresholdArea = function (minArea) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
for (var i = 0; i < this.length; i ++) {
|
||||||
|
var shape = this[i];
|
||||||
|
|
||||||
|
var area = ClipperLib.Clipper.Area(shape);
|
||||||
|
|
||||||
|
if (area < minArea) {
|
||||||
|
this.splice(i, 1);
|
||||||
|
i --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return areas;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.area = function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
return ClipperLib.Clipper.Area(this);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.join = function (path) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
for (var i = 0; i < path.length; i ++) {
|
||||||
|
this.push(path[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.clone = function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var paths = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < this.length; i ++) {
|
||||||
|
paths.push(this[i].clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
return new D3D.Paths(paths);
|
||||||
|
};
|
||||||
|
D3D.Paths.prototype.draw = function (context, color) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
context.strokeStyle = color;
|
||||||
|
for (var i = 0; i < this.length; i ++) {
|
||||||
|
var shape = this[i];
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
var length = this.closed ? (shape.length + 1) : shape.length;
|
||||||
|
for (var j = 0; j < length; j ++) {
|
||||||
|
var point = shape[j % shape.length];
|
||||||
|
|
||||||
|
context.lineTo(point.X*2, point.Y*2);
|
||||||
|
}
|
||||||
|
context.stroke();
|
||||||
|
}
|
||||||
|
};
|
113
src/slicer.js
113
src/slicer.js
@ -64,27 +64,24 @@ 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];
|
||||||
var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize();
|
|
||||||
|
|
||||||
//check for only adding unique lines
|
if (!(face.normal.y === 1 || face.normal.y === -1)) {
|
||||||
//returns index of said line
|
var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize();
|
||||||
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)
|
//check for only adding unique lines
|
||||||
this.lines[a].connects.push(b, c);
|
//returns index of said line
|
||||||
this.lines[b].connects.push(c, a);
|
var a = addLine(face.a, face.b);
|
||||||
this.lines[c].connects.push(a, b);
|
var b = addLine(face.b, face.c);
|
||||||
|
var c = addLine(face.c, face.a);
|
||||||
|
|
||||||
this.lines[a].normals.push(normal);
|
//set connecting lines (based on face)
|
||||||
this.lines[b].normals.push(normal);
|
this.lines[a].connects.push(b, c);
|
||||||
this.lines[c].normals.push(normal);
|
this.lines[b].connects.push(c, a);
|
||||||
|
this.lines[c].connects.push(a, b);
|
||||||
|
|
||||||
if (face.normal.y === 1 || face.normal.y === -1) {
|
this.lines[a].normals.push(normal);
|
||||||
this.lines[a].ignore ++;
|
this.lines[b].normals.push(normal);
|
||||||
this.lines[b].ignore ++;
|
this.lines[c].normals.push(normal);
|
||||||
this.lines[c].ignore ++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -99,14 +96,12 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var min = Math.ceil(Math.min(line.line.start.y, line.line.end.y) / step);
|
var min = Math.ceil(Math.min(line.line.start.y, line.line.end.y) / step);
|
||||||
var max = Math.floor(Math.max(line.line.start.y, line.line.end.y) / step);
|
var max = Math.floor(Math.max(line.line.start.y, line.line.end.y) / step);
|
||||||
|
|
||||||
if (line.ignore < 2) {
|
for (var layerIndex = min; layerIndex <= max; layerIndex ++) {
|
||||||
for (var layerIndex = min; layerIndex <= max; layerIndex ++) {
|
if (layerIndex >= 0) {
|
||||||
if (layerIndex >= 0) {
|
if (layersIntersections[layerIndex] === undefined) {
|
||||||
if (layersIntersections[layerIndex] === undefined) {
|
layersIntersections[layerIndex] = [];
|
||||||
layersIntersections[layerIndex] = [];
|
|
||||||
}
|
|
||||||
layersIntersections[layerIndex].push(i);
|
|
||||||
}
|
}
|
||||||
|
layersIntersections[layerIndex].push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,12 +125,12 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var done = [];
|
var done = [];
|
||||||
var slice = [];
|
var slice = new D3D.Paths([], true);
|
||||||
for (var i = 0; i < layerIntersections.length; i ++) {
|
for (var i = 0; i < layerIntersections.length; i ++) {
|
||||||
var index = layerIntersections[i];
|
var index = layerIntersections[i];
|
||||||
|
|
||||||
if (done.indexOf(index) === -1) {
|
if (done.indexOf(index) === -1) {
|
||||||
var shape = [];
|
var shape = new D3D.Path([], true);
|
||||||
|
|
||||||
while (index !== -1) {
|
while (index !== -1) {
|
||||||
var intersection = intersections[index];
|
var intersection = intersections[index];
|
||||||
@ -198,8 +193,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
|
|
||||||
//stop when ther are no intersects
|
//stop when ther are no intersects
|
||||||
if (slice.length > 0) {
|
if (slice.length > 0) {
|
||||||
slices.push(new D3D.Path(slice, true));
|
slices.push(slice);
|
||||||
//slices.push(slice);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
@ -228,36 +222,50 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
|||||||
for (var layer = 0; layer < slices.length; layer ++) {
|
for (var layer = 0; layer < slices.length; layer ++) {
|
||||||
var slice = slices[layer];
|
var slice = slices[layer];
|
||||||
|
|
||||||
var outerLayer = slice.clone();
|
var insets = new D3D.Paths();
|
||||||
outerLayer.scaleUp(scale);
|
var fills = new D3D.Paths();
|
||||||
|
var outerLayers = new D3D.Paths();
|
||||||
|
|
||||||
var insets = new D3D.Path();
|
var downFill = (layer - skinCount >= 0) ? slices[layer - skinCount] : new D3D.Paths();
|
||||||
for (var offset = wallThickness; offset <= shellThickness; offset += wallThickness) {
|
var upFill = (layer + skinCount < slices.length) ? slices[layer + skinCount] : new D3D.Paths();
|
||||||
var inset = outerLayer.offset(-offset);
|
//var surroundingLayer = downFill.intersect(upFill);
|
||||||
|
var surroundingLayer = upFill.clone().scaleUp(scale);
|
||||||
|
//D3D.Paths surroundingLayer
|
||||||
|
|
||||||
insets.join(inset);
|
for (var i = 0; i < slice.length; i ++) {
|
||||||
}
|
var part = slice[i];
|
||||||
|
|
||||||
var fillArea = (inset || outerLayer).offset(-wallThickness/2);
|
var outerLayer = part.clone();
|
||||||
|
outerLayer.scaleUp(scale);
|
||||||
|
|
||||||
var downFill = (layer - skinCount >= 0) ? slices[layer - skinCount] : new D3D.Path();
|
for (var offset = wallThickness; offset <= shellThickness; offset += wallThickness) {
|
||||||
var upFill = (layer + skinCount < slices.length) ? slices[layer + skinCount] : new D3D.Path();
|
var inset = outerLayer.offset(-offset);
|
||||||
var highFillArea = fillArea.difference(downFill.intersect(upFill).scaleUp(scale));
|
|
||||||
|
|
||||||
var lowFillArea = fillArea.difference(highFillArea);
|
insets.push(inset);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fillArea = (inset || outerLayer).offset(-wallThickness/2);
|
||||||
|
|
||||||
|
var highFillArea = fillArea.difference(surroundingLayer);
|
||||||
|
|
||||||
|
var lowFillArea = fillArea.difference(highFillArea);
|
||||||
|
|
||||||
|
var fill = new D3D.Paths([]);
|
||||||
|
|
||||||
|
fills.join(lowFillTemplate.intersect(lowFillArea));
|
||||||
|
|
||||||
var fill = new D3D.Path([], false);
|
|
||||||
fill.join(lowFillTemplate.intersect(lowFillArea));
|
|
||||||
if (highFillArea.path.length > 0) {
|
|
||||||
var highFillTemplate = this.getFillTemplate(dimensionsZ, wallThickness, (layer % 2 === 0), (layer % 2 === 1));
|
var highFillTemplate = this.getFillTemplate(dimensionsZ, wallThickness, (layer % 2 === 0), (layer % 2 === 1));
|
||||||
var highFillStrokes = highFillArea;
|
fills.join(highFillTemplate.intersect(highFillArea));
|
||||||
fill.join(highFillTemplate.intersect(highFillStrokes));
|
|
||||||
|
console.log(highFillTemplate.intersect(highFillArea));
|
||||||
|
|
||||||
|
outerLayers.push(outerLayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.push({
|
data.push({
|
||||||
outerLayer: outerLayer.scaleDown(scale),
|
outerLayer: outerLayers.scaleDown(scale),
|
||||||
insets: insets.scaleDown(scale),
|
insets: insets.scaleDown(scale),
|
||||||
fill: fill.scaleDown(scale)
|
fill: fills.scaleDown(scale)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,17 +278,17 @@ D3D.Slicer.prototype.getFillTemplate = function (dimension, size, even, uneven)
|
|||||||
|
|
||||||
if (even) {
|
if (even) {
|
||||||
for (var length = 0; length <= dimension; length += size) {
|
for (var length = 0; length <= dimension; length += size) {
|
||||||
paths.push([{X: length, Y: 0}, {X: length, Y: dimension}]);
|
paths.push(new D3D.Path([{X: length, Y: 0}, {X: length, Y: dimension}], false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (uneven) {
|
if (uneven) {
|
||||||
for (var length = 0; length <= dimension; length += size) {
|
for (var length = 0; length <= dimension; length += size) {
|
||||||
paths.push([{X: 0, Y: length}, {X: dimension, Y: length}]);
|
paths.push(new D3D.Path([{X: 0, Y: length}, {X: dimension, Y: length}], false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//return paths;
|
//return paths;
|
||||||
return new D3D.Path(paths, false);
|
return new D3D.Paths(paths);
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -302,8 +310,8 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
|||||||
function sliceToGcode (slice) {
|
function sliceToGcode (slice) {
|
||||||
var gcode = [];
|
var gcode = [];
|
||||||
|
|
||||||
for (var i = 0; i < slice.path.length; i ++) {
|
for (var i = 0; i < slice.length; i ++) {
|
||||||
var shape = slice.path[i];
|
var shape = slice[i];
|
||||||
|
|
||||||
var previousPoint;
|
var previousPoint;
|
||||||
|
|
||||||
@ -429,6 +437,7 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
var data = this.slicesToData(slices, printer);
|
var data = this.slicesToData(slices, printer);
|
||||||
var end = new Date().getTime();
|
var end = new Date().getTime();
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
console.log("Data: " + (end - start) + "ms");
|
console.log("Data: " + (end - start) + "ms");
|
||||||
|
|
||||||
//return data;
|
//return data;
|
||||||
|
Loading…
Reference in New Issue
Block a user