diff --git a/js/fea/dmaCell.js b/js/fea/dmaCell.js index 5cfe4ca7c2550a13a0c70aaaf2b29fa76dc97a9e..859904e7b8247a85509ebdf1b6f946e1487e6ec3 100644 --- a/js/fea/dmaCell.js +++ b/js/fea/dmaCell.js @@ -19,38 +19,62 @@ cellGeometry2.applyMatrix(new THREE.Matrix4().makeRotationZ(Math.PI)); cellGeometry2.applyMatrix(new THREE.Matrix4().makeTranslation(0,30/Math.sqrt(3),octHeight/2)); - var cellMaterials = [new THREE.MeshNormalMaterial(), new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; + var cellMaterials = [new THREE.MeshNormalMaterial(), + new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; - function Cell(position) { + function Cell(mode, position) { - if (Math.round(position.z/octHeight)%2==0){ - this.mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials); - } else { - this.mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials); - } - this.mesh.position.x = position.x; - this.mesh.position.y = position.y; - this.mesh.position.z = position.z; - - this.mesh.myCell = this;//we need a reference to this instance from the mesh for + this.position = position; + this.drawForMode(mode, position); this._draw(); // this.parts = this._createParts(nodes, config); } - //Cell.prototype._createParts = function(nodes, config){ - // var parts = []; - // for (var i=0;i<nodes.length;i++){ - // parts.push(new Part(nodes[i], config[i])); - // } - // return parts; - //}; + Cell.prototype._buildPartsMesh = function(){ +// var parts = []; +// for (var i=0;i<nodes.length;i++){ +// parts.push(new Part(nodes[i], config[i])); +// } +// return parts; + }; + + Cell.prototype._buildCellMesh = function(position){//abstract mesh representation of cell + + var mesh; + + if (Math.round(position.z/octHeight)%2==0){ + mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry1, cellMaterials); + } else { + mesh = THREE.SceneUtils.createMultiMaterialObject(cellGeometry2, cellMaterials); + } + mesh.position.x = position.x; + mesh.position.y = position.y; + mesh.position.z = position.z; + + mesh.myCell = this;//we need a reference to this instance from the mesh for intersection selection stuff + return mesh; + }; Cell.prototype._draw = function(){ window.three.sceneAdd(this.mesh); }; + Cell.prototype.drawForMode = function(mode, position){ + if (this.mesh) this.remove(); + this.mesh = null; + position = position || this.position; + if (mode == "cell"){ + this.mesh = this._buildCellMesh(position); + } else if (mode == "parts"){ + this.mesh = this._buildPartsMesh(); + } else { + console.warn("unrecognized draw mode for cell"); + } + if (this.mesh) this._draw(); + }; + Cell.prototype.remove = function(){ window.three.sceneRemove(this.mesh); }; diff --git a/js/models/lattice.js b/js/models/lattice.js index 4518fb1d168cf43d668dde628977eade76b843dd..cd4c63496a6081c98fc9d2fdd456fb2d39fa084e 100644 --- a/js/models/lattice.js +++ b/js/models/lattice.js @@ -12,7 +12,8 @@ Lattice = Backbone.Model.extend({ nodes: [], cells: [], numCells: 0, - partType: "triangle" + partType: "triangle", + cellMode: "cell" }, //pass in fillGeometry @@ -24,7 +25,7 @@ Lattice = Backbone.Model.extend({ addCell: function(position){ var cells = this.get("cells"); - cells.push(new Cell(position)); + cells.push(new Cell(this.get("cellMode"), position)); this.set("numCells", cells.length); window.three.render(); },