diff --git a/js/main.js b/js/main.js index 3eb1a8ddfe05962156d8c65a51a15bb311723f75..e322e1276ea927ea475b8bc11e805c289dccc975 100644 --- a/js/main.js +++ b/js/main.js @@ -8,12 +8,15 @@ $(function(){ three = new ThreeView(); //init models and views - fillGeometry = new FillGeometry();//init a singleton, add to global scope - new ImportView({model: window.fillGeometry}); + var fillGeometry = new FillGeometry();//singleton + new ImportView({model: fillGeometry}); lattice = new Lattice(); + three.setFillGeometry(fillGeometry); + + //window.fillGeometry.set({geometry:"stuff"}); setupNavBar(); diff --git a/js/models/fillGeometry.js b/js/models/fillGeometry.js index 87ba21e90302b92ff2e5059eb228c571d541da1b..4ccbd281b255e58fefe09ca1d8cf36d1c4e894dc 100644 --- a/js/models/fillGeometry.js +++ b/js/models/fillGeometry.js @@ -24,17 +24,13 @@ FillGeometry = Backbone.Model.extend({ this.on("change:mesh", this.makeBoundingBoxHelper); this.on("change:orientation", this.updateBoundingBox); this.on("change:geometry", this.buildNewMesh); - this.on("change:mesh change:orientation", this.render); this.buildNewMesh(); }, buildNewMesh:function(){ - - if (this.previous("mesh")) three.scene.remove(this.previous("mesh"));//remove current mesh from scene this.set({orientation:this.defaults.orientation}, {silent:true});//restore defaults var mesh = new THREE.Mesh(this.get("geometry"), this.get("material")); - three.scene.add(mesh); this.set({mesh: mesh}); //send new geometry out to workers @@ -61,10 +57,6 @@ FillGeometry = Backbone.Model.extend({ this.trigger("change:boundingBoxHelper"); }, - render: function(){ - three.render(); - }, - rotate: function(axis){ var orientation = this.get("orientation"); var mesh = this.get("mesh"); diff --git a/js/views/threeView.js b/js/views/threeView.js index c14b31f27cc7d57d595efd8f721f5c47d77100a9..a71cc965153a43be66ee1e7f31af1b278dcd9ab5 100644 --- a/js/views/threeView.js +++ b/js/views/threeView.js @@ -4,11 +4,6 @@ ThreeView = Backbone.View.extend({ el: "#threeContainer", - events: { - - - }, - camera: new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 1000), scene: new THREE.Scene(), renderer: new THREE.WebGLRenderer({antialias:false}), @@ -50,7 +45,6 @@ ThreeView = Backbone.View.extend({ var material = new THREE.MeshLambertMaterial( { color:0xffffff, shading: THREE.FlatShading } ); for ( var i = 0; i < 500; i ++ ) { - var mesh = new THREE.Mesh( geometry, material ); mesh.position.x = ( Math.random() - 0.5 ) * 1000; mesh.position.y = ( Math.random() - 0.5 ) * 1000; @@ -58,10 +52,20 @@ ThreeView = Backbone.View.extend({ mesh.updateMatrix(); mesh.matrixAutoUpdate = false; this.scene.add(mesh); - } }, + setFillGeometry: function(fillGeometry){ + var self = this; + fillGeometry.bind("change:geometry", function(){ + if (fillGeometry.previous("mesh")) self.scene.remove(fillGeometry.previous("mesh")); + self.render(); + }); + this.scene.add(fillGeometry.get("mesh")); + fillGeometry.bind("change:mesh change:orientation", this.render); + this.render(); + }, + onWindowResize: function(){ this.camera.aspect = window.innerWidth/window.innerHeight; this.camera.updateProjectionMatrix();