diff --git a/js/main.js b/js/main.js index 277bebf3aacc18cf6a6829fa4c58f755c5302837..d1ce6d60b2d0400f5541850bb14eb049a6df44e7 100644 --- a/js/main.js +++ b/js/main.js @@ -8,7 +8,7 @@ $(function(){ three = Three(); //init models and views - window.fillGeometry = new FillGeometry();//init a singleton, add to global scope + fillGeometry = new FillGeometry();//init a singleton, add to global scope new ImportView({model: window.fillGeometry}); diff --git a/js/models/fillGeometry.js b/js/models/fillGeometry.js index 1fd5384908edb1cd92fd02144be952713124df14..a856292b9bf86bf0682e131adaf099a209437d0e 100644 --- a/js/models/fillGeometry.js +++ b/js/models/fillGeometry.js @@ -15,7 +15,7 @@ FillGeometry = Backbone.Model.extend({ side:THREE.DoubleSide}), geometry: new THREE.BoxGeometry(100, 100, 100), filename: "Cube", - orientation: "", + orientation: [0,0,0] }, initialize: function(){ @@ -53,11 +53,14 @@ FillGeometry = Backbone.Model.extend({ makeBoundingBoxHelper: function(){ var helper = new THREE.BoundingBoxHelper(this.get("mesh"), 0x000000); this.set("boundingBoxHelper", helper); + helper.update(); three.scene.add(helper.object); + console.log(helper.box); }, updateBoundingBox: function(){ this.get("boundingBoxHelper").update(); + console.log(helper.box); // var boundingBox = this.get("geometry").boundingBox; // if (!boundingBox){ @@ -75,14 +78,19 @@ FillGeometry = Backbone.Model.extend({ }, rotate: function(axis){ + var orientation = this.get("orientation"); var mesh = this.get("mesh"); if (axis == "x"){ mesh.rotateX(Math.PI/2); + orientation[0] += Math.PI/2; } else if (axis == "y"){ mesh.rotateX(Math.PI/2); + orientation[1] += Math.PI/2; } else { mesh.rotateX(Math.PI/2); + orientation[2] += Math.PI/2; } + this.trigger("change:orientation"); } }); diff --git a/js/views/importMenu.js b/js/views/importMenu.js index 3713ff3d81c1080b4ab0f69ce876fcdcf642a6b8..8c8c102aa43ef387429bee81c1a5bef33d9b8497 100644 --- a/js/views/importMenu.js +++ b/js/views/importMenu.js @@ -80,10 +80,11 @@ $(function(){ $("#STLFilename").html("Current file loaded:  "+name); } - function showDimensions(scale){ - var boundingBox = modelMesh.geometry.boundingBox; - $("#meshDimensions").html("Dimensions: " + ((boundingBox.max.x - boundingBox.min.x)*scale).toFixed(1) + " x " + - ((boundingBox.max.y - boundingBox.min.y)*scale).toFixed(1) + " x " + ((boundingBox.max.z - boundingBox.min.z)*scale).toFixed(1)); + 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){ diff --git a/js/views/importView.js b/js/views/importView.js index 940723c37156e316ed9d4fc85ca81dc58ec4f0e6..91bc2318d61a87144579dcf04465a0a27f18a3d4 100644 --- a/js/views/importView.js +++ b/js/views/importView.js @@ -66,9 +66,11 @@ ImportView = Backbone.View.extend({ }, makeDimensionString: function(){ -// var boundingBox = this.model.get("boundingBox"); -// return ((boundingBox.max.x - boundingBox.min.x)*scale).toFixed(1) + " x " + -// ((boundingBox.max.y - boundingBox.min.y)*scale).toFixed(1) + " x " + ((boundingBox.max.z - boundingBox.min.z)*scale).toFixed(1); + //todo add in orientation effects + var scale = this.model.get("scale"); + var bounds = this.model.get("bounds"); + return ((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); }, rotate: function(e){