From 3c6965164f87e07ee1b208a28dbe49bb92fee68c Mon Sep 17 00:00:00 2001
From: Amanda Ghassaei <amandaghassaei@gmail.com>
Date: Wed, 25 Mar 2015 20:18:05 -0400
Subject: [PATCH] fill is faster

---
 js/fea/DmaPart.js         | 12 ++++++------
 js/models/FillGeometry.js |  3 ++-
 js/models/Lattice.js      | 20 +++++++++++---------
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js
index b584774d..67aa1899 100644
--- a/js/fea/DmaPart.js
+++ b/js/fea/DmaPart.js
@@ -55,11 +55,11 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
     };
 
     DMAPart.prototype.highlight = function(){
-        this.mesh.material.color.setRGB(1,0,0);
+//        this.mesh.material.color.setRGB(1,0,0);
     };
 
     DMAPart.prototype.unhighlight = function(){
-        if (this.mesh) this.mesh.material.color.setRGB(0.9619657144369509, 0.6625466032079207, 0.20799727886007258);
+//        if (this.mesh) this.mesh.material.color.setRGB(0.9619657144369509, 0.6625466032079207, 0.20799727886007258);
     };
 
     DMAPart.prototype.removeFromCell = function(){//send message back to parent cell to destroy this
@@ -124,13 +124,13 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
         var mesh;
         switch(type){
             case 0:
-                mesh = new THREE.Mesh(unitPartGeo1, partMaterial.clone());
+                mesh = new THREE.Mesh(unitPartGeo1, partMaterial);
                 break;
             case 1:
-                mesh = new THREE.Mesh(unitPartGeo2, partMaterial.clone());
+                mesh = new THREE.Mesh(unitPartGeo2, partMaterial);
                 break;
             case 2:
-                 mesh = new THREE.Mesh(unitPartGeo3, partMaterial.clone());
+                 mesh = new THREE.Mesh(unitPartGeo3, partMaterial);
                 break;
         }
         mesh.myPart = this;//need a ref back to this part
@@ -170,7 +170,7 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE
     DMAEdgeVoxPart.prototype = Object.create(DMAPart.prototype);
 
     DMAEdgeVoxPart.prototype._makeMeshForType = function(){
-        var mesh = new THREE.Mesh(unitPartGeo, partMaterial.clone());
+        var mesh = new THREE.Mesh(unitPartGeo, partMaterial);
         mesh.myPart = this;//need a ref back to this part
         return mesh;
     };
diff --git a/js/models/FillGeometry.js b/js/models/FillGeometry.js
index b099cec4..fbe31dbb 100644
--- a/js/models/FillGeometry.js
+++ b/js/models/FillGeometry.js
@@ -53,8 +53,9 @@ FillGeometry = Backbone.Model.extend({
         var scale = dmaGlobals.lattice.get("scale");
 
         var minIndex = dmaGlobals.lattice.getIndexForPosition(bounds.min);
-        console.log(minIndex);
         var maxIndex = dmaGlobals.lattice.getIndexForPosition(bounds.max);
+        dmaGlobals.lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//expand cells matrix before
+
         var raycaster = new THREE.Raycaster();
         var direction = new THREE.Vector3(0,0,1);
         var mesh = this.get("mesh");
diff --git a/js/models/Lattice.js b/js/models/Lattice.js
index 5ea45c21..a1eb829e 100644
--- a/js/models/Lattice.js
+++ b/js/models/Lattice.js
@@ -52,7 +52,7 @@ Lattice = Backbone.Model.extend({
     addCellsInRange: function(range){//add a block of cells (extrude)
         var scale = this.get("scale");
         var cells = this.get("cells");
-        this._checkForMatrixExpansion(cells, range.max, range.min, "cellsMax", "cellsMin");
+        this.checkForMatrixExpansion(cells, range.max, range.min);
 
         var cellsMin = this.get("cellsMin");
         var relativeMin = this._subtract(range.min, cellsMin);
@@ -71,17 +71,17 @@ Lattice = Backbone.Model.extend({
         dmaGlobals.three.render();
     },
 
-    addCellAtIndex: function(indices, dontRender){
+    addCellAtIndex: function(indices, noRender, noCheck){
 
         var scale = this.get("scale");
         var cells = this.get("cells");
-        this._checkForMatrixExpansion(cells, indices, indices, "cellsMax", "cellsMin");
+        if (!noCheck) this.checkForMatrixExpansion(cells, indices, indices);
 
         var index = this._subtract(indices, this.get("cellsMin"));
         if (!cells[index.x][index.y][index.z]) {
             cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, scale);
             this.set("numCells", this.get("numCells")+1);
-            if (!dontRender) dmaGlobals.three.render();
+            if (!noRender) dmaGlobals.three.render();
         } else console.warn("already a cell there");
 
     },
@@ -198,19 +198,21 @@ Lattice = Backbone.Model.extend({
     ///////////////////////////////CELLS ARRAY//////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////
 
-    _checkForMatrixExpansion: function(cells, indicesMax, indicesMin, maxName, minName){
+    checkForMatrixExpansion: function(cells, indicesMax, indicesMin){
 
-        var lastMax = this.get(maxName);
-        var lastMin = this.get(minName);
+        if (!cells) cells = this.get("cells");
+
+        var lastMax = this.get("cellsMax");
+        var lastMin = this.get("cellsMin");
         var newMax = this._updateCellsMax(indicesMax, lastMax);
         var newMin = this._updateCellsMin(indicesMin, lastMin);
         if (newMax) {
             this._expandCellsArray(cells, this._subtract(newMax, lastMax), false);
-            this.set(maxName, newMax);
+            this.set("cellsMax", newMax);
         }
         if (newMin) {
             this._expandCellsArray(cells, this._subtract(lastMin, newMin), true);
-            this.set(minName, newMin);
+            this.set("cellsMin", newMin);
         }
     },
 
-- 
GitLab