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();
97 mEngine->
renderSettings()->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );
100 mEngine->
renderSettings()->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking );
102 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
105 float aspectRatio = ( float )viewportRect.width() / viewportRect.height();
106 mEngine->
camera()->lens()->setPerspectiveProjection( mMap.
fieldOfView(), aspectRatio, 10.f, 10000.0f );
108 mFrameAction =
new Qt3DLogic::QFrameAction();
109 connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered,
110 this, &Qgs3DMapScene::onFrameTriggered );
111 addComponent( mFrameAction );
119 addCameraViewCenterEntity( mEngine->
camera() );
124 createTerrainDeferred();
149 const QList<QgsMapLayer *> modelVectorLayers = mModelVectorLayers;
155 if ( renderer->
type() == QLatin1String(
"vector" ) )
158 if ( pointSymbol->
shapeProperties()[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->
shapeProperties()[QStringLiteral(
"model" )].toString() == url )
172 removeLayerEntity( layer );
173 addLayerEntity( layer );
184 onRenderersChanged();
191 ChunkedEntity *testChunkEntity =
new ChunkedEntity( AABB( -500, 0, -500, 500, 100, 500 ), 2.f, 3.f, 7,
new TestChunkLoaderFactory );
192 testChunkEntity->setEnabled(
false );
193 testChunkEntity->setParent(
this );
194 chunkEntities << testChunkEntity;
205 Qt3DCore::QEntity *loaderEntity =
new Qt3DCore::QEntity;
206 Qt3DRender::QSceneLoader *loader =
new Qt3DRender::QSceneLoader;
207 loader->setSource( QUrl(
"file:///home/martin/Downloads/LowPolyModels/tree.dae" ) );
208 loaderEntity->addComponent( loader );
209 loaderEntity->setParent(
this );
213 Qt3DCore::QEntity *meshEntity =
new Qt3DCore::QEntity;
214 Qt3DRender::QMesh *mesh =
new Qt3DRender::QMesh;
215 mesh->setSource( QUrl(
"file:///home/martin/Downloads/LowPolyModels/tree.obj" ) );
216 meshEntity->addComponent( mesh );
217 Qt3DExtras::QPhongMaterial *material =
new Qt3DExtras::QPhongMaterial;
218 material->setAmbient( Qt::red );
219 meshEntity->addComponent( material );
220 Qt3DCore::QTransform *meshTransform =
new Qt3DCore::QTransform;
221 meshTransform->setScale( 1 );
222 meshEntity->addComponent( meshTransform );
223 meshEntity->setParent(
this );
225 onSkyboxSettingsChanged();
230 onEyeDomeShadingSettingsChanged();
232 onDebugShadowMapSettingsChanged();
233 onDebugDepthMapSettingsChanged();
236 onCameraMovementSpeedChanged();
242 float side = std::max( extent.
width(), extent.
height() );
248 return mTerrain ? mTerrain->pendingJobsCount() : 0;
254 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
255 count += entity->pendingJobsCount();
261 if ( mPickHandlers.isEmpty() )
264 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
266 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
267 chunkedEntity->setPickingEnabled(
true );
271 mPickHandlers.append( pickHandler );
276 mPickHandlers.removeOne( pickHandler );
278 if ( mPickHandlers.isEmpty() )
281 for ( Qt3DCore::QEntity *entity : mLayerEntities.values() )
283 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
284 chunkedEntity->setPickingEnabled(
false );
289 void Qgs3DMapScene::onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent,
QgsFeatureId fid )
291 QgsMapLayer *layer = mLayerEntities.key( qobject_cast<QgsChunkedEntity *>( sender() ) );
301 pickHandler->handlePickOnVectorLayer( vlayer, fid, pickEvent->worldIntersection(), pickEvent );
307 Qt3DRender::QCamera *camera = mCameraController->
camera();
308 float fov = camera->fieldOfView();
309 QRect rect = mCameraController->
viewport();
310 float screenSizePx = std::max( rect.width(), rect.height() );
314 float frustumWidthAtDistance = 2 * distance * tan( fov / 2 );
315 float err = frustumWidthAtDistance * epsilon / screenSizePx;
321 Qt3DRender::QCamera *camera = cameraController->
camera();
322 QgsChunkedEntity::SceneState state;
323 state.cameraFov = camera->fieldOfView();
324 state.cameraPos = camera->position();
325 QRect rect = cameraController->
viewport();
326 state.screenSizePx = std::max( rect.width(), rect.height() );
327 state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
331 void Qgs3DMapScene::onCameraChanged()
333 if ( mMap.
projectionType() == Qt3DRender::QCameraLens::OrthographicProjection )
335 QRect viewportRect( QPoint( 0, 0 ), mEngine->
size() );
336 const float viewWidthFromCenter = mCameraController->
distance();
337 const float viewHeightFromCenter = viewportRect.height() * viewWidthFromCenter / viewportRect.width();
338 mEngine->
camera()->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mEngine->
camera()->nearPlane(), mEngine->
camera()->farPlane() );
342 bool changedCameraPlanes = updateCameraNearFarPlanes();
344 if ( changedCameraPlanes )
349 updateCameraNearFarPlanes();
352 onShadowSettingsChanged();
357 QVector<Qt3DCore::QComponent *> toBeRemovedComponents;
358 for ( Qt3DCore::QComponent *component : entity->components() )
360 Qt3DRender::QLayer *layer = qobject_cast<Qt3DRender::QLayer *>( component );
361 if ( layer !=
nullptr )
362 toBeRemovedComponents.push_back( layer );
364 for ( Qt3DCore::QComponent *component : toBeRemovedComponents )
365 entity->removeComponent( component );
366 for ( Qt3DCore::QEntity *obj : entity->findChildren<Qt3DCore::QEntity *>() )
368 if ( obj !=
nullptr )
375 for ( Qt3DRender::QLayer *layer : layers )
376 entity->addComponent( layer );
377 for ( Qt3DCore::QEntity *child : entity->findChildren<Qt3DCore::QEntity *>() )
379 if ( child !=
nullptr )
384 void Qgs3DMapScene::updateScene()
386 QgsEventTracing::addEvent( QgsEventTracing::Instant, QStringLiteral(
"3D" ), QStringLiteral(
"Update Scene" ) );
387 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
389 if ( entity->isEnabled() )
390 entity->update(
_sceneState( mCameraController ) );
395 static void _updateNearFarPlane(
const QList<QgsChunkNode *> &activeNodes,
const QMatrix4x4 &viewMatrix,
float &fnear,
float &ffar )
397 for ( QgsChunkNode *node : activeNodes )
402 for (
int i = 0; i < 8; ++i )
404 QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.
xMin : bbox.
xMax,
405 ( ( i >> 1 ) & 1 ) ? bbox.
yMin : bbox.
yMax,
406 ( ( i >> 2 ) & 1 ) ? bbox.
zMin : bbox.
zMax, 1 );
407 QVector4D pc = viewMatrix * p;
418 bool Qgs3DMapScene::updateCameraNearFarPlanes()
435 QMatrix4x4 viewMatrix = camera->viewMatrix();
439 QList<QgsChunkNode *> activeNodes = mTerrain->activeNodes();
444 if ( activeNodes.isEmpty() )
445 activeNodes << mTerrain->rootNode();
447 _updateNearFarPlane( activeNodes, viewMatrix, fnear, ffar );
451 for ( QgsChunkedEntity *e : std::as_const( mChunkEntities ) )
454 _updateNearFarPlane( e->activeNodes(), viewMatrix, fnear, ffar );
460 if ( fnear == 1e9 && ffar == 0 )
464 qWarning() <<
"oops... this should not happen! couldn't determine near/far plane. defaulting to 1...1e9";
470 float newFar = ffar * 2;
471 float newNear = fnear / 2;
474 camera->setFarPlane( newFar );
475 camera->setNearPlane( newNear );
480 qWarning() <<
"no terrain - not setting near/far plane";
485 void Qgs3DMapScene::onFrameTriggered(
float dt )
489 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
491 if ( entity->isEnabled() && entity->needsUpdate() )
494 entity->update(
_sceneState( mCameraController ) );
501 static int frameCount = 0;
502 static float accumulatedTime = 0.0f;
512 accumulatedTime += dt;
513 if ( accumulatedTime >= 0.2f )
515 float fps = ( float )frameCount / accumulatedTime;
517 accumulatedTime = 0.0f;
522 void Qgs3DMapScene::createTerrain()
526 mChunkEntities.removeOne( mTerrain );
528 mTerrain->deleteLater();
534 if ( !mTerrainUpdateScheduled )
537 QTimer::singleShot( 0,
this, &Qgs3DMapScene::createTerrainDeferred );
538 mTerrainUpdateScheduled =
true;
543 void Qgs3DMapScene::createTerrainDeferred()
549 mMap.
terrainGenerator()->setupQuadtree( rootBbox, rootError, maxZoomLevel );
551 mTerrain =
new QgsTerrainEntity( mMap );
553 mTerrain->setParent(
this );
556 mTerrain->setShowBoundingBoxes(
true );
560 mChunkEntities << mTerrain;
565 const QList<QgsMapLayer *> layers = mMap.
layers();
569 removeLayerEntity( layer );
572 addLayerEntity( layer );
575 mTerrainUpdateScheduled =
false;
583 void Qgs3DMapScene::onBackgroundColorChanged()
588 void Qgs3DMapScene::updateLights()
590 for ( Qt3DCore::QEntity *entity : std::as_const( mLightEntities ) )
591 entity->deleteLater();
592 mLightEntities.clear();
593 for ( Qt3DCore::QEntity *entity : std::as_const( mLightOriginEntities ) )
594 entity->deleteLater();
595 mLightOriginEntities.clear();
597 auto createLightOriginEntity = [ = ]( QVector3D translation,
const QColor & color )->Qt3DCore::QEntity *
599 Qt3DCore::QEntity *originEntity =
new Qt3DCore::QEntity;
601 Qt3DCore::QTransform *trLightOriginCenter =
new Qt3DCore::QTransform;
602 trLightOriginCenter->setTranslation( translation );
603 originEntity->addComponent( trLightOriginCenter );
605 Qt3DExtras::QPhongMaterial *materialLightOriginCenter =
new Qt3DExtras::QPhongMaterial;
606 materialLightOriginCenter->setAmbient( color );
607 originEntity->addComponent( materialLightOriginCenter );
609 Qt3DExtras::QSphereMesh *rendererLightOriginCenter =
new Qt3DExtras::QSphereMesh;
610 rendererLightOriginCenter->setRadius( 20 );
611 originEntity->addComponent( rendererLightOriginCenter );
613 originEntity->setEnabled(
true );
614 originEntity->setParent(
this );
622 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
623 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
624 lightTransform->setTranslation( QVector3D( pointLightSettings.position().x(),
625 pointLightSettings.position().y(),
626 pointLightSettings.position().z() ) );
628 Qt3DRender::QPointLight *light =
new Qt3DRender::QPointLight;
629 light->setColor( pointLightSettings.color() );
630 light->setIntensity( pointLightSettings.intensity() );
632 light->setConstantAttenuation( pointLightSettings.constantAttenuation() );
633 light->setLinearAttenuation( pointLightSettings.linearAttenuation() );
634 light->setQuadraticAttenuation( pointLightSettings.quadraticAttenuation() );
636 lightEntity->addComponent( light );
637 lightEntity->addComponent( lightTransform );
638 lightEntity->setParent(
this );
639 mLightEntities << lightEntity;
642 mLightOriginEntities << createLightOriginEntity( lightTransform->translation(), pointLightSettings.color() );
648 Qt3DCore::QEntity *lightEntity =
new Qt3DCore::QEntity;
649 Qt3DCore::QTransform *lightTransform =
new Qt3DCore::QTransform;
651 Qt3DRender::QDirectionalLight *light =
new Qt3DRender::QDirectionalLight;
652 light->setColor( directionalLightSettings.color() );
653 light->setIntensity( directionalLightSettings.intensity() );
654 QgsVector3D direction = directionalLightSettings.direction();
655 light->setWorldDirection( QVector3D( direction.
x(), direction.
y(), direction.
z() ) );
657 lightEntity->addComponent( light );
658 lightEntity->addComponent( lightTransform );
659 lightEntity->setParent(
this );
660 mLightEntities << lightEntity;
663 onShadowSettingsChanged();
666 void Qgs3DMapScene::updateCameraLens()
673 void Qgs3DMapScene::onRenderersChanged()
676 qDeleteAll( mRenderersEntities );
677 mRenderersEntities.clear();
680 const QList<QgsAbstract3DRenderer *> renderers = mMap.
renderers();
683 Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
686 newEntity->setParent(
this );
687 finalizeNewEntity( newEntity );
688 mRenderersEntities[renderer] = newEntity;
693 void Qgs3DMapScene::onLayerRenderer3DChanged()
695 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
699 removeLayerEntity( layer );
702 addLayerEntity( layer );
705 void Qgs3DMapScene::onLayersChanged()
707 QSet<QgsMapLayer *> layersBefore = qgis::listToSet( mLayerEntities.keys() );
708 QList<QgsMapLayer *> layersAdded;
709 const QList<QgsMapLayer *> layers = mMap.
layers();
712 if ( !layersBefore.contains( layer ) )
714 layersAdded << layer;
718 layersBefore.remove( layer );
723 for (
QgsMapLayer *layer : std::as_const( layersBefore ) )
725 removeLayerEntity( layer );
728 for (
QgsMapLayer *layer : std::as_const( layersAdded ) )
730 addLayerEntity( layer );
736 for (
auto layer : mLayerEntities.keys() )
740 removeLayerEntity( layer );
741 addLayerEntity( layer );
746 void Qgs3DMapScene::addLayerEntity(
QgsMapLayer *layer )
748 bool needsSceneUpdate =
false;
757 ( renderer->
type() == QLatin1String(
"vector" ) || renderer->
type() == QLatin1String(
"rulebased" ) ) )
760 if ( renderer->
type() == QLatin1String(
"vector" ) )
768 mModelVectorLayers.append( layer );
772 else if ( renderer->
type() == QLatin1String(
"rulebased" ) )
775 for (
auto rule : rules )
780 mModelVectorLayers.append( layer );
803 Qt3DCore::QEntity *newEntity = renderer->
createEntity( mMap );
806 newEntity->setParent(
this );
807 mLayerEntities.insert( layer, newEntity );
809 finalizeNewEntity( newEntity );
811 if ( QgsChunkedEntity *chunkedNewEntity = qobject_cast<QgsChunkedEntity *>( newEntity ) )
813 mChunkEntities.append( chunkedNewEntity );
814 needsSceneUpdate =
true;
816 chunkedNewEntity->setPickingEnabled( !mPickHandlers.isEmpty() );
817 connect( chunkedNewEntity, &QgsChunkedEntity::pickedObject,
this, &Qgs3DMapScene::onLayerEntityPickedObject );
819 connect( chunkedNewEntity, &QgsChunkedEntity::newEntityCreated,
this, [
this]( Qt3DCore::QEntity * entity )
821 finalizeNewEntity( entity );
829 if ( needsSceneUpdate )
850 void Qgs3DMapScene::removeLayerEntity(
QgsMapLayer *layer )
852 Qt3DCore::QEntity *entity = mLayerEntities.take( layer );
854 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
856 mChunkEntities.removeOne( chunkedEntity );
860 entity->deleteLater();
869 mModelVectorLayers.removeAll( layer );
881 void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
885 for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
889 lm->setViewportSize( mCameraController->
viewport().size() );
899 bm->setViewportSize( mCameraController->
viewport().size() );
902 bm->setViewportSize( mCameraController->
viewport().size() );
906 int Qgs3DMapScene::maximumTextureSize()
const
908 QSurface *surface = mEngine->
surface();
909 QOpenGLContext context;
911 context.makeCurrent( surface );
912 QOpenGLFunctions openglFunctions( &context );
914 openglFunctions.glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size );
918 void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
920 mEntityCameraViewCenter =
new Qt3DCore::QEntity;
922 Qt3DCore::QTransform *trCameraViewCenter =
new Qt3DCore::QTransform;
923 mEntityCameraViewCenter->addComponent( trCameraViewCenter );
924 connect( camera, &Qt3DRender::QCamera::viewCenterChanged,
this, [trCameraViewCenter, camera]
926 trCameraViewCenter->setTranslation( camera->viewCenter() );
929 Qt3DExtras::QPhongMaterial *materialCameraViewCenter =
new Qt3DExtras::QPhongMaterial;
930 materialCameraViewCenter->setAmbient( Qt::red );
931 mEntityCameraViewCenter->addComponent( materialCameraViewCenter );
933 Qt3DExtras::QSphereMesh *rendererCameraViewCenter =
new Qt3DExtras::QSphereMesh;
934 rendererCameraViewCenter->setRadius( 10 );
935 mEntityCameraViewCenter->addComponent( rendererCameraViewCenter );
938 mEntityCameraViewCenter->setParent(
this );
948 if ( mSceneState == state )
954 void Qgs3DMapScene::updateSceneState()
956 if ( mTerrainUpdateScheduled )
962 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
964 if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
971 setSceneState(
Ready );
974 void Qgs3DMapScene::onSkyboxSettingsChanged()
977 if ( mSkybox !=
nullptr )
979 mSkybox->deleteLater();
987 QMap<QString, QString> faces;
993 faces[QStringLiteral(
"posX" )], faces[QStringLiteral(
"posY" )], faces[QStringLiteral(
"posZ" )],
994 faces[QStringLiteral(
"negX" )], faces[QStringLiteral(
"negY" )], faces[QStringLiteral(
"negZ" )],
1005 void Qgs3DMapScene::onShadowSettingsChanged()
1009 QList<QgsDirectionalLightSettings> directionalLights = mMap.
directionalLights();
1012 if ( shadowSettings.
renderShadows() && selectedLight >= 0 && selectedLight < directionalLights.count() )
1024 void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
1030 void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
1036 void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
1046 void Qgs3DMapScene::onCameraMovementSpeedChanged()
1053 QVector<QString> notParsedLayers;
1063 for (
auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1066 Qt3DCore::QEntity *rootEntity = it.value();
1068 switch ( layerType )
1072 notParsedLayers.push_back( layer->
name() );
1080 notParsedLayers.push_back( layer->
name() );
1090 if ( !notParsedLayers.empty() )
1092 QString message = tr(
"The following layers were not exported:" ) +
"\n";
1093 for (
const QString &layerName : notParsedLayers )
1094 message += layerName +
"\n";
1101 QVector<const QgsChunkNode *> chunks;
1102 if ( !mLayerEntities.contains( layer ) )
return chunks;
1103 if ( QgsChunkedEntity *
c = qobject_cast<QgsChunkedEntity *>( mLayerEntities[ layer ] ) )
1105 for ( QgsChunkNode *n :
c->activeNodes() )
1106 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)