diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 6804d9bec0575385d903279abda95dd1060c3557..b1bf66f9cc03392b7152cc28e69e8067e98b6a08 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -102,12 +102,11 @@ DMACell.prototype.destroy = function(){ var unitCellGeo1 = new THREE.OctahedronGeometry(1/Math.sqrt(2)); unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12)); unitCellGeo1.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3)))); + unitCellGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,unitOctHeight/2)); var unitCellGeo2 = unitCellGeo1.clone(); - unitCellGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0,-1/Math.sqrt(3),unitOctHeight/2)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - unitCellGeo2.applyMatrix(new THREE.Matrix4().makeTranslation(0,1/Math.sqrt(3),unitOctHeight/2)); var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; @@ -124,10 +123,9 @@ DMACell.prototype.destroy = function(){ var octHeight = 2*scale/Math.sqrt(6); var triHeight = latticeScale/2*Math.sqrt(3); position.x = indices.x*latticeScale; - position.y = indices.y*triHeight; + position.y = indices.y*triHeight-latticeScale/Math.sqrt(3); position.z = indices.z*octHeight; if (Math.abs(indices.y%2) == 1) position.x -= latticeScale/2; - if (Math.abs(indices.z%2) == 1) position.y -= triHeight*4/3; return position; }; @@ -138,7 +136,7 @@ DMACell.prototype.destroy = function(){ DMASideOctaCell.prototype._initParts = function(zIndex){ var parts = []; for (var i=0;i<3;i++){ - parts.push(new DMAPart(i, zIndex%2==1, this)); + parts.push(new DMATrianglePart(i, zIndex%2==1, this)); } return parts; }; diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index 48b138ed30810b8041b25c24bbe7e4358a7d0816..d0a0fd05e511d69e90353d9096474c8fb14f32e6 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -5,42 +5,6 @@ //a part, element with a single material, handled by assembler -(function () { - - var unitPartGeo1, unitPartGeo2, unitPartGeo3, unitPartGeo4, unitPartGeo5,unitPartGeo6; - - //import part geometry - var loader = new THREE.STLLoader(); - loader.load("data/trianglePart.stl", function(geometry){ - - unitPartGeo1 = geometry - unitPartGeo1.dynamic = true; - unitPartGeo1.computeBoundingBox(); - var unitScale = 1.2/unitPartGeo1.boundingBox.max.y; - unitPartGeo1.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); - unitPartGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0.25,-0.6, -0.08)); - unitPartGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6)); - unitPartGeo1.dynamic = true; - - unitPartGeo2 = unitPartGeo1.clone(); - unitPartGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(2*Math.PI/3)); - - unitPartGeo3 = unitPartGeo1.clone(); - unitPartGeo3.applyMatrix(new THREE.Matrix4().makeRotationZ(-2*Math.PI/3)); - - unitPartGeo4 = unitPartGeo1.clone(); - unitPartGeo4.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - - unitPartGeo5 = unitPartGeo2.clone(); - unitPartGeo5.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - - unitPartGeo6 = unitPartGeo3.clone(); - unitPartGeo6.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); - }); - - var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THREE.FlatShading }); - partMaterial.color.setRGB( 0.9619657144369509, 0.6625466032079207, 0.20799727886007258 ); - function DMAPart(type, oddZFlag, parent) { //todo remove this? this.parentCell = parent;//use this reference to get position and scale @@ -55,33 +19,10 @@ window.three.sceneAdd(this.mesh, "part"); }; - DMAPart.prototype._makeMeshForType = function(type){ - var mesh; - switch(type){ - case 0: - if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo4, partMaterial.clone()); - else mesh = new THREE.Mesh(unitPartGeo1, partMaterial.clone()); - break; - case 1: - if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo5, partMaterial.clone()); - else mesh = new THREE.Mesh(unitPartGeo2, partMaterial.clone()); - break; - case 2: - if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo6, partMaterial.clone()); - else mesh = new THREE.Mesh(unitPartGeo3, partMaterial.clone()); - break; - } - mesh.myPart = this;//need a ref back to this part - return mesh; - }; - - DMAPart.prototype._setMeshPosition = function(scale, position){ - var mesh = this.mesh; - mesh.position.x = position.x; - mesh.position.y = -scale/3*Math.sqrt(3)+position.y; - mesh.position.z = position.z; - if (this.oddZFlag){//adjust some offsets for odd z layers - mesh.position.y += 7*scale/6; + DMAPart.prototype.updateForScale = function(scale, position){ + if (this.mesh) { + this.mesh.scale.set(scale, scale, scale); + this._setMeshPosition(scale, position); } }; @@ -130,18 +71,80 @@ this.type = null; }; - self.DMAPart = DMAPart; - -})(); ////////////////////////////////////////////////////////////// -/////////////////SUBCLASSES/////////////////////////////////// +/////////////////TRIANGLE PART/////////////////////////////////// ////////////////////////////////////////////////////////////// +(function () { + + var unitPartGeo1, unitPartGeo2, unitPartGeo3, unitPartGeo4, unitPartGeo5,unitPartGeo6; + + //import part geometry + var loader = new THREE.STLLoader(); + loader.load("data/trianglePart.stl", function(geometry){ + + unitPartGeo1 = geometry + unitPartGeo1.dynamic = true; + unitPartGeo1.computeBoundingBox(); + var unitScale = 1.2/unitPartGeo1.boundingBox.max.y; + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeTranslation(0.25,-0.6, -0.08)); + unitPartGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6)); + unitPartGeo1.dynamic = true; + + unitPartGeo2 = unitPartGeo1.clone(); + unitPartGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(2*Math.PI/3)); + + unitPartGeo3 = unitPartGeo1.clone(); + unitPartGeo3.applyMatrix(new THREE.Matrix4().makeRotationZ(-2*Math.PI/3)); + + unitPartGeo4 = unitPartGeo1.clone(); + unitPartGeo4.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); + + unitPartGeo5 = unitPartGeo2.clone(); + unitPartGeo5.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); + + unitPartGeo6 = unitPartGeo3.clone(); + unitPartGeo6.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); + }); + + var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THREE.FlatShading }); + partMaterial.color.setRGB( 0.9619657144369509, 0.6625466032079207, 0.20799727886007258 ); + + function DMATrianglePart(type, oddZFlag, parent){ + DMAPart.call(this, type, oddZFlag, parent); + } + DMATrianglePart.prototype = Object.create(DMAPart.prototype); + + DMAPart.prototype._makeMeshForType = function(type){ + var mesh; + switch(type){ + case 0: + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo4, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo1, partMaterial.clone()); + break; + case 1: + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo5, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo2, partMaterial.clone()); + break; + case 2: + if (this.oddZFlag) mesh = new THREE.Mesh(unitPartGeo6, partMaterial.clone()); + else mesh = new THREE.Mesh(unitPartGeo3, partMaterial.clone()); + break; + } + mesh.myPart = this;//need a ref back to this part + return mesh; + }; + + DMATrianglePart.prototype._setMeshPosition = function(scale, position){ + var mesh = this.mesh; + mesh.position.x = position.x; + mesh.position.y = position.y; + mesh.position.z = position.z; + }; + + self.DMATrianglePart = DMATrianglePart; -////matt's part -//function PartTriangle(){ -//} -// -//PartTriangle.prototype = new DmaPart(); \ No newline at end of file +})(); \ No newline at end of file diff --git a/js/models/Lattice.js b/js/models/Lattice.js index b26cb522a261e4dc212392682c1c66697797e583..228d1246cd57767f19e7a7f85e5d75bd893e7f04 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -262,7 +262,7 @@ OctaFaceLattice = Lattice.extend({ //bind events this.listenTo(this, "change:columnSeparation", this._changeColSeparation); - this.set("columnSeparation", 0.1); + this.set("columnSeparation", 0.0); }, _changeColSeparation: function(){