-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlight.ts
51 lines (43 loc) · 1.37 KB
/
light.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
import { Matrix4, Vector3 } from '../matrix';
import { Object3D } from './object3d';
interface Spot {
innerConeAngle: number;
outerConeAngle: number;
}
export class Light extends Object3D {
matrixWorldInvert: Matrix4;
type: 'point' | 'directional' | 'spot';
color: Vector3;
intensity: number;
isInitial: boolean;
spot: Spot;
constructor(props, name?, parent?) {
super(name, parent);
const { type, color, intensity, isInitial, spot = {} } = props;
this.type = type;
this.color = new Vector3(color);
this.intensity = intensity;
this.isInitial = isInitial;
this.spot = spot;
this.matrixWorldInvert = new Matrix4();
}
setMatrixWorld(matrix) {
super.setMatrixWorld(matrix);
this.matrixWorldInvert.setInverseOf(this.matrixWorld);
}
setZ(z) {
// this.matrix.elements[13] = 0.5;
// this.matrix.elements[14] = -3;
this.matrix.elements[13] = z;
this.matrix.elements[14] = z;
this.setMatrixWorld(this.matrix.elements);
}
update(v) {
if (this.isInitial || this.type === 'directional') {
const camMatrix = new Matrix4();
camMatrix.makeRotationAxis(new Vector3([0, 1, 0]), v);
camMatrix.multiply(this.matrix);
this.setMatrixWorld(camMatrix.elements);
}
}
}