diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js index 2b5576b453d81692900688145e891bb553875848..3b5ba2eb1984a69973845cadeb362b315c06a0d0 100644 --- a/js/menus/LatticeMenuView.js +++ b/js/menus/LatticeMenuView.js @@ -16,7 +16,7 @@ LatticeMenuView = Backbone.View.extend({ "slide #scaleSlider": "_sliderDidSlide", "slideStop #scaleSlider": "_changeScaleSlider", "click #freeformTetraCell": "_setTetraCell", - "click #freeformOctaCell": "_setOctaCell", + "click #freeformOctaCell": "_setOctaCell" }, @@ -56,7 +56,7 @@ LatticeMenuView = Backbone.View.extend({ e.preventDefault(); var newVal = parseInt($(e.target).val()); if (isNaN(newVal)) return; - dmaGlobals.lattice.set("microGikLength", newVal); + dmaGlobals.lattice.set("gikLength", newVal); }, _clearCells: function(e){ @@ -169,8 +169,8 @@ LatticeMenuView = Backbone.View.extend({ </div>\ <br/><br/>\ <% } %>\ - <% if (connectionType == "microGik") { %>\ - GIK Length: <input id="gikLength" value="<%= microGikLength %>" placeholder="GIK length" class="form-control numberInput" type="text"><br/>\ + <% if (connectionType == "gik") { %>\ + GIK Length: <input id="gikLength" value="<%= gikLength %>" placeholder="GIK length" class="form-control numberInput" type="text"><br/>\ <% } %>\ <br/>\ Scale: <input id="latticeScale" value="<%= scale %>" placeholder="enter scale" class="form-control numberInput" type="text"><br/>\ diff --git a/js/models/AppState.js b/js/models/AppState.js index 014c449934e6688cbf73838cbda9b4afe696075b..2e85bd5ea2013a66b3653fe3dc02325c093dec75 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -52,7 +52,7 @@ AppState = Backbone.Model.extend({ allConnectionTypes: { octa: {face:"Face", freeformFace:"Freeform Face", edgeRot:"Edge", vertex:"Vertex"},//edge:"Edge", tetra: {vertex: "Vertex"}, - cube: {face:"Face", microGik: "GIK"}, + cube: {face:"Face", gik: "GIK"}, truncatedCube: {face:"Face"}, kelvin: {face: "Face"} }, @@ -288,7 +288,7 @@ AppState = Backbone.Model.extend({ case 55: case 56: case 57: - if (state) dmaGlobals.lattice.set("microGikLength", e.keyCode-48); + if (state) dmaGlobals.lattice.set("gikLength", e.keyCode-48); break; default: break; diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 61dadc32c395e87b0d2ccfb90874a3aa129246e8..6a76406029810992455c8cf7437230ee1d7165e8 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -22,10 +22,10 @@ Lattice = Backbone.Model.extend({ //spacing for connectors/joints cellSeparation: {xy:0, z:0}, - cellType: "octa", - connectionType: "face", + cellType: "cube", + connectionType: "gik", partType: "triangle", - microGikLength: 4 + gikLength: 4 }, //pass in fillGeometry @@ -440,7 +440,11 @@ Lattice = Backbone.Model.extend({ } else if (cellType == "tetra"){ _.extend(this, this.CubeLattice); } else if (cellType == "cube"){ - _.extend(this, this.CubeLattice); + if (connectionType == "face"){ + _.extend(this, this.CubeLattice); + } else if (connectionType == "gik"){ + _.extend(this, this.GIKLattice); + } } else if (cellType == "truncatedCube"){ _.extend(this, this.TruncatedCubeLattice); } else if (cellType == "kelvin"){ diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index 1121308144700fe52ec87866dc51f8ddd812723d..fd8610f2239cb065aa8dcec1d8b739b16a2144d3 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -50,6 +50,52 @@ OtherLatticeSubclasses = { } }, +//////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////GIK LATTICE////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////// + + GIKLattice: { + + _initLatticeType: function(){ + this.set("basePlane", new SquareBasePlane({scale:this.get("scale")})); + this.set("highlighter", new GIKHighlighter({scale:this.get("scale")})); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(scale){ + if (!scale) scale = this.get("scale"); + return scale*(1+2*this.get("cellSeparation").xy); + }, + + yScale: function(scale){ + return this.xScale(scale); + }, + + zScale: function(scale){ + if (!scale) scale = this.get("scale"); + return scale*(1+2*this.get("cellSeparation").z); + }, + + makeCellForLatticeType: function(indices, scale){ + return new DMACubeCell(indices, scale); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.GIKLattice), function(key){ + self[key] = null; + }); + } + }, + + //////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////TRUNCATED CUBE LATTICE//////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/threeViews/Highlighter.js b/js/threeViews/Highlighter.js index 736534a690a7c7284fb9ffc7fd99d553e8f3c70f..2f448669733d4772e9cf23d9ac02432fe339a083 100644 --- a/js/threeViews/Highlighter.js +++ b/js/threeViews/Highlighter.js @@ -74,8 +74,8 @@ Highlighter = Backbone.View.extend({ return; } this.direction = highlightedPos.direction; - this._setPosition(highlightedPos.position);//position of center point - this._setRotation(this.direction); + this._setPosition(highlightedPos.position, this.direction);//position of center point + this._setRotation(this.direction, this.index); this.show(true); }, @@ -201,15 +201,43 @@ OctaFreeFormHighlighter = Highlighter.extend({ CubeHighlighter = Highlighter.extend({ _makeGeometry: function(){ - return new THREE.BoxGeometry(1,1,0.01);; + return new THREE.BoxGeometry(1,1,0.01); } }); +GIKHighlighter = Highlighter.extend({ + + updateScale: function(scale){ + this.mesh.scale.set(dmaGlobals.lattice.get("gikLength")*scale, scale, scale); + }, + + _makeGeometry: function(){ + return new THREE.BoxGeometry(1,1,1); + }, + + _setPosition: function(position, direction){ + var scale = this.mesh.scale.z/2; + this.mesh.position.set(position.x+scale*direction.x, position.y+scale*direction.y, position.z+scale*direction.z); + }, + + _setRotation: function(direction, index){ + if ((index.z%2 == 0 && Math.abs(direction.z) > 0.9) || (index.z%2 != 0 && Math.abs(direction.z) < 0.1)) { + this.mesh.rotation.set(0, 0, Math.PI/2); + this.mesh.translateX(-this.mesh.scale.x/2+this.mesh.scale.z/2); + } + else { + this.mesh.rotation.set(0, 0,0); + this.mesh.translateX(-this.mesh.scale.x/2+this.mesh.scale.z/2); + } + } +}); + + TruncatedCubeHighlighter = Highlighter.extend({ _makeGeometry: function(){ - return new THREE.BoxGeometry(1,1,0.01);; + return new THREE.BoxGeometry(1,1,0.01); }, _setRotation: function(direction){