@woosh/meep-engine 2.124.10 → 2.124.11

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.124.10",
8
+ "version": "2.124.11",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -7,6 +7,9 @@
7
7
  * @param {number} m0 first tangent (tangent exiting from first value)
8
8
  * @param {number} m1 second tangent (tangent entering into second value)
9
9
  * @return {number}
10
+ *
11
+ * @author Alex Goldring
12
+ * @copyright Company Named Limited (c) 2025
10
13
  */
11
14
  export function spline_hermite3(t: number, p0: number, p1: number, m0: number, m1: number): number;
12
15
  //# sourceMappingURL=spline_hermite3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spline_hermite3.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline_hermite3.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,mCAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAajB"}
1
+ {"version":3,"file":"spline_hermite3.d.ts","sourceRoot":"","sources":["../../../../../src/core/math/spline/spline_hermite3.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,mCAVW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAgBjB"}
@@ -7,6 +7,9 @@
7
7
  * @param {number} m0 first tangent (tangent exiting from first value)
8
8
  * @param {number} m1 second tangent (tangent entering into second value)
9
9
  * @return {number}
10
+ *
11
+ * @author Alex Goldring
12
+ * @copyright Company Named Limited (c) 2025
10
13
  */
11
14
  export function spline_hermite3(t, p0, p1, m0, m1) {
12
15
 
@@ -1,6 +1,10 @@
1
1
  /**
2
- * Describes change of a numeric value over time. Values are stored in {@link Keyframe}s, interpolation is defined by tangents on keyframes
3
- * Inspired by unity's AnimationCurve, see https://docs.unity3d.com/ScriptReference/AnimationCurve.html
2
+ * Describes change of a numeric value over time.
3
+ * Values are stored in {@link Keyframe}s, interpolation is defined by tangents on {@link Keyframe}s.
4
+ * The curve is a cubic Hermite spline, see https://en.wikipedia.org/wiki/Cubic_Hermite_spline.
5
+ *
6
+ * @author Alex Goldring
7
+ * @copyright Company Named Limited (c) 2025
4
8
  */
5
9
  export class AnimationCurve {
6
10
  /**
@@ -81,6 +85,12 @@ export class AnimationCurve {
81
85
  * @returns {number}
82
86
  */
83
87
  get duration(): number;
88
+ /**
89
+ * Returns index of a key that is just before or at the time specified.
90
+ * @param {number} time
91
+ * @returns {number} index of the key
92
+ */
93
+ getKeyIndexByTime(time: number): number;
84
94
  /**
85
95
  *
86
96
  * @param {number} time time in seconds
@@ -1 +1 @@
1
- {"version":3,"file":"AnimationCurve.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/AnimationCurve.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH;IAkFI;;;;OAIG;IACH,kBAHW,QAAQ,EAAE,GACR,cAAc,CAQ1B;IA0ND;;;;;;;OAOG;IACH,6BANW,MAAM,eACN,MAAM,YACN,MAAM,aACN,MAAM,GACL,cAAc,CAUzB;IAED;;;;;;OAMG;IACH,4BALW,MAAM,YACN,MAAM,UACN,MAAM,GACL,cAAc,CAOzB;IAED;;;;;;;OAOG;IACH,0BANW,MAAM,eACN,MAAM,YACN,MAAM,aACN,MAAM,GACL,cAAc,CAYzB;IAxWD;;;OAGG;IACH,eAFU,QAAQ,EAAE,CAEV;IAEV;;;;OAIG;IACH,SAHW,QAAQ,GACN,MAAM,CAgClB;IAED;;;OAGG;IACH,cAFW,QAAQ,EAAE,QAUpB;IAED;;;;OAIG;IACH,YAHW,QAAQ,GACN,OAAO,CAYnB;IAED;;OAEG;IACH,cAEC;IAeD;;;OAGG;IACH,cAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAYlB;IAED;;;OAGG;IACH,gBAFY,MAAM,CAYjB;IAED;;;OAGG;IACH,gBAFa,MAAM,CAelB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACL,MAAM,CAiCjB;IAED;;;;OAIG;IACH,qBAFW,MAAM,QA+BhB;IAED;;;;OAIG;IACH,sBAHW,MAAM,UACN,MAAM,QAWhB;IAED,0BAKC;IAED;;;;OAIG;IACH,cAHW,cAAc,GACb,OAAO,CAIlB;IAED;;;OAGG;IACH,YAFW,cAAc,QAIxB;IAED;;;OAGG;IACH,SAFY,cAAc,CAQzB;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;MAIC;IAED;;aAeC;CAqDJ;yBA1XwB,eAAe"}
1
+ {"version":3,"file":"AnimationCurve.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/AnimationCurve.js"],"names":[],"mappings":"AAqBA;;;;;;;GAOG;AACH;IAkFI;;;;OAIG;IACH,kBAHW,QAAQ,EAAE,GACR,cAAc,CAQ1B;IAgRD;;;;;;;OAOG;IACH,6BANW,MAAM,eACN,MAAM,YACN,MAAM,aACN,MAAM,GACL,cAAc,CAUzB;IAED;;;;;;OAMG;IACH,4BALW,MAAM,YACN,MAAM,UACN,MAAM,GACL,cAAc,CAOzB;IAED;;;;;;;OAOG;IACH,0BANW,MAAM,eACN,MAAM,YACN,MAAM,aACN,MAAM,GACL,cAAc,CAYzB;IA9ZD;;;OAGG;IACH,eAFU,QAAQ,EAAE,CAEV;IAEV;;;;OAIG;IACH,SAHW,QAAQ,GACN,MAAM,CAgClB;IAED;;;OAGG;IACH,cAFW,QAAQ,EAAE,QAUpB;IAED;;;;OAIG;IACH,YAHW,QAAQ,GACN,OAAO,CAYnB;IAED;;OAEG;IACH,cAEC;IAeD;;;OAGG;IACH,cAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,kBAFa,MAAM,CAYlB;IAED;;;OAGG;IACH,gBAFY,MAAM,CAYjB;IAED;;;OAGG;IACH,gBAFa,MAAM,CAelB;IAED;;;;OAIG;IACH,wBAHW,MAAM,GACJ,MAAM,CA0ClB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACL,MAAM,CAoCjB;IAED;;;;OAIG;IACH,qBAFW,MAAM,QAmChB;IAED;;;;OAIG;IACH,sBAHW,MAAM,UACN,MAAM,QAWhB;IAED,0BAKC;IAED;;;;OAIG;IACH,cAHW,cAAc,GACb,OAAO,CAIlB;IAED;;;OAGG;IACH,YAFW,cAAc,QAIxB;IAED;;;OAGG;IACH,SAFY,cAAc,CAQzB;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;MAIC;IAED;;aAeC;CAqDJ;yBApbwB,eAAe"}
@@ -20,8 +20,12 @@ function compareKeyframeToTime(time, keyframe) {
20
20
  }
21
21
 
22
22
  /**
23
- * Describes change of a numeric value over time. Values are stored in {@link Keyframe}s, interpolation is defined by tangents on keyframes
24
- * Inspired by unity's AnimationCurve, see https://docs.unity3d.com/ScriptReference/AnimationCurve.html
23
+ * Describes change of a numeric value over time.
24
+ * Values are stored in {@link Keyframe}s, interpolation is defined by tangents on {@link Keyframe}s.
25
+ * The curve is a cubic Hermite spline, see https://en.wikipedia.org/wiki/Cubic_Hermite_spline.
26
+ *
27
+ * @author Alex Goldring
28
+ * @copyright Company Named Limited (c) 2025
25
29
  */
26
30
  export class AnimationCurve {
27
31
  /**
@@ -177,6 +181,53 @@ export class AnimationCurve {
177
181
  return last.time - first.time;
178
182
  }
179
183
 
184
+ /**
185
+ * Returns index of a key that is just before or at the time specified.
186
+ * @param {number} time
187
+ * @returns {number} index of the key
188
+ */
189
+ getKeyIndexByTime(time) {
190
+ const keys = this.keys;
191
+ const key_count = keys.length;
192
+
193
+ let i0 = 0;
194
+ let i1 = key_count - 1;
195
+
196
+ if (time <= keys[0].time) {
197
+ // before start
198
+ return 0;
199
+ }
200
+
201
+ // binary search
202
+ while (i0 <= i1) {
203
+ const pivot = (i0 + i1) >>> 1;
204
+
205
+ const key = keys[pivot];
206
+ const key_time = key.time;
207
+
208
+ if (key_time < time) {
209
+ i0 = pivot + 1;
210
+ } else if (key_time > time) {
211
+ i1 = pivot - 1;
212
+ } else {
213
+ i0 = pivot;
214
+ break;
215
+ }
216
+ }
217
+
218
+ if (i0 > i1) {
219
+ // swap
220
+ i0 = i1;
221
+ }
222
+
223
+ // fast-forward to last matching frame if there are multiple matches
224
+ while (i0 + 1 < key_count - 1 && keys[i0 + 1].time === time) {
225
+ i0++;
226
+ }
227
+
228
+ return i0;
229
+ }
230
+
180
231
  /**
181
232
  *
182
233
  * @param {number} time time in seconds
@@ -189,30 +240,33 @@ export class AnimationCurve {
189
240
  const key_count = keys.length;
190
241
 
191
242
  if (key_count === 0) {
243
+ // no keys, produce arbitrary value
192
244
  return 0;
193
245
  }
194
246
 
195
247
  if (key_count === 1) {
248
+ // only have one key
196
249
  return keys[0].value;
197
250
  }
198
251
 
199
- if (time <= keys[0].time) {
200
- // before start
201
- return keys[0].value;
202
- }
252
+ const i = this.getKeyIndexByTime(time);
203
253
 
204
- for (let i = 1; i < key_count; i++) {
205
- const keyframe1 = keys[i];
254
+ if (i >= key_count - 1) {
255
+ // past last keyframe
256
+ return keys[key_count - 1].value;
257
+ }
206
258
 
207
- if (time < keyframe1.time) {
208
- const keyframe0 = keys[i - 1];
259
+ const keyframe0 = keys[i];
209
260
 
210
- return evaluate_two_key_curve(time, keyframe0, keyframe1);
211
- }
261
+ if (keyframe0.time >= time) {
262
+ // on or past the keyframe
263
+ return keyframe0.value;
212
264
  }
213
265
 
214
- // past end
215
- return keys[key_count - 1].value;
266
+ const keyframe1 = keys[i + 1];
267
+
268
+ return evaluate_two_key_curve(time, keyframe0, keyframe1);
269
+
216
270
  }
217
271
 
218
272
  /**
@@ -230,6 +284,11 @@ export class AnimationCurve {
230
284
  const key_main = keys[index];
231
285
 
232
286
  const has_previous = index > 0;
287
+
288
+ const has_next = index < last_index;
289
+
290
+ // TODO check out https://github.com/MonoGame/MonoGame/blob/f6ce4cbbe3ca5a93f0d1926f58ed501217a04069/MonoGame.Framework/Curve.cs#L232
291
+
233
292
  if (has_previous) {
234
293
  const key_previous = keys[index - 1];
235
294
 
@@ -239,7 +298,6 @@ export class AnimationCurve {
239
298
  key_main.inTangent = value_span / time_span;
240
299
  }
241
300
 
242
- const has_next = index < last_index;
243
301
 
244
302
  if (has_next) {
245
303
  const key_next = keys[index + 1];
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * Single keyframe of {@link AnimationCurve}
3
+ *
4
+ * @author Alex Goldring
5
+ * @copyright Company Named Limited (c) 2025
3
6
  */
4
7
  export class Keyframe {
5
8
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Keyframe.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/Keyframe.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAyBI;;;;;;;OAOG;IACH,kBANW,MAAM,SACN,MAAM,cACN,MAAM,eACN,MAAM,GACL,QAAQ,CAQnB;IAtCD;;;OAGG;IACH,OAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;OAGG;IACH,YAFU,MAAM,CAED;IAkBf;;;;;;OAMG;IACH,UALW,MAAM,SACN,MAAM,aACN,MAAM,cACN,MAAM,QAmBhB;IAED;;;;OAIG;IACH,cAHW,QAAQ,GACN,OAAO,CAQnB;IAED;;;OAGG;IACH,YAFW,QAAQ,QAOlB;IAED;;;OAGG;IACH,SAFY,QAAQ,CAQnB;IAED;;;OAGG;IACH,QAFY,MAAM,CAKjB;IAED;;;;;MAOC;IAED;;;;;aAQC;IAIL;;;;OAIG;IACH,qBAFU,OAAO,CAEY;CAP5B"}
1
+ {"version":3,"file":"Keyframe.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/Keyframe.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH;IAyBI;;;;;;;OAOG;IACH,kBANW,MAAM,SACN,MAAM,cACN,MAAM,eACN,MAAM,GACL,QAAQ,CAQnB;IAtCD;;;OAGG;IACH,OAFU,MAAM,CAEN;IAEV;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,WAFU,MAAM,CAEF;IAEd;;;OAGG;IACH,YAFU,MAAM,CAED;IAkBf;;;;;;OAMG;IACH,UALW,MAAM,SACN,MAAM,aACN,MAAM,cACN,MAAM,QAmBhB;IAED;;;;OAIG;IACH,cAHW,QAAQ,GACN,OAAO,CAQnB;IAED;;;OAGG;IACH,YAFW,QAAQ,QAOlB;IAED;;;OAGG;IACH,SAFY,QAAQ,CAQnB;IAED;;;OAGG;IACH,QAFY,MAAM,CAKjB;IAED;;;;;MAOC;IAED;;;;;aAQC;IAIL;;;;OAIG;IACH,qBAFU,OAAO,CAEY;CAP5B"}
@@ -3,6 +3,9 @@ import { computeHashFloat } from "../../../core/primitives/numbers/computeHashFl
3
3
 
4
4
  /**
5
5
  * Single keyframe of {@link AnimationCurve}
6
+ *
7
+ * @author Alex Goldring
8
+ * @copyright Company Named Limited (c) 2025
6
9
  */
7
10
  export class Keyframe {
8
11
  /**
@@ -3,6 +3,9 @@
3
3
  * Intended to reduce complexity of a curve to improve performance and lower memory usage
4
4
  * @param {AnimationCurve} curve
5
5
  * @param {number} [error_tolerance] how much of a loss to accept, this is relative to normalized value bounds of the curve
6
+ *
7
+ * @author Alex Goldring
8
+ * @copyright Company Named Limited (c) 2025
6
9
  */
7
10
  export function animation_curve_optimize(curve: AnimationCurve, error_tolerance?: number): void;
8
11
  //# sourceMappingURL=animation_curve_optimize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"animation_curve_optimize.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/animation_curve_optimize.js"],"names":[],"mappings":"AA0CA;;;;;GAKG;AACH,gDAHW,cAAc,oBACd,MAAM,QA0ChB"}
1
+ {"version":3,"file":"animation_curve_optimize.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/curve/animation_curve_optimize.js"],"names":[],"mappings":"AAkDA;;;;;;;;GAQG;AACH,gDANW,cAAc,oBACd,MAAM,QA6ChB"}
@@ -12,9 +12,17 @@ const NORMALIZED_CHECK_DISTANCE = 0.07;
12
12
  * @param {Keyframe} key_middle
13
13
  * @param {Keyframe} key_previous
14
14
  * @param {Keyframe} key_next
15
- * @return {number} value delta if the middle frame is removed
15
+ * @return {number} value delta if the middle frame is removed, the higher this value - the more important the middle keyframe is
16
+ *
17
+ * @author Alex Goldring
18
+ * @copyright Company Named Limited (c) 2025
16
19
  */
17
- function compute_keyframe_value_effect(key_middle, key_previous, key_next) {
20
+ function compute_keyframe_value_effect(
21
+ key_middle,
22
+ key_previous,
23
+ key_next
24
+ ) {
25
+
18
26
  // check if this key contributes to the shape
19
27
  const v1_actual = evaluate_two_key_curve(key_middle.time, key_previous, key_next);
20
28
  const v1_expected = key_middle.value;
@@ -45,6 +53,9 @@ function compute_keyframe_value_effect(key_middle, key_previous, key_next) {
45
53
  * Intended to reduce complexity of a curve to improve performance and lower memory usage
46
54
  * @param {AnimationCurve} curve
47
55
  * @param {number} [error_tolerance] how much of a loss to accept, this is relative to normalized value bounds of the curve
56
+ *
57
+ * @author Alex Goldring
58
+ * @copyright Company Named Limited (c) 2025
48
59
  */
49
60
  export function animation_curve_optimize(curve, error_tolerance = 1e-3) {
50
61
  assert.lessThan(error_tolerance, 1, 'error_tolerance must be less than 1');