Skip to content

Commit a464b35

Browse files
author
Léna Voinchet
committed
Add LiDAR's name on the scene
1 parent 33a6fd3 commit a464b35

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

js/scene/SceneManager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class SceneManager{
135135
this.initScene = function(floor, wallX, wallY)
136136
{
137137
// Lighting
138-
const ambient = new AmbientLight( 0xffffff, 1);
138+
const ambient = new AmbientLight( 0xffffff, 1.8);
139139
this.scene.add(ambient);
140140

141141
// Floor
@@ -265,7 +265,7 @@ class SceneManager{
265265

266266
function buildGridHelper()
267267
{
268-
const gridHelper = new GridHelper( 2000, 2000, 0x444444, 0x444444 );
268+
const gridHelper = new GridHelper( 2000, 2000, 0x555555, 0x555555 );
269269
gridHelper.position.y = -0.001
270270

271271
return gridHelper;

js/scene/objects/sensors/Lidar.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {
55
MeshPhongMaterial,
66
MeshBasicMaterial,
77
Mesh,
8+
Vector3,
89
LineSegments,
910
Color,
1011
Group
1112
} from 'three';
1213

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';
1417

1518

1619
class Lidar{
@@ -19,6 +22,7 @@ class Lidar{
1922
static DEFAULT_LIDAR_SIZE = 0.1;
2023
static DEFAULT_MIN_ANGLE_TO_AVOID_OBSTRUCTION = Math.PI/180 * 60;
2124
static DEFAULT_RATIO_FAR_MINDIST = 2;
25+
static SIZE_TEXT_LIDAR = 0.6;
2226

2327
constructor(id, lidarTypeID = Lidar.DEFAULT_LIDAR_TYPE_ID, p_x = 0, p_z = Lidar.DEFAULT_LIDAR_HOOK_HEIGHT, r_y = 0)
2428
{
@@ -37,6 +41,8 @@ class Lidar{
3741
this.mesh = buildMesh(this.color, this.xPos, Lidar.DEFAULT_LIDAR_SIZE, this.zPos);
3842
this.rays = new Group();
3943

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+
4046
this.raysAppear = true;
4147

4248
/* BUILDERS */
@@ -53,6 +59,15 @@ class Lidar{
5359
return mesh;
5460
}
5561

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+
5671
this.buildRays = function()
5772
{
5873
const material = new MeshBasicMaterial( {color: this.color, transparent: true, opacity: 0.4, alphaTest: 0.3 } );
@@ -89,12 +104,14 @@ class Lidar{
89104
{
90105
scene.add(this.mesh);
91106
scene.add(this.rays);
107+
scene.add(this.nameText);
92108
}
93109

94110
this.removeFromScene = function(scene)
95111
{
96112
scene.remove(this.mesh);
97113
scene.remove(this.rays);
114+
scene.remove(this.nameText);
98115
}
99116

100117
/* USER'S ACTION */
@@ -103,6 +120,7 @@ class Lidar{
103120
const value = display;
104121
this.raysAppear = value;
105122
this.rays.visible = value;
123+
this.nameText.visible = value;
106124

107125
if(this.uiElement) this.uiElement.changeVisibility(value);
108126
}
@@ -113,7 +131,14 @@ class Lidar{
113131
this.zPos = this.mesh.position.y;
114132
this.rays.position.set(this.xPos, this.zPos, this.yPos);
115133

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+
117142
}
118143

119144
this.update = function()

js/scene/objects/sensors/Node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Node{
4747
this.areaAppear = true;
4848
this.areaValue = 0;
4949

50-
this.nameText = buildTextMesh("Node " + (this.id+1), Node.SIZE_TEXT_NODE, this.xPos - Node.SIZE_TEXT_NODE * 2, this.yPos + Node.SIZE_TEXT_NODE/2.0, this.zPos - (this.cameraType.rangeFar - 1))
50+
this.nameText = buildTextMesh("Cam " + (this.id+1), Node.SIZE_TEXT_NODE, this.xPos - Node.SIZE_TEXT_NODE * 2, this.yPos + Node.SIZE_TEXT_NODE/2.0, this.zPos - (this.cameraType.rangeFar - 1))
5151
this.areaValueText = buildTextMesh("AREA VALUE", Node.SIZE_TEXT_NODE * 2/3.0, this.xPos - Node.SIZE_TEXT_NODE * 4/3.0, this.yPos + 3*Node.SIZE_TEXT_NODE/2.0, this.zPos - (this.cameraType.rangeFar - 1));
5252

5353
/* BUILDERS */

0 commit comments

Comments
 (0)