-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththree.camera.note.js
126 lines (78 loc) · 2.22 KB
/
three.camera.note.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
*
z: eye - target up
\ /
\ /
\ /
------ y: z x x
/
/
x: up x z
*/
function lookAt(eye, target, up) {
const te = this.elements;
_z.subVectors(eye, target);
if (_z.lengthSq() === 0) {
// eye and target are in the same position
_z.z = 1;
}
_z.normalize();
_x.crossVectors(up, _z);
if (_x.lengthSq() === 0) {
// up and z are parallel
if (Math.abs(up.z) === 1) {
_z.x += 0.0001;
} else {
_z.z += 0.0001;
}
_z.normalize();
_x.crossVectors(up, _z);
}
_x.normalize();
_y.crossVectors(_z, _x);
te[0] = _x.x; te[4] = _y.x; te[8] = _z.x;
te[1] = _x.y; te[5] = _y.y; te[9] = _z.y;
te[2] = _x.z; te[6] = _y.z; te[10] = _z.z;
return this;
}
function lookAt(x, y, z) {
// This method does not support objects having non-uniformly-scaled parent(s)
if (x.isVector3) {
_target.copy(x);
} else {
_target.set(x, y, z);
}
const parent = this.parent;
this.updateWorldMatrix(true, false);
_position$3.setFromMatrixPosition(this.matrixWorld);
if (this.isCamera || this.isLight) {
_m1$1.lookAt(_position$3, _target, this.up);
} else {
_m1$1.lookAt(_target, _position$3, this.up);
}
this.quaternion.setFromRotationMatrix(_m1$1);
if (parent) {
_m1$1.extractRotation(parent.matrixWorld);
_q1.setFromRotationMatrix(_m1$1);
this.quaternion.premultiply(_q1.invert());
}
}
// 法向量计算规则
// normal = (c-b) x (a - b)
/**
* a
* _
* |\
* c <- b
*/
for (let i = 0, il = positionAttribute.count; i < il; i += 3) {
pA.fromBufferAttribute(positionAttribute, i + 0);
pB.fromBufferAttribute(positionAttribute, i + 1);
pC.fromBufferAttribute(positionAttribute, i + 2);
cb.subVectors(pC, pB);
ab.subVectors(pA, pB);
cb.cross(ab);
normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z);
normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z);
normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z);
}