QGIS API Documentation 3.29.0-Master (da8bb1db43)
qgs3dmapscene.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs3dmapscene.cpp
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgs3dmapscene.h"
17
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/QRenderSettings>
25#include <Qt3DRender/QSceneLoader>
26#include <Qt3DExtras/QForwardRenderer>
27#include <Qt3DExtras/QPhongMaterial>
28#include <Qt3DExtras/QPhongAlphaMaterial>
29#include <Qt3DExtras/QDiffuseSpecularMaterial>
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>
38#include <QSurface>
39#include <QUrl>
40#include <QtMath>
41
42#include <QOpenGLContext>
43#include <QOpenGLFunctions>
44#include <QTimer>
45
46#include "qgs3daxis.h"
47#include "qgslogger.h"
48#include "qgsapplication.h"
49#include "qgsaabb.h"
50#include "qgsabstract3dengine.h"
52#include "qgs3dmapsettings.h"
53#include "qgs3dutils.h"
55#include "qgscameracontroller.h"
56#include "qgschunkedentity_p.h"
57#include "qgschunknode_p.h"
58#include "qgseventtracing.h"
59#include "qgsmeshlayer.h"
61#include "qgspoint3dsymbol.h"
63#include "qgspointcloudlayer.h"
65#include "qgssourcecache.h"
66#include "qgsterrainentity_p.h"
67#include "qgsterraingenerator.h"
69#include "qgsvectorlayer.h"
73
74#include "qgslinematerial_p.h"
75#include "qgs3dsceneexporter.h"
78#include "qgsmessageoutput.h"
79
80#include "qgsskyboxentity.h"
81#include "qgsskyboxsettings.h"
82
83#include "qgswindow3dengine.h"
85#include "qgspointcloudlayer.h"
87
89 : mMap( map )
90 , mEngine( engine )
91{
92
93 connect( &map, &Qgs3DMapSettings::backgroundColorChanged, this, &Qgs3DMapScene::onBackgroundColorChanged );
94 onBackgroundColorChanged();
95
96 // The default render policy in Qt3D is "Always" - i.e. the 3D map scene gets refreshed up to 60 fps
97 // even if there's no change. Switching to "on demand" should only re-render when something has changed
98 // and we save quite a lot of resources
99 mEngine->renderSettings()->setRenderPolicy( Qt3DRender::QRenderSettings::OnDemand );
100
101 // we want precise picking of terrain (also bounding volume picking does not seem to work - not sure why)
102 mEngine->renderSettings()->pickingSettings()->setPickMethod( Qt3DRender::QPickingSettings::TrianglePicking );
103
104 QRect viewportRect( QPoint( 0, 0 ), mEngine->size() );
105
106 // Camera
107 float aspectRatio = ( float )viewportRect.width() / viewportRect.height();
108 mEngine->camera()->lens()->setPerspectiveProjection( mMap.fieldOfView(), aspectRatio, 10.f, 10000.0f );
109
110 mFrameAction = new Qt3DLogic::QFrameAction();
111 connect( mFrameAction, &Qt3DLogic::QFrameAction::triggered,
112 this, &Qgs3DMapScene::onFrameTriggered );
113 addComponent( mFrameAction ); // takes ownership
114
115 // Camera controlling
116 mCameraController = new QgsCameraController( this ); // attaches to the scene
117 mCameraController->resetView( 1000 );
118
119 addCameraViewCenterEntity( mEngine->camera() );
120 addCameraRotationCenterEntity( mCameraController );
121 updateLights();
122
123 // create terrain entity
124
125 createTerrainDeferred();
126 connect( &map, &Qgs3DMapSettings::extentChanged, this, &Qgs3DMapScene::createTerrain );
127 connect( &map, &Qgs3DMapSettings::terrainGeneratorChanged, this, &Qgs3DMapScene::createTerrain );
128 connect( &map, &Qgs3DMapSettings::terrainVerticalScaleChanged, this, &Qgs3DMapScene::createTerrain );
129 connect( &map, &Qgs3DMapSettings::mapTileResolutionChanged, this, &Qgs3DMapScene::createTerrain );
130 connect( &map, &Qgs3DMapSettings::maxTerrainScreenErrorChanged, this, &Qgs3DMapScene::createTerrain );
131 connect( &map, &Qgs3DMapSettings::maxTerrainGroundErrorChanged, this, &Qgs3DMapScene::createTerrain );
132 connect( &map, &Qgs3DMapSettings::terrainShadingChanged, this, &Qgs3DMapScene::createTerrain );
133 connect( &map, &Qgs3DMapSettings::lightSourcesChanged, this, &Qgs3DMapScene::updateLights );
134 connect( &map, &Qgs3DMapSettings::showLightSourceOriginsChanged, this, &Qgs3DMapScene::updateLights );
135 connect( &map, &Qgs3DMapSettings::fieldOfViewChanged, this, &Qgs3DMapScene::updateCameraLens );
136 connect( &map, &Qgs3DMapSettings::projectionTypeChanged, this, &Qgs3DMapScene::updateCameraLens );
137 connect( &map, &Qgs3DMapSettings::renderersChanged, this, &Qgs3DMapScene::onRenderersChanged );
138 connect( &map, &Qgs3DMapSettings::skyboxSettingsChanged, this, &Qgs3DMapScene::onSkyboxSettingsChanged );
139 connect( &map, &Qgs3DMapSettings::shadowSettingsChanged, this, &Qgs3DMapScene::onShadowSettingsChanged );
140 connect( &map, &Qgs3DMapSettings::ambientOcclusionSettingsChanged, this, &Qgs3DMapScene::onAmbientOcclusionSettingsChanged );
141 connect( &map, &Qgs3DMapSettings::eyeDomeLightingEnabledChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
142 connect( &map, &Qgs3DMapSettings::eyeDomeLightingStrengthChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
143 connect( &map, &Qgs3DMapSettings::eyeDomeLightingDistanceChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
144 connect( &map, &Qgs3DMapSettings::debugShadowMapSettingsChanged, this, &Qgs3DMapScene::onDebugShadowMapSettingsChanged );
145 connect( &map, &Qgs3DMapSettings::debugDepthMapSettingsChanged, this, &Qgs3DMapScene::onDebugDepthMapSettingsChanged );
147 connect( &map, &Qgs3DMapSettings::cameraMovementSpeedChanged, this, &Qgs3DMapScene::onCameraMovementSpeedChanged );
148 connect( &map, &Qgs3DMapSettings::cameraNavigationModeChanged, this, &Qgs3DMapScene::onCameraNavigationModeChanged );
149 connect( &map, &Qgs3DMapSettings::debugOverlayEnabledChanged, this, &Qgs3DMapScene::onDebugOverlayEnabledChanged );
150
151 connect( &map, &Qgs3DMapSettings::axisSettingsChanged, this, &Qgs3DMapScene::on3DAxisSettingsChanged );
152
153 connect( QgsApplication::sourceCache(), &QgsSourceCache::remoteSourceFetched, this, [ = ]( const QString & url )
154 {
155 const QList<QgsMapLayer *> modelVectorLayers = mModelVectorLayers;
156 for ( QgsMapLayer *layer : modelVectorLayers )
157 {
158 QgsAbstract3DRenderer *renderer = layer->renderer3D();
159 if ( renderer )
160 {
161 if ( renderer->type() == QLatin1String( "vector" ) )
162 {
163 const QgsPoint3DSymbol *pointSymbol = static_cast< const QgsPoint3DSymbol * >( static_cast< QgsVectorLayer3DRenderer *>( renderer )->symbol() );
164 if ( pointSymbol->shapeProperties()[QStringLiteral( "model" )].toString() == url )
165 {
166 removeLayerEntity( layer );
167 addLayerEntity( layer );
168 }
169 }
170 else if ( renderer->type() == QLatin1String( "rulebased" ) )
171 {
172 const QgsRuleBased3DRenderer::RuleList rules = static_cast< QgsRuleBased3DRenderer *>( renderer )->rootRule()->descendants();
173 for ( auto rule : rules )
174 {
175 const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol * >( rule->symbol() );
176 if ( pointSymbol->shapeProperties()[QStringLiteral( "model" )].toString() == url )
177 {
178 removeLayerEntity( layer );
179 addLayerEntity( layer );
180 break;
181 }
182 }
183 }
184 }
185 }
186 } );
187
188 // create entities of renderers
189
190 onRenderersChanged();
191
192 // listen to changes of layers in order to add/remove 3D renderer entities
193 connect( &map, &Qgs3DMapSettings::layersChanged, this, &Qgs3DMapScene::onLayersChanged );
194
195
196#if 0
197 ChunkedEntity *testChunkEntity = new ChunkedEntity( AABB( -500, 0, -500, 500, 100, 500 ), 2.f, 3.f, 7, new TestChunkLoaderFactory );
198 testChunkEntity->setEnabled( false );
199 testChunkEntity->setParent( this );
200 chunkEntities << testChunkEntity;
201#endif
202
203 connect( mCameraController, &QgsCameraController::cameraChanged, this, &Qgs3DMapScene::onCameraChanged );
204 connect( mEngine, &QgsAbstract3DEngine::sizeChanged, this, &Qgs3DMapScene::onCameraChanged );
205
206#if 0
207 // experiments with loading of existing 3D models.
208
209 // scene loader only gets loaded only when added to a scene...
210 // it loads everything: geometries, materials, transforms, lights, cameras (if any)
211 Qt3DCore::QEntity *loaderEntity = new Qt3DCore::QEntity;
212 Qt3DRender::QSceneLoader *loader = new Qt3DRender::QSceneLoader;
213 loader->setSource( QUrl( "file:///home/martin/Downloads/LowPolyModels/tree.dae" ) );
214 loaderEntity->addComponent( loader );
215 loaderEntity->setParent( this );
216
217 // mesh loads just geometry as one geometry...
218 // so if there are different materials (e.g. colors) used in the model, this information is lost
219 Qt3DCore::QEntity *meshEntity = new Qt3DCore::QEntity;
220 Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh;
221 mesh->setSource( QUrl( "file:///home/martin/Downloads/LowPolyModels/tree.obj" ) );
222 meshEntity->addComponent( mesh );
223 Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial;
224 material->setAmbient( Qt::red );
225 meshEntity->addComponent( material );
226 Qt3DCore::QTransform *meshTransform = new Qt3DCore::QTransform;
227 meshTransform->setScale( 1 );
228 meshEntity->addComponent( meshTransform );
229 meshEntity->setParent( this );
230#endif
231 onSkyboxSettingsChanged();
232
233 // force initial update of chunked entities
234 onCameraChanged();
235 // force initial update of eye dome shading
236 onEyeDomeShadingSettingsChanged();
237 // force initial update of debugging setting of preview quads
238 onDebugShadowMapSettingsChanged();
239 onDebugDepthMapSettingsChanged();
240 // force initial update of ambient occlusion settings
241 onAmbientOcclusionSettingsChanged();
242
243 mCameraController->setCameraNavigationMode( mMap.cameraNavigationMode() );
244 onCameraMovementSpeedChanged();
245
246 on3DAxisSettingsChanged();
247}
248
250{
251 const QgsDoubleRange yRange = elevationRange();
252 const QgsRectangle extent = sceneExtent();
253 const double side = std::max( extent.width(), extent.height() );
254 double d = side / 2 / std::tan( cameraController()->camera()->fieldOfView() / 2 * M_PI / 180 );
255 d += yRange.upper();
256 mCameraController->resetView( static_cast< float >( d ) );
257 return;
258}
259
261{
262 QgsPointXY center = extent.center();
263 QgsVector3D centerWorld = mMap.mapToWorldCoordinates( QVector3D( center.x(), center.y(), 0 ) );
264 QgsVector3D p1 = mMap.mapToWorldCoordinates( QVector3D( extent.xMinimum(), extent.yMinimum(), 0 ) );
265 QgsVector3D p2 = mMap.mapToWorldCoordinates( QVector3D( extent.xMaximum(), extent.yMaximum(), 0 ) );
266
267 float xSide = std::abs( p1.x() - p2.x() );
268 float ySide = std::abs( p1.z() - p2.z() );
269 if ( xSide < ySide )
270 {
271 float fov = 2 * std::atan( std::tan( qDegreesToRadians( cameraController()->camera()->fieldOfView() ) / 2 ) * cameraController()->camera()->aspectRatio() );
272 float r = xSide / 2.0f / std::tan( fov / 2.0f );
273 mCameraController->setViewFromTop( centerWorld.x(), centerWorld.z(), r );
274 }
275 else
276 {
277 float fov = qDegreesToRadians( cameraController()->camera()->fieldOfView() );
278 float r = ySide / 2.0f / std::tan( fov / 2.0f );
279 mCameraController->setViewFromTop( centerWorld.x(), centerWorld.z(), r );
280 }
281}
282
284{
285 Qt3DRender::QCamera *camera = mCameraController->camera();
286 QVector<QgsPointXY> extent;
287 QVector<int> pointsOrder = { 0, 1, 3, 2 };
288 for ( int i : pointsOrder )
289 {
290 const QPoint p( ( ( i >> 0 ) & 1 ) ? 0 : mEngine->size().width(), ( ( i >> 1 ) & 1 ) ? 0 : mEngine->size().height() );
291 QgsRay3D ray = Qgs3DUtils::rayFromScreenPoint( p, mEngine->size(), camera );
292 QVector3D dir = ray.direction();
293 if ( dir.y() == 0.0 )
294 dir.setY( 0.000001 );
295 double t = - ray.origin().y() / dir.y();
296 if ( t < 0 )
297 {
298 // If the projected point is on the back of the camera we choose the farthest point in the front
299 t = camera->farPlane();
300 }
301 else
302 {
303 // If the projected point is on the front of the camera we choose the closest between it and farthest point in the front
304 t = std::min<float>( t, camera->farPlane() );
305 }
306 QVector3D planePoint = ray.origin() + t * dir;
307 QgsVector3D pMap = mMap.worldToMapCoordinates( planePoint );
308 extent.push_back( QgsPointXY( pMap.x(), pMap.y() ) );
309 }
310 return extent;
311}
312
314{
315 return mTerrain ? mTerrain->pendingJobsCount() : 0;
316}
317
319{
320 int count = 0;
321 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
322 count += entity->pendingJobsCount();
323 return count;
324}
325
327{
328 if ( mPickHandlers.isEmpty() )
329 {
330 // we need to add object pickers
331 for ( Qt3DCore::QEntity *entity : mLayerEntities )
332 {
333 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
334 chunkedEntity->setPickingEnabled( true );
335 }
336 }
337
338 mPickHandlers.append( pickHandler );
339}
340
342{
343 mPickHandlers.removeOne( pickHandler );
344
345 if ( mPickHandlers.isEmpty() )
346 {
347 // we need to remove pickers
348 for ( Qt3DCore::QEntity *entity : mLayerEntities )
349 {
350 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
351 chunkedEntity->setPickingEnabled( false );
352 }
353 }
354}
355
356void Qgs3DMapScene::onLayerEntityPickedObject( Qt3DRender::QPickEvent *pickEvent, QgsFeatureId fid )
357{
358 QgsMapLayer *layer = mLayerEntities.key( qobject_cast<QgsChunkedEntity *>( sender() ) );
359 if ( !layer )
360 return;
361
362 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
363 if ( !vlayer )
364 return;
365
366 for ( Qgs3DMapScenePickHandler *pickHandler : std::as_const( mPickHandlers ) )
367 {
368 pickHandler->handlePickOnVectorLayer( vlayer, fid, pickEvent->worldIntersection(), pickEvent );
369 }
370}
371
372float Qgs3DMapScene::worldSpaceError( float epsilon, float distance )
373{
374 Qt3DRender::QCamera *camera = mCameraController->camera();
375 float fov = camera->fieldOfView();
376 const QSize size = mEngine->size();
377 float screenSizePx = std::max( size.width(), size.height() ); // TODO: is this correct?
378
379 // in qgschunkedentity_p.cpp there is inverse calculation (world space error to screen space error)
380 // with explanation of the math.
381 float frustumWidthAtDistance = 2 * distance * tan( fov / 2 );
382 float err = frustumWidthAtDistance * epsilon / screenSizePx;
383 return err;
384}
385
386QgsChunkedEntity::SceneState sceneState_( QgsAbstract3DEngine *engine )
387{
388 Qt3DRender::QCamera *camera = engine->camera();
389 QgsChunkedEntity::SceneState state;
390 state.cameraFov = camera->fieldOfView();
391 state.cameraPos = camera->position();
392 const QSize size = engine->size();
393 state.screenSizePx = std::max( size.width(), size.height() ); // TODO: is this correct?
394 state.viewProjectionMatrix = camera->projectionMatrix() * camera->viewMatrix();
395 return state;
396}
397
398void Qgs3DMapScene::onCameraChanged()
399{
400 if ( mMap.projectionType() == Qt3DRender::QCameraLens::OrthographicProjection )
401 {
402 QRect viewportRect( QPoint( 0, 0 ), mEngine->size() );
403 const float viewWidthFromCenter = mCameraController->distance();
404 const float viewHeightFromCenter = viewportRect.height() * viewWidthFromCenter / viewportRect.width();
405 mEngine->camera()->lens()->setOrthographicProjection( -viewWidthFromCenter, viewWidthFromCenter, -viewHeightFromCenter, viewHeightFromCenter, mEngine->camera()->nearPlane(), mEngine->camera()->farPlane() );
406 }
407
408 updateScene();
409 bool changedCameraPlanes = updateCameraNearFarPlanes();
410
411 if ( changedCameraPlanes )
412 {
413 // repeat update of entities - because we have updated camera's near/far planes,
414 // the active nodes may have changed as well
415 updateScene();
416 updateCameraNearFarPlanes();
417 }
418
419 onShadowSettingsChanged();
420
421 QVector<QgsPointXY> extent2D = viewFrustum2DExtent();
422 emit viewed2DExtentFrom3DChanged( extent2D );
423}
424
425void removeQLayerComponentsFromHierarchy( Qt3DCore::QEntity *entity )
426{
427 QVector<Qt3DCore::QComponent *> toBeRemovedComponents;
428 for ( Qt3DCore::QComponent *component : entity->components() )
429 {
430 Qt3DRender::QLayer *layer = qobject_cast<Qt3DRender::QLayer *>( component );
431 if ( layer != nullptr )
432 toBeRemovedComponents.push_back( layer );
433 }
434 for ( Qt3DCore::QComponent *component : toBeRemovedComponents )
435 entity->removeComponent( component );
436 for ( Qt3DCore::QEntity *obj : entity->findChildren<Qt3DCore::QEntity *>() )
437 {
438 if ( obj != nullptr )
440 }
441}
442
443void addQLayerComponentsToHierarchy( Qt3DCore::QEntity *entity, const QVector<Qt3DRender::QLayer *> &layers )
444{
445 for ( Qt3DRender::QLayer *layer : layers )
446 entity->addComponent( layer );
447 for ( Qt3DCore::QEntity *child : entity->findChildren<Qt3DCore::QEntity *>() )
448 {
449 if ( child != nullptr )
450 addQLayerComponentsToHierarchy( child, layers );
451 }
452}
453
454void Qgs3DMapScene::updateScene()
455{
456 QgsEventTracing::addEvent( QgsEventTracing::Instant, QStringLiteral( "3D" ), QStringLiteral( "Update Scene" ) );
457 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
458 {
459 if ( entity->isEnabled() )
460 entity->update( sceneState_( mEngine ) );
461 }
462 updateSceneState();
463}
464
465static void _updateNearFarPlane( const QList<QgsChunkNode *> &activeNodes, const QMatrix4x4 &viewMatrix, float &fnear, float &ffar )
466{
467 for ( QgsChunkNode *node : activeNodes )
468 {
469 // project each corner of bbox to camera coordinates
470 // and determine closest and farthest point.
471 QgsAABB bbox = node->bbox();
472 for ( int i = 0; i < 8; ++i )
473 {
474 QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.xMin : bbox.xMax,
475 ( ( i >> 1 ) & 1 ) ? bbox.yMin : bbox.yMax,
476 ( ( i >> 2 ) & 1 ) ? bbox.zMin : bbox.zMax, 1 );
477
478 QVector4D pc = viewMatrix * p;
479
480
481 float dst = -pc.z(); // in camera coordinates, x grows right, y grows down, z grows to the back
482 fnear = std::min( fnear, dst );
483 ffar = std::max( ffar, dst );
484 }
485 }
486}
487
488bool Qgs3DMapScene::updateCameraNearFarPlanes()
489{
490 // Update near and far plane from the terrain.
491 // this needs to be done with great care as we have kind of circular dependency here:
492 // active nodes are culled based on the current frustum (which involves near + far plane)
493 // and then based on active nodes we set near and far plane.
494 //
495 // All of this is just heuristics assuming that all other stuff is being rendered somewhere
496 // around the area where the terrain is.
497 //
498 // Near/far plane is setup in order to make best use of the depth buffer to avoid:
499 // 1. precision errors - if the range is too great
500 // 2. unwanted clipping of scene - if the range is too small
501
502 Qt3DRender::QCamera *camera = cameraController()->camera();
503 QMatrix4x4 viewMatrix = camera->viewMatrix();
504 float fnear = 1e9;
505 float ffar = 0;
506 QList<QgsChunkNode *> activeNodes;
507 if ( mTerrain )
508 activeNodes = mTerrain->activeNodes();
509
510 // it could be that there are no active nodes - they could be all culled or because root node
511 // is not yet loaded - we still need at least something to understand bounds of our scene
512 // so lets use the root node
513 if ( mTerrain && activeNodes.isEmpty() )
514 activeNodes << mTerrain->rootNode();
515
516 _updateNearFarPlane( activeNodes, viewMatrix, fnear, ffar );
517
518 // Also involve all the other chunked entities to make sure that they will not get
519 // clipped by the near or far plane
520 for ( QgsChunkedEntity *e : std::as_const( mChunkEntities ) )
521 {
522 if ( e != mTerrain )
523 {
524 QList<QgsChunkNode *> activeEntityNodes = e->activeNodes();
525 if ( activeEntityNodes.empty() )
526 activeEntityNodes << e->rootNode();
527 _updateNearFarPlane( activeEntityNodes, viewMatrix, fnear, ffar );
528 }
529 }
530
531 if ( fnear < 1 )
532 fnear = 1; // does not really make sense to use negative far plane (behind camera)
533
534 // when zooming in a lot, fnear can become smaller than ffar. This should not happen
535 if ( fnear > ffar )
536 std::swap( fnear, ffar );
537
538 if ( fnear == 1e9 && ffar == 0 )
539 {
540 // the update didn't work out... this should not happen
541 // well at least temporarily use some conservative starting values
542 qWarning() << "oops... this should not happen! couldn't determine near/far plane. defaulting to 1...1e9";
543 fnear = 1;
544 ffar = 1e9;
545 }
546
547 // set near/far plane - with some tolerance in front/behind expected near/far planes
548 float newFar = ffar * 2;
549 float newNear = fnear / 2;
550 if ( !qgsFloatNear( newFar, camera->farPlane() ) || !qgsFloatNear( newNear, camera->nearPlane() ) )
551 {
552 camera->setFarPlane( newFar );
553 camera->setNearPlane( newNear );
554 return true;
555 }
556
557 return false;
558}
559
560void Qgs3DMapScene::onFrameTriggered( float dt )
561{
562 mCameraController->frameTriggered( dt );
563
564 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
565 {
566 if ( entity->isEnabled() && entity->needsUpdate() )
567 {
568 QgsDebugMsgLevel( QStringLiteral( "need for update" ), 2 );
569 entity->update( sceneState_( mEngine ) );
570 }
571 }
572
573 updateSceneState();
574
575 // lock changing the FPS counter to 5 fps
576 static int frameCount = 0;
577 static float accumulatedTime = 0.0f;
578
579 if ( !mMap.isFpsCounterEnabled() )
580 {
581 frameCount = 0;
582 accumulatedTime = 0;
583 return;
584 }
585
586 frameCount++;
587 accumulatedTime += dt;
588 if ( accumulatedTime >= 0.2f )
589 {
590 float fps = ( float )frameCount / accumulatedTime;
591 frameCount = 0;
592 accumulatedTime = 0.0f;
593 emit fpsCountChanged( fps );
594 }
595}
596
597void Qgs3DMapScene::createTerrain()
598{
599 if ( mTerrain )
600 {
601 mChunkEntities.removeOne( mTerrain );
602
603 mTerrain->deleteLater();
604 mTerrain = nullptr;
605 }
606
607 if ( !mTerrainUpdateScheduled )
608 {
609 // defer re-creation of terrain: there may be multiple invocations of this slot, so create the new entity just once
610 QTimer::singleShot( 0, this, &Qgs3DMapScene::createTerrainDeferred );
611 mTerrainUpdateScheduled = true;
612 setSceneState( Updating );
613 }
614 else
615 {
617 }
618}
619
620void Qgs3DMapScene::createTerrainDeferred()
621{
622 if ( mMap.terrainRenderingEnabled() && mMap.terrainGenerator() )
623 {
624 double tile0width = mMap.terrainGenerator()->rootChunkExtent().width();
625 int maxZoomLevel = Qgs3DUtils::maxZoomLevel( tile0width, mMap.mapTileResolution(), mMap.maxTerrainGroundError() );
626 QgsAABB rootBbox = mMap.terrainGenerator()->rootChunkBbox( mMap );
627 float rootError = mMap.terrainGenerator()->rootChunkError( mMap );
628 const QgsAABB clippingBbox = Qgs3DUtils::mapToWorldExtent( mMap.extent(), rootBbox.zMin, rootBbox.zMax, mMap.origin() );
629 mMap.terrainGenerator()->setupQuadtree( rootBbox, rootError, maxZoomLevel, clippingBbox );
630
631 mTerrain = new QgsTerrainEntity( mMap );
632 mTerrain->setParent( this );
633 mTerrain->setShowBoundingBoxes( mMap.showTerrainBoundingBoxes() );
634
635 mChunkEntities << mTerrain;
636
637 connect( mTerrain, &QgsChunkedEntity::pendingJobsCountChanged, this, &Qgs3DMapScene::totalPendingJobsCountChanged );
638 connect( mTerrain, &QgsTerrainEntity::pendingJobsCountChanged, this, &Qgs3DMapScene::terrainPendingJobsCountChanged );
639 }
640 else
641 {
642 mTerrain = nullptr;
643 }
644
645 // make sure that renderers for layers are re-created as well
646 const QList<QgsMapLayer *> layers = mMap.layers();
647 for ( QgsMapLayer *layer : layers )
648 {
649 // remove old entity - if any
650 removeLayerEntity( layer );
651
652 // add new entity - if any 3D renderer
653 addLayerEntity( layer );
654 }
655
657 onCameraChanged(); // force update of the new terrain
658 mTerrainUpdateScheduled = false;
659}
660
661void Qgs3DMapScene::onBackgroundColorChanged()
662{
663 mEngine->setClearColor( mMap.backgroundColor() );
664}
665
666void Qgs3DMapScene::updateLights()
667{
668 for ( Qt3DCore::QEntity *entity : std::as_const( mLightEntities ) )
669 entity->deleteLater();
670 mLightEntities.clear();
671
672 const QList< QgsLightSource * > newLights = mMap.lightSources();
673 for ( const QgsLightSource *source : newLights )
674 {
675 mLightEntities.append( source->createEntity( mMap, this ) );
676 }
677
678 onShadowSettingsChanged();
679}
680
681void Qgs3DMapScene::updateCameraLens()
682{
683 mEngine->camera()->lens()->setFieldOfView( mMap.fieldOfView() );
684 mEngine->camera()->lens()->setProjectionType( mMap.projectionType() );
685 onCameraChanged();
686}
687
688void Qgs3DMapScene::onRenderersChanged()
689{
690 // remove entities (if any)
691 qDeleteAll( mRenderersEntities );
692 mRenderersEntities.clear();
693
694 // re-add entities from new set of renderers
695 const QList<QgsAbstract3DRenderer *> renderers = mMap.renderers();
696 for ( const QgsAbstract3DRenderer *renderer : renderers )
697 {
698 Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
699 if ( newEntity )
700 {
701 newEntity->setParent( this );
702 finalizeNewEntity( newEntity );
703 mRenderersEntities[renderer] = newEntity;
704 }
705 }
706}
707
708void Qgs3DMapScene::onLayerRenderer3DChanged()
709{
710 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
711 Q_ASSERT( layer );
712
713 // remove old entity - if any
714 removeLayerEntity( layer );
715
716 // add new entity - if any 3D renderer
717 addLayerEntity( layer );
718}
719
720void Qgs3DMapScene::onLayersChanged()
721{
722 QSet<QgsMapLayer *> layersBefore = qgis::listToSet( mLayerEntities.keys() );
723 QList<QgsMapLayer *> layersAdded;
724 const QList<QgsMapLayer *> layers = mMap.layers();
725 for ( QgsMapLayer *layer : layers )
726 {
727 if ( !layersBefore.contains( layer ) )
728 {
729 layersAdded << layer;
730 }
731 else
732 {
733 layersBefore.remove( layer );
734 }
735 }
736
737 // what is left in layersBefore are layers that have been removed
738 for ( QgsMapLayer *layer : std::as_const( layersBefore ) )
739 {
740 removeLayerEntity( layer );
741 }
742
743 for ( QgsMapLayer *layer : std::as_const( layersAdded ) )
744 {
745 addLayerEntity( layer );
746 }
747}
748
750{
751 const QList<QgsMapLayer * > layers = mLayerEntities.keys();
752 for ( QgsMapLayer *layer : layers )
753 {
754 if ( layer->temporalProperties()->isActive() )
755 {
756 removeLayerEntity( layer );
757 addLayerEntity( layer );
758 }
759 }
760}
761
762void Qgs3DMapScene::addLayerEntity( QgsMapLayer *layer )
763{
764 bool needsSceneUpdate = false;
765 QgsAbstract3DRenderer *renderer = layer->renderer3D();
766 if ( renderer )
767 {
768 // Fix vector layer's renderer to make sure the renderer is pointing to its layer.
769 // It has happened before that renderer pointed to a different layer (probably after copying a style).
770 // This is a bit of a hack and it should be handled in QgsMapLayer::setRenderer3D() but in qgis_core
771 // the vector layer 3D renderer classes are not available.
772 if ( layer->type() == QgsMapLayerType::VectorLayer &&
773 ( renderer->type() == QLatin1String( "vector" ) || renderer->type() == QLatin1String( "rulebased" ) ) )
774 {
775 static_cast<QgsAbstractVectorLayer3DRenderer *>( renderer )->setLayer( static_cast<QgsVectorLayer *>( layer ) );
776 if ( renderer->type() == QLatin1String( "vector" ) )
777 {
778 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
779 if ( vlayer->geometryType() == QgsWkbTypes::PointGeometry )
780 {
781 const QgsPoint3DSymbol *pointSymbol = static_cast< const QgsPoint3DSymbol * >( static_cast< QgsVectorLayer3DRenderer *>( renderer )->symbol() );
782 if ( pointSymbol->shape() == QgsPoint3DSymbol::Model )
783 {
784 mModelVectorLayers.append( layer );
785 }
786 }
787 }
788 else if ( renderer->type() == QLatin1String( "rulebased" ) )
789 {
790 const QgsRuleBased3DRenderer::RuleList rules = static_cast< QgsRuleBased3DRenderer *>( renderer )->rootRule()->descendants();
791 for ( auto rule : rules )
792 {
793 const QgsPoint3DSymbol *pointSymbol = dynamic_cast< const QgsPoint3DSymbol * >( rule->symbol() );
794 if ( pointSymbol && pointSymbol->shape() == QgsPoint3DSymbol::Model )
795 {
796 mModelVectorLayers.append( layer );
797 break;
798 }
799 }
800 }
801 }
802 else if ( layer->type() == QgsMapLayerType::MeshLayer && renderer->type() == QLatin1String( "mesh" ) )
803 {
804 QgsMeshLayer3DRenderer *meshRenderer = static_cast<QgsMeshLayer3DRenderer *>( renderer );
805 meshRenderer->setLayer( static_cast<QgsMeshLayer *>( layer ) );
806
807 // Before entity creation, set the maximum texture size
808 // Not very clean, but for now, only place found in the workflow to do that simple
809 QgsMesh3DSymbol *sym = meshRenderer->symbol()->clone();
810 sym->setMaximumTextureSize( maximumTextureSize() );
811 meshRenderer->setSymbol( sym );
812 }
813 else if ( layer->type() == QgsMapLayerType::PointCloudLayer && renderer->type() == QLatin1String( "pointcloud" ) )
814 {
815 QgsPointCloudLayer3DRenderer *pointCloudRenderer = static_cast<QgsPointCloudLayer3DRenderer *>( renderer );
816 pointCloudRenderer->setLayer( static_cast<QgsPointCloudLayer *>( layer ) );
817 }
818
819 Qt3DCore::QEntity *newEntity = renderer->createEntity( mMap );
820 if ( newEntity )
821 {
822 newEntity->setParent( this );
823 mLayerEntities.insert( layer, newEntity );
824
825 finalizeNewEntity( newEntity );
826
827 if ( QgsChunkedEntity *chunkedNewEntity = qobject_cast<QgsChunkedEntity *>( newEntity ) )
828 {
829 mChunkEntities.append( chunkedNewEntity );
830 needsSceneUpdate = true;
831
832 chunkedNewEntity->setPickingEnabled( !mPickHandlers.isEmpty() );
833 connect( chunkedNewEntity, &QgsChunkedEntity::pickedObject, this, &Qgs3DMapScene::onLayerEntityPickedObject );
834
835 connect( chunkedNewEntity, &QgsChunkedEntity::newEntityCreated, this, [this]( Qt3DCore::QEntity * entity )
836 {
837 finalizeNewEntity( entity );
838 } );
839
840 connect( chunkedNewEntity, &QgsChunkedEntity::pendingJobsCountChanged, this, &Qgs3DMapScene::totalPendingJobsCountChanged );
841 }
842 }
843 }
844
845 if ( needsSceneUpdate )
846 onCameraChanged(); // needed for chunked entities
847
848 connect( layer, &QgsMapLayer::request3DUpdate, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
849
850 if ( layer->type() == QgsMapLayerType::VectorLayer )
851 {
852 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
853 connect( vlayer, &QgsVectorLayer::selectionChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
854 connect( vlayer, &QgsVectorLayer::layerModified, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
855 }
856
857 if ( layer->type() == QgsMapLayerType::MeshLayer )
858 {
859 connect( layer, &QgsMapLayer::rendererChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
860 }
861
862 if ( layer->type() == QgsMapLayerType::PointCloudLayer )
863 {
864 QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer *>( layer );
865 connect( pclayer, &QgsPointCloudLayer::renderer3DChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
866 connect( pclayer, &QgsPointCloudLayer::subsetStringChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
867 }
868}
869
870void Qgs3DMapScene::removeLayerEntity( QgsMapLayer *layer )
871{
872 Qt3DCore::QEntity *entity = mLayerEntities.take( layer );
873
874 if ( QgsChunkedEntity *chunkedEntity = qobject_cast<QgsChunkedEntity *>( entity ) )
875 {
876 mChunkEntities.removeOne( chunkedEntity );
877 }
878
879 if ( entity )
880 entity->deleteLater();
881
882 disconnect( layer, &QgsMapLayer::request3DUpdate, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
883
884 if ( layer->type() == QgsMapLayerType::VectorLayer )
885 {
886 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
887 disconnect( vlayer, &QgsVectorLayer::selectionChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
888 disconnect( vlayer, &QgsVectorLayer::layerModified, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
889 mModelVectorLayers.removeAll( layer );
890 }
891
892 if ( layer->type() == QgsMapLayerType::MeshLayer )
893 {
894 disconnect( layer, &QgsMapLayer::rendererChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
895 }
896
897 if ( layer->type() == QgsMapLayerType::PointCloudLayer )
898 {
899 QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer *>( layer );
900 disconnect( pclayer, &QgsPointCloudLayer::renderer3DChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
901 disconnect( pclayer, &QgsPointCloudLayer::subsetStringChanged, this, &Qgs3DMapScene::onLayerRenderer3DChanged );
902 }
903}
904
905void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
906{
907 // this is probably not the best place for material-specific configuration,
908 // maybe this could be more generalized when other materials need some specific treatment
909 for ( QgsLineMaterial *lm : newEntity->findChildren<QgsLineMaterial *>() )
910 {
911 connect( mEngine, &QgsAbstract3DEngine::sizeChanged, lm, [lm, this]
912 {
913 lm->setViewportSize( mEngine->size() );
914 } );
915
916 lm->setViewportSize( mEngine->size() );
917 }
918 // configure billboard's viewport when the viewport is changed.
919 for ( QgsPoint3DBillboardMaterial *bm : newEntity->findChildren<QgsPoint3DBillboardMaterial *>() )
920 {
921 connect( mEngine, &QgsAbstract3DEngine::sizeChanged, bm, [bm, this]
922 {
923 bm->setViewportSize( mEngine->size() );
924 } );
925
926 bm->setViewportSize( mEngine->size() );
927 }
928
929 // Finalize adding the 3D transparent objects by adding the layer components to the entities
930 QgsShadowRenderingFrameGraph *frameGraph = mEngine->frameGraph();
931 Qt3DRender::QLayer *transparentLayer = frameGraph->transparentObjectLayer();
932 for ( Qt3DRender::QMaterial *material : newEntity->findChildren<Qt3DRender::QMaterial *>() )
933 {
934 // This handles the phong material without data defined properties.
935 if ( Qt3DExtras::QDiffuseSpecularMaterial *ph = qobject_cast<Qt3DExtras::QDiffuseSpecularMaterial *>( material ) )
936 {
937 if ( ph->diffuse().value<QColor>().alphaF() != 1.0f )
938 {
939 Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( ph->parent() );
940 if ( entity && !entity->components().contains( transparentLayer ) )
941 {
942 entity->addComponent( transparentLayer );
943 }
944 }
945 }
946 else
947 {
948 // This handles the phong material with data defined properties, the textured case and point (instanced) symbols.
949 Qt3DRender::QEffect *effect = material->effect();
950 if ( effect )
951 {
952 for ( const auto *parameter : effect->parameters() )
953 {
954 if ( parameter->name() == "opacity" && parameter->value() != 1.0f )
955 {
956 Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( material->parent() );
957 if ( entity && !entity->components().contains( transparentLayer ) )
958 {
959 entity->addComponent( transparentLayer );
960 }
961 break;
962 }
963 }
964 }
965 }
966 }
967}
968
969int Qgs3DMapScene::maximumTextureSize() const
970{
971 QSurface *surface = mEngine->surface();
972 QOpenGLContext context;
973 context.create();
974 bool success = context.makeCurrent( surface );
975
976 if ( success )
977 {
978 QOpenGLFunctions openglFunctions = QOpenGLFunctions( &context );
979
980 GLint size;
981 openglFunctions.initializeOpenGLFunctions();
982 openglFunctions.glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size );
983 return int( size );
984 }
985 else
986 {
987 return 4096; //we can't have a context to defined the max texture size, we use this reasonable value
988 }
989
990}
991
992void Qgs3DMapScene::addCameraViewCenterEntity( Qt3DRender::QCamera *camera )
993{
994 mEntityCameraViewCenter = new Qt3DCore::QEntity;
995
996 Qt3DCore::QTransform *trCameraViewCenter = new Qt3DCore::QTransform;
997 mEntityCameraViewCenter->addComponent( trCameraViewCenter );
998 connect( camera, &Qt3DRender::QCamera::viewCenterChanged, this, [trCameraViewCenter, camera]
999 {
1000 trCameraViewCenter->setTranslation( camera->viewCenter() );
1001 } );
1002
1003 Qt3DExtras::QPhongMaterial *materialCameraViewCenter = new Qt3DExtras::QPhongMaterial;
1004 materialCameraViewCenter->setAmbient( Qt::red );
1005 mEntityCameraViewCenter->addComponent( materialCameraViewCenter );
1006
1007 Qt3DExtras::QSphereMesh *rendererCameraViewCenter = new Qt3DExtras::QSphereMesh;
1008 rendererCameraViewCenter->setRadius( 10 );
1009 mEntityCameraViewCenter->addComponent( rendererCameraViewCenter );
1010
1011 mEntityCameraViewCenter->setEnabled( mMap.showCameraViewCenter() );
1012 mEntityCameraViewCenter->setParent( this );
1013
1014 connect( &mMap, &Qgs3DMapSettings::showCameraViewCenterChanged, this, [this]
1015 {
1016 mEntityCameraViewCenter->setEnabled( mMap.showCameraViewCenter() );
1017 } );
1018}
1019
1020void Qgs3DMapScene::setSceneState( Qgs3DMapScene::SceneState state )
1021{
1022 if ( mSceneState == state )
1023 return;
1024 mSceneState = state;
1025 emit sceneStateChanged();
1026}
1027
1028void Qgs3DMapScene::updateSceneState()
1029{
1030 if ( mTerrainUpdateScheduled )
1031 {
1032 setSceneState( Updating );
1033 return;
1034 }
1035
1036 for ( QgsChunkedEntity *entity : std::as_const( mChunkEntities ) )
1037 {
1038 if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
1039 {
1040 setSceneState( Updating );
1041 return;
1042 }
1043 }
1044
1045 setSceneState( Ready );
1046}
1047
1048void Qgs3DMapScene::onSkyboxSettingsChanged()
1049{
1050 QgsSkyboxSettings skyboxSettings = mMap.skyboxSettings();
1051 if ( mSkybox != nullptr )
1052 {
1053 mSkybox->deleteLater();
1054 mSkybox = nullptr;
1055 }
1056
1057 mEngine->setFrustumCullingEnabled( !mMap.isSkyboxEnabled() );
1058
1059 if ( mMap.isSkyboxEnabled() )
1060 {
1061 QMap<QString, QString> faces;
1062 switch ( skyboxSettings.skyboxType() )
1063 {
1065 faces = skyboxSettings.cubeMapFacesPaths();
1066 mSkybox = new QgsCubeFacesSkyboxEntity(
1067 faces[QStringLiteral( "posX" )], faces[QStringLiteral( "posY" )], faces[QStringLiteral( "posZ" )],
1068 faces[QStringLiteral( "negX" )], faces[QStringLiteral( "negY" )], faces[QStringLiteral( "negZ" )],
1069 this
1070 );
1071 break;
1073 mSkybox = new QgsPanoramicSkyboxEntity( skyboxSettings.panoramicTexturePath(), this );
1074 break;
1075 }
1076 }
1077}
1078
1079void Qgs3DMapScene::onShadowSettingsChanged()
1080{
1081 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1082
1083 const QList< QgsLightSource * > lightSources = mMap.lightSources();
1084 QList< QgsDirectionalLightSettings * > directionalLightSources;
1085 for ( QgsLightSource *source : lightSources )
1086 {
1087 if ( source->type() == Qgis::LightSourceType::Directional )
1088 {
1089 directionalLightSources << qgis::down_cast< QgsDirectionalLightSettings * >( source );
1090 }
1091 }
1092
1093 QgsShadowSettings shadowSettings = mMap.shadowSettings();
1094 int selectedLight = shadowSettings.selectedDirectionalLight();
1095 if ( shadowSettings.renderShadows() && selectedLight >= 0 && selectedLight < directionalLightSources.count() )
1096 {
1097 shadowRenderingFrameGraph->setShadowRenderingEnabled( true );
1098 shadowRenderingFrameGraph->setShadowBias( shadowSettings.shadowBias() );
1099 shadowRenderingFrameGraph->setShadowMapResolution( shadowSettings.shadowMapResolution() );
1100 QgsDirectionalLightSettings light = *directionalLightSources.at( selectedLight );
1101 shadowRenderingFrameGraph->setupDirectionalLight( light, shadowSettings.maximumShadowRenderingDistance() );
1102 }
1103 else
1104 shadowRenderingFrameGraph->setShadowRenderingEnabled( false );
1105}
1106
1107void Qgs3DMapScene::onAmbientOcclusionSettingsChanged()
1108{
1109 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1110 QgsAmbientOcclusionSettings ambientOcclusionSettings = mMap.ambientOcclusionSettings();
1111 shadowRenderingFrameGraph->setAmbientOcclusionEnabled( ambientOcclusionSettings.isEnabled() );
1112 shadowRenderingFrameGraph->setAmbientOcclusionRadius( ambientOcclusionSettings.radius() );
1113 shadowRenderingFrameGraph->setAmbientOcclusionIntensity( ambientOcclusionSettings.intensity() );
1114 shadowRenderingFrameGraph->setAmbientOcclusionThreshold( ambientOcclusionSettings.threshold() );
1115}
1116
1117void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
1118{
1119 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1120 shadowRenderingFrameGraph->setupShadowMapDebugging( mMap.debugShadowMapEnabled(), mMap.debugShadowMapCorner(), mMap.debugShadowMapSize() );
1121}
1122
1123void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
1124{
1125 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1126 shadowRenderingFrameGraph->setupDepthMapDebugging( mMap.debugDepthMapEnabled(), mMap.debugDepthMapCorner(), mMap.debugDepthMapSize() );
1127}
1128
1129void Qgs3DMapScene::onDebugOverlayEnabledChanged()
1130{
1131 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1132 shadowRenderingFrameGraph->setDebugOverlayEnabled( mMap.isDebugOverlayEnabled() );
1133}
1134
1135void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
1136{
1137 QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = mEngine->frameGraph();
1138
1139 bool edlEnabled = mMap.eyeDomeLightingEnabled();
1140 double edlStrength = mMap.eyeDomeLightingStrength();
1141 double edlDistance = mMap.eyeDomeLightingDistance();
1142 shadowRenderingFrameGraph->setupEyeDomeLighting( edlEnabled, edlStrength, edlDistance );
1143}
1144
1145void Qgs3DMapScene::onCameraMovementSpeedChanged()
1146{
1147 mCameraController->setCameraMovementSpeed( mMap.cameraMovementSpeed() );
1148}
1149
1150void Qgs3DMapScene::onCameraNavigationModeChanged()
1151{
1152 mCameraController->setCameraNavigationMode( mMap.cameraNavigationMode() );
1153}
1154
1156{
1157 QVector<QString> notParsedLayers;
1158 Qgs3DSceneExporter exporter;
1159
1160 exporter.setTerrainResolution( exportSettings.terrrainResolution() );
1161 exporter.setSmoothEdges( exportSettings.smoothEdges() );
1162 exporter.setExportNormals( exportSettings.exportNormals() );
1163 exporter.setExportTextures( exportSettings.exportTextures() );
1164 exporter.setTerrainTextureResolution( exportSettings.terrainTextureResolution() );
1165 exporter.setScale( exportSettings.scale() );
1166
1167 for ( auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
1168 {
1169 QgsMapLayer *layer = it.key();
1170 Qt3DCore::QEntity *rootEntity = it.value();
1171 QgsMapLayerType layerType = layer->type();
1172 switch ( layerType )
1173 {
1175 if ( !exporter.parseVectorLayerEntity( rootEntity, qobject_cast<QgsVectorLayer *>( layer ) ) )
1176 notParsedLayers.push_back( layer->name() );
1177 break;
1185 notParsedLayers.push_back( layer->name() );
1186 break;
1187 }
1188 }
1189
1190 if ( mTerrain )
1191 exporter.parseTerrain( mTerrain, "Terrain" );
1192
1193 exporter.save( exportSettings.sceneName(), exportSettings.sceneFolderPath() );
1194
1195 if ( !notParsedLayers.empty() )
1196 {
1197 QString message = tr( "The following layers were not exported:" ) + "\n";
1198 for ( const QString &layerName : notParsedLayers )
1199 message += layerName + "\n";
1200 QgsMessageOutput::showMessage( tr( "3D exporter warning" ), message, QgsMessageOutput::MessageText );
1201 }
1202}
1203
1204QVector<const QgsChunkNode *> Qgs3DMapScene::getLayerActiveChunkNodes( QgsMapLayer *layer )
1205{
1206 QVector<const QgsChunkNode *> chunks;
1207 if ( !mLayerEntities.contains( layer ) ) return chunks;
1208 if ( QgsChunkedEntity *c = qobject_cast<QgsChunkedEntity *>( mLayerEntities[ layer ] ) )
1209 {
1210 for ( QgsChunkNode *n : c->activeNodes() )
1211 chunks.push_back( n );
1212 }
1213 return chunks;
1214}
1215
1217{
1218 return mMap.extent();
1219}
1220
1222{
1223 double yMin = std::numeric_limits< double >::max();
1224 double yMax = std::numeric_limits< double >::lowest();
1225 if ( mMap.terrainRenderingEnabled() && mTerrain )
1226 {
1227 const QgsAABB bbox = mTerrain->rootNode()->bbox();
1228 yMin = std::min( yMin, static_cast< double >( bbox.yMin ) );
1229 yMax = std::max( yMax, static_cast< double >( bbox.yMax ) );
1230 }
1231
1232 for ( auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); it++ )
1233 {
1234 QgsMapLayer *layer = it.key();
1235 if ( layer->type() == QgsMapLayerType::PointCloudLayer )
1236 {
1237 QgsPointCloudLayer *pcl = qobject_cast< QgsPointCloudLayer *>( layer );
1238 QgsDoubleRange zRange = pcl->elevationProperties()->calculateZRange( pcl );
1239 yMin = std::min( yMin, zRange.lower() );
1240 yMax = std::max( yMax, zRange.upper() );
1241 }
1242 }
1243 const QgsDoubleRange yRange( std::min( yMin, std::numeric_limits<double>::max() ),
1244 std::max( yMax, std::numeric_limits<double>::lowest() ) );
1245 return yRange;
1246}
1247
1248void Qgs3DMapScene::addCameraRotationCenterEntity( QgsCameraController *controller )
1249{
1250 mEntityRotationCenter = new Qt3DCore::QEntity;
1251
1252 Qt3DCore::QTransform *trCameraViewCenter = new Qt3DCore::QTransform;
1253 mEntityRotationCenter->addComponent( trCameraViewCenter );
1254 Qt3DExtras::QPhongMaterial *materialCameraViewCenter = new Qt3DExtras::QPhongMaterial;
1255 materialCameraViewCenter->setAmbient( Qt::blue );
1256 mEntityRotationCenter->addComponent( materialCameraViewCenter );
1257 Qt3DExtras::QSphereMesh *rendererCameraViewCenter = new Qt3DExtras::QSphereMesh;
1258 rendererCameraViewCenter->setRadius( 10 );
1259 mEntityRotationCenter->addComponent( rendererCameraViewCenter );
1260 mEntityRotationCenter->setEnabled( true );
1261 mEntityRotationCenter->setParent( this );
1262
1263 connect( controller, &QgsCameraController::cameraRotationCenterChanged, this, [trCameraViewCenter]( QVector3D center )
1264 {
1265 trCameraViewCenter->setTranslation( center );
1266 } );
1267
1268 mEntityRotationCenter->setEnabled( mMap.showCameraRotationCenter() );
1269
1270 connect( &mMap, &Qgs3DMapSettings::showCameraRotationCenterChanged, this, [this]
1271 {
1272 mEntityRotationCenter->setEnabled( mMap.showCameraRotationCenter() );
1273 } );
1274}
1275
1276void Qgs3DMapScene::on3DAxisSettingsChanged()
1277{
1278 if ( m3DAxis )
1279 {
1280 m3DAxis->onAxisSettingsChanged();
1281 }
1282 else
1283 {
1284 if ( QgsWindow3DEngine *engine = dynamic_cast<QgsWindow3DEngine *>( mEngine ) )
1285 {
1286 m3DAxis = new Qgs3DAxis( static_cast<Qt3DExtras::Qt3DWindow *>( engine->window() ),
1287 engine->root(),
1288 this,
1289 mCameraController,
1290 &mMap );
1291 }
1292 }
1293}
@ Directional
Directional light source.
void onAxisSettingsChanged()
Force update of the axis and the viewport when a setting has changed.
Definition: qgs3daxis.cpp:1011
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 viewed2DExtentFrom3DChanged(QVector< QgsPointXY > extent)
Emitted when the viewed 2D extent seen by the 3D camera has changed.
QgsAbstract3DEngine * engine()
Returns the abstract 3D engine.
void fpsCountChanged(float fpsCount)
Emitted when the FPS count changes.
QgsRectangle sceneExtent()
Returns the scene extent in the map's CRS.
void setViewFrom2DExtent(const QgsRectangle &extent)
Resets camera view to show the extent extent (top view)
void registerPickHandler(Qgs3DMapScenePickHandler *pickHandler)
Registers an object that will get results of pick events on 3D entities. Does not take ownership of t...
Qgs3DMapScene(Qgs3DMapSettings &map, QgsAbstract3DEngine *engine)
Constructs a 3D scene based on map settings and Qt 3D renderer configuration.
QgsDoubleRange elevationRange() const
Returns the scene's elevation range.
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.
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.
QgsCameraController * cameraController()
Returns camera controller.
Definition: qgs3dmapscene.h:79
QVector< QgsPointXY > viewFrustum2DExtent()
Calculates the 2D extent viewed by the 3D camera as the vertices of the viewed trapezoid.
void viewZoomFull()
Resets camera view to show the whole scene (top view)
void extentChanged()
Emitted when the 3d view's 2d extent has changed.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
bool isDebugOverlayEnabled() const
Returns whether debug overlay is enabled.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
void eyeDomeLightingDistanceChanged()
Emitted when the eye dome lighting distance has changed.
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
double cameraMovementSpeed() const
Returns the camera movement speed.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
void debugDepthMapSettingsChanged()
Emitted when depth map debugging has changed.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
void backgroundColorChanged()
Emitted when the background color has changed.
Qt::Corner debugShadowMapCorner() const
Returns the corner where the shadow map preview is displayed.
bool showCameraViewCenter() const
Returns whether to show camera's view center as a sphere (for debugging)
void showCameraRotationCenterChanged()
Emitted when the flag whether camera's rotation center is shown has changed.
void cameraNavigationModeChanged()
Emitted when the camera navigation mode was changed.
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
void eyeDomeLightingEnabledChanged()
Emitted when the flag whether eye dome lighting is used has changed.
void debugOverlayEnabledChanged(bool debugOverlayEnabled)
Emitted when the debug overaly is enabled or disabled.
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
QList< QgsLightSource * > lightSources() const
Returns list of directional light sources defined in the scene.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void projectionTypeChanged()
Emitted when the camera lens projection type changes.
float fieldOfView() const
Returns the camera lens' field of view.
QgsAmbientOcclusionSettings ambientOcclusionSettings() const
Returns the current configuration of screen space ambient occlusion.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in project's CRS.
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image)
void lightSourcesChanged()
Emitted when any of the light source settings in the map changes.
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
QColor backgroundColor() const
Returns background color of the 3D map view.
double debugShadowMapSize() const
Returns the size of the shadow map preview.
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool terrainRenderingEnabled() const
Returns whether the 2D terrain surface will be rendered.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is enabled or disabled.
void axisSettingsChanged()
Emitted when 3d axis rendering settings are changed.
void ambientOcclusionSettingsChanged()
Emitted when ambient occlusion rendering settings are changed.
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
void eyeDomeLightingStrengthChanged()
Emitted when the eye dome lighting strength has changed.
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
bool isFpsCounterEnabled() const
Returns whether FPS counter label is enabled.
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
QgsCameraController::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
void debugShadowMapSettingsChanged()
Emitted when shadow map debugging has changed.
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
bool showCameraRotationCenter() const
Returns whether to show camera's rotation center as a sphere (for debugging)
Entity that handles the exporting of 3D scene.
void 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...
Definition: qgs3dutils.cpp:238
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
Definition: qgs3dutils.cpp:599
static QgsRay3D rayFromScreenPoint(const QPoint &point, const QSize &windowSize, Qt3DRender::QCamera *camera)
Convert from clicked point on the screen to a ray in world coordinates.
Definition: qgs3dutils.cpp:692
3
Definition: qgsaabb.h:34
float yMax
Definition: qgsaabb.h:88
float xMax
Definition: qgsaabb.h:87
float xMin
Definition: qgsaabb.h:84
float zMax
Definition: qgsaabb.h:89
float yMin
Definition: qgsaabb.h:85
float zMin
Definition: qgsaabb.h:86
void sizeChanged()
Emitted after a call to setSize()
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 Qt3DRender::QCamera * camera()=0
Returns pointer to the engine's camera entity.
virtual void setClearColor(const QColor &color)=0
Sets background color of the scene.
virtual void setFrustumCullingEnabled(bool enabled)=0
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...
virtual QSize size() const =0
Returns size of the engine's rendering area in pixels.
virtual Qt3DRender::QRenderSettings * renderSettings()=0
Returns access to the engine's render settings (the frame graph can be accessed from here)
Base class for all renderers that may to participate in 3D view.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
virtual Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map) const =0
Returns a 3D entity that will be used to show renderer's data in 3D scene.
class containing the configuration of ambient occlusion rendering 3
float radius() const
Returns the radius parameter of the ambient occlusion effect.
bool isEnabled() const
Returns whether ambient occlusion effect is enabled.
float intensity() const
Returns the shading factor of the ambient occlusion effect.
float threshold() const
Returns at what amount of occlusion the effect will kick in.
static QgsSourceCache * sourceCache()
Returns the application's source cache, used for caching embedded and remote source strings as local ...
Qt3DRender::QCamera * camera() const
Returns camera that is being controlled.
void setCameraNavigationMode(QgsCameraController::NavigationMode navigationMode)
Sets the navigation mode used by the camera controller.
float distance() const
Returns distance of the camera from the point it is looking at.
void cameraChanged()
Emitted when camera has been updated.
void frameTriggered(float dt)
Called internally from 3D scene when a new frame is generated. Updates camera according to keyboard/m...
void resetView(float distance)
Move camera back to the initial position (looking down towards origin of world's coordinates)
void setViewFromTop(float worldX, float worldY, float distance, float yaw=0)
Sets camera to look down towards given point in world coordinate, in given distance from plane with z...
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void cameraRotationCenterChanged(QVector3D position)
Emitted when the camera rotation center changes.
A skybox constructed from a 6 cube faces.
QgsRange which stores a range of double values.
Definition: qgsrange.h:203
virtual QgsDoubleRange calculateZRange(QgsMapLayer *layer) const
Attempts to calculate the overall elevation or z range for the specified layer, using the settings de...
Base class for all map layer types.
Definition: qgsmaplayer.h:73
QString name
Definition: qgsmaplayer.h:76
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsMapLayerType type
Definition: qgsmaplayer.h:80
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.
Definition: qgsmaplayer.h:1523
void layerModified()
Emitted when modifications has been done on layer.
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.
Definition: qgsmeshlayer.h:100
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.
QgsMapLayerElevationProperties * elevationProperties() override
Returns the layer's elevation properties.
void subsetStringChanged()
Emitted when the layer's subset string has changed.
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
T lower() const
Returns the lower bound of the range.
Definition: qgsrange.h:66
T upper() const
Returns the upper bound of the range.
Definition: qgsrange.h:73
A representation of a ray in 3D.
Definition: qgsray3d.h:31
QVector3D origin() const
Returns the origin of the ray.
Definition: qgsray3d.h:44
QVector3D direction() const
Returns the direction of the ray see setDirection()
Definition: qgsray3d.h:50
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
QList< QgsRuleBased3DRenderer::Rule * > RuleList
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
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 setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
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 setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
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.
QMap< QString, QString > cubeMapFacesPaths() const
Returns a map containing the path of each texture specified by the user.
QgsSkyboxEntity::SkyboxType skyboxType() const
Returns the type of the skybox.
QString panoramicTexturePath() const
Returns the panoramic texture path of a skybox of type "Panormaic skybox".
void remoteSourceFetched(const QString &url)
Emitted when the cache has finished retrieving a 3D model from a remote url.
bool isActive() const
Returns true if the temporal property is active.
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
virtual QgsAABB rootChunkBbox(const Qgs3DMapSettings &map) const
Returns bounding box of the root chunk.
virtual QgsRectangle rootChunkExtent() const =0
extent of the terrain's root chunk in terrain's CRS
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
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.
Definition: qgis.h:47
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
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)
Definition: qgis.h:3107
void addQLayerComponentsToHierarchy(Qt3DCore::QEntity *entity, const QVector< Qt3DRender::QLayer * > &layers)
QgsChunkedEntity::SceneState sceneState_(QgsAbstract3DEngine *engine)
void removeQLayerComponentsFromHierarchy(Qt3DCore::QEntity *entity)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39