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 pathspot.js
76 lines (71 loc) · 1.91 KB
/
spot.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { SpotLight } from 'three';
import { GUI } from 'dat.gui';
import settings from '../settings';
/**
* Utility for creating spot lights
*
* @export
* @class Spot
*/
export class Spot {
settings: Object;
light: SpotLight;
gui: GUI;
guiParent: GUI;
constructor(options: Object = {}) {
this.settings = Object.assign(
{
color: 0xd4d4d4,
intensity: 0.6,
distance: 100,
angle: Math.PI / 3,
power: Math.PI * 4,
penumbra: 0,
decay: 1,
guiOpen: false
},
options
);
this.light = new SpotLight(
this.settings.color,
this.settings.intensity,
this.settings.distance,
this.settings.angle,
this.settings.penumbra,
this.settings.decay
);
this.light.power = this.settings.power;
this.light.position.set(1, 1, 1);
}
gui(guiParent: GUI) {
this.guiParent = guiParent;
this.gui = guiParent.addFolder('spot');
if (this.settings.guiOpen) this.gui.open();
const range = 100;
this.gui.addColor(this.settings, 'color').onChange(this.onChange);
this.gui.add(this.light, 'intensity', 0, 10, settings.guiPrecision);
this.gui.add(this.light, 'distance', 0, 100);
this.gui.add(this.light, 'decay', 0, 100);
this.gui.add(this.light, 'angle', 0, 100);
this.gui.add(this.light, 'penumbra', 0, 100);
this.gui.add(this.light, 'power', 0, 100);
this.gui
.add(this.light.position, 'x', -range, range)
.step(settings.guiPrecision)
.name('position x');
this.gui
.add(this.light.position, 'y', -range, range)
.step(settings.guiPrecision)
.name('position y');
this.gui
.add(this.light.position, 'z', -range, range)
.step(settings.guiPrecision)
.name('position z');
}
onChange = () => {
this.light.color.setHex(this.settings.color);
};
dispose() {
this.guiParent.removeFolder(this.gui.name);
}
}