diff --git a/js/cells/supercells/DMASuperCell.js b/js/cells/supercells/DMASuperCell.js index 44bf5cee50087cfc46cd8695e2dd1186c01f398d..045e736eb93f690e6641e5e42c46f67dc16b5f11 100644 --- a/js/cells/supercells/DMASuperCell.js +++ b/js/cells/supercells/DMASuperCell.js @@ -42,12 +42,14 @@ define(['underscore', 'three', 'threeModel', 'lattice', 'appState', 'cell'], var json = {index: new THREE.Vector3(x, y, z)}; var callback = function(cell){ - var cellIndex = cell.getIndex();//x, y, z have changed by now + var cellIndex = cell.getIndex(); + if (material.cellsMin) cellIndex.sub(material.cellsMin); cells[cellIndex.x][cellIndex.y][cellIndex.z] = cell; }; if (material.sparseCells){ if (material.sparseCells[x][y][z]){ + json.index.add(material.cellsMin); json = _.extend(json, material.sparseCells[x][y][z]); this._makeSubCellForIndex(json, callback); }//else no cell in this spot diff --git a/js/lattice/CompositeEditorLattice.js b/js/lattice/CompositeEditorLattice.js index a8b40430e3e408ca58c152719d401daa19d82fdb..ecf86628270e97e46427dc82a5cecb31b6ad8a14 100644 --- a/js/lattice/CompositeEditorLattice.js +++ b/js/lattice/CompositeEditorLattice.js @@ -16,7 +16,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre defaults: _.extend(LatticeBase.prototype.defaults, { name: "", - color: null + color: null, + origin: new THREE.Vector3(0,0,0) }), __initialize: function(options, callback){ @@ -69,26 +70,27 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, - makeNewCompositeMaterial: function(dimensions){ + makeNewCompositeMaterial: function(bounds){ if (this.get("numCells") == 0) { console.warn("no cells in this composite"); return; } var id = this.get("id"); - var data = this.toJSONForSave(dimensions); + var data = this.toJSONForSave(bounds); materials.setMaterial(id, data); }, - toJSONForSave: function(dimensions){ + toJSONForSave: function(bounds){ var name = this.get("name"); if (name == "") name = "Composite Material " + compositeNum++; - if (dimensions) var _dimensions = dimensions.clone(); + if (bounds) var _dimensions = bounds.max.clone().sub(bounds.min); var cellsMin = this.get("cellsMin"); var cellsMax = this.get("cellsMax"); if (cellsMax) { + console.log(bounds.min); cellsMax = cellsMax.clone(); - cellsMax.sub(cellsMin); - cellsMin = new THREE.Vector3(0,0,0); + cellsMax.sub(cellsMin).sub(bounds.min); + cellsMin = new THREE.Vector3(0,0,0).sub(bounds.min); } var data = { name: name, diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 540b1b3e820eae07c155a730760063ce4d7f8006..6cdbccc7a627d3297e939d895f4833d295328ad8 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -198,7 +198,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, calculateBoundingBox: function(){ - if (!this.get("cellsMax") || !this.get("cellsMin")) return new THREE.Vector3(0,0,0); + if (!this.get("cellsMax") || !this.get("cellsMin")) return {max:new THREE.Vector3(0,0,0), min:new THREE.Vector3(0,0,0)}; var dimMax = this.get("cellsMax").clone().sub(this.get("cellsMin")).add(new THREE.Vector3(1,1,1)); var dimMin = new THREE.Vector3(0,0,0); this._loopCells(this.sparseCells, function(cell, x, y, z){ @@ -215,7 +215,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre } } }); - return dimMax.sub(dimMin); + return {max:dimMax, min:dimMin}; }, diff --git a/js/menus/CompositeMenuView.js b/js/menus/CompositeMenuView.js index 32276511e592167fbbed81bf399d934228997f58..66eceac2f3706c0eab5aa22423b9097a7864a79b 100644 --- a/js/menus/CompositeMenuView.js +++ b/js/menus/CompositeMenuView.js @@ -5,7 +5,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals', 'materials', 'text!compositeMenuTemplate', 'fileSaver'], function($, _, MenuParentView, plist, lattice, globals, materials, template, fileSaver){ - var dimensions; + var bounds; return MenuParentView.extend({ @@ -24,12 +24,12 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals', 'ma return; } this.listenTo(lattice.compositeEditor, "change", function(){ - if (lattice.compositeEditor.changedAttributes().numCells !== undefined) dimensions = lattice.compositeEditor.calculateBoundingBox(); + if (lattice.compositeEditor.changedAttributes().numCells !== undefined) bounds = lattice.compositeEditor.calculateBoundingBox(); this.render(); }); this.listenTo(this.model, "change", this.render); - dimensions = lattice.compositeEditor.calculateBoundingBox(); + bounds = lattice.compositeEditor.calculateBoundingBox(); }, @@ -57,13 +57,13 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals', 'ma this._exit(); return; } - lattice.compositeEditor.makeNewCompositeMaterial(dimensions.clone()); + lattice.compositeEditor.makeNewCompositeMaterial(bounds); this._exit(); }, _saveComposite: function(e){ e.preventDefault(); - fileSaver.saveMaterial(lattice.compositeEditor.get("id"), lattice.compositeEditor.toJSONForSave(dimensions)); + fileSaver.saveMaterial(lattice.compositeEditor.get("id"), lattice.compositeEditor.toJSONForSave(bounds)); }, _cancelComposite: function(e){ @@ -89,7 +89,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'globals', 'ma _makeTemplateJSON: function(){ return _.extend(this.model.toJSON(), plist, globals, lattice.compositeEditor.toJSON(), { - dimensions: dimensions, + dimensions: bounds.max.clone().sub(bounds.min), materials: materials.list, validCompositeMaterials: materials.getVaildAvailableCompositeKeys(lattice.compositeEditor.get("id")) }); diff --git a/js/menus/templates/CompositeMenuView.html b/js/menus/templates/CompositeMenuView.html index 90e019ebd38e121907ba3a51cd38b76b11fe9bd4..47c20a23a1323e8ff2d974bebdb91080b0613c50 100644 --- a/js/menus/templates/CompositeMenuView.html +++ b/js/menus/templates/CompositeMenuView.html @@ -1,6 +1,9 @@ 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: <%= dimensions.x %> x <%= dimensions.y %> x <%= dimensions.z %><br/><br/> +Origin (xyz): <input data-property="origin" data-key="x" value="<%= origin.x %>" placeholder="X" class="form-control intInput compositeEditor" type="text"> + <input data-property="origin" data-key="y" value="<%= origin.y %>" placeholder="Y" class="form-control intInput compositeEditor" type="text"> + <input data-property="origin" data-key="z" value="<%= origin.z %>" placeholder="Z" class="form-control intInput compositeEditor" type="text"><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/> <a id="newRandomColor" href="#" class="btn btn-block btn-lg btn-default">New Random Color</a><br/>