@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.4e55758 → 2.26.0-pr.feature-update-to-react-19.361.c04839a
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 +23 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +759 -748
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/robots/RobotAnimator.tsx +51 -34
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.c04839a",
|
|
4
4
|
"description": "React UI toolkit for building applications on top of the Wandelbots platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Globals, useSpring } from "@react-spring/three"
|
|
1
|
+
import { Globals, useSpring, type SpringValues } from "@react-spring/three"
|
|
2
2
|
import { useThree } from "@react-three/fiber"
|
|
3
3
|
import type {
|
|
4
4
|
DHParameter,
|
|
@@ -27,21 +27,27 @@ export default function RobotAnimator({
|
|
|
27
27
|
const jointObjects = useRef<Object3D[]>([])
|
|
28
28
|
const { invalidate } = useThree()
|
|
29
29
|
|
|
30
|
+
function isRobotFullyInitialized(): boolean {
|
|
31
|
+
return (
|
|
32
|
+
jointObjects.current.length > 0 &&
|
|
33
|
+
jointObjects.current.every(
|
|
34
|
+
(joint): joint is Object3D => joint !== undefined && joint !== null,
|
|
35
|
+
) &&
|
|
36
|
+
typedAxisValues !== undefined &&
|
|
37
|
+
dhParameters.length === jointObjects.current.length &&
|
|
38
|
+
dhParameters.every((param): param is DHParameter => param !== undefined)
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
function setGroupRef(group: Group | null) {
|
|
31
43
|
if (!group) return
|
|
32
44
|
|
|
33
45
|
jointObjects.current = collectJoints(group)
|
|
34
46
|
|
|
35
|
-
//
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
) {
|
|
40
|
-
// Use requestAnimationFrame to ensure axisValues is ready
|
|
41
|
-
requestAnimationFrame(() => {
|
|
42
|
-
setRotation()
|
|
43
|
-
invalidate()
|
|
44
|
-
})
|
|
47
|
+
// Only set initial position if robot is fully initialized
|
|
48
|
+
if (isRobotFullyInitialized()) {
|
|
49
|
+
setRotation()
|
|
50
|
+
invalidate()
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -50,43 +56,37 @@ export default function RobotAnimator({
|
|
|
50
56
|
setSpring.start(Object.assign({}, jointValues.current) as any)
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
const [axisValues, setSpring] = useSpring(() => ({
|
|
54
|
-
...Object.assign(
|
|
55
|
-
{},
|
|
56
|
-
rapidlyChangingMotionState.state.joint_position.joints,
|
|
57
|
-
),
|
|
58
|
-
onChange: () => {
|
|
59
|
-
setRotation()
|
|
60
|
-
invalidate()
|
|
61
|
-
},
|
|
62
|
-
onResolve: () => {
|
|
63
|
-
setRotation()
|
|
64
|
-
},
|
|
65
|
-
}))
|
|
66
|
-
|
|
67
59
|
function setRotation() {
|
|
68
|
-
//
|
|
69
|
-
if (
|
|
70
|
-
jointObjects.current.length === 0 ||
|
|
71
|
-
!jointObjects.current.every((obj) => obj != null)
|
|
72
|
-
) {
|
|
60
|
+
// Use the comprehensive validation function
|
|
61
|
+
if (!isRobotFullyInitialized()) {
|
|
73
62
|
return
|
|
74
63
|
}
|
|
75
64
|
|
|
76
|
-
const updatedJointValues = jointObjects.current.map(
|
|
77
|
-
(
|
|
65
|
+
const updatedJointValues = jointObjects.current.map(
|
|
66
|
+
(_, objectIndex) => typedAxisValues[objectIndex.toString()]?.get() || 0,
|
|
78
67
|
)
|
|
79
68
|
|
|
80
69
|
if (onRotationChanged) {
|
|
81
|
-
|
|
70
|
+
// Filter out undefined/null joints before passing to callback
|
|
71
|
+
const validJoints = jointObjects.current.filter((joint) => joint != null)
|
|
72
|
+
const validJointValues = validJoints.map(
|
|
73
|
+
(_, index) => updatedJointValues[index] || 0,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
if (validJoints.length > 0) {
|
|
77
|
+
onRotationChanged(validJoints, validJointValues)
|
|
78
|
+
}
|
|
82
79
|
} else {
|
|
83
80
|
for (const [index, object] of jointObjects.current.entries()) {
|
|
81
|
+
// Skip if object or dhParameter is undefined
|
|
82
|
+
if (!object || !dhParameters[index]) continue
|
|
83
|
+
|
|
84
84
|
const dhParam = dhParameters[index]
|
|
85
85
|
const rotationOffset = dhParam.theta || 0
|
|
86
86
|
const rotationSign = dhParam.reverse_rotation_direction ? -1 : 1
|
|
87
87
|
|
|
88
88
|
object.rotation.y =
|
|
89
|
-
rotationSign * updatedJointValues[index]
|
|
89
|
+
rotationSign * (updatedJointValues[index] || 0) + rotationOffset
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -100,5 +100,22 @@ export default function RobotAnimator({
|
|
|
100
100
|
requestAnimationFrame(() => updateJoints(newJointValues))
|
|
101
101
|
})
|
|
102
102
|
|
|
103
|
+
const [axisValues, setSpring] = useSpring(() => ({
|
|
104
|
+
...Object.assign(
|
|
105
|
+
{},
|
|
106
|
+
rapidlyChangingMotionState.state.joint_position.joints,
|
|
107
|
+
),
|
|
108
|
+
onChange: () => {
|
|
109
|
+
setRotation()
|
|
110
|
+
invalidate()
|
|
111
|
+
},
|
|
112
|
+
onResolve: () => {
|
|
113
|
+
setRotation()
|
|
114
|
+
},
|
|
115
|
+
}))
|
|
116
|
+
|
|
117
|
+
// Type the spring values properly
|
|
118
|
+
const typedAxisValues = axisValues as SpringValues<Record<string, number>>
|
|
119
|
+
|
|
103
120
|
return <group ref={setGroupRef}>{children}</group>
|
|
104
121
|
}
|