Commit e9b155b9 authored by amandaghassaei's avatar amandaghassaei

support for cuts

parent b544658a
...@@ -254,6 +254,10 @@ filter.unassignedEdges = function(fold) { ...@@ -254,6 +254,10 @@ filter.unassignedEdges = function(fold) {
return filter.edgesAssigned(fold, 'U'); return filter.edgesAssigned(fold, 'U');
}; };
filter.cutEdges = function(fold) {
return filter.edgesAssigned(fold, 'C');
};
filter.keysStartingWith = function(fold, prefix) { filter.keysStartingWith = function(fold, prefix) {
var key, results; var key, results;
results = []; results = [];
......
...@@ -32,7 +32,6 @@ function initPattern(globals){ ...@@ -32,7 +32,6 @@ function initPattern(globals){
var mountains = []; var mountains = [];
var valleys = []; var valleys = [];
var borders = []; var borders = [];
var cuts = [];
var hinges = []; var hinges = [];
var triangulations = []; var triangulations = [];
...@@ -53,7 +52,6 @@ function initPattern(globals){ ...@@ -53,7 +52,6 @@ function initPattern(globals){
mountains = []; mountains = [];
valleys = []; valleys = [];
borders = []; borders = [];
cuts = [];
hinges = []; hinges = [];
triangulations = []; triangulations = [];
...@@ -359,7 +357,9 @@ function initPattern(globals){ ...@@ -359,7 +357,9 @@ function initPattern(globals){
globals.warn(string); 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 //find max and min vertices
var max = new THREE.Vector3(-Infinity,-Infinity,-Infinity); var max = new THREE.Vector3(-Infinity,-Infinity,-Infinity);
...@@ -448,6 +448,11 @@ function initPattern(globals){ ...@@ -448,6 +448,11 @@ function initPattern(globals){
foldData.edges_foldAngles.push(null); 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.collapseNearbyVertices(foldData, globals.vertTol);
foldData = FOLD.filter.removeLoopEdges(foldData);//remove edges that points to same vertex foldData = FOLD.filter.removeLoopEdges(foldData);//remove edges that points to same vertex
foldData = FOLD.filter.removeDuplicateEdges_vertices(foldData);//remove duplicate edges foldData = FOLD.filter.removeDuplicateEdges_vertices(foldData);//remove duplicate edges
...@@ -471,12 +476,6 @@ function initPattern(globals){ ...@@ -471,12 +476,6 @@ function initPattern(globals){
foldData = reverseFaceOrder(foldData);//set faces to counter clockwise foldData = reverseFaceOrder(foldData);//set faces to counter clockwise
if (_cutsRaw.length>0) {
foldData = sortVerticesEdges(foldData);
foldData = facesVerticesToVerticesFaces(foldData);
foldData = splitCuts(foldData);
}
return processFold(foldData); return processFold(foldData);
} }
...@@ -484,6 +483,13 @@ function initPattern(globals){ ...@@ -484,6 +483,13 @@ function initPattern(globals){
rawFold = JSON.parse(JSON.stringify(fold));//save pre-triangulated for for save later 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); foldData = triangulatePolys(fold, true);
for (var i=0;i<foldData.vertices_coords.length;i++){ for (var i=0;i<foldData.vertices_coords.length;i++){
...@@ -545,7 +551,7 @@ function initPattern(globals){ ...@@ -545,7 +551,7 @@ function initPattern(globals){
verticesFaces[face[j]].push(i); verticesFaces[face[j]].push(i);
} }
} }
fold.verticesFaces = verticesFaces; fold.vertices_faces = verticesFaces;
return fold; return fold;
} }
...@@ -574,37 +580,98 @@ function initPattern(globals){ ...@@ -574,37 +580,98 @@ function initPattern(globals){
function splitCuts(fold){ function splitCuts(fold){
//todo split cuts //todo split cuts
fold = sortVerticesEdges(fold);
fold = facesVerticesToVerticesFaces(fold);
// console.log(JSON.stringify(fold));
//go around each vertex and split cut in counter-clockwise order //go around each vertex and split cut in counter-clockwise order
for (var i=0;i<fold.vertices_vertices.length;i++){ for (var i=0;i<fold.vertices_edges.length;i++){
var cutIndices = []; var groups = [[]];
var groupIndex = 0;
var verticesEdges = fold.vertices_edges[i]; var verticesEdges = fold.vertices_edges[i];
var verticesFaces = fold.vertices_faces[i];
for (var j=0;j<verticesEdges.length;j++){ for (var j=0;j<verticesEdges.length;j++){
var edgeIndex = verticesEdges[j]; var edgeIndex = verticesEdges[j];
if (fold.edges_assignment[edgeIndex] == "C"){ var assignment = fold.edges_assignment[edgeIndex];
cutIndices.push(j); groups[groupIndex].push(edgeIndex);
if (assignment == "C"){
//split cut edge into two boundary edges
groups.push([fold.edges_vertices.length]);
groupIndex++;
var newEdgeIndex = fold.edges_vertices.length;
var edge = fold.edges_vertices[edgeIndex];
fold.edges_vertices.push([edge[0], edge[1]]);
fold.edges_assignment[edgeIndex] = "B";
fold.edges_foldAngles.push(null);
fold.edges_assignment.push("B");
//add new boundary edge to other vertex
var otherVertex = edge[0];
if (otherVertex == i) otherVertex = edge[1];
var otherVertexEdges = fold.vertices_edges[otherVertex];
var otherVertexEdgeIndex = otherVertexEdges.indexOf(edgeIndex);
otherVertexEdges.splice(otherVertexEdgeIndex, 0, newEdgeIndex);
} else if (assignment == "B"){
if (j==0 && verticesEdges.length>1){
//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; if (groups.length <= 1) continue;
for (var k=groups[groupIndex].length-1;k>=0;k--){//put remainder of last group in first group
var groups = []; groups[0].unshift(groups[groupIndex][k]);
var completeLoop = false; }
var firstPass = true; groups.pop();
for (var j=cutIndices[0];!completeLoop;j++){ for (var j=1;j<groups.length;j++){//for each extra group, assign new vertex
if (j>=verticesEdges.length) j-=verticesEdges.length; var currentVertex = fold.vertices_coords[i];
if (groups.length>0) groups[groups.length-1].push(j); var vertIndex = fold.vertices_coords.length;
if (cutIndices.indexOf(j)>=0){ fold.vertices_coords.push(currentVertex.slice());
groups.push([]); var connectingIndices = [];
groups[groups.length-1].push(j); for (var k=0;k<groups[j].length;k++){//update edges_vertices
var edgeIndex = groups[j][k];
var edge = fold.edges_vertices[edgeIndex];
var otherIndex = edge[0];
if (edge[0] == i) {
edge[0] = vertIndex;
otherIndex = edge[1];
} else edge[1] = vertIndex;
connectingIndices.push(otherIndex);
}
if (connectingIndices.length<2) {
console.warn("problem here");
} else {
for (var k=1;k<connectingIndices.length;k++){//update faces_vertices
//i, k-1, k
var thisConnectingVertIndex = connectingIndices[k];
var previousConnectingVertIndex = connectingIndices[k-1];
var found = false;
for (var a=0;a<verticesFaces.length;a++){
var face = fold.faces_vertices[verticesFaces[a]];
if (face.indexOf(thisConnectingVertIndex) >= 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<fold.edges_assignment.length;i++){//todo do this inline eventually
if (fold.edges_assignment[i] == "C") fold.edges_assignment[i] = "B";
} }
//these are all incorrect now
delete fold.vertices_faces;
delete fold.vertices_edges;
delete fold.vertices_vertices;
// console.log(JSON.stringify(fold));
return fold; return fold;
} }
......
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