@@ -5,12 +5,15 @@ import {
5
5
MeshPhongMaterial ,
6
6
MeshBasicMaterial ,
7
7
Mesh ,
8
+ Vector3 ,
8
9
LineSegments ,
9
10
Color ,
10
11
Group
11
12
} from 'three' ;
12
13
13
- import { getLidarsTypes , units } from '/js/data.js'
14
+ import { TextGeometry } from 'three-text-geometry' ;
15
+ import { getLidarsTypes , units } from '/js/data.js' ;
16
+ import { SceneObjects } from '../SceneObjects.js' ;
14
17
15
18
16
19
class Lidar {
@@ -19,6 +22,7 @@ class Lidar{
19
22
static DEFAULT_LIDAR_SIZE = 0.1 ;
20
23
static DEFAULT_MIN_ANGLE_TO_AVOID_OBSTRUCTION = Math . PI / 180 * 60 ;
21
24
static DEFAULT_RATIO_FAR_MINDIST = 2 ;
25
+ static SIZE_TEXT_LIDAR = 0.6 ;
22
26
23
27
constructor ( id , lidarTypeID = Lidar . DEFAULT_LIDAR_TYPE_ID , p_x = 0 , p_z = Lidar . DEFAULT_LIDAR_HOOK_HEIGHT , r_y = 0 )
24
28
{
@@ -37,6 +41,8 @@ class Lidar{
37
41
this . mesh = buildMesh ( this . color , this . xPos , Lidar . DEFAULT_LIDAR_SIZE , this . zPos ) ;
38
42
this . rays = new Group ( ) ;
39
43
44
+ this . nameText = buildTextMesh ( "LiDAR " + ( this . id + 1 ) , Lidar . SIZE_TEXT_LIDAR , this . xPos - Lidar . SIZE_TEXT_LIDAR * 2 , this . yPos + Lidar . SIZE_TEXT_LIDAR / 2.0 , this . zPos )
45
+
40
46
this . raysAppear = true ;
41
47
42
48
/* BUILDERS */
@@ -53,6 +59,15 @@ class Lidar{
53
59
return mesh ;
54
60
}
55
61
62
+ function buildTextMesh ( text , size , initialXPos , initialYPos , initialZPos )
63
+ {
64
+ const textGeometry = new TextGeometry ( text , { font : SceneObjects . font , size : size , height : 0.01 } ) ;
65
+ const textMesh = new Mesh ( textGeometry , new MeshPhongMaterial ( { color : 0xffffff } ) )
66
+ textMesh . position . set ( initialXPos , initialZPos , initialYPos ) ;
67
+
68
+ return textMesh ;
69
+ }
70
+
56
71
this . buildRays = function ( )
57
72
{
58
73
const material = new MeshBasicMaterial ( { color : this . color , transparent : true , opacity : 0.4 , alphaTest : 0.3 } ) ;
@@ -89,12 +104,14 @@ class Lidar{
89
104
{
90
105
scene . add ( this . mesh ) ;
91
106
scene . add ( this . rays ) ;
107
+ scene . add ( this . nameText ) ;
92
108
}
93
109
94
110
this . removeFromScene = function ( scene )
95
111
{
96
112
scene . remove ( this . mesh ) ;
97
113
scene . remove ( this . rays ) ;
114
+ scene . remove ( this . nameText ) ;
98
115
}
99
116
100
117
/* USER'S ACTION */
@@ -103,6 +120,7 @@ class Lidar{
103
120
const value = display ;
104
121
this . raysAppear = value ;
105
122
this . rays . visible = value ;
123
+ this . nameText . visible = value ;
106
124
107
125
if ( this . uiElement ) this . uiElement . changeVisibility ( value ) ;
108
126
}
@@ -113,7 +131,14 @@ class Lidar{
113
131
this . zPos = this . mesh . position . y ;
114
132
this . rays . position . set ( this . xPos , this . zPos , this . yPos ) ;
115
133
116
- if ( this . uiElement ) this . uiElement . updatePosition ( this . xPos , this . zPos , currentUnitValue )
134
+ if ( this . uiElement ) this . uiElement . updatePosition ( this . xPos , this . zPos , currentUnitValue ) ;
135
+
136
+ if ( this . nameText ) {
137
+ const offset = new Vector3 ( - 1.5 , - 1.8 , 0.1 ) ; // Change the offset's value to change the text's position
138
+ const basePosition = new Vector3 ( this . xPos , this . zPos , this . yPos ) ;
139
+ this . nameText . position . copy ( basePosition . add ( offset ) ) ;
140
+ }
141
+
117
142
}
118
143
119
144
this . update = function ( )
0 commit comments