Doodle3D-Slicer/src/Slice.js

32 lines
547 B
JavaScript
Raw Normal View History

2016-04-21 22:14:22 +02:00
import Shape from 'Doodle3D/clipper-js';
2015-07-26 15:32:10 +02:00
export default class {
2016-04-23 09:56:25 +02:00
constructor() {
2015-07-26 15:32:10 +02:00
this.parts = [];
2015-06-11 14:34:30 +02:00
}
2016-05-09 11:41:21 +02:00
getOutline() {
2016-04-23 09:56:25 +02:00
const outLines = new Shape([], true);
2015-06-12 15:58:26 +02:00
2016-04-23 09:56:25 +02:00
for (let i = 0; i < this.parts.length; i ++) {
const part = this.parts[i];
2015-06-11 14:34:30 +02:00
2016-04-21 22:14:22 +02:00
if (part.shape.closed) {
2015-07-26 15:32:10 +02:00
outLines.join(this.parts[i].outerLine);
}
}
2015-06-11 14:34:30 +02:00
2015-07-26 15:32:10 +02:00
return outLines;
}
2016-05-09 11:41:21 +02:00
add(shape) {
2016-04-21 22:14:22 +02:00
const part = { shape };
2015-07-10 18:04:10 +02:00
2016-04-21 22:14:22 +02:00
if (shape.closed) {
part.innerLines = [];
part.outerLine = new Shape([], true);
part.fill = new Shape([], false);
2015-07-10 18:04:10 +02:00
}
2015-06-11 14:34:30 +02:00
2016-04-21 22:14:22 +02:00
this.parts.push(part);
2015-07-10 18:04:10 +02:00
}
2016-04-21 22:14:22 +02:00
}