Commit 2269d703 authored by amandaghassaei's avatar amandaghassaei
Browse files

stl save options

parent 54fd4251
...@@ -325,3 +325,17 @@ svg{ ...@@ -325,3 +325,17 @@ svg{
margin-top:9px; margin-top:9px;
color: white; color: white;
} }
.bigLabel{
font-size:18px;
}
.checkbox.bigLabel .icons, .radio .icons {
top: 2px;
}
.smallTxt{
font-size: 14px;
}
#stlFilename{
width:300px;
}
...@@ -597,13 +597,18 @@ ...@@ -597,13 +597,18 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
<p><b>Export STL</b><br/><br/> <p><b>Export STL</b><br/><br/>
settings:<br/> Filename: &nbsp;&nbsp;<input id="stlFilename" value="" placeholder="" class="text form-control" type="text"> .stl<br/><br/>
single sided/double sided<br/> Scale: &nbsp;&nbsp;<input id="stlScale" value="" placeholder="" class="form-control" type="text"><br/><br/>
scale Dimensions: &nbsp;&nbsp;<b><span id="stlDimensions"></span></b><br/>
<span class="smallTxt">(the STL file format is unitless, but typically assumed to be either in inches or mm)</span><br/><br/>
<label class="bigLabel checkbox" for="doublesidedSTL">
<input id="doublesidedSTL" data-toggle="checkbox" class="custom-checkbox layersSelector" type="checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>
Double Sided
</label>
</p> </p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="doSTLsave" type="button" class="btn btn-success">Save</button> <button id="doSTLsave" type="button" class="btn btn-success" data-dismiss="modal">Save</button>
<button type="button" class="btn btn default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn default" data-dismiss="modal">Cancel</button>
</div> </div>
</div><!-- /.modal-content --> </div><!-- /.modal-content -->
......
...@@ -22,8 +22,22 @@ function initControls(globals){ ...@@ -22,8 +22,22 @@ function initControls(globals){
}); });
setLink("#exportSTL", function(){ setLink("#exportSTL", function(){
updateDimensions();
$("#stlFilename").val(globals.filename + " : " + parseInt(globals.creasePercent*100) + "PercentFolded");
$('#exportSTLModal').modal('show'); $('#exportSTLModal').modal('show');
}); });
setInput("#stlScale", globals.stlScale, function(val){
globals.stlScale = val;
updateDimensions();
}, 0);
function updateDimensions(){
var dim = globals.model.getDimensions();
dim.multiplyScalar(globals.stlScale/globals.scale);
$("#stlDimensions").html(dim.x.toFixed(2) + " x " + dim.y.toFixed(2) + " x " + dim.z.toFixed(2));
}
setCheckbox("#doublesidedSTL", globals.doublesidedSTL, function(val){
globals.doublesidedSTL = val;
});
setLink("#doSTLsave", function(){ setLink("#doSTLsave", function(){
saveSTL(); saveSTL();
...@@ -261,6 +275,7 @@ function initControls(globals){ ...@@ -261,6 +275,7 @@ function initControls(globals){
if ($input.hasClass("int")){ if ($input.hasClass("int")){
if (isNaN(parseInt(val))) return; if (isNaN(parseInt(val))) return;
val = parseInt(val); val = parseInt(val);
} else if ($input.hasClass("text")){
} else { } else {
if (isNaN(parseFloat(val))) return; if (isNaN(parseFloat(val))) return;
val = parseFloat(val); val = parseFloat(val);
......
...@@ -8,6 +8,7 @@ function initGlobals(){ ...@@ -8,6 +8,7 @@ function initGlobals(){
var _globals = { var _globals = {
navMode: "simulation", navMode: "simulation",
scale: 1,
//view //view
colorMode: "color", colorMode: "color",
...@@ -54,7 +55,7 @@ function initGlobals(){ ...@@ -54,7 +55,7 @@ function initGlobals(){
filename: null, filename: null,
extension: null, extension: null,
doublesidedSTL: false, doublesidedSTL: false,
scale: 1, stlScale: 1,
userInteractionEnabled: false userInteractionEnabled: false
......
...@@ -343,6 +343,11 @@ function initModel(globals){ ...@@ -343,6 +343,11 @@ function initModel(globals){
return creases; return creases;
} }
function getDimensions(){
geometry.computeBoundingBox();
return geometry.boundingBox.max.clone().sub(geometry.boundingBox.min);
}
return { return {
pause: pause, pause: pause,
resume: resume, resume: resume,
...@@ -361,6 +366,7 @@ function initModel(globals){ ...@@ -361,6 +366,7 @@ function initModel(globals){
getColorsArray: getColorsArray, getColorsArray: getColorsArray,
sync: sync, sync: sync,
getMesh: getMesh, getMesh: getMesh,
getVertices: getVertices getVertices: getVertices,
getDimensions: getDimensions
} }
} }
\ No newline at end of file
...@@ -4,17 +4,33 @@ ...@@ -4,17 +4,33 @@
function saveSTL(){ function saveSTL(){
var geo = globals.model.getGeometry().clone(); var geo = new THREE.Geometry().fromBufferGeometry( globals.model.getGeometry() );
if (geo.vertices.length == 0) {
if (geo.vertices.length == 0 || geo.faces.length == 0) {
globals.warn("No geometry to save."); globals.warn("No geometry to save.");
return; return;
} }
if (globals.stlScale != 1){
for (var i=0;i<geo.vertices.length;i++){
geo.vertices[i].multiplyScalar(globals.stlScale);
}
}
if (globals.doublesidedSTL){
var numFaces = geo.faces.length;
for (var i=0;i<numFaces;i++){
var face = geo.faces[i];
geo.faces.push(new THREE.Face3(face.a, face.c, face.b));
}
}
var data = []; var data = [];
data.push({geo: geo, offset:new THREE.Vector3(0,0,0), orientation:new THREE.Quaternion(0,0,0,1)}); data.push({geo: geo, offset:new THREE.Vector3(0,0,0), orientation:new THREE.Quaternion(0,0,0,1)});
var stlBin = geometryToSTLBin(data); var stlBin = geometryToSTLBin(data);
if (!stlBin) return; if (!stlBin) return;
var blob = new Blob([stlBin], {type: 'application/octet-binary'}); var blob = new Blob([stlBin], {type: 'application/octet-binary'});
saveAs(blob, globals.filename + " : " + parseInt(globals.creasePercent*100) + "PercentFolded.stl"); var filename = $("#stlFilename").val();
$("#exportSTLModal").modal("hide"); if (filename == "") filename = globals.filename;
saveAs(blob, filename + ".stl");
} }
\ No newline at end of file
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