From f0e99b65d8ef9cc3895c3aafc9345534797afed6 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 3 Jun 2015 16:48:45 -0700
Subject: [PATCH] no freeform

---
 js/baseplane/OctaBasePlane.js         |   4 -
 js/cells/DMACellFreeform.js           | 177 --------------------------
 js/highlighter/Highlighter.js         |   5 -
 js/lattice/Lattice.js                 |  12 +-
 js/lattice/OctaFreeFormFaceLattice.js |  80 ------------
 js/main.js                            |   1 -
 js/menus/LatticeMenuView.js           |  11 --
 js/menus/PartMenuView.js              |   3 +-
 js/models/PList.js                    |   5 -
 9 files changed, 5 insertions(+), 293 deletions(-)
 delete mode 100644 js/cells/DMACellFreeform.js
 delete mode 100644 js/lattice/OctaFreeFormFaceLattice.js

diff --git a/js/baseplane/OctaBasePlane.js b/js/baseplane/OctaBasePlane.js
index 9bed1ab7..bc1ca132 100644
--- a/js/baseplane/OctaBasePlane.js
+++ b/js/baseplane/OctaBasePlane.js
@@ -38,10 +38,6 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three',
             return [new THREE.Mesh(geometry, this.get("material"))];
         },
 
-        getType: function(){//todo hack from freeform octa, get rid of this eventually
-            return "octa";
-        },
-
         _renderZIndexChange: function(){
             var zIndex = this.get("zIndex");
             var xScale = lattice.xScale();
diff --git a/js/cells/DMACellFreeform.js b/js/cells/DMACellFreeform.js
deleted file mode 100644
index 9b166f5a..00000000
--- a/js/cells/DMACellFreeform.js
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * Created by aghassaei on 4/14/15.
- */
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////FREEFORM SUPERCLASS////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-
-function DMAFreeFormCell(index, parentCellPos, parentCellQuat, direction, parentType){//no rigid lattice structure for cells
-    this.parentPos = parentCellPos;
-    this.parentQuaternion = parentCellQuat;
-    this.parentDirection = direction;
-    this.parentType = parentType;
-    DMACell.call(this, index);
-}
-DMAFreeFormCell.prototype = Object.create(DMACell.prototype);
-
-DMAFreeFormCell.prototype._calcPosition = function(){//todo this might not be necessary - put in lattice
-    var position = {};
-    var zScale = globals.lattice.zScale();
-    position.x = this.parentPos.x+this.parentDirection.x*zScale/2;
-    position.y = this.parentPos.y+this.parentDirection.y*zScale/2;
-    position.z = this.parentPos.z+this.parentDirection.z*zScale/2;
-    return position;
-};
-
-DMAFreeFormCell.prototype.calcHighlighterPosition = function(face){
-    //var direction = face.normal.clone().applyEuler(this.mesh.rotation);
-    var direction = face.normal.clone();
-    direction.applyQuaternion(this.mesh.quaternion);
-    var position = this.getPosition();
-    position.add(direction.clone().multiplyScalar(this.zScale()/2));
-    return {index: _.clone(this.index), direction:direction, position:position};
-};
-
-DMAFreeFormCell.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: this.getType()
-    });
-    return json;
-};
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////OCTA///////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-
-function DMAFreeFormOctaCell(index, parentCellPos, parentCellQuat, direction, parentType){
-    DMAFreeFormCell.call(this, index, parentCellPos, parentCellQuat, direction, parentType);
-}
-DMAFreeFormOctaCell.prototype = Object.create(DMAFreeFormCell.prototype);
-
-DMAFreeFormOctaCell.prototype._doMeshTransformations = function(mesh){
-
-    if (!this.parentDirection) {
-        this.parentDirection = new THREE.Vector3(0,0,1);
-        this.parentQuaternion = new THREE.Quaternion();
-        this.parentPos = new THREE.Vector3(0,0,0);
-    }
-    var direction = this.parentDirection.clone();
-    var zAxis = new THREE.Vector3(0,0,1);
-    zAxis.applyQuaternion(this.parentQuaternion);
-    var quaternion = new THREE.Quaternion().setFromUnitVectors(zAxis, direction);
-    console.log(quaternion.clone());
-    quaternion.multiply(this.parentQuaternion);
-
-    var zAlignment = direction.sub(zAxis).length();
-    if ((this.parentType == "octa" && zAlignment < 0.1) || this.parentType == "tetra"){
-        console.log("yes");
-        var zRot = new THREE.Quaternion().setFromAxisAngle(this.parentDirection, Math.PI);
-        zRot.multiply(quaternion);
-        quaternion = zRot;
-    }
-
-    mesh.quaternion.set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
-};
-
-DMAFreeFormOctaCell.prototype._initParts = function(){
-    var parts  = [];
-    parts.push(new DMAOctaTroxPart(1, this));
-    return parts;
-};
-
-DMAFreeFormOctaCell.prototype.getType = function(){
-    return "octa";
-};
-
-DMAFreeFormOctaCell.prototype._getGeometry = function(){
-    return unitFaceOctaGeo;
-};
-
-DMAFreeFormOctaCell.prototype.xScale = function(){
-    return 1;
-};
-
-DMAFreeFormOctaCell.prototype.yScale = function(){
-    return this.xScale()/2*Math.sqrt(3);
-};
-
-DMAFreeFormOctaCell.prototype.zScale = function(){
-    return 2/Math.sqrt(6);
-};
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////TETRA//////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-
-var unitCellGeo2 = new THREE.TetrahedronGeometry(Math.sqrt(3/8));
-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(index, parentCellPos, parentCellQuat, direction, parentType){
-    DMAFreeFormCell.call(this, index, parentCellPos, parentCellQuat, direction, parentType);
-}
-DMAFreeFormTetraCell.prototype = Object.create(DMAFreeFormCell.prototype);
-
-DMAFreeFormTetraCell.prototype._doMeshTransformations = function(mesh){
-    var direction = this.parentDirection.clone();
-    var zAxis = new THREE.Vector3(0,0,1);
-    zAxis.applyQuaternion(this.parentQuaternion);
-    var quaternion = new THREE.Quaternion().setFromUnitVectors(zAxis, direction);
-    quaternion.multiply(this.parentQuaternion);
-
-    var zComponent = direction.sub(zAxis).length();
-    console.log(zComponent);
-    console.log(new THREE.Euler().setFromQuaternion(quaternion));
-    if (zComponent >= 1){
-        console.log("yes");
-        console.log("");
-        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);
-};
-
-DMAFreeFormTetraCell.prototype.getType = function(){
-    return "tetra";
-};
-
-DMAFreeFormTetraCell.prototype._initParts = function(){
-    var parts  = [];
-    parts.push(new DMATetraTroxPart(1, this));
-    return parts;
-};
-
-DMAFreeFormTetraCell.prototype.xScale = function(){
-    return 1;
-};
-
-DMAFreeFormTetraCell.prototype.yScale = function(){
-    return this.xScale()/2*Math.sqrt(3);
-};
-
-DMAFreeFormTetraCell.prototype.zScale = function(){
-    return 2/Math.sqrt(24);
-};
-
-DMAFreeFormTetraCell.prototype._getGeometry = function(){
-    return unitCellGeo2;
-};
-
diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js
index 411dbcb3..839d77a4 100644
--- a/js/highlighter/Highlighter.js
+++ b/js/highlighter/Highlighter.js
@@ -132,11 +132,6 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', '
         addRemoveVoxel: function(shouldAdd){
             if (shouldAdd){
                 if (!this.isVisible() || !this.highlightedObject) return;
-                if (lattice.get("connectionType") == "freeformFace"){
-                    //todo make this work for baseplane
-                    lattice.addFreeFormCell(this.mesh.position.clone(), this.highlightedObject.getOrientation(), this.direction, this.highlightedObject.getType());
-                    return;
-                }
                 lattice.addCellAtIndex(this._getNextCellPosition());
             } else {
                 if (!this.highlightedObject) return;
diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js
index b17a97d6..569f79e4 100644
--- a/js/lattice/Lattice.js
+++ b/js/lattice/Lattice.js
@@ -374,18 +374,18 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
 
         _updateLatticeType: function(loadingFromFile){//do not clear cells if loading from file (cells array contains important metadata)
 
-            if (this.previous("connectionType") == "gik") this.clearCells();
-
             this._setToDefaultsSilently();
             this._setDefaultCellMode();
 
             if (loadingFromFile === undefined) loadingFromFile = false;
+            if (loadingFromFile) console.warn('loading from file');
+            this.clearCells();
 
             if (this._undo) this._undo();
             if (globals.basePlane) globals.basePlane.destroy();
             if (globals.highlighter) globals.highlighter.destroy();
 
-            var subclass = this._getSubclassForLatticeType(loadingFromFile);
+            var subclass = this._getSubclassForLatticeType();
             var self = this;
             require([subclass], function(subclassObject){
 
@@ -404,15 +404,12 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
             });
         },
 
-        _getSubclassForLatticeType: function(loadingFromFile){
+        _getSubclassForLatticeType: function(){
             var cellType = this.get("cellType");
             var connectionType = this.get("connectionType");
             if (cellType == "octa"){
                 if (connectionType == "face"){
                     return "octaFaceLattice";
-                } else if (connectionType == "freeformFace"){
-                    if (!loadingFromFile) this.clearCells();
-                    return "octaFreeFormFaceLattice";
                 } else if (connectionType == "edge"){
                     return "octaEdgeLattice";
                 } else if (connectionType == "edgeRot"){
@@ -426,7 +423,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
                 if (connectionType == "face"){
                     return "cubeLattice";
                 } else if (connectionType == "gik"){
-                    if (!loadingFromFile) this.clearCells();
                     return "gikLattice";
                 }
             } else if (cellType == "truncatedCube"){
diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js
deleted file mode 100644
index dff105fe..00000000
--- a/js/lattice/OctaFreeFormFaceLattice.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * Created by aghassaei on 5/26/15.
- */
-
-define(['underscore', 'backbone', 'appState', 'lattice', 'globals', 'plist', 'three', 'threeModel'],
-    function(_, Backbone, appState, lattice, globals, plist, THREE, three){
-
-    var OctaFreeFormFaceLattice = {
-
-        _initLatticeType: function(){
-            require(['octaBaseplane'], function(OctaBasePlane){
-                globals.basePlane = new OctaBasePlane();
-            });
-            require(['defaultHighlighter'], function(DefaultHighlighter){
-                globals.highlighter = new DefaultHighlighter();
-            });
-            this.set("freeformCellType", "octa");
-        },
-
-        addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){
-            var cells = this.get("cells");
-            cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, parentCellPos, parentCellOrient, direction, parentType, type));
-            this.set("numCells", this.get("numCells")+1);
-            globals.three.render();
-        },
-
-        makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){
-            if (type){
-                if (type == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType);
-                return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType);
-            }
-            if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType);
-            return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType);
-        },
-
-        getIndexForPosition: function(absPosition){//only used by baseplane
-            var yIndex = Math.floor(absPosition.y/this.yScale());
-            if (yIndex%2 != 0) absPosition.x += this.xScale()/2;
-            var index = this._indexForPosition(absPosition);
-            if (index.z%2 == 1) index.y += 1;
-            return index;
-        },
-
-        getPositionForIndex: function(index){//only used by baseplane
-            var position = _.clone(index);
-            var xScale = this.xScale();
-            position.x = (position.x+1/2)*xScale;
-            position.y = position.y*this.yScale()+1/Math.sqrt(3)/2;
-            position.z = (position.z+0.5)*this.zScale();
-            if ((index.y%2) != 0) position.x -= xScale/2;
-            return position;
-        },
-
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return 1+2*cellSeparation;
-        },
-
-        yScale: function(cellSeparation){
-            return this.xScale(cellSeparation)/2*Math.sqrt(3);
-        },
-
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;//todo xy?
-            if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*cellSeparation;
-            return 2/Math.sqrt(24)+2*cellSeparation;
-        },
-
-        _undo: function(){//remove all the mixins
-            var self = this;
-            this.set("freeformCellType", null);//todo get rid of this property
-            this.clearCells();
-            _.each(_.keys(OctaFreeFormFaceLattice), function(key){
-                self[key] = null;
-            });
-        }
-    };
-
-    return OctaFreeFormFaceLattice;
-});
\ No newline at end of file
diff --git a/js/main.js b/js/main.js
index 1182e50b..308ea673 100644
--- a/js/main.js
+++ b/js/main.js
@@ -32,7 +32,6 @@ require.config({
         kelvinLattice: 'lattice/KelvinLattice',
         octaEdgeLattice: 'lattice/OctaEdgeLattice',
         octaFaceLattice: 'lattice/OctaFaceLattice',
-        octaFreeFormFaceLattice: 'lattice/OctaFreeFormFaceLattice',
         octaRotEdgeLattice: 'lattice/OctaRotEdgeLattice',
         octavertexLattice: 'lattice/OctaVertexLattice',
         truncatedCubeLattice: 'lattice/TruncatedCubeLattice',
diff --git a/js/menus/LatticeMenuView.js b/js/menus/LatticeMenuView.js
index 42b00e67..1d75d2af 100644
--- a/js/menus/LatticeMenuView.js
+++ b/js/menus/LatticeMenuView.js
@@ -37,17 +37,6 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _
                         <% }); %>\
                     </ul>\
                 </div><br/><br/>\
-            <% if (connectionType == "freeformFace") { %>\
-            Current Draw Shape:&nbsp;&nbsp;\
-                <div class="btn-group">\
-                    <button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= freeformCellType %><span class="caret"></span></button>\
-                    <ul role="menu" class="dropdown-menu">\
-                        <li><a class="lattice dropdownSelector" data-property="freeformCellType" data-value="octa" href="#">octa</a></li>\
-                        <li><a class="lattice dropdownSelector" data-property="freeformCellType" data-value="tetra" href="#">tetra</a></li>\
-                    </ul>\
-                </div>\
-                <br/><br/>\
-            <% } %>\
             <% if (connectionType == "gik") { %>\
             GIK Length:&nbsp;&nbsp;<input data-property="superCellRange" data-key="x" value="<%= superCellRange.x %>" placeholder="GIK length" class="form-control intInput lattice" type="text"><br/>\
             <br/>\
diff --git a/js/menus/PartMenuView.js b/js/menus/PartMenuView.js
index ddf94a70..9852a657 100644
--- a/js/menus/PartMenuView.js
+++ b/js/menus/PartMenuView.js
@@ -29,9 +29,8 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _
                         <% }); %>\
                     </ul>\
                 </div><br/><br/>\
-            <!--Cell Separation <% if (connectionType != "freeformFace"){ %>(xy, z): &nbsp;&nbsp;<input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\
+            <!--Cell Separation (xy, z): &nbsp;&nbsp;<input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text">\
             &nbsp;<input data-property="cellSeparation" data-key="z" value="<%= cellSeparation.z %>" placeholder="Z" class="form-control floatInput lattice" type="text">\
-            <% } else { %>( radial ): &nbsp;&nbsp;<input data-property="cellSeparation" data-key="xy" value="<%= cellSeparation.xy %>" placeholder="XY" class="form-control floatInput lattice" type="text"><% } %>\
             <br/><br/>--><br/>\
             <% if (allMaterialTypes[cellType][connectionType]){ %> \
             Materials:<br/>\
diff --git a/js/models/PList.js b/js/models/PList.js
index b1997334..071f2fee 100644
--- a/js/models/PList.js
+++ b/js/models/PList.js
@@ -46,9 +46,6 @@ define(['three'], function(THREE){
                 face: {
                     triangle:"Triangle"
                 },
-                freeformFace: {
-                    trox:"Troxes"
-                },
                 edge: null,
                     edgeRot: {
                     vox: "Snap Voxel (high res)",
@@ -78,7 +75,6 @@ define(['three'], function(THREE){
         allMaterialTypes:{
             octa:{
                 face: null,
-                    freeformFace: null,
                     edge: null,
                     edgeRot: null,
                     vertex: null
@@ -134,7 +130,6 @@ define(['three'], function(THREE){
         allMachineTypes:{
             octa:{
                 face: {handOfGod: "Hand of God"},
-                freeformFace: {handOfGod: "Hand of God"},
                 edgeRot: {
                     shopbot: "Shopbot",
                         oneBitBot: "One Bit Bot",
-- 
GitLab