vrCameraMetrics.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Matrix } from "../../Maths/math.vector.js";
  2. /**
  3. * This represents all the required metrics to create a VR camera.
  4. * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/camera_introduction#device-orientation-camera
  5. */
  6. export class VRCameraMetrics {
  7. constructor() {
  8. /**
  9. * Define if the current vr camera should compensate the distortion of the lens or not.
  10. */
  11. this.compensateDistortion = true;
  12. /**
  13. * Defines if multiview should be enabled when rendering (Default: false)
  14. */
  15. this.multiviewEnabled = false;
  16. }
  17. /**
  18. * Gets the rendering aspect ratio based on the provided resolutions.
  19. */
  20. get aspectRatio() {
  21. return this.hResolution / (2 * this.vResolution);
  22. }
  23. /**
  24. * Gets the aspect ratio based on the FOV, scale factors, and real screen sizes.
  25. */
  26. get aspectRatioFov() {
  27. return 2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance));
  28. }
  29. /**
  30. * @internal
  31. */
  32. get leftHMatrix() {
  33. const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;
  34. const h = (4 * meters) / this.hScreenSize;
  35. return Matrix.Translation(h, 0, 0);
  36. }
  37. /**
  38. * @internal
  39. */
  40. get rightHMatrix() {
  41. const meters = this.hScreenSize / 4 - this.lensSeparationDistance / 2;
  42. const h = (4 * meters) / this.hScreenSize;
  43. return Matrix.Translation(-h, 0, 0);
  44. }
  45. /**
  46. * @internal
  47. */
  48. get leftPreViewMatrix() {
  49. return Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
  50. }
  51. /**
  52. * @internal
  53. */
  54. get rightPreViewMatrix() {
  55. return Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
  56. }
  57. /**
  58. * Get the default VRMetrics based on the most generic setup.
  59. * @returns the default vr metrics
  60. */
  61. static GetDefault() {
  62. const result = new VRCameraMetrics();
  63. result.hResolution = 1280;
  64. result.vResolution = 800;
  65. result.hScreenSize = 0.149759993;
  66. result.vScreenSize = 0.0935999975;
  67. result.vScreenCenter = 0.0467999987;
  68. result.eyeToScreenDistance = 0.0410000011;
  69. result.lensSeparationDistance = 0.063500002;
  70. result.interpupillaryDistance = 0.064000003;
  71. result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
  72. result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
  73. result.postProcessScaleFactor = 1.714605507808412;
  74. result.lensCenterOffset = 0.151976421;
  75. return result;
  76. }
  77. }
  78. //# sourceMappingURL=vrCameraMetrics.js.map