diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 0200257a231e5260479c2ab266c5cf01b09fc9f7..e077cb06a26a6ce991ac7868ae78acfd2704f006 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -115,7 +115,6 @@ DMACell.prototype.destroy = function(){ var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function DMASideOctaCell(mode, indices, scale, lattice){ DMACell.call(this, mode, indices, scale, lattice); } @@ -141,19 +140,27 @@ DMACell.prototype.destroy = function(){ }; DMASideOctaCell.prototype.calcHighlighterPosition = function(face){ - if (face.normal.z<0.99) return null;//only highlight horizontal faces - - //the vertices don't include the position transformation applied to cell. Add these to create highlighter vertices - var mesh = this.cellMesh.children[0]; - var vertices = mesh.geometry.vertices; - var newVertices = [vertices[face.a].clone(), vertices[face.b].clone(), vertices[face.c].clone()]; - var scale = this.cellMesh.scale.x; - var position = (new THREE.Vector3()).setFromMatrixPosition(mesh.matrixWorld); - _.each(newVertices, function(vertex){//apply scale - vertex.multiplyScalar(scale); - vertex.add(position); - }); - return newVertices; + + var direction = face.normal; + if (face.normal.z<0.99) direction = null;//only highlight horizontal faces + +// //the vertices don't include the position transformation applied to cell. Add these to create highlighter vertices +// var mesh = this.cellMesh.children[0]; +// var vertices = mesh.geometry.vertices; +// var newVertices = [vertices[face.a].clone(), vertices[face.b].clone(), vertices[face.c].clone()]; +// var scale = this.cellMesh.scale.x; +// var position = (new THREE.Vector3()).setFromMatrixPosition(mesh.matrixWorld); +// _.each(newVertices, function(vertex){//apply scale +// vertex.multiplyScalar(scale); +// vertex.add(position); +// }); + + var position = dmaGlobals.lattice.getPositionForIndex(this.indices); +// var scale = dmaGlobals.lattice.xScale(); +// _.each(_.keys(position), function(key){ +// position[key] += direction[key]*scale/2; +// }); + return {index: _.clone(this.indices), direction:direction, position:position}; } self.DMASideOctaCell = DMASideOctaCell; diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index c7af2da0fd7da8a953b81277516f010eea161e36..aa09216c52127106e05286c22dc16d5db22cfb7a 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -6,7 +6,6 @@ //a part, element with a single material, handled by assembler function DMAPart(type, oddZFlag, parent) { - //todo remove this? this.parentCell = parent;//use this reference to get position and scale this.oddZFlag = oddZFlag;//this tells me if cell is at an odd z height in lattice, everything needs to rotate 180 this.type = type; @@ -90,7 +89,7 @@ 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().makeTranslation(0.25,-0.6, -0.45)); unitPartGeo1.applyMatrix(new THREE.Matrix4().makeRotationZ(-Math.PI/6)); unitPartGeo1.dynamic = true; diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 62ec31d01436d3620bf95503b0ce438b7fe6c471..227cecf05847aaac4932e41567be355696d6c112 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -172,17 +172,12 @@ OctaBasePlane = BasePlane.extend({ }, calcHighlighterPosition: function(face, position){ - //the vertices don't include the position transformation applied to cell. Add these to create highlighter vertices - var mesh = this.get("mesh")[0]; - var vertices = mesh.geometry.vertices; - var newVertices = [vertices[face.a].clone(), vertices[face.b].clone(), vertices[face.c].clone()]; - var scale = dmaGlobals.lattice.get("scale"); - var position = (new THREE.Vector3()).setFromMatrixPosition(mesh.matrixWorld); - _.each(newVertices, function(vertex){//apply scale - vertex.multiplyScalar(scale); - vertex.add(position); - }); - return {index: {}, direction: new THREE.Vector3(0,0,1), position:position}; + + var index = dmaGlobals.lattice.getIndexForPosition(position); + index.z = this.get("zIndex") - 1;//pretend we're on the top of the cell underneath the baseplane + var position = dmaGlobals.lattice.getPositionForIndex(index); + position.z += dmaGlobals.lattice.zScale()/2; + return {index: index, direction: new THREE.Vector3(0,0,1), position:position}; } }); diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 5b6b523f789d5ba936512df9a5878f8253865314..c56126a12e03dd1c7f3918ce9c5d1d9eddb4fe76 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -376,12 +376,12 @@ Lattice = Backbone.Model.extend({ getPositionForIndex: function(index){ - var position = this._positionForIndex(index); -// var octHeight = 2*scale/Math.sqrt(6); -// var triHeight = latticeScale/2*Math.sqrt(3); -// position.x = indices.x*latticeScale; -// position.y = indices.y*triHeight-latticeScale/Math.sqrt(3); -// position.z = indices.z*octHeight; + var scale = this.get("scale"); + var position = _.clone(index); + var xScale = this.xScale(scale); + position.x = position.x*xScale; + position.y = position.y*this.yScale(scale)-xScale/Math.sqrt(3); + position.z = (position.z+0.5)*this.zScale(scale); if (Math.abs(index.y%2) == 1) position.x -= this.xScale()/2; return position; }, diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 7cfde2b6500cfee5bc1a58ef13289bf470ab1d2d..f449340d13ec129daaf5591a8ca80fddd92f62a8 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -89,7 +89,7 @@ Highlighter = Backbone.View.extend({ _setPosition: function(position, direction){ this.mesh.position.set(position.x, position.y, position.z); - this.mesh.rotation.set(direction.y*Math.PI, direction.x*Math.PI, 0); +// this.mesh.rotation.set(direction.y*Math.PI, direction.x*Math.PI, 0); // this.mesh.updateMatrix(); }, @@ -101,7 +101,7 @@ Highlighter = Backbone.View.extend({ var newIndex = _.clone(this.index); var direction = this.direction; _.each(_.keys(newIndex), function(key){ - newIndex[key] += direction[key]; + newIndex[key] = Math.round(newIndex[key] + direction[key]); }); return newIndex; }, @@ -135,11 +135,9 @@ OctaFaceHighlighter = Highlighter.extend({ _makeGeometry: function(){ - var geometry = new THREE.Geometry(); - //can't change size of faces or vertices buffers dynamically - geometry.vertices = [new THREE.Vector3(0,0,0), new THREE.Vector3(0,0,0), new THREE.Vector3(0,0,0)]; - geometry.faces = [new THREE.Face3(0,1,2)]; - + var rad = 1/Math.sqrt(3); + var geometry = new THREE.CylinderGeometry(rad, rad, 0.01, 3);//short triangular prism + geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); return geometry; } @@ -160,7 +158,6 @@ OctaVertexHighlighter = Highlighter.extend({ CubeHighlighter = Highlighter.extend({ _makeGeometry: function(){ - var geometry = new THREE.BoxGeometry(1,1,0.01); return geometry; }