babylon.camera.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 VRCameraMetrics = (function () {
  10. function VRCameraMetrics() {
  11. this.compensateDistorsion = true;
  12. }
  13. Object.defineProperty(VRCameraMetrics.prototype, "aspectRatio", {
  14. get: function () {
  15. return this.hResolution / (2 * this.vResolution);
  16. },
  17. enumerable: true,
  18. configurable: true
  19. });
  20. Object.defineProperty(VRCameraMetrics.prototype, "aspectRatioFov", {
  21. get: function () {
  22. return (2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance)));
  23. },
  24. enumerable: true,
  25. configurable: true
  26. });
  27. Object.defineProperty(VRCameraMetrics.prototype, "leftHMatrix", {
  28. get: function () {
  29. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  30. var h = (4 * meters) / this.hScreenSize;
  31. return BABYLON.Matrix.Translation(h, 0, 0);
  32. },
  33. enumerable: true,
  34. configurable: true
  35. });
  36. Object.defineProperty(VRCameraMetrics.prototype, "rightHMatrix", {
  37. get: function () {
  38. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  39. var h = (4 * meters) / this.hScreenSize;
  40. return BABYLON.Matrix.Translation(-h, 0, 0);
  41. },
  42. enumerable: true,
  43. configurable: true
  44. });
  45. Object.defineProperty(VRCameraMetrics.prototype, "leftPreViewMatrix", {
  46. get: function () {
  47. return BABYLON.Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
  48. },
  49. enumerable: true,
  50. configurable: true
  51. });
  52. Object.defineProperty(VRCameraMetrics.prototype, "rightPreViewMatrix", {
  53. get: function () {
  54. return BABYLON.Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
  55. },
  56. enumerable: true,
  57. configurable: true
  58. });
  59. VRCameraMetrics.GetDefault = function () {
  60. var result = new VRCameraMetrics();
  61. result.hResolution = 1280;
  62. result.vResolution = 800;
  63. result.hScreenSize = 0.149759993;
  64. result.vScreenSize = 0.0935999975;
  65. result.vScreenCenter = 0.0467999987,
  66. result.eyeToScreenDistance = 0.0410000011;
  67. result.lensSeparationDistance = 0.0635000020;
  68. result.interpupillaryDistance = 0.0640000030;
  69. result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
  70. result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
  71. result.postProcessScaleFactor = 1.714605507808412;
  72. result.lensCenterOffset = 0.151976421;
  73. return result;
  74. };
  75. return VRCameraMetrics;
  76. })();
  77. BABYLON.VRCameraMetrics = VRCameraMetrics;
  78. var Camera = (function (_super) {
  79. __extends(Camera, _super);
  80. function Camera(name, position, scene) {
  81. _super.call(this, name, scene);
  82. this.position = position;
  83. // Members
  84. this.upVector = BABYLON.Vector3.Up();
  85. this.orthoLeft = null;
  86. this.orthoRight = null;
  87. this.orthoBottom = null;
  88. this.orthoTop = null;
  89. this.fov = 0.8;
  90. this.minZ = 1.0;
  91. this.maxZ = 10000.0;
  92. this.inertia = 0.9;
  93. this.mode = Camera.PERSPECTIVE_CAMERA;
  94. this.isIntermediate = false;
  95. this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
  96. this.layerMask = 0x0FFFFFFF;
  97. this.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
  98. // Camera rig members
  99. this.cameraRigMode = Camera.RIG_MODE_NONE;
  100. this._rigCameras = new Array();
  101. // Cache
  102. this._computedViewMatrix = BABYLON.Matrix.Identity();
  103. this._projectionMatrix = new BABYLON.Matrix();
  104. this._postProcesses = new Array();
  105. this._postProcessesTakenIndices = [];
  106. this._activeMeshes = new BABYLON.SmartArray(256);
  107. this._globalPosition = BABYLON.Vector3.Zero();
  108. scene.addCamera(this);
  109. if (!scene.activeCamera) {
  110. scene.activeCamera = this;
  111. }
  112. }
  113. Object.defineProperty(Camera, "PERSPECTIVE_CAMERA", {
  114. get: function () {
  115. return Camera._PERSPECTIVE_CAMERA;
  116. },
  117. enumerable: true,
  118. configurable: true
  119. });
  120. Object.defineProperty(Camera, "ORTHOGRAPHIC_CAMERA", {
  121. get: function () {
  122. return Camera._ORTHOGRAPHIC_CAMERA;
  123. },
  124. enumerable: true,
  125. configurable: true
  126. });
  127. Object.defineProperty(Camera, "FOVMODE_VERTICAL_FIXED", {
  128. get: function () {
  129. return Camera._FOVMODE_VERTICAL_FIXED;
  130. },
  131. enumerable: true,
  132. configurable: true
  133. });
  134. Object.defineProperty(Camera, "FOVMODE_HORIZONTAL_FIXED", {
  135. get: function () {
  136. return Camera._FOVMODE_HORIZONTAL_FIXED;
  137. },
  138. enumerable: true,
  139. configurable: true
  140. });
  141. Object.defineProperty(Camera, "RIG_MODE_NONE", {
  142. get: function () {
  143. return Camera._RIG_MODE_NONE;
  144. },
  145. enumerable: true,
  146. configurable: true
  147. });
  148. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_ANAGLYPH", {
  149. get: function () {
  150. return Camera._RIG_MODE_STEREOSCOPIC_ANAGLYPH;
  151. },
  152. enumerable: true,
  153. configurable: true
  154. });
  155. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL", {
  156. get: function () {
  157. return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL;
  158. },
  159. enumerable: true,
  160. configurable: true
  161. });
  162. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED", {
  163. get: function () {
  164. return Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;
  165. },
  166. enumerable: true,
  167. configurable: true
  168. });
  169. Object.defineProperty(Camera, "RIG_MODE_STEREOSCOPIC_OVERUNDER", {
  170. get: function () {
  171. return Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER;
  172. },
  173. enumerable: true,
  174. configurable: true
  175. });
  176. Object.defineProperty(Camera, "RIG_MODE_VR", {
  177. get: function () {
  178. return Camera._RIG_MODE_VR;
  179. },
  180. enumerable: true,
  181. configurable: true
  182. });
  183. Object.defineProperty(Camera.prototype, "globalPosition", {
  184. get: function () {
  185. return this._globalPosition;
  186. },
  187. enumerable: true,
  188. configurable: true
  189. });
  190. Camera.prototype.getActiveMeshes = function () {
  191. return this._activeMeshes;
  192. };
  193. Camera.prototype.isActiveMesh = function (mesh) {
  194. return (this._activeMeshes.indexOf(mesh) !== -1);
  195. };
  196. //Cache
  197. Camera.prototype._initCache = function () {
  198. _super.prototype._initCache.call(this);
  199. this._cache.position = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  200. this._cache.upVector = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
  201. this._cache.mode = undefined;
  202. this._cache.minZ = undefined;
  203. this._cache.maxZ = undefined;
  204. this._cache.fov = undefined;
  205. this._cache.aspectRatio = undefined;
  206. this._cache.orthoLeft = undefined;
  207. this._cache.orthoRight = undefined;
  208. this._cache.orthoBottom = undefined;
  209. this._cache.orthoTop = undefined;
  210. this._cache.renderWidth = undefined;
  211. this._cache.renderHeight = undefined;
  212. };
  213. Camera.prototype._updateCache = function (ignoreParentClass) {
  214. if (!ignoreParentClass) {
  215. _super.prototype._updateCache.call(this);
  216. }
  217. var engine = this.getEngine();
  218. this._cache.position.copyFrom(this.position);
  219. this._cache.upVector.copyFrom(this.upVector);
  220. this._cache.mode = this.mode;
  221. this._cache.minZ = this.minZ;
  222. this._cache.maxZ = this.maxZ;
  223. this._cache.fov = this.fov;
  224. this._cache.aspectRatio = engine.getAspectRatio(this);
  225. this._cache.orthoLeft = this.orthoLeft;
  226. this._cache.orthoRight = this.orthoRight;
  227. this._cache.orthoBottom = this.orthoBottom;
  228. this._cache.orthoTop = this.orthoTop;
  229. this._cache.renderWidth = engine.getRenderWidth();
  230. this._cache.renderHeight = engine.getRenderHeight();
  231. };
  232. Camera.prototype._updateFromScene = function () {
  233. this.updateCache();
  234. this._update();
  235. };
  236. // Synchronized
  237. Camera.prototype._isSynchronized = function () {
  238. return this._isSynchronizedViewMatrix() && this._isSynchronizedProjectionMatrix();
  239. };
  240. Camera.prototype._isSynchronizedViewMatrix = function () {
  241. if (!_super.prototype._isSynchronized.call(this))
  242. return false;
  243. return this._cache.position.equals(this.position)
  244. && this._cache.upVector.equals(this.upVector)
  245. && this.isSynchronizedWithParent();
  246. };
  247. Camera.prototype._isSynchronizedProjectionMatrix = function () {
  248. var check = this._cache.mode === this.mode
  249. && this._cache.minZ === this.minZ
  250. && this._cache.maxZ === this.maxZ;
  251. if (!check) {
  252. return false;
  253. }
  254. var engine = this.getEngine();
  255. if (this.mode === Camera.PERSPECTIVE_CAMERA) {
  256. check = this._cache.fov === this.fov
  257. && this._cache.aspectRatio === engine.getAspectRatio(this);
  258. }
  259. else {
  260. check = this._cache.orthoLeft === this.orthoLeft
  261. && this._cache.orthoRight === this.orthoRight
  262. && this._cache.orthoBottom === this.orthoBottom
  263. && this._cache.orthoTop === this.orthoTop
  264. && this._cache.renderWidth === engine.getRenderWidth()
  265. && this._cache.renderHeight === engine.getRenderHeight();
  266. }
  267. return check;
  268. };
  269. // Controls
  270. Camera.prototype.attachControl = function (element) {
  271. };
  272. Camera.prototype.detachControl = function (element) {
  273. };
  274. Camera.prototype._update = function () {
  275. this._checkInputs();
  276. if (this.cameraRigMode !== Camera.RIG_MODE_NONE) {
  277. this._updateRigCameras();
  278. }
  279. };
  280. Camera.prototype._checkInputs = function () {
  281. };
  282. Camera.prototype.attachPostProcess = function (postProcess, insertAt) {
  283. if (insertAt === void 0) { insertAt = null; }
  284. if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
  285. BABYLON.Tools.Error("You're trying to reuse a post process not defined as reusable.");
  286. return 0;
  287. }
  288. if (insertAt == null || insertAt < 0) {
  289. this._postProcesses.push(postProcess);
  290. this._postProcessesTakenIndices.push(this._postProcesses.length - 1);
  291. return this._postProcesses.length - 1;
  292. }
  293. var add = 0;
  294. if (this._postProcesses[insertAt]) {
  295. var start = this._postProcesses.length - 1;
  296. for (var i = start; i >= insertAt + 1; --i) {
  297. this._postProcesses[i + 1] = this._postProcesses[i];
  298. }
  299. add = 1;
  300. }
  301. for (i = 0; i < this._postProcessesTakenIndices.length; ++i) {
  302. if (this._postProcessesTakenIndices[i] < insertAt) {
  303. continue;
  304. }
  305. start = this._postProcessesTakenIndices.length - 1;
  306. for (var j = start; j >= i; --j) {
  307. this._postProcessesTakenIndices[j + 1] = this._postProcessesTakenIndices[j] + add;
  308. }
  309. this._postProcessesTakenIndices[i] = insertAt;
  310. break;
  311. }
  312. if (!add && this._postProcessesTakenIndices.indexOf(insertAt) == -1) {
  313. this._postProcessesTakenIndices.push(insertAt);
  314. }
  315. var result = insertAt + add;
  316. this._postProcesses[result] = postProcess;
  317. return result;
  318. };
  319. Camera.prototype.detachPostProcess = function (postProcess, atIndices) {
  320. if (atIndices === void 0) { atIndices = null; }
  321. var result = [];
  322. if (!atIndices) {
  323. var length = this._postProcesses.length;
  324. for (var i = 0; i < length; i++) {
  325. if (this._postProcesses[i] !== postProcess) {
  326. continue;
  327. }
  328. delete this._postProcesses[i];
  329. var index = this._postProcessesTakenIndices.indexOf(i);
  330. this._postProcessesTakenIndices.splice(index, 1);
  331. }
  332. }
  333. else {
  334. atIndices = (atIndices instanceof Array) ? atIndices : [atIndices];
  335. for (i = 0; i < atIndices.length; i++) {
  336. var foundPostProcess = this._postProcesses[atIndices[i]];
  337. if (foundPostProcess !== postProcess) {
  338. result.push(i);
  339. continue;
  340. }
  341. delete this._postProcesses[atIndices[i]];
  342. index = this._postProcessesTakenIndices.indexOf(atIndices[i]);
  343. this._postProcessesTakenIndices.splice(index, 1);
  344. }
  345. }
  346. return result;
  347. };
  348. Camera.prototype.getWorldMatrix = function () {
  349. if (!this._worldMatrix) {
  350. this._worldMatrix = BABYLON.Matrix.Identity();
  351. }
  352. var viewMatrix = this.getViewMatrix();
  353. viewMatrix.invertToRef(this._worldMatrix);
  354. return this._worldMatrix;
  355. };
  356. Camera.prototype._getViewMatrix = function () {
  357. return BABYLON.Matrix.Identity();
  358. };
  359. Camera.prototype.getViewMatrix = function (force) {
  360. this._computedViewMatrix = this._computeViewMatrix(force);
  361. if (!force && this._isSynchronizedViewMatrix()) {
  362. return this._computedViewMatrix;
  363. }
  364. if (!this.parent || !this.parent.getWorldMatrix) {
  365. this._globalPosition.copyFrom(this.position);
  366. }
  367. else {
  368. if (!this._worldMatrix) {
  369. this._worldMatrix = BABYLON.Matrix.Identity();
  370. }
  371. this._computedViewMatrix.invertToRef(this._worldMatrix);
  372. this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
  373. this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
  374. this._computedViewMatrix.invert();
  375. this._markSyncedWithParent();
  376. }
  377. this._currentRenderId = this.getScene().getRenderId();
  378. return this._computedViewMatrix;
  379. };
  380. Camera.prototype._computeViewMatrix = function (force) {
  381. if (!force && this._isSynchronizedViewMatrix()) {
  382. return this._computedViewMatrix;
  383. }
  384. this._computedViewMatrix = this._getViewMatrix();
  385. this._currentRenderId = this.getScene().getRenderId();
  386. return this._computedViewMatrix;
  387. };
  388. Camera.prototype.getProjectionMatrix = function (force) {
  389. if (!force && this._isSynchronizedProjectionMatrix()) {
  390. return this._projectionMatrix;
  391. }
  392. var engine = this.getEngine();
  393. if (this.mode === Camera.PERSPECTIVE_CAMERA) {
  394. if (this.minZ <= 0) {
  395. this.minZ = 0.1;
  396. }
  397. BABYLON.Matrix.PerspectiveFovLHToRef(this.fov, engine.getAspectRatio(this), this.minZ, this.maxZ, this._projectionMatrix, this.fovMode);
  398. return this._projectionMatrix;
  399. }
  400. var halfWidth = engine.getRenderWidth() / 2.0;
  401. var halfHeight = engine.getRenderHeight() / 2.0;
  402. BABYLON.Matrix.OrthoOffCenterLHToRef(this.orthoLeft || -halfWidth, this.orthoRight || halfWidth, this.orthoBottom || -halfHeight, this.orthoTop || halfHeight, this.minZ, this.maxZ, this._projectionMatrix);
  403. return this._projectionMatrix;
  404. };
  405. Camera.prototype.dispose = function () {
  406. // Remove from scene
  407. this.getScene().removeCamera(this);
  408. while (this._rigCameras.length > 0) {
  409. this._rigCameras.pop().dispose();
  410. }
  411. // Postprocesses
  412. for (var i = 0; i < this._postProcessesTakenIndices.length; ++i) {
  413. this._postProcesses[this._postProcessesTakenIndices[i]].dispose(this);
  414. }
  415. };
  416. // ---- Camera rigs section ----
  417. Camera.prototype.setCameraRigMode = function (mode, rigParams) {
  418. while (this._rigCameras.length > 0) {
  419. this._rigCameras.pop().dispose();
  420. }
  421. this.cameraRigMode = mode;
  422. this._cameraRigParams = {};
  423. switch (this.cameraRigMode) {
  424. case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  425. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  426. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  427. case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  428. this._cameraRigParams.interaxialDistance = rigParams.interaxialDistance || 0.0637;
  429. //we have to implement stereo camera calcultating left and right viewpoints from interaxialDistance and target,
  430. //not from a given angle as it is now, but until that complete code rewriting provisional stereoHalfAngle value is introduced
  431. this._cameraRigParams.stereoHalfAngle = BABYLON.Tools.ToRadians(this._cameraRigParams.interaxialDistance / 0.0637);
  432. this._rigCameras.push(this.createRigCamera(this.name + "_L", 0));
  433. this._rigCameras.push(this.createRigCamera(this.name + "_R", 1));
  434. break;
  435. }
  436. var postProcesses = new Array();
  437. switch (this.cameraRigMode) {
  438. case Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:
  439. postProcesses.push(new BABYLON.PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[0]));
  440. this._rigCameras[0].isIntermediate = true;
  441. postProcesses.push(new BABYLON.AnaglyphPostProcess(this.name + "_anaglyph", 1.0, this._rigCameras[1]));
  442. postProcesses[1].onApply = function (effect) {
  443. effect.setTextureFromPostProcess("leftSampler", postProcesses[0]);
  444. };
  445. break;
  446. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:
  447. case Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:
  448. case Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:
  449. var isStereoscopicHoriz = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL || this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED);
  450. var firstCamIndex = (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED) ? 1 : 0;
  451. var secondCamIndex = 1 - firstCamIndex;
  452. postProcesses.push(new BABYLON.PassPostProcess(this.name + "_passthru", 1.0, this._rigCameras[firstCamIndex]));
  453. this._rigCameras[firstCamIndex].isIntermediate = true;
  454. postProcesses.push(new BABYLON.StereoscopicInterlacePostProcess(this.name + "_stereoInterlace", this._rigCameras[secondCamIndex], postProcesses[0], isStereoscopicHoriz));
  455. break;
  456. case Camera.RIG_MODE_VR:
  457. this._rigCameras.push(this.createRigCamera(this.name + "_L", 0));
  458. this._rigCameras.push(this.createRigCamera(this.name + "_R", 1));
  459. var metrics = rigParams.vrCameraMetrics || VRCameraMetrics.GetDefault();
  460. this._rigCameras[0]._cameraRigParams.vrMetrics = metrics;
  461. this._rigCameras[0].viewport = new BABYLON.Viewport(0, 0, 0.5, 1.0);
  462. this._rigCameras[0]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  463. this._rigCameras[0]._cameraRigParams.vrHMatrix = metrics.leftHMatrix;
  464. this._rigCameras[0]._cameraRigParams.vrPreViewMatrix = metrics.leftPreViewMatrix;
  465. this._rigCameras[0].getProjectionMatrix = this._rigCameras[0]._getVRProjectionMatrix;
  466. if (metrics.compensateDistorsion) {
  467. postProcesses.push(new BABYLON.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left", this._rigCameras[0], false, metrics));
  468. }
  469. this._rigCameras[1]._cameraRigParams.vrMetrics = this._rigCameras[0]._cameraRigParams.vrMetrics;
  470. this._rigCameras[1].viewport = new BABYLON.Viewport(0.5, 0, 0.5, 1.0);
  471. this._rigCameras[1]._cameraRigParams.vrWorkMatrix = new BABYLON.Matrix();
  472. this._rigCameras[1]._cameraRigParams.vrHMatrix = metrics.rightHMatrix;
  473. this._rigCameras[1]._cameraRigParams.vrPreViewMatrix = metrics.rightPreViewMatrix;
  474. this._rigCameras[1].getProjectionMatrix = this._rigCameras[1]._getVRProjectionMatrix;
  475. if (metrics.compensateDistorsion) {
  476. postProcesses.push(new BABYLON.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right", this._rigCameras[1], true, metrics));
  477. }
  478. break;
  479. }
  480. this._update();
  481. };
  482. Camera.prototype._getVRProjectionMatrix = function () {
  483. BABYLON.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov, this._cameraRigParams.vrMetrics.aspectRatio, this.minZ, this.maxZ, this._cameraRigParams.vrWorkMatrix);
  484. this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix, this._projectionMatrix);
  485. return this._projectionMatrix;
  486. };
  487. Camera.prototype.setCameraRigParameter = function (name, value) {
  488. this._cameraRigParams[name] = value;
  489. //provisionnally:
  490. if (name === "interaxialDistance") {
  491. this._cameraRigParams.stereoHalfAngle = BABYLON.Tools.ToRadians(value);
  492. }
  493. };
  494. /**
  495. * May needs to be overridden by children so sub has required properties to be copied
  496. */
  497. Camera.prototype.createRigCamera = function (name, cameraIndex) {
  498. return null;
  499. };
  500. /**
  501. * May needs to be overridden by children
  502. */
  503. Camera.prototype._updateRigCameras = function () {
  504. for (var i = 0; i < this._rigCameras.length; i++) {
  505. this._rigCameras[i].minZ = this.minZ;
  506. this._rigCameras[i].maxZ = this.maxZ;
  507. this._rigCameras[i].fov = this.fov;
  508. }
  509. // only update viewport when ANAGLYPH
  510. if (this.cameraRigMode === Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH) {
  511. this._rigCameras[0].viewport = this._rigCameras[1].viewport = this.viewport;
  512. }
  513. };
  514. // Statics
  515. Camera._PERSPECTIVE_CAMERA = 0;
  516. Camera._ORTHOGRAPHIC_CAMERA = 1;
  517. Camera._FOVMODE_VERTICAL_FIXED = 0;
  518. Camera._FOVMODE_HORIZONTAL_FIXED = 1;
  519. Camera._RIG_MODE_NONE = 0;
  520. Camera._RIG_MODE_STEREOSCOPIC_ANAGLYPH = 10;
  521. Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL = 11;
  522. Camera._RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED = 12;
  523. Camera._RIG_MODE_STEREOSCOPIC_OVERUNDER = 13;
  524. Camera._RIG_MODE_VR = 20;
  525. return Camera;
  526. })(BABYLON.Node);
  527. BABYLON.Camera = Camera;
  528. })(BABYLON || (BABYLON = {}));
  529. //# sourceMappingURL=babylon.camera.js.map