babylon.anaglyphCamera.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. var eventPrefix = BABYLON.Tools.GetPointerPrefix();
  5. BABYLON.AnaglyphCamera = function (name, alpha, beta, radius, target, eyeSpace, scene) {
  6. BABYLON.ArcRotateCamera.call(this, name, alpha, beta, radius, target, scene);
  7. this._eyeSpace = BABYLON.Tools.ToRadians(eyeSpace);
  8. this._leftCamera = new BABYLON.ArcRotateCamera(name + "_left", alpha - this._eyeSpace, beta, radius, target, scene);
  9. this._rightCamera = new BABYLON.ArcRotateCamera(name + "_right", alpha + this._eyeSpace, beta, radius, target, scene);
  10. this._leftTexture = new BABYLON.PassPostProcess(name + "_leftTexture", 1.0, this._leftCamera);
  11. this._rightTexture = new BABYLON.PassPostProcess(name + "_rightTexture", 1.0, this._rightCamera);
  12. this._anaglyphPostProcess = new BABYLON.AnaglyphPostProcess(name + "_anaglyph", 1.0, this);
  13. var that = this;
  14. this._anaglyphPostProcess.onApply = function (effect) {
  15. effect.setTextureFromPostProcess("leftSampler", that._leftTexture);
  16. effect.setTextureFromPostProcess("rightSampler", that._rightTexture);
  17. };
  18. scene.activeCameras.push(this._leftCamera);
  19. scene.activeCameras.push(this._rightCamera);
  20. scene.activeCameras.push(this);
  21. };
  22. BABYLON.AnaglyphCamera.prototype = Object.create(BABYLON.ArcRotateCamera.prototype);
  23. BABYLON.AnaglyphCamera.prototype._update = function () {
  24. this._updateCamera(this._leftCamera);
  25. this._updateCamera(this._rightCamera);
  26. this._leftCamera.alpha = this.alpha - this._eyeSpace;
  27. this._rightCamera.alpha = this.alpha + this._eyeSpace;
  28. BABYLON.ArcRotateCamera.prototype._update.call(this);
  29. };
  30. BABYLON.AnaglyphCamera.prototype._updateCamera = function (camera) {
  31. camera.inertialAlphaOffset = this.inertialAlphaOffset;
  32. camera.inertialBetaOffset = this.inertialBetaOffset;
  33. camera.inertialRadiusOffset = this.inertialRadiusOffset;
  34. camera.lowerAlphaLimit = this.lowerAlphaLimit;
  35. camera.upperAlphaLimit = this.upperAlphaLimit;
  36. camera.lowerBetaLimit = this.lowerBetaLimit;
  37. camera.upperBetaLimit = this.upperBetaLimit;
  38. camera.lowerRadiusLimit = this.lowerRadiusLimit;
  39. camera.upperRadiusLimit = this.upperRadiusLimit;
  40. camera.angularSensibility = this.angularSensibility;
  41. camera.wheelPrecision = this.wheelPrecision;
  42. camera.minZ = this.minZ;
  43. camera.maxZ = this.maxZ;
  44. camera.target = this.target;
  45. };
  46. BABYLON.AnaglyphCamera.prototype.attachControl = function (canvas, noPreventDefault) {
  47. BABYLON.ArcRotateCamera.prototype.attachControl.call(this, canvas);
  48. this._leftCamera.attachControl(canvas, noPreventDefault);
  49. this._rightCamera.attachControl(canvas, noPreventDefault);
  50. };
  51. BABYLON.AnaglyphCamera.prototype.detachControl = function (canvas) {
  52. BABYLON.ArcRotateCamera.prototype.detachControl.call(this, canvas);
  53. this._leftCamera.detachControl(canvas);
  54. this._rightCamera.detachControl(canvas);
  55. };
  56. })();