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
/
point.js
67 lines (62 loc) · 1.61 KB
/
point.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
import { PointLight } from 'three';
import { GUI } from 'dat.gui';
import settings from '../settings';
/**
* Utility for creating point lights
*
* @export
* @class Point
*/
export class Point {
settings: Object;
light: PointLight;
gui: GUI;
guiParent: GUI;
constructor(options: Object = {}) {
this.settings = Object.assign(
{
color: 0xd4d4d4,
intensity: 0.6,
distance: 100,
decay: 0,
guiOpen: false
},
options
);
this.light = new PointLight(
this.settings.color,
this.settings.intensity,
this.settings.distance,
this.settings.decay
);
this.light.position.set(1, 1, 1);
}
gui(guiParent: GUI) {
this.guiParent = guiParent;
this.gui = guiParent.addFolder('point');
if (this.settings.guiOpen) this.gui.open();
const range = 100;
this.gui.addColor(this.settings, 'color').onChange(this.onChange);
this.gui.add(this.settings, 'intensity', 0, 10, settings.guiPrecision);
this.gui.add(this.settings, 'distance', 0, 1000);
this.gui.add(this.settings, 'decay', 0, 1000);
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);
}
}