diff --git a/js/cells/CubeCell.js b/js/cells/CubeCell.js index 39db47d4aedea8ab7bdb90b0324506f700f212cc..81d38571cc8bf9e05eb2bde3bcf6e5184e391db0 100644 --- a/js/cells/CubeCell.js +++ b/js/cells/CubeCell.js @@ -10,7 +10,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], function CubeCell(json, superCell){ DMACell.call(this, json, superCell); - console.log("init cube cell"); } CubeCell.prototype = Object.create(DMACell.prototype); diff --git a/js/cells/DMACell.js b/js/cells/DMACell.js index bcb3706f8665b1be828e115a53f369d411a38da1..59d365a3abe34a8a14d53683df8478688e4ed973 100644 --- a/js/cells/DMACell.js +++ b/js/cells/DMACell.js @@ -26,7 +26,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], if (!superCell || superCell === undefined) three.sceneAdd(this.object3D);//add object3d as child of scene if top level of hierarchy } else this.hide();//stock cell - if (!this.cells && ( !superCell || superCell === undefined)) this.setMode(); + if (!this.cells) this.setMode(); } @@ -61,7 +61,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], var geometry = this._getGeometry(); var meshes = []; - var mesh = new THREE.Mesh(geometry, this.getMaterial()); + var mesh = new THREE.Mesh(geometry, this.getMaterial(true)); mesh.name = this._getMeshName(); meshes.push(mesh); @@ -156,7 +156,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], var material; if (state) material = globals.materials.deleteMaterial; - else material = this.getMaterial(); + else material = this.getMaterial(true); if (!material) return;//cell may be deleted by now if (this.object3D.children[0].material == material) return; @@ -221,7 +221,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], this.setMode(mode); }; - DMACell.prototype.getMaterial = function(){ + DMACell.prototype.getMaterial = function(returnTHREEObject){ if (!this.material) return null; var materialClass = lattice.get("materialClass"); if (!globals.materials[materialClass]) { @@ -246,7 +246,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'globals'], switch(mode) { case "supercell": - if (!this.superCell) mode = "cell";//top level item + if (!this.superCell && !this.cells) mode = "cell";//top level item setVisiblity(); break; case "cell": diff --git a/js/cells/supercells/CompositeCell.js b/js/cells/supercells/CompositeCell.js index 0fa3d90052d8bb78fecb914408522a8f3cd09459..46d2b7f4709d0f713c293e5481e986ca9fb1f45e 100644 --- a/js/cells/supercells/CompositeCell.js +++ b/js/cells/supercells/CompositeCell.js @@ -8,12 +8,11 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', CompositeCell = function(json, superCell){ DMASuperCell.call(this, json, superCell); - console.log("initComposite"); }; CompositeCell.prototype = Object.create(DMASuperCell.prototype); CompositeCell.prototype._getGeometry = function(){ - var dimensions = appState.get("superCellRange"); + var dimensions = globals.materials.compositeMaterials[this.material].dimensions; var geo = new THREE.BoxGeometry(dimensions.x, dimensions.y, dimensions.z); geo.applyMatrix(new THREE.Matrix4().makeTranslation(dimensions.x/2-0.5, dimensions.y/2-0.5, dimensions.z/2-0.5)); return geo; @@ -27,13 +26,20 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'superCell', return wireframe; }; - CompositeCell.prototype.getMaterial = function(){ + CompositeCell.prototype.getMaterial = function(returnTHREEObject){ if (!this.material) return null; var material = globals.materials.compositeMaterials[this.material]; if (!material){ console.warn("no material "+ this.material + " found"); return null; } + if (returnTHREEObject){ + if (material.material) return material.material; + else { + material.material = new THREE.MeshLambertMaterial({color:material.color, shading:THREE.FlatShading}); + return material.material; + } + } return material; }; diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 84984e079e6f89016c4cfcc9f013c43ddeb89778..79eda5980a04e1b5f7e6990d86d4739c4a829286 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -15,9 +15,9 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var material = this.getMaterial(); var range = material.dimensions || appState.get("superCellRange"); - this.cells = this._makeChildCells(range, this.getMaterial()); + this.cells = this._makeChildCells(range, material); - if (!superCell || superCell === undefined) this.setMode(null, function(){ + DMACell.prototype.setMode.call(this, null, function(){ three.conditionalRender(); });//don't pass a call down to children again } @@ -59,7 +59,6 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], DMASuperCell.prototype._makeSubCellForIndex = function(json, callback){ var subclassFile = lattice.getCellSubclassFile(); if (json.material && json.material.substr(0,5) == "super") subclassFile = "compositeCell"; - console.log(subclassFile); var self = this; require([subclassFile], function(CellSubclass){ var cell = new CellSubclass(json, self); @@ -100,6 +99,7 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], }; DMASuperCell.prototype._loopCells = function(callback){ + console.log(this.cells); var cells = this.cells; if (!cells || cells === undefined) return; for (var x=0;x<cells.length;x++){ diff --git a/js/menus/Ribbon.js b/js/menus/Ribbon.js index c530aa719d353a85935981f290f598637ed713c2..d02e3f389dc197c2182be1ef1f63298657be02b9 100644 --- a/js/menus/Ribbon.js +++ b/js/menus/Ribbon.js @@ -61,7 +61,7 @@ define(['jquery', 'underscore', 'backbone', 'plist', 'lattice'], function($, _, template: _.template('\ <div class="btn-toolbar">\ <div class="btn-group">\ - <!--<a data-type="supercell" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "supercell"){ %> ribbon-selected<% } %>" href="#">Super</a>-->\ + <a data-type="supercell" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "supercell"){ %> ribbon-selected<% } %>" href="#">Super</a>\ <a data-type="cell" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "cell"){ %> ribbon-selected<% } %>" href="#"><img data-type="cell" src="assets/imgs/cell-sm.png"></a>\ <% if (allPartTypes[cellType][connectionType]){ %>\ <a data-type="part" class="btn btn-primary btn-ribbon ribbonCellMode<% if (cellMode == "part"){ %> ribbon-selected<% } %>" href="#"><img data-type="part" src="assets/imgs/part-sm.png"></a>\ diff --git a/js/models/AppState.js b/js/models/AppState.js index f384d2ed80180aa7496892865d00e75eb503ec13..a6059661750d6abc39c5c1e554e61c73f6e9369e 100644 --- a/js/models/AppState.js +++ b/js/models/AppState.js @@ -87,10 +87,10 @@ define(['underscore', 'backbone', 'threeModel', 'three', 'plist'], function(_, B }, _updateCellMode: function(currentTab){ - if (currentTab == "lattice" || currentTab == "import") this.set("cellMode", "cell"); +// if (currentTab == "lattice" || currentTab == "import") this.set("cellMode", "cell"); //else if (currentTab == "import") this.set("cellMode", "cell"); //else if (currentTab == "sketch") this.set("cellMode", "cell"); - else if (currentTab == "part") this.set("cellMode", "part"); + if (currentTab == "part") this.set("cellMode", "part"); }, _navChanged: function(){ diff --git a/js/parts/DMAPart.js b/js/parts/DMAPart.js index 9a46ede31b88c0b95637e61306f1d04b70b8852b..73d1b4aca2e8f5dcfb1671bea3f581e5a7674983 100644 --- a/js/parts/DMAPart.js +++ b/js/parts/DMAPart.js @@ -14,7 +14,7 @@ define(['underscore', 'three'], function(_, THREE){ } DMAPart.prototype._buildMesh = function(){ - var mesh = this._translatePart(this._rotatePart(new THREE.Mesh(this._getGeometry(), this.getMaterial()))); + var mesh = this._translatePart(this._rotatePart(new THREE.Mesh(this._getGeometry(), this.getMaterial(true)))); mesh.name = "part"; return mesh; }; @@ -27,8 +27,8 @@ define(['underscore', 'three'], function(_, THREE){ return mesh; }; - DMAPart.prototype.getMaterial = function(){ - return this.parentCell.getMaterial(); + DMAPart.prototype.getMaterial = function(returnTHREEObject){ + return this.parentCell.getMaterial(returnTHREEObject); }; DMAPart.prototype.setMaterial = function(material){