From df631ee61727fc89c3a6d38ecffbcaeba419d25b Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Sat, 17 Jan 2015 04:08:42 -0500
Subject: [PATCH] threeView edits

---
 js/main.js                |  7 +++++--
 js/models/fillGeometry.js |  8 --------
 js/views/threeView.js     | 18 +++++++++++-------
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/js/main.js b/js/main.js
index 3eb1a8dd..e322e127 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 87ba21e9..4ccbd281 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 c14b31f2..a71cc965 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();
-- 
GitLab