From f76d8b474fc4d6a819fb8c4f721b41d9b3450296 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 6 Feb 2015 16:41:47 -0500 Subject: [PATCH] reorganizing --- js/main.js | 8 ++++---- js/menus/LatticeMenuView.js | 24 ++++++++++-------------- js/menus/MenuWrapperView.js | 14 +++++++------- js/models/AppState.js | 36 ++++++++++++++++++++++++++++++------ js/models/BasePlane.js | 9 +-------- js/models/Lattice.js | 29 +---------------------------- js/models/ThreeModel.js | 2 +- main.html | 2 +- 8 files changed, 55 insertions(+), 69 deletions(-) diff --git a/js/main.js b/js/main.js index 1e5b3f55..316d0df3 100644 --- a/js/main.js +++ b/js/main.js @@ -12,10 +12,10 @@ $(function(){ window.three = new ThreeModel(); //setup ui - window.appState = new AppState(); - var highlighter = new Highlighter({model:window.appState.get("lattice")}); - new NavBar({model:window.appState}); + var appState = new AppState(); + var highlighter = new Highlighter({model:appState.get("lattice")}); + new NavBar({model:appState}); //threeJS View - new ThreeView({model:window.three, appState:window.appState, highlighter:highlighter}); + new ThreeView({model:window.three, appState:appState, highlighter:highlighter}); }); diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 38081fbe..20309ceb 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -19,39 +19,35 @@ LatticeMenuView = Backbone.View.extend({ initialize: function(options){ - this.appState = options.appState; + this.lattice = options.lattice; _.bindAll(this, "render"); - this.listenTo(this.model, "change", function(){ - if(!(this.model.hasChanged('scale'))){//ignore scale mode changes - this.render(); - }; - }); - + this.listenTo(this.model, "change", this.render); + this.listenTo(this.lattice, "change:numCells", this.render) }, _clearCells: function(e){ e.preventDefault(); - this.model.clearCells(); + this.lattice.clearCells(); }, _changeScale: function(e){ e.preventDefault(); var val = parseFloat($(e.target).val()); if (isNaN(val)) return; - this.model.set("scale", val); + this.lattice.set("scale", val); }, _sliderDidSlide: function(e){ var scale = $(e.target)[0].value; -// this.model.set("scale", $(e.target)[0].value); - this.model.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui +// this.lattice.set("scale", $(e.target)[0].value); + this.lattice.previewScaleChange(scale);//does not trigger lattice change event - no rerendering of ui $("#latticeScale").val(scale); window.three.render(); }, _changeScaleSlider: function(e){ - this.model.set("scale", $(e.target)[0].value); + this.lattice.set("scale", $(e.target)[0].value); }, _changeCellType: function(e){ @@ -101,8 +97,8 @@ LatticeMenuView = Backbone.View.extend({ }, render: function(){ - if (this.appState.get("currentTab") != "lattice") return; - this.$el.html(this.template(this.model.attributes)); + if (this.model.get("currentTab") != "lattice") return; + this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes))); $('#scaleSlider').slider({ formatter: function(value) { diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 4fefe708..b5ee36b5 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -16,12 +16,12 @@ MenuWrapper = Backbone.View.extend({ _.bindAll(this, "render", "_updateCurrentTab", "_setVisibility", "_hide", "_show"); //init all tab view controllers - this.latticeMenu = new LatticeMenuView({model:options.lattice, appState:this.model}); - this.importMenu = new ImportMenuView({lattice:options.lattice, appState:this.model}); - this.sketchMenu = new SketchMenuView({model:options.lattice.get("basePlane"), appState:this.model}); - this.partMenu = new PartMenuView({model:options.lattice, appState:this.model}); - this.scriptMenu = new ScriptMenuView({appState:this.model}); - this.animationMenu = new AnimationMenuView({model:options.lattice.get("basePlane"), appState:this.model}); + this.latticeMenu = new LatticeMenuView({model:this.model, lattice:options.lattice}); +// this.importMenu = new ImportMenuView({lattice:options.lattice, appState:this.model}); +// this.sketchMenu = new SketchMenuView({model:options.lattice.get("basePlane"), appState:this.model}); +// this.partMenu = new PartMenuView({model:options.lattice, appState:this.model}); +// this.scriptMenu = new ScriptMenuView({appState:this.model}); +// this.animationMenu = new AnimationMenuView({model:options.lattice.get("basePlane"), appState:this.model}); this.lattice = options.lattice; @@ -32,7 +32,7 @@ MenuWrapper = Backbone.View.extend({ //bind events this.listenTo(this.model, "change:currentNav", this.render); - this.listenTo(options.lattice, "change:cellType change:connectionType", this._populateAndShow); + this.listenTo(this.model, "change:cellType change:connectionType", this._populateAndShow); this.listenTo(this.model, "change:currentTab", this._updateCurrentTab); this.listenTo(this.model, "change:menuIsVisible", this._setVisibility); diff --git a/js/models/AppState.js b/js/models/AppState.js index fa93c457..13e15096 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -18,7 +18,28 @@ AppState = Backbone.Model.extend({ lattice: null, menuWrapper: null, + cellMode: "cell", + cellType: "octa", + connectionType: "face", + partType: "triangle", + + allCellTypes: {octa:"Octahedron", cube:"Cube"}, + allConnectionTypes: { + octa: {face:"Face", edge:"Edge", edgeRot:"Rotated Edge", vertex:"Vertex"}, + cube: {face:"Face"} + }, + allPartTypes:{ + octa:{ + face: {triangle:"Triangle"}, + edge: {triangle:"Triangle"}, + edgeRot: {triangle:"Triangle"}, + vertex:{square:"Square", xShape:"X"} + }, + cube:{ + face: null + } + }, menuIsVisible: true, @@ -35,11 +56,14 @@ AppState = Backbone.Model.extend({ //bind events $(document).bind('keydown', {state:true}, this._handleKeyStroke); $(document).bind('keyup', {state:false}, this._handleKeyStroke); + this.listenTo(this, "change:currentTab", this._storeTab); - this.listenTo(this, "change:currentTab", this._updateLatticeMode); - this.listenTo(this, "change:cellMode", this._cellModeDidChange); this.listenTo(this, "change:currentNav", this._updateCurrentTabForNav); - this.listenTo(this, "change:lattice", this._renderNewLattice); + + this.listenTo(this, "change:currentTab", this._updateCellMode); + this.listenTo(this, "change:cellMode", this._cellModeDidChange); + + this.listenTo(this, "change:lattice", this._buildLatticeMenu); this.set("lattice", new OctaFaceLattice({appState:this})); this.get("lattice").addCellAtIndex({x:0,y:0,z:0}); @@ -59,7 +83,7 @@ AppState = Backbone.Model.extend({ else if (currentNav == "navAssemble") this.set("lastAssembleTab", currentTab); }, - _updateLatticeMode: function(){ + _updateCellMode: function(){ var currentTab = this.get("currentTab"); if (currentTab == "lattice") this.set("cellMode", "cell"); else if (currentTab == "import") this.set("cellMode", "cell"); @@ -76,14 +100,14 @@ AppState = Backbone.Model.extend({ this.get("lastSimulationTab"), {silent:true}); else if (navSelection == "navAssemble") this.set("currentTab", this.get("lastAssembleTab"), {silent:true}); - this._updateLatticeMode();//a little bit hacky, this updates the lattice, but holds off on updating the menus til the animation has happened + this._updateCellMode();//a little bit hacky, this updates the cell mode, but holds off on updating the menus til the animation has happened }, _cellModeDidChange: function(){ this.get("lattice").cellModeDidChange(this.get("cellMode")); }, - _renderNewLattice: function(){ + _buildLatticeMenu: function(){ this.set("menuWrapper", new MenuWrapper({lattice:this.get("lattice"), model:this})); }, diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index a27e9a00..191c31a6 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -22,7 +22,7 @@ BasePlane = Backbone.Model.extend({ this.listenTo(this, "change:zIndex", this._renderZIndexChange); //draw mesh - this.set("mesh", this._makeBasePlaneMesh(options.cellType, options.connectionType)); + this.set("mesh", this._makeBasePlaneMesh()); this.updateScale(options.scale); this._showMesh(); @@ -38,13 +38,6 @@ BasePlane = Backbone.Model.extend({ _renderForCurrentScene: function(){ }, - updateGeometry: function(cellType, connectionType, scale){ - this._removeMesh(); - this.set("mesh", this._makeBasePlaneMesh(cellType, connectionType)); - this.updateScale(scale); - this._showMesh(); - }, - updateScale: function(scale){ this.get("mesh").scale.set(scale, scale, scale); }, diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 49ba5c9a..9a782610 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -7,31 +7,12 @@ Lattice = Backbone.Model.extend({ defaults: { scale: window.defaultLatticeScale, - cellType: "octa", - connectionType: "face", - allCellTypes: {octa:"Octahedron", cube:"Cube"}, - allConnectionTypes: { - octa: {face:"Face", edge:"Edge", edgeRot:"Rotated Edge", vertex:"Vertex"}, - cube: {face:"Face"} - }, - allPartTypes:{ - octa:{ - face: {triangle:"Triangle"}, - edge: {triangle:"Triangle"}, - edgeRot: {triangle:"Triangle"}, - vertex:{square:"Square", xShape:"X"} - }, - cube:{ - face: null - } - }, nodes: [], cells: [[[null]]],//3D matrix containing all cells and null, dynamic size inverseCells: [[[null]]],//3d matrix containing all inverse cells and null, dynamic size cellsMin: {x:0, y:0, z:0},//min position of cells matrix cellsMax: {x:0, y:0, z:0},//max position of cells matrix numCells: 0, - partType: "triangle", basePlane: null//plane to build from }, @@ -41,7 +22,6 @@ Lattice = Backbone.Model.extend({ //bind events this.listenTo(this, "change:scale", this._scaleDidChange); - this.listenTo(this, "change:cellType change:connectionType", this._changeLatticeStructure); this.appState = options.appState; this._initialize();//call subclass init @@ -293,11 +273,6 @@ Lattice = Backbone.Model.extend({ this.get("basePlane").updateScale(scale); }, - _changeLatticeStructure: function(){ - this.clearCells(); - this.get("basePlane").updateGeometry(this.get("cellType"), this.get("connectionType"), this.get("scale")); - }, - //////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////UTILS/////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// @@ -332,9 +307,7 @@ OctaFaceLattice = Lattice.extend({ //bind events this.listenTo(this, "change:columnSeparation", this._changeColSeparation); - this.set("basePlane", new OctaBasePlane({cellType:this.get("cellType"), - connectionType:this.get("connectionType"), - scale:this.get("scale")})); + this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); this.set("columnSeparation", 0.0); }, diff --git a/js/models/ThreeModel.js b/js/models/ThreeModel.js index e6091708..0663eeb1 100644 --- a/js/models/ThreeModel.js +++ b/js/models/ThreeModel.js @@ -23,7 +23,7 @@ function ThreeModel(){ camera.position.z = 165; camera.up.set(0,0,1);//set z axis as "up" - scene.fog = new THREE.FogExp2(0xcccccc, 0.001); + scene.fog = new THREE.FogExp2(0xcccccc, 0.000); // lights var light = new THREE.DirectionalLight(0xffffff); diff --git a/main.html b/main.html index c441abe2..932f37b7 100644 --- a/main.html +++ b/main.html @@ -37,7 +37,7 @@ <!--global variables--> <script> - window.defaultLatticeScale = 1; + window.defaultLatticeScale = 20; </script> <!--multi-threading--> -- GitLab