From 9e9c8f6597eb3ec9850346b865c6e27b424415cb Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 12 Mar 2015 23:28:26 -0400 Subject: [PATCH] eod --- js/cam/Assembler.js | 10 ++++---- js/fea/DmaCell.js | 9 +++++--- js/fea/DmaCellOcta.js | 8 +++---- js/fea/DmaCellOther.js | 6 ++--- js/fea/DmaCellTetra.js | 4 ++-- js/models/Lattice.js | 6 ++--- js/models/LatticeOcta.js | 48 +++++---------------------------------- js/models/LatticeOther.js | 6 ++--- 8 files changed, 33 insertions(+), 64 deletions(-) diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 1fe79c6b..89851849 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -48,15 +48,17 @@ Assembler = Backbone.Model.extend({ this._setNeedsPostProcessing); //init origin mesh + var scale = dmaGlobals.lattice.get("scale"); var origin = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), new THREE.MeshBasicMaterial({color:0xff0000})); dmaGlobals.three.sceneAdd(origin); this.set("origin", origin); //init stock mesh - var stock = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), - new THREE.MeshBasicMaterial({color:0xffff00})); - dmaGlobals.three.sceneAdd(stock); - this.set("stock", stock); + var stock = dmaGlobals.lattice.makeCellForLatticeType(null); + var stockMesh = stock.cellMesh.clone(); + stockMesh.scale.set(scale.x, scale.y, scale.z); + dmaGlobals.three.sceneAdd(stockMesh); + this.set("stock", stockMesh); this._setCAMVisibility(); }, diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index ffa7d473..67eaf8ec 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -12,12 +12,17 @@ function DMACell(indices, scale) { this.indices = indices; this.cellMesh = this._buildCellMesh(); + if (!indices) return;//this is a way to get the cell mesh without really initing a cell + + this._doMeshTransformations(this.cellMesh);//some cell types require transformations, this may go away if i decide to do this in the geo instead + dmaGlobals.three.sceneAdd(this.cellMesh, "cell"); this.nodes = this._initNodes(this.cellMesh.children[0].geometry.vertices); this.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); var cellMode = dmaGlobals.lattice.get("cellMode"); var beamMode = dmaGlobals.lattice.get("partType") == "beam"; this.drawForMode(scale, cellMode, beamMode); + } //todo this is a mess @@ -34,12 +39,10 @@ DMACell.prototype.drawForMode = function(scale, cellMode, beamMode){ }; DMACell.prototype._buildCellMesh = function(material){//called from every subclass - var unitCellGeo = this.getGeometry(); + var unitCellGeo = this._getGeometry(); if (!material) material = cellMaterials; var mesh = THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, material); - this._doMeshTransformations(mesh);//some cell types require transformations, this may go away if i decide to do this in the geo instead mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff - dmaGlobals.three.sceneAdd(mesh, "cell"); return mesh; }; diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 0bfff72a..e2cb273c 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -29,7 +29,7 @@ DMAFaceOctaCell.prototype._doMeshTransformations = function(mesh){ if (this.indices.z%2!=0) mesh.rotation.set(0, 0, Math.PI); }; -DMAFaceOctaCell.prototype.getGeometry = function(){ +DMAFaceOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; @@ -82,7 +82,7 @@ DMAFreeFormOctaCell.prototype.getType = function(){ return "octa"; }; -DMAFreeFormOctaCell.prototype.getGeometry = function(){ +DMAFreeFormOctaCell.prototype._getGeometry = function(){ return unitFaceOctaGeo; }; @@ -191,7 +191,7 @@ DMARotatedEdgeCell.prototype.zScale = function(scale){ return this.xScale(scale)*Math.sqrt(2); }; -DMARotatedEdgeCell.prototype.getGeometry = function(){ +DMARotatedEdgeCell.prototype._getGeometry = function(){ return unitVertexOcta; }; @@ -244,6 +244,6 @@ DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face, point){ return {index: _.clone(this.indices), direction:direction, position:position}; }; -DMAVertexOctaCell.prototype.getGeometry = function(){ +DMAVertexOctaCell.prototype._getGeometry = function(){ return unitVertexOcta; }; \ No newline at end of file diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 6f4fc9f7..5e485ddb 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -39,7 +39,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return {index: _.clone(this.indices), direction:direction, position:position}; }; - DMACubeCell.prototype.getGeometry = function(){ + DMACubeCell.prototype._getGeometry = function(){ return unitCellGeo; }; @@ -122,7 +122,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return {index: _.clone(this.indices), direction:direction, position:position}; }; - DMATruncCubeCell.prototype.getGeometry = function(){ + DMATruncCubeCell.prototype._getGeometry = function(){ return unitCellGeo; }; @@ -239,7 +239,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; return mesh; }; - DMATruncOctaCell.prototype.getGeometry = function(){ + DMATruncOctaCell.prototype._getGeometry = function(){ return unitCellGeo; }; diff --git a/js/fea/DmaCellTetra.js b/js/fea/DmaCellTetra.js index 67eef77c..dc42d5e4 100644 --- a/js/fea/DmaCellTetra.js +++ b/js/fea/DmaCellTetra.js @@ -30,7 +30,7 @@ DMATetraFaceCell.prototype._doMeshTransformations = function(mesh){ if (Math.abs(zIndex%4) == 2 || Math.abs(zIndex%4) == 3) mesh.rotateZ(Math.PI/3); }; -DMATetraFaceCell.prototype.getGeometry = function(){ +DMATetraFaceCell.prototype._getGeometry = function(){ return unitCellGeo; }; @@ -88,7 +88,7 @@ DMAFreeFormTetraCell.prototype.zScale = function(scale){ return 2*scale/Math.sqrt(24); }; -DMAFreeFormTetraCell.prototype.getGeometry = function(){ +DMAFreeFormTetraCell.prototype._getGeometry = function(){ return unitCellGeo2; }; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 27234a50..bb89b505 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -60,7 +60,7 @@ Lattice = Backbone.Model.extend({ for (var y=relativeMin.y;y<=relativeMax.y;y++){ for (var z=relativeMin.z;z<=relativeMax.z;z++){ if (!cells[x][y][z]) { - cells[x][y][z] = this._makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), scale); + cells[x][y][z] = this.makeCellForLatticeType(this._add({x:x, y:y, z:z}, cellsMin), scale); this.set("numCells", this.get("numCells")+1); } else console.warn("already a cell there"); } @@ -77,7 +77,7 @@ Lattice = Backbone.Model.extend({ var index = this._subtract(indices, this.get("cellsMin")); if (!cells[index.x][index.y][index.z]) { - cells[index.x][index.y][index.z] = this._makeCellForLatticeType(indices, scale); + cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, scale); this.set("numCells", this.get("numCells")+1); dmaGlobals.three.render(); } else console.warn("already a cell there"); @@ -380,7 +380,7 @@ Lattice = Backbone.Model.extend({ if (cell.type) var type = cell.type; if (cell.destroy) cell.destroy(); - var newCell = self._makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); + var newCell = self.makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); if (parts) { //todo make this better diff --git a/js/models/LatticeOcta.js b/js/models/LatticeOcta.js index 26f7588e..9697ce9d 100644 --- a/js/models/LatticeOcta.js +++ b/js/models/LatticeOcta.js @@ -53,42 +53,6 @@ OctaLatticeSubclasses = { return position; }, -// getInvCellPositionForIndex: function(index){ -// -// var scale = this.get("scale"); -// var position = _.clone(index); -// -// var oddZ = position.z%2 != 0; -// var upPoint = (position.z%4 == 0 || Math.abs(position.z%4) == 3); -// position.z = Math.floor(position.z/2); -// -// if (!upPoint){ -// position.x = (position.x)*this.xScale(scale); -// position.y = position.y*this.yScale(scale); -// } else { -// position.x = (position.x+0.5)*this.xScale(scale); -// position.y = (position.y)*this.yScale(scale)-scale/Math.sqrt(3)/2; -// } -// -// if (oddZ){ -// position.z = (position.z + 1)*this.zScale(scale); -// } else { -// position.z = (position.z)*this.zScale(scale); -// } -// -//// if (Math.abs(index.z%4) == 1 || Math.abs(index.z%4) == 2) position.z += this.zScale(scale); -// -// if ((index.y%2) != 0) { -// if (!upPoint){ -// position.x += this.xScale(scale)/2; -// } else { -// position.x -= this.xScale(scale)/2; -// } -// } -// -// return position; -// }, - xScale: function(scale){ if (!scale) scale = this.get("scale"); var colSep = this.get("columnSeparation"); @@ -104,7 +68,7 @@ OctaLatticeSubclasses = { return 2*scale/Math.sqrt(6); }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMAFaceOctaCell(indices, scale); }, @@ -140,12 +104,12 @@ OctaLatticeSubclasses = { addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ var scale = this.get("scale"); var cells = this.get("cells"); - cells[0][0].push(this._makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction, parentType, type)); + cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, scale, parentCellPos, parentCellOrient, direction, parentType, type)); this.set("numCells", this.get("numCells")+1); dmaGlobals.three.render(); }, - _makeCellForLatticeType: function(index, scale, parentPosition, parentOrientation, direction, parentType, type){ + makeCellForLatticeType: function(index, scale, parentPosition, parentOrientation, direction, parentType, type){ if (type){ if (type == "octa") return new DMAFreeFormOctaCell(index, scale, parentPosition, parentOrientation, direction, parentType); return new DMAFreeFormTetraCell(index, scale, parentPosition, parentOrientation, direction, parentType); @@ -255,7 +219,7 @@ OctaLatticeSubclasses = { return position; }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMAEdgeOctaCell(indices, scale); }, @@ -357,7 +321,7 @@ OctaLatticeSubclasses = { return this.xScale(scale)*Math.sqrt(2)/2; }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMARotatedEdgeCell(indices, scale); }, @@ -416,7 +380,7 @@ OctaLatticeSubclasses = { return this.xScale(scale); }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMAVertexOctaCell(indices, scale); }, diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 4f1c6195..ca0f11c8 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -40,7 +40,7 @@ OtherLatticeSubclasses = { return this.xScale(scale); }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMACubeCell(indices, scale); }, @@ -87,7 +87,7 @@ OtherLatticeSubclasses = { return this.xScale(scale); }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMATruncCubeCell(indices, scale); }, @@ -136,7 +136,7 @@ OtherLatticeSubclasses = { return this.xScale(scale); }, - _makeCellForLatticeType: function(indices, scale){ + makeCellForLatticeType: function(indices, scale){ return new DMATruncOctaCell(indices, scale); }, -- GitLab