forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlensFlare.ts
88 lines (79 loc) · 3.64 KB
/
lensFlare.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Nullable } from "../types";
import { Color3 } from "../Maths/math.color";
import { Texture } from "../Materials/Textures/texture";
import { LensFlareSystem } from "./lensFlareSystem";
import { Constants } from "../Engines/constants";
/**
* This represents one of the lens effect in a `lensFlareSystem`.
* It controls one of the individual texture used in the effect.
* @see https://doc.babylonjs.com/how_to/how_to_use_lens_flares
*/
export class LensFlare {
/**
* Define the lens color.
*/
public color: Color3;
/**
* Define the lens texture.
*/
public texture: Nullable<Texture>;
/**
* Define the alpha mode to render this particular lens.
*/
public alphaMode: number = Constants.ALPHA_ONEONE;
private _system: LensFlareSystem;
/**
* Creates a new Lens Flare.
* This represents one of the lens effect in a `lensFlareSystem`.
* It controls one of the individual texture used in the effect.
* @see https://doc.babylonjs.com/how_to/how_to_use_lens_flares
* @param size Define the size of the lens flare (a floating value between 0 and 1)
* @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.
* @param color Define the lens color
* @param imgUrl Define the lens texture url
* @param system Define the `lensFlareSystem` this flare is part of
* @returns The newly created Lens Flare
*/
public static AddFlare(size: number, position: number, color: Color3, imgUrl: string, system: LensFlareSystem): LensFlare {
return new LensFlare(size, position, color, imgUrl, system);
}
/**
* Instantiates a new Lens Flare.
* This represents one of the lens effect in a `lensFlareSystem`.
* It controls one of the individual texture used in the effect.
* @see https://doc.babylonjs.com/how_to/how_to_use_lens_flares
* @param size Define the size of the lens flare in the system (a floating value between 0 and 1)
* @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.
* @param color Define the lens color
* @param imgUrl Define the lens texture url
* @param system Define the `lensFlareSystem` this flare is part of
*/
constructor(
/**
* Define the size of the lens flare in the system (a floating value between 0 and 1)
*/
public size: number,
/**
* 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.
*/
public position: number,
color: Color3,
imgUrl: string,
system: LensFlareSystem) {
this.color = color || new Color3(1, 1, 1);
this.texture = imgUrl ? new Texture(imgUrl, system.getScene(), true) : null;
this._system = system;
system.lensFlares.push(this);
}
/**
* Dispose and release the lens flare with its associated resources.
*/
public dispose(): void {
if (this.texture) {
this.texture.dispose();
}
// Remove from scene
var index = this._system.lensFlares.indexOf(this);
this._system.lensFlares.splice(index, 1);
}
}