babylon.mirrorTexture.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. var BABYLON = BABYLON || {};
  3. (function () {
  4. BABYLON.MirrorTexture = function (name, size, scene, generateMipMaps) {
  5. BABYLON.RenderTargetTexture.call(this, name, size, scene, generateMipMaps);
  6. // Internals
  7. this._transformMatrix = BABYLON.Matrix.Zero();
  8. this._mirrorMatrix = BABYLON.Matrix.Zero();
  9. };
  10. BABYLON.MirrorTexture.prototype = Object.create(BABYLON.RenderTargetTexture.prototype);
  11. // Members
  12. BABYLON.MirrorTexture.prototype.mirrorPlane = new BABYLON.Plane(0, 1, 0, 1);
  13. // Method
  14. BABYLON.MirrorTexture.prototype.onBeforeRender = function () {
  15. var scene = this._scene;
  16. BABYLON.Matrix.ReflectionToRef(this.mirrorPlane, this._mirrorMatrix);
  17. this._savedViewMatrix = scene.getViewMatrix();
  18. this._mirrorMatrix.multiplyToRef(this._savedViewMatrix, this._transformMatrix);
  19. scene.setTransformMatrix(this._transformMatrix, scene.getProjectionMatrix());
  20. BABYLON.clipPlane = this.mirrorPlane;
  21. scene.getEngine().cullBackFaces = false;
  22. };
  23. BABYLON.MirrorTexture.prototype.onAfterRender = function () {
  24. var scene = this._scene;
  25. scene.setTransformMatrix(this._savedViewMatrix, scene.getProjectionMatrix());
  26. scene.getEngine().cullBackFaces = true;
  27. delete BABYLON.clipPlane;
  28. };
  29. BABYLON.MirrorTexture.prototype.clone = function () {
  30. var textureSize = this.getSize();
  31. var newTexture = new BABYLON.MirrorTexture(this.name, textureSize.width, this._scene, this._generateMipMaps);
  32. // Base texture
  33. newTexture.hasAlpha = this.hasAlpha;
  34. newTexture.level = this.level;
  35. // Mirror Texture
  36. newTexture.mirrorPlane = this.mirrorPlane.clone();
  37. newTexture.renderList = this.renderList.slice(0);
  38. return newTexture;
  39. };
  40. })();