From 78cc6046fb72829ef61c903675f1f33d7357a374 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 12 Jun 2015 15:28:23 -0700 Subject: [PATCH] merging composite cells in --- js/cells/supercells/CompositeCell.js | 6 +++--- js/cells/supercells/DMASuperCell.js | 22 +++++++++++++++++----- js/lattice/Lattice.js | 20 +++++++++++++++++++- js/parts/DMAPart.js | 2 +- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js index 7292d349..cf4c34d7 100644 --- a/js/cells/supercells/CompositeCell.js +++ b/js/cells/supercells/CompositeCell.js @@ -12,9 +12,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', CompositeCell.prototype = Object.create(DMASuperCell.prototype); CompositeCell.prototype._makeSubCellForIndex = function(json, callback){ - require([], function(){ - - }); +// require([], function(){ +// +// }); }; CompositeCell.prototype._getGeometry = function(){ diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index fcbc3d45..ccd1b5c9 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -29,12 +29,24 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], cells[x].push([]); for (var z=0;z<range.z;z++){ //child cells add themselves to object3D - var material = this.material; - if (material.cells && material.cells[x][y][z]) material = material.cells[x][y][z].material; + + var cellMaterial = this.material; cells[x][y].push(null); - this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z)}, function(cell){ - cells[x][y][z] = cell; - }); + + if (material.sparseCells){ + if (material.sparseCells[x][y][z]){ + if (material.sparseCells[x][y][z].material) { + cellMaterial = material.sparseCells[x][y][z].material; + this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), material:cellMaterial}, function(cell){ + cells[x][y][z] = cell; + }); + } else console.warn("no material for composite cell definition subcell"); + }//else no cell in this spot + } else {//if not from composite definition, add subcell at all possible indices in supercell range + this._makeSubCellForIndex({index: new THREE.Vector3(x,y,z), material:cellMaterial}, function(cell){ + cells[x][y][z] = cell; + }); + } } } } diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 08dcadd9..279d0cdf 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -108,9 +108,27 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //events +// _materialTypeChanged: function(){ +// var materialType = this.get("materialType"); +// //verify that correct class is in sync +// if (materialType.substr(0,5) == "super"){ +// this.set("materialClass", "compositeMaterials"); +// return; +// } else { +// var materialClass = null; +// _.each(_.keys(plist.allMaterials), function(key){ +// if (_.keys(plist.allMaterials[key]).indexOf(materialType) > -1) materialClass = key; +// }); +// } +// console.log(materialClass); +// if (!materialClass) console.warn("material class not found for material " + materialType); +// else this.set("materialClass", materialClass); +// }, + _loadMaterialClass: function(){ var materialClass = this.get("materialClass"); - this.set("materialType", _.keys(plist.allMaterials[materialClass])[0], {silent:true});//set to default silently + var materialType = this.get("materialType"); + if (!plist.allMaterials[materialClass].materialType) this.set("materialType", _.keys(plist.allMaterials[materialClass])[0], {silent:true});//set to default silently if (globals.materials[materialClass]) return;//already loaded require([materialClass + "Materials"], function(MaterialClass){ globals.materials[materialClass] = MaterialClass; diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index 7acd756b..9a46ede3 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -36,7 +36,7 @@ define(['underscore', 'three'], function(_, THREE){ }; DMAPart.prototype.destroy = function(){ - if (this.mesh) {d + if (this.mesh) { this.parentCell.removeChildren(this.mesh); this.mesh = null; } -- GitLab