diff --git a/js/cam/Machine.js b/js/cam/Machine.js index aa82f302dd46856dc6727944b30c453b9bc5280a..78bc3df97168df8686aebd02dfeece92fbb804d3 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -68,6 +68,7 @@ Machine.prototype.setScale = function(scale){ } Machine.prototype._makeStockCell = function(){ + if (dmaGlobals.lattice.makeSuperCell) return dmaGlobals.lattice.makeSuperCell(); return dmaGlobals.lattice.makeCellForLatticeType(null, dmaGlobals.lattice.get("scale")); }; @@ -172,7 +173,7 @@ Machine.prototype._incrementalMove = function(objects, axis, increment, currentP Machine.prototype._setPosition = function(objects, nextPos, axis){ _.each(objects, function(object){ - if (object instanceof DMACell) object.moveTo(nextPos, axis); + if (object instanceof DMACell || object instanceof DMASuperCell) object.moveTo(nextPos, axis); else object.position[axis] = nextPos; }); }; diff --git a/js/fea/DMASuperCell.js b/js/fea/DMASuperCell.js index d0b5d6305c04c47ed46c56cca25a7649a5ea1680..8db6afc26fd5d8555abe63d6ab99569d38ae7566 100644 --- a/js/fea/DMASuperCell.js +++ b/js/fea/DMASuperCell.js @@ -7,11 +7,16 @@ var cellBrassMaterial = new THREE.MeshLambertMaterial({color:"#b5a642"}); var cellFiberGlassMaterial = new THREE.MeshLambertMaterial({color:"#fff68f"}); DMASuperCell = function(length, range, cells){ - var shouldRotate = range.max.x == range.min.x; + if (range) var shouldRotate = range.max.x == range.min.x; this.material = dmaGlobals.lattice.get("materialType"); this.mesh = this._buildSuperCellMesh(length, shouldRotate); this.setVisibility(dmaGlobals.appState.get("cellMode")=="cell"); - this.index = _.clone(range.max); + if (range) { + this.index = _.clone(range.max); + if (this.index.z %2 == 0) this.index.x -= cells.length/2.0-0.5; + else this.index.y -= cells.length/2.0-0.5; + } + this.cells = cells; this.setScale(); dmaGlobals.three.sceneAdd(this.mesh); @@ -20,7 +25,6 @@ DMASuperCell = function(length, range, cells){ DMASuperCell.prototype._buildSuperCellMesh = function(length, shouldRotate){ var superCellGeo = new THREE.BoxGeometry(1,1,1); superCellGeo.applyMatrix(new THREE.Matrix4().makeScale(length, 1, 1)); - superCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(length/2-1/2), 0, 0)); if (shouldRotate) superCellGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/2)); var mesh = THREE.SceneUtils.createMultiMaterialObject(superCellGeo, [this.getMaterialType()]); var wireframe = new THREE.BoxHelper(mesh.children[0]); @@ -36,6 +40,7 @@ DMASuperCell.prototype.getMaterialType = function(){ }; DMASuperCell.prototype._setPosition = function(index){ + if (!index) return; var position = dmaGlobals.lattice.getPositionForIndex(index); this.mesh.position.set(position.x, position.y, position.z); }; @@ -54,6 +59,38 @@ DMASuperCell.prototype.getLength = function(){ return this.cells.length-1; }; +DMASuperCell.prototype.hide = function(){//only used in the context of stock simulation + this.setVisibility(false); + _.each(this.cells, function(cell){ + if (cell) cell.hide(); + }); +}; + +DMASuperCell.prototype.draw = function(scale, cellMode, partType){ + if (this.hideForStockSimulation) return; + if (!scale) scale = dmaGlobals.lattice.get("scale"); + var partMode = cellMode == "part"; + +// this.updateForScale(scale, cellMode, partType); + + //set visibility + this.setVisibility(!partMode); + _.each(this.cells, function(cell){ + if (cell) cell.draw(scale, cellMode, partType); + }); +}; + +DMASuperCell.prototype.getPosition = function(){ + return this.mesh.position.clone(); +}; + +DMASuperCell.prototype.moveTo = function(position, axis){//used for stock simulations + this.mesh.position[axis] = position; + _.each(this.cells, function(cell){ + if (cell) cell.moveTo(position, axis); + }); +}; + DMASuperCell.prototype.destroy = function(){ if (this.destroyStarted) return;//prevents loop destroy from cells this.destroyStarted = true; diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 897c0c42f0088375609a41e9c8f42aaed34d828d..201af4061c1675821a1f4bcff497b79629b5e99a 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -163,6 +163,7 @@ DMACell.prototype._buildCellMesh = function(material){//called from every subcla return mesh; }; + DMACell.prototype._doMeshTransformations = function(mesh){};//by default, no mesh transformations DMACell.prototype._initParts = function(){ diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 5fbc42523aeb637586339a891129d17ea701195e..d543b09a156d879b56021af016079eda3c63ebce 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -70,9 +70,11 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMAGIKCell.prototype = Object.create(DMACubeCell.prototype); DMAGIKCell.prototype._buildCellMesh = function(){ - var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); - if (this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2); - return mesh; + return DMACubeCell.prototype._buildCellMesh.call(this, cellMaterial); + }; + + DMAGIKCell.prototype._doMeshTransformations = function(mesh){ + if (this.indices && this.indices.z%2 != 0) mesh.rotateZ(Math.PI/2); }; DMAGIKCell.prototype._setCellMeshVisibility = function(visible){ diff --git a/js/models/AppState.js b/js/models/AppState.js index 0725378434b2c309841c1e0df0ced9d7e92e125d..1bcc364a726b03bc86c9c101ca15807a82ba4696 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -69,8 +69,8 @@ AppState = Backbone.Model.extend({ }, edge: null, edgeRot: { - voxLowPoly: "Snap Voxel (low res)", - vox: "Snap Voxel (high res)" + vox: "Snap Voxel (high res)", + voxLowPoly: "Snap Voxel (low res)" //beam:"Beam" }, vertex: null//{ @@ -135,7 +135,8 @@ AppState = Backbone.Model.extend({ vertex:{handOfGod: "Hand of God"} }, cube:{ - face:{handOfGod: "Hand of God"} + face:{handOfGod: "Hand of God"}, + gik: {handOfGod: "Hand of God"} }, truncatedCube:{ face:{handOfGod: "Hand of God"} @@ -143,7 +144,6 @@ AppState = Backbone.Model.extend({ kelvin:{ face:{handOfGod: "Hand of God"} } -// will: "Electronics Assembler" }, allAssemblyStrategies: { raster: "Raster" @@ -249,7 +249,6 @@ AppState = Backbone.Model.extend({ this.get("lastSimulationTab")); else if (navSelection == "navAssemble") this.set("currentTab", this.get("lastAssembleTab")); - //todo make it so animation looks good again }, /////////////////////////////////////////////////////////////////////////////// diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 96f775efd220ccb4df93f7a38c65e89252e0f851..5a7d99f1736cb22081e9df0dd04345218f39e91a 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -87,14 +87,23 @@ OtherLatticeSubclasses = { return new DMAGIKCell(indices, scale); }, - addSuperCell: function(range){ + makeSuperCell: function(range){ var length = this.get("gikLength"); - var cells = this.addCellsInRange(range); - if (cells.length < 1) return; + var cells; + if (range) cells = this.addCellsInRange(range); + else { + cells = []; + var scale = this.get("scale"); + for (var i=0;i<length;i++){ + cells.push(this.makeCellForLatticeType(null, scale)); + } + } + if (cells.length < 1) return null; var superCell = new DMASuperCell(length, range, cells); _.each(cells, function(cell, index){ cell.setSuperCell(superCell, index); }); + return superCell; }, _undo: function(){//remove all the mixins, this will help with debugging later diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 944505e9b486388c6c658881b062f3ec5bcbcf0c..b22a35d6a18ab8739f63667255a504ec4fb592bb 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -255,7 +255,7 @@ GIKHighlighter = Highlighter.extend({ max = {x:position.x, y:position.y+index, z:position.z}; } var range = {min:min, max:max}; - dmaGlobals.lattice.addSuperCell(range); + dmaGlobals.lattice.makeSuperCell(range); } else { if (!this.highlightedObject) return; if (!(this.highlightedObject instanceof DMACell)) return;