@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.aabda9e → 2.26.0-pr.feature-update-to-react-19.361.5875b87
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/robots/RobotAnimator.d.ts.map +1 -1
- package/dist/index.cjs +27 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1081 -1100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/robots/RobotAnimator.tsx +22 -83
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.5875b87",
|
|
4
4
|
"description": "React UI toolkit for building applications on top of the Wandelbots platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
DHParameter,
|
|
5
5
|
MotionGroupStateResponse,
|
|
6
6
|
} from "@wandelbots/nova-api/v1"
|
|
7
|
-
import React, {
|
|
7
|
+
import React, { useRef } from "react"
|
|
8
8
|
import type { Group, Object3D } from "three"
|
|
9
9
|
import { collectJoints } from "./robotModelLogic"
|
|
10
10
|
|
|
@@ -25,44 +25,6 @@ export default function RobotAnimator({
|
|
|
25
25
|
const jointObjects = useRef<Object3D[]>([])
|
|
26
26
|
const { invalidate } = useThree()
|
|
27
27
|
|
|
28
|
-
// Get current joint values
|
|
29
|
-
const currentJointValues =
|
|
30
|
-
rapidlyChangingMotionState.state.joint_position.joints.filter(
|
|
31
|
-
(item) => item !== undefined,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
// Create spring with proper dependency array
|
|
35
|
-
const [springValues, api] = useSpring(() => ({
|
|
36
|
-
// Initialize with current values as an object
|
|
37
|
-
...currentJointValues.reduce(
|
|
38
|
-
(acc, value, index) => {
|
|
39
|
-
acc[index] = value
|
|
40
|
-
return acc
|
|
41
|
-
},
|
|
42
|
-
{} as Record<number, number>,
|
|
43
|
-
),
|
|
44
|
-
onChange: () => {
|
|
45
|
-
if (jointObjects.current.length > 0) {
|
|
46
|
-
setRotation()
|
|
47
|
-
invalidate()
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
config: { tension: 120, friction: 20 },
|
|
51
|
-
}))
|
|
52
|
-
|
|
53
|
-
// Update spring when joint values change
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const newValues = currentJointValues.reduce(
|
|
56
|
-
(acc, value, index) => {
|
|
57
|
-
acc[index] = value
|
|
58
|
-
return acc
|
|
59
|
-
},
|
|
60
|
-
{} as Record<number, number>,
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
api.start(newValues)
|
|
64
|
-
}, [currentJointValues.join(","), api]) // Use join for stable dependency
|
|
65
|
-
|
|
66
28
|
function setGroupRef(group: Group | null) {
|
|
67
29
|
if (!group) return
|
|
68
30
|
|
|
@@ -74,63 +36,40 @@ export default function RobotAnimator({
|
|
|
74
36
|
}
|
|
75
37
|
|
|
76
38
|
function setRotation() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Get the animated joint values from the spring object
|
|
83
|
-
const updatedJointValues = jointObjects.current.map((_, objectIndex) => {
|
|
84
|
-
const springValue = springValues[objectIndex as keyof typeof springValues]
|
|
85
|
-
return typeof springValue === "object" &&
|
|
86
|
-
springValue &&
|
|
87
|
-
"get" in springValue
|
|
88
|
-
? (springValue as any).get()
|
|
89
|
-
: 0
|
|
90
|
-
})
|
|
39
|
+
const updatedJointValues = jointObjects.current.map((_, objectIndex) =>
|
|
40
|
+
(axisValues as any)[objectIndex].get(),
|
|
41
|
+
)
|
|
91
42
|
|
|
92
43
|
if (onRotationChanged) {
|
|
93
|
-
|
|
94
|
-
// But let's still be defensive and only pass valid joints
|
|
95
|
-
const validJoints = jointObjects.current.filter(
|
|
96
|
-
(joint): joint is Object3D => joint != null,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
if (validJoints.length === jointObjects.current.length) {
|
|
100
|
-
// All joints are valid, pass them with corresponding values
|
|
101
|
-
onRotationChanged(validJoints, updatedJointValues)
|
|
102
|
-
} else {
|
|
103
|
-
// Some joints are invalid, don't call the callback
|
|
104
|
-
console.warn(
|
|
105
|
-
"RobotAnimator: Some joints are invalid, skipping onRotationChanged callback",
|
|
106
|
-
)
|
|
107
|
-
}
|
|
44
|
+
onRotationChanged(jointObjects.current, updatedJointValues)
|
|
108
45
|
} else {
|
|
109
46
|
for (const [index, object] of jointObjects.current.entries()) {
|
|
110
|
-
// Skip if object or dhParameter is undefined
|
|
111
|
-
if (!object || !dhParameters[index]) continue
|
|
112
|
-
|
|
113
47
|
const dhParam = dhParameters[index]
|
|
114
48
|
const rotationOffset = dhParam.theta || 0
|
|
115
49
|
const rotationSign = dhParam.reverse_rotation_direction ? -1 : 1
|
|
116
50
|
|
|
117
51
|
object.rotation.y =
|
|
118
|
-
rotationSign *
|
|
52
|
+
rotationSign * updatedJointValues[index]! + rotationOffset
|
|
119
53
|
}
|
|
120
54
|
}
|
|
121
55
|
}
|
|
122
56
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
57
|
+
// Declarative spring that automatically updates when motion state changes
|
|
58
|
+
const axisValues = useSpring({
|
|
59
|
+
to: Object.assign(
|
|
60
|
+
{},
|
|
61
|
+
rapidlyChangingMotionState.state.joint_position.joints.filter(
|
|
62
|
+
(item) => item !== undefined,
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
onChange: () => {
|
|
66
|
+
setRotation()
|
|
67
|
+
invalidate()
|
|
68
|
+
},
|
|
69
|
+
onResolve: () => {
|
|
70
|
+
setRotation()
|
|
71
|
+
},
|
|
72
|
+
})
|
|
134
73
|
|
|
135
74
|
return <group ref={setGroupRef}>{children}</group>
|
|
136
75
|
}
|