@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.23b1e20 → 2.26.0-pr.feature-update-to-react-19.361.c3fd41e

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.
@@ -1,48 +1,34 @@
1
1
  /**
2
- * Smooth value interpolation utility for animating between values
3
- * even with rapid updates. Uses THREE.MathUtils.lerp for optimized interpolation.
2
+ * Smooth value interpolation utility using spring physics with tension and friction.
3
+ * Designed for React Three Fiber applications with smooth, natural animations.
4
4
  *
5
- * Follows React Three Fiber best practices:
6
- * - Uses frame deltas for refresh-rate independence
7
- * - Avoids object creation in animation loops
8
- * - Direct mutation for performance
5
+ * Features:
6
+ * - Spring physics with configurable tension and friction
7
+ * - Frame-rate independent using delta timing
8
+ * - Handles irregular frame timing and rapid target updates
9
9
  * - Manual update() calls for useFrame integration (no automatic RAF loop)
10
- *
11
- * Note: When using with useFrame(), call update(delta) manually.
12
- * For standalone usage, call startAutoInterpolation() to begin automatic updates.
10
+ * - Direct mutation for performance
13
11
  *
14
12
  * @example
15
13
  * ```tsx
16
- * // Basic usage with spring-like animation (similar to react-spring)
14
+ * // Basic spring animation
17
15
  * const interpolator = new ValueInterpolator([0, 0, 0], {
18
- * alpha: 0.1, // Interpolation alpha (0-1, frame-rate independent)
19
- * easing: 'spring', // Spring-like animation with slight overshoot
16
+ * tension: 120, // Higher = faster, stiffer spring (default: 120)
17
+ * friction: 20, // Higher = more damping, less oscillation (default: 20)
20
18
  * onChange: (values) => {
21
- * // Update your objects with interpolated values
22
19
  * robot.joints.forEach((joint, i) => {
23
20
  * joint.rotation.y = values[i]
24
21
  * })
25
22
  * }
26
23
  * })
27
24
  *
28
- * // Different easing options:
29
- * // 'linear' - smooth linear interpolation
30
- * // 'spring' - spring-like with overshoot (similar to react-spring)
31
- * // 'easeOut' - smooth deceleration
32
- * // 'easeInOut' - smooth acceleration and deceleration
33
- *
34
- * // Set new target values
35
25
  * interpolator.setTarget([1.5, -0.8, 2.1])
36
26
  *
37
- * // React hook usage with useFrame
27
+ * // React Three Fiber usage
38
28
  * function MyComponent() {
39
- * const [interpolator] = useInterpolation([0, 0, 0], {
40
- * alpha: 0.1,
41
- * easing: 'spring'
42
- * })
29
+ * const [interpolator] = useInterpolation([0, 0, 0])
43
30
  *
44
31
  * useFrame((state, delta) => {
45
- * // Frame-rate independent updates
46
32
  * interpolator.update(delta)
47
33
  * })
48
34
  *
@@ -54,14 +40,13 @@
54
40
  * }
55
41
  * ```
56
42
  */
57
- export type EasingFunction = "linear" | "spring" | "easeOut" | "easeInOut";
58
43
  export interface InterpolationOptions {
59
- /** Interpolation alpha factor (0-1, frame-rate independent) */
60
- alpha?: number;
61
- /** Minimum threshold to consider interpolation complete */
44
+ /** Spring tension (higher = faster, stiffer spring) - default: 120 */
45
+ tension?: number;
46
+ /** Spring friction (higher = more damping, less oscillation) - default: 20 */
47
+ friction?: number;
48
+ /** Minimum threshold to consider interpolation complete - default: 0.001 */
62
49
  threshold?: number;
63
- /** Easing function to use for interpolation */
64
- easing?: EasingFunction;
65
50
  /** Callback when values change during interpolation */
66
51
  onChange?: (values: number[]) => void;
67
52
  /** Callback when interpolation reaches target values */
@@ -70,16 +55,20 @@ export interface InterpolationOptions {
70
55
  export declare class ValueInterpolator {
71
56
  private currentValues;
72
57
  private targetValues;
58
+ private previousTargetValues;
59
+ private targetUpdateTime;
73
60
  private animationId;
74
61
  private options;
62
+ private velocities;
75
63
  constructor(initialValues?: number[], options?: InterpolationOptions);
76
64
  /**
77
- * Update interpolation (call this in useFrame for frame-rate independence)
65
+ * Update interpolation using spring physics (call this in useFrame for frame-rate independence)
78
66
  * @param delta - Frame delta time for smooth animation
79
67
  */
80
68
  update(delta?: number): boolean;
81
69
  /**
82
70
  * Set new target values to interpolate towards
71
+ * Handles irregular target updates smoothly by considering update frequency
83
72
  */
84
73
  setTarget(newValues: number[]): void;
85
74
  /**
@@ -114,24 +103,22 @@ export declare class ValueInterpolator {
114
103
  * Destroy the interpolator and clean up resources
115
104
  */
116
105
  destroy(): void;
117
- /**
118
- * Apply easing function to the interpolation with frame-rate independence
119
- */
120
- private applyEasing;
121
106
  private startInterpolation;
122
107
  private animate;
123
108
  }
124
109
  /**
125
110
  * React hook for using the ValueInterpolator with useFrame
126
111
  *
127
- * This hook creates a ValueInterpolator that's designed for manual updates
128
- * via useFrame(). It will not start automatic interpolation - you must
129
- * call interpolator.update(delta) in your useFrame callback.
112
+ * This hook creates a ValueInterpolator that uses spring physics for smooth,
113
+ * natural animations. Call interpolator.update(delta) in your useFrame callback.
130
114
  *
131
115
  * @example
132
116
  * ```tsx
133
117
  * function AnimatedMesh() {
134
- * const [interpolator] = useInterpolation([0, 0, 0], { alpha: 0.1 })
118
+ * const [interpolator] = useInterpolation([0, 0, 0], {
119
+ * tension: 120, // Higher = faster spring
120
+ * friction: 20 // Higher = more damping
121
+ * })
135
122
  * const meshRef = useRef()
136
123
  *
137
124
  * useFrame((state, delta) => {
@@ -1 +1 @@
1
- {"version":3,"file":"interpolation.d.ts","sourceRoot":"","sources":["../../../src/components/utils/interpolation.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAA;AAE1E,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACrC,wDAAwD;IACxD,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAA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