babylon.anaglyphCamera.js 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var __extends = 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 buildCamera = function (that, name) {
  10. that._leftCamera.isIntermediate = true;
  11. that.subCameras.push(that._leftCamera);
  12. that.subCameras.push(that._rightCamera);
  13. that._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, that._leftCamera);
  14. that._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, that._rightCamera);
  15. that._anaglyphPostProcess.onApply = function (effect) {
  16. effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
  17. };
  18. that._update();
  19. };
  20. var AnaglyphArcRotateCamera = (function (_super) {
  21. __extends(AnaglyphArcRotateCamera, _super);
  22. // ANY
  23. function AnaglyphArcRotateCamera(name, alpha, beta, radius, target, eyeSpace, scene) {
  24. _super.call(this, name, alpha, beta, radius, target, scene);
  25. this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
  26. this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
  27. this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
  28. buildCamera(this, name);
  29. }
  30. AnaglyphArcRotateCamera.prototype._update = function () {
  31. this._updateCamera(this._leftCamera);
  32. this._updateCamera(this._rightCamera);
  33. this._leftCamera.alpha = this.alpha - this._eyeSpace;
  34. this._rightCamera.alpha = this.alpha + this._eyeSpace;
  35. _super.prototype._update.call(this);
  36. };
  37. AnaglyphArcRotateCamera.prototype._updateCamera = function (camera) {
  38. camera.beta = this.beta;
  39. camera.radius = this.radius;
  40. camera.minZ = this.minZ;
  41. camera.maxZ = this.maxZ;
  42. camera.fov = this.fov;
  43. camera.target = this.target;
  44. };
  45. return AnaglyphArcRotateCamera;
  46. })(BABYLON.ArcRotateCamera);
  47. BABYLON.AnaglyphArcRotateCamera = AnaglyphArcRotateCamera;
  48. var AnaglyphFreeCamera = (function (_super) {
  49. __extends(AnaglyphFreeCamera, _super);
  50. function AnaglyphFreeCamera(name, position, eyeSpace, scene) {
  51. _super.call(this, name, position, scene);
  52. this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
  53. this._transformMatrix = new BABYLON.Matrix();
  54. this._leftCamera = new BABYLON.FreeCamera(name + "_left", position.clone(), scene);
  55. this._rightCamera = new BABYLON.FreeCamera(name + "_right", position.clone(), scene);
  56. buildCamera(this, name);
  57. }
  58. AnaglyphFreeCamera.prototype._getSubCameraPosition = function (eyeSpace, result) {
  59. var target = this.getTarget();
  60. BABYLON.Matrix.Translation(-target.x, -target.y, -target.z).multiplyToRef(BABYLON.Matrix.RotationY(eyeSpace), this._transformMatrix);
  61. this._transformMatrix = this._transformMatrix.multiply(BABYLON.Matrix.Translation(target.x, target.y, target.z));
  62. BABYLON.Vector3.TransformCoordinatesToRef(this.position, this._transformMatrix, result);
  63. };
  64. AnaglyphFreeCamera.prototype._update = function () {
  65. this._getSubCameraPosition(-this._eyeSpace, this._leftCamera.position);
  66. this._getSubCameraPosition(this._eyeSpace, this._rightCamera.position);
  67. this._updateCamera(this._leftCamera);
  68. this._updateCamera(this._rightCamera);
  69. _super.prototype._update.call(this);
  70. };
  71. AnaglyphFreeCamera.prototype._updateCamera = function (camera) {
  72. camera.minZ = this.minZ;
  73. camera.maxZ = this.maxZ;
  74. camera.fov = this.fov;
  75. camera.viewport = this.viewport;
  76. camera.setTarget(this.getTarget());
  77. };
  78. return AnaglyphFreeCamera;
  79. })(BABYLON.FreeCamera);
  80. BABYLON.AnaglyphFreeCamera = AnaglyphFreeCamera;
  81. })(BABYLON || (BABYLON = {}));
  82. //# sourceMappingURL=babylon.anaglyphCamera.js.map