lensFlare.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Color3 } from "../Maths/math.color.js";
  2. import { Texture } from "../Materials/Textures/texture.js";
  3. import { DrawWrapper } from "../Materials/drawWrapper.js";
  4. import { VertexBuffer } from "../Buffers/buffer.js";
  5. /**
  6. * This represents one of the lens effect in a `lensFlareSystem`.
  7. * It controls one of the individual texture used in the effect.
  8. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/lenseFlare
  9. */
  10. export class LensFlare {
  11. /**
  12. * Creates a new Lens Flare.
  13. * This represents one of the lens effect in a `lensFlareSystem`.
  14. * It controls one of the individual texture used in the effect.
  15. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/lenseFlare
  16. * @param size Define the size of the lens flare (a floating value between 0 and 1)
  17. * @param position Define the position of the lens flare in the system. (a floating value between -1 and 1). A value of 0 is located on the emitter. A value greater than 0 is beyond the emitter and a value lesser than 0 is behind.
  18. * @param color Define the lens color
  19. * @param imgUrl Define the lens texture url
  20. * @param system Define the `lensFlareSystem` this flare is part of
  21. * @returns The newly created Lens Flare
  22. */
  23. static AddFlare(size, position, color, imgUrl, system) {
  24. return new LensFlare(size, position, color, imgUrl, system);
  25. }
  26. /**
  27. * Instantiates a new Lens Flare.
  28. * This represents one of the lens effect in a `lensFlareSystem`.
  29. * It controls one of the individual texture used in the effect.
  30. * @see https://doc.babylonjs.com/features/featuresDeepDive/environment/lenseFlare
  31. * @param size Define the size of the lens flare in the system (a floating value between 0 and 1)
  32. * @param position Define the position of the lens flare in the system. (a floating value between -1 and 1). A value of 0 is located on the emitter. A value greater than 0 is beyond the emitter and a value lesser than 0 is behind.
  33. * @param color Define the lens color
  34. * @param imgUrl Define the lens texture url
  35. * @param system Define the `lensFlareSystem` this flare is part of
  36. */
  37. constructor(
  38. /**
  39. * Define the size of the lens flare in the system (a floating value between 0 and 1)
  40. */
  41. size,
  42. /**
  43. * Define the position of the lens flare in the system. (a floating value between -1 and 1). A value of 0 is located on the emitter. A value greater than 0 is beyond the emitter and a value lesser than 0 is behind.
  44. */
  45. position, color, imgUrl, system) {
  46. this.size = size;
  47. this.position = position;
  48. /**
  49. * Define the alpha mode to render this particular lens.
  50. */
  51. this.alphaMode = 6;
  52. this.color = color || new Color3(1, 1, 1);
  53. this.texture = imgUrl ? new Texture(imgUrl, system.getScene(), true) : null;
  54. this._system = system;
  55. const engine = system.scene.getEngine();
  56. this._drawWrapper = new DrawWrapper(engine);
  57. this._drawWrapper.effect = engine.createEffect("lensFlare", [VertexBuffer.PositionKind], ["color", "viewportMatrix"], ["textureSampler"], "");
  58. system.lensFlares.push(this);
  59. }
  60. /**
  61. * Dispose and release the lens flare with its associated resources.
  62. */
  63. dispose() {
  64. if (this.texture) {
  65. this.texture.dispose();
  66. }
  67. // Remove from scene
  68. const index = this._system.lensFlares.indexOf(this);
  69. this._system.lensFlares.splice(index, 1);
  70. }
  71. }
  72. //# sourceMappingURL=lensFlare.js.map