Skip to content
Snippets Groups Projects
Commit bcb4019e authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

fixed clear all bug

parent 682c100d
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,8 @@
this.mesh.position.y = position.y;
this.mesh.position.z = position.z;
this.mesh.myCell = this;//we need a reference to this instance from the mesh for
this._draw();
// this.parts = this._createParts(nodes, config);
......@@ -60,6 +62,10 @@
Cell.prototype.rotate = function(rx, ry, rz){
};
Cell.prototype._destroy = function(){
this.mesh.myCell = null;
}
self.Cell = Cell;
......
......@@ -22,15 +22,21 @@ Lattice = Backbone.Model.extend({
},
addCell: function(position){
this.get("cells").push(new Cell(position));
this.set("numCells", this.get("numCells")+1);
var cells = this.get("cells");
cells.push(new Cell(position));
this.set("numCells", cells.length);
window.three.render();
},
removeCell: function(object){
var cells = this.get("cells");
cells.splice(cells.indexOf(object), 1);
this.set("numCells", this.get("numCells")-1);
var index = cells.indexOf(object.parent.myCell);
if (index == -1) {
console.warn("problem located cell in cell array");
return;
}
cells.splice(index, 1);
this.set("numCells", cells.length);
window.three.sceneRemove(object);
window.three.render();
},
......
......@@ -54,7 +54,7 @@ function ThreeModel(){
function sceneRemove(object){
var objectToRemove = object;
if (object.parent.type != "Scene") {
if (object.parent && object.parent.type != "Scene") {
objectToRemove = object.parent;
}
scene.remove(objectToRemove);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment