diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js index cda3dc621f226a11cdd4975981c6bb6df1c377cf..9a17f9239487b3c7fd2aa67af998a6335d8e6235 100644 --- a/js/cells/CubeCell.js +++ b/js/cells/CubeCell.js @@ -7,8 +7,8 @@ var unitCellGeo = new THREE.BoxGeometry(1,1,1); - function CubeCell(indices){ - DMACell.call(this, indices); + function CubeCell(index, superCell){ + DMACell.call(this, index, superCell); } CubeCell.prototype = Object.create(DMACell.prototype); @@ -32,7 +32,7 @@ _.each(_.keys(position), function(key){ position[key] += direction[key]*scale/2; }); - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; self.CubeCell = CubeCell; diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index 9ef16d08f55da508aba2da190f2a24ec4602d742..1701f53889aab637a843c14286bc172a1adf073e 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -6,16 +6,18 @@ var cellMaterial = new THREE.MeshNormalMaterial(); var wireframeMaterial = new THREE.MeshBasicMaterial({color:0x000000, wireframe:true}); -function DMACell(indices){ +function DMACell(index, superCell){ - this.indices = indices; + this.index = index; + if (superCell) this.superCell = superCell; //object 3d is parent to all 3d elements related to cell, parts, beams, nodes, etc this.object3D = this._buildObject3D(); this._addChildren(this._buildMesh(), this.object3D);//build cell meshes - if (!this.superCell){ - if (this.indices) globals.three.sceneAdd(this.object3D, "cell"); - else this.hide(); + + if (superCell === undefined) { + if (this.index) globals.three.sceneAdd(this.object3D, "cell"); + else this.hide();//stock cell } this.setMode(); @@ -28,7 +30,7 @@ DMACell.prototype._buildObject3D = function(){ return object3D; }; -DMACell.prototype.getObject3D = function(){//careful, used for stock sim only for now +DMACell.prototype.getObject3D = function(){//careful, used for stock sim and supercell only for now todo need this? return this.object3D; }; @@ -43,8 +45,8 @@ DMACell.prototype._rotateCell = function(object3D){ }; DMACell.prototype._translateCell = function(object3D){ - if (!this.indices) return object3D; - var position = globals.lattice.getPositionForIndex(this.indices); + if (!this.index) return object3D; + var position = globals.lattice.getPositionForIndex(this.index); object3D.position.set(position.x, position.y, position.z); return object3D; }; @@ -110,21 +112,9 @@ DMACell.prototype._initParts = function(){ return [];//override in subclasses }; -DMACell.prototype.setSuperCell = function(superCell, index){//todo get rid of this - this.superCell = superCell; - this.superCellIndex = index; - - if (this.superCellIndex == this.superCell.getLength()) this.mesh.rotateZ(Math.PI); - if (globals.appState.get("cellMode")=="part") { - this.parts = this._initParts(); - this.draw(); - } -}; - DMACell.prototype.setMode = function(mode){ if (mode === undefined) mode = globals.appState.get("cellMode"); - if (this.superCell) this.superCell.setMode(mode); switch(mode) { case "cell": @@ -152,10 +142,18 @@ DMACell.prototype.setMode = function(mode){ }; DMACell.prototype.getPosition = function(){ - if (this.superCell && this.indices) return globals.lattice.getPositionForIndex(this.indices); + if (this.superCell && this.index) return this.superCell.getSubCellPosition(_.clone(this.index)); return this.object3D.position.clone(); }; +DMACell.prototype.getSubCellPosition = function(subIndex){ + var index = _.clone(this.index); + _.each(_.keys(index), function(key){ + index[key] += subIndex[key]; + }); + return globals.lattice.getIndexForPosition(index); +}; + DMACell.prototype.getQuaternion = function(){ return this.object3D.quaternion.clone(); }; @@ -191,11 +189,9 @@ DMACell.prototype.zScale = function(){ }; DMACell.prototype.destroy = function(){ - if (this.destroyStarted) return; - this.destroyStarted = true; if (this.object3D) { if (this.superCell) this.object3D.parent.remove(this.object3D); - if (this.indices) globals.three.sceneRemove(this.object3D, "cell"); + else if (this.index) globals.three.sceneRemove(this.object3D, "cell"); this.object3D.myParent = null; // this.object3D.dispose(); // geometry.dispose(); @@ -205,12 +201,8 @@ DMACell.prototype.destroy = function(){ this.destroyParts(); this.nodes = null; this.beams = null; - if (this.superCell) { - this.superCell.destroy(); - this.superCell = null; - } - this.superCellIndex = null; - this.indices = null; + this.superCell = null; + this.index = null; }; DMACell.prototype.destroyParts = function(){ @@ -232,7 +224,7 @@ DMACell.prototype.destroyParts = function(){ DMACell.prototype.toJSON = function(){ var data = { - indices:this.indices//todo get rid of this and calculate from min and max + index:this.index//todo get rid of this and calculate from min and max }; if (this.parts) data.parts = this.parts; return data; diff --git a/js/cells/DMACellFreeform.js b/js/cells/DMACellFreeform.js index 0e2b6f3ec9b1031b157ebe0c8863427de16557d8..9b166f5ae8e30f76e9120648346fc152392d5b49 100644 --- a/js/cells/DMACellFreeform.js +++ b/js/cells/DMACellFreeform.js @@ -8,12 +8,12 @@ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAFreeFormCell(indices, parentCellPos, parentCellQuat, direction, parentType){//no rigid lattice structure for cells +function DMAFreeFormCell(index, parentCellPos, parentCellQuat, direction, parentType){//no rigid lattice structure for cells this.parentPos = parentCellPos; this.parentQuaternion = parentCellQuat; this.parentDirection = direction; this.parentType = parentType; - DMACell.call(this, indices); + DMACell.call(this, index); } DMAFreeFormCell.prototype = Object.create(DMACell.prototype); @@ -32,7 +32,7 @@ DMAFreeFormCell.prototype.calcHighlighterPosition = function(face){ direction.applyQuaternion(this.mesh.quaternion); var position = this.getPosition(); position.add(direction.clone().multiplyScalar(this.zScale()/2)); - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; DMAFreeFormCell.prototype.toJSON = function(){ @@ -54,8 +54,8 @@ DMAFreeFormCell.prototype.toJSON = function(){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAFreeFormOctaCell(indices, parentCellPos, parentCellQuat, direction, parentType){ - DMAFreeFormCell.call(this, indices, parentCellPos, parentCellQuat, direction, parentType); +function DMAFreeFormOctaCell(index, parentCellPos, parentCellQuat, direction, parentType){ + DMAFreeFormCell.call(this, index, parentCellPos, parentCellQuat, direction, parentType); } DMAFreeFormOctaCell.prototype = Object.create(DMAFreeFormCell.prototype); @@ -122,8 +122,8 @@ var unitCellGeo2 = new THREE.TetrahedronGeometry(Math.sqrt(3/8)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); -function DMAFreeFormTetraCell(indices, parentCellPos, parentCellQuat, direction, parentType){ - DMAFreeFormCell.call(this, indices, parentCellPos, parentCellQuat, direction, parentType); +function DMAFreeFormTetraCell(index, parentCellPos, parentCellQuat, direction, parentType){ + DMAFreeFormCell.call(this, index, parentCellPos, parentCellQuat, direction, parentType); } DMAFreeFormTetraCell.prototype = Object.create(DMAFreeFormCell.prototype); diff --git a/js/cells/GIKCell.js b/js/cells/GIKCell.js index eb7533d97386e118c957ff43cf1a3764309bd2ce..07443ce36f67d4fe8c16edb1964579effd8a54ee 100644 --- a/js/cells/GIKCell.js +++ b/js/cells/GIKCell.js @@ -7,31 +7,30 @@ var unitCellGeo = new THREE.BoxGeometry(1,1,1.28); - function GIKCell(indices){ - this.indices = indices; + function GIKCell(index, superCell){ + CubeCell.call(this, index, superCell); } GIKCell.prototype = Object.create(CubeCell.prototype); - GIKCell.prototype.setSuperCell = function(superCell, index){ - this.superCell = superCell; - this.superCellIndex = index; - CubeCell.call(this, this.indices); - if (this.superCellIndex == this.superCell.getLength()) this.object3D.rotateZ(Math.PI); - return this.object3D; - }; GIKCell.prototype._getGeometry = function(){ return unitCellGeo; }; GIKCell.prototype._translateCell = function(object3D){ - if (this.superCellIndex != null) { - var offset = this.superCellIndex-this.superCell.getLength(); + if (this.index) { + var offset = this.index-this.superCell.getLength(); object3D.position.set(offset*this.xScale(),0, 0); } return object3D; }; + GIKCell.prototype._rotateCell = function(object3D){ + var length = this.superCell.getLength(); + if (this.index.x == length || this.index.y == length) object3D.rotateZ(Math.PI); + return object3D; + }; + GIKCell.prototype.getMaterial = function(){ return this.superCell.getMaterial(); }; @@ -53,12 +52,12 @@ GIKCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal.clone().applyEuler(this.object3D.rotation).applyEuler(this.object3D.parent.rotation); - var position = globals.lattice.getPositionForIndex(this.indices); + var position = globals.lattice.getPositionForIndex(this.index); var self = this; _.each(_.keys(position), function(key){ position[key] += direction[key]*self.axisScale(key)/2; }); - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; self.GIKCell = GIKCell; diff --git a/js/cells/KelvinCell.js b/js/cells/KelvinCell.js index 4ae5de83435782d6dad483a076805a4325291623..22bdd58d4c209c70835e09af992d5139dae60909 100644 --- a/js/cells/KelvinCell.js +++ b/js/cells/KelvinCell.js @@ -97,8 +97,8 @@ ]; unitCellGeo.computeFaceNormals(); - function KelvinCell(indices, cellMode, partType){ - TruncatedCubeCell.call(this, indices, cellMode, partType); + function KelvinCell(index, superCell){ + TruncatedCubeCell.call(this, index, superCell); } KelvinCell.prototype = Object.create(TruncatedCubeCell.prototype); diff --git a/js/cells/OctaEdgeCell.js b/js/cells/OctaEdgeCell.js index eedc0a86b985edc1a41d6c23fa23c499df6617f8..91a94a7298fa58189ca61b516d1b66d3e89f0a3c 100644 --- a/js/cells/OctaEdgeCell.js +++ b/js/cells/OctaEdgeCell.js @@ -3,8 +3,8 @@ */ -function OctaEdgeCell(indices){ - OctaFaceCell.call(this, indices); +function OctaEdgeCell(index, superCell){ + OctaFaceCell.call(this, index, superCell); } OctaEdgeCell.prototype = Object.create(OctaFaceCell.prototype); @@ -18,5 +18,5 @@ OctaEdgeCell.prototype.calcHighlighterPosition = function(face){ direction.applyQuaternion(this.mesh.quaternion); var position = this.getPosition(); position.add(direction.clone().multiplyScalar(this.zScale()/2)); - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; \ No newline at end of file diff --git a/js/cells/OctaFaceCell.js b/js/cells/OctaFaceCell.js index a183db8af45634950766a15dad873d1976eab6d8..3e822357dc789536d9d6e900576c303ae3000004 100644 --- a/js/cells/OctaFaceCell.js +++ b/js/cells/OctaFaceCell.js @@ -7,8 +7,8 @@ var unitFaceOctaGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3)))); -function OctaFaceCell(mode, indices){ - DMACell.call(this, mode, indices); +function OctaFaceCell(index, superCell){ + DMACell.call(this, index, superCell); } OctaFaceCell.prototype = Object.create(DMACell.prototype); @@ -21,7 +21,7 @@ OctaFaceCell.prototype._initParts = function(){ }; OctaFaceCell.prototype._rotateCell = function(object3D){ - if (this.indices && this.indices.z%2!=0) object3D.rotation.set(0, 0, Math.PI); + if (this.index && this.index.z%2!=0) object3D.rotation.set(0, 0, Math.PI); return object3D; }; @@ -30,9 +30,9 @@ OctaFaceCell.prototype._getGeometry = function(){ }; OctaFaceCell.prototype.calcHighlighterPosition = function(face){ - if (face.normal.z<0.99) return {index: _.clone(this.indices)};//only highlight horizontal faces + if (face.normal.z<0.99) return {index: _.clone(this.index)};//only highlight horizontal faces var direction = face.normal; var position = this.getPosition(); position.z += face.normal.z*this.zScale()/2; - return {index:_.clone(this.indices), direction:direction, position:position}; + return {index:_.clone(this.index), direction:direction, position:position}; }; \ No newline at end of file diff --git a/js/cells/OctaRotEdgeCell.js b/js/cells/OctaRotEdgeCell.js index 6af7524b02d0845383f162a06af8b17f826093d8..8fea993da5eebff82e5538553b6e07ebc64c1425 100644 --- a/js/cells/OctaRotEdgeCell.js +++ b/js/cells/OctaRotEdgeCell.js @@ -5,8 +5,8 @@ var unitVertexOcta = new THREE.OctahedronGeometry(1/Math.sqrt(2)); -function OctaRotEdgeCell(indices){ - DMACell.call(this, indices); +function OctaRotEdgeCell(index, superCell){ + DMACell.call(this, index, superCell); } OctaRotEdgeCell.prototype = Object.create(DMACell.prototype); @@ -52,7 +52,7 @@ OctaRotEdgeCell.prototype.calcHighlighterPosition = function(face, point){ } if (direction.z != 0){ - if (this.indices.z%2 == 0){ + if (this.index.z%2 == 0){ if (point.x < position.x) { direction.x -= 1; position.x -= rad; @@ -87,5 +87,5 @@ OctaRotEdgeCell.prototype.calcHighlighterPosition = function(face, point){ position.y += direction.y*this.yScale()/2; } - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; \ No newline at end of file diff --git a/js/cells/OctaVertexCell.js b/js/cells/OctaVertexCell.js index cbc1431a08987a0177038be11042123ef78bb42f..ad096b920e482d60556b4fa17d2e9de23c0f5412 100644 --- a/js/cells/OctaVertexCell.js +++ b/js/cells/OctaVertexCell.js @@ -3,8 +3,8 @@ */ -function OctaVertexCell(indices){ - DMACell.call(this, indices); +function OctaVertexCell(index, superCell){ + DMACell.call(this, index, superCell); } OctaVertexCell.prototype = Object.create(DMACell.prototype); @@ -47,5 +47,5 @@ OctaVertexCell.prototype.calcHighlighterPosition = function(face, point){ } } - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; \ No newline at end of file diff --git a/js/cells/TetraEdgeCell.js b/js/cells/TetraEdgeCell.js index 0b19fc613c6897c2936861fa5ad02984f2182f0f..ab83cd3614054171b62d7ecf341792625bccff4a 100644 --- a/js/cells/TetraEdgeCell.js +++ b/js/cells/TetraEdgeCell.js @@ -3,8 +3,8 @@ */ -function DMATetraEdgeCell(indices, scale, cellMode, partType){ - TetraFaceCell.call(this, indices, scale, cellMode, partType); +function DMATetraEdgeCell(index, superCell){ + TetraFaceCell.call(this, index, superCell); } DMATetraEdgeCell.prototype = Object.create(TetraFaceCell.prototype); diff --git a/js/cells/TetraFaceCell.js b/js/cells/TetraFaceCell.js index bc076a4719f4f3aac4d3e581eba5db4bfc7122c9..ef675ce82fb5b0a881b7653bfe09dd319dd93002 100644 --- a/js/cells/TetraFaceCell.js +++ b/js/cells/TetraFaceCell.js @@ -11,18 +11,18 @@ unitCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1 var unitCellGeoUpsideDown = unitCellGeo.clone(); unitCellGeoUpsideDown.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); -function TetraFaceCell(indices){ - DMACell.call(this, indices); +function TetraFaceCell(index, superCell){ + DMACell.call(this, index, superCell); } TetraFaceCell.prototype = Object.create(DMACell.prototype); TetraFaceCell.prototype._getGeometry = function(){//abstract mesh representation of cell - if (this.indices.z%2 ==0) return unitCellGeo;//todo need this? + if (this.index.z%2 ==0) return unitCellGeo;//todo need this? return unitCellGeoUpsideDown; }; TetraFaceCell.prototype._rotateCell = function(object3D){ - var zIndex = this.indices.z; + var zIndex = this.index.z; if (Math.abs(zIndex%4) == 2 || Math.abs(zIndex%4) == 3) object3D.rotateZ(Math.PI/3); return object3D; }; \ No newline at end of file diff --git a/js/cells/TruncatedCubeCell.js b/js/cells/TruncatedCubeCell.js index 35fdca0d6b909e0019653e37b343a95c660e944d..679d0dbc41ee4b30b0238c5425cad6c54069d83f 100644 --- a/js/cells/TruncatedCubeCell.js +++ b/js/cells/TruncatedCubeCell.js @@ -49,8 +49,8 @@ ]; unitCellGeo.computeFaceNormals(); - function TruncatedCubeCell(indices){ - DMACell.call(this, indices); + function TruncatedCubeCell(index, superCell){ + DMACell.call(this, index, superCell); } TruncatedCubeCell.prototype = Object.create(DMACell.prototype); @@ -68,14 +68,14 @@ TruncatedCubeCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal; - if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return {index: _.clone(this.indices)}; + if (!(Math.abs(direction.x)>0.9 || Math.abs(direction.y)>0.9 || Math.abs(direction.z)>0.9)) return {index: _.clone(this.index)}; var position = this.getPosition(); var scale = this.zScale(); _.each(_.keys(position), function(key){ position[key] += direction[key]*scale/2; }); - return {index: _.clone(this.indices), direction:direction, position:position}; + return {index: _.clone(this.index), direction:direction, position:position}; }; self.TruncatedCubeCell = TruncatedCubeCell; diff --git a/js/cells/supercells/GIKSuperCell.js b/js/cells/supercells/GIKSuperCell.js index 06d3c2394e7293018959acd75505066e5c090ad0..4ff18a87383f07227f7a9ee08768cc051e7f9458 100644 --- a/js/cells/supercells/GIKSuperCell.js +++ b/js/cells/supercells/GIKSuperCell.js @@ -33,17 +33,19 @@ function changeGikMaterials(){ } -GIKSuperCell = function(length, range, cells){ - if (range) this.indices = _.clone(range.max); +GIKSuperCell = function(indices, length){ + if (indices) this.indices = indices; + if (length === undefined) length = globals.lattice.get("gikLength"); this.material = globals.lattice.get("materialType"); - this.cells = cells; + this.cells = this._makeChildCells(indices, length); this.object3D = this._buildObject3D(); this._addChildren(this._buildMesh(length), this.object3D); var self = this; - _.each(cells, function(cell, index){ - self.addChildCell(cell.setSuperCell(self, index)); + _.each(this.cells, function(cell){ + self._addChildren(cell.getObject3D()); }); + if (this.indices) globals.three.sceneAdd(this.object3D, "supercell"); else (this.hide()); @@ -51,6 +53,17 @@ GIKSuperCell = function(length, range, cells){ }; GIKSuperCell.prototype = Object.create(DMACell.prototype); +GIKSuperCell.prototype._makeChildCells = function(indices, length){ + var cells = []; + for (var i=0;i<length;i++){ + var childIndices = {x:0, y:0, z:0}; + if (indices.z == 0) childIndices.x += i; + else childIndices.y += i; + cells.push(new GIKCell(childIndices, this)); + } + return cells; +}; + GIKSuperCell.prototype._buildObject3D = function(){ return this._translateCell(this._rotateCell(new THREE.Object3D())); }; @@ -60,10 +73,6 @@ GIKSuperCell.prototype._rotateCell = function(object3D){ return object3D; }; -GIKSuperCell.prototype.addChildCell = function(object3D){ - this._addChildren(object3D); -}; - GIKSuperCell.prototype._buildMesh = function(length){ var meshes = []; var superCellGeo = new THREE.BoxGeometry(1,1,1.28); @@ -94,6 +103,11 @@ GIKSuperCell.prototype.getMaterial = function(){ GIKSuperCell.prototype.setMode = function(mode){ if (mode === undefined) mode = globals.appState.get("cellMode"); + + _.each(this.cells, function(cell){ + cell.setMode(mode); + }); + if (mode == "cell") mode = "supercell"; if (mode == "part") mode = "object3D"; diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js index e8847f5ab47e31e730d73a72e60d25b3e48036f2..a5eb6b4f1c862c0f71ab762eba901d0984e52f46 100644 --- a/js/lattice/GIKLattice.js +++ b/js/lattice/GIKLattice.js @@ -35,22 +35,22 @@ latticeSubclasses["GIKLattice"] = { }, makeCellForLatticeType: function(indices){ - return new GIKCell(indices); + return new GIKSuperCell(indices); }, - makeSuperCell: function(range){ - var length = this.get("gikLength"); - var cells; - if (range) cells = this.addCellsInRange(range); - else {//this is for assembler stock only - cells = []; - for (var i=0;i<length;i++){ - cells.push(this.makeCellForLatticeType(null)); - } - } - if (cells.length < 1) return null; - return new GIKSuperCell(length, range, cells); - }, +// makeSuperCell: function(range){ +// var length = this.get("gikLength"); +// var cells; +// if (range) cells = this.addCellsInRange(range); +// else {//this is for assembler stock only +// cells = []; +// for (var i=0;i<length;i++){ +// cells.push(this.makeCellForLatticeType(null)); +// } +// } +// if (cells.length < 1) return null; +// return new GIKSuperCell(length, range, cells); +// }, // _rasterGikCells: function(order, callback, var1, var2, var3, cells){ // for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){ diff --git a/js/models/AppState.js b/js/models/AppState.js index c933bd44488553f7c1d4ddb6fb392ccce9d03911..cfa6390b3aa83684b3f927fc7ff7b970e8ed2140 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: false, + realisticColorScheme: true, stockSimulationPlaying: false, manualSelectOrigin: false//mode that allows user ot select origin from existing cell diff --git a/js/three/Highlighter.js b/js/three/Highlighter.js index 2be2eb5061dcb25ff7fd55c13826a820c160dcee..3634e4f63b34b184397fdd755b852f4d81497830 100644 --- a/js/three/Highlighter.js +++ b/js/three/Highlighter.js @@ -240,29 +240,19 @@ GIKHighlighter = Highlighter.extend({ globals.three.render(); }, - addRemoveVoxel: function(shouldAdd){ - if (shouldAdd){ - if (!this.isVisible() || !this.highlightedObject) return; - var position = this._getNextCellPosition(); - var index = globals.appState.get("superCellIndex"); - var min, max; - if (this.mesh.rotation.z == 0) { - min = {x:position.x-globals.lattice.get("gikLength")+1+index, y:position.y, z:position.z}; - max = {x:position.x+index, y:position.y, z:position.z}; - } - else { - min = {x:position.x, y:position.y-globals.lattice.get("gikLength")+1+index, z:position.z}; - max = {x:position.x, y:position.y+index, z:position.z}; - } - var range = {min:min, max:max}; - globals.lattice.makeSuperCell(range); - } else { - if (!this.highlightedObject) return; - if (!(this.highlightedObject instanceof DMACell)) return; - globals.lattice.removeCell(this.highlightedObject); - } - this.setNothingHighlighted(); + _getNextCellPosition: function(){//add direction vector to current index + var newIndex = _.clone(this.index); + var direction = this.direction; + _.each(_.keys(newIndex), function(key){ + newIndex[key] = Math.round(newIndex[key] + direction[key]); + }); + + var offset = globals.appState.get("superCellIndex"); + if (newIndex.z%2 == 0) newIndex.x -= offset; + else newIndex.y -= offset; + return newIndex; } + });