From 788eaf85d3a4365c0b28d17d7eb54b7e5233a0e9 Mon Sep 17 00:00:00 2001 From: amandaghassaei <amandaghassaei@gmail.com> Date: Tue, 9 May 2017 16:54:39 -0400 Subject: [PATCH] working on better svg parsing --- index.html | 2 +- js/importer.js | 4 ++-- js/pattern.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index d28ad10..9f3d182 100644 --- a/index.html +++ b/index.html @@ -418,7 +418,7 @@ <li class="dropdown navDropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Examples <b class="caret"></b></a> <span class="dropdown-arrow"></span> - <ul class="dropdown-menu"> + <ul class="dropdown-menu" style="min-width: 200px;"> <li class="dropdown-submenu"> <a tabindex="-1">Origami<span class="pull-right fui-arrow-right"></span></a> <ul class="dropdown-menu"> diff --git a/js/importer.js b/js/importer.js index 9e1ff34..8f2e3a0 100644 --- a/js/importer.js +++ b/js/importer.js @@ -253,11 +253,11 @@ function initImporter(globals){ break; case 3: //outline - shouldSkip = true; + creaseParams.push(-Math.PI); break; case 2: //crease - creaseParams.push(Math.PI);//todo only mtn + creaseParams.push(Math.PI); break; } if (!shouldSkip) allCreaseParams.push(creaseParams); diff --git a/js/pattern.js b/js/pattern.js index a1583aa..d9248e6 100644 --- a/js/pattern.js +++ b/js/pattern.js @@ -206,17 +206,78 @@ function initPattern(globals){ mergeVertices(); //remove duplicates for each set of edges + removeDuplicates(outlines, outlines); + removeDuplicates(mountains, mountains); + removeDuplicates(valleys, valleys); + removeDuplicates(cuts, cuts); + removeDuplicates(triangulations, triangulations); + //todo remove duplicates between sets? + //remove vertices that are not useful + removeRedundantVertices(outlines.concat(mountains).concat(valleys).concat(cuts).concat(triangulations)); + + var allEdges = outlines.concat(mountains).concat(valleys).concat(cuts).concat(triangulations); - var allEdges = outlines.concat(mountains).concat(valleys).concat(cuts).concat(triangulationsRaw); polygons = findPolygons(allEdges); - console.log(polygons[0]); var faces = triangulatePolys(polygons, allEdges); var allCreaseParams = getFacesAndVerticesForEdges(faces, allEdges); globals.model.buildModel(faces, vertices, allEdges, allCreaseParams); } + function removeRedundantVertices(set){ + // var badVertices = []; + // for (var i=0;i<vertices.length;i++){ + // var vertexEdges = []; + // for (var j=0;j<=set.length;j++){ + // if (set[j][0] == i || set[j][1] == i) vertexEdges.push(j); + // } + // if (vertexEdges.length == 2){ + // var edge1 = set[vertexEdges[0]]; + // var edge2 = set[vertexEdges[1]]; + // var angle1 = Math.atan2(vertices[edge1[0]].z-vertices[edge1[1]].z, vertices[edge1[0]].x-vertices[edge1[1]].x); + // var angle2 = Math.atan2(vertices[edge2[0]].z-vertices[edge2[1]].z, vertices[edge2[0]].x-vertices[edge2[1]].x); + // if (Math.abs(angle1-angle2) < 0.01 || Math.abs(angle1-angle2-Math.PI) < 0.01){ + // badVertices.push(i); + // var v1 = edge1[0]; + // if (v1 = i) v1 = edge1[1]; + // var v2 = edge2[0]; + // if (v2 = i) v2 = edge2[1]; + // set[vertexEdges[0]] = [v1, v2];//favor outlines over mtn valleys + // set.splice(vertexEdges[1], 1);//delete extra + // } + // } + // } + // if (badVertices.length>0){ + // + // + // + // // for (var j=0;j<=set.length;j++){ + // // if (set[j][0] == i || set[j][1] == i) vertexEdges.push(j); + // // } + // // + // removeDuplicates(outlines, outlines); + // removeDuplicates(mountains, mountains); + // removeDuplicates(valleys, valleys); + // removeDuplicates(cuts, cuts); + // removeDuplicates(triangulations, triangulations); + // removeRedundantVertices(set); + // } + } + + function removeDuplicates(set1, set2){ + for (var i=set1.length-1;i>=0;i--){ + for (var j=i-1;j>=0;j--){ + var edge1 = set1[i]; + var edge2 = set2[j]; + if (edge2.indexOf(edge1[0]) >= 0 && edge2.indexOf(edge1[1]) >= 0){ + set2.splice(j, 1); + j--; + } + } + } + } + function getFacesAndVerticesForEdges(faces, allEdges){ var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle for (var i=outlines.length;i<allEdges.length;i++){ -- GitLab