Commit 788eaf85 authored by amandaghassaei's avatar amandaghassaei

working on better svg parsing

parent d7be6289
...@@ -418,7 +418,7 @@ ...@@ -418,7 +418,7 @@
<li class="dropdown navDropdown"> <li class="dropdown navDropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Examples <b class="caret"></b></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Examples <b class="caret"></b></a>
<span class="dropdown-arrow"></span> <span class="dropdown-arrow"></span>
<ul class="dropdown-menu"> <ul class="dropdown-menu" style="min-width: 200px;">
<li class="dropdown-submenu"> <li class="dropdown-submenu">
<a tabindex="-1">Origami<span class="pull-right fui-arrow-right"></span></a> <a tabindex="-1">Origami<span class="pull-right fui-arrow-right"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
......
...@@ -253,11 +253,11 @@ function initImporter(globals){ ...@@ -253,11 +253,11 @@ function initImporter(globals){
break; break;
case 3: case 3:
//outline //outline
shouldSkip = true; creaseParams.push(-Math.PI);
break; break;
case 2: case 2:
//crease //crease
creaseParams.push(Math.PI);//todo only mtn creaseParams.push(Math.PI);
break; break;
} }
if (!shouldSkip) allCreaseParams.push(creaseParams); if (!shouldSkip) allCreaseParams.push(creaseParams);
......
...@@ -206,17 +206,78 @@ function initPattern(globals){ ...@@ -206,17 +206,78 @@ function initPattern(globals){
mergeVertices(); mergeVertices();
//remove duplicates for each set of edges //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 //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); polygons = findPolygons(allEdges);
console.log(polygons[0]);
var faces = triangulatePolys(polygons, allEdges); var faces = triangulatePolys(polygons, allEdges);
var allCreaseParams = getFacesAndVerticesForEdges(faces, allEdges); var allCreaseParams = getFacesAndVerticesForEdges(faces, allEdges);
globals.model.buildModel(faces, vertices, allEdges, allCreaseParams); 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){ function getFacesAndVerticesForEdges(faces, allEdges){
var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle var allCreaseParams = [];//face1Ind, vertInd, face2Ind, ver2Ind, edgeInd, angle
for (var i=outlines.length;i<allEdges.length;i++){ for (var i=outlines.length;i<allEdges.length;i++){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment