物管理前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB

  1. (function () {
  2. class RenderPass extends THREE.Pass {
  3. constructor(scene, camera, overrideMaterial, clearColor, clearAlpha) {
  4. super();
  5. this.scene = scene;
  6. this.camera = camera;
  7. this.overrideMaterial = overrideMaterial;
  8. this.clearColor = clearColor;
  9. this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 0;
  10. this.clear = true;
  11. this.clearDepth = false;
  12. this.needsSwap = false;
  13. this._oldClearColor = new THREE.Color();
  14. }
  15. render(
  16. renderer,
  17. writeBuffer,
  18. readBuffer
  19. /*, deltaTime, maskActive */
  20. ) {
  21. const oldAutoClear = renderer.autoClear;
  22. renderer.autoClear = false;
  23. let oldClearAlpha, oldOverrideMaterial;
  24. if (this.overrideMaterial !== undefined) {
  25. oldOverrideMaterial = this.scene.overrideMaterial;
  26. this.scene.overrideMaterial = this.overrideMaterial;
  27. }
  28. if (this.clearColor) {
  29. renderer.getClearColor(this._oldClearColor);
  30. oldClearAlpha = renderer.getClearAlpha();
  31. renderer.setClearColor(this.clearColor, this.clearAlpha);
  32. }
  33. if (this.clearDepth) {
  34. renderer.clearDepth();
  35. }
  36. renderer.setRenderTarget(this.renderToScreen ? null : readBuffer); // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  37. if (this.clear)
  38. renderer.clear(renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil);
  39. renderer.render(this.scene, this.camera);
  40. if (this.clearColor) {
  41. renderer.setClearColor(this._oldClearColor, oldClearAlpha);
  42. }
  43. if (this.overrideMaterial !== undefined) {
  44. this.scene.overrideMaterial = oldOverrideMaterial;
  45. }
  46. renderer.autoClear = oldAutoClear;
  47. }
  48. }
  49. THREE.RenderPass = RenderPass;
  50. })();