@wandelbots/wandelbots-js-react-components 1.5.0 → 1.5.1
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/README.md +2 -0
- package/dist/components/robots/SupportedRobot.d.ts.map +1 -1
- package/dist/index.cjs +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +882 -869
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/robots/SupportedRobot.tsx +86 -35
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Suspense, useCallback, useRef } from "react"
|
|
1
|
+
import { Suspense, useCallback, useEffect, useRef } from "react"
|
|
2
2
|
|
|
3
3
|
import { UniversalRobots_UR3 } from "./UniversalRobots_UR3"
|
|
4
4
|
import { UniversalRobots_UR3e } from "./UniversalRobots_UR3e"
|
|
@@ -67,51 +67,102 @@ export function SupportedRobot({
|
|
|
67
67
|
(instance: THREE.Group | null) => {
|
|
68
68
|
if (instance !== null) {
|
|
69
69
|
robotRef.current = instance
|
|
70
|
+
console.log("robotRef.current", robotRef.current)
|
|
70
71
|
if (
|
|
71
72
|
isGhost &&
|
|
72
73
|
robotRef.current &&
|
|
73
74
|
robotRef.current.children.length > 0
|
|
74
75
|
) {
|
|
75
|
-
|
|
76
|
-
robotRef.current.traverse((obj) => {
|
|
77
|
-
if (obj instanceof THREE.Mesh && !obj.userData.isGhost) {
|
|
78
|
-
// Create a clone of the mesh
|
|
79
|
-
const ghost = obj.clone()
|
|
80
|
-
|
|
81
|
-
obj.material = new THREE.MeshStandardMaterial({
|
|
82
|
-
depthTest: true,
|
|
83
|
-
depthWrite: true,
|
|
84
|
-
colorWrite: false,
|
|
85
|
-
polygonOffset: true,
|
|
86
|
-
polygonOffsetFactor: 1,
|
|
87
|
-
color: "#ffffff",
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// Set the material for the ghost mesh
|
|
91
|
-
ghost.material = new THREE.MeshStandardMaterial({
|
|
92
|
-
color: "#D91433",
|
|
93
|
-
opacity: 0.3,
|
|
94
|
-
depthTest: true,
|
|
95
|
-
depthWrite: false,
|
|
96
|
-
transparent: true,
|
|
97
|
-
polygonOffset: true,
|
|
98
|
-
polygonOffsetFactor: -1,
|
|
99
|
-
})
|
|
100
|
-
ghost.userData.isGhost = true
|
|
101
|
-
|
|
102
|
-
if (obj.parent) {
|
|
103
|
-
obj.parent.add(ghost)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
robotRef.current.userData.ghostsCreated = true
|
|
108
|
-
}
|
|
76
|
+
addGhosts()
|
|
109
77
|
}
|
|
110
78
|
}
|
|
111
79
|
},
|
|
112
80
|
[isGhost],
|
|
113
81
|
)
|
|
114
82
|
|
|
83
|
+
const addGhosts = () => {
|
|
84
|
+
if (robotRef.current && !robotRef.current.userData.ghostsCreated) {
|
|
85
|
+
robotRef.current.traverse((obj) => {
|
|
86
|
+
if (obj instanceof THREE.Mesh && !obj.userData.isGhost) {
|
|
87
|
+
if (obj.material instanceof THREE.Material) {
|
|
88
|
+
obj.material.colorWrite = false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Create a clone of the mesh
|
|
92
|
+
const depth = obj.clone()
|
|
93
|
+
const ghost = obj.clone()
|
|
94
|
+
|
|
95
|
+
depth.material = new THREE.MeshStandardMaterial({
|
|
96
|
+
depthTest: true,
|
|
97
|
+
depthWrite: true,
|
|
98
|
+
colorWrite: false,
|
|
99
|
+
polygonOffset: true,
|
|
100
|
+
polygonOffsetFactor: 1,
|
|
101
|
+
})
|
|
102
|
+
depth.userData.isGhost = true
|
|
103
|
+
|
|
104
|
+
// Set the material for the ghost mesh
|
|
105
|
+
ghost.material = new THREE.MeshStandardMaterial({
|
|
106
|
+
color: "#D91433",
|
|
107
|
+
opacity: 0.3,
|
|
108
|
+
depthTest: true,
|
|
109
|
+
depthWrite: false,
|
|
110
|
+
transparent: true,
|
|
111
|
+
polygonOffset: true,
|
|
112
|
+
polygonOffsetFactor: -1,
|
|
113
|
+
})
|
|
114
|
+
ghost.userData.isGhost = true
|
|
115
|
+
|
|
116
|
+
if (obj.parent) {
|
|
117
|
+
obj.parent.add(depth)
|
|
118
|
+
obj.parent.add(ghost)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
robotRef.current.userData.ghostsCreated = true
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const removeGhosts = () => {
|
|
127
|
+
if (robotRef.current) {
|
|
128
|
+
const objectsToRemove: THREE.Object3D[] = []
|
|
129
|
+
|
|
130
|
+
robotRef.current.traverse((obj) => {
|
|
131
|
+
if (obj instanceof THREE.Mesh) {
|
|
132
|
+
if (obj.material instanceof THREE.Material) {
|
|
133
|
+
obj.material.colorWrite = true
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (
|
|
138
|
+
obj instanceof THREE.Mesh &&
|
|
139
|
+
obj.userData !== undefined &&
|
|
140
|
+
obj.userData &&
|
|
141
|
+
obj.userData.isGhost !== undefined &&
|
|
142
|
+
obj.userData.isGhost
|
|
143
|
+
) {
|
|
144
|
+
objectsToRemove.push(obj)
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
objectsToRemove.forEach((obj) => {
|
|
149
|
+
if (obj.parent) {
|
|
150
|
+
obj.parent.remove(obj)
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
robotRef.current.userData.ghostsCreated = false
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (isGhost) {
|
|
160
|
+
addGhosts()
|
|
161
|
+
} else {
|
|
162
|
+
removeGhosts()
|
|
163
|
+
}
|
|
164
|
+
}, [isGhost])
|
|
165
|
+
|
|
115
166
|
switch (modelFromController) {
|
|
116
167
|
case "UniversalRobots_UR3":
|
|
117
168
|
Robot = UniversalRobots_UR3
|