From 2de7d071a334d7aebd42eb2556a88cf67627b3cf Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Sat, 7 Mar 2015 19:55:07 -0500 Subject: [PATCH] abel to draw with tetra or octa --- js/fea/DmaCell.js | 46 ++++++++++++++++++++++++++++++------ js/models/BasePlane.js | 6 ++++- js/models/Lattice.js | 18 +++++++++----- js/threeViews/Highlighter.js | 2 +- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index 9963ff0f..26d0418b 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -64,6 +64,10 @@ DMACell.prototype._setMeshPosition = function(mesh, position){ mesh.position.z = position.z; }; +DMACell.prototype.getType = function(){ + return null;//only used in freeform layout +} + DMACell.prototype.getScale = function(){//need for part relay return dmaGlobals.lattice.get("scale"); }; @@ -187,10 +191,11 @@ DMACell.prototype.toJSON = function(){ self.DMAEdgeOctaCell = DMAEdgeOctaCell; - function DMAFreeFormOctaCell(indices, scale, parentCellPos, parentCellQuat, direction){ + function DMAFreeFormOctaCell(indices, scale, parentCellPos, parentCellQuat, direction, parentType){ this.parentPos = parentCellPos; this.parentQuaternion = parentCellQuat; this.parentDirection = direction; + this.parentType = parentType; DMAFaceOctaCell.call(this, indices, scale); } DMAFreeFormOctaCell.prototype = Object.create(DMAFaceOctaCell.prototype); @@ -203,8 +208,8 @@ DMACell.prototype.toJSON = function(){ var quaternion = new THREE.Quaternion().setFromUnitVectors(zAxis, direction); quaternion.multiply(this.parentQuaternion); - if (direction.sub(zAxis).length() < 0.1){ - var zRot = new THREE.Quaternion().setFromAxisAngle(zAxis, Math.PI); + if ((this.parentType == "octa" && direction.sub(zAxis).length() < 0.1) || this.parentType == "tetra"){ + var zRot = new THREE.Quaternion().setFromAxisAngle(this.parentDirection, Math.PI); zRot.multiply(quaternion); quaternion = zRot; } @@ -213,6 +218,10 @@ DMACell.prototype.toJSON = function(){ mesh.rotation.set(eulerRot.x, eulerRot.y, eulerRot.z); }; + DMAFreeFormOctaCell.prototype.getType = function(){ + return "octa"; + }; + DMAFreeFormOctaCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal.clone(); direction.applyQuaternion(this.cellMesh.quaternion); @@ -245,9 +254,9 @@ DMACell.prototype.toJSON = function(){ _.extend(json, { parentPosition: this.parentPos, parentOrientation: this.parentQuaternion, - direction: this.parentDirection -// position: this.getPosition(), -// orientation: this.getOrientation() + direction: this.parentDirection, + parentType: this.parentType, + type: "octa" }); return json; } @@ -295,10 +304,11 @@ DMACell.prototype.toJSON = function(){ unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI/4)); unitCellGeo2.applyMatrix(new THREE.Matrix4().makeRotationX((Math.PI-Math.atan(2*Math.sqrt(2)))/2)); - function DMAFreeFormTetraCell(indices, scale, parentCellPos, parentCellQuat, direction){ + function DMAFreeFormTetraCell(indices, scale, parentCellPos, parentCellQuat, direction, parentType){ this.parentPos = parentCellPos; this.parentQuaternion = parentCellQuat; this.parentDirection = direction; + this.parentType = parentType; DMATetraFaceCell.call(this, indices, scale); } DMAFreeFormTetraCell.prototype = Object.create(DMATetraFaceCell.prototype); @@ -307,6 +317,10 @@ DMACell.prototype.toJSON = function(){ return this._superBuildCellMesh(unitCellGeo2); }; + DMAFreeFormTetraCell.prototype.getType = function(){ + return "tetra"; + }; + DMAFreeFormTetraCell.prototype._doMeshTransformations = function(mesh){ var direction = this.parentDirection.clone(); var zAxis = new THREE.Vector3(0,0,1); @@ -314,6 +328,12 @@ DMACell.prototype.toJSON = function(){ var quaternion = new THREE.Quaternion().setFromUnitVectors(zAxis, direction); quaternion.multiply(this.parentQuaternion); + if (this.parentType == "octa" && direction.sub(zAxis).length() > 0.1){//only do this if connecting to octa + var zRot = new THREE.Quaternion().setFromAxisAngle(this.parentDirection, Math.PI); + zRot.multiply(quaternion); + quaternion = zRot; + } + var eulerRot = new THREE.Euler().setFromQuaternion(quaternion); mesh.rotation.set(eulerRot.x, eulerRot.y, eulerRot.z); }; @@ -346,6 +366,18 @@ DMACell.prototype.toJSON = function(){ return 2*scale/Math.sqrt(24); }; + DMAFreeFormTetraCell.prototype.toJSON = function(){ + var json = DMACell.prototype.toJSON.call(this); + _.extend(json, { + parentPosition: this.parentPos, + parentOrientation: this.parentQuaternion, + direction: this.parentDirection, + parentType: this.parentType, + type: "tetra" + }); + return json; + } + self.DMAFreeFormTetraCell = DMAFreeFormTetraCell; diff --git a/js/models/BasePlane.js b/js/models/BasePlane.js index 81a01e14..a35258e9 100644 --- a/js/models/BasePlane.js +++ b/js/models/BasePlane.js @@ -40,7 +40,11 @@ BasePlane = Backbone.Model.extend({ }, getOrientation: function(){ - return new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), Math.PI);; + return new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), Math.PI); + }, + + getType: function(){ + return "octa"; }, // _renderForCurrentScene: function(){ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 3a25b049..366a394a 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -408,9 +408,11 @@ Lattice = Backbone.Model.extend({ if (cell.parentOrientation) var parentOrientation = new THREE.Quaternion(cell.parentOrientation._x, cell.parentOrientation._y, cell.parentOrientation._z, cell.parentOrientation._w); if (cell.parentPosition) var parentPos = cell.parentPosition; if (cell.direction) var direction = new THREE.Vector3(cell.direction.x, cell.direction.y, cell.direction.z); + if (cell.parentType) var parentType = cell.parentType; + if (cell.type) var type = cell.type; if (cell.destroy) cell.destroy(); - var newCell = self._makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction); + var newCell = self._makeCellForLatticeType(index, scale, parentPos, parentOrientation, direction, parentType, type); if (parts) { //todo make this better @@ -650,17 +652,21 @@ Lattice = Backbone.Model.extend({ }, - addFreeFormCell: function(parentCellPos, parentCellOrient, direction){ + 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)); + 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){ - if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, scale, parentPosition, parentOrientation, direction); - return new DMAFreeFormTetraCell(index, scale, parentPosition, parentOrientation, direction); + _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); + } + if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, scale, parentPosition, parentOrientation, direction, parentType); + return new DMAFreeFormTetraCell(index, scale, parentPosition, parentOrientation, direction, parentType); }, getIndexForPosition: function(absPosition){//only used by baseplane diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 264fc158..4229989f 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -111,7 +111,7 @@ Highlighter = Backbone.View.extend({ if (!this.isVisible() || !this.highlightedObject) return; if (dmaGlobals.lattice.get("connectionType") == "freeformFace"){ //todo make this work for baseplane - dmaGlobals.lattice.addFreeFormCell(this.mesh.position.clone(), this.highlightedObject.getOrientation(), this.direction); + dmaGlobals.lattice.addFreeFormCell(this.mesh.position.clone(), this.highlightedObject.getOrientation(), this.direction, this.highlightedObject.getType()); return; } dmaGlobals.lattice.addCellAtIndex(this._getNextCellPosition()); -- GitLab