From f9850a2975baf6032c1af75888fd88a7938390e3 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 16 Jun 2015 09:26:19 -0700 Subject: [PATCH] offsets ui --- js/lattice/Lattice.js | 1 + js/lattice/LatticeBase.js | 1 - js/menus/MaterialMenuView.js | 5 ++++ js/menus/MenuWrapperView.js | 3 ++- js/models/AppState.js | 46 +++++++++++++++++++++++------------- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 7380a156..c4cff5e7 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -123,6 +123,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre return; } + //composite material appState.set("superCellRange", globals.materials.compositeMaterials[materialType].dimensions.clone()); appState.set("superCellIndex", new THREE.Vector3(0,0,0)); require(['superCellHighlighter'], function(SuperCellHighlighter){ diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index ae3f3395..35013e58 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -200,7 +200,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (material.dimensions){ var subCellMax = (new THREE.Vector3(x, y, z)).add(material.dimensions); dimVector.max(subCellMax); - console.log(dimVector); } } }); diff --git a/js/menus/MaterialMenuView.js b/js/menus/MaterialMenuView.js index 936da934..092fb0ac 100644 --- a/js/menus/MaterialMenuView.js +++ b/js/menus/MaterialMenuView.js @@ -79,6 +79,11 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals'], fu <span><%= materials.compositeMaterials[key].name %><a data-id="<%= key %>" class="editComposite">Settings...<a/></span></div>\ </label>\ <% }); %><br/>\ + <% if (_.keys(materials.compositeMaterials).length > 0) { %>\ + Offset (xyz): <input data-property="superCellIndex" data-key="x" value="<%= superCellIndex.x %>" placeholder="X" class="form-control intInput appState" type="text">\ + <input data-property="superCellIndex" data-key="y" value="<%= superCellIndex.y %>" placeholder="Y" class="form-control intInput appState" type="text">\ + <input data-property="superCellIndex" data-key="z" value="<%= superCellIndex.z %>" placeholder="Z" class="form-control intInput appState" type="text"><br/><br/>\ + <% } %>\ <a id="navToCompositeMenu" href="#" class="btn btn-block btn-lg btn-default">+ Create New Composite Material</a><br/>\ <a id="compositeFromLattice" href="#" class="btn btn-block btn-lg btn-default">New Composite From Current Assembly</a><br/>\ <% } %>\ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 08f3a2d7..6d3b270d 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -121,9 +121,10 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice'], function($, _, newVal = parseFloat(newVal); if (key){ - var value = _.clone(this._getPropertyOwner($target).get(property)); + var value = this._getPropertyOwner($target).get(property).clone(); value[key] = newVal; this._getPropertyOwner($target).set(property, value); + return; } this._getPropertyOwner($target).set(property, newVal); }, diff --git a/js/models/AppState.js b/js/models/AppState.js index a6059661..126278b7 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -34,7 +34,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist'], function(_, B cellsVisible: true, superCellIndex: new THREE.Vector3(0,0,0),//offset of superCell adds - superCellRange: new THREE.Vector3(4,1,1), + superCellRange: new THREE.Vector3(1,1,1), realisticColorScheme: false, @@ -135,7 +135,7 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist'], function(_, B } else this.downKeys[e.keyCode] = false; // console.log(e); - // console.log(e.keyCode); +// console.log(e.keyCode); switch(e.keyCode){ case 8://delete key - causes back nav in chrome, super annoying e.preventDefault(); @@ -165,6 +165,8 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist'], function(_, B } else { globals.fileSaver.save(); } + } else { + if (state) this.set("superCellIndex", this._incrementSuperCellIndex("y", this.get("superCellIndex").clone())); } break; case 79://o open @@ -192,29 +194,39 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist'], function(_, B this.set("superCellRange", range); } break; - case 81://q - increase supercell index - if (this.lattice.get("connectionType") != "gik") break; - if (state) { - var index = this.get("superCellIndex").clone(); - index.x += 1; - if (index.x > this.get("superCellRange").x-1) index.x = 0; - this.set("superCellIndex", index); - } + case 87://w - increase supercell index + console.log(this.get("superCellIndex")); + if (state) this.set("superCellIndex", this._incrementSuperCellIndex("x", this.get("superCellIndex").clone())); + break; + case 81://q - decrease supercell index + if (state) this.set("superCellIndex", this._decrementSuperCellIndex("x", this.get("superCellIndex").clone())); break; case 65://a - decrease supercell index - if (this.lattice.get("connectionType") != "gik") break; - if (state) { - var index = this.get("superCellIndex").clone(); - index.x -= 1; - if (index.x < 0) index.x = this.get("superCellRange").x-1; - this.set("superCellIndex", index); - } + if (state) this.set("superCellIndex", this._decrementSuperCellIndex("y", this.get("superCellIndex").clone())); + break; + case 88://x - increase supercell index + if (state) this.set("superCellIndex", this._incrementSuperCellIndex("z", this.get("superCellIndex").clone())); + break; + case 90://z - decrease supercell index + if (state) this.set("superCellIndex", this._decrementSuperCellIndex("z", this.get("superCellIndex").clone())); break; default: break; } }, + _incrementSuperCellIndex: function(key, object){ + object[key] += 1; + if (object[key] > this.get("superCellRange")[key]-1) object[key] = 0; + return object; + }, + + _decrementSuperCellIndex: function(key, object){ + object[key] -= 1; + if (object[key] < 0) object[key] = this.get("superCellRange")[key]-1; + return object; + }, + _handleScroll: function(e){//disable two finger swipe back if (Math.abs(e.originalEvent.deltaX) > Math.abs(e.originalEvent.deltaY)) e.preventDefault(); } -- GitLab