diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index ed033200e3f45a7e58b270385e15cb3763639498..812b88cddc4a9c1d8a8667c1f3c4a2bb2ea1711e 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -22,7 +22,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], if (this.superCell) this.superCell.addChildren(this.object3D);//add as child of supercell if (this.index){ - if (!this.cells) three.addCell(this.object3D.children[0]);//add mesh as highlightable object, only for lowest level of hierarchy + if (!this.cells) lattice.getUItarget().addHighlightableCell(this.object3D.children[0]);//add mesh as highlightable object, only for lowest level of hierarchy if (!superCell || superCell === undefined) three.sceneAdd(this.object3D);//add object3d as child of scene if top level of hierarchy } else this.hide();//stock cell @@ -329,7 +329,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], if (this.superCell) this.superCell.removeChildren(this.object3D); else if (this.index) { three.sceneRemove(this.object3D); - if (!this.cells) three.removeCell(this.object3D.children[0]);//remove mesh as highlightable object + if (!this.cells) lattice.getUItarget().removeHighlightableCell(this.object3D.children[0]);//remove mesh as highlightable object } this.object3D.myParent = null; // this.object3D.dispose(); diff --git a/js/highlighter/Highlighter.js b/js/highlighter/Highlighter.js index c9380d1025f047149f43df67c4b9da101ca9de4e..c6595e3355952ab162975195577ec022dda5a929 100644 --- a/js/highlighter/Highlighter.js +++ b/js/highlighter/Highlighter.js @@ -155,11 +155,11 @@ define(['underscore', 'backbone', 'threeModel', 'appState', 'lattice', 'cell', ' addRemoveVoxel: function(shouldAdd){ if (shouldAdd){ if (!this.isVisible() || !this.highlightedObject) return; - lattice.addCellAtIndex(this._getNextCellPosition()); + lattice.getUItarget().addCellAtIndex(this._getNextCellPosition()); } else { if (!this.highlightedObject) return; if (!(this.highlightedObject instanceof DMACell)) return; - lattice.removeCell(this.highlightedObject); + lattice.getUItarget().removeCell(this.highlightedObject); } this.setNothingHighlighted(); }, diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index c4bc280034f5bfc14807c9ee569c9ca93f19a8cf..d96236de6550ae6abc4e62980b0a786d7be67686 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -22,9 +22,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre __initialize: function(options, callback){ if (!options.id || options.id == "") this.set("id", this.cid); if (!options.color || options.color == "") this.set("color", makeRandomColor(), {silent:true}); - this.set("numCells", 3);//todo remove this - this.set("cellsMin", new THREE.Vector3(0,0,0)); - this.set("cellsMax", new THREE.Vector3(0,0,0)); if (callback) callback(this); }, @@ -47,6 +44,30 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }); }, + + + + + //3d ui + + addHighlightableCell: function(cell){ + three.addCompositeCell(cell); + }, + + removeHighlightableCell: function(cell){ + three.removeCompositeCell(cell); + }, + + getHighlightableCells: function(){ + return three.getCompositeCells(); + }, + + + + + + + _changeRandomColor: function(){ this.set("color", makeRandomColor()); }, @@ -63,7 +84,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre color: this.get("color"), altColor: this.get("color"), numCells: this.get("numCells"), - cells: JSON.parse(JSON.stringify(this.cells)), + cells: JSON.parse(JSON.stringify(this.sparseCells)), cellsMin: this.get("cellsMin").clone(), cellsMax: this.get("cellsMax").clone(), dimensions: new THREE.Vector3().subVectors(this.get("cellsMax"), this.get("cellsMin")) @@ -76,6 +97,18 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre delete globals.materials.compositeMaterials[id];//todo trigger change on all instances }, + + + + + + + //deallocate + + __clearCells: function(silent){ + three.removeAllCompositeCells();//todo add flag in cell destroy to avoid redundancy here + }, + destroy: function(){ this.clearCells(true); var self = this; diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index cbf054b177ea0c0274c9334468d9d886f382724c..341bcc7d625639a6101ea78d288bb5fae3acf15a 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -164,7 +164,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre _navChanged: function(){ var currentNav = appState.get("currentNav"); - if (!this.inCompositeMode() && this.exitCompositeEditing) this.exitCompositeEditing(); + if (currentNav != "navComposite" && this.compositeEditor && this.exitCompositeEditing) this.exitCompositeEditing(); }, _updateCellSeparation: function(){ @@ -180,6 +180,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, __clearCells: function(silent){ + three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here this.set("nodes", [], {silent:silent}); if (globals.basePlane) globals.basePlane.set("zIndex", 0, {silent:silent}); }, @@ -262,7 +263,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, inCompositeMode: function(){ - return appState.get("currentNav") == "navComposite"; + return appState.get("currentNav") == "navComposite" && this.compositeEditor; }, exitCompositeEditing: function(){ @@ -271,6 +272,23 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.showCells(); }, + getUItarget: function(){ + if (this.inCompositeMode()) return this.compositeEditor; + return this; + }, + + addHighlightableCell: function(cell){ + three.addCell(cell); + }, + + removeHighlightableCell: function(cell){ + three.removeCell(cell); + }, + + getHighlightableCells: function(){ + return three.getCells(); + }, + diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 9714f965a4c9cb5f82af33da84c9db181195e45d..8e7137d032e85bab5d966c617ab746b72be5ab02 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -121,7 +121,6 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this._loopCells(this.sparseCells, function(cell){//send destroy to top level if (cell) cell.destroy(); }); - three.removeAllCells();//todo add flag in cell destroy to avoid redundancy here this.cells = [[[null]]]; this.sparseCells = [[[null]]]; this.set("cellsMax", null, {silent:silent}); @@ -338,7 +337,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre //save/load toJSON: function(){//a minimal toJSON for ui stuff - no need to parse all cells - return _.omit(this.attributes, ["cells", "nodes"]);//omit makes a copy + return _.omit(this.attributes, ["nodes"]);//omit makes a copy }//todo something weird here }); diff --git a/js/main.js b/js/main.js index f26f8c4b0bb3adc275d41327a6e95368d22fc2cd..626b9c43685ca83a038ed19a8c10a3647acfcdf8 100644 --- a/js/main.js +++ b/js/main.js @@ -151,5 +151,5 @@ require(['appState', 'lattice', 'menuWrapper', 'navbar', 'ribbon', 'threeModel', new ThreeView({model:three}); -// if (lattice.get("connectionType") != "gik") lattice.addCellAtIndex({x:0,y:0,z:0});//add a cell +// if (lattice.get("connectionType") != "gik") lattice.getUItarget().addCellAtIndex({x:0,y:0,z:0});//add a cell }); diff --git a/js/menus/CompositeMenu.js b/js/menus/CompositeMenu.js index 71f49bd8209ed962c64df793ccb7b82ef607f6d8..9e51a21be81254aace0d283e524fd5e48edda3b5 100644 --- a/js/menus/CompositeMenu.js +++ b/js/menus/CompositeMenu.js @@ -83,6 +83,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ <a href="#" class="btn btn-halfWidth btn-lg btn-default importJSON">Load Composite</a>\ <a id="saveComposite" href="#" class="btn btn-halfWidth btn-lg pull-right btn-default">Save Composite</a><br/><br/>\ Name: <input id="compositeName" data-property="name" value="<%= name %>" placeholder="Enter Name" class="seventyFiveWidth form-control textInput compositeEditor" type="text"><br/><br/>\ + Num Cells: <%= numCells %><br/><br/>\ Bounding Box: ()<br/><br/>\ Display Color: \ <input id="compositeColor" style="border-color: <%= color %> ;" data-property="color" value="<%= color %>" placeholder="Enter HEX" class="halfWidth compositeEditor form-control hexInput" type="text"><br/><br/>\ diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index 341d6ce4d8de71c031c2fa2f98722f1e8a9865b2..221f2361818fdb31c0111b7a20e69bca488aac55 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -40,7 +40,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice'], function($, _ _buildWall: function(e){ e.preventDefault(); - lattice.addCellsInRange({min:{x:-5,y:-5,z:0}, max:{x:5,y:5,z:3}}); + lattice.getUItarget().addCellsInRange({min:{x:-5,y:-5,z:0}, max:{x:5,y:5,z:3}}); }, _readDataURL: function(event, numFiles, filename, files){ diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index ddbabef071ab9138aa68c18299c7a5766d9133f3..08f3a2d764f0156152dff233c6e0fb6a0e53115e 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -157,7 +157,7 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice'], function($, _, _clearCells: function(e){ e.preventDefault(); - lattice.clearCells(); + lattice.getUItarget().clearCells(); }, _getPropertyOwner: function($target){ diff --git a/js/models/FileSaver.js b/js/models/FileSaver.js index 79e275c4425dd1e4fb3a9f22a577428757b988f5..be441f13343914335ca6a3da4f688f7345ffcf9f 100644 --- a/js/models/FileSaver.js +++ b/js/models/FileSaver.js @@ -53,7 +53,7 @@ define(['underscore', 'fileSaverLib'], function(_, saveAs){ } function loadFile(data){//todo make this better - globals.lattice.clearCells(); + globals.lattice.getUItarget().clearCells(); _setData(data, false); globals.lattice._updateLatticeType(true); globals.lattice.trigger("change:scale"); diff --git a/js/three/FillGeometry.js b/js/three/FillGeometry.js index 7fdcc3ee3fbef61cd5403a1eb668bb4f92ccebd2..89a8cd0e2389c77a04dc127e13bd0b9be8529e99 100644 --- a/js/three/FillGeometry.js +++ b/js/three/FillGeometry.js @@ -78,11 +78,11 @@ FillGeometry = Backbone.Model.extend({ if (position.z<nextIntersection) continue; else { inside = true; - globals.lattice.addCellAtIndex(index, true, true); + globals.lattice.getUItarget().addCellAtIndex(index, true, true); } } else { if (position.z<nextIntersection) { - globals.lattice.addCellAtIndex(index, true, true); + globals.lattice.getUItarget().addCellAtIndex(index, true, true); continue; } else inside = false; diff --git a/js/three/ThreeModel.js b/js/three/ThreeModel.js index b24105d2e1139d017af122bd53b9fcf1e0f7a364..35a1d72fdd3641b44ad2ff49519d66aedc5fe84c 100644 --- a/js/three/ThreeModel.js +++ b/js/three/ThreeModel.js @@ -11,6 +11,7 @@ define(['underscore', 'three'], function(_, THREE){ //store all meshes to highlight var cells = []; + var compositeCells = []; // var parts = []; var basePlane = []; @@ -71,14 +72,26 @@ define(['underscore', 'three'], function(_, THREE){ cells.push(cell); } + function addCompositeCell(cell){ + compositeCells.push(cell); + } + function removeCell(cell){ cells.splice(cells.indexOf(cell), 1); } + function removeCompositeCell(cell){ + compositeCells.splice(compositeCells.indexOf(cell)); + } + function getCells(){ return cells; } + function getCompositeCells(){ + return compositeCells; + } + function sceneRemove(object){ scene.remove(object); } @@ -92,6 +105,10 @@ define(['underscore', 'three'], function(_, THREE){ cells = []; } + function removeAllCompositeCells(){ + compositeCells = []; + } + function startAnimationLoop(){ if (animationLoopRunning) return; stopAnimationFlag = false; @@ -146,10 +163,14 @@ define(['underscore', 'three'], function(_, THREE){ domElement: renderer.domElement, camera: camera, getCells: getCells, + getCompositeCells: getCompositeCells, addCell: addCell, + addCompositeCell: addCompositeCell, removeCell: removeCell, + removeCompositeCell: removeCompositeCell, getBasePlane: getBasePlane, - removeAllCells: removeAllCells + removeAllCells: removeAllCells, + removeAllCompositeCells: removeAllCompositeCells } }); \ No newline at end of file diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js index 517c2d3c0f4400b342a838b17951db2012450fc7..242fb786d5d9f05a959449d393cb925e4160d5b5 100644 --- a/js/three/ThreeView.js +++ b/js/three/ThreeView.js @@ -2,8 +2,8 @@ * Created by aghassaei on 1/16/15. */ -define(['underscore', 'backbone', 'three', 'appState', 'globals', 'orbitControls'], - function(_, Backbone, THREE, appState, globals){ +define(['underscore', 'backbone', 'three', 'appState', 'globals', 'lattice', 'orbitControls'], + function(_, Backbone, THREE, appState, globals, lattice){ return Backbone.View.extend({ @@ -97,7 +97,7 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'orbitControls var vector = new THREE.Vector2(2*(e.pageX-this.$el.offset().left)/this.$el.width()-1, 1-2*(e.pageY-this.$el.offset().top)/this.$el.height()); this.mouseProjection.setFromCamera(vector, this.model.camera); - var objsToIntersect = this.model.getCells().concat(this.model.getBasePlane()); + var objsToIntersect = lattice.getUItarget().getHighlightableCells().concat(this.model.getBasePlane()); // if (globals.highlighter.isVisible()) objsToIntersect = objsToIntersect.concat(globals.highlighter.mesh); var intersections = this.mouseProjection.intersectObjects(objsToIntersect, false); if (intersections.length == 0) {//no intersections