Skip to content
Snippets Groups Projects
Commit 7b95b84a authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

removing some stuff

parent 6c2d9bcc
Branches
No related tags found
No related merge requests found
/**
* Created by aghassaei on 1/8/15.
*/
$(function(){
three = three || {};
workers = workers || {};
modelMesh = {};
var modelScaleSlider = $('#stlModelScale');
function loadSTL(file){
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function (e) {
var geometry = e.content;
resetUI();
// _.each(workers.allWorkers, function(worker){
// worker.postMessage({model: JSON.stringify(e.content)});
// });
var material = new THREE.MeshLambertMaterial( { color:0xffa500, shading: THREE.FlatShading, transparent:true, opacity:0.5, side:THREE.DoubleSide} );
modelMesh = new THREE.Mesh(geometry, material);
three.scene.add(modelMesh);
three.render();
showDimensions(1);
$("#STLImportStats").fadeIn();
});
loader.load(file);
}
function resetUI(){
three.clearAll();
modelScaleSlider.slider('setValue', 1);
}
//load file from data folder
$(".stlImport").click(function(e){
e.preventDefault();
var fileName = $(this).data("file");
loadSTL('data/' + fileName);
setFileName(fileName);
});
//upload from local filesystem
$("#uploadSTL").change(function() {
var input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label, input.get(0).files]);
input.val("");
});
$('.btn-file :file').on('fileselect', function(event, numFiles, label, files) {
var reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onload = (function() {
return function(e) {
loadSTL(e.target.result);
setFileName(label);
}
})();
});
modelScaleSlider.slider({
formatter: function(value) {
return value;
}
});
modelScaleSlider.change(function(){
var value = $(this).slider('getValue');
modelMesh.scale.set(value,value,value);
showDimensions(value);
three.render();
});
function setFileName(name){
$("#STLFilename").html("Current file loaded:&nbsp&nbsp"+name);
}
function showDimensions(scale, orintation){
//todo add in orientation effects
var bounds = this.model.get("bounds");
$("#meshDimensions").html("Dimensions: " + ((bounds.max.x - bounds.min.x)*scale).toFixed(1) + " x " +
((bounds.max.y - bounds.min.y)*scale).toFixed(1) + " x " + ((bounds.max.z - bounds.min.z)*scale).toFixed(1));
}
$("#stlRotateX").click(function(e){
e.preventDefault();
modelMesh.rotateX(Math.PI/2);
three.render();
});
$("#stlRotateY").click(function(e){
e.preventDefault();
modelMesh.rotateY(Math.PI/2);
three.render();
});
$("#stlRotateZ").click(function(e){
e.preventDefault();
modelMesh.rotateZ(Math.PI/2);
three.render();
});
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment