diff --git a/dependencies/OrbitControls.js b/dependencies/OrbitControls.js index d3b602b8e30540bed002e6a6af0964c6ef6d5626..aec1e06738f423ab448c8396df5357d44ff16d11 100644 --- a/dependencies/OrbitControls.js +++ b/dependencies/OrbitControls.js @@ -130,6 +130,11 @@ THREE.OrbitControls = function ( object, domElement ) { var startEvent = { type: 'start'}; var endEvent = { type: 'end'}; + this.setTarget = function(target){//three vector + this.target = target; +// this.target0 = this.target.clone(); + }; + this.rotateLeft = function ( angle ) { if ( angle === undefined ) { diff --git a/js/lattice/Lattice.js b/js/lattice/Lattice.js index b8f540500b58fabae3070405ff66ceb0890a148f..ee480c28b5cac3a2f7bd3fe3b43793a5840971c2 100644 --- a/js/lattice/Lattice.js +++ b/js/lattice/Lattice.js @@ -35,6 +35,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre this.listenTo(this, "change:cellSeparation", this._updateCellSeparation); this.listenTo(appState, "change:currentNav", this._navChanged); + this.listenTo(this, "change:cellsMin change:cellsMax", this._updateThreeViewControls); this._updateLatticeType(); }, @@ -104,6 +105,13 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre if (globals.basePlane) globals.basePlane.set("zIndex", 0, {silent:silent}); }, + _updateThreeViewControls: function(){ + var cellsMin = this.get("cellsMin"); + var cellsMax = this.get("cellsMax"); + if (cellsMax === null || cellsMin === null) return; + if (globals.threeView) globals.threeView.setOrbitControlsFor(this.get("cellsMin").clone(), this.get("cellsMax").clone()) + }, + diff --git a/js/main.js b/js/main.js index 39387825118bbefd09767da80c99de981c84b413..206e08f28f35799f27488b855af08a57eab0d232 100644 --- a/js/main.js +++ b/js/main.js @@ -250,12 +250,13 @@ require.config({ //}; //init stuff -require(['appState', 'lattice', 'navbar', 'threeModel', 'threeView', 'flatUI', 'bootstrapSlider', 'ribbon', 'menuWrapper', 'scriptView'], - function(appState, lattice, Navbar, three, ThreeView){ +require(['appState', 'lattice', 'navbar', 'threeModel', 'threeView', 'globals', 'flatUI', 'bootstrapSlider', 'ribbon', 'menuWrapper', 'scriptView'], + function(appState, lattice, Navbar, three, ThreeView, globals){ new Navbar({model:appState}); - new ThreeView({model:three}); + var threeView = new ThreeView({model:three}); + globals.threeView = threeView;//todo fix this // if (lattice.get("connectionType") != "gik") lattice.getUItarget().addCellAtIndex({x:0,y:0,z:0});//add a cell }); diff --git a/js/three/ThreeView.js b/js/three/ThreeView.js index d06897b8e31b3f50bda992c8497da1158790cede..c2200e796e51eb087c70647c17cca5de87030895 100644 --- a/js/three/ThreeView.js +++ b/js/three/ThreeView.js @@ -60,6 +60,10 @@ define(['underscore', 'backbone', 'three', 'appState', 'globals', 'lattice', 'or this.controls.reset(); }, + setOrbitControlsFor: function(min, max){ + this.controls.setTarget(max.sub(min).divideScalar(2).add(min)); + }, + //////////////////////////////////////////////////////////////////////////////// ///////////////////////////////MOUSE EVENTS///////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////