From 8f475195b8faf70fa6d3cb913094522b57c4225b Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 1 Feb 2018 12:23:34 +0100 Subject: [PATCH] clean up create lines --- src/sliceActions/createLines.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/sliceActions/createLines.js b/src/sliceActions/createLines.js index e9f9fd2..b0c23ca 100644 --- a/src/sliceActions/createLines.js +++ b/src/sliceActions/createLines.js @@ -10,24 +10,27 @@ function addLine(geometry, lineLookup, lines, a, b, faceIndex) { lineLookup[`${a}_${b}`] = index; const line = new THREE.Line3(geometry.vertices[a], geometry.vertices[b]); - lines.push({ line, faces: [] }); + const faces = []; + lines.push({ line, faces }); } - - const { faces } = lines[index]; - faces.push(faceIndex); + lines[index].faces.push(faceIndex); return index; } export default function createLines(geometry, settings) { + const faces = []; const lines = []; const lineLookup = {}; - const faces = geometry.faces.map((face, i) => { + for (let i = 0; i < geometry.faces.length; i ++) { const { normal, materialIndex: objectIndex, a, b, c } = geometry.faces[i]; // skip faces that point up or down - if (normal.y > .999 || normal.y < -.999) return; + if (normal.y > .999 || normal.y < -.999) { + faces.push(null); + continue; + } const indexA = addLine(geometry, lineLookup, lines, a, b, i); const indexB = addLine(geometry, lineLookup, lines, b, c, i); @@ -35,8 +38,9 @@ export default function createLines(geometry, settings) { const flatNormal = normalize({ x: normal.z, y: normal.x }); const lineIndexes = [indexA, indexB, indexC]; - return { lineIndexes, flatNormal, objectIndex }; - }); + + faces.push({ lineIndexes, flatNormal, objectIndex }); + } return { lines, faces }; }