Skip to content
Snippets Groups Projects
Commit 8e985f31 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

moving stuff around

parent eed1fff7
No related branches found
No related tags found
No related merge requests found
......@@ -149,7 +149,7 @@
if (this.cellMesh) {
window.three.sceneRemove(this.cellMesh);
this.cellMesh.myCell = null;
this.cellMesh.dispose();
// this.cellMesh.dispose();
// geometry.dispose();
// material.dispose();
this.cellMesh = null;
......
......@@ -94,7 +94,7 @@
DMAPart.prototype.destroy = function(){
if (this.mesh) {
window.three.sceneRemove(this.mesh);
this.mesh.dispose();
// this.mesh.dispose();
// geometry.dispose();
// material.dispose();
this.mesh = null;
......
......@@ -11,12 +11,14 @@ $(function(){
//init threeJS and geometry models
window.three = new ThreeModel();
var lattice = new Lattice();
new ThreeView({model:window.three, lattice:lattice});
//setup ui
var appState = new AppState({lattice:lattice});
new MenuWrapper({lattice:lattice, model:appState});
new NavBar({model:appState});
//threeJS View
new ThreeView({model:window.three, lattice:lattice, appState:appState});
lattice.addCell(new THREE.Vector3(0,0,0));
});
......@@ -19,8 +19,9 @@ LatticeMenuView = Backbone.View.extend({
_.bindAll(this, "render");
this.listenTo(this.model, "change", function(){
if(!model.hasChanged('cellMode')) return;//ignore cell mode changes
this.render();
if(!this.model.hasChanged('cellMode')){//ignore cell mode changes
this.render();
};
});
},
......
......@@ -16,11 +16,21 @@ AppState = Backbone.Model.extend({
lastSimulationTab: "physics",
lastAssembleTab: "assembler",
menuIsVisible: true
menuIsVisible: true,
//key bindings
shift: false,
deleteMode: false,
extrudeMode: false
},
initialize: function(options){
_.bindAll(this, "_handleKeyStroke");
//bind events
$(document).bind('keydown', {state:true}, this._handleKeyStroke);
$(document).bind('keyup', {state:false}, this._handleKeyStroke);
this.listenTo(this, "change:currentTab", this._storeTab);
this.listenTo(this, "change:currentTab", this._updateLatticeMode);
this.listenTo(this, "change:currentNav", this._updateCurrentTabForNav);
......@@ -47,10 +57,40 @@ AppState = Backbone.Model.extend({
//update to last tab open in that section
_updateCurrentTabForNav: function(){
var navSelection = this.get("currentNav");
if (navSelection=="navDesign") this.set("currentTab", this.get("lastDesignTab"), {silent:true});
else if (navSelection=="navSim") this.set("currentTab", this.get("lastSimulationTab"), {silent:true});
else if (navSelection=="navAssemble") this.set("currentTab", this.get("lastAssembleTab"), {silent:true});
if (navSelection == "navDesign") this.set("currentTab",
this.get("lastDesignTab"), {silent:true});
else if (navSelection == "navSim") this.set("currentTab",
this.get("lastSimulationTab"), {silent:true});
else if (navSelection == "navAssemble") this.set("currentTab",
this.get("lastAssembleTab"), {silent:true});
this._updateLatticeMode();//a little bit hacky, this updates the lattice, but holds off on updating the menus til the animation has happened
},
///////////////////////////////////////////////////////////////////////////////
////////////////////KEYS AND MOUSE EVENTS//////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
_handleKeyStroke: function(e){//receives keyup and keydown
var state = e.data.state;
var currentTab = this.get("currentTab");
switch(e.keyCode){
case 16://shift
this.set("shift", state);
break;
case 32://space bar
e.preventDefault();
this.set("deleteMode", state);
break;
case 69://e
// if (currentTab != "sketch") return;
this.set("extrudeMode", state);
break;
default:
break;
}
}
});
\ No newline at end of file
......@@ -151,6 +151,7 @@ Lattice = Backbone.Model.extend({
removeCell: function(object){
if (!object) return;
var cell = object.parent.myCell;
var index = this._subtract(cell.indices, this.get("cellsMin"));
var cells = this.get("cells");
......
......@@ -5,15 +5,12 @@
ThreeView = Backbone.View.extend({
events: {
"mousemove": "_mouseMoved",
"mousedown": "_mouseDown",
"mouseup": "_mouseUp"
"mousemove": "_mouseMoved",
"mouseup": "_mouseUp",
"mousedown": "_mouseDown"
},
mouseIsDown: false,//store state of mouse click
shiftIsDown: false,//used to add many voxels at once
deleteMode: false,//delete cells instead of adding (space bar)
extrudeMode: false,//extrude a column of cells
mouseIsDown: false,//store state of mouse click inside this el
extrudeVisualizer: ExtrudeVisualizer(),
mouseProjection: new THREE.Raycaster(),
highlighter: null,
......@@ -28,63 +25,55 @@ ThreeView = Backbone.View.extend({
initialize: function(options){
this.lattice = options.lattice;
this.appState = options.appState;
_.bindAll(this, "_animate", "_mouseMoved", "_handleKeyStroke", "_drawBasePlane");
_.bindAll(this, "_animate", "_mouseMoved", "_drawBasePlane");
//bind events
$(document).bind('keydown', {state:true}, this._handleKeyStroke);
$(document).bind('keyup', {state:false}, this._handleKeyStroke);
this.listenTo(this.lattice, "change:type, change:scale", this._drawBasePlane);
this.listenTo(this.lattice, "change:type change:scale", this._drawBasePlane);
this.listenTo(this.appState, "change:deleteMode change:extrudeMode change:shift", this._setControlsEnabled);
this.controls = new THREE.OrbitControls(this.model.camera, this.$el.get(0));
this.controls.addEventListener('change', this.model.render);
this.$el.append(this.model.domElement);
this._animate();
this.$el.append(this.model.domElement);//render only once
this.basePlane = this._drawBasePlane();
//init highlighter
this.highlighter = this._initHighlighter();
window.three.sceneAdd(this.highlighter, true);
this.model.render();
this._animate();
},
_initHighlighter: function(){
var highlightGeometry = new THREE.Geometry();
//can't change size of faces or vertices buffers dynamically
highlightGeometry.vertices = [new THREE.Vector3(0,0,0), new THREE.Vector3(0,0,0), new THREE.Vector3(0,0,0)];
highlightGeometry.faces = [new THREE.Face3(0,1,2)];
this.highlighter = new THREE.Mesh(highlightGeometry,
var highlighter = new THREE.Mesh(highlightGeometry,
new THREE.MeshBasicMaterial({side:THREE.DoubleSide, transparent:true, opacity:0.4, color:0xffffff, vertexColors:THREE.FaceColors}));
this.highlighter.geometry.dynamic = true;
this.highlighter.visible = false;
window.three.sceneAdd(this.highlighter, true);
this.model.render();
highlighter.geometry.dynamic = true;
highlighter.visible = false;
return highlighter;
},
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////CONTROLS/////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
_animate: function(){
requestAnimationFrame(this._animate);
this.controls.update();
},
_handleKeyStroke: function(e){//receives keyup and keydown
var state = e.data.state;
switch(e.keyCode){
case 16://shift
this.shiftIsDown = state;
this.controls.enabled = !state;
break;
case 32://space bar
e.preventDefault();
this.deleteMode = state;
this.controls.enabled = !state;
break;
case 69://e
this.extrudeMode = state;
this.controls.enabled = !state;
break;
default:
break;
_setControlsEnabled: function(){
if (this.appState.get("deleteMode") || this.appState.get("shift") || this.appState.get("extrudeMode")){
this.controls.enabled = false;
} else {
this.controls.enabled = true;
}
},
......@@ -104,10 +93,10 @@ ThreeView = Backbone.View.extend({
return;
}
if (this.extrudeMode && this.mouseIsDown && this.extrudeVisualizer.getMeshNum()>0){
this.extrudeVisualizer.dragHandle(1-2*(e.pageY-this.$el.offset().top)/this.$el.height());
return;
}
// if (this.appState.get("extrudeMode") && this.mouseIsDown && this.extrudeVisualizer.getMeshNum()>0){
// this.extrudeVisualizer.dragHandle(1-2*(e.pageY-this.$el.offset().top)/this.$el.height());
// return;
// }
//make projection vector
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());
......@@ -118,19 +107,19 @@ ThreeView = Backbone.View.extend({
//check if we're intersecting anything
var intersections = this.mouseProjection.intersectObjects(this.model.objects, true);
if (intersections.length == 0) {
this.currentIntersectedObject == null;
this.currentIntersectedObject = null;
this._hideHighlighter();
return;
}
this.currentIntersectedObject = intersections[0].object;
if (this.deleteMode && this.mouseIsDown){
if (this.appState.get("deleteMode") && this.mouseIsDown){
this._addRemoveVoxel();
return;
}
if (this.extrudeMode && this.mouseIsDown){
if (this.appState.get("extrudeMode") && this.mouseIsDown){
if (!this.highlighter.visible) return;
this.extrudeVisualizer.makeMeshFromProfile([this.highlighter]);
return;
......@@ -157,14 +146,14 @@ ThreeView = Backbone.View.extend({
(new THREE.Vector3()).addVectors(vertices[intersection.b], position), (new THREE.Vector3()).addVectors(vertices[intersection.c], position)];
this.highlighter.geometry.verticesNeedUpdate = true;
if (this.mouseIsDown && this.shiftIsDown) this._addRemoveVoxel();
if (this.mouseIsDown && this.appState.get("shift")) this._addRemoveVoxel();
window.three.render();
},
_addRemoveVoxel: function(){
if (this.deleteMode){
if (this.appState.get("deleteMode")){
if (this.currentIntersectedObject === this.basePlane) return;
this.lattice.removeCell(this.currentIntersectedObject);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment