From 51485121a0e19fcffb3694004f69460e65bc730f Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Wed, 3 Jun 2015 17:09:49 -0700 Subject: [PATCH] three sceneAdd sceneRemove one arg --- js/baseplane/BasePlane.js | 4 +- js/cells/DMACell.js | 8 +-- js/cells/supercells/DMASuperCell.js | 6 +-- js/fea/DmaBeam.js | 2 +- js/highlighter/Highlighter.js | 4 +- js/lattice/Lattice.js | 2 +- js/three/FillGeometry.js | 2 +- js/three/ThreeModel.js | 75 +++++++++++------------------ 8 files changed, 38 insertions(+), 65 deletions(-) diff --git a/js/baseplane/BasePlane.js b/js/baseplane/BasePlane.js index a12dbb8c..a5d587e9 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 a091d557..46b20385 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 1b9d13f5..e3d7aee2 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 d054e2cd..d84ca756 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 839d77a4..a2a86e75 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 569f79e4..f2493b37 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 976a33f1..7fdcc3ee 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 2911a844..9af042f0 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 } -- GitLab