@math.gl/core 4.2.0-alpha.5 → 5.0.0-alpha.1
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/dist/classes/euler.d.ts +37 -25
- package/dist/classes/euler.d.ts.map +1 -1
- package/dist/classes/euler.js +99 -54
- package/dist/classes/euler.js.map +1 -1
- package/dist/classes/pose.d.ts.map +1 -1
- package/dist/classes/pose.js +2 -3
- package/dist/classes/pose.js.map +1 -1
- package/dist/index.cjs +102 -55
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/classes/euler.ts +111 -60
- package/src/classes/pose.ts +2 -3
- package/src/index.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type { Matrix4Like } from "./classes/matrix4.js";
|
|
|
17
17
|
export { SphericalCoordinates } from "./classes/spherical-coordinates.js";
|
|
18
18
|
export { Pose } from "./classes/pose.js";
|
|
19
19
|
export { Euler } from "./classes/euler.js";
|
|
20
|
+
export type { EulerRotationOrder } from "./classes/euler.js";
|
|
20
21
|
export * as _MathUtils from "./lib/math-utils.js";
|
|
21
22
|
export { assert } from "./lib/assert.js";
|
|
22
23
|
export { config, configure, safeMod, normalizeAngle, formatValue, isArray, clone, equals, exactEquals, toRadians, toDegrees, radians, degrees, sin, cos, tan, asin, acos, atan, clamp, lerp, withEpsilon } from "./lib/common.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,UAAU,EACV,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACd,MAAM,gBAAgB,CAAC;A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AClC,OAAO,KAAK,IAAI,4BAAyB;AACzC,4BAA4B;AAC5B,OAAO,KAAK,IAAI,4BAAyB;AACzC,8BAA8B;AAC9B,OAAO,KAAK,IAAI,4BAAyB;AACzC,8BAA8B;AAC9B,OAAO,KAAK,IAAI,4BAAyB"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAoBpC,UAAU;AACV,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,qCAAkC;AAClE,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,iCAA8B;AACxD,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,iCAA8B;AACxD,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,UAAU,EAAC,gCAA6B;AAQhD,eAAe;AACf,OAAO,EAAC,oBAAoB,EAAC,2CAAwC;AACrE,OAAO,EAAC,IAAI,EAAC,0BAAuB;AACpC,OAAO,EAAC,KAAK,EAAC,2BAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAoBpC,UAAU;AACV,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,qCAAkC;AAClE,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,iCAA8B;AACxD,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,iCAA8B;AACxD,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAAC,OAAO,EAAC,6BAA0B;AAC1C,OAAO,EAA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"
|
|
9
|
+
"version": "5.0.0-alpha.1",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"webgl",
|
|
12
12
|
"javascript",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"./src/lib/common.js"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@math.gl/types": "
|
|
48
|
+
"@math.gl/types": "5.0.0-alpha.1"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0c9bf3e5da10ce0fdafe84f3a8520c5ed9c15211"
|
|
51
51
|
}
|
package/src/classes/euler.ts
CHANGED
|
@@ -14,8 +14,10 @@ import {checkNumber} from '../lib/validators';
|
|
|
14
14
|
const ERR_UNKNOWN_ORDER = 'Unknown Euler angle order';
|
|
15
15
|
const ALMOST_ONE = 0.99999;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/** Order in which Euler rotations are applied. */
|
|
18
|
+
export type EulerRotationOrder = 'zyx' | 'yxz' | 'xzy' | 'zxy' | 'yzx' | 'xyz';
|
|
19
|
+
|
|
20
|
+
enum RotationOrderIndex {
|
|
19
21
|
ZYX = 0,
|
|
20
22
|
YXZ = 1,
|
|
21
23
|
XZY = 2,
|
|
@@ -24,37 +26,65 @@ enum RotationOrder {
|
|
|
24
26
|
XYZ = 5
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
const ROTATION_ORDER_INDICES: Record<EulerRotationOrder, RotationOrderIndex> = {
|
|
30
|
+
zyx: RotationOrderIndex.ZYX,
|
|
31
|
+
yxz: RotationOrderIndex.YXZ,
|
|
32
|
+
xzy: RotationOrderIndex.XZY,
|
|
33
|
+
zxy: RotationOrderIndex.ZXY,
|
|
34
|
+
yzx: RotationOrderIndex.YZX,
|
|
35
|
+
xyz: RotationOrderIndex.XYZ
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const ROTATION_ORDERS = {
|
|
39
|
+
ZYX: 'zyx',
|
|
40
|
+
YXZ: 'yxz',
|
|
41
|
+
XZY: 'xzy',
|
|
42
|
+
ZXY: 'zxy',
|
|
43
|
+
YZX: 'yzx',
|
|
44
|
+
XYZ: 'xyz'
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
27
47
|
export class Euler extends MathArray {
|
|
28
48
|
// Constants
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
/** @deprecated Pass the string `'zyx'` directly. */
|
|
50
|
+
static get ZYX(): EulerRotationOrder {
|
|
51
|
+
return 'zyx';
|
|
31
52
|
}
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
/** @deprecated Pass the string `'yxz'` directly. */
|
|
54
|
+
static get YXZ(): EulerRotationOrder {
|
|
55
|
+
return 'yxz';
|
|
34
56
|
}
|
|
35
|
-
|
|
36
|
-
|
|
57
|
+
/** @deprecated Pass the string `'xzy'` directly. */
|
|
58
|
+
static get XZY(): EulerRotationOrder {
|
|
59
|
+
return 'xzy';
|
|
37
60
|
}
|
|
38
|
-
|
|
39
|
-
|
|
61
|
+
/** @deprecated Pass the string `'zxy'` directly. */
|
|
62
|
+
static get ZXY(): EulerRotationOrder {
|
|
63
|
+
return 'zxy';
|
|
40
64
|
}
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
/** @deprecated Pass the string `'yzx'` directly. */
|
|
66
|
+
static get YZX(): EulerRotationOrder {
|
|
67
|
+
return 'yzx';
|
|
43
68
|
}
|
|
44
|
-
|
|
45
|
-
|
|
69
|
+
/** @deprecated Pass the string `'xyz'` directly. */
|
|
70
|
+
static get XYZ(): EulerRotationOrder {
|
|
71
|
+
return 'xyz';
|
|
46
72
|
}
|
|
47
|
-
|
|
48
|
-
|
|
73
|
+
/** @deprecated Pass the string `'zyx'` directly. */
|
|
74
|
+
static get RollPitchYaw(): EulerRotationOrder {
|
|
75
|
+
return 'zyx';
|
|
49
76
|
}
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
/** @deprecated Pass the string `'zyx'` directly. */
|
|
78
|
+
static get DefaultOrder(): EulerRotationOrder {
|
|
79
|
+
return 'zyx';
|
|
52
80
|
}
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
/** @deprecated Pass an {@link EulerRotationOrder} string directly. */
|
|
82
|
+
static get RotationOrders(): typeof ROTATION_ORDERS {
|
|
83
|
+
return ROTATION_ORDERS;
|
|
55
84
|
}
|
|
56
|
-
|
|
57
|
-
|
|
85
|
+
/** @deprecated Euler rotation orders are already represented as strings. */
|
|
86
|
+
static rotationOrder(order: EulerRotationOrder): EulerRotationOrder {
|
|
87
|
+
return order;
|
|
58
88
|
}
|
|
59
89
|
get ELEMENTS(): number {
|
|
60
90
|
return 4;
|
|
@@ -67,7 +97,7 @@ export class Euler extends MathArray {
|
|
|
67
97
|
* @param {Number=} [z]
|
|
68
98
|
* @param {Number=} [order]
|
|
69
99
|
*/
|
|
70
|
-
constructor(x = 0, y = 0, z = 0, order =
|
|
100
|
+
constructor(x = 0, y = 0, z = 0, order: EulerRotationOrder = 'zyx') {
|
|
71
101
|
// PERF NOTE: initialize elements as double precision numbers
|
|
72
102
|
super(-0, -0, -0, -0);
|
|
73
103
|
// eslint-disable-next-line prefer-rest-params
|
|
@@ -93,7 +123,7 @@ export class Euler extends MathArray {
|
|
|
93
123
|
const roll = Math.atan2(t3, t4);
|
|
94
124
|
const pitch = Math.asin(t2);
|
|
95
125
|
const yaw = Math.atan2(t1, t0);
|
|
96
|
-
return this.set(roll, pitch, yaw,
|
|
126
|
+
return this.set(roll, pitch, yaw, 'zyx');
|
|
97
127
|
}
|
|
98
128
|
|
|
99
129
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -111,18 +141,19 @@ export class Euler extends MathArray {
|
|
|
111
141
|
this[0] = array[0];
|
|
112
142
|
this[1] = array[1];
|
|
113
143
|
this[2] = array[2];
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
if (Number.isFinite(array[3]) && validateOrder(array[3])) {
|
|
145
|
+
this[3] = array[3];
|
|
146
|
+
}
|
|
116
147
|
return this.check();
|
|
117
148
|
}
|
|
118
149
|
|
|
119
150
|
// Sets the three angles, and optionally sets the rotation order
|
|
120
151
|
// If order is not specified, preserves currently set order
|
|
121
|
-
set(x = 0, y = 0, z = 0, order:
|
|
152
|
+
set(x = 0, y = 0, z = 0, order: EulerRotationOrder): this {
|
|
122
153
|
this[0] = x;
|
|
123
154
|
this[1] = y;
|
|
124
155
|
this[2] = z;
|
|
125
|
-
this[3] =
|
|
156
|
+
this[3] = order ? checkOrder(order) : this[3];
|
|
126
157
|
return this.check();
|
|
127
158
|
}
|
|
128
159
|
|
|
@@ -248,16 +279,16 @@ export class Euler extends MathArray {
|
|
|
248
279
|
}
|
|
249
280
|
|
|
250
281
|
// rotation order, in all three angle notations
|
|
251
|
-
get order():
|
|
252
|
-
return this[3];
|
|
282
|
+
get order(): EulerRotationOrder {
|
|
283
|
+
return getOrder(this[3]);
|
|
253
284
|
}
|
|
254
|
-
set order(value:
|
|
285
|
+
set order(value: EulerRotationOrder) {
|
|
255
286
|
this[3] = checkOrder(value);
|
|
256
287
|
}
|
|
257
288
|
|
|
258
289
|
// Constructors
|
|
259
|
-
fromVector3(v: Readonly<NumericArray>, order:
|
|
260
|
-
return this.set(v[0], v[1], v[2],
|
|
290
|
+
fromVector3(v: Readonly<NumericArray>, order: EulerRotationOrder = this.order): this {
|
|
291
|
+
return this.set(v[0], v[1], v[2], order);
|
|
261
292
|
}
|
|
262
293
|
|
|
263
294
|
// TODO - with and without 4th element
|
|
@@ -273,10 +304,10 @@ export class Euler extends MathArray {
|
|
|
273
304
|
|
|
274
305
|
// Common ZYX rotation order
|
|
275
306
|
fromRollPitchYaw(roll: number, pitch: number, yaw: number): this {
|
|
276
|
-
return this.set(roll, pitch, yaw,
|
|
307
|
+
return this.set(roll, pitch, yaw, 'zyx');
|
|
277
308
|
}
|
|
278
309
|
|
|
279
|
-
fromRotationMatrix(m: Readonly<NumericArray>, order:
|
|
310
|
+
fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder = 'zyx'): this {
|
|
280
311
|
this._fromRotationMatrix(m, order);
|
|
281
312
|
return this.check();
|
|
282
313
|
}
|
|
@@ -291,17 +322,17 @@ export class Euler extends MathArray {
|
|
|
291
322
|
getQuaternion(): Quaternion {
|
|
292
323
|
const q = new Quaternion();
|
|
293
324
|
switch (this[3]) {
|
|
294
|
-
case
|
|
325
|
+
case RotationOrderIndex.XYZ:
|
|
295
326
|
return q.rotateX(this[0]).rotateY(this[1]).rotateZ(this[2]);
|
|
296
|
-
case
|
|
327
|
+
case RotationOrderIndex.YXZ:
|
|
297
328
|
return q.rotateY(this[1]).rotateX(this[0]).rotateZ(this[2]);
|
|
298
|
-
case
|
|
329
|
+
case RotationOrderIndex.ZXY:
|
|
299
330
|
return q.rotateZ(this[2]).rotateX(this[0]).rotateY(this[1]);
|
|
300
|
-
case
|
|
331
|
+
case RotationOrderIndex.ZYX:
|
|
301
332
|
return q.rotateZ(this[2]).rotateY(this[1]).rotateX(this[0]);
|
|
302
|
-
case
|
|
333
|
+
case RotationOrderIndex.YZX:
|
|
303
334
|
return q.rotateY(this[1]).rotateZ(this[2]).rotateX(this[0]);
|
|
304
|
-
case
|
|
335
|
+
case RotationOrderIndex.XZY:
|
|
305
336
|
return q.rotateX(this[0]).rotateZ(this[2]).rotateY(this[1]);
|
|
306
337
|
default:
|
|
307
338
|
throw new Error(ERR_UNKNOWN_ORDER);
|
|
@@ -316,7 +347,7 @@ export class Euler extends MathArray {
|
|
|
316
347
|
// const q = new Quaternion().setFromEuler(this);
|
|
317
348
|
// return this.setFromQuaternion(q, newOrder);
|
|
318
349
|
/* eslint-disable complexity, max-statements, one-var */
|
|
319
|
-
_fromRotationMatrix(m: Readonly<NumericArray>, order =
|
|
350
|
+
_fromRotationMatrix(m: Readonly<NumericArray>, order: EulerRotationOrder = 'zyx'): this {
|
|
320
351
|
// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
|
|
321
352
|
const m11 = m[0],
|
|
322
353
|
m12 = m[4],
|
|
@@ -327,9 +358,9 @@ export class Euler extends MathArray {
|
|
|
327
358
|
const m31 = m[2],
|
|
328
359
|
m32 = m[6],
|
|
329
360
|
m33 = m[10];
|
|
330
|
-
|
|
331
|
-
switch (
|
|
332
|
-
case
|
|
361
|
+
const orderIndex = order ? checkOrder(order) : this[3];
|
|
362
|
+
switch (orderIndex) {
|
|
363
|
+
case RotationOrderIndex.XYZ:
|
|
333
364
|
this[1] = Math.asin(clamp(m13, -1, 1));
|
|
334
365
|
if (Math.abs(m13) < ALMOST_ONE) {
|
|
335
366
|
this[0] = Math.atan2(-m23, m33);
|
|
@@ -339,7 +370,7 @@ export class Euler extends MathArray {
|
|
|
339
370
|
this[2] = 0;
|
|
340
371
|
}
|
|
341
372
|
break;
|
|
342
|
-
case
|
|
373
|
+
case RotationOrderIndex.YXZ:
|
|
343
374
|
this[0] = Math.asin(-clamp(m23, -1, 1));
|
|
344
375
|
if (Math.abs(m23) < ALMOST_ONE) {
|
|
345
376
|
this[1] = Math.atan2(m13, m33);
|
|
@@ -349,7 +380,7 @@ export class Euler extends MathArray {
|
|
|
349
380
|
this[2] = 0;
|
|
350
381
|
}
|
|
351
382
|
break;
|
|
352
|
-
case
|
|
383
|
+
case RotationOrderIndex.ZXY:
|
|
353
384
|
this[0] = Math.asin(clamp(m32, -1, 1));
|
|
354
385
|
if (Math.abs(m32) < ALMOST_ONE) {
|
|
355
386
|
this[1] = Math.atan2(-m31, m33);
|
|
@@ -359,7 +390,7 @@ export class Euler extends MathArray {
|
|
|
359
390
|
this[2] = Math.atan2(m21, m11);
|
|
360
391
|
}
|
|
361
392
|
break;
|
|
362
|
-
case
|
|
393
|
+
case RotationOrderIndex.ZYX:
|
|
363
394
|
this[1] = Math.asin(-clamp(m31, -1, 1));
|
|
364
395
|
if (Math.abs(m31) < ALMOST_ONE) {
|
|
365
396
|
this[0] = Math.atan2(m32, m33);
|
|
@@ -369,7 +400,7 @@ export class Euler extends MathArray {
|
|
|
369
400
|
this[2] = Math.atan2(-m12, m22);
|
|
370
401
|
}
|
|
371
402
|
break;
|
|
372
|
-
case
|
|
403
|
+
case RotationOrderIndex.YZX:
|
|
373
404
|
this[2] = Math.asin(clamp(m21, -1, 1));
|
|
374
405
|
if (Math.abs(m21) < ALMOST_ONE) {
|
|
375
406
|
this[0] = Math.atan2(-m23, m22);
|
|
@@ -379,7 +410,7 @@ export class Euler extends MathArray {
|
|
|
379
410
|
this[1] = Math.atan2(m13, m33);
|
|
380
411
|
}
|
|
381
412
|
break;
|
|
382
|
-
case
|
|
413
|
+
case RotationOrderIndex.XZY:
|
|
383
414
|
this[2] = Math.asin(-clamp(m12, -1, 1));
|
|
384
415
|
if (Math.abs(m12) < ALMOST_ONE) {
|
|
385
416
|
this[0] = Math.atan2(m32, m22);
|
|
@@ -392,7 +423,7 @@ export class Euler extends MathArray {
|
|
|
392
423
|
default:
|
|
393
424
|
throw new Error(ERR_UNKNOWN_ORDER);
|
|
394
425
|
}
|
|
395
|
-
this[3] =
|
|
426
|
+
this[3] = orderIndex;
|
|
396
427
|
return this;
|
|
397
428
|
}
|
|
398
429
|
|
|
@@ -408,7 +439,7 @@ export class Euler extends MathArray {
|
|
|
408
439
|
const d = Math.sin(y);
|
|
409
440
|
const f = Math.sin(z);
|
|
410
441
|
switch (this[3]) {
|
|
411
|
-
case
|
|
442
|
+
case RotationOrderIndex.XYZ: {
|
|
412
443
|
const ae = a * e,
|
|
413
444
|
af = a * f,
|
|
414
445
|
be = b * e,
|
|
@@ -424,7 +455,7 @@ export class Euler extends MathArray {
|
|
|
424
455
|
te[10] = a * c;
|
|
425
456
|
break;
|
|
426
457
|
}
|
|
427
|
-
case
|
|
458
|
+
case RotationOrderIndex.YXZ: {
|
|
428
459
|
const ce = c * e,
|
|
429
460
|
cf = c * f,
|
|
430
461
|
de = d * e,
|
|
@@ -440,7 +471,7 @@ export class Euler extends MathArray {
|
|
|
440
471
|
te[10] = a * c;
|
|
441
472
|
break;
|
|
442
473
|
}
|
|
443
|
-
case
|
|
474
|
+
case RotationOrderIndex.ZXY: {
|
|
444
475
|
const ce = c * e,
|
|
445
476
|
cf = c * f,
|
|
446
477
|
de = d * e,
|
|
@@ -456,7 +487,7 @@ export class Euler extends MathArray {
|
|
|
456
487
|
te[10] = a * c;
|
|
457
488
|
break;
|
|
458
489
|
}
|
|
459
|
-
case
|
|
490
|
+
case RotationOrderIndex.ZYX: {
|
|
460
491
|
const ae = a * e,
|
|
461
492
|
af = a * f,
|
|
462
493
|
be = b * e,
|
|
@@ -472,7 +503,7 @@ export class Euler extends MathArray {
|
|
|
472
503
|
te[10] = a * c;
|
|
473
504
|
break;
|
|
474
505
|
}
|
|
475
|
-
case
|
|
506
|
+
case RotationOrderIndex.YZX: {
|
|
476
507
|
const ac = a * c,
|
|
477
508
|
ad = a * d,
|
|
478
509
|
bc = b * c,
|
|
@@ -488,7 +519,7 @@ export class Euler extends MathArray {
|
|
|
488
519
|
te[10] = ac - bd * f;
|
|
489
520
|
break;
|
|
490
521
|
}
|
|
491
|
-
case
|
|
522
|
+
case RotationOrderIndex.XZY: {
|
|
492
523
|
const ac = a * c,
|
|
493
524
|
ad = a * d,
|
|
494
525
|
bc = b * c,
|
|
@@ -541,9 +572,29 @@ function validateOrder(value: number): boolean {
|
|
|
541
572
|
return value >= 0 && value < 6;
|
|
542
573
|
}
|
|
543
574
|
|
|
544
|
-
function checkOrder(value:
|
|
545
|
-
|
|
575
|
+
function checkOrder(value: EulerRotationOrder): RotationOrderIndex {
|
|
576
|
+
const order = ROTATION_ORDER_INDICES[value];
|
|
577
|
+
if (order === undefined) {
|
|
546
578
|
throw new Error(ERR_UNKNOWN_ORDER);
|
|
547
579
|
}
|
|
548
|
-
return
|
|
580
|
+
return order;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function getOrder(value: number): EulerRotationOrder {
|
|
584
|
+
switch (value) {
|
|
585
|
+
case RotationOrderIndex.ZYX:
|
|
586
|
+
return 'zyx';
|
|
587
|
+
case RotationOrderIndex.YXZ:
|
|
588
|
+
return 'yxz';
|
|
589
|
+
case RotationOrderIndex.XZY:
|
|
590
|
+
return 'xzy';
|
|
591
|
+
case RotationOrderIndex.ZXY:
|
|
592
|
+
return 'zxy';
|
|
593
|
+
case RotationOrderIndex.YZX:
|
|
594
|
+
return 'yzx';
|
|
595
|
+
case RotationOrderIndex.XYZ:
|
|
596
|
+
return 'xyz';
|
|
597
|
+
default:
|
|
598
|
+
throw new Error(ERR_UNKNOWN_ORDER);
|
|
599
|
+
}
|
|
549
600
|
}
|
package/src/classes/pose.ts
CHANGED
|
@@ -39,10 +39,9 @@ export class Pose {
|
|
|
39
39
|
this.position = new Vector3(x, y, z);
|
|
40
40
|
}
|
|
41
41
|
if (Array.isArray(orientation) && orientation.length === 4) {
|
|
42
|
-
|
|
43
|
-
this.orientation = new Euler(orientation, orientation[3]);
|
|
42
|
+
this.orientation = new Euler().fromArray(orientation);
|
|
44
43
|
} else {
|
|
45
|
-
this.orientation = new Euler(roll, pitch, yaw,
|
|
44
|
+
this.orientation = new Euler(roll, pitch, yaw, 'zyx');
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type {Matrix4Like} from './classes/matrix4';
|
|
|
41
41
|
export {SphericalCoordinates} from './classes/spherical-coordinates';
|
|
42
42
|
export {Pose} from './classes/pose';
|
|
43
43
|
export {Euler} from './classes/euler';
|
|
44
|
+
export type {EulerRotationOrder} from './classes/euler';
|
|
44
45
|
|
|
45
46
|
export * as _MathUtils from './lib/math-utils';
|
|
46
47
|
|