@@ -31,8 +31,6 @@ class SceneObjects{
31
31
this . nodeMeshes = [ ] ;
32
32
this . lidarsMeshes = [ ] ;
33
33
this . dummiesMeshes = [ ] ;
34
- this . numberOfNodesCreated = 0 ;
35
- this . numberOfLidarsCreated = 0 ;
36
34
37
35
const givenAreaPolygonRegions = [ [ ] ] ;
38
36
@@ -158,8 +156,16 @@ class SceneObjects{
158
156
console . log ( "Add Node button will work in an instant" ) ;
159
157
return ;
160
158
}
161
- const newCamera = new Node ( this . numberOfNodesCreated , mode , typeID , x , y , z , p , a , r ) ;
162
- this . numberOfNodesCreated ++ ;
159
+
160
+ let idOfNode = 0 ;
161
+
162
+ // Method .some() returns true if AT LEAST one element of the array passes the test
163
+ while ( nodes . some ( node => node . id === idOfNode ) ) {
164
+ idOfNode ++ ;
165
+ }
166
+
167
+ const newCamera = new Node ( idOfNode , mode , typeID , x , y , z , p , a , r ) ;
168
+
163
169
if ( ! isBuilder ) newCamera . uiElement = new NodeUI ( newCamera , sceneManager ) ;
164
170
165
171
//Offset
@@ -276,8 +282,16 @@ class SceneObjects{
276
282
console . log ( "Add Lidar button will work in an instant" ) ;
277
283
return ;
278
284
}
279
- const newLidar = new Lidar ( this . numberOfLidarsCreated , sizeDetected , typeID , x , z , r ) ;
280
- this . numberOfLidarsCreated ++ ;
285
+
286
+ let idOfLidar = 0 ;
287
+
288
+ // Method .some() returns true if AT LEAST one element of the array passes the test
289
+ while ( lidars . some ( lidar => lidar . id === idOfLidar ) ) {
290
+ idOfLidar ++ ;
291
+ }
292
+
293
+ const newLidar = new Lidar ( idOfLidar , sizeDetected , typeID , x , z , r ) ;
294
+
281
295
if ( ! isBuilder ) newLidar . uiElement = new LidarUI ( newLidar , sceneManager ) ;
282
296
283
297
// Offset
0 commit comments