@woosh/meep-engine 2.131.3 → 2.131.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 (26) hide show
  1. package/package.json +1 -1
  2. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  3. package/src/core/collection/queue/Deque.js +17 -12
  4. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD.d.ts +1 -0
  5. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD.d.ts.map +1 -1
  6. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD.js +1 -0
  7. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.d.ts +39 -0
  8. package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js +235 -214
  9. package/src/core/math/physics/mie/compute_lorenz_mie_optical_properties.d.ts.map +1 -1
  10. package/src/core/math/physics/mie/compute_lorenz_mie_optical_properties.js +3 -342
  11. package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.js +1 -1
  12. package/src/core/math/physics/mie/compute_mie_phase.d.ts +16 -0
  13. package/src/core/math/physics/mie/compute_mie_phase.d.ts.map +1 -0
  14. package/src/core/math/physics/mie/compute_mie_phase.js +84 -0
  15. package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts +28 -0
  16. package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts.map +1 -0
  17. package/src/core/math/physics/mie/lorenz_mie_coefs.js +232 -0
  18. package/src/core/math/physics/mie/mie_ab_to_optical_properties.d.ts +14 -0
  19. package/src/core/math/physics/mie/mie_ab_to_optical_properties.d.ts.map +1 -0
  20. package/src/core/math/physics/mie/mie_ab_to_optical_properties.js +109 -0
  21. package/src/core/model/node-graph/node/NodeInstance.d.ts +2 -0
  22. package/src/core/model/node-graph/node/NodeInstance.d.ts.map +1 -1
  23. package/src/core/model/node-graph/node/NodeInstance.js +11 -5
  24. package/src/engine/animation/curve/AnimationCurve.d.ts +18 -3
  25. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  26. package/src/engine/animation/curve/AnimationCurve.js +69 -36
@@ -1,5 +1,4 @@
1
1
  import { assert } from "../../../core/assert.js";
2
- import { binarySearchHighIndex } from "../../../core/collection/array/binarySearchHighIndex.js";
3
2
  import { computeHashArray } from "../../../core/collection/array/computeHashArray.js";
4
3
  import { isArrayEqual } from "../../../core/collection/array/isArrayEqual.js";
5
4
  import { lerp } from "../../../core/math/lerp.js";
@@ -9,16 +8,6 @@ import { invokeObjectToJSON } from "../../../core/model/object/invokeObjectToJSO
9
8
  import { evaluate_two_key_curve } from "./evaluate_two_key_curve.js";
10
9
  import { Keyframe } from "./Keyframe.js";
11
10
 
12
- /**
13
- *
14
- * @param {number} time
15
- * @param {Keyframe} keyframe
16
- * @return {number}
17
- */
18
- function compareKeyframeToTime(time, keyframe) {
19
- return time - keyframe.time;
20
- }
21
-
22
11
  /**
23
12
  * Describes change of a numeric value over time.
24
13
  * Values are stored in {@link Keyframe}s, interpolation is defined by tangents on {@link Keyframe}s.
@@ -33,6 +22,13 @@ function compareKeyframeToTime(time, keyframe) {
33
22
  *
34
23
  * jump_curve.evaluate(0.1); // what is the height at time 0.1?
35
24
  *
25
+ * @example
26
+ * const curve = AnimationCurve.easeInOut();
27
+ *
28
+ * sprite.transparency = curve.evaluate(time); // smoothly animate transparency of the sprite
29
+ *
30
+ * @implements Iterable<Keyframe>
31
+ *
36
32
  * @author Alex Goldring
37
33
  * @copyright Company Named Limited (c) 2025
38
34
  */
@@ -61,6 +57,8 @@ export class AnimationCurve {
61
57
  const key_count = keys.length;
62
58
  const last_key_index = key_count - 1;
63
59
 
60
+ // Optimization: if the curve is empty or the new key is chronologically
61
+ // after the last key, we can simply push it to the end.
64
62
  if (
65
63
  last_key_index < 0
66
64
  || keys[last_key_index].time <= key.time
@@ -71,17 +69,21 @@ export class AnimationCurve {
71
69
 
72
70
  return key_count;
73
71
 
74
- } else {
72
+ } else if (key_count > 0 && keys[0].time > key.time) {
75
73
 
76
- // figure out the right place to insert the key
77
- // TODO make use of this.getKeyIndexByTime instead
78
- const i = binarySearchHighIndex(keys, key.time, compareKeyframeToTime, 0, last_key_index);
74
+ keys.unshift(key);
79
75
 
80
- // insert key at the right place
81
- keys.splice(i, 0, key);
82
-
83
- return i;
76
+ return 0;
84
77
  }
78
+
79
+ // figure out the right place to insert the key
80
+ const i = this.getKeyIndexLow(key.time) + 1;
81
+
82
+ // insert key at the right place
83
+ keys.splice(i, 0, key);
84
+
85
+ return i;
86
+
85
87
  }
86
88
 
87
89
  /**
@@ -101,7 +103,7 @@ export class AnimationCurve {
101
103
  /**
102
104
  *
103
105
  * @param {Keyframe} key
104
- * @returns {boolean}
106
+ * @returns {boolean} true if the key was removed, false if the key was not found
105
107
  */
106
108
  remove(key) {
107
109
  const i = this.keys.indexOf(key);
@@ -196,21 +198,37 @@ export class AnimationCurve {
196
198
 
197
199
  /**
198
200
  * Returns index of a key that is just before or at the time specified.
201
+ * Useful for insertion and evaluation logic.
202
+ * Note: if time is past the end of last key - index of the last key will be returned instead
199
203
  * @param {number} time
200
204
  * @returns {number} index of the key
201
205
  */
202
- getKeyIndexByTime(time) {
206
+ getKeyIndexLow(time) {
207
+ assert.isNumber(time, 'time');
208
+ assert.notNaN(time, 'time');
209
+
203
210
  const keys = this.keys;
204
211
  const key_count = keys.length;
205
212
 
206
- let i0 = 0;
207
- let i1 = key_count - 1;
213
+ if (key_count === 0) {
214
+ // no keys
215
+ return 0;
216
+ }
208
217
 
209
218
  if (time <= keys[0].time) {
210
219
  // before start
211
220
  return 0;
212
221
  }
213
222
 
223
+ if (time >= keys[key_count - 1].time) {
224
+ // after the end
225
+ return key_count - 1;
226
+ }
227
+
228
+ let found_index = 0;
229
+ let i0 = 0;
230
+ let i1 = key_count - 1;
231
+
214
232
  // binary search
215
233
  while (i0 <= i1) {
216
234
  const pivot = (i0 + i1) >>> 1;
@@ -218,27 +236,22 @@ export class AnimationCurve {
218
236
  const key = keys[pivot];
219
237
  const key_time = key.time;
220
238
 
221
- if (key_time < time) {
239
+ if (key_time <= time) {
240
+ found_index = pivot;
222
241
  i0 = pivot + 1;
223
242
  } else if (key_time > time) {
224
243
  i1 = pivot - 1;
225
- } else {
226
- i0 = pivot;
227
- break;
228
244
  }
229
245
  }
230
246
 
231
- if (i0 > i1) {
232
- // swap
233
- i0 = i1;
234
- }
247
+ assert.lessThanOrEqual(keys[found_index].time, time, 'keys[found_index].time >= time');
235
248
 
236
249
  // fast-forward to last matching frame if there are multiple matches
237
- while (i0 + 1 < key_count - 1 && keys[i0 + 1].time === time) {
238
- i0++;
250
+ while (found_index + 2 < key_count && keys[found_index + 1].time === time) {
251
+ found_index++;
239
252
  }
240
253
 
241
- return i0;
254
+ return found_index;
242
255
  }
243
256
 
244
257
  /**
@@ -262,7 +275,7 @@ export class AnimationCurve {
262
275
  return keys[0].value;
263
276
  }
264
277
 
265
- const i = this.getKeyIndexByTime(time);
278
+ const i = this.getKeyIndexLow(time);
266
279
 
267
280
  if (i >= key_count - 1) {
268
281
  // past last keyframe
@@ -400,12 +413,25 @@ export class AnimationCurve {
400
413
 
401
414
  keyframe.fromJSON(keys[i]);
402
415
 
416
+ // The 'add' sorts the keys incrementally, we can do this faster if we assume the input is already sorted.
417
+ // But to be safe we don't make that assumption
418
+
403
419
  this.add(keyframe);
404
420
 
405
421
  }
406
422
 
407
423
  }
408
424
 
425
+ * [Symbol.iterator]() {
426
+
427
+ for (const key of this.keys) {
428
+
429
+ yield key;
430
+
431
+ }
432
+
433
+ }
434
+
409
435
  /**
410
436
  * Utility constructor
411
437
  * @param {Keyframe[]} keys
@@ -422,6 +448,7 @@ export class AnimationCurve {
422
448
  /**
423
449
  * S-shaped curve that starts slowly, ramps up and flattens out again.
424
450
  * Useful for pleasing transitions where exit and entry should not be abrupt.
451
+ *
425
452
  * @param {number} [timeStart]
426
453
  * @param {number} [valueStart]
427
454
  * @param {number} [timeEnd]
@@ -482,4 +509,10 @@ export class AnimationCurve {
482
509
  * @readonly
483
510
  * @type {boolean}
484
511
  */
485
- AnimationCurve.prototype.isAnimationCurve = true;
512
+ AnimationCurve.prototype.isAnimationCurve = true;
513
+
514
+
515
+ /**
516
+ * @deprecated use `getKeyIndexLow` instead
517
+ */
518
+ AnimationCurve.prototype.getKeyIndexByTime = AnimationCurve.prototype.getKeyIndexLow;