@@ -48,43 +48,46 @@ export class URDFControls extends GUI {
48
48
return this . _jointsFolder ;
49
49
}
50
50
51
- createWorkspaceControls ( workingPath : string ) {
52
- if ( ! workingPath ) {
53
- return ;
54
- }
51
+ private _isEmpty ( obj : Object ) : Boolean {
52
+ return Object . keys ( obj ) . length === 0 ;
53
+ }
55
54
56
- this . _workingPath = workingPath ;
57
- const workspaceSettings = {
58
- 'Path' : this . _workingPath ,
59
- 'set path' : ( ) => { }
55
+ createWorkspaceControls ( workingPath : string = '' ) {
56
+ if ( this . _isEmpty ( this . controls . path ) ) {
57
+ this . _workingPath = workingPath ;
58
+ const workspaceSettings = {
59
+ 'Path' : this . _workingPath ,
60
+ 'set path' : ( ) => { }
61
+ }
62
+ this . _workspaceFolder . add ( workspaceSettings , 'Path' ) ;
63
+ this . controls . path = this . _workspaceFolder . add ( workspaceSettings , 'set path' ) ;
64
+ this . _workspaceFolder . open ( ) ;
60
65
}
61
- this . _workspaceFolder . add ( workspaceSettings , 'Path' ) ;
62
- this . controls . path = this . _workspaceFolder . add ( workspaceSettings , 'set path' ) ;
63
- this . _workspaceFolder . open ( ) ;
64
66
return this . controls . path ;
65
67
}
66
68
67
69
createSceneControls (
68
70
bgColor = new Color ( 0x263238 ) ,
69
71
gridColor = new Color ( 0x263238 )
70
72
) {
71
-
72
- const sceneSettings = {
73
- 'Background' : this . _convertColor2Array ( bgColor ) ,
74
- 'Grid' : this . _convertColor2Array ( gridColor ) ,
75
- 'Height' : 0
76
- } ;
77
-
78
- this . controls . scene . background = this . _sceneFolder . addColor ( sceneSettings , 'Background' ) ;
79
- this . controls . scene . grid = this . _sceneFolder . addColor ( sceneSettings , 'Grid' ) ;
80
-
81
- const minHeight = - 2 ;
82
- const maxHeight = 5 ;
83
- const stepSize = 0.1 ;
84
- this . controls . scene . height = this . _sceneFolder . add (
85
- sceneSettings , 'Height' , minHeight , maxHeight , stepSize ) ;
86
-
87
- this . _sceneFolder . open ( ) ;
73
+ if ( this . _isEmpty ( this . controls . scene . background ) ) {
74
+ const sceneSettings = {
75
+ 'Background' : this . _convertColor2Array ( bgColor ) ,
76
+ 'Grid' : this . _convertColor2Array ( gridColor ) ,
77
+ 'Height' : 0
78
+ } ;
79
+
80
+ this . controls . scene . background = this . _sceneFolder . addColor ( sceneSettings , 'Background' ) ;
81
+ this . controls . scene . grid = this . _sceneFolder . addColor ( sceneSettings , 'Grid' ) ;
82
+
83
+ const minHeight = - 2 ;
84
+ const maxHeight = 5 ;
85
+ const stepSize = 0.1 ;
86
+ this . controls . scene . height = this . _sceneFolder . add (
87
+ sceneSettings , 'Height' , minHeight , maxHeight , stepSize ) ;
88
+
89
+ this . _sceneFolder . open ( ) ;
90
+ }
88
91
return this . controls . scene ;
89
92
}
90
93
@@ -101,27 +104,29 @@ export class URDFControls extends GUI {
101
104
}
102
105
103
106
createJointControls ( joints : Joints ) {
104
- Object . keys ( joints ) . forEach ( ( name : string ) => {
105
- // Skip joints which should not be moved
106
- if ( joints [ name ] . jointType === 'fixed' ) {
107
- return ;
108
- }
109
-
110
- const limitMin = Number ( joints [ name ] . limit . lower ) ;
111
- const limitMax = Number ( joints [ name ] . limit . upper ) ;
112
-
113
- // Skip joint if the limits are not defined
114
- if ( limitMin === 0 && limitMax === 0 ) {
115
- return ;
116
- }
117
-
118
- const stepSize = ( limitMax - limitMin ) / 20 ;
119
- const initValue = joints [ name ] . jointValue [ 0 ] ;
120
-
121
- this . controls . joints [ name ] = this . _jointsFolder . add (
122
- { [ name ] : initValue } , name , limitMin , limitMax , stepSize ) ;
123
- } ) ;
124
- this . _jointsFolder . open ( ) ;
107
+ if ( this . _isEmpty ( this . controls . joints ) ) {
108
+ Object . keys ( joints ) . forEach ( ( name : string ) => {
109
+ // Skip joints which should not be moved
110
+ if ( joints [ name ] . jointType === 'fixed' ) {
111
+ return ;
112
+ }
113
+
114
+ const limitMin = Number ( joints [ name ] . limit . lower ) ;
115
+ const limitMax = Number ( joints [ name ] . limit . upper ) ;
116
+
117
+ // Skip joint if the limits are not defined
118
+ if ( limitMin === 0 && limitMax === 0 ) {
119
+ return ;
120
+ }
121
+
122
+ const stepSize = ( limitMax - limitMin ) / 20 ;
123
+ const initValue = joints [ name ] . jointValue [ 0 ] ;
124
+
125
+ this . controls . joints [ name ] = this . _jointsFolder . add (
126
+ { [ name ] : initValue } , name , limitMin , limitMax , stepSize ) ;
127
+ } ) ;
128
+ this . _jointsFolder . open ( ) ;
129
+ }
125
130
return this . controls . joints ;
126
131
}
127
132
}
0 commit comments