From f06c8c79ed42cf8843355a0f9ef62672a9b4dee0 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Tue, 2 Jun 2015 09:06:56 -0700 Subject: [PATCH] init with alternative color --- js/cells/supercells/DMASuperCell.js | 4 +-- js/cells/supercells/GIKSuperCell.js | 38 +++++++---------------------- js/lattice/Lattice.js | 2 ++ js/models/AppState.js | 2 +- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 977b0ffe..1b9d13f5 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -8,7 +8,7 @@ DMASuperCell = function(index, superCell){//supercells might have supercells this.material = globals.lattice.get("materialType");//todo move to dmacell DMACell.call(this, index, superCell); var range = globals.lattice.get("superCellRange"); - this.cells = this._makeChildCells(index, range);//three dimensional array + this.cells = this._makeChildCells(index, range);//todo three dimensional array? var self = this; _.each(this.cells, function(cell){ @@ -20,7 +20,7 @@ DMASuperCell = function(index, superCell){//supercells might have supercells DMASuperCell.prototype = Object.create(DMACell.prototype); DMASuperCell.prototype._makeChildCells = function(index, range){ - var cells = [];//todo make cells a 3d array? + var cells = []; for (var x=0;x<range.x;x++){ for (var y=0;y<range.y;y++){ for (var z=0;z<range.z;z++){ diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 12e975ca..2510d3e4 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -4,20 +4,11 @@ var allGIKMaterials = {}; var gikMaterialList = AppPList().allMaterialTypes.cube.gik; -_.each(_.keys(gikMaterialList), function(material){ - allGIKMaterials[material] = new THREE.MeshLambertMaterial({color:gikMaterialList[material].color}); - if (gikMaterialList[material].opacity){ - allGIKMaterials[material].transparent = true; - allGIKMaterials[material].opacity = gikMaterialList[material].opacity; - } else { - allGIKMaterials[material].transparent = false; - } -}); - function changeGikMaterials(){ - _.each(_.keys(allGIKMaterials), function(material){ + _.each(_.keys(gikMaterialList), function(material){ if (globals.appState.get("realisticColorScheme")) { - allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].color); + if (allGIKMaterials[material]) allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].color); + else allGIKMaterials[material] = new THREE.MeshLambertMaterial({color:gikMaterialList[material].color}); if (gikMaterialList[material].opacity){ allGIKMaterials[material].transparent = true; allGIKMaterials[material].opacity = gikMaterialList[material].opacity; @@ -26,7 +17,8 @@ function changeGikMaterials(){ } } else { - allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].altColor); + if (allGIKMaterials[material]) allGIKMaterials[material].color = new THREE.Color(gikMaterialList[material].altColor); + else allGIKMaterials[material] = new THREE.MeshLambertMaterial({color:gikMaterialList[material].altColor}); allGIKMaterials[material].transparent = false; } }); @@ -46,6 +38,10 @@ GIKSuperCell.prototype._rotateCell = function(object3D){ return object3D; }; +GIKSuperCell.prototype.getMaterial = function(){ + return allGIKMaterials[this.material]; +}; + GIKSuperCell.prototype._buildMesh = function(){ var length = globals.lattice.get("superCellRange").x; var meshes = []; @@ -68,20 +64,4 @@ GIKSuperCell.prototype._buildWireframe = function(mesh){ wireframe.matrixWorld = mesh.matrixWorld; wireframe.matrixAutoUpdate = true; return wireframe; -}; - -GIKSuperCell.prototype.getMaterial = function(){ - return allGIKMaterials[this.material]; -}; - -GIKSuperCell.prototype.destroy = function(){ - this.object3D.myParent = null; - globals.three.sceneRemove(this.object3D, this._getSceneName()); - this.object3D = null; - _.each(this.cells, function(cell){ - if (cell) cell.destroy(); - }); - this.cells = null; - this.index = null; - this.material = null; }; \ No newline at end of file diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 8882bfde..0b4f5828 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -41,6 +41,8 @@ Lattice = Backbone.Model.extend({ this.listenTo(globals.appState, "change:cellMode", this._updateForMode); this.listenTo(globals.appState, "change:cellsVisible", this._setCellVisibility); + + changeGikMaterials(); }, delayedInit: function(){ diff --git a/js/models/AppState.js b/js/models/AppState.js index 10dbaf11..ba5855e3 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -36,7 +36,7 @@ AppState = Backbone.Model.extend({ superCellIndex: 0,//offset of superCell adds todo lattice? - realisticColorScheme: true, + realisticColorScheme: false, stockSimulationPlaying: false, manualSelectOrigin: false//mode that allows user ot select origin from existing cell -- GitLab