Commit 56fc3d49 authored by amandaghassaei's avatar amandaghassaei

sim lattice on sim subclasses

parent 01b1db2d
......@@ -96,11 +96,16 @@ require.config({
//emSim
emSimPlist: 'plists/EMSimPlist',
emSim: 'simulation/EM/emSim',
emSimLattice: 'simulation/EM/emSimLattice',
emSimCell: 'simulation/EM/emSimCell',
emSimSuperCell: 'simulation/EM/emSimSuperCell',
emWire: 'simulation/EM/emWire'
emSim: 'simulation/function/EM/emSim',
emSimLattice: 'simulation/function/EM/emSimLattice',
emSimCell: 'simulation/function/EM/emSimCell',
emWire: 'simulation/function/EM/emWire',
//elementFEASim
elementFEASimPlist: 'plists/EMSimPlist',
elementFEASim: 'simulation/element/FEA/elementFEASim',
elementFEASimLattice: 'simulation/element/FEA/elementFEASimLattice',
elementFEASimCell: 'simulation/element/FEA/elementFEASimCell'
},
shim: {
......
......@@ -30,14 +30,14 @@ define(['jquery', 'underscore', 'menuParent', 'emSimPlist', 'emSimLattice', 'emS
e.stopPropagation();
e.preventDefault();
var wireId = $(e.target).data("id");
var signalCell = emSimLattice.get("wires")[wireId].getSignal();
var signalCell = emSim.simLattice.get("wires")[wireId].getSignal();
require(['menuWrapper'], function(menuWrapper){
menuWrapper.initTabWithObject(signalCell, "signal", "emNavSignal")
});
},
_makeTemplateJSON: function(){
return _.extend(emSimLattice.toJSON(), emPlist, emSim.toJSON());
return _.extend(emSim.simLattice.toJSON(), emPlist, emSim.toJSON());
},
template: _.template(template)
......
......@@ -42,7 +42,7 @@ define(['jquery', 'underscore', 'menuParent', 'emSimPlist', 'emSim', 'emSimLatti
_makeTemplateJSON: function(){
return _.extend(emSim.toJSON(), emSimLattice.toJSON(), emPlist);
return _.extend(emSim.toJSON(), emSim.simLattice.toJSON(), emPlist);
},
template: _.template(template)
......
......@@ -26,7 +26,7 @@ define(['jquery', 'underscore', 'menuParent', 'emSimPlist', 'emSimLattice', 'emS
saveExitMenu: function(){
this.signal.setAsSignalGenerator(signal);
emSimLattice.resetWiresMetaTexture();
emSim.simLattice.resetWiresMetaTexture();
return true;
},
......
/**
* Created by ghassaei on 5/23/16.
*/
define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'lattice'],
function(THREE, _, Backbone, three, appState, lattice){
var Sim = Backbone.Model.extend({
defaults:{
dtSolver: 10,//us
dtRender: 100,//frames
isRunning: false,
needsReset: false,
viewMode: 'default',
colorMin: null,
colorMax: null,
autoRangeColor: true,
numSimMaterials: 20,//number of materials used in gradient view
manualSelectFixed: false,
showFixed: false,
fixedIndices: []
},
initialize: function(){
this.listenTo(appState, "change:currentNav", this._navChanged);
this.listenTo(appState, "change:currentTab", this._tabChanged);
this.listenTo(this, "change:showFixed", this._toggleFixedVisibility);
this.listenTo(this, "change:viewMode change:colorMax change:colorMin", this._viewModechanged);
this._navChanged();
this.time = 0;
this.simMaterials = this._buildSimMaterials();
},
_buildSimMaterials: function(){
var materials = [];
var numMaterials = this.get("numSimMaterials");
for (var i=0;i<numMaterials;i++){
materials.push(new THREE.MeshLambertMaterial({color: this._colorForVal(i, 0, numMaterials-1)}));
}
return materials;
},
_colorForVal : function(val, min, max){
if (min==max) return new THREE.Color();
var scaledVal = (1-(val - min)/(max - min)) * 0.7;
var color = new THREE.Color();
color.setHSL(scaledVal, 1, 0.5);
return color;
},
_materialForVal: function(val, min, max, numMaterials){
var index = Math.round((numMaterials-1)*(val-min)/(max-min));
if (min == max) index = 0;
return this.simMaterials[index];
},
_getViewMode: function(){
return this.get("viewMode");
},
run: function(){
var self = this;
this.set("isRunning", true);
this.set("needsReset", true);
var dt = this.get("dtSolver")/1000000;//convert to sec
var renderRate = this.get("dtRender");
var gravityVect = this.get("gravityVector").clone().normalize().multiplyScalar(this.get("gravity"));
var groundHeight = this.get("groundHeight");
var friction = this.get("friction");
this.simLattice.setConstants(dt, gravityVect, groundHeight, friction);
three.startAnimationLoop(function(){
for (var i=0;i<renderRate-1;i++){
self.time += dt;
this.simLattice.iter(dt, self.time, gravityVect, groundHeight, friction, false);
}
self.time += dt;
this.simLattice.iter(dt, self.time, gravityVect, groundHeight, friction, true);
//if (self._getViewMode() == "translation"){
// self.calcTranslation();
//}
});
},
pause: function(){
three.stopAnimationLoop();
this.set("isRunning", false);
},
reset: function(){
three.stopAnimationLoop();
this.set("isRunning", false);
this.set("needsReset", false);
this.simLattice.reset();
this.time = 0;
if (this._getViewMode == "translation"){
this.calcTranslation();
}
three.render();
},
fixCellAtIndex: function(index){
var position = index.clone().sub(lattice.get("cellsMin"));
var fixed = this.simLattice.fixCellAtIndex(position);
var fixedIndices = this.get("fixedIndices");
if (fixed) fixedIndices.push(index.clone());
else {
for (var i=0;i<fixedIndices.length;i++){
if (fixedIndices[i].equals(index)) {
fixedIndices.splice(i, 1);
break;
}
}
}
this.trigger("change");
},
_toggleFixedVisibility: function(){
var state = this.get("showFixed");
var cellsMin = lattice.get("cellsMin");
lattice.loopCells(function(cell, x, y, z){
if (!state || this.simLattice.isFixedAtIndex(new THREE.Vector3(x,y,z))) cell.show();
else cell.hide();
});
three.render();
},
_viewModechanged: function(){
//var viewMode = this._getViewMode();
//if (viewMode == "default") {
// this.simLattice.loopCells(function(cell){
// cell.showDefaultColor();
// });
//} else if (viewMode == "translation") {
// this.calcTranslation();
//}
three.render();
},
calcTranslation: function(){
var max = 0;
var min = 0;
var self = this;
var numMaterials = this.get("numSimMaterials");
if (!this.get("autoRangeColor")){
if (this.get("colorMin")) min = this.get("colorMin");
if (this.get("colorMax")) max = this.get("colorMax");
} else {
this.simLattice.loopCells(function(cell){
var translation = cell.getTranslation().length();
if (translation>max) max = translation;
});
this.set("colorMin", min);
this.set("colorMax", max);
}
this.simLattice.loopCells(function(cell){
var val = cell.getTranslation().length();
cell.showTranslation(self._materialForVal(val, min, max, numMaterials));
});
}
});
return Sim;
});
\ No newline at end of file
/**
* Created by ghassaei on 5/23/16.
*/
define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLattice', 'lattice'],
function(THREE, _, Backbone, three, appState, emSimLattice, lattice){
var Sim = Backbone.Model.extend({
defaults:{
dtSolver: 10,//us
dtRender: 100,//frames
isRunning: false,
needsReset: false,
viewMode: 'default',
colorMin: null,
colorMax: null,
autoRangeColor: true,
numSimMaterials: 20,//number of materials used in gradient view
manualSelectFixed: false,
showFixed: false,
fixedIndices: [],
},
initialize: function(){
this.listenTo(appState, "change:currentNav", this._navChanged);
this.listenTo(appState, "change:currentTab", this._tabChanged);
this.listenTo(this, "change:showFixed", this._toggleFixedVisibility);
this.listenTo(this, "change:viewMode change:colorMax change:colorMin", this._viewModechanged);
this._navChanged();
this.time = 0;
this.simMaterials = this._buildSimMaterials();
},
_buildSimMaterials: function(){
var materials = [];
var numMaterials = this.get("numSimMaterials");
for (var i=0;i<numMaterials;i++){
materials.push(new THREE.MeshLambertMaterial({color: this._colorForVal(i, 0, numMaterials-1)}));
}
return materials;
},
_colorForVal : function(val, min, max){
if (min==max) return new THREE.Color();
var scaledVal = (1-(val - min)/(max - min)) * 0.7;
var color = new THREE.Color();
color.setHSL(scaledVal, 1, 0.5);
return color;
},
_materialForVal: function(val, min, max, numMaterials){
var index = Math.round((numMaterials-1)*(val-min)/(max-min));
if (min == max) index = 0;
return this.simMaterials[index];
},
_getViewMode: function(){
return this.get("viewMode");
},
run: function(){
var self = this;
this.set("isRunning", true);
this.set("needsReset", true);
var dt = this.get("dtSolver")/1000000;//convert to sec
var renderRate = this.get("dtRender");
var gravityVect = this.get("gravityVector").clone().normalize().multiplyScalar(this.get("gravity"));
var groundHeight = this.get("groundHeight");
var friction = this.get("friction");
emSimLattice.setConstants(dt, gravityVect, groundHeight, friction);
three.startAnimationLoop(function(){
for (var i=0;i<renderRate-1;i++){
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, friction, false);
}
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, friction, true);
//if (self._getViewMode() == "translation"){
// self.calcTranslation();
//}
});
},
pause: function(){
three.stopAnimationLoop();
this.set("isRunning", false);
},
reset: function(){
three.stopAnimationLoop();
this.set("isRunning", false);
this.set("needsReset", false);
emSimLattice.reset();
this.time = 0;
if (this._getViewMode == "translation"){
this.calcTranslation();
}
three.render();
},
fixCellAtIndex: function(index){
var position = index.clone().sub(lattice.get("cellsMin"));
var fixed = emSimLattice.fixCellAtIndex(position);
var fixedIndices = this.get("fixedIndices");
if (fixed) fixedIndices.push(index.clone());
else {
for (var i=0;i<fixedIndices.length;i++){
if (fixedIndices[i].equals(index)) {
fixedIndices.splice(i, 1);
break;
}
}
}
this.trigger("change");
},
_toggleFixedVisibility: function(){
var state = this.get("showFixed");
var cellsMin = lattice.get("cellsMin");
lattice.loopCells(function(cell, x, y, z){
if (!state || emSimLattice.isFixedAtIndex(new THREE.Vector3(x,y,z))) cell.show();
else cell.hide();
});
three.render();
},
_viewModechanged: function(){
//var viewMode = this._getViewMode();
//if (viewMode == "default") {
// emSimLattice.loopCells(function(cell){
// cell.showDefaultColor();
// });
//} else if (viewMode == "translation") {
// this.calcTranslation();
//}
three.render();
},
calcTranslation: function(){
var max = 0;
var min = 0;
var self = this;
var numMaterials = this.get("numSimMaterials");
if (!this.get("autoRangeColor")){
if (this.get("colorMin")) min = this.get("colorMin");
if (this.get("colorMax")) max = this.get("colorMax");
} else {
emSimLattice.loopCells(function(cell){
var translation = cell.getTranslation().length();
if (translation>max) max = translation;
});
this.set("colorMin", min);
this.set("colorMax", max);
}
emSimLattice.loopCells(function(cell){
var val = cell.getTranslation().length();
cell.showTranslation(self._materialForVal(val, min, max, numMaterials));
});
}
});
return new Sim();
});
\ No newline at end of file
/**
* Created by ghassaei on 5/23/16.
*/
/**
* Created by ghassaei on 5/23/16.
*/
......@@ -4,7 +4,7 @@
define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLattice', 'lattice', 'plist', 'globals'],
function(THREE, _, Backbone, three, appState, emSimLattice, lattice, plist, globals){
function(THREE, _, Backbone, three, appState, EmSimLattice, lattice, plist, globals){
var emSim = Backbone.Model.extend({
......@@ -39,6 +39,8 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
initialize: function(){
this.simLattice = new EmSimLattice();
this.listenTo(appState, "change:currentNav", this._navChanged);
this.listenTo(appState, "change:currentTab", this._tabChanged);
this.listenTo(this, "change:showFixed", this._toggleFixedVisibility);
......@@ -98,7 +100,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
var previous = appState.previous("currentNav");
if (previous != "emNavSignal" && plist.allMenus[appState.get("currentNav")].parent != "emNavSim"){
emSimLattice.setCells(lattice.getCells(), this.get("fixedIndices"));
this.simLattice.setCells(lattice.getCells(), this.get("fixedIndices"));
}
var currentTab = appState.get("currentTab");
......@@ -129,22 +131,22 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
showActuator: function(index){
if (index === undefined) index = this.get("visibleActuator");
emSimLattice.loopCells(function(cell){
this.simLattice.loopCells(function(cell){
cell.setTransparent(true);
});
emSimLattice.get("actuators")[index].cell.setTransparent(false);
this.simLattice.get("actuators")[index].cell.setTransparent(false);
three.render();
},
showConductors: function(groupNum){
if (groupNum === undefined) groupNum = this.get("visibleWire");
if (_.keys(emSimLattice.get("wires")).length == 0 || groupNum == -2){
if (_.keys(this.simLattice.get("wires")).length == 0 || groupNum == -2){
lattice.setOpaque();
three.render();
return;
}
var allVisible = groupNum == -1;
emSimLattice.loopCells(function(cell){
this.simLattice.loopCells(function(cell){
cell.setTransparent(!cell.conductiveGroupVisible(allVisible, groupNum));
});
three.render();
......@@ -169,15 +171,15 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
var gravityVect = this.get("gravityVector").clone().normalize().multiplyScalar(this.get("gravity"));
var groundHeight = this.get("groundHeight");
var friction = this.get("friction");
emSimLattice.setConstants(dt, gravityVect, groundHeight, friction);
this.simLattice.setConstants(dt, gravityVect, groundHeight, friction);
three.startAnimationLoop(function(){
for (var i=0;i<renderRate-1;i++){
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, friction, false);
self.simLattice.iter(dt, self.time, gravityVect, groundHeight, friction, false);
}
self.time += dt;
emSimLattice.iter(dt, self.time, gravityVect, groundHeight, friction, true);
self.simLattice.iter(dt, self.time, gravityVect, groundHeight, friction, true);
//if (self._getViewMode() == "translation"){
// self.calcTranslation();
//}
......@@ -193,7 +195,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
three.stopAnimationLoop();
this.set("isRunning", false);
this.set("needsReset", false);
emSimLattice.reset();
this.simLattice.reset();
this.time = 0;
if (this._getViewMode == "translation"){
this.calcTranslation();
......@@ -204,7 +206,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
fixCellAtIndex: function(index){
var position = index.clone().sub(lattice.get("cellsMin"));
var fixed = emSimLattice.fixCellAtIndex(position);
var fixed = this.simLattice.fixCellAtIndex(position);
var fixedIndices = this.get("fixedIndices");
if (fixed) fixedIndices.push(index.clone());
else {
......@@ -222,7 +224,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
var state = this.get("showFixed");
var cellsMin = lattice.get("cellsMin");
lattice.loopCells(function(cell, x, y, z){
if (!state || emSimLattice.isFixedAtIndex(new THREE.Vector3(x,y,z))) cell.show();
if (!state || this.simLattice.isFixedAtIndex(new THREE.Vector3(x,y,z))) cell.show();
else cell.hide();
});
three.render();
......@@ -232,7 +234,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
_viewModechanged: function(){
//var viewMode = this._getViewMode();
//if (viewMode == "default") {
// emSimLattice.loopCells(function(cell){
// this.simLattice.loopCells(function(cell){
// cell.showDefaultColor();
// });
//} else if (viewMode == "translation") {
......@@ -250,14 +252,14 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
if (this.get("colorMin")) min = this.get("colorMin");
if (this.get("colorMax")) max = this.get("colorMax");
} else {
emSimLattice.loopCells(function(cell){
this.simLattice.loopCells(function(cell){
var translation = cell.getTranslation().length();
if (translation>max) max = translation;
});
this.set("colorMin", min);
this.set("colorMax", max);
}
emSimLattice.loopCells(function(cell){
this.simLattice.loopCells(function(cell){
var val = cell.getTranslation().length();
cell.showTranslation(self._materialForVal(val, min, max, numMaterials));
});
......@@ -274,7 +276,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
friction: this.get("friction")
};
var signals = [];
_.each(emSimLattice.get("signals"), function(signal){
_.each(this.simLattice.get("signals"), function(signal){
if (!signal.index) return;//deleted
signals.push(_.extend(signal.getSignalJSON(), {index:signal.getIndex()}));
});
......@@ -303,7 +305,7 @@ define(['three', 'underscore', 'backbone', 'threeModel', 'appState', 'emSimLatti
var json = _.omit(signal, "index");
signalsData.push({index: index, json:json});
});
emSimLattice.set("signalsData", signalsData);
this.simLattice.set("signalsData", signalsData);
}
}
......
......@@ -4,8 +4,8 @@
define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'GPUMath', "text!simulation/shaders/vertexShader.js",
"text!simulation/EM/shaders/velocityCalcShader.js", "text!simulation/shaders/packToBytesShader.js", "text!simulation/EM/shaders/positionCalcShader.js",
"text!simulation/EM/shaders/quaternionCalcShader.js", 'emSimCell'],
"text!simulation/function/EM/shaders/velocityCalcShader.js", "text!simulation/shaders/packToBytesShader.js", "text!simulation/function/EM/shaders/positionCalcShader.js",
"text!simulation/function/EM/shaders/quaternionCalcShader.js", 'emSimCell'],
function(_, Backbone, three, lattice, plist, EMWire, gpuMath, vertexShader, velocityCalcShader, packToBytesShader,
positionCalcShader, quaternionCalcShader) {
......@@ -926,7 +926,7 @@ define(['underscore', 'backbone', 'threeModel', 'lattice', 'plist', 'emWire', 'G
});
return new EMSimLattice();
return EMSimLattice;
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment