From 14c7f9b7456a600f283ac41cb96febc0d19d9486 Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Tue, 2 Jun 2015 18:09:03 -0700
Subject: [PATCH] lattice in require

---
 js/lattice/GIKLattice.js              |  10 ++-
 js/lattice/KelvinLattice.js           |  90 ++++++++++---------
 js/lattice/OctaEdgeLattice.js         | 121 ++++++++++++++------------
 js/lattice/OctaFaceLattice.js         | 108 ++++++++++++-----------
 js/lattice/OctaFreeFormFaceLattice.js | 120 +++++++++++++------------
 js/lattice/OctaRotEdgeLattice.js      | 112 +++++++++++++-----------
 js/lattice/OctaVertexLattice.js       | 106 +++++++++++-----------
 js/lattice/TruncatedCubeLattice.js    |  91 ++++++++++---------
 js/main.js                            |   8 ++
 9 files changed, 416 insertions(+), 350 deletions(-)

diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js
index 0e92a52b..a8bf98df 100644
--- a/js/lattice/GIKLattice.js
+++ b/js/lattice/GIKLattice.js
@@ -9,9 +9,13 @@ define(['lattice', 'globals'], function(lattice, globals){
         GIKLattice: {
 
             _initLatticeType: function(){
-                globals.basePlane = new SquareBasePlane();
-                globals.highlighter = new GIKHighlighter();
-                globals.highlighter.updateGikLength();
+                require(['squareBaseplane'], function(SquareBasePlane){
+                    globals.basePlane = new SquareBasePlane();
+                });
+                require(['gikHighlighter'], function(GIKHighlighter){
+                    globals.highlighter = new GIKHighlighter();
+                    globals.highlighter.updateGikLength();
+                });
             },
 
             getIndexForPosition: function(absPosition){
diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js
index fedacfd3..7a872cbe 100644
--- a/js/lattice/KelvinLattice.js
+++ b/js/lattice/KelvinLattice.js
@@ -3,45 +3,53 @@
  */
 
 
-latticeSubclasses = latticeSubclasses || {};
-
-latticeSubclasses["KelvinLattice"] = {
-
-        _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane();
-            globals.highlighter = new TruncatedCubeHighlighter();
-        },
-
-        getIndexForPosition: function(absPosition){
-            return this._indexForPosition(absPosition);
-        },
-
-        getPositionForIndex: function(index){
-            return this._positionForIndex(index);
-        },
-
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return 2*Math.sqrt(2)+2*cellSeparation;
-        },
-
-        yScale: function(cellSeparation){
-            return this.xScale(cellSeparation);
-        },
-
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
-            return 2*Math.sqrt(2)+2*cellSeparation;
-        },
-
-        makeCellForLatticeType: function(indices){
-            return new KelvinCell(indices);
-        },
-
-        _undo: function(){//remove all the mixins, this will help with debugging later
-            var self = this;
-            _.each(_.keys(this.KelvinLattice), function(key){
-                self[key] = null;
-            });
+define(['lattice', 'globals'], function(lattice, globals){
+
+    _.extend(lattice, {
+
+        KelvinLattice: {
+
+            _initLatticeType: function(){
+                require(['squareBaseplane'], function(SquareBasePlane){
+                    globals.basePlane = new SquareBasePlane();
+                });
+                require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){
+                    globals.highlighter = new TruncatedCubeHighlighter();
+                });
+            },
+
+            getIndexForPosition: function(absPosition){
+                return this._indexForPosition(absPosition);
+            },
+
+            getPositionForIndex: function(index){
+                return this._positionForIndex(index);
+            },
+
+            xScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
+                return 2*Math.sqrt(2)+2*cellSeparation;
+            },
+
+            yScale: function(cellSeparation){
+                return this.xScale(cellSeparation);
+            },
+
+            zScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
+                return 2*Math.sqrt(2)+2*cellSeparation;
+            },
+
+            makeCellForLatticeType: function(indices){
+                return new KelvinCell(indices);
+            },
+
+            _undo: function(){//remove all the mixins, this will help with debugging later
+                var self = this;
+                _.each(_.keys(this.KelvinLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
+    });
+});
diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js
index 803778c3..62b6a02e 100644
--- a/js/lattice/OctaEdgeLattice.js
+++ b/js/lattice/OctaEdgeLattice.js
@@ -2,72 +2,79 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
+define(['lattice', 'globals'], function(lattice, globals){
 
-latticeSubclasses["OctaEdgeLattice"] = {
+    _.extend(lattice, {
 
-        _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane();
-            globals.highlighter = new OctaEdgeHighlighter();
+        OctaEdgeLattice: {
 
-        },
+            _initLatticeType: function(){
+                require(['octaBaseplane'], function(OctaBasePlane){
+                    globals.basePlane = new OctaBasePlane();
+                });
+                require(['defaultHighlighter'], function(DefaultHighlighter){
+                    globals.highlighter = new DefaultHighlighter();
+                });
+            },
 
-        getIndexForPosition: function(absPosition){
-            //todo finish this
-            var yIndex = Math.floor(absPosition.y/this.yScale());
-            if (yIndex%2 != 0) absPosition.x += this.xScale()/2;
-            var yScale = 1/Math.sqrt(3);
-            var index = this._indexForPosition(absPosition);
-            if (index.z%3 == 1) {
-                absPosition.x -= this.xScale()/2;
-                absPosition.y += yScale/2;
-            } else if (index.z%3 == 2){
-                absPosition.y += yScale;
-            }
-            var index = this._indexForPosition(absPosition);
-            return index;
-        },
+            getIndexForPosition: function(absPosition){
+                //todo finish this
+                var yIndex = Math.floor(absPosition.y/this.yScale());
+                if (yIndex%2 != 0) absPosition.x += this.xScale()/2;
+                var yScale = 1/Math.sqrt(3);
+                var index = this._indexForPosition(absPosition);
+                if (index.z%3 == 1) {
+                    absPosition.x -= this.xScale()/2;
+                    absPosition.y += yScale/2;
+                } else if (index.z%3 == 2){
+                    absPosition.y += yScale;
+                }
+                var index = this._indexForPosition(absPosition);
+                return index;
+            },
 
-        getPositionForIndex: function(index){
+            getPositionForIndex: function(index){
 
-            var position = _.clone(index);
-            var xScale = this.xScale();
-            var yScale = 1/Math.sqrt(3);
-            position.x = (position.x+1/2)*xScale;
-            position.y = position.y*this.yScale()+yScale/2;
-            position.z = (position.z+0.5)*this.zScale();
-            if (index.y%2 != 0) position.x -= this.xScale()/2;
-            if (index.z%3 == 1) {
-                position.x += this.xScale()/2;
-                position.y -= yScale/2;
-            } else if (index.z%3 == 2){
-                position.y -= yScale;
-            }
-            return position;
-        },
+                var position = _.clone(index);
+                var xScale = this.xScale();
+                var yScale = 1/Math.sqrt(3);
+                position.x = (position.x+1/2)*xScale;
+                position.y = position.y*this.yScale()+yScale/2;
+                position.z = (position.z+0.5)*this.zScale();
+                if (index.y%2 != 0) position.x -= this.xScale()/2;
+                if (index.z%3 == 1) {
+                    position.x += this.xScale()/2;
+                    position.y -= yScale/2;
+                } else if (index.z%3 == 2){
+                    position.y -= yScale;
+                }
+                return position;
+            },
 
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return 1+2*cellSeparation;
-        },
+            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);
-        },
+            yScale: function(cellSeparation){
+                return this.xScale(cellSeparation)/2*Math.sqrt(3);
+            },
 
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
-            return 2/Math.sqrt(6)+2*cellSeparation;
-        },
+            zScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
+                return 2/Math.sqrt(6)+2*cellSeparation;
+            },
 
-        makeCellForLatticeType: function(indices){
-            return new DMAEdgeOctaCell(indices);
-        },
+            makeCellForLatticeType: function(indices){
+                return new DMAEdgeOctaCell(indices);
+            },
 
-        _undo: function(){//remove all the mixins, this will help with debugging later
-            var self = this;
-            _.each(_.keys(this.OctaEdgeLattice), function(key){
-                self[key] = null;
-            });
+            _undo: function(){//remove all the mixins, this will help with debugging later
+                var self = this;
+                _.each(_.keys(this.OctaEdgeLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
+    });
+});
diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js
index 38534915..1f256c4c 100644
--- a/js/lattice/OctaFaceLattice.js
+++ b/js/lattice/OctaFaceLattice.js
@@ -2,54 +2,62 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
-
-latticeSubclasses["OctaFaceLattice"] = {
-
-        _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane();
-            globals.highlighter = new OctaFaceHighlighter();
-        },
-
-        getIndexForPosition: function(absPosition){
-            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){
-            var position = _.clone(index);
-            position.x = (position.x+1/2);
-            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 -= this.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").z;
-            return 2/Math.sqrt(6)+2*cellSeparation;
-        },
-
-        makeCellForLatticeType: function(indices){
-            return new OctaFaceCell(indices);
-        },
-
-        _undo: function(){//remove all the mixins
-            var self = this;
-            _.each(_.keys(this.OctaFaceLattice), function(key){
-                self[key] = null;
-            });
+define(['lattice', 'globals'], function(lattice, globals){
+
+    _.extend(lattice, {
+
+        OctaFaceLattice: {
+
+            _initLatticeType: function(){
+                require(['octaBaseplane'], function(OctaBasePlane){
+                    globals.basePlane = new OctaBasePlane();
+                });
+                require(['defaultHighlighter'], function(DefaultHighlighter){
+                    globals.highlighter = new DefaultHighlighter();
+                });
+            },
+
+            getIndexForPosition: function(absPosition){
+                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){
+                var position = _.clone(index);
+                position.x = (position.x+1/2);
+                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 -= this.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").z;
+                return 2/Math.sqrt(6)+2*cellSeparation;
+            },
+
+            makeCellForLatticeType: function(indices){
+                return new OctaFaceCell(indices);
+            },
+
+            _undo: function(){//remove all the mixins
+                var self = this;
+                _.each(_.keys(this.OctaFaceLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
+    });
+});
diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js
index 1aa1d261..e2d6ab89 100644
--- a/js/lattice/OctaFreeFormFaceLattice.js
+++ b/js/lattice/OctaFreeFormFaceLattice.js
@@ -2,73 +2,79 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
+define(['lattice', 'globals'], function(lattice, globals){
 
-latticeSubclasses["OctaFreeFormFaceLattice"] = {
+    _.extend(lattice, {
 
-         _initLatticeType: function(){
-            globals.basePlane = new OctaBasePlane();
-            globals.highlighter = new OctaFreeFormHighlighter();
+        OctaFreeFormFaceLattice: {
 
-            this.set("freeformCellType", "octa");
+            _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();
+            },
 
-        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);
+            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);
-            }
-            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;
-        },
+            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;
-        },
+            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;
-        },
+            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);
-        },
+            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;
-        },
+            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(this.OctaFreeFormFaceLattice), function(key){
-                self[key] = null;
-            });
+            _undo: function(){//remove all the mixins
+                var self = this;
+                this.set("freeformCellType", null);//todo get rid of this property
+                this.clearCells();
+                _.each(_.keys(this.OctaFreeFormFaceLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
\ No newline at end of file
+    });
+});
\ No newline at end of file
diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js
index c1190f11..03fb6340 100644
--- a/js/lattice/OctaRotEdgeLattice.js
+++ b/js/lattice/OctaRotEdgeLattice.js
@@ -2,57 +2,65 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
-
-latticeSubclasses["OctaRotEdgeLattice"] = {
-
-        _initLatticeType: function(){
-            globals.basePlane = new RotEdgeOctaBasePlane();
-            globals.highlighter = new OctaVertexHighlighter();
-        },
-
-        getIndexForPosition: function(absPosition){
-            var position = {};
-            position.x = Math.floor(absPosition.x/this.xScale()+0.5);
-            position.y = Math.floor(absPosition.y/this.yScale()+0.5);
-            position.z = Math.floor(absPosition.z/this.zScale()+0.5);
-            return position;
-        },
-
-        getPositionForIndex: function(index){
-            var position = _.clone(index);
-            if (index.z %2 != 0){
-                position.x += 0.5;
-                position.y += 0.5;
+define(['lattice', 'globals'], function(lattice, globals){
+
+    _.extend(lattice, {
+
+        OctaRotEdgeLattice: {
+
+            _initLatticeType: function(){
+                require(['rotEdgeOctaBasePlane'], function(RotEdgeOctaBasePlane){
+                    globals.basePlane = new RotEdgeOctaBasePlane();
+                });
+                require(['defaultHighlighter'], function(DefaultHighlighter){
+                    globals.highlighter = new DefaultHighlighter();
+                });
+            },
+
+            getIndexForPosition: function(absPosition){
+                var position = {};
+                position.x = Math.floor(absPosition.x/this.xScale()+0.5);
+                position.y = Math.floor(absPosition.y/this.yScale()+0.5);
+                position.z = Math.floor(absPosition.z/this.zScale()+0.5);
+                return position;
+            },
+
+            getPositionForIndex: function(index){
+                var position = _.clone(index);
+                if (index.z %2 != 0){
+                    position.x += 0.5;
+                    position.y += 0.5;
+                }
+                position.x = (position.x)*this.xScale();
+                position.y = (position.y)*this.yScale();
+                position.z = (position.z+1)*this.zScale();
+                return position;
+            },
+
+            xScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
+                return 1 + 2*cellSeparation;
+            },
+
+            yScale: function(cellSeparation){
+                return this.xScale(cellSeparation);
+            },
+
+            zScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
+                return Math.sqrt(2)/2 + 2*cellSeparation;
+            },
+
+            makeCellForLatticeType: function(indices){
+                return new OctaRotEdgeCell(indices);
+            },
+
+            _undo: function(){//remove all the mixins
+                var self = this;
+                _.each(_.keys(this.OctaRotEdgeLattice), function(key){
+                    self[key] = null;
+                });
             }
-            position.x = (position.x)*this.xScale();
-            position.y = (position.y)*this.yScale();
-            position.z = (position.z+1)*this.zScale();
-            return position;
-        },
-
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return 1 + 2*cellSeparation;
-        },
-
-        yScale: function(cellSeparation){
-            return this.xScale(cellSeparation);
-        },
-
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
-            return Math.sqrt(2)/2 + 2*cellSeparation;
-        },
-
-        makeCellForLatticeType: function(indices){
-            return new OctaRotEdgeCell(indices);
-        },
-
-        _undo: function(){//remove all the mixins
-            var self = this;
-            _.each(_.keys(this.OctaRotEdgeLattice), function(key){
-                self[key] = null;
-            });
         }
-    }
+    });
+});
diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js
index b61c207e..628aa0e5 100644
--- a/js/lattice/OctaVertexLattice.js
+++ b/js/lattice/OctaVertexLattice.js
@@ -2,53 +2,61 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
-
-latticeSubclasses["OctaVertexLattice"] = {
-
-        _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane();
-            globals.highlighter = new OctaVertexHighlighter();
-        },
-
-        getIndexForPosition: function(absPosition){
-            var position = {};
-            position.x = Math.floor(absPosition.x/this.xScale()+0.5);
-            position.y = Math.floor(absPosition.y/this.yScale()+0.5);
-            position.z = Math.floor(absPosition.z/this.zScale()+0.5);
-            return position;
-        },
-
-        getPositionForIndex: function(index){
-            var position = _.clone(index);
-            position.x = (position.x)*this.xScale();
-            position.y = (position.y)*this.yScale();
-            position.z = (position.z+0.5)*this.zScale();
-            return position;
-        },
-
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return Math.sqrt(2)+2*cellSeparation;
-        },
-
-        yScale: function(cellSeparation){
-            return this.xScale(cellSeparation);
-        },
-
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
-            return Math.sqrt(2)+2*cellSeparation;
-        },
-
-        makeCellForLatticeType: function(indices){
-            return new OctaVertexCell(indices);
-        },
-
-        _undo: function(){//remove all the mixins, this will help with debugging later
-            var self = this;
-            _.each(_.keys(this.OctaVertexLattice), function(key){
-                self[key] = null;
-            });
+define(['lattice', 'globals'], function(lattice, globals){
+
+    _.extend(lattice, {
+
+        OctaVertexLattice: {
+
+            _initLatticeType: function(){
+                require(['squareBaseplane'], function(SquareBasePlane){
+                    globals.basePlane = new SquareBasePlane();
+                });
+                require(['defaultHighlighter'], function(DefaultHighlighter){
+                    globals.highlighter = new DefaultHighlighter();
+                });
+            },
+
+            getIndexForPosition: function(absPosition){
+                var position = {};
+                position.x = Math.floor(absPosition.x/this.xScale()+0.5);
+                position.y = Math.floor(absPosition.y/this.yScale()+0.5);
+                position.z = Math.floor(absPosition.z/this.zScale()+0.5);
+                return position;
+            },
+
+            getPositionForIndex: function(index){
+                var position = _.clone(index);
+                position.x = (position.x)*this.xScale();
+                position.y = (position.y)*this.yScale();
+                position.z = (position.z+0.5)*this.zScale();
+                return position;
+            },
+
+            xScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
+                return Math.sqrt(2)+2*cellSeparation;
+            },
+
+            yScale: function(cellSeparation){
+                return this.xScale(cellSeparation);
+            },
+
+            zScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
+                return Math.sqrt(2)+2*cellSeparation;
+            },
+
+            makeCellForLatticeType: function(indices){
+                return new OctaVertexCell(indices);
+            },
+
+            _undo: function(){//remove all the mixins, this will help with debugging later
+                var self = this;
+                _.each(_.keys(this.OctaVertexLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
+    });
+});
diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js
index 57006216..798a82ca 100644
--- a/js/lattice/TruncatedCubeLattice.js
+++ b/js/lattice/TruncatedCubeLattice.js
@@ -2,45 +2,54 @@
  * Created by aghassaei on 5/26/15.
  */
 
-latticeSubclasses = latticeSubclasses || {};
-
-latticeSubclasses["TruncatedCubeLattice"] = {
-
-        _initLatticeType: function(){
-            globals.basePlane = new SquareBasePlane();
-            globals.highlighter = new TruncatedCubeHighlighter();
-        },
-
-        getIndexForPosition: function(absPosition){
-            return this._indexForPosition(absPosition);
-        },
-
-        getPositionForIndex: function(index){
-            return this._positionForIndex(index);
-        },
-
-        xScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
-            return Math.sqrt(2)+2*cellSeparation;
-        },
-
-        yScale: function(cellSeparation){
-            return this.xScale(cellSeparation);
-        },
-
-        zScale: function(cellSeparation){
-            if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
-            return Math.sqrt(2)+2*cellSeparation;
-        },
-
-        makeCellForLatticeType: function(indices){
-            return new TruncatedCubeCell(indices);
-        },
-
-        _undo: function(){//remove all the mixins, this will help with debugging later
-            var self = this;
-            _.each(_.keys(this.TruncatedCubeLattice), function(key){
-                self[key] = null;
-            });
+
+define(['lattice', 'globals'], function(lattice, globals){
+
+    _.extend(lattice, {
+
+        TruncatedCubeLattice: {
+
+            _initLatticeType: function(){
+                require(['squareBaseplane'], function(SquareBasePlane){
+                    globals.basePlane = new SquareBasePlane();
+                });
+                require(['truncatedCubeHighlighter'], function(TruncatedCubeHighlighter){
+                    globals.highlighter = new TruncatedCubeHighlighter();
+                });
+            },
+
+            getIndexForPosition: function(absPosition){
+                return this._indexForPosition(absPosition);
+            },
+
+            getPositionForIndex: function(index){
+                return this._positionForIndex(index);
+            },
+
+            xScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").xy;
+                return Math.sqrt(2)+2*cellSeparation;
+            },
+
+            yScale: function(cellSeparation){
+                return this.xScale(cellSeparation);
+            },
+
+            zScale: function(cellSeparation){
+                if (cellSeparation === undefined) cellSeparation = this.get("cellSeparation").z;
+                return Math.sqrt(2)+2*cellSeparation;
+            },
+
+            makeCellForLatticeType: function(indices){
+                return new TruncatedCubeCell(indices);
+            },
+
+            _undo: function(){//remove all the mixins, this will help with debugging later
+                var self = this;
+                _.each(_.keys(this.TruncatedCubeLattice), function(key){
+                    self[key] = null;
+                });
+            }
         }
-    }
+    });
+});
diff --git a/js/main.js b/js/main.js
index 7dc4bf8b..4516b059 100644
--- a/js/main.js
+++ b/js/main.js
@@ -32,6 +32,14 @@ require.config({
         octaBaseplane: 'baseplane/OctaBasePlane',
         rotEdgeOctaBaseplane: 'baseplane/RotEdgeOctaBasePlane',
 
+        //highlighter
+        highlighter: 'highlighter/Highlighter',
+        defaultHighlighter: 'highlighter/DefaultHighlighter',
+        cubeHighlighter: 'highlighter/CubeHighlighter',
+        gikHighlighter: 'highlighter/GIKHighlighter',
+        octaFaceHighlighter: 'highlighter/OctaFaceHighlighter',
+        truncatedCubeHighlighter: 'highlighter/TruncatedCubeHighlighter',
+
         //UI
         navbar: 'menus/Navbar',
         navViewMenu: 'menus/NavViewMenu',//view dropdown
-- 
GitLab