From f638319c2c619a10e218e19cfcb8c1572019c741 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 19 Jun 2015 16:56:49 -0700 Subject: [PATCH] working out some gik materials stuff --- js/cells/DMACell.js | 25 +++++++++++++------------ js/cells/supercells/CompositeCell.js | 2 +- js/cells/supercells/DMASuperCell.js | 7 +++++-- js/cells/supercells/GIKSuperCell.js | 23 ++++++++++------------- js/lattice/LatticeBase.js | 4 ++-- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 612f6e4b..2f0d6f2a 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -13,7 +13,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' if (json.index) this.index = new THREE.Vector3(json.index.x, json.index.y, json.index.z); if (superCell) this.superCell = superCell; - this.material = json.material || appState.get("materialType"); + this.materialName = json.materialName || appState.get("materialType"); //object 3d is parent to all 3d elements owned by cell: cell mesh and wireframe, parts, beams, nodes, etc this.object3D = this._buildObject3D(); @@ -155,7 +155,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.setDeleteMode = function(state){ var material; - if (state) material = materials.deleteMaterial; + if (!state && !this.materialName) return;//cell may be deleted by now + if (state) material = materials.deleteMaterial.threeMaterial; else material = this.getMaterial(true); if (!material) return;//cell may be deleted by now if (this.object3D.children[0].material == material) return; @@ -222,20 +223,20 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' }; DMACell.prototype.getMaterial = function(returnTHREEObject){ - if (!this.material) { + if (!this.materialName) { console.warn("no material type set for cell"); return null; } - if (!returnTHREEObject) return materials[this.material]; - if (!materials[this.material]) { - console.warn("no material object found of type " + this.materials); + if (!returnTHREEObject) return materials[this.materialName]; + if (!materials[this.materialName]) { + console.warn("no material object found of type " + this.materialNames); return null; } - if (!materials[this.material].threeMaterial){ - console.warn("no three material object found for type "+ this.material); + if (!materials[this.materialName].threeMaterial){ + console.warn("no three material object found for type "+ this.materialName); return null; } - return materials[this.material].threeMaterial; + return materials[this.materialName].threeMaterial; }; DMACell.prototype.setOpacity = function(opacity){ @@ -358,7 +359,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' this.nodes = null; this.beams = null; this.superCell = null; - this.material = null; + this.materialName = null; this.index = null; }; @@ -372,9 +373,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals', ' DMACell.prototype.toJSON = function(){ var data = { - material: this.material + material: this.materialName }; - if (materials[this.material].cells) return data;//material definition in material composites + if (materials[this.materialName].cells) return data;//material definition in material composites if (this.cells) data.cells = this.cells; return data; }; diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js index 867326d5..49a0021a 100644 --- a/js/cells/supercells/CompositeCell.js +++ b/js/cells/supercells/CompositeCell.js @@ -12,7 +12,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', CompositeCell.prototype = Object.create(DMASuperCell.prototype); CompositeCell.prototype._getGeometry = function(){ - var dimensions = materials[this.material].dimensions; + var dimensions = materials[this.materialName].dimensions; var geo = new THREE.BoxGeometry(dimensions.x*lattice.xScale(), dimensions.y*lattice.yScale(), dimensions.z*lattice.zScale()); geo.applyMatrix(new THREE.Matrix4().makeTranslation(dimensions.x/2-0.5, dimensions.y/2-0.5, dimensions.z/2-0.5)); return geo; diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index c75708fa..1dfaade0 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -15,6 +15,8 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var material = this.getMaterial(); var range = appState.get("superCellRange"); + console.log(material); + if (material.dimensions) range = material.dimensions; if (material.cellsMax) range = (new THREE.Vector3(1,1,1)).add(material.cellsMax).sub(material.cellsMin); this.cells = this._makeChildCells(range, material); @@ -25,6 +27,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], DMASuperCell.prototype = Object.create(DMACell.prototype); DMASuperCell.prototype._makeChildCells = function(range, material){ + console.log(range); var cells = []; for (var x=0;x<range.x;x++){ cells.push([]); @@ -33,7 +36,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], for (var z=0;z<range.z;z++){ //child cells add themselves to object3D - var cellMaterial = this.material; + var cellMaterial = this.materialName; cells[x][y].push(null); if (material.sparseCells){ @@ -59,7 +62,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], DMASuperCell.prototype._makeSubCellForIndex = function(json, callback){ var subclassFile = lattice.getCellSubclassFile(); - if (json.material && json.material.substr(0,5) == "super") subclassFile = "compositeCell"; + if (json.materialName && json.materialName.substr(0,5) == "super") subclassFile = "compositeCell"; var self = this; require([subclassFile], function(CellSubclass){ var cell = new CellSubclass(json, self); diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index f80081c4..dd6d54f4 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -4,11 +4,11 @@ -define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', 'gikCell'], - function(_, THREE, three, lattice, appState, DMASuperCell, GIKCell){ +define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', 'gikCell', 'materials'], + function(_, THREE, three, lattice, appState, DMASuperCell, GIKCell, materials){ var unitGeos = {}; - var materials = {}; + var gikMaterials = {}; function makePartWithLength(length){ var geo = new THREE.BoxGeometry(lattice.xScale(0),lattice.yScale(0),lattice.zScale(0)); @@ -43,19 +43,16 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', if (returnTHREEObject){ return DMASuperCell.prototype.getMaterial.call(this, returnTHREEObject); } - if (!materials[this.material]) materials[this.material] = {}; var length = this.getLength(); - if (!materials[this.material]["length" + (length+1)]) { - materials[this.material]["length" + (length+1)] = - { - material: this.material, - cellsMin: new THREE.Vector3(0,0,0), - cellsMax: new THREE.Vector3(length, 0, 0), - dimensions: new THREE.Vector3(length+1, 1, 1) + var name = this.materialName + "length" + (length+1); + if (!gikMaterials[name]) { + gikMaterials[name] = { + materialName: this.materialName, + dimensions: new THREE.Vector3(length+1, 1, 1), + threeMaterial: materials[this.materialName].threeMaterial }; } - console.log(materials[this.material]); - return materials[this.material]["length" + (length+1)]; + return gikMaterials[name]; }; GIKSuperCell.prototype._buildWireframe = function(mesh){ diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 8f695957..f4d40a86 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -93,7 +93,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre makeCellForLatticeType: function(json, callback){ var subclassFile = this.getCellSubclassFile(); - if (json.material && json.material.substr(0,5) == "super") subclassFile = "compositeCell"; + if (json.materialName && json.materialName.substr(0,5) == "super") subclassFile = "compositeCell"; require([subclassFile], function(CellSubclass){ var cell = new CellSubclass(json); if (callback) callback(cell); @@ -131,7 +131,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (!this.sparseCells[relIndex.x][relIndex.y][relIndex.z]) { var self = this; if (!noRender || noRender === undefined) three.setRenderFlag(); - this.makeCellForLatticeType({index:index, material:material}, function(cell){ + this.makeCellForLatticeType({index:index, materialName:material}, function(cell){ self.sparseCells[relIndex.x][relIndex.y][relIndex.z] = cell; self.set("numCells", self.get("numCells")+1); }); -- GitLab