From 36a34bc9eebc7b66715e4e09b3a54a4ffce267b9 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 17 Jan 2015 18:11:32 -0500 Subject: [PATCH] more cleaning up --- js/main.js | 8 +++++--- js/views/fillGeometryView.js | 33 +++++++++++++++++++++++++++++++++ js/views/threeView.js | 13 ------------- main.html | 1 + 4 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 js/views/fillGeometryView.js diff --git a/js/main.js b/js/main.js index c171dfe8..d3824df9 100644 --- a/js/main.js +++ b/js/main.js @@ -7,13 +7,15 @@ $(function(){ window.workers = persistentWorkers(8); + + //init threeJS view var threeModel = new ThreeModel(); - var three = new ThreeView({model:threeModel});//singleton, my threejs view + var three = new ThreeView({model:threeModel}); - //init models and views + //backbone models and views var fillGeometry = new FillGeometry();//singleton, mesh to fill with lattice new ImportView({model: fillGeometry}); - three.setFillGeometry(fillGeometry); + new FillGeometryView({model: fillGeometry, three:threeModel}); lattice = new Lattice(); diff --git a/js/views/fillGeometryView.js b/js/views/fillGeometryView.js new file mode 100644 index 00000000..df71d156 --- /dev/null +++ b/js/views/fillGeometryView.js @@ -0,0 +1,33 @@ +/** + * Created by aghassaei on 1/16/15. + */ + + +FillGeometryView = Backbone.View.extend({ + + events: { + + + }, + + initialize: function(options){ + + this.three = options.three; + + //bind events + this.listenTo(this.model, "change:geometry", this.replaceFillGeometry); + this.listenTo(this.model, "change:orientation", this.render); + + this.replaceFillGeometry(); + }, + + replaceFillGeometry: function(){ + if (this.model.previous("mesh")) this.three.sceneRemove(this.model.previous("mesh")); + this.three.sceneAdd(this.model.get("mesh")); + this.three.render(); + }, + + render: function(){ + this.three.render(); + } +}); \ No newline at end of file diff --git a/js/views/threeView.js b/js/views/threeView.js index e3a8f9bf..bc2452b9 100644 --- a/js/views/threeView.js +++ b/js/views/threeView.js @@ -20,19 +20,6 @@ ThreeView = Backbone.View.extend({ this.animate(); }, - setFillGeometry: function(fillGeometry){//call this once - this.fillGeometry = fillGeometry; - this.listenTo(fillGeometry, "change:geometry", this.replaceFillGeometry); - this.listenTo(fillGeometry, "change:orientation", this.model.render); - this.replaceFillGeometry(); - }, - - replaceFillGeometry: function(){ - if (this.fillGeometry.previous("mesh")) this.model.sceneRemove(this.fillGeometry.previous("mesh")); - this.model.sceneAdd(this.fillGeometry.get("mesh")); - this.model.render(); - }, - animate: function(){ requestAnimationFrame(this.animate); this.controls.update(); diff --git a/main.html b/main.html index 6e8122c4..746e828a 100644 --- a/main.html +++ b/main.html @@ -47,6 +47,7 @@ <!--views--> <script src="js/views/threeView.js"></script> <script src="js/views/importView.js"></script> + <script src="js/views/fillGeometryView.js"></script> <script src="js/main.js"></script> -- GitLab