@wandelbots/wandelbots-js-react-components 2.26.0-pr.feature-update-to-react-19.361.b99883a → 2.26.0-pr.feature-update-to-react-19.361.fad9b97
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 +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +413 -406
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/robots/RobotAnimator.tsx +46 -17
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.fad9b97",
|
|
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, { useRef } from "react"
|
|
7
|
+
import React, { useEffect, useRef, useState } from "react"
|
|
8
8
|
import type { Group, Object3D } from "three"
|
|
9
9
|
import { useAutorun } from "../utils/hooks"
|
|
10
10
|
import { collectJoints } from "./robotModelLogic"
|
|
@@ -25,24 +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, setIsInitialized] = useState(false)
|
|
28
29
|
const { invalidate } = useThree()
|
|
29
30
|
|
|
30
31
|
function setGroupRef(group: Group | null) {
|
|
31
|
-
if (!group)
|
|
32
|
+
if (!group) {
|
|
33
|
+
setIsInitialized(false)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
32
36
|
|
|
33
37
|
jointObjects.current = collectJoints(group)
|
|
34
38
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
// Only mark as initialized if we have valid joint objects
|
|
40
|
+
if (
|
|
41
|
+
jointObjects.current.length > 0 &&
|
|
42
|
+
jointObjects.current.every((obj) => obj != null)
|
|
43
|
+
) {
|
|
44
|
+
setIsInitialized(true)
|
|
45
|
+
} else {
|
|
46
|
+
setIsInitialized(false)
|
|
47
|
+
}
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
function updateJoints(newJointValues: number[]) {
|
|
51
|
+
if (!isInitialized) return
|
|
52
|
+
|
|
41
53
|
jointValues.current = newJointValues
|
|
42
54
|
setSpring.start(Object.assign({}, jointValues.current) as any)
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
function setRotation() {
|
|
58
|
+
if (!isInitialized) return
|
|
59
|
+
|
|
46
60
|
const updatedJointValues = jointObjects.current.map((_, objectIndex) =>
|
|
47
61
|
(axisValues as any)[objectIndex].get(),
|
|
48
62
|
)
|
|
@@ -61,28 +75,43 @@ export default function RobotAnimator({
|
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
|
|
64
|
-
|
|
65
|
-
const newJointValues =
|
|
66
|
-
rapidlyChangingMotionState.state.joint_position.joints.filter(
|
|
67
|
-
(item) => item !== undefined,
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
requestAnimationFrame(() => updateJoints(newJointValues))
|
|
71
|
-
})
|
|
72
|
-
|
|
78
|
+
// Initialize spring only after joints are ready
|
|
73
79
|
const [axisValues, setSpring] = useSpring(() => ({
|
|
74
80
|
...Object.assign(
|
|
75
81
|
{},
|
|
76
82
|
rapidlyChangingMotionState.state.joint_position.joints,
|
|
77
83
|
),
|
|
78
84
|
onChange: () => {
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
if (isInitialized) {
|
|
86
|
+
setRotation()
|
|
87
|
+
invalidate()
|
|
88
|
+
}
|
|
81
89
|
},
|
|
82
90
|
onResolve: () => {
|
|
83
|
-
|
|
91
|
+
if (isInitialized) {
|
|
92
|
+
setRotation()
|
|
93
|
+
}
|
|
84
94
|
},
|
|
85
95
|
}))
|
|
86
96
|
|
|
97
|
+
// Effect to handle initial rotation when component becomes initialized
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (isInitialized) {
|
|
100
|
+
setRotation()
|
|
101
|
+
invalidate()
|
|
102
|
+
}
|
|
103
|
+
}, [isInitialized])
|
|
104
|
+
|
|
105
|
+
useAutorun(() => {
|
|
106
|
+
if (!isInitialized) return
|
|
107
|
+
|
|
108
|
+
const newJointValues =
|
|
109
|
+
rapidlyChangingMotionState.state.joint_position.joints.filter(
|
|
110
|
+
(item) => item !== undefined,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
requestAnimationFrame(() => updateJoints(newJointValues))
|
|
114
|
+
})
|
|
115
|
+
|
|
87
116
|
return <group ref={setGroupRef}>{children}</group>
|
|
88
117
|
}
|