babylon.arcRotateCamera.js 28 KB

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