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>
41 #include <QOpenGLContext>
42 #include <QOpenGLFunctions>
92 onBackgroundColorChanged();
98 #if QT_VERSION >= 0x050900
100 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() );
249 return mTerrain ? mTerrain->pendingJobsCount() : 0;
255 for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
256 count += entity->pendingJobsCount();
262 if ( mPickHandlers.isEmpty() )
265 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
267 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
268 chunkedEntity->setPickingEnabled(
true );
272 mPickHandlers.append( pickHandler );
277 mPickHandlers.removeOne( pickHandler );
279 if ( mPickHandlers.isEmpty() )
282 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
284 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
285 chunkedEntity->setPickingEnabled(
false );
290 void Qgs3DMapScene::onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent,
QgsFeatureId fid )
292 QgsMapLayer *layer = mLayerEntities.key( qobject_cast<QgsChunkedEntity *>( sender() ) );
302 pickHandler->handlePickOnVectorLayer( vlayer, fid, pickEvent->worldIntersection(), pickEvent );
308 Qt3DRender::QCamera *camera = mCameraController->
camera();
309 float fov = camera->fieldOfView();
310 QRect rect = mCameraController->
viewport();
311 float screenSizePx = std::max( rect.width(), rect.height() );
315 float frustumWidthAtDistance = 2 * distance * tan( fov / 2 );
316 float err = frustumWidthAtDistance * epsilon / screenSizePx;
322 Qt3DRender::QCamera *camera = cameraController->
camera();
323 QgsChunkedEntity::SceneState state;
324 state.cameraFov = camera->fieldOfView();
325 state.cameraPos = camera->position();
326 QRect rect = cameraController->
viewport();
327 state.screenSizePx = std::max( rect.width(), rect.height() );
328 state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
332 void Qgs3DMapScene::onCameraChanged()
334 if ( mMap.
projectionType() == Qt3DRender::QCameraLens::OrthographicProjection )
336 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
337 const float viewWidthFromCenter = mCameraController->
distance();
338 const float viewHeightFromCenter = viewportRect.height() * viewWidthFromCenter / viewportRect.width();
339 mEngine->
camera()->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mEngine->
camera()->nearPlane(), mEngine->
camera()->farPlane() );
343 bool changedCameraPlanes = updateCameraNearFarPlanes();
345 if ( changedCameraPlanes )
350 updateCameraNearFarPlanes();
353 onShadowSettingsChanged();
358 QVector<Qt3DCore::QComponent *> toBeRemovedComponents;
359 for ( Qt3DCore::QComponent *component : entity->components() )
361 Qt3DRender::QLayer *layer = qobject_cast<Qt3DRender::QLayer *>( component );
362 if ( layer !=
nullptr )
363 toBeRemovedComponents.push_back( layer );
365 for ( Qt3DCore::QComponent *component : toBeRemovedComponents )
366 entity->removeComponent( component );
367 for ( Qt3DCore::QEntity *obj : entity->findChildren<Qt3DCore::QEntity *>() )
369 if ( obj !=
nullptr )
376 for ( Qt3DRender::QLayer *layer : layers )
377 entity->addComponent( layer );
378 for ( Qt3DCore::QEntity *child : entity->findChildren<Qt3DCore::QEntity *>() )
380 if ( child !=
nullptr )
385 void Qgs3DMapScene::updateScene()
387 QgsEventTracing::addEvent( QgsEventTracing::Instant, QStringLiteral(
"3D" ), QStringLiteral(
"Update Scene" ) );
388 for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
390 if ( entity->isEnabled() )
391 entity->update(
_sceneState( mCameraController ) );
393 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
395 if ( windowEngine !=
nullptr )
397 QVector<Qt3DRender::QLayer *> layers;
398 layers.push_back( windowEngine->shadowRenderingFrameGraph()->castShadowsLayer() );
399 layers.push_back( windowEngine->shadowRenderingFrameGraph()->forwardRenderLayer() );
407 static void _updateNearFarPlane(
const QList<QgsChunkNode *> &activeNodes,
const QMatrix4x4 &viewMatrix,
float &fnear,
float &ffar )
409 for ( QgsChunkNode *node : activeNodes )
414 for (
int i = 0; i < 8; ++i )
416 QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.
xMin : bbox.
xMax,
417 ( ( i >> 1 ) & 1 ) ? bbox.
yMin : bbox.
yMax,
418 ( ( i >> 2 ) & 1 ) ? bbox.
zMin : bbox.
zMax, 1 );
419 QVector4D pc = viewMatrix * p;
430 bool Qgs3DMapScene::updateCameraNearFarPlanes()
447 QMatrix4x4 viewMatrix = camera->viewMatrix();
451 QList<QgsChunkNode *> activeNodes = mTerrain->activeNodes();
456 if ( activeNodes.isEmpty() )
457 activeNodes << mTerrain->rootNode();
459 _updateNearFarPlane( activeNodes, viewMatrix, fnear, ffar );
463 for ( QgsChunkedEntity *e : qgis::as_const( mChunkEntities ) )
466 _updateNearFarPlane( e->activeNodes(), viewMatrix, fnear, ffar );
472 if ( fnear == 1e9 && ffar == 0 )
476 qWarning() <<
"oops... this should not happen! couldn't determine near/far plane. defaulting to 1...1e9";
482 float newFar = ffar * 2;
483 float newNear = fnear / 2;
486 camera->setFarPlane( newFar );
487 camera->setNearPlane( newNear );
492 qWarning() <<
"no terrain - not setting near/far plane";
497 void Qgs3DMapScene::onFrameTriggered(
float dt )
501 for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
503 if ( entity->isEnabled() && entity->needsUpdate() )
506 entity->update(
_sceneState( mCameraController ) );
513 static int frameCount = 0;
514 static float accumulatedTime = 0.0f;
524 accumulatedTime += dt;
525 if ( accumulatedTime >= 0.2f )
527 float fps = ( float )frameCount / accumulatedTime;
529 accumulatedTime = 0.0f;
534 void Qgs3DMapScene::createTerrain()
538 mChunkEntities.removeOne( mTerrain );
540 mTerrain->deleteLater();
546 if ( !mTerrainUpdateScheduled )
549 QTimer::singleShot( 0,
this, &Qgs3DMapScene::createTerrainDeferred );
550 mTerrainUpdateScheduled =
true;
555 void Qgs3DMapScene::createTerrainDeferred()
561 mMap.
terrainGenerator()->setupQuadtree( rootBbox, rootError, maxZoomLevel );
563 mTerrain =
new QgsTerrainEntity( mMap );
565 mTerrain->setParent(
this );
568 mTerrain->setShowBoundingBoxes(
true );
572 mChunkEntities << mTerrain;
580 removeLayerEntity( layer );
583 addLayerEntity( layer );
586 mTerrainUpdateScheduled =
false;
594 void Qgs3DMapScene::onBackgroundColorChanged()
599 void Qgs3DMapScene::updateLights()
601 for ( Qt3DCore::QEntity *entity : qgis::as_const( mLightEntities ) )
602 entity->deleteLater();
603 mLightEntities.clear();
604 for ( Qt3DCore::QEntity *entity : qgis::as_const( mLightOriginEntities ) )
605 entity->deleteLater();
606 mLightOriginEntities.clear();
608 auto createLightOriginEntity = [ = ]( QVector3D translation,
const QColor & color )->Qt3DCore::QEntity *
610 Qt3DCore::QEntity *originEntity =
new Qt3DCore::QEntity;
612 Qt3DCore::QTransform *trLightOriginCenter =
new Qt3DCore::QTransform;
613 trLightOriginCenter->setTranslation( translation );
614 originEntity->addComponent( trLightOriginCenter );
616 Qt3DExtras::QPhongMaterial *materialLightOriginCenter =
new Qt3DExtras::QPhongMaterial;
617 materialLightOriginCenter->setAmbient( color );
618 originEntity->addComponent( materialLightOriginCenter );
620 Qt3DExtras::QSphereMesh *rendererLightOriginCenter =
new Qt3DExtras::QSphereMesh;
621 rendererLightOriginCenter->setRadius( 20 );
622 originEntity->addComponent( rendererLightOriginCenter );
624 originEntity->setEnabled(
true );
625 originEntity->setParent(
this );
633 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
634 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
635 lightTransform->setTranslation( QVector3D( pointLightSettings.position().x(),
636 pointLightSettings.position().y(),
637 pointLightSettings.position().z() ) );
639 Qt3DRender::QPointLight *light =
new Qt3DRender::QPointLight;
640 light->setColor( pointLightSettings.color() );
641 light->setIntensity( pointLightSettings.intensity() );
643 light->setConstantAttenuation( pointLightSettings.constantAttenuation() );
644 light->setLinearAttenuation( pointLightSettings.linearAttenuation() );
645 light->setQuadraticAttenuation( pointLightSettings.quadraticAttenuation() );
647 lightEntity->addComponent( light );
648 lightEntity->addComponent( lightTransform );
649 lightEntity->setParent(
this );
650 mLightEntities << lightEntity;
653 mLightOriginEntities << createLightOriginEntity( lightTransform->translation(), pointLightSettings.color() );
659 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
660 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
662 Qt3DRender::QDirectionalLight *light =
new Qt3DRender::QDirectionalLight;
663 light->setColor( directionalLightSettings.color() );
664 light->setIntensity( directionalLightSettings.intensity() );
665 QgsVector3D direction = directionalLightSettings.direction();
666 light->setWorldDirection( QVector3D( direction.
x(), direction.
y(), direction.
z() ) );
668 lightEntity->addComponent( light );
669 lightEntity->addComponent( lightTransform );
670 lightEntity->setParent(
this );
671 mLightEntities << lightEntity;
674 onShadowSettingsChanged();
677 void Qgs3DMapScene::updateCameraLens()
684 void Qgs3DMapScene::onRenderersChanged()
687 qDeleteAll( mRenderersEntities );
688 mRenderersEntities.clear();
691 const QList<QgsAbstract3DRenderer *> renderers = mMap.
renderers();
694 Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
697 newEntity->setParent(
this );
698 finalizeNewEntity( newEntity );
699 mRenderersEntities[renderer] = newEntity;
704 void Qgs3DMapScene::onLayerRenderer3DChanged()
706 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
710 removeLayerEntity( layer );
713 addLayerEntity( layer );
716 void Qgs3DMapScene::onLayersChanged()
718 QSet<QgsMapLayer *> layersBefore = qgis::listToSet( mLayerEntities.keys() );
719 QList<QgsMapLayer *> layersAdded;
722 if ( !layersBefore.contains( layer ) )
724 layersAdded << layer;
728 layersBefore.remove( layer );
735 removeLayerEntity( layer );
740 addLayerEntity( layer );
746 for (
auto layer : mLayerEntities.keys() )
750 removeLayerEntity( layer );
751 addLayerEntity( layer );
756 void Qgs3DMapScene::addLayerEntity(
QgsMapLayer *layer )
758 bool needsSceneUpdate =
false;
767 ( renderer->
type() == QLatin1String(
"vector" ) || renderer->
type() == QLatin1String(
"rulebased" ) ) )
770 if ( renderer->
type() == QLatin1String(
"vector" ) )
778 mModelVectorLayers.append( layer );
782 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
785 for (
auto rule : rules )
790 mModelVectorLayers.append( layer );
813 Qt3DCore::QEntity *newEntity = renderer->
createEntity( mMap );
816 newEntity->setParent(
this );
817 mLayerEntities.insert( layer, newEntity );
819 finalizeNewEntity( newEntity );
821 if ( QgsChunkedEntity *chunkedNewEntity = qobject_cast<QgsChunkedEntity *>( newEntity ) )
823 mChunkEntities.append( chunkedNewEntity );
824 needsSceneUpdate =
true;
826 chunkedNewEntity->setPickingEnabled( !mPickHandlers.isEmpty() );
827 connect( chunkedNewEntity, &QgsChunkedEntity::pickedObject,
this, &Qgs3DMapScene::onLayerEntityPickedObject );
829 connect( chunkedNewEntity, &QgsChunkedEntity::newEntityCreated,
this, [
this]( Qt3DCore::QEntity * entity )
831 finalizeNewEntity( entity );
839 if ( needsSceneUpdate )
860 void Qgs3DMapScene::removeLayerEntity(
QgsMapLayer *layer )
862 Qt3DCore::QEntity *entity = mLayerEntities.take( layer );
864 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
866 mChunkEntities.removeOne( chunkedEntity );
870 entity->deleteLater();
879 mModelVectorLayers.removeAll( layer );
891 void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
895 for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
899 lm->setViewportSize( mCameraController->
viewport().size() );
909 bm->setViewportSize( mCameraController->
viewport().size() );
912 bm->setViewportSize( mCameraController->
viewport().size() );
916 int Qgs3DMapScene::maximumTextureSize()
const
918 QSurface *surface = mEngine->
surface();
919 QOpenGLContext context;
921 context.makeCurrent( surface );
922 QOpenGLFunctions openglFunctions( &context );
924 openglFunctions.glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size );
928 void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
930 mEntityCameraViewCenter =
new Qt3DCore::QEntity;
932 Qt3DCore::QTransform *trCameraViewCenter =
new Qt3DCore::QTransform;
933 mEntityCameraViewCenter->addComponent( trCameraViewCenter );
934 connect( camera, &Qt3DRender::QCamera::viewCenterChanged,
this, [trCameraViewCenter, camera]
936 trCameraViewCenter->setTranslation( camera->viewCenter() );
939 Qt3DExtras::QPhongMaterial *materialCameraViewCenter =
new Qt3DExtras::QPhongMaterial;
940 materialCameraViewCenter->setAmbient( Qt::red );
941 mEntityCameraViewCenter->addComponent( materialCameraViewCenter );
943 Qt3DExtras::QSphereMesh *rendererCameraViewCenter =
new Qt3DExtras::QSphereMesh;
944 rendererCameraViewCenter->setRadius( 10 );
945 mEntityCameraViewCenter->addComponent( rendererCameraViewCenter );
948 mEntityCameraViewCenter->setParent(
this );
958 if ( mSceneState == state )
964 void Qgs3DMapScene::updateSceneState()
966 if ( mTerrainUpdateScheduled )
972 for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
974 if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
981 setSceneState(
Ready );
984 void Qgs3DMapScene::onSkyboxSettingsChanged()
987 if ( mSkybox !=
nullptr )
989 mSkybox->deleteLater();
997 QMap<QString, QString> faces;
1003 faces[QStringLiteral(
"posX" )], faces[QStringLiteral(
"posY" )], faces[QStringLiteral(
"posZ" )],
1004 faces[QStringLiteral(
"negX" )], faces[QStringLiteral(
"negY" )], faces[QStringLiteral(
"negZ" )],
1015 void Qgs3DMapScene::onShadowSettingsChanged()
1019 QList<QgsDirectionalLightSettings> directionalLights = mMap.
directionalLights();
1022 if ( shadowSettings.
renderShadows() && selectedLight >= 0 && selectedLight < directionalLights.count() )
1034 void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
1040 void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
1046 void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
1056 void Qgs3DMapScene::onCameraMovementSpeedChanged()
1063 QVector<QString> notParsedLayers;
1073 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1076 Qt3DCore::QEntity *rootEntity = it.value();
1078 switch ( layerType )
1082 notParsedLayers.push_back( layer->
name() );
1090 notParsedLayers.push_back( layer->
name() );
1100 if ( !notParsedLayers.empty() )
1102 QString message = tr(
"The following layers were not exported:" ) +
"\n";
1103 for (
const QString &layerName : notParsedLayers )
1104 message += layerName +
"\n";
1111 QVector<const QgsChunkNode *> chunks;
1112 if ( !mLayerEntities.contains( layer ) )
return chunks;
1113 if ( QgsChunkedEntity *
c = qobject_cast<QgsChunkedEntity *>( mLayerEntities[ layer ] ) )
1115 for ( QgsChunkNode *n :
c->activeNodes() )
1116 chunks.push_back( n );
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.
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.
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.
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 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.
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 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.
A rectangle specified with double values.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
double width() const SIP_HOLDGIL
Returns the width of the 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 layerModified()
Emitted when modifications has been done on layer.
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)