diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js index a12dbb8c2c0f20755c9e61d7fae78fd62a3aee58..a5d587e9e91bf595f02ede7c2302ef528f11dbe3 100644 --- a/js/baseplane/BasePlane.js +++ b/js/baseplane/BasePlane.js @@ -29,7 +29,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], }); object3D.myParent = this; this.set("object3D", object3D); - three.sceneAdd(object3D, "basePlane"); + three.sceneAddBasePlane(object3D); three.render(); this._setVisibility(); }, @@ -51,7 +51,7 @@ define(['underscore', 'backbone', 'appState', 'lattice', 'threeModel', 'three'], _removeMesh: function(){ this.get("object3D").myParent = null; - three.sceneRemove(this.get("object3D"), "basePlane"); + three.sceneRemoveBasePlane(this.get("object3D")); three.render(); }, diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index a091d5573d5a934dfbffe9cacadb15edd2178b9a..46b20385f69f49e31e69f1f37f644dde2bb8284d 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -19,7 +19,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], this._addChildren(this._buildMesh(), this.object3D);//build cell meshes if (superCell === undefined) { - if (this.index) three.sceneAdd(this.object3D, this._getSceneName()); + if (this.index) three.sceneAdd(this.object3D); else this.hide();//stock cell } @@ -37,10 +37,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], return "object3D"; }; - DMACell.prototype._getSceneName = function(){ - return "cell"; - }; - DMACell.prototype.getObject3D = function(){//careful, used for stock sim and supercell only for now todo need this? return this.object3D; }; @@ -205,7 +201,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState'], DMACell.prototype.destroy = function(){ if (this.object3D) { if (this.superCell) this.object3D.parent.remove(this.object3D); - else if (this.index) three.sceneRemove(this.object3D, "cell"); + else if (this.index) three.sceneRemove(this.object3D); this.object3D.myParent = null; // this.object3D.dispose(); // geometry.dispose(); diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 1b9d13f5b85b27f7aa22bedd050ebcad4f3707ce..e3d7aee26d860c6ebc91af1e9e2aa07927a43f90 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -39,10 +39,6 @@ DMASuperCell.prototype._getModeName = function(){ return ""; }; -DMASuperCell.prototype._getSceneName = function(){ - return "supercell"; -}; - DMASuperCell.prototype.setMode = function(mode){ if (mode === undefined) mode = globals.appState.get("cellMode"); @@ -66,7 +62,7 @@ DMASuperCell.prototype.getLength = function(){ DMASuperCell.prototype.destroy = function(){ this.object3D.myParent = null; - globals.three.sceneRemove(this.object3D, this._getSceneName()); + globals.three.sceneRemove(this.object3D); this.object3D = null; _.each(this.cells, function(cell){ if (cell) cell.destroy(); diff --git a/js/fea/DmaBeam.js b/js/fea/DmaBeam.js index d054e2cd2e090fef980ae4d5c57f1485b49e4c4c..d84ca7561b8f58105f59473ca9cfc23cd3be6aea 100644 --- a/js/fea/DmaBeam.js +++ b/js/fea/DmaBeam.js @@ -58,7 +58,7 @@ DmaBeam.prototype.setVisibility = function(visible){ }; DmaBeam.prototype.destroy = function(){ - globals.three.sceneRemove(this.mesh, "part"); + globals.three.sceneRemove(this.mesh); this.mesh = null; var self = this; _.each(this.nodes, function(node){ diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index 839d77a4ae7d3fe4fca5cb012f02bd7edf876aad..a2a86e7536919b79a65433757fdfae61a7df213b 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -24,7 +24,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' // vertexColors:THREE.FaceColors })); - three.sceneAdd(this.mesh, "highlighter"); + three.sceneAdd(this.mesh); this.hide(); //bind events @@ -143,7 +143,7 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' destroy: function(){ this.setNothingHighlighted(); - three.sceneRemove(this.mesh, null); + three.sceneRemove(this.mesh); this.mesh = null; this.stopListening(); } diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index 569f79e420213dc59eed71cf07b21a8ed6e8686e..f2493b379014d554377a7cce60f33a5df5314d97 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -133,11 +133,11 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre three.render(); }, - //todo send clear all to three and destroy without sceneRemove to cell clearCells: function(){ this._iterCells(this.get("cells"), function(cell){ if (cell && cell.destroy) cell.destroy(); }); + three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here this.set("cells", [[[null]]]); this.set("cellsMax", {x:0, y:0, z:0}); this.set("cellsMin", {x:0, y:0, z:0}); diff --git a/js/three/FillGeometry.js b/js/three/FillGeometry.js index 976a33f127311a2c553bb33a886ad3327664ba86..7fdcc3ee3fbef61cd5403a1eb668bb4f92ccebd2 100644 --- a/js/three/FillGeometry.js +++ b/js/three/FillGeometry.js @@ -32,7 +32,7 @@ FillGeometry = Backbone.Model.extend({ side:THREE.DoubleSide})); this.makeBoundingBox(mesh); this.set({mesh: mesh}); - globals.three.sceneAdd(mesh, null); + globals.three.sceneAdd(mesh); globals.three.render(); }, diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js index 2911a844b4f0dac5778c8b51facd257ca42070ae..9af042f070fcad6f9182d603f4a05f3af47adea6 100644 --- a/js/three/ThreeModel.js +++ b/js/three/ThreeModel.js @@ -52,59 +52,38 @@ define(['underscore', 'three'], function(_, THREE){ render(); } - function sceneAdd(object, type){ - + function sceneAdd(object){ scene.add(object); + } - if (type == "cell"){ - cells.push(object.children[0]); - } else if (type == "supercell"){ - _.each(object.children, function(child){//add cells as hover - if (child.name != "object3D") return; - cells.push(child.children[0]); - }); - } else if (type == "part"){//todo change this -// parts.push(object); - } else if (type == "basePlane"){ - basePlane.push(object.children[0]); - } else if (type == "highlighter"){ - - } else { - console.warn("no recognized type " + type + " for"); -// console.log(object); - } + function sceneAddBasePlane(object){ + sceneAdd(object); + basePlane.push(object.children[0]); } - function sceneRemove(object, type){ - - if (type == "cell"){ - cells.splice(cells.indexOf(object.children[0]), 1); - } else if (type == "supercell"){ - _.each(object.children, function(child){//add cells as hover - if (child.name != "object3D") return; - cells.splice(cells.indexOf(child.children[0]), 1); - }); - } else if (type == "part"){ -// parts.splice(parts.indexOf(object), 1); - } else if (type == "basePlane"){ - basePlane.splice(0, basePlane.length);//delete array without removing reference - } else { -// console.warn("no recognized type " + type + " for"); -// console.log(object); - } + function getBasePlane(){ + return basePlane; + } + function addCell(cell){ + cells.push(cell); + } + + function getCells(){ + return cells; + } + + function sceneRemove(object){ scene.remove(object); } + function sceneRemoveBasePlane(object){ + sceneRemove(object); + basePlane = []; + } + function removeAllCells(){ - _.each(cells, function(cell){ - scene.remove(cell); - }); -// _.each(parts, function(part){ -// scene.remove(part); -// }); - cells.splice(0, cells.length); -// parts.splice(0, parts.length); + cells = []; } function startAnimationLoop(){ @@ -145,11 +124,13 @@ define(['underscore', 'three'], function(_, THREE){ stopAnimationLoop: stopAnimationLoop, sceneRemove: sceneRemove, sceneAdd: sceneAdd, + sceneAddBasePlane: sceneAddBasePlane, + sceneRemoveBasePlane: sceneRemoveBasePlane, domElement: renderer.domElement, camera: camera, - cells: cells, -// parts: parts, - basePlane: basePlane, + getCells: getCells, + addCell: addCell, + getBasePlane: getBasePlane, removeAllCells: removeAllCells }