@yangyongtao/gaea 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -67
- package/package.json +28 -7
- package/public/Gaea.apple-touch-icon.png +0 -0
- package/public/Gaea.apple-touch-icon.png.import +35 -0
- package/public/Gaea.audio.worklet.js +211 -0
- package/public/Gaea.html +245 -0
- package/public/Gaea.icon.png +0 -0
- package/public/Gaea.icon.png.import +35 -0
- package/public/Gaea.js +782 -0
- package/public/Gaea.png +0 -0
- package/public/Gaea.png.import +35 -0
- package/public/Gaea.worker.js +1 -0
- package/public/GaeaApp.html +275 -0
- package/public/GaeaMethods.js +4342 -0
- package/public/GaeaModule.html +276 -0
- package/public/config.js +76 -0
- package/public/constants.js +185 -0
- package/public/favicon.ico +0 -0
- package/public/image/1.png +0 -0
- package/public/image/12-min-min.gif +0 -0
- package/public/image/3.png +0 -0
- package/public/image/labelImg//345/217/263/350/276/271.png +0 -0
- package/public/image/labelImg//345/267/246/350/276/271.png +0 -0
- package/public/image/labelImg//346/260/264/344/275/215.png +0 -0
- package/public/image/screenIcon//345/205/266/344/273/226.png +0 -0
- package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/272/242.png +0 -0
- package/public/image/screenIcon//345/256/211/345/205/250/347/233/221/346/265/213/350/201/232/345/220/210-/347/273/277.png +0 -0
- package/public/image/screenIcon//346/212/242/351/231/251/345/215/225/344/275/215.png +0 -0
- package/public/image/screenIcon//346/226/255/351/235/242.png +0 -0
- package/public/image/screenIcon//346/227/240/344/272/272/346/234/272.png +0 -0
- package/public/image/screenIcon//346/227/240/344/272/272/346/234/272/345/237/272/345/234/260.png +0 -0
- package/public/image/screenIcon//346/260/264/345/272/223/347/253/231.png +0 -0
- package/public/image/screenIcon//346/260/264/346/226/207/346/265/213/347/253/231.png +0 -0
- package/public/image/screenIcon//346/260/264/351/227/270.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/346/255/243/345/270/270.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/344/277/235.png +0 -0
- package/public/image/screenIcon//346/262/263/351/201/223/347/253/231-/350/266/205/350/255/246.png +0 -0
- package/public/image/screenIcon//346/263/265/347/253/231-/347/201/260.png +0 -0
- package/public/image/screenIcon//346/263/265/347/253/231-/347/273/277.png +0 -0
- package/public/image/screenIcon//346/265/201/351/207/217/346/265/213/347/253/231.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-1/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-2/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-3/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-4/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-5/347/272/247.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/346/251/231.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/347/272/242.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/347/273/277.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/350/247/204/346/250/241/344/273/245/344/270/213.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230-/351/273/204.png +0 -0
- package/public/image/screenIcon//346/265/267/345/241/230.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/227/240/346/225/260/346/215/256.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/346/255/243/345/270/270.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/344/277/235.png +0 -0
- package/public/image/screenIcon//346/275/256/344/275/215/347/253/231-/350/266/205/350/255/246.png +0 -0
- package/public/image/screenIcon//347/211/251/350/265/204/344/273/223/345/272/223.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/345/205/263.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/345/274/200.png +0 -0
- package/public/image/screenIcon//347/220/203/346/234/272-/347/272/242.png +0 -0
- package/public/image/screenIcon//350/247/206/351/242/221/347/233/221/346/216/247.png +0 -0
- package/public/image/screenIcon//351/227/270/351/227/250-/347/201/260.png +0 -0
- package/public/image/screenIcon//351/227/270/351/227/250-/347/273/277.png +0 -0
- package/public/image/screenIcon//351/230/262/346/264/252/344/273/223/345/272/223.png +0 -0
- package/public/image/screenIcon//351/232/220/346/202/243.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/346/265/205/350/223/235.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/201/260.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/262/211.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/272/242.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/347/273/277.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/350/223/235.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/204.png +0 -0
- package/public/image/screenIcon//351/233/250/351/207/217/347/253/231-/351/273/221.png +0 -0
- package/public/image/screenIcon//351/243/216/351/200/237.png +0 -0
- package/public/image/screenIcon//351/243/216/351/200/237/346/265/213/347/253/231.png +0 -0
- package/public/image//346/260/264/346/226/207.gif +0 -0
- package/public/image//350/211/262/345/270/246.png +0 -0
- package/public/index.html +22 -0
- package/public/index.js +185662 -0
- package/public/jsWebControl-1.0.0.min.js +31 -0
- package/public/jsencrypt.min.js +1 -0
- package/public/math/Box2.js +203 -0
- package/public/math/Box3.js +532 -0
- package/public/math/Color.js +605 -0
- package/public/math/ColorManagement.js +74 -0
- package/public/math/Cylindrical.js +61 -0
- package/public/math/EngineUtils.js +81 -0
- package/public/math/Euler.js +315 -0
- package/public/math/Frustum.js +162 -0
- package/public/math/Interpolant.js +241 -0
- package/public/math/Line3.js +115 -0
- package/public/math/MathUtils.js +345 -0
- package/public/math/Matrix3.js +365 -0
- package/public/math/Matrix4.js +858 -0
- package/public/math/Plane.js +205 -0
- package/public/math/Quaternion.js +724 -0
- package/public/math/Ray.js +493 -0
- package/public/math/Sphere.js +243 -0
- package/public/math/Spherical.js +86 -0
- package/public/math/SphericalHarmonics3.js +243 -0
- package/public/math/Triangle.js +299 -0
- package/public/math/Vector2.js +464 -0
- package/public/math/Vector3.js +715 -0
- package/public/math/Vector4.js +644 -0
- package/public/math/interpolants/CubicInterpolant.js +151 -0
- package/public/math/interpolants/DiscreteInterpolant.js +26 -0
- package/public/math/interpolants/LinearInterpolant.js +38 -0
- package/public/math/interpolants/QuaternionLinearInterpolant.js +39 -0
- package/public/static/Cloud.png +0 -0
- package/public/static/Global2.jpg +0 -0
- package/public/static/css/main.css +170 -0
- package/public/static/geojson//346/265/267/345/241/230.geojson +99 -0
- package/public/static/img/loading.gif +0 -0
- package/public/static/js/app.js +359 -0
- package/public/static/js/appcontroller.js +207 -0
- package/public/static/js/dist/game.dev.js +137 -0
- package/public/static/js/env.js +74 -0
- package/public/static/js/event/event.js +107 -0
- package/public/static/js/init.js +8 -0
- package/public/static/js/initcloudmorph.js +1 -0
- package/public/static/js/log.js +35 -0
- package/public/static/js/network/ajax.js +29 -0
- package/public/static/js/network/rtcp.js +172 -0
- package/public/static/js/network/socket.js +106 -0
- package/public/web-control.min.js +2 -0
- package/scripts/postinstall.mjs +127 -0
- package/src/GaeaMethods.js +68 -405
- package/src/components/FlyAlongRoute.vue +1 -0
- package/src/components/WeatherControl.vue +2 -0
- package/src/directives/vDrag.js +70 -0
- package/src/index.js +1 -8
- package/src/plugin.js +16 -0
- package/src/utils.js +10 -21
- package/src/vite-plugin.js +117 -0
- package/public/static/1111.res +0 -0
- package/src/config.js +0 -40
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import * as MathUtils from './MathUtils.js';
|
|
2
|
+
import { Vector3 } from "./Vector3.js";
|
|
3
|
+
|
|
4
|
+
class Quaternion {
|
|
5
|
+
|
|
6
|
+
constructor(x = 0, y = 0, z = 0, w = 1) {
|
|
7
|
+
|
|
8
|
+
this.isQuaternion = true;
|
|
9
|
+
|
|
10
|
+
this._x = x;
|
|
11
|
+
this._y = y;
|
|
12
|
+
this._z = z;
|
|
13
|
+
this._w = w;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
|
|
18
|
+
|
|
19
|
+
// fuzz-free, array-based Quaternion SLERP operation
|
|
20
|
+
|
|
21
|
+
let x0 = src0[srcOffset0 + 0],
|
|
22
|
+
y0 = src0[srcOffset0 + 1],
|
|
23
|
+
z0 = src0[srcOffset0 + 2],
|
|
24
|
+
w0 = src0[srcOffset0 + 3];
|
|
25
|
+
|
|
26
|
+
const x1 = src1[srcOffset1 + 0],
|
|
27
|
+
y1 = src1[srcOffset1 + 1],
|
|
28
|
+
z1 = src1[srcOffset1 + 2],
|
|
29
|
+
w1 = src1[srcOffset1 + 3];
|
|
30
|
+
|
|
31
|
+
if (t === 0) {
|
|
32
|
+
|
|
33
|
+
dst[dstOffset + 0] = x0;
|
|
34
|
+
dst[dstOffset + 1] = y0;
|
|
35
|
+
dst[dstOffset + 2] = z0;
|
|
36
|
+
dst[dstOffset + 3] = w0;
|
|
37
|
+
return;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (t === 1) {
|
|
42
|
+
|
|
43
|
+
dst[dstOffset + 0] = x1;
|
|
44
|
+
dst[dstOffset + 1] = y1;
|
|
45
|
+
dst[dstOffset + 2] = z1;
|
|
46
|
+
dst[dstOffset + 3] = w1;
|
|
47
|
+
return;
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
|
|
52
|
+
|
|
53
|
+
let s = 1 - t;
|
|
54
|
+
const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
|
|
55
|
+
dir = (cos >= 0 ? 1 : - 1),
|
|
56
|
+
sqrSin = 1 - cos * cos;
|
|
57
|
+
|
|
58
|
+
// Skip the Slerp for tiny steps to avoid numeric problems:
|
|
59
|
+
if (sqrSin > Number.EPSILON) {
|
|
60
|
+
|
|
61
|
+
const sin = Math.sqrt(sqrSin),
|
|
62
|
+
len = Math.atan2(sin, cos * dir);
|
|
63
|
+
|
|
64
|
+
s = Math.sin(s * len) / sin;
|
|
65
|
+
t = Math.sin(t * len) / sin;
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const tDir = t * dir;
|
|
70
|
+
|
|
71
|
+
x0 = x0 * s + x1 * tDir;
|
|
72
|
+
y0 = y0 * s + y1 * tDir;
|
|
73
|
+
z0 = z0 * s + z1 * tDir;
|
|
74
|
+
w0 = w0 * s + w1 * tDir;
|
|
75
|
+
|
|
76
|
+
// Normalize in case we just did a lerp:
|
|
77
|
+
if (s === 1 - t) {
|
|
78
|
+
|
|
79
|
+
const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
|
|
80
|
+
|
|
81
|
+
x0 *= f;
|
|
82
|
+
y0 *= f;
|
|
83
|
+
z0 *= f;
|
|
84
|
+
w0 *= f;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
dst[dstOffset] = x0;
|
|
91
|
+
dst[dstOffset + 1] = y0;
|
|
92
|
+
dst[dstOffset + 2] = z0;
|
|
93
|
+
dst[dstOffset + 3] = w0;
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
|
|
98
|
+
|
|
99
|
+
const x0 = src0[srcOffset0];
|
|
100
|
+
const y0 = src0[srcOffset0 + 1];
|
|
101
|
+
const z0 = src0[srcOffset0 + 2];
|
|
102
|
+
const w0 = src0[srcOffset0 + 3];
|
|
103
|
+
|
|
104
|
+
const x1 = src1[srcOffset1];
|
|
105
|
+
const y1 = src1[srcOffset1 + 1];
|
|
106
|
+
const z1 = src1[srcOffset1 + 2];
|
|
107
|
+
const w1 = src1[srcOffset1 + 3];
|
|
108
|
+
|
|
109
|
+
dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
|
|
110
|
+
dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
|
|
111
|
+
dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
|
|
112
|
+
dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
|
|
113
|
+
|
|
114
|
+
return dst;
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get x() {
|
|
119
|
+
|
|
120
|
+
return this._x;
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
set x(value) {
|
|
125
|
+
|
|
126
|
+
this._x = value;
|
|
127
|
+
this._onChangeCallback();
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get y() {
|
|
132
|
+
|
|
133
|
+
return this._y;
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
set y(value) {
|
|
138
|
+
|
|
139
|
+
this._y = value;
|
|
140
|
+
this._onChangeCallback();
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get z() {
|
|
145
|
+
|
|
146
|
+
return this._z;
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
set z(value) {
|
|
151
|
+
|
|
152
|
+
this._z = value;
|
|
153
|
+
this._onChangeCallback();
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
get w() {
|
|
158
|
+
|
|
159
|
+
return this._w;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
set w(value) {
|
|
164
|
+
|
|
165
|
+
this._w = value;
|
|
166
|
+
this._onChangeCallback();
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
set(x, y, z, w) {
|
|
171
|
+
|
|
172
|
+
this._x = x;
|
|
173
|
+
this._y = y;
|
|
174
|
+
this._z = z;
|
|
175
|
+
this._w = w;
|
|
176
|
+
|
|
177
|
+
this._onChangeCallback();
|
|
178
|
+
|
|
179
|
+
return this;
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
clone() {
|
|
184
|
+
|
|
185
|
+
return new this.constructor(this._x, this._y, this._z, this._w);
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
copy(quaternion) {
|
|
190
|
+
|
|
191
|
+
this._x = quaternion.x;
|
|
192
|
+
this._y = quaternion.y;
|
|
193
|
+
this._z = quaternion.z;
|
|
194
|
+
this._w = quaternion.w;
|
|
195
|
+
|
|
196
|
+
this._onChangeCallback();
|
|
197
|
+
|
|
198
|
+
return this;
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
GetEuler() {
|
|
203
|
+
const x = this._x, y = this._y, z = this._z, w = this._w;
|
|
204
|
+
// 构建矩阵元素
|
|
205
|
+
const matrix = [
|
|
206
|
+
// Row0
|
|
207
|
+
[
|
|
208
|
+
1 - 2 * (y * y + z * z),
|
|
209
|
+
2 * (x * y - z * w),
|
|
210
|
+
2 * (x * z + y * w)
|
|
211
|
+
],
|
|
212
|
+
// Row1
|
|
213
|
+
[
|
|
214
|
+
2 * (x * y + z * w),
|
|
215
|
+
1 - 2 * (x * x + z * z),
|
|
216
|
+
2 * (y * z - x * w)
|
|
217
|
+
],
|
|
218
|
+
// Row2
|
|
219
|
+
[
|
|
220
|
+
2 * (x * z - y * w),
|
|
221
|
+
2 * (y * z + x * w),
|
|
222
|
+
1 - 2 * (x * x + y * y)
|
|
223
|
+
]
|
|
224
|
+
];
|
|
225
|
+
// 创建结果对象
|
|
226
|
+
const result = { x: 0, y: 0, z: 0 };
|
|
227
|
+
// 完全按照您提供的Godot代码流程实现
|
|
228
|
+
result.z = 0.0;
|
|
229
|
+
const num = matrix[1][2]; // 这对应basis.Row1[2]
|
|
230
|
+
if (num < 1.0) {
|
|
231
|
+
if (num > -1.0) {
|
|
232
|
+
result.x = Math.asin(0.0 - num);
|
|
233
|
+
result.y = Math.atan2(matrix[0][2], matrix[2][2]);
|
|
234
|
+
result.z = Math.atan2(matrix[1][0], matrix[1][1]);
|
|
235
|
+
} else {
|
|
236
|
+
result.x = 1.5707963705062866;
|
|
237
|
+
result.y = 0.0 - Math.atan2(0.0 - matrix[0][1], matrix[0][0]);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
result.x = -1.5707963705062866;
|
|
241
|
+
result.y = 0.0 - Math.atan2(0.0 - matrix[0][1], matrix[0][0]);
|
|
242
|
+
}
|
|
243
|
+
var vector = new Vector3(result.x, result.y, result.z);
|
|
244
|
+
return vector;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
setFromEuler(euler, update) {
|
|
248
|
+
|
|
249
|
+
const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
|
|
250
|
+
|
|
251
|
+
// http://www.mathworks.com/matlabcentral/fileexchange/
|
|
252
|
+
// 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
|
|
253
|
+
// content/SpinCalc.m
|
|
254
|
+
|
|
255
|
+
const cos = Math.cos;
|
|
256
|
+
const sin = Math.sin;
|
|
257
|
+
|
|
258
|
+
const c1 = cos(x / 2);
|
|
259
|
+
const c2 = cos(y / 2);
|
|
260
|
+
const c3 = cos(z / 2);
|
|
261
|
+
|
|
262
|
+
const s1 = sin(x / 2);
|
|
263
|
+
const s2 = sin(y / 2);
|
|
264
|
+
const s3 = sin(z / 2);
|
|
265
|
+
|
|
266
|
+
switch (order) {
|
|
267
|
+
|
|
268
|
+
case 'XYZ':
|
|
269
|
+
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
270
|
+
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
271
|
+
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
272
|
+
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
273
|
+
break;
|
|
274
|
+
|
|
275
|
+
case 'YXZ':
|
|
276
|
+
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
277
|
+
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
278
|
+
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
279
|
+
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
280
|
+
break;
|
|
281
|
+
|
|
282
|
+
case 'ZXY':
|
|
283
|
+
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
284
|
+
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
285
|
+
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
286
|
+
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
287
|
+
break;
|
|
288
|
+
|
|
289
|
+
case 'ZYX':
|
|
290
|
+
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
291
|
+
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
292
|
+
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
293
|
+
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
294
|
+
break;
|
|
295
|
+
|
|
296
|
+
case 'YZX':
|
|
297
|
+
this._x = s1 * c2 * c3 + c1 * s2 * s3;
|
|
298
|
+
this._y = c1 * s2 * c3 + s1 * c2 * s3;
|
|
299
|
+
this._z = c1 * c2 * s3 - s1 * s2 * c3;
|
|
300
|
+
this._w = c1 * c2 * c3 - s1 * s2 * s3;
|
|
301
|
+
break;
|
|
302
|
+
|
|
303
|
+
case 'XZY':
|
|
304
|
+
this._x = s1 * c2 * c3 - c1 * s2 * s3;
|
|
305
|
+
this._y = c1 * s2 * c3 - s1 * c2 * s3;
|
|
306
|
+
this._z = c1 * c2 * s3 + s1 * s2 * c3;
|
|
307
|
+
this._w = c1 * c2 * c3 + s1 * s2 * s3;
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
default:
|
|
311
|
+
console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (update !== false) this._onChangeCallback();
|
|
316
|
+
|
|
317
|
+
return this;
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
setFromAxisAngle(axis, angle) {
|
|
322
|
+
|
|
323
|
+
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
|
|
324
|
+
|
|
325
|
+
// assumes axis is normalized
|
|
326
|
+
|
|
327
|
+
const halfAngle = angle / 2, s = Math.sin(halfAngle);
|
|
328
|
+
|
|
329
|
+
this._x = axis.x * s;
|
|
330
|
+
this._y = axis.y * s;
|
|
331
|
+
this._z = axis.z * s;
|
|
332
|
+
this._w = Math.cos(halfAngle);
|
|
333
|
+
|
|
334
|
+
this._onChangeCallback();
|
|
335
|
+
|
|
336
|
+
return this;
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
setFromRotationMatrix(m) {
|
|
341
|
+
|
|
342
|
+
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
|
|
343
|
+
|
|
344
|
+
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
345
|
+
|
|
346
|
+
const te = m.elements,
|
|
347
|
+
|
|
348
|
+
m11 = te[0], m12 = te[4], m13 = te[8],
|
|
349
|
+
m21 = te[1], m22 = te[5], m23 = te[9],
|
|
350
|
+
m31 = te[2], m32 = te[6], m33 = te[10],
|
|
351
|
+
|
|
352
|
+
trace = m11 + m22 + m33;
|
|
353
|
+
|
|
354
|
+
if (trace > 0) {
|
|
355
|
+
|
|
356
|
+
const s = 0.5 / Math.sqrt(trace + 1.0);
|
|
357
|
+
|
|
358
|
+
this._w = 0.25 / s;
|
|
359
|
+
this._x = (m32 - m23) * s;
|
|
360
|
+
this._y = (m13 - m31) * s;
|
|
361
|
+
this._z = (m21 - m12) * s;
|
|
362
|
+
|
|
363
|
+
} else if (m11 > m22 && m11 > m33) {
|
|
364
|
+
|
|
365
|
+
const s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
|
|
366
|
+
|
|
367
|
+
this._w = (m32 - m23) / s;
|
|
368
|
+
this._x = 0.25 * s;
|
|
369
|
+
this._y = (m12 + m21) / s;
|
|
370
|
+
this._z = (m13 + m31) / s;
|
|
371
|
+
|
|
372
|
+
} else if (m22 > m33) {
|
|
373
|
+
|
|
374
|
+
const s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
|
|
375
|
+
|
|
376
|
+
this._w = (m13 - m31) / s;
|
|
377
|
+
this._x = (m12 + m21) / s;
|
|
378
|
+
this._y = 0.25 * s;
|
|
379
|
+
this._z = (m23 + m32) / s;
|
|
380
|
+
|
|
381
|
+
} else {
|
|
382
|
+
|
|
383
|
+
const s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
|
|
384
|
+
|
|
385
|
+
this._w = (m21 - m12) / s;
|
|
386
|
+
this._x = (m13 + m31) / s;
|
|
387
|
+
this._y = (m23 + m32) / s;
|
|
388
|
+
this._z = 0.25 * s;
|
|
389
|
+
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
this._onChangeCallback();
|
|
393
|
+
|
|
394
|
+
return this;
|
|
395
|
+
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
setFromUnitVectors(vFrom, vTo) {
|
|
399
|
+
|
|
400
|
+
// assumes direction vectors vFrom and vTo are normalized
|
|
401
|
+
|
|
402
|
+
let r = vFrom.dot(vTo) + 1;
|
|
403
|
+
|
|
404
|
+
if (r < Number.EPSILON) {
|
|
405
|
+
|
|
406
|
+
// vFrom and vTo point in opposite directions
|
|
407
|
+
|
|
408
|
+
r = 0;
|
|
409
|
+
|
|
410
|
+
if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
|
|
411
|
+
|
|
412
|
+
this._x = - vFrom.y;
|
|
413
|
+
this._y = vFrom.x;
|
|
414
|
+
this._z = 0;
|
|
415
|
+
this._w = r;
|
|
416
|
+
|
|
417
|
+
} else {
|
|
418
|
+
|
|
419
|
+
this._x = 0;
|
|
420
|
+
this._y = - vFrom.z;
|
|
421
|
+
this._z = vFrom.y;
|
|
422
|
+
this._w = r;
|
|
423
|
+
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
} else {
|
|
427
|
+
|
|
428
|
+
// crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
|
|
429
|
+
|
|
430
|
+
this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
|
|
431
|
+
this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
|
|
432
|
+
this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
|
|
433
|
+
this._w = r;
|
|
434
|
+
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return this.normalize();
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
angleTo(q) {
|
|
442
|
+
|
|
443
|
+
return 2 * Math.acos(Math.abs(MathUtils.clamp(this.dot(q), - 1, 1)));
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
rotateTowards(q, step) {
|
|
448
|
+
|
|
449
|
+
const angle = this.angleTo(q);
|
|
450
|
+
|
|
451
|
+
if (angle === 0) return this;
|
|
452
|
+
|
|
453
|
+
const t = Math.min(1, step / angle);
|
|
454
|
+
|
|
455
|
+
this.slerp(q, t);
|
|
456
|
+
|
|
457
|
+
return this;
|
|
458
|
+
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
identity() {
|
|
462
|
+
|
|
463
|
+
return this.set(0, 0, 0, 1);
|
|
464
|
+
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
invert() {
|
|
468
|
+
|
|
469
|
+
// quaternion is assumed to have unit length
|
|
470
|
+
|
|
471
|
+
return this.conjugate();
|
|
472
|
+
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
conjugate() {
|
|
476
|
+
|
|
477
|
+
this._x *= - 1;
|
|
478
|
+
this._y *= - 1;
|
|
479
|
+
this._z *= - 1;
|
|
480
|
+
|
|
481
|
+
this._onChangeCallback();
|
|
482
|
+
|
|
483
|
+
return this;
|
|
484
|
+
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
dot(v) {
|
|
488
|
+
|
|
489
|
+
return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
|
|
490
|
+
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
lengthSq() {
|
|
494
|
+
|
|
495
|
+
return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
|
|
496
|
+
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
length() {
|
|
500
|
+
|
|
501
|
+
return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
|
|
502
|
+
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
normalize() {
|
|
506
|
+
|
|
507
|
+
let l = this.length();
|
|
508
|
+
|
|
509
|
+
if (l === 0) {
|
|
510
|
+
|
|
511
|
+
this._x = 0;
|
|
512
|
+
this._y = 0;
|
|
513
|
+
this._z = 0;
|
|
514
|
+
this._w = 1;
|
|
515
|
+
|
|
516
|
+
} else {
|
|
517
|
+
|
|
518
|
+
l = 1 / l;
|
|
519
|
+
|
|
520
|
+
this._x = this._x * l;
|
|
521
|
+
this._y = this._y * l;
|
|
522
|
+
this._z = this._z * l;
|
|
523
|
+
this._w = this._w * l;
|
|
524
|
+
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
this._onChangeCallback();
|
|
528
|
+
|
|
529
|
+
return this;
|
|
530
|
+
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
multiply(q) {
|
|
534
|
+
|
|
535
|
+
return this.multiplyQuaternions(this, q);
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
premultiply(q) {
|
|
540
|
+
|
|
541
|
+
return this.multiplyQuaternions(q, this);
|
|
542
|
+
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
multiplyQuaternions(a, b) {
|
|
546
|
+
|
|
547
|
+
// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
|
|
548
|
+
|
|
549
|
+
const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
|
|
550
|
+
const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
|
|
551
|
+
|
|
552
|
+
this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
|
|
553
|
+
this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
|
|
554
|
+
this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
|
|
555
|
+
this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
|
|
556
|
+
|
|
557
|
+
this._onChangeCallback();
|
|
558
|
+
|
|
559
|
+
return this;
|
|
560
|
+
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
slerp(qb, t) {
|
|
564
|
+
|
|
565
|
+
if (t === 0) return this;
|
|
566
|
+
if (t === 1) return this.copy(qb);
|
|
567
|
+
|
|
568
|
+
const x = this._x, y = this._y, z = this._z, w = this._w;
|
|
569
|
+
|
|
570
|
+
// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
|
|
571
|
+
|
|
572
|
+
let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
|
|
573
|
+
|
|
574
|
+
if (cosHalfTheta < 0) {
|
|
575
|
+
|
|
576
|
+
this._w = - qb._w;
|
|
577
|
+
this._x = - qb._x;
|
|
578
|
+
this._y = - qb._y;
|
|
579
|
+
this._z = - qb._z;
|
|
580
|
+
|
|
581
|
+
cosHalfTheta = - cosHalfTheta;
|
|
582
|
+
|
|
583
|
+
} else {
|
|
584
|
+
|
|
585
|
+
this.copy(qb);
|
|
586
|
+
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (cosHalfTheta >= 1.0) {
|
|
590
|
+
|
|
591
|
+
this._w = w;
|
|
592
|
+
this._x = x;
|
|
593
|
+
this._y = y;
|
|
594
|
+
this._z = z;
|
|
595
|
+
|
|
596
|
+
return this;
|
|
597
|
+
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
|
|
601
|
+
|
|
602
|
+
if (sqrSinHalfTheta <= Number.EPSILON) {
|
|
603
|
+
|
|
604
|
+
const s = 1 - t;
|
|
605
|
+
this._w = s * w + t * this._w;
|
|
606
|
+
this._x = s * x + t * this._x;
|
|
607
|
+
this._y = s * y + t * this._y;
|
|
608
|
+
this._z = s * z + t * this._z;
|
|
609
|
+
|
|
610
|
+
this.normalize();
|
|
611
|
+
this._onChangeCallback();
|
|
612
|
+
|
|
613
|
+
return this;
|
|
614
|
+
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
|
|
618
|
+
const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
|
|
619
|
+
const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
|
|
620
|
+
ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
|
|
621
|
+
|
|
622
|
+
this._w = (w * ratioA + this._w * ratioB);
|
|
623
|
+
this._x = (x * ratioA + this._x * ratioB);
|
|
624
|
+
this._y = (y * ratioA + this._y * ratioB);
|
|
625
|
+
this._z = (z * ratioA + this._z * ratioB);
|
|
626
|
+
|
|
627
|
+
this._onChangeCallback();
|
|
628
|
+
|
|
629
|
+
return this;
|
|
630
|
+
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
slerpQuaternions(qa, qb, t) {
|
|
634
|
+
|
|
635
|
+
return this.copy(qa).slerp(qb, t);
|
|
636
|
+
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
random() {
|
|
640
|
+
|
|
641
|
+
// Derived from http://planning.cs.uiuc.edu/node198.html
|
|
642
|
+
// Note, this source uses w, x, y, z ordering,
|
|
643
|
+
// so we swap the order below.
|
|
644
|
+
|
|
645
|
+
const u1 = Math.random();
|
|
646
|
+
const sqrt1u1 = Math.sqrt(1 - u1);
|
|
647
|
+
const sqrtu1 = Math.sqrt(u1);
|
|
648
|
+
|
|
649
|
+
const u2 = 2 * Math.PI * Math.random();
|
|
650
|
+
|
|
651
|
+
const u3 = 2 * Math.PI * Math.random();
|
|
652
|
+
|
|
653
|
+
return this.set(
|
|
654
|
+
sqrt1u1 * Math.cos(u2),
|
|
655
|
+
sqrtu1 * Math.sin(u3),
|
|
656
|
+
sqrtu1 * Math.cos(u3),
|
|
657
|
+
sqrt1u1 * Math.sin(u2),
|
|
658
|
+
);
|
|
659
|
+
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
equals(quaternion) {
|
|
663
|
+
|
|
664
|
+
return (quaternion._x === this._x) && (quaternion._y === this._y) && (quaternion._z === this._z) && (quaternion._w === this._w);
|
|
665
|
+
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
fromArray(array, offset = 0) {
|
|
669
|
+
|
|
670
|
+
this._x = array[offset];
|
|
671
|
+
this._y = array[offset + 1];
|
|
672
|
+
this._z = array[offset + 2];
|
|
673
|
+
this._w = array[offset + 3];
|
|
674
|
+
|
|
675
|
+
this._onChangeCallback();
|
|
676
|
+
|
|
677
|
+
return this;
|
|
678
|
+
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
toArray(array = [], offset = 0) {
|
|
682
|
+
|
|
683
|
+
array[offset] = this._x;
|
|
684
|
+
array[offset + 1] = this._y;
|
|
685
|
+
array[offset + 2] = this._z;
|
|
686
|
+
array[offset + 3] = this._w;
|
|
687
|
+
|
|
688
|
+
return array;
|
|
689
|
+
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
fromBufferAttribute(attribute, index) {
|
|
693
|
+
|
|
694
|
+
this._x = attribute.getX(index);
|
|
695
|
+
this._y = attribute.getY(index);
|
|
696
|
+
this._z = attribute.getZ(index);
|
|
697
|
+
this._w = attribute.getW(index);
|
|
698
|
+
|
|
699
|
+
return this;
|
|
700
|
+
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
_onChange(callback) {
|
|
704
|
+
|
|
705
|
+
this._onChangeCallback = callback;
|
|
706
|
+
|
|
707
|
+
return this;
|
|
708
|
+
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
_onChangeCallback() { }
|
|
712
|
+
|
|
713
|
+
*[Symbol.iterator]() {
|
|
714
|
+
|
|
715
|
+
yield this._x;
|
|
716
|
+
yield this._y;
|
|
717
|
+
yield this._z;
|
|
718
|
+
yield this._w;
|
|
719
|
+
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
export { Quaternion };
|