-
Notifications
You must be signed in to change notification settings - Fork 46
/
skybox.ts
67 lines (58 loc) · 1.78 KB
/
skybox.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
import { SkyboxMaterial } from "./skybox-material"
import { Mesh3D } from "../mesh/mesh"
import { Container3D } from "../container"
import { Cubemap } from "../cubemap/cubemap"
import { Camera } from "../camera/camera"
import { CubemapFaces } from "../cubemap/cubemap-faces"
/**
* A skybox is a method of creating backgrounds in a 3D scene. It consists of
* a cubemap texture which has six sides. Note that the skybox should be rendered
* before all other objects in the scene.
*/
export class Skybox extends Container3D {
private _mesh: Mesh3D
/**
* Creates a new skybox using the specified cubemap.
* @param cubemap Cubemap to use for rendering.
*/
constructor(cubemap: Cubemap) {
super()
this._mesh = this.addChild(Mesh3D.createCube(new SkyboxMaterial(cubemap)))
this._mesh.renderSortOrder = -1
}
/**
* Camera used when rendering. If this value is not set, the main camera will
* be used by default.
*/
get camera() {
return (<SkyboxMaterial>this._mesh.material).camera
}
set camera(value: Camera | undefined) {
(<SkyboxMaterial>this._mesh.material).camera = value
}
/**
* The cubemap exposure used when rendering.
*/
get exposure() {
return (<SkyboxMaterial>this._mesh.material).exposure
}
set exposure(value: number) {
(<SkyboxMaterial>this._mesh.material).exposure = value
}
/**
* The cubemap texture used when rendering.
*/
get cubemap() {
return (<SkyboxMaterial>this._mesh.material).cubemap
}
set cubemap(value: Cubemap) {
(<SkyboxMaterial>this._mesh.material).cubemap = value
}
/**
* Creates a new skybox from the specified source.
* @param source The source to create the skybox from.
*/
static from(source: CubemapFaces) {
return new Skybox(Cubemap.fromFaces(source))
}
}