UNPKG

awv3

Version:
843 lines (745 loc) 34.8 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _promise = require('babel-runtime/core-js/promise'); var _promise2 = _interopRequireDefault(_promise); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _three = require('three'); var THREE = _interopRequireWildcard(_three); var _error = require('../core/error'); var Error = _interopRequireWildcard(_error); var _helpers = require('../core/helpers'); var Helpers = _interopRequireWildcard(_helpers); var _canvas = require('../core/canvas'); var _easing2 = require('../animation/easing'); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Orbit = function () { function Orbit() { var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Error.log('View undefined'); var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; (0, _classCallCheck3.default)(this, Orbit); this.view = view; this.canvas = view.canvas; this.dom = view.dom; this.camera = options.camera; var camera = this.camera || this.view.camera; this.easing = _easing2.exponential.out; this.duration = 1000; this._zoomed = false; this._autoZoom = { start: 0, end: 0, time: 0, length: 0, ease: this.easing, duration: this.duration }; this._autoFocus = { start: new THREE.Vector3(), end: new THREE.Vector3(), time: 0, ease: this.easing, duration: this.duration }; this._autoTheta = { start: 0, end: 0, time: 0, ease: this.easing, duration: this.duration }; this._autoPhi = { start: 0, end: 0, time: 0, ease: this.easing, duration: this.duration }; this._autoFov = { start: 0, end: 0, time: 0, ease: this.easing, duration: this.duration }; // ... this.enabled = options.enabled || true; this.zoomTarget = options.zoomTarget || new THREE.Vector3(); this.dynamicDampingFactor = options.dynamicDampingFactor || 0.55; this.dynamicDampingFactorAuto = options.dynamicDampingFactorAuto || 0.2; this.noZoom = options.noZoom || false; this.zoomSpeed = options.zoomSpeed || 5; this.zoomMode = options.zoomMode || Orbit.ZoomMode.Center; this.minDistance = options.minDistance || 0; this.maxDistance = options.maxDistance || Infinity; this.noRotate = options.noRotate || false; this.rotateSpeed = options.rotateSpeed || 0.9; this.noPan = options.noPan || false; this.panMode = options.panMode || Orbit.PanMode.Both; this.minPolarAngle = options.minPolarAngle || 0; // radians this.maxPolarAngle = options.maxPolarAngle || Math.PI; // radians this.interactionStopsAutomation = options.interactionStopsAutomation || true; this.inMotion = false; this.interaction = false; this.automation = false; this.target = new THREE.Vector3(); this.phi = 0; this.theta = 0; this.distance = 0; this._rotateStart = new THREE.Vector2(); this._rotateEnd = new THREE.Vector2(); this._rotateDelta = new THREE.Vector2(); this._panStart = new THREE.Vector2(); this._panEnd = new THREE.Vector2(); this._panDelta = new THREE.Vector2(); this._panOffset = new THREE.Vector3(); this._wheelStart = new THREE.Vector2(); this._wheelEnd = new THREE.Vector2(); this._wheelDelta = new THREE.Vector2(); this._polarStart = new THREE.Vector2(); this._polarEnd = new THREE.Vector2(); this._mousePosition = new THREE.Vector2(); this._panning = new THREE.Vector3(); this._eye = new THREE.Vector3(); this._phiDelta = 0; this._thetaDelta = 0; this._scale = 1; this._state = Orbit.State.none; this._quat = new THREE.Quaternion().setFromUnitVectors(options.up || camera.up, new THREE.Vector3(0, 1, 0)); this._quatInverse = this._quat.clone().inverse(); this._touchZoomDistanceEnd; this._touchZoomDistanceStart; this._aDelta = new THREE.Vector2(); this._lastState = []; this._idleCallbacks = []; this._activeCallbacks = []; } (0, _createClass3.default)(Orbit, [{ key: 'clone', value: function clone() { var result = new Orbit(this.view); result.enabled = this.enabled; result.inMotion = this.inMotion; result.interaction = this.interaction; result.automation = this.automation; result.target = this.target.clone(); result.zoomTarget = this.zoomTarget.clone(); result.dynamicDampingFactor = this.dynamicDampingFactor; result.dynamicDampingFactorAuto = this.dynamicDampingFactorAuto; result.noZoom = this.noZoom; result.zoomSpeed = this.zoomSpeed; result.zoomMode = this.zoomMode; result.minDistance = this.minDistance; result.maxDistance = this.maxDistance; result.noRotate = this.noRotate; result.rotateSpeed = this.rotateSpeed; result.noPan = this.noPan; result.panMode = this.panMode; result.minPolarAngle = this.minPolarAngle; result.maxPolarAngle = this.maxPolarAngle; result.phi = this.phi; result.theta = this.theta; result.distance = this.distance; return result; } }, { key: 'easing', value: function easing(_easing) { this.easing = _easing; return this; } }, { key: 'duration', value: function duration(_duration) { this.duration = _duration; return this; } }, { key: 'zoom', value: function zoom() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { value: this.view.scene.getRadius() * 4, easing: this.easing, duration: this.duration }; var camera = this.camera || this.view.camera; if (typeof options === 'number') options = { value: options, easing: this.easing, duration: this.duration }; if (options instanceof THREE.Object3D) options = { value: options.getRadius() * 4, easing: this.easing, duration: this.duration }; options.value = options.value || this.view.scene.getRadius() * 4; options.duration = options.duration || this.duration; options.easing = options.easing || this.easing; this.automation = true; this._wheelStart.y = 0; this._wheelEnd.y = 0; this._autoZoom.ease = options.easing; this._autoZoom.duration = options.duration; this._autoZoom.time = this.canvas.renderer.time; this._autoZoom.length = this._eye.copy(camera.position).sub(this.target).length(); this._autoZoom.start = 1; this._autoZoom.end = options.value / this._autoZoom.length; return this; } }, { key: 'focus', value: function focus() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { value: this.view.scene.getCenter(), easing: this.easing, duration: this.duration }; if (options instanceof THREE.Vector3) options = { value: options, easing: this.easing, duration: this.duration }; if (options instanceof THREE.Object3D) options = { value: options.getCenter(), easing: this.easing, duration: this.duration }; this.automation = true; this._autoFocus.ease = options.easing || this.easing; this._autoFocus.duration = options.duration || this.duration; this._autoFocus.time = this.canvas.renderer.time; this._autoFocus.start.copy(this.target); this._autoFocus.end.copy(options.value || this.view.scene.getCenter()); return this; } }, { key: 'rotateTheta', value: function rotateTheta() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { value: 0, easing: this.easing, duration: this.duration }; if (typeof options === 'number') options = { value: options, easing: this.easing, duration: this.duration }; var theta = options.value || 0; var thetaNow = this.theta; if (thetaNow < 0) thetaNow += 2 * Math.PI; if (theta < 0) theta += 2 * Math.PI; var thetaDist = Math.abs(theta - thetaNow); if (2 * Math.PI - thetaDist < thetaDist) { if (theta < thetaNow) { theta += 2 * Math.PI; } else { thetaNow += 2 * Math.PI; } } this.automation = true; this._autoTheta.ease = options.easing || this.easing; this._autoTheta.duration = options.duration || this.duration; this._autoTheta.time = this.canvas.renderer.time; this._autoTheta.start = thetaNow; this._autoTheta.end = theta; this._autoTheta.old = undefined; return this; } }, { key: 'rotatePhi', value: function rotatePhi() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { value: 0, easing: this.easing, duration: this.duration }; if (typeof options === 'number') options = { value: options, easing: this.easing, duration: this.duration }; var phi = options.value || 0; var phiNow = this.phi; if (phiNow < 0) phiNow += 2 * Math.PI; if (phi < 0) phi += 2 * Math.PI; var phiDist = Math.abs(phi - phiNow); if (2 * Math.PI - phiDist < phiDist) { if (phi < phiNow) { phi += 2 * Math.PI; } else { phiNow += 2 * Math.PI; } } this.automation = true; this._autoPhi.ease = options.easing || this.easing; this._autoPhi.duration = options.duration || this.duration; this._autoPhi.time = this.canvas.renderer.time; this._autoPhi.start = phiNow; this._autoPhi.end = phi; this._autoPhi.old = undefined; return this; } }, { key: 'rotate', value: function rotate(theta, phi) { return this.rotateTheta(theta).rotatePhi(phi); } }, { key: 'fov', value: function fov() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { value: 0, easing: this.easing, duration: this.duration }; var camera = this.camera || this.view.camera; if (typeof options === 'number') options = { value: options, easing: this.easing, duration: this.duration }; options.angle = options.angle || 0; this.automation = true; this._autoFov.ease = options.easing || this.easing; this._autoFov.duration = options.duration || this.duration; this._autoFov.time = this.canvas.renderer.time; this._autoFov.start = camera.fov; this._autoFov.end = options.value || camera.fov; return this; } }, { key: '_automate', value: function _automate(time, override) { var camera = this.camera || this.view.camera; var animates = false; // Focus if (!!this._autoFocus.time > 0) { var elapsed = override ? 1 : Math.min(1.1, (time - this._autoFocus.time) / this._autoFocus.duration); var value = this._autoFocus.start.clone().add(this._autoFocus.end.clone().sub(this._autoFocus.start).multiplyScalar(this._autoFocus.ease(elapsed))); this.target.copy(value); if (elapsed >= 1) this._autoFocus.time = 0; animates = true; } // Theta if (!!this._autoTheta.time > 0) { var _elapsed = override ? 1 : Math.min(1.1, (time - this._autoTheta.time) / this._autoTheta.duration); var _value = this._autoTheta.start + (this._autoTheta.end - this._autoTheta.start) * this._autoTheta.ease(_elapsed); animates = true; if (!this._autoTheta.old) { this._autoTheta.old = _value; this._thetaDelta = _value - this._autoTheta.start; } else { var oldVal = this._autoTheta.old; this._autoTheta.old = _value; this._thetaDelta = _value - oldVal; } if (_elapsed >= 1) this._autoTheta.time = 0; } // Phi if (!!this._autoPhi.time > 0) { var _elapsed2 = override ? 1 : Math.min(1.05, (time - this._autoPhi.time) / this._autoPhi.duration); var _value2 = this._autoPhi.start + (this._autoPhi.end - this._autoPhi.start) * this._autoPhi.ease(_elapsed2); animates = true; if (!this._autoPhi.old) { this._autoPhi.old = _value2; this._phiDelta = _value2 - this._autoPhi.start; } else { var _oldVal = this._autoPhi.old; this._autoPhi.old = _value2; this._phiDelta = _value2 - _oldVal; } if (_elapsed2 >= 1) this._autoPhi.time = 0; } // Zoom if (!!this._autoZoom.time > 0) { var _elapsed3 = override ? 1 : Math.min(1.05, (time - this._autoZoom.time) / this._autoZoom.duration); var _value3 = this._autoZoom.start + (this._autoZoom.end - this._autoZoom.start) * this._autoZoom.ease(_elapsed3); this._scale = _value3; if (_elapsed3 >= 1) this._autoZoom.time = 0; animates = true; } else { this._autoZoom.length = 0; } // Fov if (!!this._autoFov.time > 0) { var _elapsed4 = override ? 1 : Math.min(1.05, (time - this._autoFov.time) / this._autoFov.duration); var _value4 = this._autoFov.start + (this._autoFov.end - this._autoFov.start) * this._autoFov.ease(_elapsed4); camera.fov = _value4; camera.updateProjectionMatrix(); if (_elapsed4 >= 1) this._autoFov.time = 0; animates = true; } return animates; } }, { key: 'now', value: function now() { var time = this.canvas.renderer.time; // Focus if (!!this._autoFocus.time > 0) this._autoFocus.duration = 1; // Theta if (!!this._autoTheta.time > 0) this._autoTheta.duration = 1; // Phi if (!!this._autoPhi.time > 0) this._autoPhi.duration = 1; // Zoom if (!!this._autoZoom.time > 0) this._autoZoom.duration = 1; // Fov if (!!this._autoFov.time > 0) this._autoFov.duration = 1; this.update(time + 1, true); return this; } // pass in distance in world space to move left }, { key: 'panLeft', value: function panLeft(distance) { var camera = this.camera || this.view.camera; if (this.panMode === Orbit.PanMode.Horizontal || this.panMode === Orbit.PanMode.Both) { var te = camera.matrix.elements; // get X column of matrix this._panOffset.set(te[0], te[1], te[2]); this._panOffset.multiplyScalar(-distance); this._panning.add(this._panOffset); } } // pass in distance in world space to move up }, { key: 'panUp', value: function panUp(distance) { var camera = this.camera || this.view.camera; if (this.panMode === Orbit.PanMode.Vertical || this.panMode === Orbit.PanMode.Both) { var te = camera.matrix.elements; // get Y column of matrix this._panOffset.set(te[4], te[5], te[6]); this._panOffset.multiplyScalar(distance); this._panning.add(this._panOffset); } } // pass in x,y of change desired in pixel space, // right and down are positive }, { key: 'panPixels', value: function panPixels(deltaX, deltaY) { var camera = this.camera || this.view.camera; var position = camera.position, offset = position.clone().sub(this.target), targetDistance = offset.length(); // half of the fov is center to top of screen targetDistance *= Math.tan(camera.fov / 2 * Math.PI / 180.0); // we actually don't use screenWidth, since perspective camera is fixed to screen height this.panLeft(deltaX * targetDistance / (this.view.height || 1) * 2); this.panUp(deltaY * targetDistance / (this.view.height || 1) * 2); } }, { key: '_rotate', value: function _rotate() { if (!this.noRotate) { var delta = this._rotateEnd.clone().sub(this._rotateStart).multiplyScalar(this.dynamicDampingFactor); if (delta.length() > 0.01) { this._rotateStart.add(delta); if (this.dynamicDampingFactor < 1.00) { this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart); } else { this._rotateDelta = delta; } // rotating across whole screen goes 360 degrees around this._thetaDelta -= 2 * Math.PI * this._rotateDelta.x / (this.view.width || 1) * this.rotateSpeed; // rotating up and down along whole screen attempts to go 360, but limited to 180 this._phiDelta -= 2 * Math.PI * this._rotateDelta.y / (this.view.height || 1) * this.rotateSpeed; return true; } } return false; } }, { key: '_zoom', value: function _zoom(point) { var camera = this.camera || this.view.camera; if (!this.noZoom) { // By mousewheel var delta = this._wheelEnd.clone().sub(this._wheelStart).multiplyScalar(this.dynamicDampingFactor); if (delta.length() > 0.00001) { this._wheelStart.add(delta); this._wheelDelta.subVectors(this._wheelEnd, this._wheelStart); var factor = 1.0 + this._wheelDelta.y * this.zoomSpeed; if (factor !== 1.0 && factor > 0.0) { var distance = camera.zoom || camera.position.distanceTo(this.target); if (factor > 1 && distance > this.maxDistance) return false; if (!point) { if (this.zoomMode === Orbit.ZoomMode.Target && !!this.zoomTarget) point = this.zoomTarget.clone();else if (this.zoomMode === Orbit.ZoomMode.Mouse) { point = this._mousePosition.clone(); } else point = new THREE.Vector2(0, 0); //ndc coords of screen center } // this._scale = factor; //determine 3D position of mouse cursor (on target plane) var ndcTarget = this.target.clone().project(camera); var ndcPos = new THREE.Vector3(point.x, point.y, ndcTarget.z); var worldPos = ndcPos.clone().unproject(camera); //change eye-target distance this.distance *= factor; //adjust target point so that "point" stays in place this.target.lerpVectors(worldPos, this.target, factor); } return true; } // By touch if (this._state === Orbit.State.TouchZoomPan) { var factor = this._touchZoomDistanceStart / this._touchZoomDistanceEnd; if (factor != 0 && !isNaN(factor)) { this._touchZoomDistanceStart = this._touchZoomDistanceEnd; this._scale = factor; } return true; } } return false; } }, { key: '_pan', value: function _pan() { if (this.noPan === false) { var delta = this._panEnd.clone().sub(this._panStart).multiplyScalar(this.dynamicDampingFactor); if (delta.length() > 0.01) { this._panStart.add(delta); this._panDelta.subVectors(this._panEnd, this._panStart); this.panPixels(this._panDelta.x, this._panDelta.y); return true; } } return false; } }, { key: 'stop', value: function stop() { this.automation = false; this._autoZoom.time = 0; this._autoZoom.length = 0; this._autoFocus.time = 0; this._autoTheta.time = 0; this._autoPhi.time = 0; this._autoFov.time = 0; this._wheelStart.y = 0; this._wheelEnd.y = 0; //stgatilov: fix bug with zooming in the midst of dragging //there is no point in setting panStart to zero here /*this._panStart.set(0, 0); this._panEnd.set(0, 0);*/ this.emptyIdleCallbacks(); return this; } }, { key: 'store', value: function store(controls) { var camera = this.camera || this.view.camera; this._lastState = [camera.fov, this.target.clone(), this.target.distanceTo(camera.position), this.theta, this.phi]; if (!!controls) controls.fov(lastState[0]).focus(lastState[1]).zoom(lastState[2]).rotate(lastState[3], lastState[4]).now(); return this; } }, { key: 'back', value: function back() { if (this._lastState.length > 0) { this.automation = true; this.fov(lastState[0]).focus(lastState[1]).zoom(lastState[2]).rotate(lastState[3], lastState[4]); } return this; } }, { key: 'polar', value: function polar(min, max) { this.automation = true; this._polarStart.set(this.minPolarAngle, this.maxPolarAngle); this._polarEnd.set(min, max); return this; } }, { key: 'pan', value: function pan(x, y) { this.automation = true; this._panStart.set(0, 0); this._panEnd.set(x, y); return this; } }, { key: 'waitIdle', value: function waitIdle() { var _this = this; return new _promise2.default(function (resolve) { return _this._idleCallbacks.push(function () { return resolve(_this); }); }); } }, { key: 'wait', value: function wait() { return this.waitIdle(); } }, { key: 'waitActive', value: function waitActive() { var _this2 = this; return new _promise2.default(function (resolve) { return _this2._activeCallbacks.push(function () { return resolve(_this2); }); }); } }, { key: 'emptyIdleCallbacks', value: function emptyIdleCallbacks() { if (this._idleCallbacks.length > 0) for (var i = 0, l = this._idleCallbacks.length; i < l; i++) { this._idleCallbacks.shift()(); } } }, { key: 'emptyActiveCallbacks', value: function emptyActiveCallbacks() { if (this._activeCallbacks.length > 0) for (var i = 0, l = this._activeCallbacks.length; i < l; i++) { this._activeCallbacks.shift()(); } } }, { key: 'update', value: function update(time, override) { if (this.enabled && !this.automation && !this.interaction) return; var camera = this.camera || this.view.camera; var oldMotion = this.inMotion, position = camera.position; if (!!override) { this.view.invalidate(); } this.inMotion = false; this.distance = this._eye.copy(position).sub(this.target).length(); var focussed = this._automate(time, override), rotated = this._rotate(), zoomed = this._zoom(), panned = this._pan(); if (rotated || zoomed || panned || focussed || override) { this.inMotion = true; // rotate eye to "y-axis-is-up" space this._eye.applyQuaternion(this._quat); // angle from z-axis around y-axis this.theta = Math.atan2(this._eye.x, this._eye.z); // angle from y-axis this.phi = Math.atan2(Math.sqrt(this._eye.x * this._eye.x + this._eye.z * this._eye.z), this._eye.y); this.theta += this._thetaDelta; this.phi += this._phiDelta; // restrict phi to be between desired limits this.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this.phi)); // restrict phi to be between EPS and PI-EPS this.phi = Math.max(Orbit.Eps, Math.min(this.maxPolarAngle - Orbit.Eps, this.phi)); var radius = (!!this._autoZoom.length ? this._autoZoom.length : this.distance) * this._scale; // restrict radius to be between desired limits radius = Math.max(this.minDistance, Math.min(this.maxDistance, radius)); // move target to panned location this.target.add(this._panning); this._eye.x = radius * Math.sin(this.phi) * Math.sin(this.theta); this._eye.y = radius * Math.cos(this.phi); this._eye.z = radius * Math.sin(this.phi) * Math.cos(this.theta); // rotate eye back to "camera-up-vector-is-up" space this._eye.applyQuaternion(this._quatInverse); camera.position.copy(this.target).add(this._eye); camera.lookAt(this.target); camera.target.copy(this.target); this._thetaDelta = 0; this._phiDelta = 0; this._scale = 1; this._panning.set(0, 0, 0); if (oldMotion == false) { this.emptyActiveCallbacks(); } } else { this.interaction = false; this.automation = false; this.emptyIdleCallbacks(); } return this; } }, { key: 'onMouseDown', value: function onMouseDown(event) { if (this.enabled === false) return; this.automation = this.interaction = true; if (this.interactionStopsAutomation) this.stop(); // for convenience allow panning with MouseL if noRotate is active if (event.button === 0 && this.noRotate || event.button === 2) { if (this.noPan === true) return; this._state = Orbit.State.Pan; this._panStart.set(event.clientX, event.clientY); this._panEnd.copy(this._panStart); } else if (event.button === 0) { if (this.noRotate === true) return; this._state = Orbit.State.Rotate; this._rotateStart.set(event.clientX, event.clientY); this._rotateEnd.copy(this._rotateStart); } } }, { key: 'onMouseMove', value: function onMouseMove(event) { if (!this.enabled) return; this.automation = this.interaction = true; if (this._state === Orbit.State.Rotate) { this._rotateEnd.set(event.clientX, event.clientY); } else if (this._state === Orbit.State.Pan) { this._panEnd.set(event.clientX, event.clientY); } } }, { key: 'onMouseUp', value: function onMouseUp(event) { this.interaction = false; this._state = Orbit.State.None; } }, { key: 'onMouseWheel', value: function onMouseWheel(event) { if (this.enabled === false || this.noZoom === true) return; this.automation = this.interaction = true; if (this.interactionStopsAutomation) this.stop(); this._autoZoom.start = this._autoZoom.end = 0; this._wheelStart.y += event.delta * 0.01; this._mousePosition.x = event.offsetX / this.view.width * 2 - 1; this._mousePosition.y = -(event.offsetY / this.view.height) * 2 + 1; } }, { key: 'onTouchStart', value: function onTouchStart(event) { if (this.enabled === false) return; this.automation = this.interaction = true; if (this.interactionStopsAutomation) this.stop(); // for convenience allow panning mit MouseL if noRotate is active if (event.touches.length == 1 && this.noRotate || event.touches.length == 2) { this._state = Orbit.State.TouchZoomPan; if (event.touches.length == 2 && this.noZoom !== true) { var dx = event.touches[0].pageX - event.touches[1].pageX; var dy = event.touches[0].pageY - event.touches[1].pageY; this._touchZoomDistanceEnd = this._touchZoomDistanceStart = Math.sqrt(dx * dx + dy * dy); dx = (event.touches[0].pageX + event.touches[1].pageX) / 2; dy = (event.touches[0].pageY + event.touches[1].pageY) / 2; this._panStart.set(dx, dy); this._panEnd.copy(this._panStart); } else if (event.touches.length == 1 && this.noPan !== true) { this._touchZoomDistanceStart = this._touchZoomDistanceEnd = 0; this._panStart.set(event.touches[0].pageX, event.touches[0].pageY); } this._panEnd.copy(this._panStart); } else if (event.touches.length == 1) { if (this.noRotate === true) return; this._state = Orbit.State.TouchRotate; this._rotateStart.set(event.touches[0].pageX, event.touches[0].pageY); this._rotateEnd.copy(this._rotateStart); } else { this._state = Orbit.State.None; } } }, { key: 'onTouchMove', value: function onTouchMove(event) { if (this.enabled === false) return; this.automation = this.interaction = true; // for convenience allow panning mit MouseL if noRotate is active if (event.touches.length == 1 && this.noRotate || event.touches.length == 2) { if (this._state != Orbit.State.TouchZoomPan) return; if (event.touches.length == 2) { var dx = event.touches[0].pageX - event.touches[1].pageX; var dy = event.touches[0].pageY - event.touches[1].pageY; this._touchZoomDistanceEnd = Math.sqrt(dx * dx + dy * dy); dx = (event.touches[0].pageX + event.touches[1].pageX) / 2; dy = (event.touches[0].pageY + event.touches[1].pageY) / 2; this._panEnd.set(dx, dy); } else if (event.touches.length == 1) { this._touchZoomDistanceStart = this._touchZoomDistanceEnd = 0; this._panEnd.set(event.touches[0].pageX, event.touches[0].pageY); } } else if (event.touches.length == 1) { if (this._state != Orbit.State.TouchRotate) return; this._rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY); } else { this._state = Orbit.State.None; } } }, { key: 'onTouchEnd', value: function onTouchEnd(event) { this.interaction = false; if (this.enabled === false) return; switch (event.touches.length) { case 2: this._touchZoomDistanceStart = this._touchZoomDistanceEnd = 0; break; } this._state = Orbit.State.None; } }, { key: 'up', set: function set(value) { var camera = this.camera || this.view.camera; camera.up.copy(value); camera.updateProjectionMatrix(); this._quat = new THREE.Quaternion().setFromUnitVectors(camera.up, new THREE.Vector3(0, 1, 0)); this._quatInverse = this._quat.clone().inverse(); this.view.invalidate(); }, get: function get() { var camera = this.camera || this.view.camera; return camera.up.clone(); } }]); return Orbit; }(); exports.default = Orbit; Orbit.PanMode = { Horizontal: 1, Vertical: 2, Both: 3 }; Orbit.ZoomMode = { Center: 0, Mouse: 1, Target: 2 }; Orbit.Eps = 0.000001; Orbit.State = { None: -1, Rotate: 0, Zoom: 1, Pan: 2, TouchRotate: 3, TouchZoomPan: 4 };