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

listento insted of bind, simplifying code

parent df631ee6
No related branches found
No related tags found
No related merge requests found
...@@ -5,22 +5,23 @@ ...@@ -5,22 +5,23 @@
$(function(){ $(function(){
window.workers = persistentWorkers(8);
three = new ThreeView(); three = new ThreeView();
//init models and views //init models and views
var fillGeometry = new FillGeometry();//singleton var fillGeometry = new FillGeometry();//singleton
three.setFillGeometry(fillGeometry);
new ImportView({model: fillGeometry}); new ImportView({model: fillGeometry});
lattice = new Lattice(); lattice = new Lattice();
three.setFillGeometry(fillGeometry);
//window.fillGeometry.set({geometry:"stuff"});
setupNavBar(); setupNavBar();
workers = persistentWorkers(8);
......
...@@ -48,7 +48,7 @@ FillGeometry = Backbone.Model.extend({ ...@@ -48,7 +48,7 @@ FillGeometry = Backbone.Model.extend({
var helper = new THREE.BoundingBoxHelper(this.get("mesh"), 0x000000); var helper = new THREE.BoundingBoxHelper(this.get("mesh"), 0x000000);
this.set("boundingBoxHelper", helper); this.set("boundingBoxHelper", helper);
helper.update(); helper.update();
three.scene.add(helper.object); // three.scene.add(helper.object);
this.trigger("change:boundingBoxHelper"); this.trigger("change:boundingBoxHelper");
}, },
......
...@@ -105,5 +105,4 @@ function persistentWorkers(numWorkers){ ...@@ -105,5 +105,4 @@ function persistentWorkers(numWorkers){
} }
return {map:map, allWorkers:allWorkers};//return all public methods and vars return {map:map, allWorkers:allWorkers};//return all public methods and vars
} }
\ No newline at end of file
...@@ -17,7 +17,7 @@ ImportView = Backbone.View.extend({ ...@@ -17,7 +17,7 @@ ImportView = Backbone.View.extend({
initialize: function(){ initialize: function(){
_.bindAll(this, "render", "onMeshLoad"); _.bindAll(this, "render", "onMeshLoad");
this.model.bind("change:filename change:boundingBoxHelper", this.render);//boundingBoxHelper covers orientation this.listenTo(this.model, "change:filename change:boundingBoxHelper", this.render);//boundingBoxHelper covers orientation
this.render(); this.render();
}, },
......
/**
* Created by aghassaei on 1/16/15.
*/
ThreeView = Backbone.View.extend({ ThreeView = Backbone.View.extend({
...@@ -10,7 +12,7 @@ ThreeView = Backbone.View.extend({ ...@@ -10,7 +12,7 @@ ThreeView = Backbone.View.extend({
initialize: function(){ initialize: function(){
_.bindAll(this, "render", "animate", "onWindowResize"); _.bindAll(this, "render", "animate", "onWindowResize", "clearAll");
this.camera.position.z = 500; this.camera.position.z = 500;
this.scene.fog = new THREE.FogExp2( 0xcccccc, 0.002); this.scene.fog = new THREE.FogExp2( 0xcccccc, 0.002);
...@@ -55,14 +57,16 @@ ThreeView = Backbone.View.extend({ ...@@ -55,14 +57,16 @@ ThreeView = Backbone.View.extend({
} }
}, },
setFillGeometry: function(fillGeometry){ setFillGeometry: function(fillGeometry){//call this once
var self = this; this.fillGeometry = fillGeometry;
fillGeometry.bind("change:geometry", function(){ this.listenTo(fillGeometry, "change:geometry", this.replaceFillGeometry);
if (fillGeometry.previous("mesh")) self.scene.remove(fillGeometry.previous("mesh")); this.listenTo(fillGeometry, "change:orientation", this.render);
self.render(); this.replaceFillGeometry();
}); },
this.scene.add(fillGeometry.get("mesh"));
fillGeometry.bind("change:mesh change:orientation", this.render); replaceFillGeometry: function(){
if (this.fillGeometry.previous("mesh")) this.scene.remove(this.fillGeometry.previous("mesh"));
this.scene.add(this.fillGeometry.get("mesh"));
this.render(); this.render();
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment