From 5a38cda60cfc686041ba051915c1a2a6c95b592f Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 25 Feb 2015 11:46:50 -0500 Subject: [PATCH] preserve cells toggle --- js/fea/DmaCell.js | 24 ++++++------------------ js/menus/LatticeMenuView.js | 13 +++++++++++-- js/models/Lattice.js | 1 + 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index d5553f2c..314f156e 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -143,17 +143,6 @@ DMACell.prototype.destroy = function(){ 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); position.z += dmaGlobals.lattice.zScale()/2; return {index: _.clone(this.indices), direction:direction, position:position}; @@ -209,7 +198,8 @@ DMACell.prototype.destroy = function(){ var unitCellGeo = new THREE.BoxGeometry(1,1,1); - var cellMaterial = new THREE.MeshNormalMaterial(); + var cellMaterials = [new THREE.MeshNormalMaterial(), + new THREE.MeshBasicMaterial({color:0x000000, wireframe:true})]; function DMACubeCell(mode, indices, scale, lattice){ @@ -225,11 +215,11 @@ DMACell.prototype.destroy = function(){ return parts; }; - DMACubeCell.prototype._buildCellMesh = function(zIndex){//abstract mesh representation of cell - var mesh = new THREE.Mesh(unitCellGeo, cellMaterial); + DMACubeCell.prototype._buildCellMesh = function(){//abstract mesh representation of cell + var mesh = new THREE.SceneUtils.createMultiMaterialObject(unitCellGeo, cellMaterials); mesh.myParent = this;//we need a reference to this instance from the mesh for intersection selection stuff - var wireframe = new THREE.BoxHelper(mesh); - wireframe.material.color.set(0x000000); +// var wireframe = new THREE.BoxHelper(mesh); +// wireframe.material.color.set(0x000000); // mesh.add(wireframe); return mesh; }; @@ -237,8 +227,6 @@ DMACell.prototype.destroy = function(){ DMACubeCell.prototype.calcHighlighterPosition = function(face){ var direction = face.normal; -// if (direction.z<0.99) direction = null;//only highlight horizontal faces - var position = dmaGlobals.lattice.getPositionForIndex(this.indices); var scale = dmaGlobals.lattice.xScale(); _.each(_.keys(position), function(key){ diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 47cefba1..63d805c1 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -13,7 +13,8 @@ LatticeMenuView = Backbone.View.extend({ "click .cellType": "_changeCellType", "click .connectionType": "_changeConnectionType", "slide #scaleSlider": "_sliderDidSlide", - "slideStop #scaleSlider": "_changeScaleSlider" + "slideStop #scaleSlider": "_changeScaleSlider", + "change #preserveCells": "_changePreserveCells" }, @@ -23,7 +24,7 @@ LatticeMenuView = Backbone.View.extend({ _.bindAll(this, "render"); this.listenTo(this.model, "change", this.render); - this.listenTo(this.lattice, "change:numCells", this.render) + this.listenTo(this.lattice, "change", this.render) }, _clearCells: function(e){ @@ -96,6 +97,10 @@ LatticeMenuView = Backbone.View.extend({ } }, + _changePreserveCells: function(e){ + this.lattice.set("shouldPreserveCells", $(e.target).prop("checked")); + }, + render: function(){ if (this.model.get("currentTab") != "lattice") return; this.$el.html(this.template(_.extend(this.model.attributes, this.lattice.attributes))); @@ -126,6 +131,10 @@ LatticeMenuView = Backbone.View.extend({ <% }); %>\ </ul>\ </div><br/><br/>\ + <label class="checkbox">\ + <input type="checkbox" <% if (shouldPreserveCells) { %> checked="checked" <% } %> value="" id="preserveCells" data-toggle="checkbox" class="custom-checkbox"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span>\ + Preserve cells on lattice change\ + </label>\ Scale: <input id="scaleSlider" data-slider-id="ex1Slider" type="text" data-slider-min="1" data-slider-max="100" data-slider-step="0.1" data-slider-value="<%= scale %>"/>\ <br/><input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control" type="text"><br/>\ Num Cells: <%= numCells %><br/>\ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 8de4e2fd..5ffd611e 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -325,6 +325,7 @@ Lattice = Backbone.Model.extend({ _.extend(this, this.CubeLattice); } this._initLatticeType(); + if (this.get("shouldPreserveCells")){ var self = this; var scale = this.get("scale"); -- GitLab