mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 13:37:58 +01:00
Merge branch 'develop'
This commit is contained in:
commit
b6d9cffbbb
@ -1,80 +0,0 @@
|
|||||||
import Shape from 'clipper-js';
|
|
||||||
import comb from '../src/sliceActions/helpers/comb.js';
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
document.body.appendChild(canvas);
|
|
||||||
canvas.width = 720;
|
|
||||||
canvas.height = 480;
|
|
||||||
const context = canvas.getContext('2d');
|
|
||||||
|
|
||||||
const outline = new Shape([[
|
|
||||||
{ x: 100, y: 100 },
|
|
||||||
{ x: 400, y: 100 },
|
|
||||||
{ x: 400, y: 150 },
|
|
||||||
{ x: 200, y: 150 },
|
|
||||||
{ x: 200, y: 200 },
|
|
||||||
{ x: 400, y: 200 },
|
|
||||||
{ x: 400, y: 250 },
|
|
||||||
{ x: 200, y: 250 },
|
|
||||||
{ x: 200, y: 300 },
|
|
||||||
{ x: 400, y: 300 },
|
|
||||||
{ x: 400, y: 400 },
|
|
||||||
{ x: 100, y: 400 }
|
|
||||||
], [
|
|
||||||
{ x: 130, y: 310 },
|
|
||||||
{ x: 130, y: 370 },
|
|
||||||
{ x: 360, y: 370 },
|
|
||||||
{ x: 360, y: 360 },
|
|
||||||
{ x: 150, y: 360 },
|
|
||||||
{ x: 150, y: 350 },
|
|
||||||
{ x: 360, y: 350 },
|
|
||||||
{ x: 360, y: 340 },
|
|
||||||
{ x: 150, y: 340 },
|
|
||||||
{ x: 150, y: 330 },
|
|
||||||
{ x: 360, y: 330 },
|
|
||||||
{ x: 360, y: 310 }
|
|
||||||
]], true, true, false);
|
|
||||||
|
|
||||||
const start = { x: 380, y: 120 };
|
|
||||||
const end = { x: 200, y: 380 };
|
|
||||||
|
|
||||||
let combPath = comb(outline, start, end);
|
|
||||||
|
|
||||||
canvas.onmousemove = (event) => {
|
|
||||||
start.x = event.x;
|
|
||||||
start.y = event.y;
|
|
||||||
|
|
||||||
combPath = comb(outline, start, end);
|
|
||||||
draw();
|
|
||||||
};
|
|
||||||
|
|
||||||
draw();
|
|
||||||
|
|
||||||
function draw() {
|
|
||||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
context.strokeStyle = 'black';
|
|
||||||
for (const path of outline.mapToLower()) {
|
|
||||||
context.beginPath();
|
|
||||||
for (const point of path) {
|
|
||||||
context.lineTo(point.x, point.y);
|
|
||||||
}
|
|
||||||
context.closePath();
|
|
||||||
context.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
context.strokeStyle = 'red';
|
|
||||||
context.beginPath();
|
|
||||||
for (const point of combPath) {
|
|
||||||
context.lineTo(point.x, point.y);
|
|
||||||
}
|
|
||||||
context.stroke();
|
|
||||||
|
|
||||||
context.beginPath();
|
|
||||||
context.arc(start.x, start.y, 3, 0, Math.PI * 2.0, false);
|
|
||||||
context.stroke();
|
|
||||||
|
|
||||||
context.beginPath();
|
|
||||||
context.arc(end.x, end.y, 3, 0, Math.PI * 2.0, false);
|
|
||||||
context.stroke();
|
|
||||||
}
|
|
1
simpleExample/models/test.json
Normal file
1
simpleExample/models/test.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,2 +1 @@
|
|||||||
export const CLEAN_DELTA = 0.05;
|
|
||||||
export const PRECISION = 0.01;
|
export const PRECISION = 0.01;
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import Shape from 'clipper-js';
|
import Shape from 'clipper-js';
|
||||||
import Slice from './helpers/Slice.js';
|
import Slice from './helpers/Slice.js';
|
||||||
|
|
||||||
import { CLEAN_DELTA, PRECISION } from '../constants.js';
|
import { PRECISION } from '../constants.js';
|
||||||
|
|
||||||
const cleanDelta = CLEAN_DELTA / PRECISION;
|
|
||||||
|
|
||||||
export default function shapesToSlices(shapes, settings) {
|
export default function shapesToSlices(shapes, settings) {
|
||||||
const sliceLayers = [];
|
const sliceLayers = [];
|
||||||
@ -14,14 +12,14 @@ export default function shapesToSlices(shapes, settings) {
|
|||||||
fillShapes = new Shape(fillShapes, true, true, true, true)
|
fillShapes = new Shape(fillShapes, true, true, true, true)
|
||||||
.fixOrientation()
|
.fixOrientation()
|
||||||
.simplify('pftNonZero')
|
.simplify('pftNonZero')
|
||||||
.clean(cleanDelta)
|
.clean(1)
|
||||||
.seperateShapes();
|
.seperateShapes();
|
||||||
|
|
||||||
lineShapesClosed = new Shape(lineShapesClosed, true, true, true, true)
|
lineShapesClosed = new Shape(lineShapesClosed, true, true, true, true)
|
||||||
.clean(cleanDelta);
|
.clean(1);
|
||||||
|
|
||||||
lineShapesOpen = new Shape(lineShapesOpen, false, true, true, true)
|
lineShapesOpen = new Shape(lineShapesOpen, false, true, true, true)
|
||||||
.clean(cleanDelta);
|
.clean(1);
|
||||||
|
|
||||||
const slice = new Slice();
|
const slice = new Slice();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user