babylon.mirrorTexture.js 1.9 KB

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