Commit c009a2ec authored by amandaghassaei's avatar amandaghassaei

fold save working

parent bfcb21d2
......@@ -1119,8 +1119,8 @@
Save with triangulated faces
</label>
<label class="bigLabel checkbox" for="exportFoldAngle">
<input id="exportFoldAngle" data-toggle="checkbox" disabled class="custom-checkbox layersSelector" type="checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Save with vertices_foldAngles (coming soon)
<input id="exportFoldAngle" data-toggle="checkbox" class="custom-checkbox layersSelector" type="checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Save with vertices_foldAngles
</label>
<span class="smallTxt">For more information about the FOLD file format, see the <a target="_blank" href="https://github.com/edemaine/fold">offical docs</a></span>.
</div>
......
......@@ -136,6 +136,9 @@ function initControls(globals){
setCheckbox("#triangulateFOLDexport", globals.triangulateFOLDexport, function(val){
globals.triangulateFOLDexport = val;
});
setCheckbox("#exportFoldAngle", globals.exportFoldAngle, function(val){
globals.exportFoldAngle = val;
});
setLink("#doSTLsave", function(){
saveSTL();
......
......@@ -71,7 +71,7 @@ function initGlobals(){
//save fold settings
foldUnits: "unit",
triangulateFOLDexport: false,
exportFoldAngle: false,
exportFoldAngle: true,
pausedForPatternView: false,
......
......@@ -7,6 +7,7 @@ function initPattern(globals){
var FOLD = require('fold');
var foldData = {};
var rawFold = {};
clearFold();
function clearFold(){
......@@ -16,6 +17,7 @@ function initPattern(globals){
foldData.edges_foldAngles = [];//target angles
delete foldData.vertices_vertices;
delete foldData.faces_vertices;
rawFold = {};
}
......@@ -27,7 +29,6 @@ function initPattern(globals){
var cutsRaw = [];
var triangulationsRaw = [];
var hingesRaw = [];
var rawFold;
var mountains = [];
var valleys = [];
......@@ -114,7 +115,7 @@ function initPattern(globals){
if (stroke == "#000000" || stroke == "#000" || stroke == "black" || stroke == "rgb(0, 0, 0)") return "border";
if (stroke == "#ff0000" || stroke == "#f00" || stroke == "red" || stroke == "rgb(255, 0, 0)") return "mountain";
if (stroke == "#0000ff" || stroke == "#00f" || stroke == "blue" || stroke == "rgb(0, 0, 255)") return "valley";
if (stroke == "#00ff00" || stroke == "#0f0" || stroke == "green" || stroke == "rgb(0, 255, 0)") return "cut";
// if (stroke == "#00ff00" || stroke == "#0f0" || stroke == "green" || stroke == "rgb(0, 255, 0)") return "cut";
if (stroke == "#ffff00" || stroke == "#ff0" || stroke == "yellow" || stroke == "rgb(255, 255, 0)") return "triangulation";
if (stroke == "#ff00ff" || stroke == "#f0f" || stroke == "magenta" || stroke == "rgb(255, 0, 255)") return "hinge";
badColors.push(stroke);
......@@ -446,7 +447,7 @@ function initPattern(globals){
foldData.vertices_vertices = FOLD.convert.sort_vertices_vertices(foldData);
foldData = FOLD.convert.vertices_vertices_to_faces_vertices(foldData);
foldData = reverseFaceOrder(foldData);//set faces to counter clockwise
console.log(JSON.stringify(foldData));
// console.log(JSON.stringify(foldData));
rawFold = JSON.parse(JSON.stringify(foldData));//save pre-triangulated for for save later
......@@ -595,7 +596,7 @@ function initPattern(globals){
console.warn("different edge assignments");
return false;
}
angleAvg += fold.edges_foldAngles[i];
if (fold.edges_foldAngles[i]) angleAvg += fold.edges_foldAngles[i];
fold.edges_vertices.splice(i, 1);
fold.edges_assignment.splice(i, 1);
fold.edges_foldAngles.splice(i, 1);
......@@ -858,18 +859,9 @@ function initPattern(globals){
};
}
function getAllEdges(){
return {
mountains: mountains,
valleys: valleys,
borders: borders,
cuts: cuts,
triangulations: triangulations
}
}
function getPolygons(){//todo export fold complete
return foldData.faces_vertices;
function getFoldData(raw){
if (raw) return rawFold;
return foldData;
}
return {
......@@ -877,7 +869,6 @@ function initPattern(globals){
saveSVG: saveSVG,
getFacesAndVerticesForEdges: getFacesAndVerticesForEdges,
triangulatePolys: triangulatePolys,
getAllEdges: getAllEdges,
getPolygons: getPolygons
getFoldData: getFoldData
}
}
\ No newline at end of file
......@@ -39,52 +39,16 @@ function saveFOLD(){
json.vertices_coords.push([vertex.x, vertex.y, vertex.z]);
}
var edges = globals.pattern.getAllEdges();
for (var i=0;i<edges.mountains.length;i++){
var nodes = edges.mountains[i];
json.edges_vertices.push([nodes[0], nodes[1]]);
json.edges_assignment.push("M");
}
for (var i=0;i<edges.valleys.length;i++){
var nodes = edges.valleys[i];
json.edges_vertices.push([nodes[0], nodes[1]]);
json.edges_assignment.push("V");
}
for (var i=0;i<edges.cuts.length;i++){
var nodes = edges.cuts[i];
json.edges_vertices.push([nodes[0], nodes[1]]);
json.edges_assignment.push("B");
}
for (var i=0;i<edges.outlines.length;i++){
var nodes = edges.outlines[i];
json.edges_vertices.push([nodes[0], nodes[1]]);
json.edges_assignment.push("B");
}
if (globals.triangulateFOLDexport){
for (var i=0;i<edges.triangulations.length;i++){
var nodes = edges.triangulations[i];
json.edges_vertices.push([nodes[0], nodes[1]]);
json.edges_assignment.push("F");
}
for (var i=0;i<geo.faces.length;i++){
var face = geo.faces[i];
json.faces_vertices.push([face.a, face.b, face.c]);
}
} else {
var polys = globals.pattern.getPolygons();
for (var i=0;i<polys.length;i++){
var poly = polys[i].slice();
poly.pop();
json.faces_vertices.push(poly);
}
}
var useTriangulated = globals.triangulateFOLDexport;
var fold = globals.pattern.getFoldData(!useTriangulated);
json.edges_vertices = fold.edges_vertices;
json.edges_assignment = fold.edges_assignment;
json.faces_vertices = fold.faces_vertices;
if (globals.exportFoldAngle){
var foldAngles = [];
//todo target fold angles or current?
json.edges_foldAngles = foldAngles;
json.edges_foldAngles = fold.edges_foldAngles;
}
console.log(json);
var blob = new Blob([JSON.stringify(json, null, 4)], {type: 'application/octet-binary'});
saveAs(blob, filename + ".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