From 558f17437129ce7e8a25f3bdbd5ff3744d1872aa Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 27 May 2015 17:51:33 -0700 Subject: [PATCH] alternate colors working --- index.html | 3 ++- js/cells/supercells/GIKSuperCell.js | 16 ++++++++++++++-- js/menus/PartMenuView.js | 2 +- js/models/AllAppPLists.js | 2 +- js/models/AppState.js | 6 ++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index ac6c6f47..8f483e02 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,8 @@ <!--numerical javascript--> <script src="dependencies/numeric-1.2.6.js"></script> + <script src="js/models/AllAppPLists.js"></script> + <!--multi-threading--> <script src="js/multiThreading/worker.js"></script> <script src="js/multiThreading/persistentWorkers.js"></script><!--global workers--> @@ -82,7 +84,6 @@ <script src="js/models/FillGeometry.js"></script> <script src="js/models/BasePlane.js"></script> <script src="js/models/extrudeVisualizer.js"></script> - <script src="js/models/AllAppPLists.js"></script> <script src="js/models/AppState.js"></script> <script src="js/cam/Machine.js"></script> <script src="js/cam/MachineOneBit.js"></script> diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index c6f34311..3e90ad33 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -2,6 +2,19 @@ * Created by aghassaei on 5/26/15. */ +var allGIKMaterials = {}; +var gikMaterialList = AppPList().allMaterialTypes.cube.gik; +_.each(_.keys(gikMaterialList), function(material){ + allGIKMaterials[material] = new THREE.MeshLambertMaterial({color:gikMaterialList[material].color}); +}); + +function changeGikMaterials(){ + _.each(_.keys(allGIKMaterials), function(material){ + if (globals.appState.get("realisticColorScheme")) allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].color); + else allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].altColor); + }); +} + GIKSuperCell = function(length, range, cells){ if (range) this.indices = _.clone(range.max); @@ -57,8 +70,7 @@ GIKSuperCell.prototype._buildWireframe = function(mesh){ }; GIKSuperCell.prototype.getMaterial = function(){ - var material = globals.plist.allMaterialTypes[globals.lattice.get("cellType")][globals.lattice.get("connectionType")][globals.lattice.get("materialType")]; - return new THREE.MeshLambertMaterial({color:material.color}); + return allGIKMaterials[globals.lattice.get("materialType")]; }; GIKSuperCell.prototype.setMode = function(mode){ diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js index 03050fe0..991c2150 100644 --- a/js/menus/PartMenuView.js +++ b/js/menus/PartMenuView.js @@ -45,7 +45,7 @@ PartMenuView = Backbone.View.extend({ <label class="radio colorSwatches">\ <input type="radio" <%if (key == materialType){ %>checked<%}%> name="materialType" value="<%= key %>" data-toggle="radio" class="custom-radio lattice"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ <div class="materialColorSwatch">\ - <div style="background-color:<%= allMaterialTypes[cellType][connectionType][key].color %>"></div>\ + <div style="background-color:<% if(realisticColorScheme){ %><%= allMaterialTypes[cellType][connectionType][key].color %><% }else{ %><%= allMaterialTypes[cellType][connectionType][key].altColor %><% } %>"></div>\ <span><%= allMaterialTypes[cellType][connectionType][key].name %></span></div>\ </label>\ <% }); %>\ diff --git a/js/models/AllAppPLists.js b/js/models/AllAppPLists.js index c4f7e6da..ad0c995b 100644 --- a/js/models/AllAppPLists.js +++ b/js/models/AllAppPLists.js @@ -107,7 +107,7 @@ function AppPList(){ silicon: { name: "Silicon", color: "#bcc6cc", - altColor: "#34495e" + altColor: "#3498db" } } }, diff --git a/js/models/AppState.js b/js/models/AppState.js index c70fe3e0..7ca3e812 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -46,6 +46,7 @@ AppState = Backbone.Model.extend({ this.listenTo(this, "change:currentTab", this._tabChanged); this.listenTo(this, "change:currentNav", this._navChanged); + this.listenTo(this, "change:realisticColorScheme", this._updateColorScheme); this.downKeys = {};//track keypresses to prevent repeat keystrokeson hold @@ -95,6 +96,11 @@ AppState = Backbone.Model.extend({ this.get("lastAssembleTab")); }, + _updateColorScheme: function(){ + changeGikMaterials(); + globals.three.render(); + }, + /////////////////////////////////////////////////////////////////////////////// /////////////////////KEY BINDINGS////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -- GitLab