forked from GreggJuanEduardoPH/vue-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgl-spot-light.js
84 lines (82 loc) · 2.59 KB
/
vgl-spot-light.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
77
78
79
80
81
82
83
84
import { SpotLight } from 'three';
import VglLight from './vgl-light';
import { parseVector3 } from '../parsers';
import { vector3, float } from '../types';
import { validateVector3 } from '../validators';
/**
* This light gets emitted from a single point in one direction, along a cone that increases in size the further from the light it gets. Corresponding [THREE.SpotLight](https://threejs.org/docs/index.html#api/lights/SpotLight). This light can cast shadows.
*
* Properties of [VglLight](vgl-light) are also available as mixin.
*/
export default {
mixins: [VglLight],
props: {
/**
* The distance from the light where the intensity is 0.
* When set to 0, then the light never stops.
*/
distance: { type: float, default: 0 },
/**
* The amount the light dims along the distance of the light.
* For physically correct lighting, set this to 2.
*/
decay: { type: float, default: 1 },
/**
* Maximum extent of the spotlight, in radians, from its direction.
* Should be no more than Math.PI/2.
*/
angle: { type: float, default: Math.PI / 3 },
/**
* Percent of the spotlight cone that is attenuated due to penumbra.
* Takes values between zero and 1.
*/
penumbra: { type: float, default: 0 },
/** The spotlight's pointing position. */
target: { type: vector3, validator: validateVector3 },
},
computed: {
/** The THREE.SpotLight instance. */
inst: () => new SpotLight(),
},
beforeDestroy() {
if (this.inst.target.parent) this.inst.target.parent.remove(this.inst.target);
},
watch: {
inst: {
handler(inst) {
Object.assign(inst, {
distance: parseFloat(this.distance),
decay: parseFloat(this.decay),
angle: parseFloat(this.angle),
penumbra: parseFloat(this.penumbra),
});
if (this.target) inst.target.position.copy(parseVector3(this.target));
if (this.parent) this.parent.add(inst.target);
},
immediate: true,
},
parent(parent) {
parent.add(this.inst.target);
},
distance(distance) {
this.inst.distance = parseFloat(distance);
this.vglObject3d.emit();
},
decay(decay) {
this.inst.decay = parseFloat(decay);
this.vglObject3d.emit();
},
angle(angle) {
this.inst.angle = parseFloat(angle);
this.vglObject3d.emit();
},
penumbra(penumbra) {
this.inst.penumbra = parseFloat(penumbra);
this.vglObject3d.emit();
},
target(target) {
this.inst.target.position.copy(parseVector3(target));
this.vglObject3d.emit();
},
},
};