@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.c3fd41e → 2.26.0-pr.feature-update-to-react-19.361.fbd0985
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/dist/components/utils/interpolation.d.ts +30 -10
- package/dist/components/utils/interpolation.d.ts.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +32 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/robots/RobotAnimator.tsx +4 -4
- package/src/components/utils/interpolation.ts +49 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wandelbots/wandelbots-js-react-components",
|
|
3
|
-
"version": "2.26.0-pr.feature-update-to-react-19.361.
|
|
3
|
+
"version": "2.26.0-pr.feature-update-to-react-19.361.fbd0985",
|
|
4
4
|
"description": "React UI toolkit for building applications on top of the Wandelbots platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@ export default function RobotAnimator({
|
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
interpolatorRef.current = new ValueInterpolator(initialJointValues, {
|
|
38
|
-
tension: 120, //
|
|
39
|
-
friction: 20, //
|
|
38
|
+
tension: 120, // Controls spring stiffness - higher values create faster, more responsive motion
|
|
39
|
+
friction: 20, // Controls damping - higher values reduce oscillation and create smoother settling
|
|
40
40
|
threshold: 0.001,
|
|
41
41
|
})
|
|
42
42
|
|
|
@@ -45,13 +45,13 @@ export default function RobotAnimator({
|
|
|
45
45
|
}
|
|
46
46
|
}, [])
|
|
47
47
|
|
|
48
|
-
//
|
|
48
|
+
// Animation loop that runs at the display's refresh rate
|
|
49
49
|
useFrame((state, delta) => {
|
|
50
50
|
if (interpolatorRef.current) {
|
|
51
51
|
const isComplete = interpolatorRef.current.update(delta)
|
|
52
52
|
setRotation()
|
|
53
53
|
|
|
54
|
-
//
|
|
54
|
+
// Trigger a re-render only if the animation is still running
|
|
55
55
|
if (!isComplete) {
|
|
56
56
|
invalidate()
|
|
57
57
|
}
|
|
@@ -88,45 +88,51 @@ export class ValueInterpolator {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* Update interpolation using spring physics
|
|
92
|
-
*
|
|
91
|
+
* Update interpolation using spring physics
|
|
92
|
+
*
|
|
93
|
+
* Call this method every frame for smooth animation. In React Three Fiber,
|
|
94
|
+
* call from within useFrame callback with the provided delta time.
|
|
95
|
+
*
|
|
96
|
+
* @param delta - Time elapsed since last update in seconds (e.g., 1/60 ≈ 0.0167 for 60fps)
|
|
97
|
+
* @returns true when interpolation is complete (all values reached their targets)
|
|
93
98
|
*/
|
|
94
99
|
update(delta: number = 1 / 60): boolean {
|
|
95
100
|
let hasChanges = false
|
|
96
101
|
let isComplete = true
|
|
97
102
|
|
|
98
|
-
//
|
|
99
|
-
const clampedDelta = Math.min(delta, 1 / 15) //
|
|
103
|
+
// Limit delta to prevent physics instability during large frame drops
|
|
104
|
+
const clampedDelta = Math.min(delta, 1 / 15) // Maximum 66ms frame time allowed
|
|
100
105
|
|
|
101
106
|
for (let i = 0; i < this.currentValues.length; i++) {
|
|
102
107
|
const current = this.currentValues[i]
|
|
103
108
|
const target = this.targetValues[i]
|
|
104
109
|
const velocity = this.velocities[i]
|
|
105
110
|
|
|
106
|
-
//
|
|
111
|
+
// Calculate spring physics forces
|
|
107
112
|
const displacement = target - current
|
|
108
113
|
const springForce = displacement * this.options.tension
|
|
109
114
|
const dampingForce = velocity * this.options.friction
|
|
110
115
|
|
|
111
|
-
//
|
|
116
|
+
// Calculate acceleration from net force (F = ma, assuming mass = 1)
|
|
112
117
|
const acceleration = springForce - dampingForce
|
|
113
118
|
|
|
114
|
-
//
|
|
119
|
+
// Integrate physics using Verlet method for numerical stability
|
|
115
120
|
const newVelocity = velocity + acceleration * clampedDelta
|
|
116
121
|
const newValue = current + newVelocity * clampedDelta
|
|
117
122
|
|
|
118
|
-
//
|
|
123
|
+
// Determine if this value has settled (close to target with low velocity)
|
|
119
124
|
const isValueComplete =
|
|
120
125
|
Math.abs(displacement) < this.options.threshold &&
|
|
121
126
|
Math.abs(newVelocity) < this.options.threshold * 10
|
|
122
127
|
|
|
123
128
|
if (!isValueComplete) {
|
|
124
129
|
isComplete = false
|
|
130
|
+
// Continue spring animation
|
|
125
131
|
this.currentValues[i] = newValue
|
|
126
132
|
this.velocities[i] = newVelocity
|
|
127
133
|
hasChanges = true
|
|
128
134
|
} else {
|
|
129
|
-
// Snap to target when close enough
|
|
135
|
+
// Snap exactly to target when close enough (prevents endless micro-movements)
|
|
130
136
|
if (this.currentValues[i] !== target) {
|
|
131
137
|
this.currentValues[i] = target
|
|
132
138
|
this.velocities[i] = 0
|
|
@@ -147,8 +153,10 @@ export class ValueInterpolator {
|
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
/**
|
|
150
|
-
* Set new target values to
|
|
151
|
-
*
|
|
156
|
+
* Set new target values for the interpolation to move towards
|
|
157
|
+
*
|
|
158
|
+
* Includes smart blending for very rapid target updates (faster than 120fps)
|
|
159
|
+
* to prevent jarring movements when targets change frequently.
|
|
152
160
|
*/
|
|
153
161
|
setTarget(newValues: number[]): void {
|
|
154
162
|
const now = performance.now()
|
|
@@ -159,21 +167,21 @@ export class ValueInterpolator {
|
|
|
159
167
|
this.targetValues = [...newValues]
|
|
160
168
|
this.targetUpdateTime = now
|
|
161
169
|
|
|
162
|
-
//
|
|
163
|
-
//
|
|
170
|
+
// Apply target blending for extremely rapid updates to prevent jarring jumps
|
|
171
|
+
// Only activates when targets change faster than 120fps (< 8ms between updates)
|
|
164
172
|
if (
|
|
165
173
|
timeSinceLastUpdate < 8 &&
|
|
166
174
|
timeSinceLastUpdate > 0 &&
|
|
167
175
|
this.previousTargetValues.length > 0
|
|
168
176
|
) {
|
|
169
|
-
//
|
|
170
|
-
const blendFactor = Math.min(timeSinceLastUpdate / 8, 1) // 0
|
|
177
|
+
// Blend between previous and new target based on time elapsed
|
|
178
|
+
const blendFactor = Math.min(timeSinceLastUpdate / 8, 1) // 0 to 1 over 8ms
|
|
171
179
|
|
|
172
180
|
for (let i = 0; i < this.targetValues.length; i++) {
|
|
173
181
|
const prev = this.previousTargetValues[i] || 0
|
|
174
182
|
const next = newValues[i] || 0
|
|
175
183
|
|
|
176
|
-
// Only blend
|
|
184
|
+
// Only blend significant changes to avoid unnecessary smoothing
|
|
177
185
|
const change = Math.abs(next - prev)
|
|
178
186
|
if (change > 0.1) {
|
|
179
187
|
this.targetValues[i] = prev + (next - prev) * blendFactor
|
|
@@ -181,43 +189,49 @@ export class ValueInterpolator {
|
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
// Ensure arrays have
|
|
192
|
+
// Ensure value and velocity arrays have matching lengths
|
|
185
193
|
while (this.currentValues.length < newValues.length) {
|
|
186
194
|
this.currentValues.push(newValues[this.currentValues.length])
|
|
187
|
-
this.velocities.push(0) //
|
|
195
|
+
this.velocities.push(0) // New values start with zero velocity
|
|
188
196
|
}
|
|
189
197
|
if (this.currentValues.length > newValues.length) {
|
|
190
198
|
this.currentValues = this.currentValues.slice(0, newValues.length)
|
|
191
199
|
this.velocities = this.velocities.slice(0, newValues.length)
|
|
192
200
|
}
|
|
193
201
|
|
|
194
|
-
//
|
|
195
|
-
// This prevents conflicts with useFrame
|
|
202
|
+
// Does not start automatic interpolation - requires manual update() calls
|
|
203
|
+
// This design prevents conflicts when using with React Three Fiber's useFrame
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
/**
|
|
199
|
-
* Get
|
|
207
|
+
* Get a copy of all current interpolated values
|
|
200
208
|
*/
|
|
201
209
|
getCurrentValues(): number[] {
|
|
202
210
|
return [...this.currentValues]
|
|
203
211
|
}
|
|
204
212
|
|
|
205
213
|
/**
|
|
206
|
-
* Get a
|
|
214
|
+
* Get a single interpolated value by its array index
|
|
207
215
|
*/
|
|
208
216
|
getValue(index: number): number {
|
|
209
217
|
return this.currentValues[index] ?? 0
|
|
210
218
|
}
|
|
211
219
|
|
|
212
220
|
/**
|
|
213
|
-
* Check if interpolation is currently
|
|
221
|
+
* Check if automatic interpolation is currently running
|
|
222
|
+
*
|
|
223
|
+
* This only tracks auto-interpolation started with startAutoInterpolation().
|
|
224
|
+
* Manual update() calls are not tracked by this method.
|
|
214
225
|
*/
|
|
215
226
|
isInterpolating(): boolean {
|
|
216
227
|
return this.animationId !== null
|
|
217
228
|
}
|
|
218
229
|
|
|
219
230
|
/**
|
|
220
|
-
* Stop
|
|
231
|
+
* Stop automatic interpolation if it's running
|
|
232
|
+
*
|
|
233
|
+
* This cancels the internal animation frame loop but does not affect
|
|
234
|
+
* manual update() calls.
|
|
221
235
|
*/
|
|
222
236
|
stop(): void {
|
|
223
237
|
if (this.animationId !== null) {
|
|
@@ -247,14 +261,21 @@ export class ValueInterpolator {
|
|
|
247
261
|
}
|
|
248
262
|
|
|
249
263
|
/**
|
|
250
|
-
* Start automatic interpolation
|
|
264
|
+
* Start automatic interpolation with an animation loop
|
|
265
|
+
*
|
|
266
|
+
* This begins a requestAnimationFrame loop that calls update() automatically.
|
|
267
|
+
* For React Three Fiber components, prefer using manual update() calls
|
|
268
|
+
* within useFrame hooks instead.
|
|
251
269
|
*/
|
|
252
270
|
startAutoInterpolation(): void {
|
|
253
271
|
this.startInterpolation()
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
/**
|
|
257
|
-
*
|
|
275
|
+
* Clean up all resources and stop any running animations
|
|
276
|
+
*
|
|
277
|
+
* This cancels any active animation frames and resets internal state.
|
|
278
|
+
* Call this when the component unmounts or is no longer needed.
|
|
258
279
|
*/
|
|
259
280
|
destroy(): void {
|
|
260
281
|
this.stop()
|
|
@@ -269,8 +290,8 @@ export class ValueInterpolator {
|
|
|
269
290
|
}
|
|
270
291
|
|
|
271
292
|
private animate = (): void => {
|
|
272
|
-
// Use
|
|
273
|
-
const isComplete = this.update(1 / 60) //
|
|
293
|
+
// Use delta timing with a fallback for consistent automatic animations
|
|
294
|
+
const isComplete = this.update(1 / 60) // Simulate 60fps for auto-interpolation
|
|
274
295
|
|
|
275
296
|
if (!isComplete) {
|
|
276
297
|
this.animationId = requestAnimationFrame(this.animate)
|