diff --git a/js/main.js b/js/main.js index c171dfe81c3a50a93f295aef506f5a3e01255138..d3824df91749c0f4c14f6814986a58cfc60c1ca8 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 0000000000000000000000000000000000000000..df71d156eebf098377538b4dafd0d9daa7d079a4 --- /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 e3a8f9bf09fcc7a3620877df6c44fd2c91db4144..bc2452b94289e53ca423bd6a62a25fe8798ba0f2 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 6e8122c4dcae61f56d949eaf6d6461ce6109ef71..746e828a9ccd55e9e05a6e0472a1f7249ed4a433 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>