@perplexdotgg/bounce 1.0.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.
Files changed (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/package.json +32 -0
  4. package/src/builders/ConvexHullBuilder.ts +437 -0
  5. package/src/builders/ConvexHullBuilder2d.ts +344 -0
  6. package/src/builders/ConvexHullBuilder3d.ts +1689 -0
  7. package/src/builders/HeightMapBuilder.ts +414 -0
  8. package/src/builders/TriangleMeshBuilder.ts +92 -0
  9. package/src/collision/CastShapesModule.ts +184 -0
  10. package/src/collision/CollideShapesModule.ts +152 -0
  11. package/src/collision/HeightMapCaster.ts +38 -0
  12. package/src/collision/HeightMapCollider.ts +33 -0
  13. package/src/collision/TriangleCaster.ts +249 -0
  14. package/src/collision/TriangleCollider.ts +308 -0
  15. package/src/collision/TriangleCollider2.ts +379 -0
  16. package/src/collision/activeEdge.ts +146 -0
  17. package/src/collision/cast/cast.ts +139 -0
  18. package/src/collision/cast/castCompoundVsCompound.ts +59 -0
  19. package/src/collision/cast/castCompoundVsConvex.ts +116 -0
  20. package/src/collision/cast/castConvexVsCompound.ts +123 -0
  21. package/src/collision/cast/castConvexVsConvex.ts +213 -0
  22. package/src/collision/cast/castConvexVsHeightMap.ts +73 -0
  23. package/src/collision/cast/castConvexVsTriangleMesh.ts +56 -0
  24. package/src/collision/cast/castRayVsCompound.ts +44 -0
  25. package/src/collision/cast/castRayVsConvex.ts +45 -0
  26. package/src/collision/cast/castRayVsHeightMap.ts +58 -0
  27. package/src/collision/cast/castRayVsTriangleMesh.ts +58 -0
  28. package/src/collision/closestPoints/closestPoints.ts +23 -0
  29. package/src/collision/closestPoints/computeBarycentricCoordinates2d.ts +32 -0
  30. package/src/collision/closestPoints/computeBarycentricCoordinates3d.ts +81 -0
  31. package/src/collision/closestPoints/computeClosestPointOnLine.ts +30 -0
  32. package/src/collision/closestPoints/computeClosestPointOnTetrahedron.ts +96 -0
  33. package/src/collision/closestPoints/computeClosestPointOnTriangle.ts +195 -0
  34. package/src/collision/closestPoints/isOriginOutsideOfPlane.ts +25 -0
  35. package/src/collision/closestPoints/isOriginOutsideOfTrianglePlanes.ts +72 -0
  36. package/src/collision/collide/collide.ts +146 -0
  37. package/src/collision/collide/collideCompoundVsCompound.ts +60 -0
  38. package/src/collision/collide/collideCompoundVsConvex.ts +59 -0
  39. package/src/collision/collide/collideCompoundVsHeightMap.ts +73 -0
  40. package/src/collision/collide/collideCompoundVsTriangleMesh.ts +56 -0
  41. package/src/collision/collide/collideConvexVsCompound.ts +57 -0
  42. package/src/collision/collide/collideConvexVsConvex.ts +225 -0
  43. package/src/collision/collide/collideConvexVsConvexImp.ts +236 -0
  44. package/src/collision/collide/collideConvexVsHeightMap.ts +53 -0
  45. package/src/collision/collide/collideConvexVsTriangleMesh.ts +58 -0
  46. package/src/collision/collide/collideHeightMapVsCompound.ts +69 -0
  47. package/src/collision/collide/collideHeightMapVsConvex.ts +53 -0
  48. package/src/collision/collide/collideSphereVsSphere.ts +81 -0
  49. package/src/collision/collide/collideTriangleMeshVsCompound.ts +58 -0
  50. package/src/collision/collide/collideTriangleMeshVsConvex.ts +58 -0
  51. package/src/collision/epa/EpaConvexHullBuilder.ts +397 -0
  52. package/src/collision/epa/StaticArray.ts +154 -0
  53. package/src/collision/epa/TriangleFactory.ts +32 -0
  54. package/src/collision/epa/arrays.ts +99 -0
  55. package/src/collision/epa/binaryHeap.ts +82 -0
  56. package/src/collision/epa/structs.ts +227 -0
  57. package/src/collision/gjk/GjkModule.ts +864 -0
  58. package/src/collision/gjk/PenetrationDepthModule.ts +493 -0
  59. package/src/collision/gjk/SupportPoints.ts +50 -0
  60. package/src/collision/imp/MinkowskiDifference.ts +36 -0
  61. package/src/collision/imp/computeExploredDistanceLowerUpperBound.ts +40 -0
  62. package/src/collision/imp/finalizeImpResult.ts +69 -0
  63. package/src/collision/imp/findContactImp.ts +196 -0
  64. package/src/collision/imp/imp.ts +28 -0
  65. package/src/collision/imp/incrementalMinimumDistanceExploreDirection.ts +207 -0
  66. package/src/collision/mpr/findPortal.ts +152 -0
  67. package/src/collision/mpr/mpr.ts +29 -0
  68. package/src/collision/mpr/updatePortal.ts +52 -0
  69. package/src/constraints/BaseConstraint.ts +50 -0
  70. package/src/constraints/ConstraintOptions.ts +22 -0
  71. package/src/constraints/ConstraintSolver.ts +119 -0
  72. package/src/constraints/DistanceConstraint.ts +229 -0
  73. package/src/constraints/FixedConstraint.ts +203 -0
  74. package/src/constraints/HingeConstraint.ts +460 -0
  75. package/src/constraints/PointConstraint.ts +108 -0
  76. package/src/constraints/components/AngleComponent.ts +226 -0
  77. package/src/constraints/components/AxisComponent.ts +263 -0
  78. package/src/constraints/components/HingeComponent.ts +215 -0
  79. package/src/constraints/components/Motor.ts +36 -0
  80. package/src/constraints/components/PointConstraintComponent.ts +179 -0
  81. package/src/constraints/components/RotationEulerComponent.ts +139 -0
  82. package/src/constraints/components/Spring.ts +30 -0
  83. package/src/constraints/components/SpringComponent.ts +71 -0
  84. package/src/constraints/types.ts +6 -0
  85. package/src/helpers.ts +147 -0
  86. package/src/index.ts +50 -0
  87. package/src/math/BasicTransform.ts +19 -0
  88. package/src/math/NumberValue.ts +13 -0
  89. package/src/math/isometry.ts +64 -0
  90. package/src/math/mat3.ts +529 -0
  91. package/src/math/mat4.ts +588 -0
  92. package/src/math/quat.ts +193 -0
  93. package/src/math/scalar.ts +81 -0
  94. package/src/math/tensor.ts +17 -0
  95. package/src/math/vec3.ts +589 -0
  96. package/src/math/vec4.ts +10 -0
  97. package/src/physics/Body.ts +581 -0
  98. package/src/physics/CollisionFilter.ts +52 -0
  99. package/src/physics/SleepModule.ts +163 -0
  100. package/src/physics/broadphase/BodyPairsModule.ts +363 -0
  101. package/src/physics/broadphase/BvhModule.ts +237 -0
  102. package/src/physics/broadphase/BvhTree.ts +803 -0
  103. package/src/physics/broadphase/ConstraintPairsModule.ts +385 -0
  104. package/src/physics/broadphase/TriangleMeshBvhTree.ts +379 -0
  105. package/src/physics/manifold/ContactManifold.ts +227 -0
  106. package/src/physics/manifold/ContactManifoldModule.ts +623 -0
  107. package/src/physics/manifold/Face.ts +119 -0
  108. package/src/physics/manifold/ManifoldCache.ts +116 -0
  109. package/src/physics/manifold/clipping/clipPolyVsEdge.ts +131 -0
  110. package/src/physics/manifold/clipping/clipPolyVsPlane.ts +73 -0
  111. package/src/physics/manifold/clipping/clipPolyVsPoly.ts +72 -0
  112. package/src/physics/narrowphase/CollideBodiesModule.ts +755 -0
  113. package/src/physics/solver/ContactConstraintModule.ts +659 -0
  114. package/src/physics/solver/ManifoldConstraint.ts +420 -0
  115. package/src/physics/solver/estimateCollisionResponse.ts +146 -0
  116. package/src/shape/Aabb.ts +400 -0
  117. package/src/shape/Box.ts +231 -0
  118. package/src/shape/Capsule.ts +332 -0
  119. package/src/shape/CompoundShape.ts +288 -0
  120. package/src/shape/Convex.ts +130 -0
  121. package/src/shape/ConvexHull.ts +423 -0
  122. package/src/shape/Cylinder.ts +313 -0
  123. package/src/shape/HeightMap.ts +511 -0
  124. package/src/shape/Line.ts +14 -0
  125. package/src/shape/Plane.ts +116 -0
  126. package/src/shape/Ray.ts +81 -0
  127. package/src/shape/Segment.ts +25 -0
  128. package/src/shape/Shape.ts +77 -0
  129. package/src/shape/Sphere.ts +181 -0
  130. package/src/shape/TransformedShape.ts +51 -0
  131. package/src/shape/Triangle.ts +122 -0
  132. package/src/shape/TriangleMesh.ts +186 -0
  133. package/src/types.ts +1 -0
  134. package/src/world.ts +1335 -0
  135. package/tests/BodyPairsModule.test.ts +71 -0
  136. package/tests/BvhTree.test.ts +406 -0
  137. package/tests/test.md +642 -0
  138. package/tests/vec3.test.ts +12 -0
  139. package/tsconfig.json +20 -0
  140. package/vite.config.js +40 -0
@@ -0,0 +1,64 @@
1
+ import { createClass, MonomorphType, PropertyDefinitionMap } from "monomorph";
2
+ import { Mat4 } from "./mat4";
3
+ import { Quat } from "./quat";
4
+ import { Vec3 } from "./vec3";
5
+ import { Mat3 } from "./mat3";
6
+
7
+ const isometryProps = {
8
+ matrix: MonomorphType(Mat4),
9
+ } as const satisfies PropertyDefinitionMap;
10
+
11
+ const tempTranslation = /*@__PURE__*/ Vec3.create();
12
+ const tempRotation = /*@__PURE__*/ Quat.create();
13
+ const rotation = /*@__PURE__*/ Mat3.create();
14
+
15
+ const inverseMatrix = /*@__PURE__*/ Mat4.create();
16
+
17
+ export class Isometry extends createClass<Isometry, typeof isometryProps>(isometryProps) {
18
+ fromRotationAndTranslation(rotation?: Quat, translation?: Vec3) {
19
+ if (rotation) {
20
+ tempRotation.copy(rotation);
21
+ } else {
22
+ tempRotation.identity();
23
+ }
24
+
25
+ if (translation) {
26
+ tempTranslation.copy(translation);
27
+ } else {
28
+ tempTranslation.zero();
29
+ }
30
+
31
+ this.matrix.fromRotationTranslation(tempRotation, tempTranslation);
32
+ return this;
33
+ }
34
+
35
+ fromInverseRotationAndTranslation(rotation: Quat, translation: Vec3) {
36
+ this.matrix.fromRotationTranslation(rotation, translation);
37
+ this.matrix.invert();
38
+ return this;
39
+ }
40
+
41
+ rotateVector(vector: Vec3) {
42
+ rotation.fromMat4(this.matrix);
43
+ vector.transformVectorFromMat3(vector, rotation);
44
+ return vector;
45
+ }
46
+
47
+ inverseRotateVector(out: Vec3, vector: Vec3) {
48
+ rotation.fromMat4(this.matrix);
49
+ rotation.invert();
50
+ out.transformVectorFromMat3(vector, rotation);
51
+ return out;
52
+ }
53
+
54
+ transformPoint(point: Vec3) {
55
+ point.transformFromMat4(this.matrix);
56
+ return point;
57
+ }
58
+
59
+ inverseTransformPoint(point: Vec3) {
60
+ inverseMatrix.invertMatrix(this.matrix);
61
+ point.transformFromMat4(inverseMatrix);
62
+ return point;
63
+ }
64
+ }
@@ -0,0 +1,529 @@
1
+ import { createClass, NumberType, PropertyDefinitionMap } from "monomorph";
2
+ import { Mat4 } from "./mat4";
3
+ import { Quat } from "./quat";
4
+ import { Vec3 } from "./vec3";
5
+
6
+ export const mat3Keys = ["e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8"] as const;
7
+
8
+ const mat3Props = {
9
+ e0: NumberType(0),
10
+ e1: NumberType(0),
11
+ e2: NumberType(0),
12
+
13
+ e3: NumberType(0),
14
+ e4: NumberType(0),
15
+ e5: NumberType(0),
16
+
17
+ e6: NumberType(0),
18
+ e7: NumberType(0),
19
+ e8: NumberType(0),
20
+ } as const satisfies PropertyDefinitionMap;
21
+
22
+ export class Mat3 extends createClass<Mat3, typeof mat3Props>(mat3Props) {
23
+ adjointMatrix(a: Mat3) {
24
+ let a00 = a.e0,
25
+ a01 = a.e1,
26
+ a02 = a.e2;
27
+ let a10 = a.e3,
28
+ a11 = a.e4,
29
+ a12 = a.e5;
30
+ let a20 = a.e6,
31
+ a21 = a.e7,
32
+ a22 = a.e8;
33
+
34
+ this.e0 = a11 * a22 - a12 * a21;
35
+ this.e1 = a02 * a21 - a01 * a22;
36
+ this.e2 = a01 * a12 - a02 * a11;
37
+ this.e3 = a12 * a20 - a10 * a22;
38
+ this.e4 = a00 * a22 - a02 * a20;
39
+ this.e5 = a02 * a10 - a00 * a12;
40
+ this.e6 = a10 * a21 - a11 * a20;
41
+ this.e7 = a01 * a20 - a00 * a21;
42
+ this.e8 = a00 * a11 - a01 * a10;
43
+ return this;
44
+ }
45
+
46
+ adjoint() {
47
+ let a00 = this.e0,
48
+ a01 = this.e1,
49
+ a02 = this.e2;
50
+ let a10 = this.e3,
51
+ a11 = this.e4,
52
+ a12 = this.e5;
53
+ let a20 = this.e6,
54
+ a21 = this.e7,
55
+ a22 = this.e8;
56
+
57
+ this.e0 = a11 * a22 - a12 * a21;
58
+ this.e1 = a02 * a21 - a01 * a22;
59
+ this.e2 = a01 * a12 - a02 * a11;
60
+ this.e3 = a12 * a20 - a10 * a22;
61
+ this.e4 = a00 * a22 - a02 * a20;
62
+ this.e5 = a02 * a10 - a00 * a12;
63
+ this.e6 = a10 * a21 - a11 * a20;
64
+ this.e7 = a01 * a20 - a00 * a21;
65
+ this.e8 = a00 * a11 - a01 * a10;
66
+ return this;
67
+ }
68
+
69
+ computeDeterminant() {
70
+ let a00 = this.e0,
71
+ a01 = this.e1,
72
+ a02 = this.e2;
73
+ let a10 = this.e3,
74
+ a11 = this.e4,
75
+ a12 = this.e5;
76
+ let a20 = this.e6,
77
+ a21 = this.e7,
78
+ a22 = this.e8;
79
+
80
+ return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
81
+ }
82
+
83
+ setColumns(column0: Vec3, column1: Vec3, column2: Vec3): void {
84
+ this.e0 = column0.x;
85
+ this.e1 = column0.y;
86
+ this.e2 = column0.z;
87
+ this.e3 = column1.x;
88
+ this.e4 = column1.y;
89
+ this.e5 = column1.z;
90
+ this.e6 = column2.x;
91
+ this.e7 = column2.y;
92
+ this.e8 = column2.z;
93
+ }
94
+
95
+ fill(value: number) {
96
+ this.e0 = value;
97
+ this.e1 = value;
98
+ this.e2 = value;
99
+ this.e3 = value;
100
+ this.e4 = value;
101
+ this.e5 = value;
102
+ this.e6 = value;
103
+ this.e7 = value;
104
+ this.e8 = value;
105
+ }
106
+
107
+ fillDiagonal(value: number) {
108
+ this.e0 = value;
109
+ this.e4 = value;
110
+ this.e8 = value;
111
+ }
112
+
113
+ fillOffDiagonal(value: number) {
114
+ this.e1 = value;
115
+ this.e2 = value;
116
+ this.e3 = value;
117
+ this.e5 = value;
118
+ this.e6 = value;
119
+ this.e7 = value;
120
+ }
121
+
122
+ fromMat4(a: Mat4) {
123
+ this.e0 = a.e0;
124
+ this.e1 = a.e1;
125
+ this.e2 = a.e2;
126
+ this.e3 = a.e4;
127
+ this.e4 = a.e5;
128
+ this.e5 = a.e6;
129
+ this.e6 = a.e8;
130
+ this.e7 = a.e9;
131
+ this.e8 = a.e10;
132
+
133
+ return this;
134
+ }
135
+
136
+ transpose() {
137
+ const a01 = this.e1;
138
+ const a02 = this.e2;
139
+ const a12 = this.e5;
140
+ this.e1 = this.e3;
141
+ this.e2 = this.e6;
142
+ this.e3 = a01;
143
+ this.e5 = this.e7;
144
+ this.e6 = a02;
145
+ this.e7 = a12;
146
+
147
+ return this;
148
+ }
149
+
150
+ transposeMatrix(a: Mat3) {
151
+ this.e0 = a.e0;
152
+ this.e1 = a.e3;
153
+ this.e2 = a.e6;
154
+ this.e3 = a.e1;
155
+ this.e4 = a.e4;
156
+ this.e5 = a.e7;
157
+ this.e6 = a.e2;
158
+ this.e7 = a.e5;
159
+ this.e8 = a.e8;
160
+
161
+ return this;
162
+ }
163
+
164
+ invert(): Mat3 | null {
165
+ const a00 = this.e0;
166
+ const a01 = this.e1;
167
+ const a02 = this.e2;
168
+ const a10 = this.e3;
169
+ const a11 = this.e4;
170
+ const a12 = this.e5;
171
+ const a20 = this.e6;
172
+ const a21 = this.e7;
173
+ const a22 = this.e8;
174
+
175
+ const b01 = a22 * a11 - a12 * a21;
176
+ const b11 = -a22 * a10 + a12 * a20;
177
+ const b21 = a21 * a10 - a11 * a20;
178
+
179
+ // Calculate the determinant
180
+ let det = a00 * b01 + a01 * b11 + a02 * b21;
181
+
182
+ if (!det) {
183
+ return null;
184
+ }
185
+ det = 1.0 / det;
186
+
187
+ this.e0 = b01 * det;
188
+ this.e1 = (-a22 * a01 + a02 * a21) * det;
189
+ this.e2 = (a12 * a01 - a02 * a11) * det;
190
+ this.e3 = b11 * det;
191
+ this.e4 = (a22 * a00 - a02 * a20) * det;
192
+ this.e5 = (-a12 * a00 + a02 * a10) * det;
193
+ this.e6 = b21 * det;
194
+ this.e7 = (-a21 * a00 + a01 * a20) * det;
195
+ this.e8 = (a11 * a00 - a01 * a10) * det;
196
+ return this;
197
+ }
198
+
199
+ invertMat3(a: Mat3): Mat3 | null {
200
+ const a00 = a.e0;
201
+ const a01 = a.e1;
202
+ const a02 = a.e2;
203
+ const a10 = a.e3;
204
+ const a11 = a.e4;
205
+ const a12 = a.e5;
206
+ const a20 = a.e6;
207
+ const a21 = a.e7;
208
+ const a22 = a.e8;
209
+
210
+ const b01 = a22 * a11 - a12 * a21;
211
+ const b11 = -a22 * a10 + a12 * a20;
212
+ const b21 = a21 * a10 - a11 * a20;
213
+
214
+ // Calculate the determinant
215
+ let det = a00 * b01 + a01 * b11 + a02 * b21;
216
+
217
+ if (!det) {
218
+ return null;
219
+ }
220
+ det = 1.0 / det;
221
+
222
+ this.e0 = b01 * det;
223
+ this.e1 = (-a22 * a01 + a02 * a21) * det;
224
+ this.e2 = (a12 * a01 - a02 * a11) * det;
225
+ this.e3 = b11 * det;
226
+ this.e4 = (a22 * a00 - a02 * a20) * det;
227
+ this.e5 = (-a12 * a00 + a02 * a10) * det;
228
+ this.e6 = b21 * det;
229
+ this.e7 = (-a21 * a00 + a01 * a20) * det;
230
+ this.e8 = (a11 * a00 - a01 * a10) * det;
231
+ return this;
232
+ }
233
+
234
+ zero() {
235
+ this.e0 = 0;
236
+ this.e1 = 0;
237
+ this.e2 = 0;
238
+ this.e3 = 0;
239
+ this.e4 = 0;
240
+ this.e5 = 0;
241
+ this.e6 = 0;
242
+ this.e7 = 0;
243
+ this.e8 = 0;
244
+
245
+ return this;
246
+ }
247
+
248
+ multiplyMat3(b: Mat3): Mat3 {
249
+ const a00 = this.e0;
250
+ const a01 = this.e1;
251
+ const a02 = this.e2;
252
+ const a10 = this.e3;
253
+ const a11 = this.e4;
254
+ const a12 = this.e5;
255
+ const a20 = this.e6;
256
+ const a21 = this.e7;
257
+ const a22 = this.e8;
258
+
259
+ const b00 = b.e0;
260
+ const b01 = b.e1;
261
+ const b02 = b.e2;
262
+ const b10 = b.e3;
263
+ const b11 = b.e4;
264
+ const b12 = b.e5;
265
+ const b20 = b.e6;
266
+ const b21 = b.e7;
267
+ const b22 = b.e8;
268
+
269
+ this.e0 = b00 * a00 + b01 * a10 + b02 * a20;
270
+ this.e1 = b00 * a01 + b01 * a11 + b02 * a21;
271
+ this.e2 = b00 * a02 + b01 * a12 + b02 * a22;
272
+
273
+ this.e3 = b10 * a00 + b11 * a10 + b12 * a20;
274
+ this.e4 = b10 * a01 + b11 * a11 + b12 * a21;
275
+ this.e5 = b10 * a02 + b11 * a12 + b12 * a22;
276
+
277
+ this.e6 = b20 * a00 + b21 * a10 + b22 * a20;
278
+ this.e7 = b20 * a01 + b21 * a11 + b22 * a21;
279
+ this.e8 = b20 * a02 + b21 * a12 + b22 * a22;
280
+ return this;
281
+ }
282
+
283
+ addMatrix(a: Mat3) {
284
+ this.e0 += a.e0;
285
+ this.e1 += a.e1;
286
+ this.e2 += a.e2;
287
+ this.e3 += a.e3;
288
+ this.e4 += a.e4;
289
+ this.e5 += a.e5;
290
+ this.e6 += a.e6;
291
+ this.e7 += a.e7;
292
+ this.e8 += a.e8;
293
+
294
+ return this;
295
+ }
296
+
297
+ addMatrices(a: Mat3, b: Mat3) {
298
+ this.e0 = a.e0 + b.e0;
299
+ this.e1 = a.e1 + b.e1;
300
+ this.e2 = a.e2 + b.e2;
301
+ this.e3 = a.e3 + b.e3;
302
+ this.e4 = a.e4 + b.e4;
303
+ this.e5 = a.e5 + b.e5;
304
+ this.e6 = a.e6 + b.e6;
305
+ this.e7 = a.e7 + b.e7;
306
+ this.e8 = a.e8 + b.e8;
307
+ return this;
308
+ }
309
+
310
+ subtractMatrix(a: Mat3) {
311
+ this.e0 -= a.e0;
312
+ this.e1 -= a.e1;
313
+ this.e2 -= a.e2;
314
+ this.e3 -= a.e3;
315
+ this.e4 -= a.e4;
316
+ this.e5 -= a.e5;
317
+ this.e6 -= a.e6;
318
+ this.e7 -= a.e7;
319
+ this.e8 -= a.e8;
320
+
321
+ return this;
322
+ }
323
+
324
+ subtractMatrices(a: Mat3, b: Mat3) {
325
+ this.e0 = a.e0 - b.e0;
326
+ this.e1 = a.e1 - b.e1;
327
+ this.e2 = a.e2 - b.e2;
328
+ this.e3 = a.e3 - b.e3;
329
+ this.e4 = a.e4 - b.e4;
330
+ this.e5 = a.e5 - b.e5;
331
+ this.e6 = a.e6 - b.e6;
332
+ this.e7 = a.e7 - b.e7;
333
+ this.e8 = a.e8 - b.e8;
334
+ return this;
335
+ }
336
+
337
+ outerProduct(a: Vec3, b: Vec3) {
338
+ this.e0 = a.x * b.x;
339
+ this.e1 = a.y * b.x;
340
+ this.e2 = a.z * b.x;
341
+ this.e3 = a.x * b.y;
342
+ this.e4 = a.y * b.y;
343
+ this.e5 = a.z * b.y;
344
+ this.e6 = a.x * b.z;
345
+ this.e7 = a.y * b.z;
346
+ this.e8 = a.z * b.z;
347
+ return this;
348
+ }
349
+
350
+ multiplyByScalar(b: number) {
351
+ this.e0 *= b;
352
+ this.e1 *= b;
353
+ this.e2 *= b;
354
+ this.e3 *= b;
355
+ this.e4 *= b;
356
+ this.e5 *= b;
357
+ this.e6 *= b;
358
+ this.e7 *= b;
359
+ this.e8 *= b;
360
+
361
+ return this;
362
+ }
363
+
364
+ multiplyMatrixByScalar(a: Mat3, b: number) {
365
+ this.e0 = a.e0 * b;
366
+ this.e1 = a.e1 * b;
367
+ this.e2 = a.e2 * b;
368
+ this.e3 = a.e3 * b;
369
+ this.e4 = a.e4 * b;
370
+ this.e5 = a.e5 * b;
371
+ this.e6 = a.e6 * b;
372
+ this.e7 = a.e7 * b;
373
+ this.e8 = a.e8 * b;
374
+ return this;
375
+ }
376
+
377
+ identity() {
378
+ this.e0 = 1;
379
+ this.e1 = 0;
380
+ this.e2 = 0;
381
+ this.e3 = 0;
382
+ this.e4 = 1;
383
+ this.e5 = 0;
384
+ this.e6 = 0;
385
+ this.e7 = 0;
386
+ this.e8 = 1;
387
+
388
+ return this;
389
+ }
390
+
391
+ multiplyMat3RightTransposed(a: Mat3) {
392
+ rightTransposed.transposeMatrix(a);
393
+ this.multiplyMat3s(this, rightTransposed);
394
+ return this;
395
+ }
396
+
397
+ multiplyMat3s(a: Mat3, b: Mat3): Mat3 {
398
+ const a00 = a.e0;
399
+ const a01 = a.e1;
400
+ const a02 = a.e2;
401
+ const a10 = a.e3;
402
+ const a11 = a.e4;
403
+ const a12 = a.e5;
404
+ const a20 = a.e6;
405
+ const a21 = a.e7;
406
+ const a22 = a.e8;
407
+
408
+ const b00 = b.e0;
409
+ const b01 = b.e1;
410
+ const b02 = b.e2;
411
+ const b10 = b.e3;
412
+ const b11 = b.e4;
413
+ const b12 = b.e5;
414
+ const b20 = b.e6;
415
+ const b21 = b.e7;
416
+ const b22 = b.e8;
417
+
418
+ this.e0 = b00 * a00 + b01 * a10 + b02 * a20;
419
+ this.e1 = b00 * a01 + b01 * a11 + b02 * a21;
420
+ this.e2 = b00 * a02 + b01 * a12 + b02 * a22;
421
+
422
+ this.e3 = b10 * a00 + b11 * a10 + b12 * a20;
423
+ this.e4 = b10 * a01 + b11 * a11 + b12 * a21;
424
+ this.e5 = b10 * a02 + b11 * a12 + b12 * a22;
425
+
426
+ this.e6 = b20 * a00 + b21 * a10 + b22 * a20;
427
+ this.e7 = b20 * a01 + b21 * a11 + b22 * a21;
428
+ this.e8 = b20 * a02 + b21 * a12 + b22 * a22;
429
+ return this;
430
+ }
431
+
432
+ fromQuat(q: Quat): Mat3 {
433
+ const x = q.x;
434
+ const y = q.y;
435
+ const z = q.z;
436
+ const w = q.w;
437
+ const x2 = x + x;
438
+ const y2 = y + y;
439
+ const z2 = z + z;
440
+
441
+ const xx = x * x2;
442
+ const yx = y * x2;
443
+ const yy = y * y2;
444
+ const zx = z * x2;
445
+ const zy = z * y2;
446
+ const zz = z * z2;
447
+ const wx = w * x2;
448
+ const wy = w * y2;
449
+ const wz = w * z2;
450
+
451
+ this.e0 = 1 - yy - zz;
452
+ this.e3 = yx - wz;
453
+ this.e6 = zx + wy;
454
+
455
+ this.e1 = yx + wz;
456
+ this.e4 = 1 - xx - zz;
457
+ this.e7 = zy - wx;
458
+
459
+ this.e2 = zx - wy;
460
+ this.e5 = zy + wx;
461
+ this.e8 = 1 - xx - yy;
462
+
463
+ return this;
464
+ }
465
+
466
+ isExactlyZero() {
467
+ return (
468
+ this.e0 === 0 &&
469
+ this.e1 === 0 &&
470
+ this.e2 === 0 &&
471
+ this.e3 === 0 &&
472
+ this.e4 === 0 &&
473
+ this.e5 === 0 &&
474
+ this.e6 === 0 &&
475
+ this.e7 === 0 &&
476
+ this.e8 === 0
477
+ );
478
+ }
479
+
480
+ asSkewSymmetricMatrix(a: Vec3) {
481
+ this.e0 = +0;
482
+ this.e1 = +a.z;
483
+ this.e2 = -a.y;
484
+ this.e3 = -a.z;
485
+ this.e4 = +0;
486
+ this.e5 = +a.x;
487
+ this.e6 = +a.y;
488
+ this.e7 = -a.x;
489
+ this.e8 = +0;
490
+ return this;
491
+ }
492
+
493
+ multiplyMatrices(a: Mat3, b: Mat3) {
494
+ let a00 = a.e0,
495
+ a01 = a.e1,
496
+ a02 = a.e2;
497
+ let a10 = a.e3,
498
+ a11 = a.e4,
499
+ a12 = a.e5;
500
+ let a20 = a.e6,
501
+ a21 = a.e7,
502
+ a22 = a.e8;
503
+
504
+ let b00 = b.e0,
505
+ b01 = b.e1,
506
+ b02 = b.e2;
507
+ let b10 = b.e3,
508
+ b11 = b.e4,
509
+ b12 = b.e5;
510
+ let b20 = b.e6,
511
+ b21 = b.e7,
512
+ b22 = b.e8;
513
+
514
+ this.e0 = b00 * a00 + b01 * a10 + b02 * a20;
515
+ this.e1 = b00 * a01 + b01 * a11 + b02 * a21;
516
+ this.e2 = b00 * a02 + b01 * a12 + b02 * a22;
517
+
518
+ this.e3 = b10 * a00 + b11 * a10 + b12 * a20;
519
+ this.e4 = b10 * a01 + b11 * a11 + b12 * a21;
520
+ this.e5 = b10 * a02 + b11 * a12 + b12 * a22;
521
+
522
+ this.e6 = b20 * a00 + b21 * a10 + b22 * a20;
523
+ this.e7 = b20 * a01 + b21 * a11 + b22 * a21;
524
+ this.e8 = b20 * a02 + b21 * a12 + b22 * a22;
525
+ return this;
526
+ }
527
+ }
528
+
529
+ const rightTransposed = /*@__PURE__*/ Mat3.create();