This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdirectional.js
61 lines (56 loc) · 1.58 KB
/
directional.js
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
import { DirectionalLight, DirectionalLightHelper } from 'three';
import { GUI } from 'dat.gui';
import settings from '../settings';
/**
* Utility for creating directional lights
*
* @export
* @class Directional
*/
export default class Directional {
settings: Object;
light: DirectionalLight;
gui: GUI;
guiParent: GUI;
helper: DirectionalLightHelper;
constructor(options: Object = {}) {
this.settings = Object.assign(
{
color: 0xd4d4d4,
intensity: 0.6,
guiOpen: false
},
options
);
this.light = new DirectionalLight(this.settings.color, this.settings.intensity);
this.light.position.set(1, 1, 1);
this.helper = new DirectionalLightHelper(this.light);
}
gui(guiParent: GUI) {
this.guiParent = guiParent;
this.gui = guiParent.addFolder('directional');
if (this.settings.guiOpen) this.gui.open();
this.gui.addColor(this.settings, 'color').onChange(this.onChange);
this.gui.add(this.light, 'intensity', 0, 1, settings.guiPrecision);
const range = 1;
this.gui
.add(this.light.position, 'x', -range, range)
.step(settings.guiPrecision)
.name('direction x');
this.gui
.add(this.light.position, 'y', -range, range)
.step(settings.guiPrecision)
.name('direction y');
this.gui
.add(this.light.position, 'z', -range, range)
.step(settings.guiPrecision)
.name('direction z');
}
onChange = () => {
this.light.color.setHex(this.settings.color);
this.helper.update();
};
dispose() {
this.guiParent.removeFolder(this.gui.name);
}
}