@aura3d/math 1.0.6

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 (97) hide show
  1. package/README.md +18 -0
  2. package/dist/Box3.d.ts +19 -0
  3. package/dist/Box3.d.ts.map +1 -0
  4. package/dist/Box3.js +61 -0
  5. package/dist/Box3.js.map +1 -0
  6. package/dist/Color.d.ts +15 -0
  7. package/dist/Color.d.ts.map +1 -0
  8. package/dist/Color.js +41 -0
  9. package/dist/Color.js.map +1 -0
  10. package/dist/Curves.d.ts +22 -0
  11. package/dist/Curves.d.ts.map +1 -0
  12. package/dist/Curves.js +74 -0
  13. package/dist/Curves.js.map +1 -0
  14. package/dist/Easing.d.ts +7 -0
  15. package/dist/Easing.d.ts.map +1 -0
  16. package/dist/Easing.js +24 -0
  17. package/dist/Easing.js.map +1 -0
  18. package/dist/Euler.d.ts +12 -0
  19. package/dist/Euler.d.ts.map +1 -0
  20. package/dist/Euler.js +30 -0
  21. package/dist/Euler.js.map +1 -0
  22. package/dist/Frustum.d.ts +14 -0
  23. package/dist/Frustum.d.ts.map +1 -0
  24. package/dist/Frustum.js +40 -0
  25. package/dist/Frustum.js.map +1 -0
  26. package/dist/Interpolation.d.ts +11 -0
  27. package/dist/Interpolation.d.ts.map +1 -0
  28. package/dist/Interpolation.js +30 -0
  29. package/dist/Interpolation.js.map +1 -0
  30. package/dist/Matrix3.d.ts +9 -0
  31. package/dist/Matrix3.d.ts.map +1 -0
  32. package/dist/Matrix3.js +51 -0
  33. package/dist/Matrix3.js.map +1 -0
  34. package/dist/Matrix4.d.ts +45 -0
  35. package/dist/Matrix4.d.ts.map +1 -0
  36. package/dist/Matrix4.js +204 -0
  37. package/dist/Matrix4.js.map +1 -0
  38. package/dist/Plane.d.ts +11 -0
  39. package/dist/Plane.d.ts.map +1 -0
  40. package/dist/Plane.js +31 -0
  41. package/dist/Plane.js.map +1 -0
  42. package/dist/Quaternion.d.ts +25 -0
  43. package/dist/Quaternion.d.ts.map +1 -0
  44. package/dist/Quaternion.js +121 -0
  45. package/dist/Quaternion.js.map +1 -0
  46. package/dist/Random.d.ts +9 -0
  47. package/dist/Random.d.ts.map +1 -0
  48. package/dist/Random.js +30 -0
  49. package/dist/Random.js.map +1 -0
  50. package/dist/Ray.d.ts +14 -0
  51. package/dist/Ray.d.ts.map +1 -0
  52. package/dist/Ray.js +67 -0
  53. package/dist/Ray.js.map +1 -0
  54. package/dist/Sphere.d.ts +9 -0
  55. package/dist/Sphere.d.ts.map +1 -0
  56. package/dist/Sphere.js +18 -0
  57. package/dist/Sphere.js.map +1 -0
  58. package/dist/Transform.d.ts +14 -0
  59. package/dist/Transform.d.ts.map +1 -0
  60. package/dist/Transform.js +28 -0
  61. package/dist/Transform.js.map +1 -0
  62. package/dist/Vector2.d.ts +22 -0
  63. package/dist/Vector2.d.ts.map +1 -0
  64. package/dist/Vector2.js +54 -0
  65. package/dist/Vector2.js.map +1 -0
  66. package/dist/Vector3.d.ts +34 -0
  67. package/dist/Vector3.d.ts.map +1 -0
  68. package/dist/Vector3.js +77 -0
  69. package/dist/Vector3.js.map +1 -0
  70. package/dist/Vector4.d.ts +19 -0
  71. package/dist/Vector4.d.ts.map +1 -0
  72. package/dist/Vector4.js +43 -0
  73. package/dist/Vector4.js.map +1 -0
  74. package/dist/index.d.ts +19 -0
  75. package/dist/index.d.ts.map +1 -0
  76. package/dist/index.js +19 -0
  77. package/dist/index.js.map +1 -0
  78. package/package.json +13 -0
  79. package/src/Box3.ts +65 -0
  80. package/src/Color.ts +49 -0
  81. package/src/Curves.ts +79 -0
  82. package/src/Easing.ts +24 -0
  83. package/src/Euler.ts +30 -0
  84. package/src/Frustum.ts +43 -0
  85. package/src/Interpolation.ts +34 -0
  86. package/src/Matrix3.ts +54 -0
  87. package/src/Matrix4.ts +240 -0
  88. package/src/Plane.ts +34 -0
  89. package/src/Quaternion.ts +178 -0
  90. package/src/Random.ts +32 -0
  91. package/src/Ray.ts +67 -0
  92. package/src/Sphere.ts +18 -0
  93. package/src/Transform.ts +33 -0
  94. package/src/Vector2.ts +66 -0
  95. package/src/Vector3.ts +101 -0
  96. package/src/Vector4.ts +55 -0
  97. package/src/index.ts +18 -0
package/dist/Sphere.js ADDED
@@ -0,0 +1,18 @@
1
+ import { Vector3 } from "./Vector3.js";
2
+ export class Sphere {
3
+ center;
4
+ radius;
5
+ constructor(center = Vector3.zero.clone(), radius = 0) {
6
+ this.center = center;
7
+ this.radius = radius;
8
+ if (!Number.isFinite(radius) || radius < 0)
9
+ throw new RangeError("Sphere radius must be finite and non-negative.");
10
+ }
11
+ containsPoint(point) {
12
+ return this.center.distanceTo(point) <= this.radius;
13
+ }
14
+ intersectsSphere(other) {
15
+ return this.center.distanceTo(other.center) <= this.radius + other.radius;
16
+ }
17
+ }
18
+ //# sourceMappingURL=Sphere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sphere.js","sourceRoot":"","sources":["../../../../packages/math/src/Sphere.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,MAAM;IAEN;IACA;IAFX,YACW,SAAS,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,EAC7B,SAAS,CAAC;QADV,WAAM,GAAN,MAAM,CAAuB;QAC7B,WAAM,GAAN,MAAM,CAAI;QAEnB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAC;IACrH,CAAC;IAED,aAAa,CAAC,KAAc;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC;IACtD,CAAC;IAED,gBAAgB,CAAC,KAAa;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5E,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { Matrix4 } from "./Matrix4.js";
2
+ import { Quaternion } from "./Quaternion.js";
3
+ import { Vector3 } from "./Vector3.js";
4
+ export declare class Transform {
5
+ readonly position: Vector3;
6
+ readonly rotation: Quaternion;
7
+ readonly scale: Vector3;
8
+ constructor(position?: Vector3, rotation?: Quaternion, scale?: Vector3);
9
+ static identity(): Transform;
10
+ toMatrix4(): Matrix4;
11
+ combine(child: Transform): Transform;
12
+ transformPoint(point: Vector3): Vector3;
13
+ }
14
+ //# sourceMappingURL=Transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transform.d.ts","sourceRoot":"","sources":["../../../../packages/math/src/Transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,qBAAa,SAAS;IAElB,QAAQ,CAAC,QAAQ;IACjB,QAAQ,CAAC,QAAQ;IACjB,QAAQ,CAAC,KAAK;gBAFL,QAAQ,UAAuB,EAC/B,QAAQ,aAA8B,EACtC,KAAK,UAAsB;IAGtC,MAAM,CAAC,QAAQ,IAAI,SAAS;IAI5B,SAAS,IAAI,OAAO;IAIpB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS;IAUpC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAGxC"}
@@ -0,0 +1,28 @@
1
+ import { Matrix4 } from "./Matrix4.js";
2
+ import { Quaternion } from "./Quaternion.js";
3
+ import { Vector3 } from "./Vector3.js";
4
+ export class Transform {
5
+ position;
6
+ rotation;
7
+ scale;
8
+ constructor(position = Vector3.zero.clone(), rotation = Quaternion.identity.clone(), scale = Vector3.one.clone()) {
9
+ this.position = position;
10
+ this.rotation = rotation;
11
+ this.scale = scale;
12
+ }
13
+ static identity() {
14
+ return new Transform();
15
+ }
16
+ toMatrix4() {
17
+ return Matrix4.compose(this.position, this.rotation, this.scale);
18
+ }
19
+ combine(child) {
20
+ const scaledPosition = child.position.multiply(this.scale);
21
+ const rotatedPosition = this.rotation.rotateVector(scaledPosition);
22
+ return new Transform(this.position.add(rotatedPosition), this.rotation.multiply(child.rotation).normalize(), this.scale.multiply(child.scale));
23
+ }
24
+ transformPoint(point) {
25
+ return this.toMatrix4().transformPoint(point);
26
+ }
27
+ }
28
+ //# sourceMappingURL=Transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transform.js","sourceRoot":"","sources":["../../../../packages/math/src/Transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,OAAO,SAAS;IAET;IACA;IACA;IAHX,YACW,WAAW,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,EAC/B,WAAW,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,EACtC,QAAQ,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE;QAF3B,aAAQ,GAAR,QAAQ,CAAuB;QAC/B,aAAQ,GAAR,QAAQ,CAA8B;QACtC,UAAK,GAAL,KAAK,CAAsB;IACnC,CAAC;IAEJ,MAAM,CAAC,QAAQ;QACb,OAAO,IAAI,SAAS,EAAE,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,CAAC,KAAgB;QACtB,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3D,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QACnE,OAAO,IAAI,SAAS,CAClB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,EAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,SAAS,EAAE,EAClD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CACjC,CAAC;IACJ,CAAC;IAED,cAAc,CAAC,KAAc;QAC3B,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ export declare class Vector2 {
2
+ readonly x: number;
3
+ readonly y: number;
4
+ static readonly zero: Readonly<Vector2>;
5
+ static readonly one: Readonly<Vector2>;
6
+ constructor(x?: number, y?: number);
7
+ clone(): Vector2;
8
+ add(v: Vector2): Vector2;
9
+ subtract(v: Vector2): Vector2;
10
+ multiplyScalar(scalar: number): Vector2;
11
+ divide(v: Vector2): Vector2;
12
+ divideScalar(scalar: number): Vector2;
13
+ dot(v: Vector2): number;
14
+ lengthSquared(): number;
15
+ length(): number;
16
+ normalize(): Vector2;
17
+ distanceTo(v: Vector2): number;
18
+ lerp(v: Vector2, t: number): Vector2;
19
+ equals(v: Vector2, epsilon?: number): boolean;
20
+ toArray(): [number, number];
21
+ }
22
+ //# sourceMappingURL=Vector2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../../../packages/math/src/Vector2.ts"],"names":[],"mappings":"AAAA,qBAAa,OAAO;IAKhB,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;IALZ,MAAM,CAAC,QAAQ,CAAC,IAAI,oBAAoC;IACxD,MAAM,CAAC,QAAQ,CAAC,GAAG,oBAAoC;gBAG5C,CAAC,SAAI,EACL,CAAC,SAAI;IAGhB,KAAK,IAAI,OAAO;IAIhB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAIxB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI7B,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIvC,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI3B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;IAIvB,aAAa,IAAI,MAAM;IAIvB,MAAM,IAAI,MAAM;IAIhB,SAAS,IAAI,OAAO;IAKpB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;IAI9B,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAIpC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,SAAQ,GAAG,OAAO;IAI5C,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;CAG5B"}
@@ -0,0 +1,54 @@
1
+ export class Vector2 {
2
+ x;
3
+ y;
4
+ static zero = Object.freeze(new Vector2(0, 0));
5
+ static one = Object.freeze(new Vector2(1, 1));
6
+ constructor(x = 0, y = 0) {
7
+ this.x = x;
8
+ this.y = y;
9
+ }
10
+ clone() {
11
+ return new Vector2(this.x, this.y);
12
+ }
13
+ add(v) {
14
+ return new Vector2(this.x + v.x, this.y + v.y);
15
+ }
16
+ subtract(v) {
17
+ return new Vector2(this.x - v.x, this.y - v.y);
18
+ }
19
+ multiplyScalar(scalar) {
20
+ return new Vector2(this.x * scalar, this.y * scalar);
21
+ }
22
+ divide(v) {
23
+ return new Vector2(this.x / v.x, this.y / v.y);
24
+ }
25
+ divideScalar(scalar) {
26
+ return new Vector2(this.x / scalar, this.y / scalar);
27
+ }
28
+ dot(v) {
29
+ return this.x * v.x + this.y * v.y;
30
+ }
31
+ lengthSquared() {
32
+ return this.dot(this);
33
+ }
34
+ length() {
35
+ return Math.hypot(this.x, this.y);
36
+ }
37
+ normalize() {
38
+ const len = this.length();
39
+ return len === 0 ? Vector2.zero.clone() : this.multiplyScalar(1 / len);
40
+ }
41
+ distanceTo(v) {
42
+ return this.subtract(v).length();
43
+ }
44
+ lerp(v, t) {
45
+ return new Vector2(this.x + (v.x - this.x) * t, this.y + (v.y - this.y) * t);
46
+ }
47
+ equals(v, epsilon = 1e-10) {
48
+ return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon;
49
+ }
50
+ toArray() {
51
+ return [this.x, this.y];
52
+ }
53
+ }
54
+ //# sourceMappingURL=Vector2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector2.js","sourceRoot":"","sources":["../../../../packages/math/src/Vector2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,OAAO;IAKP;IACA;IALX,MAAM,CAAU,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,CAAU,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEvD,YACW,IAAI,CAAC,EACL,IAAI,CAAC;QADL,MAAC,GAAD,CAAC,CAAI;QACL,MAAC,GAAD,CAAC,CAAI;IACb,CAAC;IAEJ,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,CAAU;QACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,QAAQ,CAAC,CAAU;QACjB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC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AED,IAAI,CAAC,CAAU,EAAE,CAAS;QACxB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,MAAM,CAAC,CAAU,EAAE,OAAO,GAAG,KAAK;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IAChF,CAAC;IAED,OAAO;QACL,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { Matrix4 } from "./Matrix4.js";
2
+ import type { Quaternion } from "./Quaternion.js";
3
+ export declare class Vector3 {
4
+ readonly x: number;
5
+ readonly y: number;
6
+ readonly z: number;
7
+ static readonly zero: Readonly<Vector3>;
8
+ static readonly one: Readonly<Vector3>;
9
+ static readonly up: Readonly<Vector3>;
10
+ static readonly right: Readonly<Vector3>;
11
+ static readonly forward: Readonly<Vector3>;
12
+ constructor(x?: number, y?: number, z?: number);
13
+ clone(): Vector3;
14
+ add(v: Vector3): Vector3;
15
+ subtract(v: Vector3): Vector3;
16
+ multiplyScalar(scalar: number): Vector3;
17
+ multiply(v: Vector3): Vector3;
18
+ divide(v: Vector3): Vector3;
19
+ divideScalar(scalar: number): Vector3;
20
+ dot(v: Vector3): number;
21
+ cross(v: Vector3): Vector3;
22
+ lengthSquared(): number;
23
+ length(): number;
24
+ normalize(): Vector3;
25
+ distanceTo(v: Vector3): number;
26
+ lerp(v: Vector3, t: number): Vector3;
27
+ transformMatrix4(matrix: Matrix4): Vector3;
28
+ rotateByQuaternion(rotation: Quaternion): Vector3;
29
+ min(v: Vector3): Vector3;
30
+ max(v: Vector3): Vector3;
31
+ equals(v: Vector3, epsilon?: number): boolean;
32
+ toArray(): [number, number, number];
33
+ }
34
+ //# sourceMappingURL=Vector3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector3.d.ts","sourceRoot":"","sources":["../../../../packages/math/src/Vector3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,qBAAa,OAAO;IAQhB,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;IATZ,MAAM,CAAC,QAAQ,CAAC,IAAI,oBAAuC;IAC3D,MAAM,CAAC,QAAQ,CAAC,GAAG,oBAAuC;IAC1D,MAAM,CAAC,QAAQ,CAAC,EAAE,oBAAuC;IACzD,MAAM,CAAC,QAAQ,CAAC,KAAK,oBAAuC;IAC5D,MAAM,CAAC,QAAQ,CAAC,OAAO,oBAAwC;gBAGpD,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI;IAGhB,KAAK,IAAI,OAAO;IAIhB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAIxB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI7B,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIvC,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI7B,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI3B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;IAIvB,KAAK,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAQ1B,aAAa,IAAI,MAAM;IAIvB,MAAM,IAAI,MAAM;IAIhB,SAAS,IAAI,OAAO;IAKpB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;IAI9B,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IAIpC,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAI1C,kBAAkB,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO;IAIjD,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAIxB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAIxB,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,SAAQ,GAAG,OAAO;IAI5C,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;CAGpC"}
@@ -0,0 +1,77 @@
1
+ export class Vector3 {
2
+ x;
3
+ y;
4
+ z;
5
+ static zero = Object.freeze(new Vector3(0, 0, 0));
6
+ static one = Object.freeze(new Vector3(1, 1, 1));
7
+ static up = Object.freeze(new Vector3(0, 1, 0));
8
+ static right = Object.freeze(new Vector3(1, 0, 0));
9
+ static forward = Object.freeze(new Vector3(0, 0, -1));
10
+ constructor(x = 0, y = 0, z = 0) {
11
+ this.x = x;
12
+ this.y = y;
13
+ this.z = z;
14
+ }
15
+ clone() {
16
+ return new Vector3(this.x, this.y, this.z);
17
+ }
18
+ add(v) {
19
+ return new Vector3(this.x + v.x, this.y + v.y, this.z + v.z);
20
+ }
21
+ subtract(v) {
22
+ return new Vector3(this.x - v.x, this.y - v.y, this.z - v.z);
23
+ }
24
+ multiplyScalar(scalar) {
25
+ return new Vector3(this.x * scalar, this.y * scalar, this.z * scalar);
26
+ }
27
+ multiply(v) {
28
+ return new Vector3(this.x * v.x, this.y * v.y, this.z * v.z);
29
+ }
30
+ divide(v) {
31
+ return new Vector3(this.x / v.x, this.y / v.y, this.z / v.z);
32
+ }
33
+ divideScalar(scalar) {
34
+ return new Vector3(this.x / scalar, this.y / scalar, this.z / scalar);
35
+ }
36
+ dot(v) {
37
+ return this.x * v.x + this.y * v.y + this.z * v.z;
38
+ }
39
+ cross(v) {
40
+ return new Vector3(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
41
+ }
42
+ lengthSquared() {
43
+ return this.dot(this);
44
+ }
45
+ length() {
46
+ return Math.hypot(this.x, this.y, this.z);
47
+ }
48
+ normalize() {
49
+ const len = this.length();
50
+ return len === 0 ? Vector3.zero.clone() : this.multiplyScalar(1 / len);
51
+ }
52
+ distanceTo(v) {
53
+ return this.subtract(v).length();
54
+ }
55
+ lerp(v, t) {
56
+ return new Vector3(this.x + (v.x - this.x) * t, this.y + (v.y - this.y) * t, this.z + (v.z - this.z) * t);
57
+ }
58
+ transformMatrix4(matrix) {
59
+ return matrix.transformPoint(this);
60
+ }
61
+ rotateByQuaternion(rotation) {
62
+ return rotation.rotateVector(this);
63
+ }
64
+ min(v) {
65
+ return new Vector3(Math.min(this.x, v.x), Math.min(this.y, v.y), Math.min(this.z, v.z));
66
+ }
67
+ max(v) {
68
+ return new Vector3(Math.max(this.x, v.x), Math.max(this.y, v.y), Math.max(this.z, v.z));
69
+ }
70
+ equals(v, epsilon = 1e-10) {
71
+ return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon && Math.abs(this.z - v.z) <= epsilon;
72
+ }
73
+ toArray() {
74
+ return [this.x, this.y, this.z];
75
+ }
76
+ }
77
+ //# sourceMappingURL=Vector3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector3.js","sourceRoot":"","sources":["../../../../packages/math/src/Vector3.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,OAAO;IAQP;IACA;IACA;IATX,MAAM,CAAU,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,C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G,CAAC,CAAU;QACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,GAAG,CAAC,CAAU;QACZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,MAAM,CAAC,CAAU,EAAE,OAAO,GAAG,KAAK;QAChC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IACrH,CAAC;IAED,OAAO;QACL,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Matrix4 } from "./Matrix4.js";
2
+ export declare class Vector4 {
3
+ readonly x: number;
4
+ readonly y: number;
5
+ readonly z: number;
6
+ readonly w: number;
7
+ constructor(x?: number, y?: number, z?: number, w?: number);
8
+ add(v: Vector4): Vector4;
9
+ subtract(v: Vector4): Vector4;
10
+ multiplyScalar(scalar: number): Vector4;
11
+ divide(v: Vector4): Vector4;
12
+ divideScalar(scalar: number): Vector4;
13
+ dot(v: Vector4): number;
14
+ lerp(v: Vector4, t: number): Vector4;
15
+ transformMatrix4(matrix: Matrix4): Vector4;
16
+ equals(v: Vector4, epsilon?: number): boolean;
17
+ toArray(): [number, number, number, number];
18
+ }
19
+ //# sourceMappingURL=Vector4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector4.d.ts","sourceRoot":"","sources":["../../../../packages/math/src/Vector4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,qBAAa,OAAO;IAEhB,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;IACV,QAAQ,CAAC,CAAC;gBAHD,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI,EACL,CAAC,SAAI;IAGhB,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAIxB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI7B,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIvC,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO;IAI3B,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIrC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM;IAIvB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;IASpC,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAI1C,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,SAAQ,GAAG,OAAO;IAI5C,OAAO,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;CAG5C"}
@@ -0,0 +1,43 @@
1
+ export class Vector4 {
2
+ x;
3
+ y;
4
+ z;
5
+ w;
6
+ constructor(x = 0, y = 0, z = 0, w = 0) {
7
+ this.x = x;
8
+ this.y = y;
9
+ this.z = z;
10
+ this.w = w;
11
+ }
12
+ add(v) {
13
+ return new Vector4(this.x + v.x, this.y + v.y, this.z + v.z, this.w + v.w);
14
+ }
15
+ subtract(v) {
16
+ return new Vector4(this.x - v.x, this.y - v.y, this.z - v.z, this.w - v.w);
17
+ }
18
+ multiplyScalar(scalar) {
19
+ return new Vector4(this.x * scalar, this.y * scalar, this.z * scalar, this.w * scalar);
20
+ }
21
+ divide(v) {
22
+ return new Vector4(this.x / v.x, this.y / v.y, this.z / v.z, this.w / v.w);
23
+ }
24
+ divideScalar(scalar) {
25
+ return new Vector4(this.x / scalar, this.y / scalar, this.z / scalar, this.w / scalar);
26
+ }
27
+ dot(v) {
28
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
29
+ }
30
+ lerp(v, t) {
31
+ return new Vector4(this.x + (v.x - this.x) * t, this.y + (v.y - this.y) * t, this.z + (v.z - this.z) * t, this.w + (v.w - this.w) * t);
32
+ }
33
+ transformMatrix4(matrix) {
34
+ return matrix.transformVector4(this);
35
+ }
36
+ equals(v, epsilon = 1e-10) {
37
+ return Math.abs(this.x - v.x) <= epsilon && Math.abs(this.y - v.y) <= epsilon && Math.abs(this.z - v.z) <= epsilon && Math.abs(this.w - v.w) <= epsilon;
38
+ }
39
+ toArray() {
40
+ return [this.x, this.y, this.z, this.w];
41
+ }
42
+ }
43
+ //# sourceMappingURL=Vector4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector4.js","sourceRoot":"","sources":["../../../../packages/math/src/Vector4.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IAEP;IACA;IACA;IACA;IAJX,YACW,IAAI,CAAC,EACL,IAAI,CAAC,EACL,IAAI,CAAC,EACL,IAAI,CAAC;QAHL,MAAC,GAAD,CAAC,CAAI;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AAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;IAC1J,CAAC;IAED,OAAO;QACL,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ export * from "./Vector2.js";
2
+ export * from "./Vector3.js";
3
+ export * from "./Vector4.js";
4
+ export * from "./Matrix3.js";
5
+ export * from "./Matrix4.js";
6
+ export * from "./Quaternion.js";
7
+ export * from "./Euler.js";
8
+ export * from "./Color.js";
9
+ export * from "./Ray.js";
10
+ export * from "./Plane.js";
11
+ export * from "./Box3.js";
12
+ export * from "./Sphere.js";
13
+ export * from "./Frustum.js";
14
+ export * from "./Transform.js";
15
+ export * from "./Interpolation.js";
16
+ export * from "./Easing.js";
17
+ export * from "./Random.js";
18
+ export * from "./Curves.js";
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/math/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ export * from "./Vector2.js";
2
+ export * from "./Vector3.js";
3
+ export * from "./Vector4.js";
4
+ export * from "./Matrix3.js";
5
+ export * from "./Matrix4.js";
6
+ export * from "./Quaternion.js";
7
+ export * from "./Euler.js";
8
+ export * from "./Color.js";
9
+ export * from "./Ray.js";
10
+ export * from "./Plane.js";
11
+ export * from "./Box3.js";
12
+ export * from "./Sphere.js";
13
+ export * from "./Frustum.js";
14
+ export * from "./Transform.js";
15
+ export * from "./Interpolation.js";
16
+ export * from "./Easing.js";
17
+ export * from "./Random.js";
18
+ export * from "./Curves.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/math/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@aura3d/math",
3
+ "version": "1.0.6",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ }
13
+ }
package/src/Box3.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { Matrix4 } from "./Matrix4.js";
2
+ import { Sphere } from "./Sphere.js";
3
+ import { Vector3 } from "./Vector3.js";
4
+
5
+ export class Box3 {
6
+ constructor(
7
+ readonly min = new Vector3(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY),
8
+ readonly max = new Vector3(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY)
9
+ ) {}
10
+
11
+ static fromPoints(points: readonly Vector3[]): Box3 {
12
+ return points.reduce((box, point) => box.expandByPoint(point), new Box3());
13
+ }
14
+
15
+ isEmpty(): boolean {
16
+ return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z;
17
+ }
18
+
19
+ expandByPoint(point: Vector3): Box3 {
20
+ return new Box3(this.min.min(point), this.max.max(point));
21
+ }
22
+
23
+ union(box: Box3): Box3 {
24
+ if (this.isEmpty()) return box;
25
+ if (box.isEmpty()) return this;
26
+ return new Box3(this.min.min(box.min), this.max.max(box.max));
27
+ }
28
+
29
+ intersectsBox(box: Box3): boolean {
30
+ if (this.isEmpty() || box.isEmpty()) return false;
31
+ return !(box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z);
32
+ }
33
+
34
+ containsPoint(point: Vector3): boolean {
35
+ return !this.isEmpty() && point.x >= this.min.x && point.x <= this.max.x && point.y >= this.min.y && point.y <= this.max.y && point.z >= this.min.z && point.z <= this.max.z;
36
+ }
37
+
38
+ getCenter(): Vector3 {
39
+ return this.isEmpty() ? Vector3.zero.clone() : this.min.add(this.max).multiplyScalar(0.5);
40
+ }
41
+
42
+ getSize(): Vector3 {
43
+ return this.isEmpty() ? Vector3.zero.clone() : this.max.subtract(this.min);
44
+ }
45
+
46
+ getBoundingSphere(): Sphere {
47
+ const center = this.getCenter();
48
+ return new Sphere(center, center.distanceTo(this.max));
49
+ }
50
+
51
+ transform(matrix: Matrix4): Box3 {
52
+ if (this.isEmpty()) return new Box3();
53
+ const corners = [
54
+ new Vector3(this.min.x, this.min.y, this.min.z),
55
+ new Vector3(this.min.x, this.min.y, this.max.z),
56
+ new Vector3(this.min.x, this.max.y, this.min.z),
57
+ new Vector3(this.min.x, this.max.y, this.max.z),
58
+ new Vector3(this.max.x, this.min.y, this.min.z),
59
+ new Vector3(this.max.x, this.min.y, this.max.z),
60
+ new Vector3(this.max.x, this.max.y, this.min.z),
61
+ new Vector3(this.max.x, this.max.y, this.max.z)
62
+ ];
63
+ return Box3.fromPoints(corners.map((corner) => matrix.transformPoint(corner)));
64
+ }
65
+ }
package/src/Color.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { clamp } from "./Interpolation.js";
2
+
3
+ export class Color {
4
+ constructor(
5
+ readonly r = 1,
6
+ readonly g = 1,
7
+ readonly b = 1,
8
+ readonly a = 1
9
+ ) {
10
+ for (const channel of [r, g, b, a]) {
11
+ if (!Number.isFinite(channel)) throw new RangeError("Color channels must be finite.");
12
+ }
13
+ }
14
+
15
+ static fromSRGB(r: number, g: number, b: number, a = 1): Color {
16
+ return new Color(srgbToLinear(r), srgbToLinear(g), srgbToLinear(b), a);
17
+ }
18
+
19
+ toSRGB(): Color {
20
+ return new Color(linearToSrgb(this.r), linearToSrgb(this.g), linearToSrgb(this.b), this.a);
21
+ }
22
+
23
+ clamp01(): Color {
24
+ return new Color(clamp(this.r), clamp(this.g), clamp(this.b), clamp(this.a));
25
+ }
26
+
27
+ lerp(to: Color, t: number): Color {
28
+ return new Color(
29
+ this.r + (to.r - this.r) * t,
30
+ this.g + (to.g - this.g) * t,
31
+ this.b + (to.b - this.b) * t,
32
+ this.a + (to.a - this.a) * t
33
+ );
34
+ }
35
+
36
+ equals(color: Color, epsilon = 1e-10): boolean {
37
+ return Math.abs(this.r - color.r) <= epsilon && Math.abs(this.g - color.g) <= epsilon && Math.abs(this.b - color.b) <= epsilon && Math.abs(this.a - color.a) <= epsilon;
38
+ }
39
+ }
40
+
41
+ export function srgbToLinear(value: number): number {
42
+ const v = clamp(value);
43
+ return v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
44
+ }
45
+
46
+ export function linearToSrgb(value: number): number {
47
+ const v = clamp(value);
48
+ return v <= 0.0031308 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
49
+ }
package/src/Curves.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { Vector3 } from "./Vector3.js";
2
+
3
+ export interface CurveSample {
4
+ readonly position: Vector3;
5
+ readonly tangent: Vector3;
6
+ }
7
+
8
+ export class CatmullRomCurve3 {
9
+ constructor(public readonly points: readonly Vector3[]) {
10
+ if (points.length < 2) throw new Error("CatmullRomCurve3 requires at least two points.");
11
+ }
12
+
13
+ getPoint(t: number): Vector3 {
14
+ const clamped = clamp01(t);
15
+ const scaled = clamped * (this.points.length - 1);
16
+ const index = Math.min(Math.floor(scaled), this.points.length - 2);
17
+ const localT = scaled - index;
18
+ const p0 = this.points[Math.max(0, index - 1)]!;
19
+ const p1 = this.points[index]!;
20
+ const p2 = this.points[index + 1]!;
21
+ const p3 = this.points[Math.min(this.points.length - 1, index + 2)]!;
22
+ return catmullRom(p0, p1, p2, p3, localT);
23
+ }
24
+
25
+ getTangent(t: number): Vector3 {
26
+ const delta = 1e-4;
27
+ const before = this.getPoint(Math.max(0, t - delta));
28
+ const after = this.getPoint(Math.min(1, t + delta));
29
+ return after.subtract(before).normalize();
30
+ }
31
+
32
+ sample(t: number): CurveSample {
33
+ return { position: this.getPoint(t), tangent: this.getTangent(t) };
34
+ }
35
+ }
36
+
37
+ export class CubicBezierCurve3 {
38
+ constructor(
39
+ public readonly p0: Vector3,
40
+ public readonly p1: Vector3,
41
+ public readonly p2: Vector3,
42
+ public readonly p3: Vector3
43
+ ) {}
44
+
45
+ getPoint(t: number): Vector3 {
46
+ const u = 1 - clamp01(t);
47
+ const tt = clamp01(t) * clamp01(t);
48
+ const uu = u * u;
49
+ const uuu = uu * u;
50
+ const ttt = tt * clamp01(t);
51
+ return this.p0.multiplyScalar(uuu)
52
+ .add(this.p1.multiplyScalar(3 * uu * clamp01(t)))
53
+ .add(this.p2.multiplyScalar(3 * u * tt))
54
+ .add(this.p3.multiplyScalar(ttt));
55
+ }
56
+
57
+ getTangent(t: number): Vector3 {
58
+ const u = 1 - clamp01(t);
59
+ return this.p1.subtract(this.p0).multiplyScalar(3 * u * u)
60
+ .add(this.p2.subtract(this.p1).multiplyScalar(6 * u * clamp01(t)))
61
+ .add(this.p3.subtract(this.p2).multiplyScalar(3 * clamp01(t) * clamp01(t)))
62
+ .normalize();
63
+ }
64
+ }
65
+
66
+ function catmullRom(p0: Vector3, p1: Vector3, p2: Vector3, p3: Vector3, t: number): Vector3 {
67
+ const t2 = t * t;
68
+ const t3 = t2 * t;
69
+ return p1.multiplyScalar(2)
70
+ .add(p2.subtract(p0).multiplyScalar(t))
71
+ .add(p0.multiplyScalar(2).subtract(p1.multiplyScalar(5)).add(p2.multiplyScalar(4)).subtract(p3).multiplyScalar(t2))
72
+ .add(p3.subtract(p0).add(p1.multiplyScalar(3).subtract(p2.multiplyScalar(3))).multiplyScalar(t3))
73
+ .multiplyScalar(0.5);
74
+ }
75
+
76
+ function clamp01(value: number): number {
77
+ if (!Number.isFinite(value)) throw new Error("Curve parameter must be finite.");
78
+ return Math.min(1, Math.max(0, value));
79
+ }
package/src/Easing.ts ADDED
@@ -0,0 +1,24 @@
1
+ export const Easing = Object.freeze({
2
+ linear(t: number): number {
3
+ assertUnit(t);
4
+ return t;
5
+ },
6
+ easeInQuad(t: number): number {
7
+ assertUnit(t);
8
+ return t * t;
9
+ },
10
+ easeOutQuad(t: number): number {
11
+ assertUnit(t);
12
+ return t * (2 - t);
13
+ },
14
+ easeInOutCubic(t: number): number {
15
+ assertUnit(t);
16
+ return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
17
+ }
18
+ });
19
+
20
+ function assertUnit(t: number): void {
21
+ if (!Number.isFinite(t) || t < 0 || t > 1) {
22
+ throw new RangeError("Easing input must be a finite value in [0, 1].");
23
+ }
24
+ }