-
Notifications
You must be signed in to change notification settings - Fork 46
/
lighting-environment.ts
53 lines (45 loc) · 1.63 KB
/
lighting-environment.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
import { Renderer, IRendererPlugin } from "@pixi/core"
import { Compatibility } from "../compatibility/compatibility"
import { ImageBasedLighting } from "./image-based-lighting"
import { Light } from "./light"
import { Fog } from "./fog"
/**
* A lighting environment represents the different lighting conditions for a
* specific object or an entire scene.
*/
export class LightingEnvironment implements IRendererPlugin {
/** The image-based lighting object. */
imageBasedLighting?: ImageBasedLighting
/** The lights affecting this lighting environment. */
lights: Light[] = []
fog?: Fog
/** The main lighting environment which is used by default. */
static main: LightingEnvironment
/**
* Creates a new lighting environment using the specified renderer.
* @param renderer The renderer to use.
* @param imageBasedLighting The image based lighting to use.
*/
constructor(public renderer: Renderer, imageBasedLighting?: ImageBasedLighting) {
this.renderer.on("prerender", () => {
for (let light of this.lights) {
// Make sure the transform has been updated in the case where the light
// is not part of the stage hierarchy.
if (!light.parent) {
light.transform.updateTransform()
}
}
})
if (!LightingEnvironment.main) {
LightingEnvironment.main = this
}
this.imageBasedLighting = imageBasedLighting
}
destroy() {
}
/** Value indicating if this object is valid to be used for rendering. */
get valid() {
return !this.imageBasedLighting || this.imageBasedLighting.valid
}
}
Compatibility.installRendererPlugin("lighting", LightingEnvironment)