Commit 70c09d89 authored by amandaghassaei's avatar amandaghassaei
Browse files

svg import supports angle

parent b1cc2fe5
...@@ -30,6 +30,8 @@ function initPattern(globals){ ...@@ -30,6 +30,8 @@ function initPattern(globals){
//format all lines //format all lines
var $paths = _$svg.children("path"); var $paths = _$svg.children("path");
$paths.css({fill:"none", 'stroke-dasharray':"none"}); $paths.css({fill:"none", 'stroke-dasharray':"none"});
var _mountainAngles = [];
var _valleyAngles = [];
var $outlines = $paths.filter(function(){ var $outlines = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); var stroke = $(this).attr("stroke").toLowerCase();
...@@ -37,13 +39,21 @@ function initPattern(globals){ ...@@ -37,13 +39,21 @@ function initPattern(globals){
}); });
var $mountains = $paths.filter(function(){ var $mountains = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); var color = hexToColor($(this).attr("stroke").toLowerCase());
return stroke == "#ff0000" || stroke == "#f00"; if (color.r > 0 && color.g == 0 && color.b == 0){
_mountainAngles.push(-color.r*Math.PI);
return true;
}
return false;
}); });
var $valleys = $paths.filter(function(){ var $valleys = $paths.filter(function(){
var stroke = $(this).attr("stroke").toLowerCase(); var color = hexToColor($(this).attr("stroke").toLowerCase());
return stroke == "#0000ff" || stroke == "#00f"; if (color.b > 0 && color.g == 0 && color.r == 0){
_valleyAngles.push(color.b*Math.PI);
return true;
}
return false;
}); });
var $cuts = $paths.filter(function(){ var $cuts = $paths.filter(function(){
...@@ -56,7 +66,7 @@ function initPattern(globals){ ...@@ -56,7 +66,7 @@ function initPattern(globals){
return stroke == "#ffff00" || stroke == "#ff0"; return stroke == "#ffff00" || stroke == "#ff0";
}); });
parseSVG($outlines, $mountains, $valleys, $cuts, $triangulations); parseSVG($outlines, $mountains, $valleys, $cuts, $triangulations, _mountainAngles, _valleyAngles);
//find max and min vertices //find max and min vertices
var max = new THREE.Vector3(0,0,0); var max = new THREE.Vector3(0,0,0);
...@@ -95,7 +105,15 @@ function initPattern(globals){ ...@@ -95,7 +105,15 @@ function initPattern(globals){
}); });
} }
function parsePath(_verticesRaw, _segmentsRaw, $paths){ function hexToColor(stroke){
stroke = stroke.slice(1);
if (stroke.length == 3){
stroke = stroke[0]+stroke[0]+stroke[1]+stroke[1]+stroke[2]+stroke[2];
}
return new THREE.Color(parseInt("0x" + stroke));
}
function parsePath(_verticesRaw, _segmentsRaw, $paths, angles){
for (var i=0;i<$paths.length;i++){ for (var i=0;i<$paths.length;i++){
var segments = $paths[i].getPathData(); var segments = $paths[i].getPathData();
for (var j=0;j<segments.length;j++){ for (var j=0;j<segments.length;j++){
...@@ -113,6 +131,7 @@ function initPattern(globals){ ...@@ -113,6 +131,7 @@ function initPattern(globals){
case "l"://dx, dy case "l"://dx, dy
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
var vertex = _verticesRaw[_verticesRaw.length-1].clone(); var vertex = _verticesRaw[_verticesRaw.length-1].clone();
vertex.x += segment.values[0]; vertex.x += segment.values[0];
vertex.z += segment.values[1]; vertex.z += segment.values[1];
...@@ -121,6 +140,7 @@ function initPattern(globals){ ...@@ -121,6 +140,7 @@ function initPattern(globals){
case "v"://dy case "v"://dy
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
var vertex = _verticesRaw[_verticesRaw.length-1].clone(); var vertex = _verticesRaw[_verticesRaw.length-1].clone();
vertex.z += segment.values[0]; vertex.z += segment.values[0];
_verticesRaw.push(vertex); _verticesRaw.push(vertex);
...@@ -128,6 +148,7 @@ function initPattern(globals){ ...@@ -128,6 +148,7 @@ function initPattern(globals){
case "h"://dx case "h"://dx
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
var vertex = _verticesRaw[_verticesRaw.length-1].clone(); var vertex = _verticesRaw[_verticesRaw.length-1].clone();
vertex.x += segment.values[0]; vertex.x += segment.values[0];
_verticesRaw.push(vertex); _verticesRaw.push(vertex);
...@@ -139,11 +160,13 @@ function initPattern(globals){ ...@@ -139,11 +160,13 @@ function initPattern(globals){
case "L"://x, y case "L"://x, y
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
_verticesRaw.push(new THREE.Vector3(segment.values[0], 0, segment.values[1])); _verticesRaw.push(new THREE.Vector3(segment.values[0], 0, segment.values[1]));
break; break;
case "V"://y case "V"://y
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
var vertex = _verticesRaw[_verticesRaw.length-1].clone(); var vertex = _verticesRaw[_verticesRaw.length-1].clone();
vertex.z = segment.values[0]; vertex.z = segment.values[0];
_verticesRaw.push(vertex); _verticesRaw.push(vertex);
...@@ -151,6 +174,7 @@ function initPattern(globals){ ...@@ -151,6 +174,7 @@ function initPattern(globals){
case "H"://x case "H"://x
_segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]); _segmentsRaw.push([_verticesRaw.length-1, _verticesRaw.length]);
if (angles && _segmentsRaw.length>0) _segmentsRaw[_segmentsRaw.length-1].push(angles[i]);
var vertex = _verticesRaw[_verticesRaw.length-1].clone(); var vertex = _verticesRaw[_verticesRaw.length-1].clone();
vertex.x = segment.values[0]; vertex.x = segment.values[0];
_verticesRaw.push(vertex); _verticesRaw.push(vertex);
...@@ -160,7 +184,7 @@ function initPattern(globals){ ...@@ -160,7 +184,7 @@ function initPattern(globals){
} }
} }
function parseSVG($outlines, $mountains, $valleys, $cuts, $triangulations){ function parseSVG($outlines, $mountains, $valleys, $cuts, $triangulations, _mountainAngles, _valleyAngles){
var _verticesRaw = []; var _verticesRaw = [];
var _mountainsRaw = []; var _mountainsRaw = [];
...@@ -170,8 +194,8 @@ function initPattern(globals){ ...@@ -170,8 +194,8 @@ function initPattern(globals){
var _triangulationsRaw = []; var _triangulationsRaw = [];
parsePath(_verticesRaw, _outlinesRaw, $outlines); parsePath(_verticesRaw, _outlinesRaw, $outlines);
parsePath(_verticesRaw, _mountainsRaw, $mountains); parsePath(_verticesRaw, _mountainsRaw, $mountains, _mountainAngles);
parsePath(_verticesRaw, _valleysRaw, $valleys); parsePath(_verticesRaw, _valleysRaw, $valleys, _valleyAngles);
parsePath(_verticesRaw, _cutsRaw, $cuts); parsePath(_verticesRaw, _cutsRaw, $cuts);
parsePath(_verticesRaw, _triangulationsRaw, $triangulations); parsePath(_verticesRaw, _triangulationsRaw, $triangulations);
...@@ -225,10 +249,7 @@ function initPattern(globals){ ...@@ -225,10 +249,7 @@ function initPattern(globals){
creaseParams.push(i); creaseParams.push(i);
if (i<(outlines.length+mountains.length+valleys.length)){ if (i<(outlines.length+mountains.length+valleys.length)){
var angle = -Math.PI; var angle = allEdges[i][2];
if (i<(outlines.length+mountains.length)){
angle *= -1;
}
creaseParams.push(angle); creaseParams.push(angle);
} else { } else {
creaseParams.push(0); creaseParams.push(0);
...@@ -608,15 +629,15 @@ function initPattern(globals){ ...@@ -608,15 +629,15 @@ function initPattern(globals){
_verticesRaw.push(data.intersection); _verticesRaw.push(data.intersection);
if (seg1Int){ if (seg1Int){
set1.splice(i+1, 0, [vertIndex, set1[i][0]]); set1.splice(i+1, 0, [vertIndex, set1[i][0], set1[i][2]]);
set1.splice(i+1, 0, [vertIndex, set1[i][1]]); set1.splice(i+1, 0, [vertIndex, set1[i][1], set1[i][2]]);
set1.splice(i, 1); set1.splice(i, 1);
i++; i++;
if (j==0) i++; if (j==0) i++;
} }
if (seg2Int){ if (seg2Int){
set2.splice(j+1, 0, [vertIndex, set2[j][0]]); set2.splice(j+1, 0, [vertIndex, set2[j][0], set2[i][2]]);
set2.splice(j+1, 0, [vertIndex, set2[j][1]]); set2.splice(j+1, 0, [vertIndex, set2[j][1], set2[i][2]]);
set2.splice(j, 1); set2.splice(j, 1);
j += 2; j += 2;
} }
......
Supports Markdown
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