2016-02-12 10:41:41 +00:00
|
|
|
import EventEmitter from 'eventemitter3';
|
|
|
|
import THREE from 'three';
|
2016-02-19 09:48:43 +00:00
|
|
|
import OrbitControls from '../vendor/OrbitControls';
|
2016-02-12 10:41:41 +00:00
|
|
|
|
|
|
|
class Orbit extends EventEmitter {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2016-02-12 19:23:53 +00:00
|
|
|
// Proxy control events
|
2016-02-12 22:28:31 +00:00
|
|
|
//
|
|
|
|
// There's currently no distinction between pan, orbit and zoom events
|
2016-02-12 19:23:53 +00:00
|
|
|
_initEvents() {
|
|
|
|
this._controls.addEventListener('start', (event) => {
|
2016-02-19 09:48:43 +00:00
|
|
|
this._world.emit('controlsMoveStart', event.target.target);
|
2016-02-12 19:23:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this._controls.addEventListener('change', (event) => {
|
2016-02-19 09:48:43 +00:00
|
|
|
this._world.emit('controlsMove', event.target.target);
|
2016-02-12 19:23:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this._controls.addEventListener('end', (event) => {
|
2016-02-19 09:48:43 +00:00
|
|
|
this._world.emit('controlsMoveEnd', event.target.target);
|
2016-02-12 19:23:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:41:41 +00:00
|
|
|
// Moving the camera along the [x,y,z] axis based on a target position
|
|
|
|
_panTo(point, animate) {}
|
|
|
|
_panBy(pointDelta, animate) {}
|
|
|
|
|
|
|
|
// Zooming the camera in and out
|
|
|
|
_zoomTo(metres, animate) {}
|
|
|
|
_zoomBy(metresDelta, animate) {}
|
|
|
|
|
|
|
|
// Force camera to look at something other than the target
|
|
|
|
_lookAt(point, animate) {}
|
|
|
|
|
|
|
|
// Make camera look at the target
|
|
|
|
_lookAtTarget() {}
|
|
|
|
|
|
|
|
// Tilt (up and down)
|
|
|
|
_tiltTo(angle, animate) {}
|
|
|
|
_tiltBy(angleDelta, animate) {}
|
|
|
|
|
|
|
|
// Rotate (left and right)
|
|
|
|
_rotateTo(angle, animate) {}
|
|
|
|
_rotateBy(angleDelta, animate) {}
|
|
|
|
|
|
|
|
// Fly to the given point, animating pan and tilt/rotation to final position
|
|
|
|
// with nice zoom out and in
|
|
|
|
//
|
|
|
|
// Calling flyTo a second time before the previous animation has completed
|
|
|
|
// will immediately start the new animation from wherever the previous one
|
|
|
|
// has got to
|
|
|
|
_flyTo(point, noZoom) {}
|
|
|
|
|
2016-02-12 19:23:53 +00:00
|
|
|
// Proxy to OrbitControls.update()
|
|
|
|
update() {
|
|
|
|
this._controls.update();
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:41:41 +00:00
|
|
|
// Add controls to world instance and store world reference
|
|
|
|
addTo(world) {
|
|
|
|
world.addControls(this);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Internal method called by World.addControls to actually add the controls
|
|
|
|
_addToWorld(world) {
|
|
|
|
this._world = world;
|
|
|
|
|
|
|
|
// TODO: Override panLeft and panUp methods to prevent panning on Y axis
|
|
|
|
// See: http://stackoverflow.com/a/26188674/997339
|
2016-02-19 09:48:43 +00:00
|
|
|
this._controls = new OrbitControls(world._engine._camera, world._container);
|
2016-02-12 10:41:41 +00:00
|
|
|
|
2016-02-13 13:56:58 +00:00
|
|
|
// Disable keys for now as no events are fired for them anyway
|
|
|
|
this._controls.keys = false;
|
|
|
|
|
|
|
|
// 89 degrees
|
|
|
|
this._controls.maxPolarAngle = 1.5533;
|
2016-02-12 21:51:41 +00:00
|
|
|
|
2016-02-12 22:28:31 +00:00
|
|
|
// this._controls.enableDamping = true;
|
|
|
|
// this._controls.dampingFactor = 0.25;
|
2016-02-12 21:51:41 +00:00
|
|
|
|
2016-02-12 19:23:53 +00:00
|
|
|
this._initEvents();
|
2016-02-12 10:41:41 +00:00
|
|
|
|
2016-02-12 19:23:53 +00:00
|
|
|
this.emit('added');
|
2016-02-12 10:41:41 +00:00
|
|
|
}
|
2016-02-29 09:17:22 +00:00
|
|
|
|
|
|
|
// Destroys the controls and removes them from memory
|
|
|
|
destroy() {
|
|
|
|
// TODO: Remove event listeners
|
|
|
|
|
|
|
|
this._controls.dispose();
|
|
|
|
|
|
|
|
this._world = null;
|
|
|
|
this._controls = null;
|
|
|
|
}
|
2016-02-12 10:41:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 20:34:53 +00:00
|
|
|
export default Orbit;
|
|
|
|
|
|
|
|
var noNew = function() {
|
2016-02-12 10:41:41 +00:00
|
|
|
return new Orbit();
|
|
|
|
};
|
2016-03-01 20:34:53 +00:00
|
|
|
|
|
|
|
// Initialise without requiring new keyword
|
|
|
|
export {noNew as orbit};
|