Skip to content

Commit 2228935

Browse files
author
Léna Voinchet
committed
Update function changeLidarType
1 parent 01d7659 commit 2228935

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed

js/UI/LidarUI.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,26 +212,26 @@ class LidarUI{
212212

213213
function changeLidarType()
214214
{
215-
lidar.lidarType = getLidarsTypes().find(type => type.name === document.getElementById('lidar-type-' + lidar.id).value);
215+
const newTypeName = document.getElementById(`lidar-type-${lidar.id}`).value;
216+
const newLidarTypeData = getLidarsTypes().find(type => type.name === newTypeName);
216217

217-
sceneManager.scene.remove(lidar.rays);
218-
lidar.rays.children.forEach(r => {
219-
if(r.isLineSegments)
220-
{
221-
r.geometry.dispose();
222-
r.material.dispose();
223-
}
224-
});
225-
lidar.rays.clear();
226-
lidar.buildRays();
227-
sceneManager.scene.add(lidar.rays);
218+
if (!newLidarTypeData) {
219+
console.error("Nouveau type de LiDAR non trouvé:", newTypeName);
220+
return;
221+
}
222+
223+
// STEP 1 : The LiDAR deals with its own type change, recreates the 3D objects, etc
224+
lidar.setType(newLidarTypeData, sceneManager);
228225

226+
// STEP 2 : Update UI with new camera properties
229227
document.getElementById(`lidar-fov${lidar.id}`).innerHTML = lidar.lidarType.fov + '°';
230228
document.getElementById(`lidar-res${lidar.id}`).innerHTML = lidar.lidarType.angularResolution + '°';
231-
document.getElementById(`lidar-near${lidar.id}`).innerHTML = (Math.round(lidar.lidarType.rangeNear*document.getElementById('lidar-near' + lidar.id).dataset.unit * 100) / 100.0);
232-
document.getElementById(`lidar-far${lidar.id}`).innerHTML = (Math.round(lidar.lidarType.rangeFar*document.getElementById('lidar-far' + lidar.id).dataset.unit * 100) / 100.0);
229+
document.getElementById(`lidar-near${lidar.id}`).innerHTML = (Math.round(lidar.lidarType.rangeNear*document.getElementById(`lidar-near${lidar.id}`).dataset.unit * 100) / 100.0);
230+
document.getElementById(`lidar-far${lidar.id}`).innerHTML = (Math.round(lidar.lidarType.rangeFar*document.getElementById(`lidar-far${lidar.id}`).dataset.unit * 100) / 100.0);
233231

232+
// STEP 3 : Save changes
234233
sceneManager.objects.populateStorage();
234+
235235
}
236236

237237
this.changeVisibilityUIOnly = function(visible)

js/UI/NodeUI.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,6 @@ class NodeUI {
233233
// STEP 3 : Save changes
234234
sceneManager.objects.populateStorage();
235235

236-
// STEP 4 : Notify ViewportManager if needed
237-
if (sceneManager.viewportManager && typeof sceneManager.viewportManager.handleCameraInstanceChanged === 'function') {
238-
sceneManager.viewportManager.handleCameraInstanceChanged(node.id, node.cameraPerspective);
239-
}
240-
241-
242236
}
243237

244238
this.changeFar = function()

js/scene/objects/SceneObjects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ class SceneObjects{
258258
console.error(`L'élément select 'cam-type-${newCamera.id}' n'a pas été trouvé pour la duplication.`);
259259
}
260260

261+
// Make sure frustum visibility choice is consistent with the other ones
262+
newCamera.changeFrustumVisibility(node.toggleFrustumOrNot);
263+
261264
this.populateStorage();
262265
}
263266

js/scene/objects/sensors/Lidar.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,43 @@ class Lidar{
204204

205205
}
206206

207+
setType(newLidarTypeData, sceneManager)
208+
{
209+
const scene = sceneManager.scene;
210+
211+
// Remove every ancient element
212+
if (this.rays) {
213+
this.rays.children.forEach(m => {
214+
m.geometry.dispose();
215+
m.material.dispose();
216+
});
217+
this.rays.clear();
218+
this.rays.remove();
219+
}
220+
if (this.raysShapeHelper) scene.remove(this.raysShapeHelper);
221+
if (this.nameText) scene.remove(this.nameText);
222+
223+
// Update LiDAR Type
224+
this.lidarType = newLidarTypeData;
225+
226+
// Rebuild LiDAR
227+
this.buildRays();
228+
this.raysShapeHelper = this.buildRaysOutlineHelper();
229+
230+
// Add every element to the scene
231+
scene.add(this.rays);
232+
scene.add(this.raysShapeHelper);
233+
234+
this.nameText = this.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)
235+
scene.add(this.nameText);
236+
237+
// Adapt Text and Mesh
238+
this.updateTransformation();
239+
240+
// Update visibility
241+
this.changeVisibility(this.lidarAppear);
242+
}
243+
207244
/* SCENE MANAGEMENT */
208245
addToScene(scene)
209246
{

js/scene/objects/sensors/Node.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ class Node{
158158
this.cameraPerspective = newCam;
159159
this.cameraPerspectiveHelper = newCamHelper;
160160

161-
// Adapt Text et Mesh
162-
this.updateTransformation();
163-
164161
// Add every element to the scene
165162
scene.add(this.cameraPerspective);
166163
scene.add(this.cameraPerspectiveHelper);
@@ -172,6 +169,9 @@ class Node{
172169
scene.add(this.areaValueText);
173170
this.updateAreaText(sceneManager.currentUnit);
174171

172+
// Adapt Text et Mesh
173+
this.updateTransformation();
174+
175175
// Update visibility
176176
this.changeVisibility(this.cameraAppear);
177177
}

0 commit comments

Comments
 (0)