Commit 2269d703 authored by amandaghassaei's avatar amandaghassaei

stl save options

parent 54fd4251
......@@ -325,3 +325,17 @@ svg{
margin-top:9px;
color: white;
}
.bigLabel{
font-size:18px;
}
.checkbox.bigLabel .icons, .radio .icons {
top: 2px;
}
.smallTxt{
font-size: 14px;
}
#stlFilename{
width:300px;
}
......@@ -597,13 +597,18 @@
<span aria-hidden="true">&times;</span>
</button>
<p><b>Export STL</b><br/><br/>
settings:<br/>
single sided/double sided<br/>
scale
Filename: &nbsp;&nbsp;<input id="stlFilename" value="" placeholder="" class="text form-control" type="text"> .stl<br/><br/>
Scale: &nbsp;&nbsp;<input id="stlScale" value="" placeholder="" class="form-control" type="text"><br/><br/>
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>
</div>
<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>
</div>
</div><!-- /.modal-content -->
......
......@@ -22,8 +22,22 @@ function initControls(globals){
});
setLink("#exportSTL", function(){
updateDimensions();
$("#stlFilename").val(globals.filename + " : " + parseInt(globals.creasePercent*100) + "PercentFolded");
$('#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(){
saveSTL();
......@@ -261,6 +275,7 @@ function initControls(globals){
if ($input.hasClass("int")){
if (isNaN(parseInt(val))) return;
val = parseInt(val);
} else if ($input.hasClass("text")){
} else {
if (isNaN(parseFloat(val))) return;
val = parseFloat(val);
......
......@@ -8,6 +8,7 @@ function initGlobals(){
var _globals = {
navMode: "simulation",
scale: 1,
//view
colorMode: "color",
......@@ -54,7 +55,7 @@ function initGlobals(){
filename: null,
extension: null,
doublesidedSTL: false,
scale: 1,
stlScale: 1,
userInteractionEnabled: false
......
......@@ -343,6 +343,11 @@ function initModel(globals){
return creases;
}
function getDimensions(){
geometry.computeBoundingBox();
return geometry.boundingBox.max.clone().sub(geometry.boundingBox.min);
}
return {
pause: pause,
resume: resume,
......@@ -361,6 +366,7 @@ function initModel(globals){
getColorsArray: getColorsArray,
sync: sync,
getMesh: getMesh,
getVertices: getVertices
getVertices: getVertices,
getDimensions: getDimensions
}
}
\ No newline at end of file
......@@ -4,17 +4,33 @@
function saveSTL(){
var geo = globals.model.getGeometry().clone();
if (geo.vertices.length == 0) {
var geo = new THREE.Geometry().fromBufferGeometry( globals.model.getGeometry() );
if (geo.vertices.length == 0 || geo.faces.length == 0) {
globals.warn("No geometry to save.");
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 = [];
data.push({geo: geo, offset:new THREE.Vector3(0,0,0), orientation:new THREE.Quaternion(0,0,0,1)});
var stlBin = geometryToSTLBin(data);
if (!stlBin) return;
var blob = new Blob([stlBin], {type: 'application/octet-binary'});
saveAs(blob, globals.filename + " : " + parseInt(globals.creasePercent*100) + "PercentFolded.stl");
$("#exportSTLModal").modal("hide");
var filename = $("#stlFilename").val();
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