diff --git a/dependencies/loaders/STLLoader.js b/dependencies/loaders/STLLoader.js index e309326e2056514f94b361b25ef669db74180ac5..16564b7c2be7267a6303a396f85b12b471579fb2 100755 --- a/dependencies/loaders/STLLoader.js +++ b/dependencies/loaders/STLLoader.js @@ -18,6 +18,8 @@ * scene.add( new THREE.Mesh( geometry ) ); * }); * +* python -m SimpleHTTPServer +* * For binary STLs geometry might contain colors for vertices. To use it: * // use the same code to load STL as above * if (geometry.hasColors) { diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index 4e188caf9da1ccfedc9a772295a6619f72fc6a88..e8a6f025d4bccd1e8e25c2d077ecb2e2b4eb928f 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -91,13 +91,6 @@ ImportMenuView = Backbone.View.extend({ this.$el.html(this.template(this.model.attributes)); }, - destroy: function(){ - this.stopListening(); - this.model = null; - this.lattice = null; - this.appState = null; - }, - // makeDimensionString: function(){ // var bounds = this.model.get("boundingBoxHelper").box; // return (bounds.max.x - bounds.min.x).toFixed(1) + " x " + diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 731f97fb92918f12e47b7629ef1285bddcd0658d..04dc173decf13eff6a712d2d20df1285af86bee3 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -10,8 +10,8 @@ LatticeMenuView = Backbone.View.extend({ events: { "click #latticeMenuClearCells": "_clearCells", "change #latticeScale": "_changeScale", -// "click .cellType": "_changeCellType", -// "click .connectionType": "_changeConnectionType", + "click .cellType": "_changeCellType", + "click .connectionType": "_changeConnectionType", "slide #scaleSlider": "_sliderDidSlide", "slideStop #scaleSlider": "_changeScaleSlider" }, @@ -56,12 +56,21 @@ LatticeMenuView = Backbone.View.extend({ //reset everything to defaults silently if (cellType != this.model.get("cellType")){ - this._setLatticeToDefaultsSilently(cellType); + this._setAppStateToDefaultsSilently(cellType); } this.model.set("cellType", cellType); }, - _setLatticeToDefaultsSilently: function(newCellType, newConnectionType){ + _changeConnectionType: function(e){ + e.preventDefault(); + var connectionType = $(e.target).data("type"); + if (connectionType != this.model.get("connectionType")){ + this._setAppStateToDefaultsSilently(this.model.get("cellType"), connectionType); + } + this.model.set("connectionType", connectionType); + }, + + _setAppStateToDefaultsSilently: function(newCellType, newConnectionType){ if (newCellType == "cube") { if (!newConnectionType){ newConnectionType = "face"; @@ -87,15 +96,6 @@ LatticeMenuView = Backbone.View.extend({ } }, - _changeConnectionType: function(e){ - e.preventDefault(); - var connectionType = $(e.target).data("type"); - if (connectionType != this.model.get("connectionType")){ - this._setLatticeToDefaultsSilently(this.model.get("cellType"), connectionType); - } - this.model.set("connectionType", connectionType); - }, - render: function(){ if (this.model.get("currentTab") != "lattice") return; this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes))); @@ -107,12 +107,6 @@ LatticeMenuView = Backbone.View.extend({ }); }, - destroy: function(){ - this.stopListening(); - this.model = null; - this.lattice = null; - }, - template: _.template('\ Cell Type: \ <div class="btn-group">\ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 7b26324c8667425660c5bfaf2fdca84d4df0280b..60dc0fe72249cddf42341f59aec9d190f5250db7 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -23,8 +23,6 @@ MenuWrapper = Backbone.View.extend({ this.scriptMenu = new ScriptMenuView({model:this.model}); // this.animationMenu = new AnimationMenuView({model:options.lattice.get("basePlane"), appState:this.model}); - this.lattice = options.lattice; - //data names and titles this.designMenuTabs = {lattice:"Lattice", import:"Import", sketch:"Sketch", part:"Part", script:"Script"}; this.simMenuTabs = {physics:"Physics", part:"Part", material:"Material", optimize:"Optimize"}; @@ -87,7 +85,7 @@ MenuWrapper = Backbone.View.extend({ {navDesign:this.designMenuTabs, navSim:this.simMenuTabs, navAssemble:this.assemMenuTabs, - }, this.lattice.attributes))); + }))); this._updateCurrentTab(); this._show(); }, @@ -110,22 +108,6 @@ MenuWrapper = Backbone.View.extend({ this.model.set("menuIsVisible", true); }, - destroy: function(){ - this.stopListening(); - this.lattice = null; - this.template = null; - this._dealloc(this.latticeMenu); - this._dealloc(this.importMenu); - this._dealloc(this.sketchMenu); - this._dealloc(this.partMenu); - this._dealloc(this.scriptMenu); - }, - - _dealloc: function(object){ - object.destroy(); - object = null; - }, - template: _.template('\ <ul class="nav nav-tabs nav-justified">\ <% var dict = eval(currentNav);\ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index eb9f52c98b8cb3785342cd8ede6bfca8479d5d31..e266c67183759e0d9a3578b43bd6b2e81b396d7f 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -34,12 +34,6 @@ PartMenuView = Backbone.View.extend({ }); }, - destroy: function(){ - this.stopListening(); - this.model = null; - this.lattice = null; - }, - template: _.template('\ Part Type: \ <div class="btn-group">\ diff --git a/js/menus/ScriptMenuView.js b/js/menus/ScriptMenuView.js index 5b755e359d466b5fe210af4284aa35244e6da652..324e4b79f64d8c2f78f4fe46a5d8f9479bf7f480 100644 --- a/js/menus/ScriptMenuView.js +++ b/js/menus/ScriptMenuView.js @@ -19,11 +19,6 @@ ScriptMenuView = Backbone.View.extend({ this.$el.html(this.template()); }, - destroy: function(){ - this.stopListening(); - this.model = null; - }, - template: _.template('\ some kind of scripting functionality?\ ') diff --git a/js/menus/SketchMenuView.js b/js/menus/SketchMenuView.js index ec1171070cf7eb4717eb9ee83de3b426efee0236..1aefd45cdd4982560cc84116d85474c1ca5642b9 100644 --- a/js/menus/SketchMenuView.js +++ b/js/menus/SketchMenuView.js @@ -34,12 +34,6 @@ SketchMenuView = Backbone.View.extend({ }); }, - destroy: function(){ - this.stopListening(); - this.model = null; - this.appState = null; - }, - template: _.template('\ Sketch Plane Height: <input id="zHeightSlider" data-slider-id="ex1Slider" type="text" data-slider-min="0" data-slider-max="20" data-slider-step="2" data-slider-value="<%= zIndex %>"/>\ ') diff --git a/js/models/AppState.js b/js/models/AppState.js index e2903c6f0c7b569adc33f782fac47c378fb9160a..8696020251ca5b77082b0a08c874b3d653208ac9 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -62,10 +62,13 @@ AppState = Backbone.Model.extend({ this.listenTo(this, "change:currentTab", this._updateCellMode); this.listenTo(this, "change:cellMode", this._cellModeDidChange); - this.listenTo(this, "change:cellType change:connectionType", this._buildNewLattice); + this.listenTo(this, "change:cellType change:connectionType", this._updateLatticetype); - this._buildNewLattice(); + this.set("lattice", new Lattice({appState:this})); + this.get("lattice").updateLatticeType(this.get("cellType"), this.get("connectionType")); this.get("lattice").addCellAtIndex({x:0,y:0,z:0}); + + this.set("menuWrapper", new MenuWrapper({model: this, lattice:this.get("lattice")})); }, @@ -106,31 +109,10 @@ AppState = Backbone.Model.extend({ this.get("lattice").cellModeDidChange(this.get("cellMode")); }, - _buildNewLattice: function(){ - var currentLattice = this.get("lattice"); - if (currentLattice) { - currentLattice.destroy(); - } + _updateLatticetype: function(){ var type = this.get("cellType"); var connectionType = this.get("connectionType"); - if (type == "octa"){ - if (connectionType == "face"){ - this.set("lattice", new OctaFaceLattice({appState:this})); - } else if (connectionType == "edge"){ - this.set("lattice", new OctaEdgeLattice({appState:this})); - } else if (connectionType == "edgeRot"){ - - } else if (connectionType == "vertex"){ - - } - } else if (type == "cube"){ - - } - var currentMenu = this.get("menuWrapper"); - if (currentMenu) { - currentMenu.destroy(); - } - this.set("menuWrapper", new MenuWrapper({lattice:this.get("lattice"), model:this})); + this.get("lattice").updateLatticeType(type, connectionType); }, /////////////////////////////////////////////////////////////////////////////// diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 7d50d1a82cf9c708c00d3ad30580e646adeb0ba3..950290f211c3079b05ae0ba2b8e79de1266a18df 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -24,7 +24,6 @@ Lattice = Backbone.Model.extend({ this.listenTo(this, "change:scale", this._scaleDidChange); this.appState = options.appState; - this._initialize();//call subclass init }, //////////////////////////////////////////////////////////////////////////////////// @@ -90,7 +89,7 @@ Lattice = Backbone.Model.extend({ this.set("cellsMin", {x:0, y:0, z:0}); this.set("nodes", []); this.set("numCells", 0); - this.get("basePlane").set("zIndex", 0); + if (this.get("basePlane")) this.get("basePlane").set("zIndex", 0); window.three.render(); }, @@ -273,6 +272,29 @@ Lattice = Backbone.Model.extend({ this.get("basePlane").updateScale(scale); }, + //////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////CONNECTION TYPE////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////// + + updateLatticeType: function(cellType, connectionType){ + this.clearCells(); + if (this._undo) this._undo(); + if (cellType == "octa"){ + if (connectionType == "face"){ + _.extend(this, this.OctaFaceLattice); + } else if (connectionType == "edge"){ + _.extend(this, this.OctaEdgeLattice); + } else if (connectionType == "edgeRot"){ + + } else if (connectionType == "vertex"){ + + } + } else if (cellType == "cube"){ + + } + this._initLatticeType(); + }, + //////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////UTILS/////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// @@ -292,130 +314,134 @@ Lattice = Backbone.Model.extend({ return this.get("scale"); }, - destroy: function(){ - this.stopListening(); - this.set("scale", null, {silent:true}); - this.set("nodes", null, {silent:true}); - this.clearCells(); -// this._iterCells(this.get("cells"), function(cell){ -// if (cell) cell.destroy(); -// }); - this.set("cells", null, {silent:true}); - this.set("inverseCells", null, {silent:true}); - this.set("cellsMin", null, {silent:true}); - this.set("cellsMax", null, {silent:true}); - this.set("numCells", null, {silent:true}); - this.get("basePlane").destroy(); - this.set("basePlane", null, {silent:true}); - } - -}); - - //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////FACE CONN OCTA LATTICE//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// -OctaFaceLattice = Lattice.extend({ - - _initialize: function(){ + OctaFaceLattice: { - //bind events - this.listenTo(this, "change:columnSeparation", this._changeColSeparation); + _initLatticeType: function(){ - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); - this.set("columnSeparation", 0.0); - }, - - _changeColSeparation: function(){ - var colSep = this.get("columnSeparation"); - var scale = this.get("scale"); - this.get("basePlane").updateColSeparation(colSep); - this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.updateForScale(scale); - }); - window.three.render(); - }, + //bind events + this.listenTo(this, "change:columnSeparation", this._changeColSeparation); - addCellAtPosition: function(absPosition){ + this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); + this.set("columnSeparation", 0.0); + }, - //calc indices in cell matrix - var scale = this.get("scale"); - var colSep = this.get("columnSeparation"); - var latticeScale = scale*(1+2*colSep); - var octHeight = 2*scale/Math.sqrt(6); - var triHeight = latticeScale/2*Math.sqrt(3); - var position = {}; - position.x = Math.round(absPosition.x/latticeScale); - position.y = Math.round(absPosition.y/triHeight); - position.z = Math.round(absPosition.z/octHeight); - if (position.z%2 == 1) position.y += 1; - - this.addCellAtIndex(position); - }, + _changeColSeparation: function(){ + var colSep = this.get("columnSeparation"); + var scale = this.get("scale"); + this.get("basePlane").updateColSeparation(colSep); + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.updateForScale(scale); + }); + window.three.render(); + }, + + addCellAtPosition: function(absPosition){ + + //calc indices in cell matrix + var scale = this.get("scale"); + var colSep = this.get("columnSeparation"); + var latticeScale = scale*(1+2*colSep); + var octHeight = 2*scale/Math.sqrt(6); + var triHeight = latticeScale/2*Math.sqrt(3); + var position = {}; + position.x = Math.round(absPosition.x/latticeScale); + position.y = Math.round(absPosition.y/triHeight); + position.z = Math.round(absPosition.z/octHeight); + if (position.z%2 == 1) position.y += 1; + + this.addCellAtIndex(position); + }, + + getScale: function(){ + return this.get("scale")*(1.0+2*this.get("columnSeparation")); + }, + + _makeCellForLatticeType: function(indices, scale){ + return new DMASideOctaCell(this.appState.get("cellMode"), indices, scale, this); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + this._initLatticeType = null; + this._changeColSeparation = null; + this.addCellAtPosition = null; + this.getScale = null; + this._makeCellForLatticeType = null; + this.stopListening(this, "columnSeparation"); + this.set("columnSeparation", null); + this._undo = null; + } - getScale: function(){ - return this.get("scale")*(1.0+2*this.get("columnSeparation")); }, - _makeCellForLatticeType: function(indices, scale){ - return new DMASideOctaCell(this.appState.get("cellMode"), indices, scale, this); - } - -}); - //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////EDGE CONN OCTA LATTICE//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// -OctaEdgeLattice = Lattice.extend({ + OctaEdgeLattice: { - _initialize: function(){ + _initLatticeType: function(){ - //bind events - this.listenTo(this, "change:columnSeparation", this._changeColSeparation); + //bind events + this.listenTo(this, "change:columnSeparation", this._changeColSeparation); - this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); - this.set("columnSeparation", 0.0); - }, - - _changeColSeparation: function(){ - var colSep = this.get("columnSeparation"); - var scale = this.get("scale"); - this.get("basePlane").updateColSeparation(colSep); - this._iterCells(this.get("cells"), function(cell){ - if (cell) cell.updateForScale(scale); - }); - window.three.render(); - }, + this.set("basePlane", new OctaBasePlane({scale:this.get("scale")})); + this.set("columnSeparation", 0.0); + }, - addCellAtPosition: function(absPosition){ - - //calc indices in cell matrix - var scale = this.get("scale"); - var colSep = this.get("columnSeparation"); - var latticeScale = scale*(1+2*colSep); - var octHeight = 2*scale/Math.sqrt(6); - var triHeight = latticeScale/2*Math.sqrt(3); - var position = {}; - position.x = Math.round(absPosition.x/latticeScale); - position.y = Math.round(absPosition.y/triHeight); - position.z = Math.round(absPosition.z/octHeight); - if (position.z%2 == 1) position.y += 1; - - this.addCellAtIndex(position); - }, - - getScale: function(){ - return this.get("scale")*(1.0+2*this.get("columnSeparation")); - }, + _changeColSeparation: function(){ + var colSep = this.get("columnSeparation"); + var scale = this.get("scale"); + this.get("basePlane").updateColSeparation(colSep); + this._iterCells(this.get("cells"), function(cell){ + if (cell) cell.updateForScale(scale); + }); + window.three.render(); + }, + + addCellAtPosition: function(absPosition){ + + //calc indices in cell matrix + var scale = this.get("scale"); + var colSep = this.get("columnSeparation"); + var latticeScale = scale*(1+2*colSep); + var octHeight = 2*scale/Math.sqrt(6); + var triHeight = latticeScale/2*Math.sqrt(3); + var position = {}; + position.x = Math.round(absPosition.x/latticeScale); + position.y = Math.round(absPosition.y/triHeight); + position.z = Math.round(absPosition.z/octHeight); + if (position.z%2 == 1) position.y += 1; + + this.addCellAtIndex(position); + }, + + getScale: function(){ + return this.get("scale")*(1.0+2*this.get("columnSeparation")); + }, + + _makeCellForLatticeType: function(indices, scale){ + return new DMASideOctaCell(this.appState.get("cellMode"), indices, scale, this); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + this._initLatticeType = null; + this._changeColSeparation = null; + this.addCellAtPosition = null; + this.getScale = null; + this._makeCellForLatticeType = null; + this.stopListening(this, "columnSeparation"); + this.set("columnSeparation", null); + this._undo = null; + } - _makeCellForLatticeType: function(indices, scale){ - return new DMASideOctaCell(this.appState.get("cellMode"), indices, scale, this); } -}); + //////////////////////////////////////////////////////////////////////////////////////// @@ -427,4 +453,8 @@ OctaEdgeLattice = Lattice.extend({ //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////CUBE LATTICE////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +//////////////////////////////////////////////////////////////////////////////////////// + + + +}); \ No newline at end of file