@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.fd043dc → 2.26.0-pr.feature-update-to-react-19.361.08e5c02

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
@@ -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.fd043dc",
3
+ "version": "2.26.0-pr.feature-update-to-react-19.361.08e5c02",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -52,7 +52,7 @@
52
52
  "@emotion/styled": "^11.14.0",
53
53
  "@mui/icons-material": "^7.1.1",
54
54
  "@mui/material": "^7.1.1",
55
- "@react-spring/three": "^10.0.1",
55
+ "@react-spring/three": "10.0.0",
56
56
  "@react-three/drei": "^10.2.0",
57
57
  "@react-three/fiber": "^9.1.2",
58
58
  "@rollup/plugin-commonjs": "^28.0.2",
@@ -1,4 +1,4 @@
1
- import { Globals, useSpring, type SpringValues } from "@react-spring/three"
1
+ import { Globals, useSpring } from "@react-spring/three"
2
2
  import { useThree } from "@react-three/fiber"
3
3
  import type {
4
4
  DHParameter,
@@ -25,8 +25,38 @@ export default function RobotAnimator({
25
25
  Globals.assign({ frameLoop: "always" })
26
26
  const jointValues = useRef<number[]>([])
27
27
  const jointObjects = useRef<Object3D[]>([])
28
+ const isInitialized = useRef(false)
28
29
  const { invalidate } = useThree()
29
30
 
31
+ // Use a direct spring that responds to joint value changes
32
+ const currentJointValues =
33
+ rapidlyChangingMotionState.state.joint_position.joints.filter(
34
+ (item) => item !== undefined,
35
+ )
36
+
37
+ const targetValues = Object.fromEntries(
38
+ currentJointValues.map((value, index) => [index.toString(), value]),
39
+ )
40
+
41
+ const springProps = useSpring({
42
+ ...targetValues,
43
+ onChange: () => {
44
+ setRotation()
45
+ invalidate()
46
+ },
47
+ config: { tension: 120, friction: 20 },
48
+ })
49
+
50
+ useAutorun(() => {
51
+ const newJointValues =
52
+ rapidlyChangingMotionState.state.joint_position.joints.filter(
53
+ (item) => item !== undefined,
54
+ )
55
+
56
+ jointValues.current = newJointValues
57
+ // The spring will automatically update via the dependency on currentJointValues
58
+ })
59
+
30
60
  function setGroupRef(group: Group | null) {
31
61
  if (!group) return
32
62
 
@@ -39,20 +69,17 @@ export default function RobotAnimator({
39
69
  }
40
70
  }
41
71
 
42
- function updateJoints(newJointValues: number[]) {
43
- jointValues.current = newJointValues
44
- setSpring.start(Object.assign({}, jointValues.current) as any)
45
- }
46
-
47
72
  function setRotation() {
48
73
  // Use the comprehensive validation function
49
74
  if (!isRobotFullyInitialized()) {
50
75
  return
51
76
  }
52
77
 
53
- const updatedJointValues = jointObjects.current.map(
54
- (_, objectIndex) => typedAxisValues[objectIndex.toString()]?.get() || 0,
55
- )
78
+ const updatedJointValues = jointObjects.current.map((_, objectIndex) => {
79
+ const key = objectIndex.toString()
80
+ const springValue = (springProps as any)[key]
81
+ return springValue ? springValue.get() : 0
82
+ })
56
83
 
57
84
  if (onRotationChanged) {
58
85
  // Since we've validated everything, all joints should be valid
@@ -85,39 +112,13 @@ export default function RobotAnimator({
85
112
  }
86
113
  }
87
114
 
88
- useAutorun(() => {
89
- const newJointValues =
90
- rapidlyChangingMotionState.state.joint_position.joints.filter(
91
- (item) => item !== undefined,
92
- )
93
-
94
- requestAnimationFrame(() => updateJoints(newJointValues))
95
- })
96
-
97
- const [axisValues, setSpring] = useSpring(() => ({
98
- ...Object.assign(
99
- {},
100
- rapidlyChangingMotionState.state.joint_position.joints,
101
- ),
102
- onChange: () => {
103
- setRotation()
104
- invalidate()
105
- },
106
- onResolve: () => {
107
- setRotation()
108
- },
109
- }))
110
-
111
- // Type the spring values properly
112
- const typedAxisValues = axisValues as SpringValues<Record<string, number>>
113
-
114
115
  function isRobotFullyInitialized(): boolean {
115
116
  return (
116
117
  jointObjects.current.length > 0 &&
117
118
  jointObjects.current.every(
118
119
  (joint): joint is Object3D => joint !== undefined && joint !== null,
119
120
  ) &&
120
- typedAxisValues !== undefined &&
121
+ Object.keys(springProps as any).length > 0 &&
121
122
  dhParameters.length === jointObjects.current.length &&
122
123
  dhParameters.every((param): param is DHParameter => param !== undefined)
123
124
  )