physics-animator 0.11.0 → 0.13.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.
@@ -45,17 +45,17 @@ exports.SpringAnimator = {
45
45
  var Spring;
46
46
  (function (Spring) {
47
47
  /**
48
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
48
+ * Exponential decay without any bounce
49
49
  *
50
- * `damping = 3.356694 / approxHalfLife_s`
51
- *
52
- * `strength = damping * damping / 4`
50
+ * Control with either duration_s or halfLife_s
53
51
  */
54
52
  function Exponential(options) {
55
53
  // found numerically
56
54
  const halfLifeConstant = 3.356694; // from solve (1+u)*exp(-u)=0.5 for u, and constant = 2u
57
55
  const pointOnePercentConstant = 18.46682; // from solve (1+u)*exp(-u)=0.001 for u, and constant = 2u
58
- const damping = pointOnePercentConstant / options.duration_s;
56
+ const damping = ('halfLife_s' in options)
57
+ ? halfLifeConstant / options.halfLife_s
58
+ : pointOnePercentConstant / options.duration_s;
59
59
  let strength = damping * damping / 4;
60
60
  return { damping, strength };
61
61
  }
@@ -42,17 +42,17 @@ export const SpringAnimator = {
42
42
  export var Spring;
43
43
  (function (Spring) {
44
44
  /**
45
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
45
+ * Exponential decay without any bounce
46
46
  *
47
- * `damping = 3.356694 / approxHalfLife_s`
48
- *
49
- * `strength = damping * damping / 4`
47
+ * Control with either duration_s or halfLife_s
50
48
  */
51
49
  function Exponential(options) {
52
50
  // found numerically
53
51
  const halfLifeConstant = 3.356694; // from solve (1+u)*exp(-u)=0.5 for u, and constant = 2u
54
52
  const pointOnePercentConstant = 18.46682; // from solve (1+u)*exp(-u)=0.001 for u, and constant = 2u
55
- const damping = pointOnePercentConstant / options.duration_s;
53
+ const damping = ('halfLife_s' in options)
54
+ ? halfLifeConstant / options.halfLife_s
55
+ : pointOnePercentConstant / options.duration_s;
56
56
  let strength = damping * damping / 4;
57
57
  return { damping, strength };
58
58
  }
@@ -44,14 +44,14 @@ export declare class Animator {
44
44
  protected beforeChange: EventSignal<void, void>;
45
45
  protected afterChange: EventSignal<void, void>;
46
46
  constructor(onBeforeStep?: (dt_s: number) => void, onAfterStep?: (dt_s: number) => void);
47
- setTo<Obj>(object: Obj, target: Partial<Obj>): void;
48
- animateTo<Obj, Parameters, State, FieldType>(object: Obj, target: Partial<Obj>, animator?: IFieldAnimator<Parameters, State, FieldType>, params?: Parameters | null): void;
49
- springTo<Obj>(object: Obj, target: Partial<Obj>, params: SpringParameters | null): void;
50
- customTweenTo<Obj>(object: Obj, target: Partial<Obj>, duration_s: number, easingFn: EasingStepFn): void;
51
- linearTo<Obj>(object: Obj, target: Partial<Obj>, duration_s: number): void;
52
- easeInOutTo<Obj>(object: Obj, target: Partial<Obj>, duration_s: number): void;
53
- easeInTo<Obj>(object: Obj, target: Partial<Obj>, duration_s: number): void;
54
- easeOutTo<Obj>(object: Obj, target: Partial<Obj>, duration_s: number): void;
47
+ setTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>): void;
48
+ animateTo<Obj extends Record<string, any>, Parameters, State, FieldType>(object: Obj, target: Partial<Obj>, animator?: IFieldAnimator<Parameters, State, FieldType>, params?: Parameters | null): void;
49
+ springTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, params: SpringParameters | null): void;
50
+ customTweenTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, duration_s: number, easingFn: EasingStepFn): void;
51
+ linearTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, duration_s: number): void;
52
+ easeInOutTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, duration_s: number): void;
53
+ easeInTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, duration_s: number): void;
54
+ easeOutTo<Obj extends Record<string, any>>(object: Obj, target: Partial<Obj>, duration_s: number): void;
55
55
  onCompleteField<Obj, Name extends keyof Obj>(object: Obj, field: Name, callback: (object: Obj, field: Name) => void, once?: 'once'): {
56
56
  priority: number;
57
57
  listener: (event: {
@@ -8,6 +8,8 @@ export declare const SpringAnimator: IFieldAnimator<SpringParameters, SpringStat
8
8
  type ExponentialParameters = {
9
9
  /** Defined as the point in time we'll reach within 0.01% of target from 0 velocity start */
10
10
  duration_s: number;
11
+ } | {
12
+ halfLife_s: number;
11
13
  };
12
14
  type UnderdampedParameters = {
13
15
  /** Defined as the point in time we'll reach within 0.01% of target from 0 velocity start */
@@ -31,11 +33,9 @@ export declare namespace Spring {
31
33
  damping: number;
32
34
  };
33
35
  /**
34
- * Starting with 0 velocity, this parameter describes how long it would take to reach half-way to the target
36
+ * Exponential decay without any bounce
35
37
  *
36
- * `damping = 3.356694 / approxHalfLife_s`
37
- *
38
- * `strength = damping * damping / 4`
38
+ * Control with either duration_s or halfLife_s
39
39
  */
40
40
  function Exponential(options: ExponentialParameters): PhysicsParameters;
41
41
  function Underdamped(options: UnderdampedParameters): PhysicsParameters;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "physics-animator",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "author": "haxiomic (George Corney)",
5
5
  "license": "MIT",
6
6
  "description": "A TypeScript animation system grounded in physics with three.js and react support.",