18 #include <Qt3DRender/QCamera>
19 #include <Qt3DRender/QMesh>
20 #include <Qt3DRender/QObjectPicker>
21 #include <Qt3DRender/QPickEvent>
22 #include <Qt3DRender/QPickingSettings>
23 #include <Qt3DRender/QPickTriangleEvent>
24 #include <Qt3DRender/QPointLight>
25 #include <Qt3DRender/QDirectionalLight>
26 #include <Qt3DRender/QRenderSettings>
27 #include <Qt3DRender/QSceneLoader>
28 #include <Qt3DExtras/QForwardRenderer>
29 #include <Qt3DExtras/QPhongMaterial>
30 #include <Qt3DExtras/QSphereMesh>
31 #include <Qt3DLogic/QFrameAction>
32 #include <Qt3DRender/QEffect>
33 #include <Qt3DRender/QTechnique>
34 #include <Qt3DRender/QRenderPass>
35 #include <Qt3DRender/QRenderState>
36 #include <Qt3DRender/QCullFace>
37 #include <Qt3DRender/QDepthTest>
42 #include <QOpenGLContext>
43 #include <QOpenGLFunctions>
93 onBackgroundColorChanged();
98 mEngine->
renderSettings()->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );
101 mEngine->
renderSettings()->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking );
103 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
106 float aspectRatio = ( float )viewportRect.width() / viewportRect.height();
107 mEngine->
camera()->lens()->setPerspectiveProjection( mMap.
fieldOfView(), aspectRatio, 10.f, 10000.0f );
109 mFrameAction =
new Qt3DLogic::QFrameAction();
110 connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered,
111 this, &Qgs3DMapScene::onFrameTriggered );
112 addComponent( mFrameAction );
120 addCameraViewCenterEntity( mEngine->
camera() );
125 createTerrainDeferred();
150 const QList<QgsMapLayer *> modelVectorLayers = mModelVectorLayers;
156 if ( renderer->
type() == QLatin1String(
"vector" ) )
159 if ( pointSymbol->
shapeProperties()[QStringLiteral(
"model" )].toString() == url )
161 removeLayerEntity( layer );
162 addLayerEntity( layer );
165 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
168 for (
auto rule : rules )
171 if ( pointSymbol->
shapeProperties()[QStringLiteral(
"model" )].toString() == url )
173 removeLayerEntity( layer );
174 addLayerEntity( layer );
185 onRenderersChanged();
192 ChunkedEntity *testChunkEntity =
new ChunkedEntity( AABB( -500, 0, -500, 500, 100, 500 ), 2.f, 3.f, 7,
new TestChunkLoaderFactory );
193 testChunkEntity->setEnabled(
false );
194 testChunkEntity->setParent(
this );
195 chunkEntities << testChunkEntity;
206 Qt3DCore::QEntity *loaderEntity =
new Qt3DCore::QEntity;
207 Qt3DRender::QSceneLoader *loader =
new Qt3DRender::QSceneLoader;
208 loader->setSource( QUrl(
"file:///home/martin/Downloads/LowPolyModels/tree.dae" ) );
209 loaderEntity->addComponent( loader );
210 loaderEntity->setParent(
this );
214 Qt3DCore::QEntity *meshEntity =
new Qt3DCore::QEntity;
215 Qt3DRender::QMesh *mesh =
new Qt3DRender::QMesh;
216 mesh->setSource( QUrl(
"file:///home/martin/Downloads/LowPolyModels/tree.obj" ) );
217 meshEntity->addComponent( mesh );
218 Qt3DExtras::QPhongMaterial *material =
new Qt3DExtras::QPhongMaterial;
219 material->setAmbient( Qt::red );
220 meshEntity->addComponent( material );
221 Qt3DCore::QTransform *meshTransform =
new Qt3DCore::QTransform;
222 meshTransform->setScale( 1 );
223 meshEntity->addComponent( meshTransform );
224 meshEntity->setParent(
this );
226 onSkyboxSettingsChanged();
231 onEyeDomeShadingSettingsChanged();
233 onDebugShadowMapSettingsChanged();
234 onDebugDepthMapSettingsChanged();
237 onCameraMovementSpeedChanged();
243 float side = std::max( extent.
width(), extent.
height() );
244 float a = side / 2.0f / std::sin( qDegreesToRadians(
cameraController()->camera()->fieldOfView() ) / 2.0f );
246 mCameraController->
resetView( 1.5 * std::sqrt( a * a - side * side ) );
251 return mTerrain ? mTerrain->pendingJobsCount() : 0;
257 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
258 count += entity->pendingJobsCount();
264 if ( mPickHandlers.isEmpty() )
267 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
269 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
270 chunkedEntity->setPickingEnabled(
true );
274 mPickHandlers.append( pickHandler );
279 mPickHandlers.removeOne( pickHandler );
281 if ( mPickHandlers.isEmpty() )
284 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
286 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
287 chunkedEntity->setPickingEnabled(
false );
292 void Qgs3DMapScene::onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent,
QgsFeatureId fid )
294 QgsMapLayer *layer = mLayerEntities.key( qobject_cast<QgsChunkedEntity *>( sender() ) );
304 pickHandler->handlePickOnVectorLayer( vlayer, fid, pickEvent->worldIntersection(), pickEvent );
310 Qt3DRender::QCamera *camera = mCameraController->
camera();
311 float fov = camera->fieldOfView();
312 QRect rect = mCameraController->
viewport();
313 float screenSizePx = std::max( rect.width(), rect.height() );
317 float frustumWidthAtDistance = 2 * distance * tan( fov / 2 );
318 float err = frustumWidthAtDistance * epsilon / screenSizePx;
324 Qt3DRender::QCamera *camera = cameraController->
camera();
325 QgsChunkedEntity::SceneState state;
326 state.cameraFov = camera->fieldOfView();
327 state.cameraPos = camera->position();
328 QRect rect = cameraController->
viewport();
329 state.screenSizePx = std::max( rect.width(), rect.height() );
330 state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
334 void Qgs3DMapScene::onCameraChanged()
336 if ( mMap.
projectionType() == Qt3DRender::QCameraLens::OrthographicProjection )
338 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
339 const float viewWidthFromCenter = mCameraController->
distance();
340 const float viewHeightFromCenter = viewportRect.height() * viewWidthFromCenter / viewportRect.width();
341 mEngine->
camera()->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mEngine->
camera()->nearPlane(), mEngine->
camera()->farPlane() );
345 bool changedCameraPlanes = updateCameraNearFarPlanes();
347 if ( changedCameraPlanes )
352 updateCameraNearFarPlanes();
355 onShadowSettingsChanged();
360 QVector<Qt3DCore::QComponent *> toBeRemovedComponents;
361 for ( Qt3DCore::QComponent *component : entity->components() )
363 Qt3DRender::QLayer *layer = qobject_cast<Qt3DRender::QLayer *>( component );
364 if ( layer !=
nullptr )
365 toBeRemovedComponents.push_back( layer );
367 for ( Qt3DCore::QComponent *component : toBeRemovedComponents )
368 entity->removeComponent( component );
369 for ( Qt3DCore::QEntity *obj : entity->findChildren<Qt3DCore::QEntity *>() )
371 if ( obj !=
nullptr )
378 for ( Qt3DRender::QLayer *layer : layers )
379 entity->addComponent( layer );
380 for ( Qt3DCore::QEntity *child : entity->findChildren<Qt3DCore::QEntity *>() )
382 if ( child !=
nullptr )
387 void Qgs3DMapScene::updateScene()
389 QgsEventTracing::addEvent( QgsEventTracing::Instant, QStringLiteral(
"3D" ), QStringLiteral(
"Update Scene" ) );
390 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
392 if ( entity->isEnabled() )
393 entity->update(
_sceneState( mCameraController ) );
398 static void _updateNearFarPlane(
const QList<QgsChunkNode *> &activeNodes,
const QMatrix4x4 &viewMatrix,
float &fnear,
float &ffar )
400 for ( QgsChunkNode *node : activeNodes )
405 for (
int i = 0; i < 8; ++i )
407 QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.
xMin : bbox.
xMax,
408 ( ( i >> 1 ) & 1 ) ? bbox.
yMin : bbox.
yMax,
409 ( ( i >> 2 ) & 1 ) ? bbox.
zMin : bbox.
zMax, 1 );
411 QVector4D pc = viewMatrix * p;
414 fnear = std::min( fnear, dst );
415 ffar = std::max( ffar, dst );
420 bool Qgs3DMapScene::updateCameraNearFarPlanes()
435 QMatrix4x4 viewMatrix = camera->viewMatrix();
438 QList<QgsChunkNode *> activeNodes;
440 activeNodes = mTerrain->activeNodes();
445 if ( mTerrain && activeNodes.isEmpty() )
446 activeNodes << mTerrain->rootNode();
448 _updateNearFarPlane( activeNodes, viewMatrix, fnear, ffar );
452 for ( QgsChunkedEntity *e : std::as_const( mChunkEntities ) )
456 QList<QgsChunkNode *> activeEntityNodes = e->activeNodes();
457 if ( activeEntityNodes.empty() )
458 activeEntityNodes << e->rootNode();
459 _updateNearFarPlane( activeEntityNodes, viewMatrix, fnear, ffar );
466 if ( fnear == 1e9 && ffar == 0 )
470 qWarning() <<
"oops... this should not happen! couldn't determine near/far plane. defaulting to 1...1e9";
476 float newFar = ffar * 2;
477 float newNear = fnear / 2;
480 camera->setFarPlane( newFar );
481 camera->setNearPlane( newNear );
488 void Qgs3DMapScene::onFrameTriggered(
float dt )
492 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
494 if ( entity->isEnabled() && entity->needsUpdate() )
497 entity->update(
_sceneState( mCameraController ) );
504 static int frameCount = 0;
505 static float accumulatedTime = 0.0f;
515 accumulatedTime += dt;
516 if ( accumulatedTime >= 0.2f )
518 float fps = ( float )frameCount / accumulatedTime;
520 accumulatedTime = 0.0f;
525 void Qgs3DMapScene::createTerrain()
529 mChunkEntities.removeOne( mTerrain );
531 mTerrain->deleteLater();
535 if ( !mTerrainUpdateScheduled )
538 QTimer::singleShot( 0,
this, &Qgs3DMapScene::createTerrainDeferred );
539 mTerrainUpdateScheduled =
true;
548 void Qgs3DMapScene::createTerrainDeferred()
556 mMap.
terrainGenerator()->setupQuadtree( rootBbox, rootError, maxZoomLevel );
558 mTerrain =
new QgsTerrainEntity( mMap );
559 mTerrain->setParent(
this );
564 mChunkEntities << mTerrain;
576 const QList<QgsMapLayer *> layers = mMap.
layers();
580 removeLayerEntity( layer );
583 addLayerEntity( layer );
588 mTerrainUpdateScheduled =
false;
591 void Qgs3DMapScene::onBackgroundColorChanged()
596 void Qgs3DMapScene::updateLights()
598 for ( Qt3DCore::QEntity *entity : std::as_const( mLightEntities ) )
599 entity->deleteLater();
600 mLightEntities.clear();
601 for ( Qt3DCore::QEntity *entity : std::as_const( mLightOriginEntities ) )
602 entity->deleteLater();
603 mLightOriginEntities.clear();
605 auto createLightOriginEntity = [ = ]( QVector3D translation,
const QColor & color )->Qt3DCore::QEntity *
607 Qt3DCore::QEntity *originEntity =
new Qt3DCore::QEntity;
609 Qt3DCore::QTransform *trLightOriginCenter =
new Qt3DCore::QTransform;
610 trLightOriginCenter->setTranslation( translation );
611 originEntity->addComponent( trLightOriginCenter );
613 Qt3DExtras::QPhongMaterial *materialLightOriginCenter =
new Qt3DExtras::QPhongMaterial;
614 materialLightOriginCenter->setAmbient( color );
615 originEntity->addComponent( materialLightOriginCenter );
617 Qt3DExtras::QSphereMesh *rendererLightOriginCenter =
new Qt3DExtras::QSphereMesh;
618 rendererLightOriginCenter->setRadius( 20 );
619 originEntity->addComponent( rendererLightOriginCenter );
621 originEntity->setEnabled(
true );
622 originEntity->setParent(
this );
630 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
631 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
632 lightTransform->setTranslation( QVector3D( pointLightSettings.position().x(),
633 pointLightSettings.position().y(),
634 pointLightSettings.position().z() ) );
636 Qt3DRender::QPointLight *light =
new Qt3DRender::QPointLight;
637 light->setColor( pointLightSettings.color() );
638 light->setIntensity( pointLightSettings.intensity() );
640 light->setConstantAttenuation( pointLightSettings.constantAttenuation() );
641 light->setLinearAttenuation( pointLightSettings.linearAttenuation() );
642 light->setQuadraticAttenuation( pointLightSettings.quadraticAttenuation() );
644 lightEntity->addComponent( light );
645 lightEntity->addComponent( lightTransform );
646 lightEntity->setParent(
this );
647 mLightEntities << lightEntity;
650 mLightOriginEntities << createLightOriginEntity( lightTransform->translation(), pointLightSettings.color() );
656 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
657 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
659 Qt3DRender::QDirectionalLight *light =
new Qt3DRender::QDirectionalLight;
660 light->setColor( directionalLightSettings.color() );
661 light->setIntensity( directionalLightSettings.intensity() );
662 QgsVector3D direction = directionalLightSettings.direction();
663 light->setWorldDirection( QVector3D( direction.
x(), direction.
y(), direction.
z() ) );
665 lightEntity->addComponent( light );
666 lightEntity->addComponent( lightTransform );
667 lightEntity->setParent(
this );
668 mLightEntities << lightEntity;
671 onShadowSettingsChanged();
674 void Qgs3DMapScene::updateCameraLens()
681 void Qgs3DMapScene::onRenderersChanged()
684 qDeleteAll( mRenderersEntities );
685 mRenderersEntities.clear();
688 const QList<QgsAbstract3DRenderer *> renderers = mMap.
renderers();
691 Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
694 newEntity->setParent(
this );
695 finalizeNewEntity( newEntity );
696 mRenderersEntities[renderer] = newEntity;
701 void Qgs3DMapScene::onLayerRenderer3DChanged()
703 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
707 removeLayerEntity( layer );
710 addLayerEntity( layer );
713 void Qgs3DMapScene::onLayersChanged()
715 QSet<QgsMapLayer *> layersBefore = qgis::listToSet( mLayerEntities.keys() );
716 QList<QgsMapLayer *> layersAdded;
717 const QList<QgsMapLayer *> layers = mMap.
layers();
720 if ( !layersBefore.contains( layer ) )
722 layersAdded << layer;
726 layersBefore.remove( layer );
731 for (
QgsMapLayer *layer : std::as_const( layersBefore ) )
733 removeLayerEntity( layer );
736 for (
QgsMapLayer *layer : std::as_const( layersAdded ) )
738 addLayerEntity( layer );
744 for (
auto layer : mLayerEntities.keys() )
748 removeLayerEntity( layer );
749 addLayerEntity( layer );
754 void Qgs3DMapScene::addLayerEntity(
QgsMapLayer *layer )
756 bool needsSceneUpdate =
false;
765 ( renderer->
type() == QLatin1String(
"vector" ) || renderer->
type() == QLatin1String(
"rulebased" ) ) )
768 if ( renderer->
type() == QLatin1String(
"vector" ) )
776 mModelVectorLayers.append( layer );
780 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
783 for (
auto rule : rules )
788 mModelVectorLayers.append( layer );
811 Qt3DCore::QEntity *newEntity = renderer->
createEntity( mMap );
814 newEntity->setParent(
this );
815 mLayerEntities.insert( layer, newEntity );
817 finalizeNewEntity( newEntity );
819 if ( QgsChunkedEntity *chunkedNewEntity = qobject_cast<QgsChunkedEntity *>( newEntity ) )
821 mChunkEntities.append( chunkedNewEntity );
822 needsSceneUpdate =
true;
824 chunkedNewEntity->setPickingEnabled( !mPickHandlers.isEmpty() );
825 connect( chunkedNewEntity, &QgsChunkedEntity::pickedObject,
this, &Qgs3DMapScene::onLayerEntityPickedObject );
827 connect( chunkedNewEntity, &QgsChunkedEntity::newEntityCreated,
this, [
this]( Qt3DCore::QEntity * entity )
829 finalizeNewEntity( entity );
837 if ( needsSceneUpdate )
858 void Qgs3DMapScene::removeLayerEntity(
QgsMapLayer *layer )
860 Qt3DCore::QEntity *entity = mLayerEntities.take( layer );
862 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
864 mChunkEntities.removeOne( chunkedEntity );
868 entity->deleteLater();
877 mModelVectorLayers.removeAll( layer );
889 void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
893 for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
897 lm->setViewportSize( mCameraController->
viewport().size() );
907 bm->setViewportSize( mCameraController->
viewport().size() );
910 bm->setViewportSize( mCameraController->
viewport().size() );
914 int Qgs3DMapScene::maximumTextureSize()
const
916 QSurface *surface = mEngine->
surface();
917 QOpenGLContext context;
919 context.makeCurrent( surface );
920 QOpenGLFunctions openglFunctions( &context );
922 openglFunctions.glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size );
926 void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
928 mEntityCameraViewCenter =
new Qt3DCore::QEntity;
930 Qt3DCore::QTransform *trCameraViewCenter =
new Qt3DCore::QTransform;
931 mEntityCameraViewCenter->addComponent( trCameraViewCenter );
932 connect( camera, &Qt3DRender::QCamera::viewCenterChanged,
this, [trCameraViewCenter, camera]
934 trCameraViewCenter->setTranslation( camera->viewCenter() );
937 Qt3DExtras::QPhongMaterial *materialCameraViewCenter =
new Qt3DExtras::QPhongMaterial;
938 materialCameraViewCenter->setAmbient( Qt::red );
939 mEntityCameraViewCenter->addComponent( materialCameraViewCenter );
941 Qt3DExtras::QSphereMesh *rendererCameraViewCenter =
new Qt3DExtras::QSphereMesh;
942 rendererCameraViewCenter->setRadius( 10 );
943 mEntityCameraViewCenter->addComponent( rendererCameraViewCenter );
946 mEntityCameraViewCenter->setParent(
this );
956 if ( mSceneState == state )
962 void Qgs3DMapScene::updateSceneState()
964 if ( mTerrainUpdateScheduled )
970 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
972 if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
979 setSceneState(
Ready );
982 void Qgs3DMapScene::onSkyboxSettingsChanged()
985 if ( mSkybox !=
nullptr )
987 mSkybox->deleteLater();
995 QMap<QString, QString> faces;
1001 faces[QStringLiteral(
"posX" )], faces[QStringLiteral(
"posY" )], faces[QStringLiteral(
"posZ" )],
1002 faces[QStringLiteral(
"negX" )], faces[QStringLiteral(
"negY" )], faces[QStringLiteral(
"negZ" )],
1013 void Qgs3DMapScene::onShadowSettingsChanged()
1017 QList<QgsDirectionalLightSettings> directionalLights = mMap.
directionalLights();
1020 if ( shadowSettings.
renderShadows() && selectedLight >= 0 && selectedLight < directionalLights.count() )
1032 void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
1038 void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
1044 void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
1054 void Qgs3DMapScene::onCameraMovementSpeedChanged()
1061 QVector<QString> notParsedLayers;
1071 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1074 Qt3DCore::QEntity *rootEntity = it.value();
1076 switch ( layerType )
1080 notParsedLayers.push_back( layer->
name() );
1088 notParsedLayers.push_back( layer->
name() );
1098 if ( !notParsedLayers.empty() )
1100 QString message = tr(
"The following layers were not exported:" ) +
"\n";
1101 for (
const QString &layerName : notParsedLayers )
1102 message += layerName +
"\n";
1109 QVector<const QgsChunkNode *> chunks;
1110 if ( !mLayerEntities.contains( layer ) )
return chunks;
1111 if ( QgsChunkedEntity *
c = qobject_cast<QgsChunkedEntity *>( mLayerEntities[ layer ] ) )
1113 for ( QgsChunkNode *n :
c->activeNodes() )
1114 chunks.push_back( n );
1124 for (
QgsMapLayer *layer : mLayerEntities.keys() )
1126 Qt3DCore::QEntity *layerEntity = mLayerEntities[ layer ];
1127 QgsChunkedEntity *
c = qobject_cast<QgsChunkedEntity *>( layerEntity );
1130 QgsChunkNode *chunkNode =
c->rootNode();
1131 QgsAABB bbox = chunkNode->bbox();
1138 QgsRectangle terrainExtent = terrainGenerator->extent();
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.
void unregisterPickHandler(Qgs3DMapScenePickHandler *pickHandler)
Unregisters previously registered pick handler. Pick handler is not deleted. Also removes object pick...
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 fpsCountChanged(float fpsCount)
Emitted when the FPS count changes.
QgsRectangle sceneExtent()
Returns the scene extent in the map's CRS.
void registerPickHandler(Qgs3DMapScenePickHandler *pickHandler)
Registers an object that will get results of pick events on 3D entities. Does not take ownership of t...
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.
void totalPendingJobsCountChanged()
Emitted when the total number of pending jobs changes.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is activated or deactivated.
QgsCameraController * cameraController()
Returns camera controller.
void sceneStateChanged()
Emitted when the scene's state has changed.
int terrainPendingJobsCount() const
Returns number of pending jobs of the terrain entity.
float worldSpaceError(float epsilon, float distance)
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.
void viewZoomFull()
Resets camera view to show the whole scene (top view)
Qgs3DMapScene(const Qgs3DMapSettings &map, QgsAbstract3DEngine *engine)
Constructs a 3D scene based on map settings and Qt 3D renderer configuration.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data.
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.
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.
QList< QgsDirectionalLightSettings > directionalLights() const
Returns list of directional lights defined in the scene.
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 directionalLightsChanged()
Emitted when the list of directional lights changes.
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 skyboxSettingsChanged()
Emitted when skybox settings are changed.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
void pointLightsChanged()
Emitted when the list of point lights changes.
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.
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image)
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
QColor backgroundColor() const
Returns background color of the 3D map view.
double debugShadowMapSize() const
Returns the size of the shadow map preview.
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.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is enabled or disabled.
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.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
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< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
QgsCameraController::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
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.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Entity that handles the exporting of 3D scene.
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 save(const QString &sceneName, const QString &sceneFolderPath)
Saves the scene to a .obj file.
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 QgsRectangle worldToLayerExtent(const QgsAABB &bbox, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts axis aligned bounding box in 3D world coordinates to extent in map layer CRS.
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...
virtual void setClearColor(const QColor &color)=0
Sets background color of the scene.
virtual Qt3DRender::QRenderSettings * renderSettings()=0
Returns access to the engine's render settings (the frame graph can be accessed from here)
virtual Qt3DRender::QCamera * camera()=0
Returns pointer to the engine's camera entity.
virtual QSurface * surface() const =0
Returns the surface of the engine.
QgsShadowRenderingFrameGraph * frameGraph()
Returns the shadow rendering frame graph object used to render the scene.
virtual void setFrustumCullingEnabled(bool enabled)=0
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...
virtual QSize size() const =0
Returns size of the engine's rendering area in pixels.
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(const Qgs3DMapSettings &map) const =0
Returns a 3D entity that will be used to show renderer's data in 3D scene.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
void setViewport(QRect viewport)
Sets viewport rectangle. Called internally from 3D canvas. Allows conversion of mouse coordinates.
void setCameraNavigationMode(QgsCameraController::NavigationMode navigationMode)
Sets the navigation mode used by the camera controller.
Qt3DRender::QCamera * camera
float distance() const
Returns distance of the camera from the point it is looking at.
void setCamera(Qt3DRender::QCamera *camera)
Assigns camera that should be controlled by this class. Called internally from 3D scene.
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 setTerrainEntity(QgsTerrainEntity *te)
Connects to object picker attached to terrain entity.
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void viewportChanged()
Emitted when viewport rectangle has been updated.
A skybox constructed from a 6 cube faces.
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.
QgsCoordinateReferenceSystem crs
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
void rendererChanged()
Signal emitted when renderer is changed.
void layerModified()
Emitted when modifications has been done on layer.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
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.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
A skybox constructed from a panoramic image.
Shape shape() const
Returns 3D shape for points.
QVariantMap shapeProperties() const
Returns a key-value dictionary of point shape properties.
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.
static QgsProject * instance()
Returns the QgsProject singleton instance.
A rectangle specified with double values.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
QList< QgsRuleBased3DRenderer::Rule * > RuleList
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
void setShadowBias(float shadowBias)
Sets the shadow bias value.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
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.
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".
QMap< QString, QString > cubeMapFacesPaths() const
Returns a map containing the path of each texture specified by the user.
void remoteSourceFetched(const QString &url)
Emitted when the cache has finished retrieving a 3D model from a remote url.
bool isActive() const
Returns true if the temporal property is active.
virtual QgsRectangle extent() const =0
extent of the terrain in terrain's CRS
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.
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 QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QgsMapLayerType
Types of layers that can be added to a map.
@ PointCloudLayer
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
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)
void addQLayerComponentsToHierarchy(Qt3DCore::QEntity *entity, const QVector< Qt3DRender::QLayer * > layers)
QgsChunkedEntity::SceneState _sceneState(QgsCameraController *cameraController)
void removeQLayerComponentsFromHierarchy(Qt3DCore::QEntity *entity)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
#define QgsDebugMsgLevel(str, level)