|
@@ -1,10 +1,39 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
|
|
+ /**
|
|
|
|
+ * This represents a Lens Flare System or the shiny effect created by the light reflection on the camera lenses.
|
|
|
|
+ * It is usually composed of several `BABYLON.lensFlare`.
|
|
|
|
+ * @see http://doc.babylonjs.com/how_to/how_to_use_lens_flares
|
|
|
|
+ */
|
|
export class LensFlareSystem {
|
|
export class LensFlareSystem {
|
|
|
|
+ /**
|
|
|
|
+ * List of lens flares used in this system.
|
|
|
|
+ */
|
|
public lensFlares = new Array<LensFlare>();
|
|
public lensFlares = new Array<LensFlare>();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Define a limit from the border the lens flare can be visible.
|
|
|
|
+ */
|
|
public borderLimit = 300;
|
|
public borderLimit = 300;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Define a viewport border we do not want to see the lens flare in.
|
|
|
|
+ */
|
|
public viewportBorder = 0;
|
|
public viewportBorder = 0;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Define a predicate which could limit the list of meshes able to occlude the effect.
|
|
|
|
+ */
|
|
public meshesSelectionPredicate: (mesh: AbstractMesh) => boolean;
|
|
public meshesSelectionPredicate: (mesh: AbstractMesh) => boolean;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Restricts the rendering of the effect to only the camera rendering this layer mask.
|
|
|
|
+ */
|
|
public layerMask: number = 0x0FFFFFFF;
|
|
public layerMask: number = 0x0FFFFFFF;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Define the id of the lens flare system in the scene.
|
|
|
|
+ * (equal to name by default)
|
|
|
|
+ */
|
|
public id: string;
|
|
public id: string;
|
|
|
|
|
|
private _scene: Scene;
|
|
private _scene: Scene;
|
|
@@ -16,6 +45,15 @@
|
|
private _positionY: number;
|
|
private _positionY: number;
|
|
private _isEnabled = true;
|
|
private _isEnabled = true;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Instantiates a lens flare system.
|
|
|
|
+ * This represents a Lens Flare System or the shiny effect created by the light reflection on the camera lenses.
|
|
|
|
+ * It is usually composed of several `BABYLON.lensFlare`.
|
|
|
|
+ * @see http://doc.babylonjs.com/how_to/how_to_use_lens_flares
|
|
|
|
+ * @param name Define the name of the lens flare system in the scene
|
|
|
|
+ * @param emitter Define the source (the emitter) of the lens flares (it can be a camera, a light or a mesh).
|
|
|
|
+ * @param scene Define the scene the lens flare system belongs to
|
|
|
|
+ */
|
|
constructor(public name: string, emitter: any, scene: Scene) {
|
|
constructor(public name: string, emitter: any, scene: Scene) {
|
|
|
|
|
|
this._scene = scene || Engine.LastCreatedScene;
|
|
this._scene = scene || Engine.LastCreatedScene;
|
|
@@ -61,6 +99,9 @@
|
|
["textureSampler"], "");
|
|
["textureSampler"], "");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Define if the lens flare system is enabled.
|
|
|
|
+ */
|
|
public get isEnabled(): boolean {
|
|
public get isEnabled(): boolean {
|
|
return this._isEnabled;
|
|
return this._isEnabled;
|
|
}
|
|
}
|
|
@@ -69,22 +110,41 @@
|
|
this._isEnabled = value;
|
|
this._isEnabled = value;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get the scene the effects belongs to.
|
|
|
|
+ * @returns the scene holding the lens flare system
|
|
|
|
+ */
|
|
public getScene(): Scene {
|
|
public getScene(): Scene {
|
|
return this._scene;
|
|
return this._scene;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get the emitter of the lens flare system.
|
|
|
|
+ * It defines the source of the lens flares (it can be a camera, a light or a mesh).
|
|
|
|
+ */
|
|
public getEmitter(): any {
|
|
public getEmitter(): any {
|
|
return this._emitter;
|
|
return this._emitter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Set the emitter of the lens flare system.
|
|
|
|
+ * It defines the source of the lens flares (it can be a camera, a light or a mesh).
|
|
|
|
+ */
|
|
public setEmitter(newEmitter: any): void {
|
|
public setEmitter(newEmitter: any): void {
|
|
this._emitter = newEmitter;
|
|
this._emitter = newEmitter;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Get the lens flare system emitter position.
|
|
|
|
+ * The emitter defines the source of the lens flares (it can be a camera, a light or a mesh).
|
|
|
|
+ */
|
|
public getEmitterPosition(): Vector3 {
|
|
public getEmitterPosition(): Vector3 {
|
|
return this._emitter.getAbsolutePosition ? this._emitter.getAbsolutePosition() : this._emitter.position;
|
|
return this._emitter.getAbsolutePosition ? this._emitter.getAbsolutePosition() : this._emitter.position;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @hidden
|
|
|
|
+ */
|
|
public computeEffectivePosition(globalViewport: Viewport): boolean {
|
|
public computeEffectivePosition(globalViewport: Viewport): boolean {
|
|
var position = this.getEmitterPosition();
|
|
var position = this.getEmitterPosition();
|
|
|
|
|
|
@@ -134,6 +194,9 @@
|
|
return !pickInfo || !pickInfo.hit || pickInfo.distance > distance;
|
|
return !pickInfo || !pickInfo.hit || pickInfo.distance > distance;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @hidden
|
|
|
|
+ */
|
|
public render(): boolean {
|
|
public render(): boolean {
|
|
if (!this._effect.isReady() || !this._scene.activeCamera)
|
|
if (!this._effect.isReady() || !this._scene.activeCamera)
|
|
return false;
|
|
return false;
|
|
@@ -249,6 +312,9 @@
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Dispose and release the lens flare with its associated resources.
|
|
|
|
+ */
|
|
public dispose(): void {
|
|
public dispose(): void {
|
|
var vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];
|
|
var vertexBuffer = this._vertexBuffers[VertexBuffer.PositionKind];
|
|
if (vertexBuffer) {
|
|
if (vertexBuffer) {
|
|
@@ -270,6 +336,13 @@
|
|
this._scene.lensFlareSystems.splice(index, 1);
|
|
this._scene.lensFlareSystems.splice(index, 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Parse a lens flare system from a JSON repressentation
|
|
|
|
+ * @param parsedLensFlareSystem Define the JSON to parse
|
|
|
|
+ * @param scene Define the scene the parsed system should be instantiated in
|
|
|
|
+ * @param rootUrl Define the rootUrl of the load sequence to easily find a load relative dependencies such as textures
|
|
|
|
+ * @returns the parsed system
|
|
|
|
+ */
|
|
public static Parse(parsedLensFlareSystem: any, scene: Scene, rootUrl: string): LensFlareSystem {
|
|
public static Parse(parsedLensFlareSystem: any, scene: Scene, rootUrl: string): LensFlareSystem {
|
|
var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
|
|
var emitter = scene.getLastEntryByID(parsedLensFlareSystem.emitterId);
|
|
|
|
|
|
@@ -288,6 +361,10 @@
|
|
return lensFlareSystem;
|
|
return lensFlareSystem;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Serialize the current Lens Flare System into a JSON representation.
|
|
|
|
+ * @returns the serialized JSON
|
|
|
|
+ */
|
|
public serialize(): any {
|
|
public serialize(): any {
|
|
var serializationObject: any = {};
|
|
var serializationObject: any = {};
|
|
|
|
|