@vived/app 2.20.1 → 2.21.2
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/lib/Core/BaseApp/Boundary.d.ts +49 -0
- package/lib/Core/BaseApp/Boundary.js +2 -0
- package/lib/Core/BaseApp/Entity.d.ts +11 -0
- package/lib/Core/BaseApp/Entity.js +2 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorNoHostHandler.js +10 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/BaseApp/Errors/index.d.ts +3 -0
- package/lib/Core/BaseApp/Errors/index.js +15 -0
- package/lib/Core/BaseApp/UseCase.d.ts +43 -0
- package/lib/Core/BaseApp/UseCase.js +250 -0
- package/lib/Core/BaseAppState/Boundary.d.ts +14 -0
- package/lib/Core/BaseAppState/Boundary.js +2 -0
- package/lib/Core/BaseAppState/Entity.d.ts +5 -0
- package/lib/Core/BaseAppState/Entity.js +2 -0
- package/lib/Core/BaseAppState/UseCase.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase.js +54 -0
- package/lib/Core/BaseAppState/UseCase_Imp.d.ts +16 -0
- package/lib/Core/BaseAppState/UseCase_Imp.js +54 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.d.ts +16 -0
- package/lib/Core/DevicePreview/DevicePreviewUC_Imp.js +56 -0
- package/lib/Core/DevicePreview/boundary.d.ts +14 -0
- package/lib/Core/DevicePreview/boundary.js +2 -0
- package/lib/Core/DevicePreview/entity.d.ts +5 -0
- package/lib/Core/DevicePreview/entity.js +2 -0
- package/lib/Core/DispatchToHost/Entity.d.ts +4 -0
- package/lib/Core/DispatchToHost/Entity.js +2 -0
- package/lib/Core/DispatchToHost/UseCase.d.ts +12 -0
- package/lib/Core/DispatchToHost/UseCase.js +70 -0
- package/lib/Core/DispatchToHost/boundary.d.ts +9 -0
- package/lib/Core/DispatchToHost/boundary.js +2 -0
- package/lib/Core/Serilization/Boundary.d.ts +20 -0
- package/lib/Core/Serilization/Boundary.js +2 -0
- package/lib/Core/Serilization/Entity.d.ts +3 -0
- package/lib/Core/Serilization/Entity.js +2 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.d.ts +3 -0
- package/lib/Core/Serilization/ErrorDuplicateSystemName.js +12 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.d.ts +3 -0
- package/lib/Core/Serilization/ErrorUnsupportedVersionNumber.js +10 -0
- package/lib/Core/Serilization/Errors.d.ts +6 -0
- package/lib/Core/Serilization/Errors.js +19 -0
- package/lib/Core/Serilization/UseCase.d.ts +10 -0
- package/lib/Core/Serilization/UseCase.js +52 -0
- package/lib/Core/Serilization/UseCase_Imp.d.ts +10 -0
- package/lib/Core/Serilization/UseCase_Imp.js +51 -0
- package/lib/Core/index.d.ts +3 -0
- package/lib/Core/index.js +19 -0
- package/lib/Entities/Color.d.ts +20 -0
- package/lib/Entities/Color.js +59 -0
- package/lib/Entities/LineSegment2D.d.ts +11 -0
- package/lib/Entities/LineSegment2D.js +70 -0
- package/lib/Entities/MouseInput.js +1 -0
- package/lib/Entities/MouseSceneInput.d.ts +15 -0
- package/lib/Entities/MouseSceneInput.js +109 -0
- package/lib/Entities/OrbitCamera.d.ts +76 -0
- package/lib/Entities/OrbitCamera.js +243 -0
- package/lib/Entities/ParametricLine.d.ts +29 -0
- package/lib/Entities/ParametricLine.js +79 -0
- package/lib/Entities/ParametricPlane.d.ts +20 -0
- package/lib/Entities/ParametricPlane.js +63 -0
- package/lib/Entities/SceneRoot.d.ts +69 -0
- package/lib/Entities/SceneRoot.js +77 -0
- package/lib/Entities/TransformNode.d.ts +78 -0
- package/lib/Entities/TransformNode.js +217 -0
- package/lib/Entities/Vector2.d.ts +21 -0
- package/lib/Entities/Vector2.js +83 -0
- package/lib/Entities/Vector3.d.ts +19 -0
- package/lib/Entities/Vector3.js +75 -0
- package/lib/Entities/WorkPlane.d.ts +69 -0
- package/lib/Entities/WorkPlane.js +122 -0
- package/lib/Entities/index.d.ts +3 -0
- package/lib/Entities/index.js +3 -0
- package/lib/Interface/Controllers/appHandler.d.ts +12 -0
- package/lib/Interface/Controllers/appHandler.js +94 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.d.ts +3 -0
- package/lib/Interface/Controllers/defaultAppHanlderFunctions.js +31 -0
- package/lib/Interface/Controllers/dispatchStateChange.d.ts +2 -0
- package/lib/Interface/Controllers/dispatchStateChange.js +10 -0
- package/lib/Interface/Controllers/index.d.ts +9 -0
- package/lib/Interface/Controllers/index.js +21 -0
- package/lib/Interface/Controllers/makeAppHandler.d.ts +12 -0
- package/lib/Interface/Controllers/makeAppHandler.js +96 -0
- package/lib/Interface/Controllers/setDevicePreview.d.ts +2 -0
- package/lib/Interface/Controllers/setDevicePreview.js +14 -0
- package/lib/Interface/Controllers/setIsAuthoring.d.ts +2 -0
- package/lib/Interface/Controllers/setIsAuthoring.js +14 -0
- package/lib/Interface/Controllers/setState.d.ts +2 -0
- package/lib/Interface/Controllers/setState.js +21 -0
- package/lib/Interface/Controllers/showBabylonInspector.d.ts +2 -0
- package/lib/Interface/Controllers/showBabylonInspector.js +9 -0
- package/lib/Interface/Controllers/startApp.d.ts +1 -0
- package/lib/Interface/Controllers/startApp.js +9 -0
- package/lib/Interface/Controllers/stopApp.d.ts +2 -0
- package/lib/Interface/Controllers/stopApp.js +10 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.d.ts +13 -0
- package/lib/Interface/PresentationManagers/DevicePreviewPM.js +25 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/IsAuthoringPM.js +23 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.d.ts +10 -0
- package/lib/Interface/PresentationManagers/ShowBabylonInspectorPM.js +23 -0
- package/lib/Interface/PresentationManagers/index.d.ts +3 -0
- package/lib/Interface/PresentationManagers/index.js +15 -0
- package/lib/Interface/appHandler.d.ts +12 -0
- package/lib/Interface/appHandler.js +94 -0
- package/lib/Interface/index.d.ts +2 -0
- package/lib/Interface/index.js +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.d.ts +14 -0
- package/lib/PresentationManagers/OrbitCameraPM.js +31 -0
- package/lib/PresentationManagers/TransformNodePM.d.ts +14 -0
- package/lib/PresentationManagers/TransformNodePM.js +23 -0
- package/lib/PresentationManagers/index.d.ts +1 -0
- package/lib/PresentationManagers/index.js +1 -0
- package/lib/UseCases/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.d.ts +36 -0
- package/lib/UseCases/OrbitCamera/LerpOrbitCamera.js +71 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.d.ts +9 -0
- package/lib/UseCases/OrbitCamera/PixelDolly_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.d.ts +10 -0
- package/lib/UseCases/OrbitCamera/PixelPlanePan_OrbitCamera.js +31 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.d.ts +22 -0
- package/lib/UseCases/OrbitCamera/SerializeOrbitCamera.js +81 -0
- package/lib/UseCases/OrbitCamera/index.d.ts +4 -0
- package/lib/UseCases/OrbitCamera/index.js +16 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.d.ts +18 -0
- package/lib/UseCases/SceneRoot/SerializeSceneRoot.js +48 -0
- package/lib/UseCases/SceneRoot/index.d.ts +1 -0
- package/lib/UseCases/SceneRoot/index.js +13 -0
- package/lib/UseCases/SerializeCamera.d.ts +21 -0
- package/lib/UseCases/SerializeCamera.js +59 -0
- package/lib/UseCases/SerializeOrbitCamera.d.ts +21 -0
- package/lib/UseCases/SerializeOrbitCamera.js +59 -0
- package/lib/UseCases/SerializedCamDemo.d.ts +0 -0
- package/lib/UseCases/SerializedCamDemo.js +1 -0
- package/lib/UseCases/index.d.ts +1 -0
- package/lib/UseCases/index.js +1 -0
- package/lib/ValueObjects/Angle.d.ts +18 -0
- package/lib/ValueObjects/Angle.js +26 -2
- package/lib/ValueObjects/Color.d.ts +46 -0
- package/lib/ValueObjects/Color.js +46 -0
- package/lib/ValueObjects/Matrix.d.ts +120 -0
- package/lib/ValueObjects/Matrix.js +423 -0
- package/lib/ValueObjects/Quaternion.d.ts +94 -0
- package/lib/ValueObjects/Quaternion.js +243 -0
- package/lib/ValueObjects/Vector2.d.ts +82 -0
- package/lib/ValueObjects/Vector2.js +82 -0
- package/lib/ValueObjects/Vector3.d.ts +107 -0
- package/lib/ValueObjects/Vector3.js +116 -0
- package/lib/ValueObjects/index.d.ts +2 -0
- package/lib/ValueObjects/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Angle } from "./Angle";
|
|
2
|
+
import { Quaternion } from "./Quaternion";
|
|
3
|
+
import { Vector3 } from "./Vector3";
|
|
4
|
+
export declare type MatrixArray = [
|
|
5
|
+
number,
|
|
6
|
+
number,
|
|
7
|
+
number,
|
|
8
|
+
number,
|
|
9
|
+
number,
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number,
|
|
16
|
+
number,
|
|
17
|
+
number,
|
|
18
|
+
number,
|
|
19
|
+
number,
|
|
20
|
+
number
|
|
21
|
+
];
|
|
22
|
+
export declare class Matrix {
|
|
23
|
+
/**
|
|
24
|
+
* Consructs an identity matrix
|
|
25
|
+
* @returns An identity matrix
|
|
26
|
+
*/
|
|
27
|
+
static Identity(): Matrix;
|
|
28
|
+
/**
|
|
29
|
+
* Constructs an matrix of zeros
|
|
30
|
+
* @returns A matrix of zeros
|
|
31
|
+
*/
|
|
32
|
+
static Zero(): Matrix;
|
|
33
|
+
/**
|
|
34
|
+
* Compares two matricies
|
|
35
|
+
* @param a Matrix A
|
|
36
|
+
* @param b Matrix B
|
|
37
|
+
* @returns True if all the elements in matrix A are equal to all the elements of matrix B
|
|
38
|
+
*/
|
|
39
|
+
static Equal(a: Matrix, b: Matrix): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Checks to see if Matrix A is close to Matrix B by comparing elements
|
|
42
|
+
* @param a Matrix A
|
|
43
|
+
* @param b Matrix B
|
|
44
|
+
* @param threshold "Close" thershold. Defaults to 0.001
|
|
45
|
+
* @returns True if all the difference between the elements in each array is less than the threshold
|
|
46
|
+
*/
|
|
47
|
+
static Close(a: Matrix, b: Matrix, threshold?: number): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Multiplies Matrix A and B (AxB)
|
|
50
|
+
* @param a Matrix A
|
|
51
|
+
* @param b Matrix B
|
|
52
|
+
* @returns The result of AxB
|
|
53
|
+
*/
|
|
54
|
+
static Multiply(a: Matrix, b: Matrix): Matrix;
|
|
55
|
+
/**
|
|
56
|
+
* Composes a matrix from a scale vector, rotation quaterion, and translation vector
|
|
57
|
+
* @param scale The scale of the transformation matrix
|
|
58
|
+
* @param rotation The rotation of the transformation matrix
|
|
59
|
+
* @param translation The translation of the transformation matrix
|
|
60
|
+
* @returns The composed matrix
|
|
61
|
+
*/
|
|
62
|
+
static Compose(scale: Vector3, rotation: Quaternion, translation: Vector3): Matrix;
|
|
63
|
+
/**
|
|
64
|
+
* Inverts a matrix into a new matrix.
|
|
65
|
+
* @param matrix The matrix to invert
|
|
66
|
+
* @returns The inverted matrix unless the matrix cannot be inverted, then the identity is returned
|
|
67
|
+
*/
|
|
68
|
+
static Invert(matrix: Matrix): Matrix;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a rotation matrix for a given axes and angle
|
|
71
|
+
* @param axis The axes of rotation
|
|
72
|
+
* @param angle The angle of rotation
|
|
73
|
+
* @returns A new rotation matrix
|
|
74
|
+
*/
|
|
75
|
+
static FromRotationAxisAngle(axis: Vector3, angle: Angle): Matrix;
|
|
76
|
+
/**
|
|
77
|
+
* Make a new transformation matrix that has the same scale and rotation as the original but the translation is set
|
|
78
|
+
* @param original The original matrix
|
|
79
|
+
* @param translation The new translation value
|
|
80
|
+
* @returns A new matrix that is the same as the original but the translation has been changed
|
|
81
|
+
*/
|
|
82
|
+
static SetMatrixTranslation(original: Matrix, translation: Vector3): Matrix;
|
|
83
|
+
/**
|
|
84
|
+
* Make a new transformation matrix that has the same scale and translation as the original but the rotation is set
|
|
85
|
+
* @param original The original matrix
|
|
86
|
+
* @param rotation The new rotation value
|
|
87
|
+
* @returns A new matrix that is the same as the original but the rotation has been changed
|
|
88
|
+
*/
|
|
89
|
+
static SetMatrixRotation(original: Matrix, rotation: Quaternion): Matrix;
|
|
90
|
+
/**
|
|
91
|
+
* Make a new transformation matrix that has the same rotation and translation as the original but the scale is set
|
|
92
|
+
* @param original The original matrix
|
|
93
|
+
* @param scale The new scale value
|
|
94
|
+
* @returns A new matrix that is the same as the original but the scale has been changed
|
|
95
|
+
*/
|
|
96
|
+
static SetMatrixScale(original: Matrix, scale: Vector3): Matrix;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the determinate of the matrix
|
|
99
|
+
*/
|
|
100
|
+
get determinate(): number;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the translation component of the transformation matrix as a Vector
|
|
103
|
+
*/
|
|
104
|
+
get translation(): Vector3;
|
|
105
|
+
/**
|
|
106
|
+
* Returns the scale of the transformation matrix as a vector
|
|
107
|
+
*/
|
|
108
|
+
get scale(): Vector3;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the rotation components of the transformation matrix as a Quaternion
|
|
111
|
+
*/
|
|
112
|
+
get rotation(): Quaternion;
|
|
113
|
+
/**
|
|
114
|
+
* Returns just the rotation matrix of the transformation matrix
|
|
115
|
+
*/
|
|
116
|
+
get rotationMatrix(): Matrix;
|
|
117
|
+
private readonly _m;
|
|
118
|
+
get m(): MatrixArray;
|
|
119
|
+
constructor(m: MatrixArray);
|
|
120
|
+
}
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Matrix = void 0;
|
|
4
|
+
const Quaternion_1 = require("./Quaternion");
|
|
5
|
+
const Vector3_1 = require("./Vector3");
|
|
6
|
+
class Matrix {
|
|
7
|
+
constructor(m) {
|
|
8
|
+
this._m = m;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Consructs an identity matrix
|
|
12
|
+
* @returns An identity matrix
|
|
13
|
+
*/
|
|
14
|
+
static Identity() {
|
|
15
|
+
return new Matrix([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Constructs an matrix of zeros
|
|
19
|
+
* @returns A matrix of zeros
|
|
20
|
+
*/
|
|
21
|
+
static Zero() {
|
|
22
|
+
return new Matrix([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Compares two matricies
|
|
26
|
+
* @param a Matrix A
|
|
27
|
+
* @param b Matrix B
|
|
28
|
+
* @returns True if all the elements in matrix A are equal to all the elements of matrix B
|
|
29
|
+
*/
|
|
30
|
+
static Equal(a, b) {
|
|
31
|
+
let areEqual = true;
|
|
32
|
+
for (let i = 0; i < 16; i++) {
|
|
33
|
+
if (a._m[i] !== b._m[i]) {
|
|
34
|
+
areEqual = false;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return areEqual;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks to see if Matrix A is close to Matrix B by comparing elements
|
|
42
|
+
* @param a Matrix A
|
|
43
|
+
* @param b Matrix B
|
|
44
|
+
* @param threshold "Close" thershold. Defaults to 0.001
|
|
45
|
+
* @returns True if all the difference between the elements in each array is less than the threshold
|
|
46
|
+
*/
|
|
47
|
+
static Close(a, b, threshold = 0.001) {
|
|
48
|
+
let areClose = true;
|
|
49
|
+
for (let i = 0; i < 16; i++) {
|
|
50
|
+
let diff = a._m[i] - b._m[i];
|
|
51
|
+
if (diff < 0) {
|
|
52
|
+
diff = -diff;
|
|
53
|
+
}
|
|
54
|
+
if (diff > threshold) {
|
|
55
|
+
areClose = false;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return areClose;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Multiplies Matrix A and B (AxB)
|
|
63
|
+
* @param a Matrix A
|
|
64
|
+
* @param b Matrix B
|
|
65
|
+
* @returns The result of AxB
|
|
66
|
+
*/
|
|
67
|
+
static Multiply(a, b) {
|
|
68
|
+
const aMatrix = a._m;
|
|
69
|
+
const bMatrix = b._m;
|
|
70
|
+
const tm0 = bMatrix[0];
|
|
71
|
+
const tm1 = bMatrix[1];
|
|
72
|
+
const tm2 = bMatrix[2];
|
|
73
|
+
const tm3 = bMatrix[3];
|
|
74
|
+
const tm4 = bMatrix[4];
|
|
75
|
+
const tm5 = bMatrix[5];
|
|
76
|
+
const tm6 = bMatrix[6];
|
|
77
|
+
const tm7 = bMatrix[7];
|
|
78
|
+
const tm8 = bMatrix[8];
|
|
79
|
+
const tm9 = bMatrix[9];
|
|
80
|
+
const tm10 = bMatrix[10];
|
|
81
|
+
const tm11 = bMatrix[11];
|
|
82
|
+
const tm12 = bMatrix[12];
|
|
83
|
+
const tm13 = bMatrix[13];
|
|
84
|
+
const tm14 = bMatrix[14];
|
|
85
|
+
const tm15 = bMatrix[15];
|
|
86
|
+
const om0 = aMatrix[0];
|
|
87
|
+
const om1 = aMatrix[1];
|
|
88
|
+
const om2 = aMatrix[2];
|
|
89
|
+
const om3 = aMatrix[3];
|
|
90
|
+
const om4 = aMatrix[4];
|
|
91
|
+
const om5 = aMatrix[5];
|
|
92
|
+
const om6 = aMatrix[6];
|
|
93
|
+
const om7 = aMatrix[7];
|
|
94
|
+
const om8 = aMatrix[8];
|
|
95
|
+
const om9 = aMatrix[9];
|
|
96
|
+
const om10 = aMatrix[10];
|
|
97
|
+
const om11 = aMatrix[11];
|
|
98
|
+
const om12 = aMatrix[12];
|
|
99
|
+
const om13 = aMatrix[13];
|
|
100
|
+
const om14 = aMatrix[14];
|
|
101
|
+
const om15 = aMatrix[15];
|
|
102
|
+
const result1 = tm0 * om0 + tm1 * om4 + tm2 * om8 + tm3 * om12;
|
|
103
|
+
const result2 = tm0 * om1 + tm1 * om5 + tm2 * om9 + tm3 * om13;
|
|
104
|
+
const result3 = tm0 * om2 + tm1 * om6 + tm2 * om10 + tm3 * om14;
|
|
105
|
+
const result4 = tm0 * om3 + tm1 * om7 + tm2 * om11 + tm3 * om15;
|
|
106
|
+
const result5 = tm4 * om0 + tm5 * om4 + tm6 * om8 + tm7 * om12;
|
|
107
|
+
const result6 = tm4 * om1 + tm5 * om5 + tm6 * om9 + tm7 * om13;
|
|
108
|
+
const result7 = tm4 * om2 + tm5 * om6 + tm6 * om10 + tm7 * om14;
|
|
109
|
+
const result8 = tm4 * om3 + tm5 * om7 + tm6 * om11 + tm7 * om15;
|
|
110
|
+
const result9 = tm8 * om0 + tm9 * om4 + tm10 * om8 + tm11 * om12;
|
|
111
|
+
const result10 = tm8 * om1 + tm9 * om5 + tm10 * om9 + tm11 * om13;
|
|
112
|
+
const result11 = tm8 * om2 + tm9 * om6 + tm10 * om10 + tm11 * om14;
|
|
113
|
+
const result12 = tm8 * om3 + tm9 * om7 + tm10 * om11 + tm11 * om15;
|
|
114
|
+
const result13 = tm12 * om0 + tm13 * om4 + tm14 * om8 + tm15 * om12;
|
|
115
|
+
const result14 = tm12 * om1 + tm13 * om5 + tm14 * om9 + tm15 * om13;
|
|
116
|
+
const result15 = tm12 * om2 + tm13 * om6 + tm14 * om10 + tm15 * om14;
|
|
117
|
+
const result16 = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15;
|
|
118
|
+
return new Matrix([
|
|
119
|
+
result1,
|
|
120
|
+
result2,
|
|
121
|
+
result3,
|
|
122
|
+
result4,
|
|
123
|
+
result5,
|
|
124
|
+
result6,
|
|
125
|
+
result7,
|
|
126
|
+
result8,
|
|
127
|
+
result9,
|
|
128
|
+
result10,
|
|
129
|
+
result11,
|
|
130
|
+
result12,
|
|
131
|
+
result13,
|
|
132
|
+
result14,
|
|
133
|
+
result15,
|
|
134
|
+
result16,
|
|
135
|
+
]);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Composes a matrix from a scale vector, rotation quaterion, and translation vector
|
|
139
|
+
* @param scale The scale of the transformation matrix
|
|
140
|
+
* @param rotation The rotation of the transformation matrix
|
|
141
|
+
* @param translation The translation of the transformation matrix
|
|
142
|
+
* @returns The composed matrix
|
|
143
|
+
*/
|
|
144
|
+
static Compose(scale, rotation, translation) {
|
|
145
|
+
const final = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
146
|
+
const rotX = rotation.x;
|
|
147
|
+
const rotY = rotation.y;
|
|
148
|
+
const rotZ = rotation.z;
|
|
149
|
+
const rotW = rotation.w;
|
|
150
|
+
const x2 = rotX + rotX;
|
|
151
|
+
const y2 = rotY + rotY;
|
|
152
|
+
const z2 = rotZ + rotZ;
|
|
153
|
+
const xx = rotX * x2;
|
|
154
|
+
const xy = rotX * y2;
|
|
155
|
+
const xz = rotX * z2;
|
|
156
|
+
const yy = rotY * y2;
|
|
157
|
+
const yz = rotY * z2;
|
|
158
|
+
const zz = rotZ * z2;
|
|
159
|
+
const wx = rotW * x2;
|
|
160
|
+
const wy = rotW * y2;
|
|
161
|
+
const wz = rotW * z2;
|
|
162
|
+
const scaleX = scale.x;
|
|
163
|
+
const scaleY = scale.y;
|
|
164
|
+
const scaleZ = scale.z;
|
|
165
|
+
final[0] = (1 - (yy + zz)) * scaleX;
|
|
166
|
+
final[1] = (xy + wz) * scaleX;
|
|
167
|
+
final[2] = (xz - wy) * scaleX;
|
|
168
|
+
final[3] = 0;
|
|
169
|
+
final[4] = (xy - wz) * scaleY;
|
|
170
|
+
final[5] = (1 - (xx + zz)) * scaleY;
|
|
171
|
+
final[6] = (yz + wx) * scaleY;
|
|
172
|
+
final[7] = 0;
|
|
173
|
+
final[8] = (xz + wy) * scaleZ;
|
|
174
|
+
final[9] = (yz - wx) * scaleZ;
|
|
175
|
+
final[10] = (1 - (xx + yy)) * scaleZ;
|
|
176
|
+
final[11] = 0;
|
|
177
|
+
final[12] = translation.x;
|
|
178
|
+
final[13] = translation.y;
|
|
179
|
+
final[14] = translation.z;
|
|
180
|
+
final[15] = 1;
|
|
181
|
+
return new Matrix(final);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Inverts a matrix into a new matrix.
|
|
185
|
+
* @param matrix The matrix to invert
|
|
186
|
+
* @returns The inverted matrix unless the matrix cannot be inverted, then the identity is returned
|
|
187
|
+
*/
|
|
188
|
+
static Invert(matrix) {
|
|
189
|
+
const m = matrix._m;
|
|
190
|
+
const m00 = m[0];
|
|
191
|
+
const m01 = m[1];
|
|
192
|
+
const m02 = m[2];
|
|
193
|
+
const m03 = m[3];
|
|
194
|
+
const m10 = m[4];
|
|
195
|
+
const m11 = m[5];
|
|
196
|
+
const m12 = m[6];
|
|
197
|
+
const m13 = m[7];
|
|
198
|
+
const m20 = m[8];
|
|
199
|
+
const m21 = m[9];
|
|
200
|
+
const m22 = m[10];
|
|
201
|
+
const m23 = m[11];
|
|
202
|
+
const m30 = m[12];
|
|
203
|
+
const m31 = m[13];
|
|
204
|
+
const m32 = m[14];
|
|
205
|
+
const m33 = m[15];
|
|
206
|
+
const det_12_33 = m12 * m33 - m32 * m13;
|
|
207
|
+
const det_11_33 = m11 * m33 - m31 * m13;
|
|
208
|
+
const det_11_32 = m11 * m32 - m31 * m12;
|
|
209
|
+
const det_10_33 = m10 * m33 - m30 * m13;
|
|
210
|
+
const det_10_32 = m10 * m32 - m30 * m12;
|
|
211
|
+
const det_10_31 = m10 * m31 - m30 * m11;
|
|
212
|
+
const det_12_23 = m12 * m23 - m22 * m13;
|
|
213
|
+
const det_11_23 = m11 * m23 - m21 * m13;
|
|
214
|
+
const det_11_22 = m11 * m22 - m21 * m12;
|
|
215
|
+
const det_10_23 = m10 * m23 - m20 * m13;
|
|
216
|
+
const det_10_22 = m10 * m22 - m20 * m12;
|
|
217
|
+
const det_10_21 = m10 * m21 - m20 * m11;
|
|
218
|
+
const det_22_33 = m22 * m33 - m32 * m23;
|
|
219
|
+
const det_21_33 = m21 * m33 - m31 * m23;
|
|
220
|
+
const det_21_32 = m21 * m32 - m31 * m22;
|
|
221
|
+
const det_20_33 = m20 * m33 - m30 * m23;
|
|
222
|
+
const det_20_32 = m20 * m32 - m22 * m30;
|
|
223
|
+
const det_20_31 = m20 * m31 - m30 * m21;
|
|
224
|
+
const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);
|
|
225
|
+
const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);
|
|
226
|
+
const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);
|
|
227
|
+
const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);
|
|
228
|
+
const det = m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03;
|
|
229
|
+
if (det === 0)
|
|
230
|
+
return Matrix.Identity();
|
|
231
|
+
const detInv = 1 / det;
|
|
232
|
+
const cofact_10 = -(m01 * det_22_33 - m02 * det_21_33 + m03 * det_21_32);
|
|
233
|
+
const cofact_11 = +(m00 * det_22_33 - m02 * det_20_33 + m03 * det_20_32);
|
|
234
|
+
const cofact_12 = -(m00 * det_21_33 - m01 * det_20_33 + m03 * det_20_31);
|
|
235
|
+
const cofact_13 = +(m00 * det_21_32 - m01 * det_20_32 + m02 * det_20_31);
|
|
236
|
+
const cofact_20 = +(m01 * det_12_33 - m02 * det_11_33 + m03 * det_11_32);
|
|
237
|
+
const cofact_21 = -(m00 * det_12_33 - m02 * det_10_33 + m03 * det_10_32);
|
|
238
|
+
const cofact_22 = +(m00 * det_11_33 - m01 * det_10_33 + m03 * det_10_31);
|
|
239
|
+
const cofact_23 = -(m00 * det_11_32 - m01 * det_10_32 + m02 * det_10_31);
|
|
240
|
+
const cofact_30 = -(m01 * det_12_23 - m02 * det_11_23 + m03 * det_11_22);
|
|
241
|
+
const cofact_31 = +(m00 * det_12_23 - m02 * det_10_23 + m03 * det_10_22);
|
|
242
|
+
const cofact_32 = -(m00 * det_11_23 - m01 * det_10_23 + m03 * det_10_21);
|
|
243
|
+
const cofact_33 = +(m00 * det_11_22 - m01 * det_10_22 + m02 * det_10_21);
|
|
244
|
+
return new Matrix([
|
|
245
|
+
cofact_00 * detInv,
|
|
246
|
+
cofact_10 * detInv,
|
|
247
|
+
cofact_20 * detInv,
|
|
248
|
+
cofact_30 * detInv,
|
|
249
|
+
cofact_01 * detInv,
|
|
250
|
+
cofact_11 * detInv,
|
|
251
|
+
cofact_21 * detInv,
|
|
252
|
+
cofact_31 * detInv,
|
|
253
|
+
cofact_02 * detInv,
|
|
254
|
+
cofact_12 * detInv,
|
|
255
|
+
cofact_22 * detInv,
|
|
256
|
+
cofact_32 * detInv,
|
|
257
|
+
cofact_03 * detInv,
|
|
258
|
+
cofact_13 * detInv,
|
|
259
|
+
cofact_23 * detInv,
|
|
260
|
+
cofact_33 * detInv,
|
|
261
|
+
]);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Creates a rotation matrix for a given axes and angle
|
|
265
|
+
* @param axis The axes of rotation
|
|
266
|
+
* @param angle The angle of rotation
|
|
267
|
+
* @returns A new rotation matrix
|
|
268
|
+
*/
|
|
269
|
+
static FromRotationAxisAngle(axis, angle) {
|
|
270
|
+
const sin = Math.sin(-angle.radians);
|
|
271
|
+
const cosin = Math.cos(-angle.radians);
|
|
272
|
+
const c1 = 1 - cosin;
|
|
273
|
+
const unit = axis.unit;
|
|
274
|
+
const m = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
275
|
+
m[0] = unit.x * unit.x * c1 + cosin;
|
|
276
|
+
m[1] = unit.x * unit.y * c1 - unit.z * sin;
|
|
277
|
+
m[2] = unit.x * unit.z * c1 + unit.y * sin;
|
|
278
|
+
m[3] = 0.0;
|
|
279
|
+
m[4] = unit.y * unit.x * c1 + unit.z * sin;
|
|
280
|
+
m[5] = unit.y * unit.y * c1 + cosin;
|
|
281
|
+
m[6] = unit.y * unit.z * c1 - unit.x * sin;
|
|
282
|
+
m[7] = 0.0;
|
|
283
|
+
m[8] = unit.z * unit.x * c1 - unit.y * sin;
|
|
284
|
+
m[9] = unit.z * unit.y * c1 + unit.x * sin;
|
|
285
|
+
m[10] = unit.z * unit.z * c1 + cosin;
|
|
286
|
+
m[11] = 0.0;
|
|
287
|
+
m[12] = 0.0;
|
|
288
|
+
m[13] = 0.0;
|
|
289
|
+
m[14] = 0.0;
|
|
290
|
+
m[15] = 1.0;
|
|
291
|
+
return new Matrix(m);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Make a new transformation matrix that has the same scale and rotation as the original but the translation is set
|
|
295
|
+
* @param original The original matrix
|
|
296
|
+
* @param translation The new translation value
|
|
297
|
+
* @returns A new matrix that is the same as the original but the translation has been changed
|
|
298
|
+
*/
|
|
299
|
+
static SetMatrixTranslation(original, translation) {
|
|
300
|
+
const values = original.m;
|
|
301
|
+
values[12] = translation.x;
|
|
302
|
+
values[13] = translation.y;
|
|
303
|
+
values[14] = translation.z;
|
|
304
|
+
return new Matrix(values);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Make a new transformation matrix that has the same scale and translation as the original but the rotation is set
|
|
308
|
+
* @param original The original matrix
|
|
309
|
+
* @param rotation The new rotation value
|
|
310
|
+
* @returns A new matrix that is the same as the original but the rotation has been changed
|
|
311
|
+
*/
|
|
312
|
+
static SetMatrixRotation(original, rotation) {
|
|
313
|
+
const scale = original.scale;
|
|
314
|
+
const translation = original.translation;
|
|
315
|
+
return Matrix.Compose(scale, rotation, translation);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Make a new transformation matrix that has the same rotation and translation as the original but the scale is set
|
|
319
|
+
* @param original The original matrix
|
|
320
|
+
* @param scale The new scale value
|
|
321
|
+
* @returns A new matrix that is the same as the original but the scale has been changed
|
|
322
|
+
*/
|
|
323
|
+
static SetMatrixScale(original, scale) {
|
|
324
|
+
const rotation = original.rotation;
|
|
325
|
+
const translation = original.translation;
|
|
326
|
+
return Matrix.Compose(scale, rotation, translation);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Returns the determinate of the matrix
|
|
330
|
+
*/
|
|
331
|
+
get determinate() {
|
|
332
|
+
const m = this._m;
|
|
333
|
+
const m00 = m[0];
|
|
334
|
+
const m01 = m[1];
|
|
335
|
+
const m02 = m[2];
|
|
336
|
+
const m03 = m[3];
|
|
337
|
+
const m10 = m[4];
|
|
338
|
+
const m11 = m[5];
|
|
339
|
+
const m12 = m[6];
|
|
340
|
+
const m13 = m[7];
|
|
341
|
+
const m20 = m[8];
|
|
342
|
+
const m21 = m[9];
|
|
343
|
+
const m22 = m[10];
|
|
344
|
+
const m23 = m[11];
|
|
345
|
+
const m30 = m[12];
|
|
346
|
+
const m31 = m[13];
|
|
347
|
+
const m32 = m[14];
|
|
348
|
+
const m33 = m[15];
|
|
349
|
+
const det_22_33 = m22 * m33 - m32 * m23;
|
|
350
|
+
const det_21_33 = m21 * m33 - m31 * m23;
|
|
351
|
+
const det_21_32 = m21 * m32 - m31 * m22;
|
|
352
|
+
const det_20_33 = m20 * m33 - m30 * m23;
|
|
353
|
+
const det_20_32 = m20 * m32 - m22 * m30;
|
|
354
|
+
const det_20_31 = m20 * m31 - m30 * m21;
|
|
355
|
+
const cofact_00 = +(m11 * det_22_33 - m12 * det_21_33 + m13 * det_21_32);
|
|
356
|
+
const cofact_01 = -(m10 * det_22_33 - m12 * det_20_33 + m13 * det_20_32);
|
|
357
|
+
const cofact_02 = +(m10 * det_21_33 - m11 * det_20_33 + m13 * det_20_31);
|
|
358
|
+
const cofact_03 = -(m10 * det_21_32 - m11 * det_20_32 + m12 * det_20_31);
|
|
359
|
+
return (m00 * cofact_00 + m01 * cofact_01 + m02 * cofact_02 + m03 * cofact_03);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Returns the translation component of the transformation matrix as a Vector
|
|
363
|
+
*/
|
|
364
|
+
get translation() {
|
|
365
|
+
return new Vector3_1.Vector3(this._m[12], this._m[13], this._m[14]);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns the scale of the transformation matrix as a vector
|
|
369
|
+
*/
|
|
370
|
+
get scale() {
|
|
371
|
+
const x = Math.sqrt(this._m[0] * this._m[0] +
|
|
372
|
+
this._m[1] * this._m[1] +
|
|
373
|
+
this._m[2] * this._m[2]);
|
|
374
|
+
let y = Math.sqrt(this._m[4] * this._m[4] +
|
|
375
|
+
this._m[5] * this._m[5] +
|
|
376
|
+
this._m[6] * this._m[6]);
|
|
377
|
+
const z = Math.sqrt(this._m[8] * this._m[8] +
|
|
378
|
+
this._m[9] * this._m[9] +
|
|
379
|
+
this._m[10] * this._m[10]);
|
|
380
|
+
if (this.determinate <= 0) {
|
|
381
|
+
y = -y;
|
|
382
|
+
}
|
|
383
|
+
return new Vector3_1.Vector3(x, y, z);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Returns the rotation components of the transformation matrix as a Quaternion
|
|
387
|
+
*/
|
|
388
|
+
get rotation() {
|
|
389
|
+
return Quaternion_1.Quaternion.FromRotationMatrix(this.rotationMatrix);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Returns just the rotation matrix of the transformation matrix
|
|
393
|
+
*/
|
|
394
|
+
get rotationMatrix() {
|
|
395
|
+
const scale = this.scale;
|
|
396
|
+
const sx = 1 / scale.x;
|
|
397
|
+
const sy = 1 / scale.y;
|
|
398
|
+
const sz = 1 / scale.z;
|
|
399
|
+
const rMatrixValues = [
|
|
400
|
+
this._m[0] * sx,
|
|
401
|
+
this._m[1] * sx,
|
|
402
|
+
this._m[2] * sx,
|
|
403
|
+
0.0,
|
|
404
|
+
this._m[4] * sy,
|
|
405
|
+
this._m[5] * sy,
|
|
406
|
+
this._m[6] * sy,
|
|
407
|
+
0.0,
|
|
408
|
+
this._m[8] * sz,
|
|
409
|
+
this._m[9] * sz,
|
|
410
|
+
this._m[10] * sz,
|
|
411
|
+
0.0,
|
|
412
|
+
0.0,
|
|
413
|
+
0.0,
|
|
414
|
+
0.0,
|
|
415
|
+
1.0,
|
|
416
|
+
];
|
|
417
|
+
return new Matrix(rMatrixValues);
|
|
418
|
+
}
|
|
419
|
+
get m() {
|
|
420
|
+
return [...this._m];
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
exports.Matrix = Matrix;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Angle } from "./Angle";
|
|
2
|
+
import { Matrix } from "./Matrix";
|
|
3
|
+
import { Vector3 } from "./Vector3";
|
|
4
|
+
export declare class Quaternion {
|
|
5
|
+
/**
|
|
6
|
+
* Checks to see if two Quaternions are equal
|
|
7
|
+
* @param a Quaternion A
|
|
8
|
+
* @param b Quaternion B
|
|
9
|
+
* @returns True if they are equal, otherwise false
|
|
10
|
+
*/
|
|
11
|
+
static Equal(a: Quaternion, b: Quaternion): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Checks two quaternions to see if they are close
|
|
14
|
+
* @param a Quaterion A
|
|
15
|
+
* @param b Quaterion B
|
|
16
|
+
* @param threshold "Close" threshold. Defaults to 0.001
|
|
17
|
+
* @returns True if each of Quaterion's components are within the threshold of each other
|
|
18
|
+
*/
|
|
19
|
+
static Close(a: Quaternion, b: Quaternion, threshold?: number): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Multiplies A*B
|
|
22
|
+
* @param a Quaterion A
|
|
23
|
+
* @param b Quaternion B
|
|
24
|
+
* @returns The result of A*B
|
|
25
|
+
*/
|
|
26
|
+
static Multiply(a: Quaternion, b: Quaternion): Quaternion;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new Quaterion from an array of values
|
|
29
|
+
* @param values The four values of the Quaterion: [x,y,z,w]
|
|
30
|
+
* @returns A Quaterion
|
|
31
|
+
*/
|
|
32
|
+
static FromArray(values: [number, number, number, number]): Quaternion;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an Identity Quaternion
|
|
35
|
+
* @returns An Identity Quaternion
|
|
36
|
+
*/
|
|
37
|
+
static Identity(): Quaternion;
|
|
38
|
+
/**
|
|
39
|
+
* Creates an quaterion about an axis for a given angle
|
|
40
|
+
* @param axis The rotation axis
|
|
41
|
+
* @param angle The rotation angle
|
|
42
|
+
* @returns The resulting Quaterion
|
|
43
|
+
*/
|
|
44
|
+
static FromAngleAxis(axis: Vector3, angle: Angle): Quaternion;
|
|
45
|
+
/**
|
|
46
|
+
* Froms up a Quaternion from the Yaw-Pitch-Roll (Tait-Bryan) convetion
|
|
47
|
+
* @param yaw defines the rotation around the y axis
|
|
48
|
+
* @param pitch defines the rotation around the x axis
|
|
49
|
+
* @param roll defines the rotation around the z axis
|
|
50
|
+
* @returns the resulting quaterion
|
|
51
|
+
*/
|
|
52
|
+
static FromYawPitchRoll(yaw: Angle, pitch: Angle, roll: Angle): Quaternion;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Quaternion from three euler angles.
|
|
55
|
+
* @param x Rotation about the x axis
|
|
56
|
+
* @param y Rotation about the y axis
|
|
57
|
+
* @param z Rotation about the z axis
|
|
58
|
+
* @returns The Quaterion
|
|
59
|
+
*/
|
|
60
|
+
static FromEuler(x: Angle, y: Angle, z: Angle): Quaternion;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a new Quaternion that is an invert of A
|
|
63
|
+
* @param a The quaternion to invert
|
|
64
|
+
* @returns The inverted Quaternion
|
|
65
|
+
*/
|
|
66
|
+
static Inverse(a: Quaternion): Quaternion;
|
|
67
|
+
/**
|
|
68
|
+
* Spherically interpolates between two quaternions
|
|
69
|
+
* @param initial The initial quaternion
|
|
70
|
+
* @param final The final quaterion
|
|
71
|
+
* @param percent The percent along the slerp. 0 will return the initial quaterion and 1 will return the final quaterion
|
|
72
|
+
* @returns The interpolated quaterion
|
|
73
|
+
*/
|
|
74
|
+
static Slerp(initial: Quaternion, final: Quaternion, percent: number): Quaternion;
|
|
75
|
+
/**
|
|
76
|
+
* Calculates a Quaternion from a rotation matrix
|
|
77
|
+
* @param rotationMatrix A normalized, non-scaled rotation matrix
|
|
78
|
+
* @returns The Quaterion
|
|
79
|
+
*/
|
|
80
|
+
static FromRotationMatrix(rotationMatrix: Matrix): Quaternion;
|
|
81
|
+
static ToRotationMatrix(quat: Quaternion): Matrix;
|
|
82
|
+
/**
|
|
83
|
+
* Copy the quaternion to an array
|
|
84
|
+
* @returns an array populated with 4 elements from the quaternion coordinates
|
|
85
|
+
*/
|
|
86
|
+
toArray(): [number, number, number, number];
|
|
87
|
+
get angle(): Angle;
|
|
88
|
+
get axis(): Vector3;
|
|
89
|
+
readonly x: number;
|
|
90
|
+
readonly y: number;
|
|
91
|
+
readonly z: number;
|
|
92
|
+
readonly w: number;
|
|
93
|
+
constructor(x: number, y: number, z: number, w: number);
|
|
94
|
+
}
|