mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 13:37:58 +01:00
parent
491067b070
commit
64d28affe6
@ -14,31 +14,60 @@ export default function intersectionsToShapes(intersectionLayers, faces, openObj
|
|||||||
|
|
||||||
const shapes = {};
|
const shapes = {};
|
||||||
|
|
||||||
|
const startConnects = {};
|
||||||
|
const endConnects = {};
|
||||||
|
|
||||||
for (let i = 0; i < faceIndexes.length; i ++) {
|
for (let i = 0; i < faceIndexes.length; i ++) {
|
||||||
const { lineIndexes, objectIndex, flatNormal } = faces[faceIndexes[i]];
|
const faceIndex = faceIndexes[i];
|
||||||
|
const { lineIndexes, flatNormal, objectIndex } = faces[faceIndex];
|
||||||
|
|
||||||
const a = points[lineIndexes[0]];
|
const a = lineIndexes[0];
|
||||||
const b = points[lineIndexes[1]];
|
const b = lineIndexes[1];
|
||||||
const c = points[lineIndexes[2]];
|
const c = lineIndexes[2];
|
||||||
|
|
||||||
const lineSegment = [];
|
let pointA;
|
||||||
if (a && b) {
|
let pointB;
|
||||||
lineSegment.push(a, b);
|
if (points[a] && points[b]) {
|
||||||
} else if (b && c) {
|
pointA = a;
|
||||||
lineSegment.push(b, c);
|
pointB = b;
|
||||||
} else if (c && a) {
|
} else if (points[b] && points[c]) {
|
||||||
lineSegment.push(c, a);
|
pointA = b;
|
||||||
|
pointB = c;
|
||||||
|
} else if (points[c] && points[a]) {
|
||||||
|
pointA = c;
|
||||||
|
pointB = a;
|
||||||
} else {
|
} else {
|
||||||
|
// should never happen
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const segmentNormal = normalize(normal(subtract(lineSegment[1], lineSegment[0])));
|
const segmentNormal = normalize(normal(subtract(points[pointA], points[pointB])));
|
||||||
if (dot(segmentNormal, flatNormal) < 0) lineSegment.reverse();
|
if (dot(segmentNormal, flatNormal) < 0) {
|
||||||
|
const temp = pointB;
|
||||||
|
pointB = pointA;
|
||||||
|
pointA = temp;
|
||||||
|
}
|
||||||
|
|
||||||
if (!shapes[objectIndex]) shapes[objectIndex] = { lineSegments: [] };
|
if (endConnects[pointA]) {
|
||||||
const shape = shapes[objectIndex];
|
const lineSegment = endConnects[pointA];
|
||||||
|
lineSegment.push(points[pointB]);
|
||||||
|
delete endConnects[pointA];
|
||||||
|
endConnects[pointB] = lineSegment;
|
||||||
|
} else if (startConnects[pointB]) {
|
||||||
|
const lineSegment = startConnects[pointB];
|
||||||
|
lineSegment.unshift(points[pointA]);
|
||||||
|
delete startConnects[pointB];
|
||||||
|
startConnects[pointA] = lineSegment;
|
||||||
|
} else {
|
||||||
|
const lineSegment = [points[pointA], points[pointB]];
|
||||||
|
startConnects[pointA] = lineSegment;
|
||||||
|
endConnects[pointB] = lineSegment;
|
||||||
|
|
||||||
shape.lineSegments.push(lineSegment)
|
if (!shapes[objectIndex]) shapes[objectIndex] = { lineSegments: [] };
|
||||||
|
const shape = shapes[objectIndex];
|
||||||
|
|
||||||
|
shape.lineSegments.push(lineSegment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const objectIndex in shapes) {
|
for (const objectIndex in shapes) {
|
||||||
|
Loading…
Reference in New Issue
Block a user