@wandelbots/wandelbots-js-react-components 1.4.3 → 1.5.0

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": "1.4.3",
3
+ "version": "1.5.0",
4
4
  "description": "React UI toolkit for building applications on top of the Wandelbots platform",
5
5
  "files": [
6
6
  "dist",
@@ -6,6 +6,7 @@ import { defaultGetModel, SupportedRobot } from "./SupportedRobot"
6
6
  export type ConnectecMotionGroupRobotProps = {
7
7
  connectedMotionGroup: ConnectedMotionGroup
8
8
  getModel?: (modelFromController: string) => string
9
+ isGhost?: boolean
9
10
  } & GroupProps
10
11
 
11
12
  /**
@@ -22,6 +23,7 @@ export type ConnectecMotionGroupRobotProps = {
22
23
  export function Robot({
23
24
  connectedMotionGroup,
24
25
  getModel = defaultGetModel,
26
+ isGhost = false,
25
27
  ...props
26
28
  }: ConnectecMotionGroupRobotProps) {
27
29
  if (!connectedMotionGroup.dhParameters) {
@@ -36,6 +38,7 @@ export function Robot({
36
38
  modelFromController={connectedMotionGroup.modelFromController || ""}
37
39
  dhParameters={connectedMotionGroup.dhParameters}
38
40
  getModel={getModel}
41
+ isGhost={isGhost}
39
42
  {...props}
40
43
  />
41
44
  )
@@ -1,4 +1,4 @@
1
- import { Suspense } from "react"
1
+ import { Suspense, useCallback, useRef } from "react"
2
2
 
3
3
  import { UniversalRobots_UR3 } from "./UniversalRobots_UR3"
4
4
  import { UniversalRobots_UR3e } from "./UniversalRobots_UR3e"
@@ -27,6 +27,8 @@ import type {
27
27
  } from "@wandelbots/wandelbots-api-client"
28
28
  import { DHRobot } from "./DHRobot"
29
29
 
30
+ import * as THREE from "three"
31
+
30
32
  export type DHRobotProps = {
31
33
  rapidlyChangingMotionState: MotionGroupStateResponse
32
34
  dhParameters: Array<DHParameter>
@@ -42,6 +44,7 @@ export type SupportedRobotProps = {
42
44
  modelFromController: string
43
45
  dhParameters: DHParameter[]
44
46
  getModel?: (modelFromController: string) => string
47
+ isGhost?: boolean
45
48
  } & GroupProps
46
49
 
47
50
  export function defaultGetModel(modelFromController: string): string {
@@ -53,10 +56,62 @@ export function SupportedRobot({
53
56
  modelFromController,
54
57
  dhParameters,
55
58
  getModel = defaultGetModel,
59
+ isGhost = false,
56
60
  ...props
57
61
  }: SupportedRobotProps) {
58
62
  let Robot
59
63
 
64
+ const robotRef = useRef<THREE.Group>(new THREE.Group())
65
+
66
+ const setRobotRef = useCallback(
67
+ (instance: THREE.Group | null) => {
68
+ if (instance !== null) {
69
+ robotRef.current = instance
70
+ if (
71
+ isGhost &&
72
+ robotRef.current &&
73
+ robotRef.current.children.length > 0
74
+ ) {
75
+ if (!robotRef.current.userData.ghostsCreated) {
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
+ }
109
+ }
110
+ }
111
+ },
112
+ [isGhost],
113
+ )
114
+
60
115
  switch (modelFromController) {
61
116
  case "UniversalRobots_UR3":
62
117
  Robot = UniversalRobots_UR3
@@ -136,12 +191,14 @@ export function SupportedRobot({
136
191
  />
137
192
  }
138
193
  >
139
- <Robot
140
- rapidlyChangingMotionState={rapidlyChangingMotionState}
141
- modelURL={getModel(modelFromController)}
142
- dhParameters={dhParameters}
143
- {...props}
144
- />
194
+ <group ref={setRobotRef}>
195
+ <Robot
196
+ rapidlyChangingMotionState={rapidlyChangingMotionState}
197
+ modelURL={getModel(modelFromController)}
198
+ dhParameters={dhParameters}
199
+ {...props}
200
+ />
201
+ </group>
145
202
  </Suspense>
146
203
  )
147
204
  }
@@ -1,8 +1,12 @@
1
- import React from "react";
2
-
3
1
  export function RobotIcon() {
4
2
  return (
5
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <svg
4
+ width="24"
5
+ height="24"
6
+ viewBox="0 0 24 24"
7
+ fill="none"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ >
6
10
  <path
7
11
  fill-rule="evenodd"
8
12
  clip-rule="evenodd"
@@ -10,5 +14,5 @@ export function RobotIcon() {
10
14
  fill="white"
11
15
  />
12
16
  </svg>
13
- );
17
+ )
14
18
  }