@woosh/meep-engine 2.126.64 → 2.126.65

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.126.64",
8
+ "version": "2.126.65",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -19,7 +19,7 @@ export function spline3_hermite(t, p0, p1, m0, m1) {
19
19
  const a = 2 * t3 - 3 * t2 + 1;
20
20
  const b = t3 - 2 * t2 + t;
21
21
  const c = t3 - t2;
22
- const d = -2 * t3 + 3 * t2;
22
+ const d = 3 * t2 - 2 * t3;
23
23
 
24
24
  return a * p0 + b * m0 + c * m1 + d * p1;
25
25
  }
@@ -120,7 +120,7 @@ export class Keyframe {
120
120
  */
121
121
  hash() {
122
122
  return computeHashFloat(this.time)
123
- ^ computeHashFloat(this.value);
123
+ ^ (computeHashFloat(this.value) * 31);
124
124
  }
125
125
 
126
126
  toJSON() {
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Subdivide a curve segment by introducing a new keyframe at a given normalized time.
3
+ * Subdivision does not alter the curve shape in any way, it is intended primarily for editing purposes.
4
+ * @param {Keyframe} out keyframe to be added at the point of subdivision, its tangents, time and value will be overwritten
5
+ * @param {Keyframe} key0
6
+ * @param {Keyframe} key1
7
+ * @param {number} t normalized time in [0..1] between key0 and key1 where new frame is to be inserted
8
+ * @returns {Keyframe} `out`, for convenience
9
+ * @see AnimationCurve
10
+ * @example
11
+ * const new_frame = animation_curve_subdivide(new Keyframe(), key0, key1, 0.5);
12
+ * curve.add(new_frame);
13
+ */
14
+ export function animation_curve_subdivide(out: Keyframe, key0: Keyframe, key1: Keyframe, t: number): Keyframe;
15
+ //# sourceMappingURL=animation_curve_subdivide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation_curve_subdivide.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/animation_curve_subdivide.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,+CAVW,QAAQ,QACR,QAAQ,QACR,QAAQ,KACR,MAAM,GACJ,QAAQ,CA2CpB"}
@@ -0,0 +1,55 @@
1
+ import { lerp } from "../../../core/math/lerp.js";
2
+ import { spline3_hermite } from "../../../core/math/spline/spline3_hermite.js";
3
+ import { spline3_hermite_derivative } from "../../../core/math/spline/spline3_hermite_derivative.js";
4
+
5
+ /**
6
+ * Subdivide a curve segment by introducing a new keyframe at a given normalized time.
7
+ * Subdivision does not alter the curve shape in any way, it is intended primarily for editing purposes.
8
+ * @param {Keyframe} out keyframe to be added at the point of subdivision, its tangents, time and value will be overwritten
9
+ * @param {Keyframe} key0
10
+ * @param {Keyframe} key1
11
+ * @param {number} t normalized time in [0..1] between key0 and key1 where new frame is to be inserted
12
+ * @returns {Keyframe} `out`, for convenience
13
+ * @see AnimationCurve
14
+ * @example
15
+ * const new_frame = animation_curve_subdivide(new Keyframe(), key0, key1, 0.5);
16
+ * curve.add(new_frame);
17
+ */
18
+ export function animation_curve_subdivide(
19
+ out,
20
+ key0,
21
+ key1,
22
+ t
23
+ ) {
24
+
25
+ const v0 = key0.value;
26
+ const v1 = key1.value;
27
+
28
+ const time_span = key1.time - key0.time;
29
+
30
+ // Note that Keyframe tangents are normalized, so we denomalize them before using them
31
+ const m0 = key0.outTangent * time_span;
32
+ const m1 = key1.inTangent * time_span;
33
+
34
+ const xm = spline3_hermite(
35
+ t,
36
+ v0, v1,
37
+ m0, m1
38
+ );
39
+ const vm = spline3_hermite_derivative(
40
+ t,
41
+ v0, v1,
42
+ m0, m1
43
+ );
44
+
45
+ out.time = lerp(key0.time, key1.time, t);
46
+ out.value = xm;
47
+
48
+ // re-normalize tangent
49
+ const new_tangent = vm / time_span;
50
+
51
+ out.inTangent = new_tangent;
52
+ out.outTangent = new_tangent;
53
+
54
+ return out;
55
+ }