depthPeelingSceneComponent.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { Scene } from "../scene.js";
  2. import { SceneComponentConstants } from "../sceneComponent.js";
  3. import { DepthPeelingRenderer } from "./depthPeelingRenderer.js";
  4. Object.defineProperty(Scene.prototype, "depthPeelingRenderer", {
  5. get: function () {
  6. if (!this._depthPeelingRenderer) {
  7. let component = this._getComponent(SceneComponentConstants.NAME_DEPTHPEELINGRENDERER);
  8. if (!component) {
  9. component = new DepthPeelingSceneComponent(this);
  10. this._addComponent(component);
  11. }
  12. }
  13. return this._depthPeelingRenderer;
  14. },
  15. set: function (value) {
  16. this._depthPeelingRenderer = value;
  17. },
  18. enumerable: true,
  19. configurable: true,
  20. });
  21. Object.defineProperty(Scene.prototype, "useOrderIndependentTransparency", {
  22. get: function () {
  23. return this._useOrderIndependentTransparency;
  24. },
  25. set: function (value) {
  26. if (this._useOrderIndependentTransparency === value) {
  27. return;
  28. }
  29. this._useOrderIndependentTransparency = value;
  30. this.markAllMaterialsAsDirty(63);
  31. this.prePassRenderer?.markAsDirty();
  32. },
  33. enumerable: true,
  34. configurable: true,
  35. });
  36. /**
  37. * Scene component to render order independent transparency with depth peeling
  38. */
  39. export class DepthPeelingSceneComponent {
  40. /**
  41. * Creates a new instance of the component for the given scene
  42. * @param scene Defines the scene to register the component in
  43. */
  44. constructor(scene) {
  45. /**
  46. * The component name helpful to identify the component in the list of scene components.
  47. */
  48. this.name = SceneComponentConstants.NAME_DEPTHPEELINGRENDERER;
  49. this.scene = scene;
  50. scene.depthPeelingRenderer = new DepthPeelingRenderer(scene);
  51. }
  52. /**
  53. * Registers the component in a given scene
  54. */
  55. register() { }
  56. /**
  57. * Rebuilds the elements related to this component in case of
  58. * context lost for instance.
  59. */
  60. rebuild() { }
  61. /**
  62. * Disposes the component and the associated resources.
  63. */
  64. dispose() {
  65. this.scene.depthPeelingRenderer?.dispose();
  66. this.scene.depthPeelingRenderer = null;
  67. }
  68. }
  69. //# sourceMappingURL=depthPeelingSceneComponent.js.map