18#include <Qt3DRender/QCamera>
19#include <Qt3DRender/QMesh>
20#include <Qt3DRender/QRenderSettings>
21#include <Qt3DRender/QSceneLoader>
22#include <Qt3DExtras/QForwardRenderer>
23#include <Qt3DExtras/QPhongMaterial>
24#include <Qt3DExtras/QPhongAlphaMaterial>
25#include <Qt3DExtras/QDiffuseSpecularMaterial>
26#include <Qt3DExtras/QSphereMesh>
27#include <Qt3DLogic/QFrameAction>
28#include <Qt3DRender/QEffect>
29#include <Qt3DRender/QTechnique>
30#include <Qt3DRender/QRenderPass>
31#include <Qt3DRender/QRenderState>
32#include <Qt3DRender/QCullFace>
33#include <Qt3DRender/QDepthTest>
38#include <QOpenGLContext>
39#include <QOpenGLFunctions>
92 onBackgroundColorChanged();
97 mEngine->
renderSettings()->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );
99 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
102 float aspectRatio = ( float )viewportRect.width() / viewportRect.height();
103 mEngine->
camera()->lens()->setPerspectiveProjection( mMap.
fieldOfView(), aspectRatio, 10.f, 10000.0f );
105 mFrameAction =
new Qt3DLogic::QFrameAction();
106 connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered,
107 this, &Qgs3DMapScene::onFrameTriggered );
108 addComponent( mFrameAction );
114 addCameraViewCenterEntity( mEngine->
camera() );
115 addCameraRotationCenterEntity( mCameraController );
120 createTerrainDeferred();
149 const QList<QgsMapLayer *> modelVectorLayers = mModelVectorLayers;
155 if ( renderer->
type() == QLatin1String(
"vector" ) )
158 if ( pointSymbol->
shapeProperty( QStringLiteral(
"model" ) ).toString() == url )
160 removeLayerEntity( layer );
161 addLayerEntity( layer );
164 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
167 for (
auto rule : rules )
170 if ( pointSymbol->
shapeProperty( QStringLiteral(
"model" ) ).toString() == url )
172 removeLayerEntity( layer );
173 addLayerEntity( layer );
188 onSkyboxSettingsChanged();
193 onEyeDomeShadingSettingsChanged();
195 onDebugShadowMapSettingsChanged();
196 onDebugDepthMapSettingsChanged();
198 onAmbientOcclusionSettingsChanged();
201 onCameraMovementSpeedChanged();
203 on3DAxisSettingsChanged();
210 const double side = std::max( extent.
width(), extent.
height() );
211 double d = side / 2 / std::tan(
cameraController()->camera()->fieldOfView() / 2 * M_PI / 180 );
213 mCameraController->
resetView(
static_cast< float >( d ) );
224 float xSide = std::abs( p1.
x() - p2.
x() );
225 float ySide = std::abs( p1.
z() - p2.
z() );
228 float fov = 2 * std::atan( std::tan( qDegreesToRadians(
cameraController()->camera()->fieldOfView() ) / 2 ) *
cameraController()->camera()->aspectRatio() );
229 float r = xSide / 2.0f / std::tan( fov / 2.0f );
234 float fov = qDegreesToRadians(
cameraController()->camera()->fieldOfView() );
235 float r = ySide / 2.0f / std::tan( fov / 2.0f );
242 Qt3DRender::QCamera *camera = mCameraController->
camera();
243 QVector<QgsPointXY> extent;
244 QVector<int> pointsOrder = { 0, 1, 3, 2 };
245 for (
int i : pointsOrder )
247 const QPoint p( ( ( i >> 0 ) & 1 ) ? 0 : mEngine->
size().width(), ( ( i >> 1 ) & 1 ) ? 0 : mEngine->
size().height() );
249 QVector3D dir = ray.direction();
250 if ( dir.y() == 0.0 )
251 dir.setY( 0.000001 );
252 double t = - ray.origin().y() / dir.y();
256 t = camera->farPlane();
261 t = std::min<float>( t, camera->farPlane() );
263 QVector3D planePoint = ray.origin() + t * dir;
272 return mTerrain ? mTerrain->pendingJobsCount() : 0;
278 for ( Qgs3DMapSceneEntity *entity : std::as_const( mSceneEntities ) )
279 count += entity->pendingJobsCount();
285 Qt3DRender::QCamera *camera = mCameraController->
camera();
286 float fov = camera->fieldOfView();
287 const QSize size = mEngine->
size();
288 float screenSizePx = std::max( size.width(), size.height() );
292 float frustumWidthAtDistance = 2 * distance * tan( fov / 2 );
293 float err = frustumWidthAtDistance * epsilon / screenSizePx;
297void Qgs3DMapScene::onCameraChanged()
299 if ( mMap.
projectionType() == Qt3DRender::QCameraLens::OrthographicProjection )
301 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
302 const float viewWidthFromCenter = mCameraController->
distance();
303 const float viewHeightFromCenter = viewportRect.height() * viewWidthFromCenter / viewportRect.width();
304 mEngine->
camera()->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mEngine->
camera()->nearPlane(), mEngine->
camera()->farPlane() );
308 bool changedCameraPlanes = updateCameraNearFarPlanes();
310 if ( changedCameraPlanes )
315 updateCameraNearFarPlanes();
318 onShadowSettingsChanged();
324void Qgs3DMapScene::updateScene(
bool forceUpdate )
326 if ( !mSceneUpdatesEnabled )
333 QgsEventTracing::addEvent( QgsEventTracing::Instant, QStringLiteral(
"3D" ), QStringLiteral(
"Update Scene" ) );
335 Qgs3DMapSceneEntity::SceneContext sceneContext;
336 Qt3DRender::QCamera *camera = mEngine->
camera();
337 sceneContext.cameraFov = camera->fieldOfView();
338 sceneContext.cameraPos = camera->position();
339 const QSize size = mEngine->
size();
340 sceneContext.screenSizePx = std::max( size.width(), size.height() );
341 sceneContext.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
344 for ( Qgs3DMapSceneEntity *entity : std::as_const( mSceneEntities ) )
346 if ( forceUpdate || ( entity->isEnabled() && entity->needsUpdate() ) )
348 entity->handleSceneUpdate( sceneContext );
349 if ( entity->hasReachedGpuMemoryLimit() )
357bool Qgs3DMapScene::updateCameraNearFarPlanes()
372 QMatrix4x4 viewMatrix = camera->viewMatrix();
378 for ( Qgs3DMapSceneEntity *se : std::as_const( mSceneEntities ) )
380 const QgsRange<float> depthRange = se->getNearFarPlaneRange( viewMatrix );
382 fnear = std::min( fnear, depthRange.
lower() );
383 ffar = std::max( ffar, depthRange.
upper() );
392 if ( fnear == 1e9 && ffar == 0 )
402 std::swap( fnear, ffar );
405 float newFar = ffar * 2;
406 float newNear = fnear / 2;
409 camera->setFarPlane( newFar );
410 camera->setNearPlane( newNear );
417void Qgs3DMapScene::onFrameTriggered(
float dt )
424 static int frameCount = 0;
425 static float accumulatedTime = 0.0f;
435 accumulatedTime += dt;
436 if ( accumulatedTime >= 0.2f )
438 float fps = ( float )frameCount / accumulatedTime;
440 accumulatedTime = 0.0f;
445void Qgs3DMapScene::createTerrain()
449 mSceneEntities.removeOne( mTerrain );
455 if ( !mTerrainUpdateScheduled )
458 QTimer::singleShot( 0,
this, &Qgs3DMapScene::createTerrainDeferred );
459 mTerrainUpdateScheduled =
true;
468void Qgs3DMapScene::createTerrainDeferred()
477 mMap.
terrainGenerator()->setupQuadtree( rootBbox, rootError, maxZoomLevel, clippingBbox );
479 mTerrain =
new QgsTerrainEntity( &mMap );
480 mTerrain->setParent(
this );
483 mSceneEntities << mTerrain;
487 connect( mTerrain, &Qgs3DMapSceneEntity::newEntityCreated,
this, [
this]( Qt3DCore::QEntity * entity )
490 handleClippingOnEntity( entity );
503 removeLayerEntity( layer );
506 addLayerEntity( layer );
511 mTerrainUpdateScheduled =
false;
514void Qgs3DMapScene::onBackgroundColorChanged()
519void Qgs3DMapScene::updateLights()
521 for ( Qt3DCore::QEntity *entity : std::as_const( mLightEntities ) )
522 entity->deleteLater();
523 mLightEntities.clear();
525 const QList< QgsLightSource * > newLights = mMap.
lightSources();
528 mLightEntities.append( source->createEntity( mMap,
this ) );
531 onShadowSettingsChanged();
534void Qgs3DMapScene::updateCameraLens()
541void Qgs3DMapScene::onLayerRenderer3DChanged()
543 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
547 removeLayerEntity( layer );
550 addLayerEntity( layer );
553void Qgs3DMapScene::onLayersChanged()
555 QSet<QgsMapLayer *> layersBefore = qgis::listToSet( mLayerEntities.keys() );
556 QList<QgsMapLayer *> layersAdded;
560 if ( !layersBefore.contains( layer ) )
562 layersAdded << layer;
566 layersBefore.remove( layer );
571 for (
QgsMapLayer *layer : std::as_const( layersBefore ) )
573 removeLayerEntity( layer );
576 for (
QgsMapLayer *layer : std::as_const( layersAdded ) )
578 addLayerEntity( layer );
584 const QList<QgsMapLayer * >
layers = mLayerEntities.keys();
589 if ( temporalProperties->isActive() )
591 removeLayerEntity( layer );
592 addLayerEntity( layer );
598void Qgs3DMapScene::addLayerEntity(
QgsMapLayer *layer )
600 bool needsSceneUpdate =
false;
609 ( renderer->
type() == QLatin1String(
"vector" ) || renderer->
type() == QLatin1String(
"rulebased" ) ) )
612 if ( renderer->
type() == QLatin1String(
"vector" ) )
620 mModelVectorLayers.append( layer );
624 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
627 for (
auto rule : rules )
632 mModelVectorLayers.append( layer );
660 Qt3DCore::QEntity *newEntity = renderer->
createEntity( &mMap );
663 newEntity->setParent(
this );
664 mLayerEntities.insert( layer, newEntity );
666 finalizeNewEntity( newEntity );
668 if ( Qgs3DMapSceneEntity *sceneNewEntity = qobject_cast<Qgs3DMapSceneEntity *>( newEntity ) )
670 needsSceneUpdate =
true;
671 mSceneEntities.append( sceneNewEntity );
673 connect( sceneNewEntity, &Qgs3DMapSceneEntity::newEntityCreated,
this, [
this]( Qt3DCore::QEntity * entity )
675 finalizeNewEntity( entity );
677 updateCameraNearFarPlanes();
685 if ( needsSceneUpdate )
710void Qgs3DMapScene::removeLayerEntity(
QgsMapLayer *layer )
712 Qt3DCore::QEntity *entity = mLayerEntities.take( layer );
714 if ( Qgs3DMapSceneEntity *sceneEntity = qobject_cast<Qgs3DMapSceneEntity *>( entity ) )
716 mSceneEntities.removeOne( sceneEntity );
720 entity->deleteLater();
729 mModelVectorLayers.removeAll( layer );
745void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
748 handleClippingOnEntity( newEntity );
752 const QList< QgsLineMaterial *> childLineMaterials = newEntity->findChildren<QgsLineMaterial *>();
753 for ( QgsLineMaterial *lm : childLineMaterials )
757 lm->setViewportSize( mEngine->
size() );
760 lm->setViewportSize( mEngine->
size() );
768 bm->setViewportSize( mEngine->
size() );
777 const QList< Qt3DRender::QMaterial *> childMaterials = newEntity->findChildren<Qt3DRender::QMaterial *>();
778 for ( Qt3DRender::QMaterial *material : childMaterials )
781 if ( Qt3DExtras::QDiffuseSpecularMaterial *ph = qobject_cast<Qt3DExtras::QDiffuseSpecularMaterial *>( material ) )
783 if ( ph->diffuse().value<QColor>().alphaF() != 1.0f )
785 Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( ph->parent() );
786 if ( entity && !entity->components().contains( transparentLayer ) )
788 entity->addComponent( transparentLayer );
795 Qt3DRender::QEffect *effect = material->effect();
798 const QVector< Qt3DRender::QParameter *> parameters = effect->parameters();
799 for (
const Qt3DRender::QParameter *parameter : parameters )
801 if ( parameter->name() ==
"opacity" && parameter->value() != 1.0f )
803 Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( material->parent() );
804 if ( entity && !entity->components().contains( transparentLayer ) )
806 entity->addComponent( transparentLayer );
816int Qgs3DMapScene::maximumTextureSize()
const
818 QSurface *surface = mEngine->
surface();
819 QOpenGLContext context;
821 bool success = context.makeCurrent( surface );
825 QOpenGLFunctions openglFunctions = QOpenGLFunctions( &context );
828 openglFunctions.initializeOpenGLFunctions();
829 openglFunctions.glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size );
839void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
841 mEntityCameraViewCenter =
new Qt3DCore::QEntity;
843 Qt3DCore::QTransform *trCameraViewCenter =
new Qt3DCore::QTransform;
844 mEntityCameraViewCenter->addComponent( trCameraViewCenter );
845 connect( camera, &Qt3DRender::QCamera::viewCenterChanged,
this, [trCameraViewCenter, camera]
847 trCameraViewCenter->setTranslation( camera->viewCenter() );
850 Qt3DExtras::QPhongMaterial *materialCameraViewCenter =
new Qt3DExtras::QPhongMaterial;
851 materialCameraViewCenter->setAmbient( Qt::red );
852 mEntityCameraViewCenter->addComponent( materialCameraViewCenter );
854 Qt3DExtras::QSphereMesh *rendererCameraViewCenter =
new Qt3DExtras::QSphereMesh;
855 rendererCameraViewCenter->setRadius( 10 );
856 mEntityCameraViewCenter->addComponent( rendererCameraViewCenter );
859 mEntityCameraViewCenter->setParent(
this );
869 if ( mSceneState == state )
875void Qgs3DMapScene::updateSceneState()
877 if ( mTerrainUpdateScheduled )
883 for ( Qgs3DMapSceneEntity *entity : std::as_const( mSceneEntities ) )
885 if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
892 setSceneState(
Ready );
895void Qgs3DMapScene::onSkyboxSettingsChanged()
900 mSkybox->deleteLater();
908 QMap<QString, QString> faces;
914 faces[QStringLiteral(
"posX" )], faces[QStringLiteral(
"posY" )], faces[QStringLiteral(
"posZ" )],
915 faces[QStringLiteral(
"negX" )], faces[QStringLiteral(
"negY" )], faces[QStringLiteral(
"negZ" )],
926void Qgs3DMapScene::onShadowSettingsChanged()
930 const QList< QgsLightSource * > lightSources = mMap.
lightSources();
931 QList< QgsDirectionalLightSettings * > directionalLightSources;
936 directionalLightSources << qgis::down_cast< QgsDirectionalLightSettings * >( source );
942 if ( shadowSettings.
renderShadows() && selectedLight >= 0 && selectedLight < directionalLightSources.count() )
954void Qgs3DMapScene::onAmbientOcclusionSettingsChanged()
964void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
969void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
974void Qgs3DMapScene::onDebugOverlayEnabledChanged()
980void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
988void Qgs3DMapScene::onCameraMovementSpeedChanged()
993void Qgs3DMapScene::onCameraNavigationModeChanged()
1000 QVector<QString> notParsedLayers;
1010 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1013 Qt3DCore::QEntity *rootEntity = it.value();
1015 switch ( layerType )
1019 notParsedLayers.push_back( layer->
name() );
1029 notParsedLayers.push_back( layer->
name() );
1039 if ( !notParsedLayers.empty() )
1041 QString message = tr(
"The following layers were not exported:" ) +
"\n";
1042 for (
const QString &layerName : notParsedLayers )
1043 message += layerName +
"\n";
1050 QVector<const QgsChunkNode *> chunks;
1051 if ( !mLayerEntities.contains( layer ) )
return chunks;
1052 if ( QgsChunkedEntity *
c = qobject_cast<QgsChunkedEntity *>( mLayerEntities[ layer ] ) )
1054 const QList< QgsChunkNode * > activeNodes =
c->activeNodes();
1055 for ( QgsChunkNode *n : activeNodes )
1056 chunks.push_back( n );
1068 double yMin = std::numeric_limits< double >::max();
1069 double yMax = std::numeric_limits< double >::lowest();
1072 const QgsAABB bbox = mTerrain->rootNode()->bbox();
1073 yMin = std::min( yMin,
static_cast< double >( bbox.
yMin ) );
1074 yMax = std::max( yMax,
static_cast< double >( bbox.
yMax ) );
1077 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); it++ )
1080 switch ( layer->
type() )
1086 yMin = std::min( yMin, zRange.
lower() );
1087 yMax = std::max( yMax, zRange.
upper() );
1092 QgsMeshLayer *meshLayer = qobject_cast< QgsMeshLayer *>( layer );
1100 yMin = std::min( yMin, verticalGroupMetadata.
minimum() * verticalScale );
1101 yMax = std::max( yMax, verticalGroupMetadata.
maximum() * verticalScale );
1111 yMin = std::min( yMin, zRange.
lower() );
1112 yMax = std::max( yMax, zRange.
upper() );
1125 const QgsDoubleRange yRange( std::min( yMin, std::numeric_limits<double>::max() ),
1126 std::max( yMax, std::numeric_limits<double>::lowest() ) );
1137 mEntityRotationCenter =
new Qt3DCore::QEntity;
1139 Qt3DCore::QTransform *trRotationCenter =
new Qt3DCore::QTransform;
1140 mEntityRotationCenter->addComponent( trRotationCenter );
1141 Qt3DExtras::QPhongMaterial *materialRotationCenter =
new Qt3DExtras::QPhongMaterial;
1142 materialRotationCenter->setAmbient( Qt::blue );
1143 mEntityRotationCenter->addComponent( materialRotationCenter );
1144 Qt3DExtras::QSphereMesh *rendererRotationCenter =
new Qt3DExtras::QSphereMesh;
1145 rendererRotationCenter->setRadius( 10 );
1146 mEntityRotationCenter->addComponent( rendererRotationCenter );
1147 mEntityRotationCenter->setEnabled(
false );
1148 mEntityRotationCenter->setParent(
this );
1152 trRotationCenter->setTranslation( center );
1161void Qgs3DMapScene::on3DAxisSettingsChanged()
1180void Qgs3DMapScene::handleClippingOnEntity( QEntity *entity )
const
1182 if ( mClipPlanesEquations.isEmpty() )
1186 material->disableClipping();
1193 material->enableClipping( mClipPlanesEquations );
1199 for ( QObject *child : entity->children() )
1201 Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>( child );
1204 handleClippingOnEntity( childEntity );
1209void Qgs3DMapScene::handleClippingOnAllEntities()
const
1213 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1215 handleClippingOnEntity( it.value() );
1219 handleClippingOnEntity( mTerrain );
1225 if ( clipPlaneEquations.size() > 8 )
1227 QgsDebugMsgLevel( QStringLiteral(
"Qgs3DMapScene::enableClipping: it is not possible to use more than 8 clipping planes." ), 2 );
1229 mClipPlanesEquations = clipPlaneEquations.mid( 0, 8 );
1236 handleClippingOnAllEntities();
1241 mClipPlanesEquations.clear();
1248 handleClippingOnAllEntities();
LayerType
Types of layers that can be added to a map.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
@ Directional
Directional light source.
void onAxisSettingsChanged()
Force update of the axis and the viewport when a setting has changed.
Manages the various settings the user can choose from when exporting a 3D scene 3.
bool exportNormals() const
Returns whether normals will be exported.
int terrrainResolution() const
Returns the terrain resolution.
QString sceneFolderPath() const
Returns the scene folder path.
float scale() const
Returns the scale of the exported model.
int terrainTextureResolution() const
Returns the terrain texture resolution.
QString sceneName() const
Returns the scene name.
bool smoothEdges() const
Returns whether triangles edges will look smooth.
bool exportTextures() const
Returns whether textures will be exported.
QVector< const QgsChunkNode * > getLayerActiveChunkNodes(QgsMapLayer *layer)
Returns the active chunk nodes of layer.
void exportScene(const Qgs3DMapExportSettings &exportSettings)
Exports the scene according to the scene export settings.
void terrainPendingJobsCountChanged()
Emitted when the number of terrain's pending jobs changes.
void viewed2DExtentFrom3DChanged(QVector< QgsPointXY > extent)
Emitted when the viewed 2D extent seen by the 3D camera has changed.
void fpsCountChanged(float fpsCount)
Emitted when the FPS count changes.
void setViewFrom2DExtent(const QgsRectangle &extent)
Resets camera view to show the extent extent (top view)
void disableClipping()
Disables OpenGL clipping.
Qgs3DMapScene(Qgs3DMapSettings &map, QgsAbstract3DEngine *engine)
Constructs a 3D scene based on map settings and Qt 3D renderer configuration.
QgsAbstract3DEngine * engine() const
Returns the abstract 3D engine.
void gpuMemoryLimitReached()
Emitted when one of the entities reaches its GPU memory limit and it is not possible to lower the GPU...
QgsDoubleRange elevationRange() const
Returns the scene's elevation range.
QgsCameraController * cameraController() const
Returns camera controller.
SceneState
Enumeration of possible states of the 3D scene.
@ Ready
The scene is fully loaded/updated.
@ Updating
The scene is still being loaded/updated.
int totalPendingJobsCount() const
Returns number of pending jobs for all chunked entities.
void updateTemporal()
Updates the temporale entities.
static Q_DECL_DEPRECATED QMap< QString, Qgs3DMapScene * > openScenes()
Returns a map of 3D map scenes (by name) open in the QGIS application.
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is activated or deactivated.
QgsRectangle sceneExtent() const
Returns the scene extent in the map's CRS.
void sceneStateChanged()
Emitted when the scene's state has changed.
int terrainPendingJobsCount() const
Returns number of pending jobs of the terrain entity.
QList< QgsMapLayer * > layers() const
Returns the layers that contain chunked entities.
QVector< QgsPointXY > viewFrustum2DExtent() const
Calculates the 2D extent viewed by the 3D camera as the vertices of the viewed trapezoid.
void enableClipping(const QList< QVector4D > &clipPlaneEquations)
Enables OpenGL clipping based on the planes equations defined in clipPlaneEquations.
float worldSpaceError(float epsilon, float distance) const
Given screen error (in pixels) and distance from camera (in 3D world coordinates),...
void terrainEntityChanged()
Emitted when the current terrain entity is replaced by a new one.
static std::function< QMap< QString, Qgs3DMapScene * >() > sOpenScenesFunction
Static function for returning open 3D map scenes.
void viewZoomFull()
Resets camera view to show the whole scene (top view)
void extentChanged()
Emitted when the 3d view's 2d extent has changed.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
bool isDebugOverlayEnabled() const
Returns whether debug overlay is enabled.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
void eyeDomeLightingDistanceChanged()
Emitted when the eye dome lighting distance has changed.
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
double cameraMovementSpeed() const
Returns the camera movement speed.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
void debugDepthMapSettingsChanged()
Emitted when depth map debugging has changed.
Qgis::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
void backgroundColorChanged()
Emitted when the background color has changed.
Qt::Corner debugShadowMapCorner() const
Returns the corner where the shadow map preview is displayed.
bool showCameraViewCenter() const
Returns whether to show camera's view center as a sphere (for debugging)
void showCameraRotationCenterChanged()
Emitted when the flag whether camera's rotation center is shown has changed.
void cameraNavigationModeChanged()
Emitted when the camera navigation mode was changed.
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
void eyeDomeLightingEnabledChanged()
Emitted when the flag whether eye dome lighting is used has changed.
void debugOverlayEnabledChanged(bool debugOverlayEnabled)
Emitted when the debug overaly is enabled or disabled.
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
QList< QgsLightSource * > lightSources() const
Returns list of directional light sources defined in the scene.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
void projectionTypeChanged()
Emitted when the camera lens projection type changes.
float fieldOfView() const
Returns the camera lens' field of view.
QgsAmbientOcclusionSettings ambientOcclusionSettings() const
Returns the current configuration of screen space ambient occlusion.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image)
void lightSourcesChanged()
Emitted when any of the light source settings in the map changes.
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
QColor backgroundColor() const
Returns background color of the 3D map view.
double debugShadowMapSize() const
Returns the size of the shadow map preview.
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool terrainRenderingEnabled() const
Returns whether the 2D terrain surface will be rendered.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is enabled or disabled.
void axisSettingsChanged()
Emitted when 3d axis rendering settings are changed.
void ambientOcclusionSettingsChanged()
Emitted when ambient occlusion rendering settings are changed.
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
void eyeDomeLightingStrengthChanged()
Emitted when the eye dome lighting strength has changed.
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
bool isFpsCounterEnabled() const
Returns whether FPS counter label is enabled.
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
void debugShadowMapSettingsChanged()
Emitted when shadow map debugging has changed.
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0).
bool showCameraRotationCenter() const
Returns whether to show camera's rotation center as a sphere (for debugging)
Entity that handles the exporting of 3D scene.
void save(const QString &sceneName, const QString &sceneFolderPath, int precision=6)
Saves the scene to a .obj file.
void setExportTextures(bool exportTextures)
Sets whether the textures will be exported.
void parseTerrain(QgsTerrainEntity *terrain, const QString &layer)
Creates terrain export objects from the terrain entity.
void setTerrainResolution(int resolution)
Sets the terrain resolution.
void setTerrainTextureResolution(int resolution)
Sets the terrain texture resolution.
bool parseVectorLayerEntity(Qt3DCore::QEntity *entity, QgsVectorLayer *layer)
Creates necessary export objects from entity if it represents valid vector layer entity Returns false...
void setScale(float scale)
Sets the scale of the exported 3D model.
void setExportNormals(bool exportNormals)
Sets whether the normals will be exported.
void setSmoothEdges(bool smoothEdges)
Sets whether the triangles will look smooth.
static int maxZoomLevel(double tile0width, double tileResolution, double maxError)
Calculates the highest needed zoom level for tiles in quad-tree given width of the base tile (zoom le...
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
static void computeBoundingBoxNearFarPlanes(const QgsAABB &bbox, const QMatrix4x4 &viewMatrix, float &fnear, float &ffar)
This routine computes nearPlane farPlane from the closest and farthest corners point of bounding box ...
static QgsRay3D rayFromScreenPoint(const QPoint &point, const QSize &windowSize, Qt3DRender::QCamera *camera)
Convert from clicked point on the screen to a ray in world coordinates.
void sizeChanged()
Emitted after a call to setSize()
virtual QSurface * surface() const =0
Returns the surface of the engine.
virtual Qt3DRender::QCamera * camera()=0
Returns pointer to the engine's camera entity.
virtual void setClearColor(const QColor &color)=0
Sets background color of the scene.
virtual void setFrustumCullingEnabled(bool enabled)=0
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...
QgsFrameGraph * frameGraph()
Returns the shadow rendering frame graph object used to render the scene.
virtual QSize size() const =0
Returns size of the engine's rendering area in pixels.
virtual Qt3DRender::QRenderSettings * renderSettings()=0
Returns access to the engine's render settings (the frame graph can be accessed from here)
Base class for all renderers that may to participate in 3D view.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
virtual Qt3DCore::QEntity * createEntity(Qgs3DMapSettings *map) const =0
Returns a 3D entity that will be used to show renderer's data in 3D scene.
class containing the configuration of ambient occlusion rendering 3
float radius() const
Returns the radius parameter of the ambient occlusion effect.
bool isEnabled() const
Returns whether ambient occlusion effect is enabled.
float intensity() const
Returns the shading factor of the ambient occlusion effect.
float threshold() const
Returns at what amount of occlusion the effect will kick in.
static QgsSourceCache * sourceCache()
Returns the application's source cache, used for caching embedded and remote source strings as local ...
Qt3DRender::QCamera * camera() const
Returns camera that is being controlled.
float distance() const
Returns distance of the camera from the point it is looking at.
void setCameraNavigationMode(Qgis::NavigationMode navigationMode)
Sets the navigation mode used by the camera controller.
void cameraChanged()
Emitted when camera has been updated.
void frameTriggered(float dt)
Called internally from 3D scene when a new frame is generated. Updates camera according to keyboard/m...
void resetView(float distance)
Move camera back to the initial position (looking down towards origin of world's coordinates)
void setViewFromTop(float worldX, float worldY, float distance, float yaw=0)
Sets camera to look down towards given point in world coordinate, in given distance from plane with z...
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void cameraRotationCenterChanged(QVector3D position)
Emitted when the camera rotation center changes.
A skybox constructed from a 6 cube faces.
QgsRange which stores a range of double values.
bool isInfinite() const
Returns true if the range consists of all possible values.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void removeClipPlanes()
Disables OpenGL clipping.
void setShadowBias(float shadowBias)
Sets the shadow bias value.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
void setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
void setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
virtual QgsDoubleRange calculateZRange(QgsMapLayer *layer) const
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
Base class for storage of map layer temporal properties.
Base class for all map layer types.
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
void rendererChanged()
Signal emitted when renderer is changed.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
void layerModified()
Emitted when modifications has been done on layer.
double verticalScale() const
Returns mesh vertical scale.
int verticalDatasetGroupIndex() const
Returns the index of the dataset group that will be used to render the vertical component of the 3D m...
void setMaximumTextureSize(int maximumTextureSize)
Sets the maximum texture size supported by the hardware Used to store the GL_MAX_TEXTURE_SIZE value t...
QgsMesh3DSymbol * clone() const override SIP_FACTORY
Returns a new instance of the symbol with the same settings.
3D renderer that renders all mesh triangles of a mesh layer.
void setSymbol(QgsMesh3DSymbol *symbol)
Sets 3D symbol associated with the renderer.
const QgsMesh3DSymbol * symbol() const
Returns 3D symbol associated with the renderer.
void setLayer(QgsMeshLayer *layer)
Sets vector layer associated with the renderer.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
A skybox constructed from a panoramic image.
void setViewportSize(const QSizeF size)
Set the size of the view port.
Qgis::Point3DShape shape() const
Returns 3D shape for points.
QVariant shapeProperty(const QString &property) const
Returns the value for a specific shape property.
3D renderer that renders all points from a point cloud layer
void setLayer(QgsPointCloudLayer *layer)
Sets point cloud layer associated with the renderer.
Represents a map layer supporting display of point clouds.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
A class to represent a 2D point.
A template based class for storing ranges (lower to upper values).
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
bool isEmpty() const
Returns true if the range is empty, ie the lower bound equals (or exceeds) the upper bound and either...
A representation of a ray in 3D.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double width() const
Returns the width of the rectangle.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsPointXY center() const
Returns the center point of the rectangle.
double height() const
Returns the height of the rectangle.
QList< QgsRuleBased3DRenderer::Rule * > RuleList
class containing the configuration of shadows rendering 3
int selectedDirectionalLight() const
Returns the selected direcctional light used to cast shadows.
bool renderShadows() const
Returns whether shadow rendering is enabled.
int shadowMapResolution() const
Returns the resolution of the shadow map texture used to generate the shadows.
double maximumShadowRenderingDistance() const
Returns the maximum shadow rendering distance accounted for when rendering shadows Objects further aw...
double shadowBias() const
Returns the shadow bias used to correct the numerical imprecision of shadows (for the depth test) Thi...
Contains the configuration of a skybox entity.
QMap< QString, QString > cubeMapFacesPaths() const
Returns a map containing the path of each texture specified by the user.
QgsSkyboxEntity::SkyboxType skyboxType() const
Returns the type of the skybox.
QString panoramicTexturePath() const
Returns the panoramic texture path of a skybox of type "Panormaic skybox".
void remoteSourceFetched(const QString &url)
Emitted when the cache has finished retrieving a 3D model from a remote url.
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
virtual QgsAABB rootChunkBbox(const Qgs3DMapSettings &map) const
Returns bounding box of the root chunk.
virtual QgsRectangle rootChunkExtent() const =0
extent of the terrain's root chunk in terrain's CRS
void setLayer(QgsTiledSceneLayer *layer)
Sets tiled scene layer associated with the renderer.
Represents a map layer supporting display of tiled scene objects.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
double y() const
Returns Y coordinate.
double z() const
Returns Z coordinate.
double x() const
Returns X coordinate.
3D renderer that renders all features of a vector layer with the same 3D symbol.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsFloatNear(float a, float b, float epsilon=4 *FLT_EPSILON)
Compare two floats (but allow some difference)
#define QgsDebugMsgLevel(str, level)