babylon.arcRotateCamera.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var BABYLON;
  7. (function (BABYLON) {
  8. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  9. var ArcRotateCamera = (function (_super) {
  10. __extends(ArcRotateCamera, _super);
  11. function ArcRotateCamera(name, alpha, beta, radius, target, scene) {
  12. var _this = this;
  13. _super.call(this, name, BABYLON.Vector3.Zero(), scene);
  14. this.alpha = alpha;
  15. this.beta = beta;
  16. this.radius = radius;
  17. this.target = target;
  18. this.inertialAlphaOffset = 0;
  19. this.inertialBetaOffset = 0;
  20. this.inertialRadiusOffset = 0;
  21. this.lowerAlphaLimit = null;
  22. this.upperAlphaLimit = null;
  23. this.lowerBetaLimit = 0.01;
  24. this.upperBetaLimit = Math.PI;
  25. this.lowerRadiusLimit = null;
  26. this.upperRadiusLimit = null;
  27. this.angularSensibilityX = 1000.0;
  28. this.angularSensibilityY = 1000.0;
  29. this.wheelPrecision = 3.0;
  30. this.pinchPrecision = 2.0;
  31. this.panningSensibility = 50.0;
  32. this.inertialPanningX = 0;
  33. this.inertialPanningY = 0;
  34. this.keysUp = [38];
  35. this.keysDown = [40];
  36. this.keysLeft = [37];
  37. this.keysRight = [39];
  38. this.zoomOnFactor = 1;
  39. this.targetScreenOffset = BABYLON.Vector2.Zero();
  40. this.pinchInwards = true;
  41. this.allowUpsideDown = true;
  42. this._keys = [];
  43. this._viewMatrix = new BABYLON.Matrix();
  44. this._isRightClick = false;
  45. this._isCtrlPushed = false;
  46. this.checkCollisions = false;
  47. this.collisionRadius = new BABYLON.Vector3(0.5, 0.5, 0.5);
  48. this._collider = new BABYLON.Collider();
  49. this._previousPosition = BABYLON.Vector3.Zero();
  50. this._collisionVelocity = BABYLON.Vector3.Zero();
  51. this._newPosition = BABYLON.Vector3.Zero();
  52. this._onCollisionPositionChange = function (collisionId, newPosition, collidedMesh) {
  53. if (collidedMesh === void 0) { collidedMesh = null; }
  54. if (_this.getScene().workerCollisions && _this.checkCollisions) {
  55. newPosition.multiplyInPlace(_this._collider.radius);
  56. }
  57. if (!collidedMesh) {
  58. _this._previousPosition.copyFrom(_this.position);
  59. }
  60. else {
  61. _this.setPosition(_this.position);
  62. if (_this.onCollide) {
  63. _this.onCollide(collidedMesh);
  64. }
  65. }
  66. // Recompute because of constraints
  67. var cosa = Math.cos(_this.alpha);
  68. var sina = Math.sin(_this.alpha);
  69. var cosb = Math.cos(_this.beta);
  70. var sinb = Math.sin(_this.beta);
  71. var target = _this._getTargetPosition();
  72. target.addToRef(new BABYLON.Vector3(_this.radius * cosa * sinb, _this.radius * cosb, _this.radius * sina * sinb), _this._newPosition);
  73. _this.position.copyFrom(_this._newPosition);
  74. var up = _this.upVector;
  75. if (_this.allowUpsideDown && _this.beta < 0) {
  76. var up = up.clone();
  77. up = up.negate();
  78. }
  79. BABYLON.Matrix.LookAtLHToRef(_this.position, target, up, _this._viewMatrix);
  80. _this._viewMatrix.m[12] += _this.targetScreenOffset.x;
  81. _this._viewMatrix.m[13] += _this.targetScreenOffset.y;
  82. _this._collisionTriggered = false;
  83. };
  84. if (!this.target) {
  85. this.target = BABYLON.Vector3.Zero();
  86. }
  87. this.getViewMatrix();
  88. }
  89. Object.defineProperty(ArcRotateCamera.prototype, "angularSensibility", {
  90. //deprecated angularSensibility support
  91. get: function () {
  92. BABYLON.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
  93. return Math.max(this.angularSensibilityX, this.angularSensibilityY);
  94. },
  95. //deprecated angularSensibility support
  96. set: function (value) {
  97. BABYLON.Tools.Warn("Warning: angularSensibility is deprecated, use angularSensibilityX and angularSensibilityY instead.");
  98. this.angularSensibilityX = value;
  99. this.angularSensibilityY = value;
  100. },
  101. enumerable: true,
  102. configurable: true
  103. });
  104. ArcRotateCamera.prototype._getTargetPosition = function () {
  105. return this.target.position || this.target;
  106. };
  107. // Cache
  108. ArcRotateCamera.prototype._initCache = function () {
  109. _super.prototype._initCache.call(this);
  110. this._cache.target = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  111. this._cache.alpha = undefined;
  112. this._cache.beta = undefined;
  113. this._cache.radius = undefined;
  114. this._cache.targetScreenOffset = BABYLON.Vector2.Zero();
  115. };
  116. ArcRotateCamera.prototype._updateCache = function (ignoreParentClass) {
  117. if (!ignoreParentClass) {
  118. _super.prototype._updateCache.call(this);
  119. }
  120. this._cache.target.copyFrom(this._getTargetPosition());
  121. this._cache.alpha = this.alpha;
  122. this._cache.beta = this.beta;
  123. this._cache.radius = this.radius;
  124. this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset);
  125. };
  126. // Synchronized
  127. ArcRotateCamera.prototype._isSynchronizedViewMatrix = function () {
  128. if (!_super.prototype._isSynchronizedViewMatrix.call(this))
  129. return false;
  130. return this._cache.target.equals(this._getTargetPosition())
  131. && this._cache.alpha === this.alpha
  132. && this._cache.beta === this.beta
  133. && this._cache.radius === this.radius
  134. && this._cache.targetScreenOffset.equals(this.targetScreenOffset);
  135. };
  136. // Methods
  137. ArcRotateCamera.prototype.attachControl = function (element, noPreventDefault, useCtrlForPanning) {
  138. var _this = this;
  139. if (useCtrlForPanning === void 0) { useCtrlForPanning = true; }
  140. var cacheSoloPointer; // cache pointer object for better perf on camera rotation
  141. var previousPinchDistance = 0;
  142. var pointers = new BABYLON.SmartCollection();
  143. if (this._attachedElement) {
  144. return;
  145. }
  146. this._attachedElement = element;
  147. var engine = this.getEngine();
  148. if (this._onPointerDown === undefined) {
  149. this._onPointerDown = function (evt) {
  150. // Manage panning with right click
  151. _this._isRightClick = evt.button === 2 ? true : false;
  152. // manage pointers
  153. pointers.add(evt.pointerId, { x: evt.clientX, y: evt.clientY, type: evt.pointerType });
  154. cacheSoloPointer = pointers.item(evt.pointerId);
  155. if (!noPreventDefault) {
  156. evt.preventDefault();
  157. }
  158. };
  159. this._onPointerUp = function (evt) {
  160. cacheSoloPointer = null;
  161. previousPinchDistance = 0;
  162. //would be better to use pointers.remove(evt.pointerId) for multitouch gestures,
  163. //but emptying completly pointers collection is required to fix a bug on iPhone :
  164. //when changing orientation while pinching camera, one pointer stay pressed forever if we don't release all pointers
  165. //will be ok to put back pointers.remove(evt.pointerId); when iPhone bug corrected
  166. pointers.empty();
  167. if (!noPreventDefault) {
  168. evt.preventDefault();
  169. }
  170. };
  171. this._onContextMenu = function (evt) {
  172. evt.preventDefault();
  173. };
  174. this._onPointerMove = function (evt) {
  175. if (!noPreventDefault) {
  176. evt.preventDefault();
  177. }
  178. switch (pointers.count) {
  179. case 1:
  180. if (this.panningSensibility !== 0 && ((_this._isCtrlPushed && useCtrlForPanning) || (!useCtrlForPanning && _this._isRightClick))) {
  181. _this.inertialPanningX += -(evt.clientX - cacheSoloPointer.x) / _this.panningSensibility;
  182. _this.inertialPanningY += (evt.clientY - cacheSoloPointer.y) / _this.panningSensibility;
  183. }
  184. else {
  185. var offsetX = evt.clientX - cacheSoloPointer.x;
  186. var offsetY = evt.clientY - cacheSoloPointer.y;
  187. _this.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
  188. _this.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
  189. }
  190. cacheSoloPointer.x = evt.clientX;
  191. cacheSoloPointer.y = evt.clientY;
  192. break;
  193. case 2:
  194. //if (noPreventDefault) { evt.preventDefault(); } //if pinch gesture, could be usefull to force preventDefault to avoid html page scroll/zoom in some mobile browsers
  195. pointers.item(evt.pointerId).x = evt.clientX;
  196. pointers.item(evt.pointerId).y = evt.clientY;
  197. var direction = _this.pinchInwards ? 1 : -1;
  198. var distX = pointers.getItemByIndex(0).x - pointers.getItemByIndex(1).x;
  199. var distY = pointers.getItemByIndex(0).y - pointers.getItemByIndex(1).y;
  200. var pinchSquaredDistance = (distX * distX) + (distY * distY);
  201. if (previousPinchDistance === 0) {
  202. previousPinchDistance = pinchSquaredDistance;
  203. return;
  204. }
  205. if (pinchSquaredDistance !== previousPinchDistance) {
  206. _this.inertialRadiusOffset += (pinchSquaredDistance - previousPinchDistance) / (_this.pinchPrecision * _this.wheelPrecision * ((_this.angularSensibilityX + _this.angularSensibilityY) / 2) * direction);
  207. previousPinchDistance = pinchSquaredDistance;
  208. }
  209. break;
  210. default:
  211. if (pointers.item(evt.pointerId)) {
  212. pointers.item(evt.pointerId).x = evt.clientX;
  213. pointers.item(evt.pointerId).y = evt.clientY;
  214. }
  215. }
  216. };
  217. this._onMouseMove = function (evt) {
  218. if (!engine.isPointerLock) {
  219. return;
  220. }
  221. var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
  222. var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
  223. _this.inertialAlphaOffset -= offsetX / _this.angularSensibilityX;
  224. _this.inertialBetaOffset -= offsetY / _this.angularSensibilityY;
  225. if (!noPreventDefault) {
  226. evt.preventDefault();
  227. }
  228. };
  229. this._wheel = function (event) {
  230. var delta = 0;
  231. if (event.wheelDelta) {
  232. delta = event.wheelDelta / (_this.wheelPrecision * 40);
  233. }
  234. else if (event.detail) {
  235. delta = -event.detail / _this.wheelPrecision;
  236. }
  237. if (delta)
  238. _this.inertialRadiusOffset += delta;
  239. if (event.preventDefault) {
  240. if (!noPreventDefault) {
  241. event.preventDefault();
  242. }
  243. }
  244. };
  245. this._onKeyDown = function (evt) {
  246. _this._isCtrlPushed = evt.ctrlKey;
  247. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  248. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  249. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  250. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  251. var index = _this._keys.indexOf(evt.keyCode);
  252. if (index === -1) {
  253. _this._keys.push(evt.keyCode);
  254. }
  255. if (evt.preventDefault) {
  256. if (!noPreventDefault) {
  257. evt.preventDefault();
  258. }
  259. }
  260. }
  261. };
  262. this._onKeyUp = function (evt) {
  263. _this._isCtrlPushed = evt.ctrlKey;
  264. if (_this.keysUp.indexOf(evt.keyCode) !== -1 ||
  265. _this.keysDown.indexOf(evt.keyCode) !== -1 ||
  266. _this.keysLeft.indexOf(evt.keyCode) !== -1 ||
  267. _this.keysRight.indexOf(evt.keyCode) !== -1) {
  268. var index = _this._keys.indexOf(evt.keyCode);
  269. if (index >= 0) {
  270. _this._keys.splice(index, 1);
  271. }
  272. if (evt.preventDefault) {
  273. if (!noPreventDefault) {
  274. evt.preventDefault();
  275. }
  276. }
  277. }
  278. };
  279. this._onLostFocus = function () {
  280. _this._keys = [];
  281. pointers.empty();
  282. previousPinchDistance = 0;
  283. cacheSoloPointer = null;
  284. };
  285. this._onGestureStart = function (e) {
  286. if (window.MSGesture === undefined) {
  287. return;
  288. }
  289. if (!_this._MSGestureHandler) {
  290. _this._MSGestureHandler = new MSGesture();
  291. _this._MSGestureHandler.target = element;
  292. }
  293. _this._MSGestureHandler.addPointer(e.pointerId);
  294. };
  295. this._onGesture = function (e) {
  296. _this.radius *= e.scale;
  297. if (e.preventDefault) {
  298. if (!noPreventDefault) {
  299. e.stopPropagation();
  300. e.preventDefault();
  301. }
  302. }
  303. };
  304. this._reset = function () {
  305. _this._keys = [];
  306. _this.inertialAlphaOffset = 0;
  307. _this.inertialBetaOffset = 0;
  308. _this.inertialRadiusOffset = 0;
  309. pointers.empty();
  310. previousPinchDistance = 0;
  311. cacheSoloPointer = null;
  312. };
  313. }
  314. if (!useCtrlForPanning) {
  315. element.addEventListener("contextmenu", this._onContextMenu, false);
  316. }
  317. element.addEventListener(eventPrefix + "down", this._onPointerDown, false);
  318. element.addEventListener(eventPrefix + "up", this._onPointerUp, false);
  319. element.addEventListener(eventPrefix + "out", this._onPointerUp, false);
  320. element.addEventListener(eventPrefix + "move", this._onPointerMove, false);
  321. element.addEventListener("mousemove", this._onMouseMove, false);
  322. element.addEventListener("MSPointerDown", this._onGestureStart, false);
  323. element.addEventListener("MSGestureChange", this._onGesture, false);
  324. element.addEventListener('mousewheel', this._wheel, false);
  325. element.addEventListener('DOMMouseScroll', this._wheel, false);
  326. BABYLON.Tools.RegisterTopRootEvents([
  327. { name: "keydown", handler: this._onKeyDown },
  328. { name: "keyup", handler: this._onKeyUp },
  329. { name: "blur", handler: this._onLostFocus }
  330. ]);
  331. };
  332. ArcRotateCamera.prototype.detachControl = function (element) {
  333. if (this._attachedElement !== element) {
  334. return;
  335. }
  336. element.removeEventListener("contextmenu", this._onContextMenu);
  337. element.removeEventListener(eventPrefix + "down", this._onPointerDown);
  338. element.removeEventListener(eventPrefix + "up", this._onPointerUp);
  339. element.removeEventListener(eventPrefix + "out", this._onPointerUp);
  340. element.removeEventListener(eventPrefix + "move", this._onPointerMove);
  341. element.removeEventListener("mousemove", this._onMouseMove);
  342. element.removeEventListener("MSPointerDown", this._onGestureStart);
  343. element.removeEventListener("MSGestureChange", this._onGesture);
  344. element.removeEventListener('mousewheel', this._wheel);
  345. element.removeEventListener('DOMMouseScroll', this._wheel);
  346. BABYLON.Tools.UnregisterTopRootEvents([
  347. { name: "keydown", handler: this._onKeyDown },
  348. { name: "keyup", handler: this._onKeyUp },
  349. { name: "blur", handler: this._onLostFocus }
  350. ]);
  351. this._MSGestureHandler = null;
  352. this._attachedElement = null;
  353. if (this._reset) {
  354. this._reset();
  355. }
  356. };
  357. ArcRotateCamera.prototype._checkInputs = function () {
  358. //if (async) collision inspection was triggered, don't update the camera's position - until the collision callback was called.
  359. if (this._collisionTriggered) {
  360. return;
  361. }
  362. // Keyboard
  363. for (var index = 0; index < this._keys.length; index++) {
  364. var keyCode = this._keys[index];
  365. if (this.keysLeft.indexOf(keyCode) !== -1) {
  366. this.inertialAlphaOffset -= 0.01;
  367. }
  368. else if (this.keysUp.indexOf(keyCode) !== -1) {
  369. this.inertialBetaOffset -= 0.01;
  370. }
  371. else if (this.keysRight.indexOf(keyCode) !== -1) {
  372. this.inertialAlphaOffset += 0.01;
  373. }
  374. else if (this.keysDown.indexOf(keyCode) !== -1) {
  375. this.inertialBetaOffset += 0.01;
  376. }
  377. }
  378. // Inertia
  379. if (this.inertialAlphaOffset !== 0 || this.inertialBetaOffset !== 0 || this.inertialRadiusOffset != 0) {
  380. this.alpha += this.beta <= 0 ? -this.inertialAlphaOffset : this.inertialAlphaOffset;
  381. this.beta += this.inertialBetaOffset;
  382. this.radius -= this.inertialRadiusOffset;
  383. this.inertialAlphaOffset *= this.inertia;
  384. this.inertialBetaOffset *= this.inertia;
  385. this.inertialRadiusOffset *= this.inertia;
  386. if (Math.abs(this.inertialAlphaOffset) < BABYLON.Engine.Epsilon)
  387. this.inertialAlphaOffset = 0;
  388. if (Math.abs(this.inertialBetaOffset) < BABYLON.Engine.Epsilon)
  389. this.inertialBetaOffset = 0;
  390. if (Math.abs(this.inertialRadiusOffset) < BABYLON.Engine.Epsilon)
  391. this.inertialRadiusOffset = 0;
  392. }
  393. // Panning inertia
  394. if (this.inertialPanningX !== 0 || this.inertialPanningY !== 0) {
  395. if (!this._localDirection) {
  396. this._localDirection = BABYLON.Vector3.Zero();
  397. this._transformedDirection = BABYLON.Vector3.Zero();
  398. }
  399. this.inertialPanningX *= this.inertia;
  400. this.inertialPanningY *= this.inertia;
  401. if (Math.abs(this.inertialPanningX) < BABYLON.Engine.Epsilon)
  402. this.inertialPanningX = 0;
  403. if (Math.abs(this.inertialPanningY) < BABYLON.Engine.Epsilon)
  404. this.inertialPanningY = 0;
  405. this._localDirection.copyFromFloats(this.inertialPanningX, this.inertialPanningY, 0);
  406. this._viewMatrix.invertToRef(this._cameraTransformMatrix);
  407. BABYLON.Vector3.TransformNormalToRef(this._localDirection, this._cameraTransformMatrix, this._transformedDirection);
  408. this.target.addInPlace(this._transformedDirection);
  409. }
  410. // Limits
  411. this._checkLimits();
  412. _super.prototype._checkInputs.call(this);
  413. };
  414. ArcRotateCamera.prototype._checkLimits = function () {
  415. if (this.lowerBetaLimit === null || this.lowerBetaLimit === undefined) {
  416. if (this.allowUpsideDown && this.beta > Math.PI) {
  417. this.beta = this.beta - (2 * Math.PI);
  418. }
  419. }
  420. else {
  421. if (this.beta < this.lowerBetaLimit) {
  422. this.beta = this.lowerBetaLimit;
  423. }
  424. }
  425. if (this.upperBetaLimit === null || this.upperBetaLimit === undefined) {
  426. if (this.allowUpsideDown && this.beta < -Math.PI) {
  427. this.beta = this.beta + (2 * Math.PI);
  428. }
  429. }
  430. else {
  431. if (this.beta > this.upperBetaLimit) {
  432. this.beta = this.upperBetaLimit;
  433. }
  434. }
  435. if (this.lowerAlphaLimit && this.alpha < this.lowerAlphaLimit) {
  436. this.alpha = this.lowerAlphaLimit;
  437. }
  438. if (this.upperAlphaLimit && this.alpha > this.upperAlphaLimit) {
  439. this.alpha = this.upperAlphaLimit;
  440. }
  441. if (this.lowerRadiusLimit && this.radius < this.lowerRadiusLimit) {
  442. this.radius = this.lowerRadiusLimit;
  443. }
  444. if (this.upperRadiusLimit && this.radius > this.upperRadiusLimit) {
  445. this.radius = this.upperRadiusLimit;
  446. }
  447. };
  448. ArcRotateCamera.prototype.setPosition = function (position) {
  449. var radiusv3 = position.subtract(this._getTargetPosition());
  450. this.radius = radiusv3.length();
  451. // Alpha
  452. this.alpha = Math.acos(radiusv3.x / Math.sqrt(Math.pow(radiusv3.x, 2) + Math.pow(radiusv3.z, 2)));
  453. if (radiusv3.z < 0) {
  454. this.alpha = 2 * Math.PI - this.alpha;
  455. }
  456. // Beta
  457. this.beta = Math.acos(radiusv3.y / this.radius);
  458. this._checkLimits();
  459. };
  460. ArcRotateCamera.prototype.setTarget = function (target) {
  461. this.target = target;
  462. };
  463. ArcRotateCamera.prototype._getViewMatrix = function () {
  464. // Compute
  465. var cosa = Math.cos(this.alpha);
  466. var sina = Math.sin(this.alpha);
  467. var cosb = Math.cos(this.beta);
  468. var sinb = Math.sin(this.beta);
  469. var target = this._getTargetPosition();
  470. target.addToRef(new BABYLON.Vector3(this.radius * cosa * sinb, this.radius * cosb, this.radius * sina * sinb), this._newPosition);
  471. if (this.getScene().collisionsEnabled && this.checkCollisions) {
  472. this._collider.radius = this.collisionRadius;
  473. this._newPosition.subtractToRef(this.position, this._collisionVelocity);
  474. this._collisionTriggered = true;
  475. this.getScene().collisionCoordinator.getNewPosition(this.position, this._collisionVelocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
  476. }
  477. else {
  478. this.position.copyFrom(this._newPosition);
  479. var up = this.upVector;
  480. if (this.allowUpsideDown && this.beta < 0) {
  481. var up = up.clone();
  482. up = up.negate();
  483. }
  484. BABYLON.Matrix.LookAtLHToRef(this.position, target, up, this._viewMatrix);
  485. this._viewMatrix.m[12] += this.targetScreenOffset.x;
  486. this._viewMatrix.m[13] += this.targetScreenOffset.y;
  487. }
  488. return this._viewMatrix;
  489. };
  490. ArcRotateCamera.prototype.zoomOn = function (meshes, doNotUpdateMaxZ) {
  491. if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
  492. meshes = meshes || this.getScene().meshes;
  493. var minMaxVector = BABYLON.Mesh.MinMax(meshes);
  494. var distance = BABYLON.Vector3.Distance(minMaxVector.min, minMaxVector.max);
  495. this.radius = distance * this.zoomOnFactor;
  496. this.focusOn({ min: minMaxVector.min, max: minMaxVector.max, distance: distance }, doNotUpdateMaxZ);
  497. };
  498. ArcRotateCamera.prototype.focusOn = function (meshesOrMinMaxVectorAndDistance, doNotUpdateMaxZ) {
  499. if (doNotUpdateMaxZ === void 0) { doNotUpdateMaxZ = false; }
  500. var meshesOrMinMaxVector;
  501. var distance;
  502. if (meshesOrMinMaxVectorAndDistance.min === undefined) {
  503. meshesOrMinMaxVector = meshesOrMinMaxVectorAndDistance || this.getScene().meshes;
  504. meshesOrMinMaxVector = BABYLON.Mesh.MinMax(meshesOrMinMaxVector);
  505. distance = BABYLON.Vector3.Distance(meshesOrMinMaxVector.min, meshesOrMinMaxVector.max);
  506. }
  507. else {
  508. meshesOrMinMaxVector = meshesOrMinMaxVectorAndDistance;
  509. distance = meshesOrMinMaxVectorAndDistance.distance;
  510. }
  511. this.target = BABYLON.Mesh.Center(meshesOrMinMaxVector);
  512. if (!doNotUpdateMaxZ) {
  513. this.maxZ = distance * 2;
  514. }
  515. };
  516. /**
  517. * @override
  518. * Override Camera.createRigCamera
  519. */
  520. ArcRotateCamera.prototype.createRigCamera = function (name, cameraIndex) {
  521. switch (this.cameraRigMode) {
  522. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  523. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  524. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  525. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  526. case BABYLON.Camera.RIG_MODE_VR:
  527. var alphaShift = this._cameraRigParams.stereoHalfAngle * (cameraIndex === 0 ? 1 : -1);
  528. return new ArcRotateCamera(name, this.alpha + alphaShift, this.beta, this.radius, this.target, this.getScene());
  529. }
  530. };
  531. /**
  532. * @override
  533. * Override Camera._updateRigCameras
  534. */
  535. ArcRotateCamera.prototype._updateRigCameras = function () {
  536. switch (this.cameraRigMode) {
  537. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  538. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  539. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  540. case BABYLON.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  541. case BABYLON.Camera.RIG_MODE_VR:
  542. var camLeft = this._rigCameras[0];
  543. var camRight = this._rigCameras[1];
  544. camLeft.alpha = this.alpha - this._cameraRigParams.stereoHalfAngle;
  545. camRight.alpha = this.alpha + this._cameraRigParams.stereoHalfAngle;
  546. camLeft.beta = camRight.beta = this.beta;
  547. camLeft.radius = camRight.radius = this.radius;
  548. break;
  549. }
  550. _super.prototype._updateRigCameras.call(this);
  551. };
  552. return ArcRotateCamera;
  553. })(BABYLON.TargetCamera);
  554. BABYLON.ArcRotateCamera = ArcRotateCamera;
  555. })(BABYLON || (BABYLON = {}));