From 6e4354bb5221e2286e70faf15bd211cce307c56a Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 12 Mar 2015 17:11:44 -0400 Subject: [PATCH] get geometry method on cell --- js/cam/Assembler.js | 9 ++++++++- js/fea/DmaCell.js | 4 ++-- js/fea/DmaCellOcta.js | 32 ++++++++++++++++---------------- js/fea/DmaCellOther.js | 22 +++++++++++++++++----- js/fea/DmaCellTetra.js | 14 +++++++++----- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index 3ef8b113..1fe79c6b 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -31,6 +31,7 @@ Assembler = Backbone.Model.extend({ //bind events this.listenTo(dmaGlobals.appState, "change:currentTab", this._setCAMVisibility); this.listenTo(this, "change:originPosition", this._moveOrigin); + this.listenTo(this, "change:stockPosition", this._moveStock); this.listenTo(dmaGlobals.appState, "change:units", this._setNeedsPostProcessing); this.listenTo(this, "change:originPosition " + @@ -54,7 +55,7 @@ Assembler = Backbone.Model.extend({ //init stock mesh var stock = new THREE.Mesh(new THREE.SphereGeometry(dmaGlobals.lattice.get("scale")/4), new THREE.MeshBasicMaterial({color:0xffff00})); - dmaGlobals.three.sceneAdd(origin); + dmaGlobals.three.sceneAdd(stock); this.set("stock", stock); this._setCAMVisibility(); }, @@ -74,6 +75,12 @@ Assembler = Backbone.Model.extend({ dmaGlobals.three.render(); }, + _moveStock: function(){ + var position = this.get("stockPosition"); + this.get("stock").position.set(position.x, position.y, position.z); + dmaGlobals.three.render(); + }, + _setNeedsPostProcessing: function(){ this.set("needsPostProcessing", true); }, diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index fb04ff96..ffa7d473 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -28,13 +28,13 @@ DMACell.prototype.drawForMode = function(scale, cellMode, beamMode){ _.each(this.parts, function(part){ if (part) part.setVisibility(cellMode == "part" && !beamMode); }); - var self = this; _.each(this.beams, function(beam){ beam.setVisibility(beamMode && cellMode == "part"); }); }; -DMACell.prototype._buildCellMesh = function(unitCellGeo, material){//called from every subclass +DMACell.prototype._buildCellMesh = function(material){//called from every subclass + 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 diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 39b78487..0bfff72a 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -25,14 +25,14 @@ DMAFaceOctaCell.prototype._initParts = function(){ return parts; }; -DMAFaceOctaCell.prototype._buildCellMesh = function(){ - return DMACell.prototype._buildCellMesh.call(this, unitFaceOctaGeo); -}; - DMAFaceOctaCell.prototype._doMeshTransformations = function(mesh){ if (this.indices.z%2!=0) mesh.rotation.set(0, 0, Math.PI); }; +DMAFaceOctaCell.prototype.getGeometry = function(){ + return unitFaceOctaGeo; +}; + DMAFaceOctaCell.prototype.calcHighlighterPosition = function(face){ if (face.normal.z<0.99) return {index: _.clone(this.indices)};//only highlight horizontal faces var direction = face.normal; @@ -52,10 +52,6 @@ function DMAFreeFormOctaCell(indices, scale, parentCellPos, parentCellQuat, dire } DMAFreeFormOctaCell.prototype = Object.create(DMAFreeFormCell.prototype); -DMAFreeFormOctaCell.prototype._buildCellMesh = function(){ - return DMACell.prototype._buildCellMesh.call(this, unitFaceOctaGeo); -}; - DMAFreeFormOctaCell.prototype._doMeshTransformations = function(mesh){ var direction = this.parentDirection.clone(); @@ -86,6 +82,10 @@ DMAFreeFormOctaCell.prototype.getType = function(){ return "octa"; }; +DMAFreeFormOctaCell.prototype.getGeometry = function(){ + return unitFaceOctaGeo; +}; + DMAFreeFormOctaCell.prototype.zScale = function(scale){ if (!scale) scale = dmaGlobals.lattice.get("scale"); return 2*scale/Math.sqrt(6); @@ -126,10 +126,6 @@ function DMARotatedEdgeCell(indices, scale){ } DMARotatedEdgeCell.prototype = Object.create(DMACell.prototype); -DMARotatedEdgeCell.prototype._buildCellMesh = function(){ - return DMACell.prototype._buildCellMesh.call(this, unitVertexOcta); -}; - DMARotatedEdgeCell.prototype._doMeshTransformations = function(mesh){ mesh.rotation.set(0, 0, Math.PI/4); }; @@ -195,6 +191,10 @@ DMARotatedEdgeCell.prototype.zScale = function(scale){ return this.xScale(scale)*Math.sqrt(2); }; +DMARotatedEdgeCell.prototype.getGeometry = function(){ + return unitVertexOcta; +}; + /////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////VERTEX CONNECTED/////////////////////////////////////////////////////// @@ -206,10 +206,6 @@ function DMAVertexOctaCell(indices, scale){ } DMAVertexOctaCell.prototype = Object.create(DMACell.prototype); -DMAVertexOctaCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - return DMACell.prototype._buildCellMesh.call(this, unitVertexOcta); -}; - DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face, point){ var position = this.getPosition(); @@ -246,4 +242,8 @@ DMAVertexOctaCell.prototype.calcHighlighterPosition = function(face, point){ } return {index: _.clone(this.indices), direction:direction, position:position}; +}; + +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 3feacaa4..6f4fc9f7 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -21,7 +21,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMACubeCell.prototype = Object.create(DMACell.prototype); DMACubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, unitCellGeo, cellMaterial); + var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); var wireframe = new THREE.BoxHelper(mesh.children[0]); wireframe.material.color.set(0x000000); mesh.children.push(wireframe); @@ -37,7 +37,11 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; position[key] += direction[key]*scale/2; }); return {index: _.clone(this.indices), direction:direction, position:position}; - } + }; + + DMACubeCell.prototype.getGeometry = function(){ + return unitCellGeo; + }; self.DMACubeCell = DMACubeCell; @@ -100,7 +104,7 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMATruncCubeCell.prototype = Object.create(DMACell.prototype); DMATruncCubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, unitCellGeo, cellMaterial); + var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); mesh.children.push(new THREE.EdgesHelper(mesh.children[0], 0x000000)); return mesh; }; @@ -116,7 +120,11 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; position[key] += direction[key]*scale/2; }); return {index: _.clone(this.indices), direction:direction, position:position}; - } + }; + + DMATruncCubeCell.prototype.getGeometry = function(){ + return unitCellGeo; + }; self.DMATruncCubeCell = DMATruncCubeCell; @@ -226,11 +234,15 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); DMATruncOctaCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - var mesh = DMACell.prototype._buildCellMesh.call(this, unitCellGeo, cellMaterial); + var mesh = DMACell.prototype._buildCellMesh.call(this, cellMaterial); mesh.children.push(new THREE.EdgesHelper(mesh.children[0], 0x000000)); return mesh; }; + DMATruncOctaCell.prototype.getGeometry = function(){ + return unitCellGeo; + }; + self.DMATruncOctaCell = DMATruncOctaCell; })(); diff --git a/js/fea/DmaCellTetra.js b/js/fea/DmaCellTetra.js index 0ad033a9..67eef77c 100644 --- a/js/fea/DmaCellTetra.js +++ b/js/fea/DmaCellTetra.js @@ -21,7 +21,7 @@ DMATetraFaceCell.prototype = Object.create(DMACell.prototype); DMATetraFaceCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell var zIndex = this.indices.z; - if (zIndex%2 ==0) return DMACell.prototype._buildCellMesh.call(this, unitCellGeo); + if (zIndex%2 ==0) return DMACell.prototype._buildCellMesh.call(this); return DMACell.prototype._buildCellMesh.call(this, unitCellGeoUpsideDown); }; @@ -30,6 +30,10 @@ 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(){ + return unitCellGeo; +}; + /////////////////////////////////////////////////////////////////////////////////////////////// @@ -58,10 +62,6 @@ function DMAFreeFormTetraCell(indices, scale, parentCellPos, parentCellQuat, dir } DMAFreeFormTetraCell.prototype = Object.create(DMAFreeFormCell.prototype); -DMAFreeFormTetraCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell - return DMACell.prototype._buildCellMesh.call(this, unitCellGeo2); -}; - DMAFreeFormTetraCell.prototype._doMeshTransformations = function(mesh){ var direction = this.parentDirection.clone(); var zAxis = new THREE.Vector3(0,0,1); @@ -88,4 +88,8 @@ DMAFreeFormTetraCell.prototype.zScale = function(scale){ return 2*scale/Math.sqrt(24); }; +DMAFreeFormTetraCell.prototype.getGeometry = function(){ + return unitCellGeo2; +}; + -- GitLab