babylon.mirrorTexture.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 MirrorTexture = (function (_super) {
  10. __extends(MirrorTexture, _super);
  11. function MirrorTexture(name, size, scene, generateMipMaps) {
  12. var _this = this;
  13. _super.call(this, name, size, scene, generateMipMaps, true);
  14. this.mirrorPlane = new BABYLON.Plane(0, 1, 0, 1);
  15. this._transformMatrix = BABYLON.Matrix.Zero();
  16. this._mirrorMatrix = BABYLON.Matrix.Zero();
  17. this.onBeforeRender = function () {
  18. BABYLON.Matrix.ReflectionToRef(_this.mirrorPlane, _this._mirrorMatrix);
  19. _this._savedViewMatrix = scene.getViewMatrix();
  20. _this._mirrorMatrix.multiplyToRef(_this._savedViewMatrix, _this._transformMatrix);
  21. scene.setTransformMatrix(_this._transformMatrix, scene.getProjectionMatrix());
  22. scene.clipPlane = _this.mirrorPlane;
  23. scene.getEngine().cullBackFaces = false;
  24. };
  25. this.onAfterRender = function () {
  26. scene.setTransformMatrix(_this._savedViewMatrix, scene.getProjectionMatrix());
  27. scene.getEngine().cullBackFaces = true;
  28. delete scene.clipPlane;
  29. };
  30. }
  31. MirrorTexture.prototype.clone = function () {
  32. var textureSize = this.getSize();
  33. var newTexture = new BABYLON.MirrorTexture(this.name, textureSize.width, this.getScene(), this._generateMipMaps);
  34. // Base texture
  35. newTexture.hasAlpha = this.hasAlpha;
  36. newTexture.level = this.level;
  37. // Mirror Texture
  38. newTexture.mirrorPlane = this.mirrorPlane.clone();
  39. newTexture.renderList = this.renderList.slice(0);
  40. return newTexture;
  41. };
  42. return MirrorTexture;
  43. })(BABYLON.RenderTargetTexture);
  44. BABYLON.MirrorTexture = MirrorTexture;
  45. })(BABYLON || (BABYLON = {}));
  46. //# sourceMappingURL=babylon.mirrorTexture.js.map