From e9b155b9ddf6cc677eb6c461ce248d78ed0bad63 Mon Sep 17 00:00:00 2001 From: amandaghassaei Date: Tue, 4 Jul 2017 16:34:07 -0400 Subject: [PATCH] support for cuts --- dependencies/fold.js | 4 ++ js/pattern.js | 131 ++++++++++++++++++++++++++++++++----------- 2 files changed, 103 insertions(+), 32 deletions(-) diff --git a/dependencies/fold.js b/dependencies/fold.js index e0ec863..761819d 100755 --- a/dependencies/fold.js +++ b/dependencies/fold.js @@ -254,6 +254,10 @@ filter.unassignedEdges = function(fold) { return filter.edgesAssigned(fold, 'U'); }; +filter.cutEdges = function(fold) { + return filter.edgesAssigned(fold, 'C'); +}; + filter.keysStartingWith = function(fold, prefix) { var key, results; results = []; diff --git a/js/pattern.js b/js/pattern.js index 67f89a8..5ad614b 100755 --- a/js/pattern.js +++ b/js/pattern.js @@ -32,7 +32,6 @@ function initPattern(globals){ var mountains = []; var valleys = []; var borders = []; - var cuts = []; var hinges = []; var triangulations = []; @@ -53,7 +52,6 @@ function initPattern(globals){ mountains = []; valleys = []; borders = []; - cuts = []; hinges = []; triangulations = []; @@ -359,7 +357,9 @@ function initPattern(globals){ globals.warn(string); } - parseSVG(verticesRaw, bordersRaw, mountainsRaw, valleysRaw, cutsRaw, triangulationsRaw, hingesRaw); + //todo revert back to old pattern if bad import + var error = parseSVG(verticesRaw, bordersRaw, mountainsRaw, valleysRaw, cutsRaw, triangulationsRaw, hingesRaw); + if (error) return; //find max and min vertices var max = new THREE.Vector3(-Infinity,-Infinity,-Infinity); @@ -448,6 +448,11 @@ function initPattern(globals){ foldData.edges_foldAngles.push(null); }); + if (foldData.vertices_coords.length == 0 || foldData.edges_vertices.length == 0){ + globals.warn("No valid geometry found in SVG, be sure to ungroup all and remove all clipping masks."); + return true; + } + foldData = FOLD.filter.collapseNearbyVertices(foldData, globals.vertTol); foldData = FOLD.filter.removeLoopEdges(foldData);//remove edges that points to same vertex foldData = FOLD.filter.removeDuplicateEdges_vertices(foldData);//remove duplicate edges @@ -471,12 +476,6 @@ function initPattern(globals){ foldData = reverseFaceOrder(foldData);//set faces to counter clockwise - if (_cutsRaw.length>0) { - foldData = sortVerticesEdges(foldData); - foldData = facesVerticesToVerticesFaces(foldData); - foldData = splitCuts(foldData); - } - return processFold(foldData); } @@ -484,6 +483,13 @@ function initPattern(globals){ rawFold = JSON.parse(JSON.stringify(fold));//save pre-triangulated for for save later + var cuts = FOLD.filter.cutEdges(fold); + if (cuts.length>0) { + fold = splitCuts(fold); + } + delete fold.vertices_vertices; + delete fold.vertices_edges; + foldData = triangulatePolys(fold, true); for (var i=0;i1){ + //check if next edge is also boundary + var nextEdgeIndex = verticesEdges[1]; + if (fold.edges_assignment[nextEdgeIndex] == "B"){ + groups.push([]); + groupIndex++; + } + } else if (groups[groupIndex].length>1) { + groups.push([]); + groupIndex++; + } } } - if (cutIndices.length == 0) continue; - - var groups = []; - var completeLoop = false; - var firstPass = true; - for (var j=cutIndices[0];!completeLoop;j++){ - if (j>=verticesEdges.length) j-=verticesEdges.length; - if (groups.length>0) groups[groups.length-1].push(j); - if (cutIndices.indexOf(j)>=0){ - groups.push([]); - groups[groups.length-1].push(j); + if (groups.length <= 1) continue; + for (var k=groups[groupIndex].length-1;k>=0;k--){//put remainder of last group in first group + groups[0].unshift(groups[groupIndex][k]); + } + groups.pop(); + for (var j=1;j= 0 && face.indexOf(previousConnectingVertIndex) >= 0){ + found = true; + var b = face.indexOf(i); + if (b<0) console.warn("problem here"); + else face[b] = vertIndex + break; + } + } + if (!found) console.warn("problem here"); + } } - if (!firstPass && j==cutIndices[0]) completeLoop = true; - firstPass = false; } - console.log(groups); - } - //update faces_vertices, edges_vertices, delete vertices_edges, vertices_vertices, vertices_faces - for (var i=0;i