Skip to content

Commit

Permalink
[3D] correctly compute near/far planes when a scene is reloaded (qgis…
Browse files Browse the repository at this point in the history
…#55632)

* qgs3dmapcanvaswidget: Directly use canvas cameracontroller method

* qgs3dmapcanvas: Update the navigation widget on near/far plane changes

`Qgs3DNavigationWidget` is updated when the camera parameters are
updated by `QgsCameraController`. However, the near far planes of the
camera can be updated from the `Qgs3DMapScene`. In that case, the
`Qgs3DNavigationWidget` also neeeds to be updated.

This issue is fixed by listening to the near/far plane changes from
the scene camera in `Qgs3DMapCanvas`.

* qgs3dmapscene: Ensure to update near/far planes on new entity creation

The near/far planes are computed in `Qgs3DMapScene` when the camera
parameters have changed. Their values depend on the bounding boxes of
the visible entities. However, the near and far planes are not
recomputed when a new entity is added.
This can be problematic for entities from a vector layer because their
vertical extent is unknown when the associated bounding boxes are
created.

This issue is fixed by calling
`Qgs3DMapscene::updateCameraNearFarPlanes` when a new scene entity is
created. Indeed, on a new scene entity, the exact exact bounding box
has been computed by the loader of the chunked entity.
  • Loading branch information
ptitjano authored Jan 22, 2024
1 parent cfbb13f commit 2e7c0e6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ void Qgs3DMapScene::addLayerEntity( QgsMapLayer *layer )
connect( sceneNewEntity, &Qgs3DMapSceneEntity::newEntityCreated, this, [this]( Qt3DCore::QEntity * entity )
{
finalizeNewEntity( entity );
// this ensures to update the near/far planes with the exact bounding box of the new entity.
updateCameraNearFarPlanes();
} );

connect( sceneNewEntity, &Qgs3DMapSceneEntity::pendingJobsCountChanged, this, &Qgs3DMapScene::totalPendingJobsCountChanged );
Expand Down
6 changes: 5 additions & 1 deletion src/app/3d/qgs3dmapcanvaswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,11 @@ void Qgs3DMapCanvasWidget::setMapSettings( Qgs3DMapSettings *map )
connect( mCanvas->scene(), &Qgs3DMapScene::totalPendingJobsCountChanged, this, &Qgs3DMapCanvasWidget::onTotalPendingJobsCountChanged );
connect( mCanvas->scene(), &Qgs3DMapScene::gpuMemoryLimitReached, this, &Qgs3DMapCanvasWidget::onGpuMemoryLimitReached );

mAnimationWidget->setCameraController( mCanvas->scene()->cameraController() );
// update the navigation widget when the near/far planes have been updated by the map scene
connect( mCanvas->cameraController()->camera(), &Qt3DRender::QCamera::nearPlaneChanged, mNavigationWidget, &Qgs3DNavigationWidget::updateFromCamera );
connect( mCanvas->cameraController()->camera(), &Qt3DRender::QCamera::farPlaneChanged, mNavigationWidget, &Qgs3DNavigationWidget::updateFromCamera );

mAnimationWidget->setCameraController( mCanvas->cameraController() );
mAnimationWidget->setMap( map );

// Disable button for switching the map theme if the terrain generator is a mesh, or if there is no terrain
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e7c0e6

Please sign in to comment.