QGIS API Documentation  3.27.0-Master (11ef3e5184)
qgs3dmapsettings.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.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 "qgs3dmapsettings.h"
17 
18 #include "qgs3dutils.h"
20 #include "qgsdemterraingenerator.h"
21 #include "qgsmeshterraingenerator.h"
24 #include "qgsmeshlayer3drenderer.h"
27 #include "qgsterrainprovider.h"
28 
29 #include <QDomDocument>
30 #include <QDomElement>
31 
32 #include "qgssymbollayerutils.h"
33 #include "qgsrasterlayer.h"
34 
36  : QObject( nullptr )
37 {
38  connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
39  {
41  } );
42  connectChangedSignalsToSettingsChanged();
43 }
44 
46  : QObject( nullptr )
47  , QgsTemporalRangeObject( other )
48  , mOrigin( other.mOrigin )
49  , mCrs( other.mCrs )
50  , mBackgroundColor( other.mBackgroundColor )
51  , mSelectionColor( other.mSelectionColor )
52  , mTerrainVerticalScale( other.mTerrainVerticalScale )
53  , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
54  , mMapTileResolution( other.mMapTileResolution )
55  , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
56  , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
57  , mTerrainElevationOffset( other.mTerrainElevationOffset )
58  , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
59  , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
60  , mTerrainMapTheme( other.mTerrainMapTheme )
61  , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
62  , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
63  , mShowCameraViewCenter( other.mShowCameraViewCenter )
64  , mShowCameraRotationCenter( other.mShowCameraRotationCenter )
65  , mShowLightSources( other.mShowLightSources )
66  , mShowLabels( other.mShowLabels )
67  , mFieldOfView( other.mFieldOfView )
68  , mProjectionType( other.mProjectionType )
69  , mCameraNavigationMode( other.mCameraNavigationMode )
70  , mCameraMovementSpeed( other.mCameraMovementSpeed )
71  , mLayers( other.mLayers )
72  , mRenderers() // initialized in body
73  , mTransformContext( other.mTransformContext )
74  , mPathResolver( other.mPathResolver )
75  , mMapThemes( other.mMapThemes )
76  , mDpi( other.mDpi )
77  , mIsFpsCounterEnabled( other.mIsFpsCounterEnabled )
78  , mIsSkyboxEnabled( other.mIsSkyboxEnabled )
79  , mSkyboxSettings( other.mSkyboxSettings )
80  , mShadowSettings( other.mShadowSettings )
81  , mAmbientOcclusionSettings( other.mAmbientOcclusionSettings )
82  , mEyeDomeLightingEnabled( other.mEyeDomeLightingEnabled )
83  , mEyeDomeLightingStrength( other.mEyeDomeLightingStrength )
84  , mEyeDomeLightingDistance( other.mEyeDomeLightingDistance )
85  , mViewSyncMode( other.mViewSyncMode )
86  , mVisualizeViewFrustum( other.mVisualizeViewFrustum )
87  , mDebugShadowMapEnabled( other.mDebugShadowMapEnabled )
88  , mDebugShadowMapCorner( other.mDebugShadowMapCorner )
89  , mDebugShadowMapSize( other.mDebugShadowMapSize )
90  , mDebugDepthMapEnabled( other.mDebugDepthMapEnabled )
91  , mDebugDepthMapCorner( other.mDebugDepthMapCorner )
92  , mDebugDepthMapSize( other.mDebugDepthMapSize )
93  , mTerrainRenderingEnabled( other.mTerrainRenderingEnabled )
94  , mRendererUsage( other.mRendererUsage )
95  , m3dAxisSettings( other.m3dAxisSettings )
96  , mIsDebugOverlayEnabled( other.mIsDebugOverlayEnabled )
97 {
98  for ( QgsAbstract3DRenderer *renderer : std::as_const( other.mRenderers ) )
99  {
100  mRenderers << renderer->clone();
101  }
102 
103  for ( QgsLightSource *source : std::as_const( other.mLightSources ) )
104  {
105  if ( source )
106  mLightSources << source->clone();
107  }
108 
109  connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
110  {
112  } );
113  connectChangedSignalsToSettingsChanged();
114 }
115 
117 {
118  qDeleteAll( mRenderers );
119  qDeleteAll( mLightSources );
120 }
121 
122 void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
123 {
125  QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
126  mOrigin = QgsVector3D(
127  elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
128  elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
129  elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
130 
131  QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
132  if ( !elemCamera.isNull() )
133  {
134  mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
135  mProjectionType = static_cast< Qt3DRender::QCameraLens::ProjectionType >( elemCamera.attribute( QStringLiteral( "projection-type" ), QStringLiteral( "1" ) ).toInt() );
136  QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
137  if ( cameraNavigationMode == QLatin1String( "terrain-based-navigation" ) )
138  mCameraNavigationMode = QgsCameraController::NavigationMode::TerrainBasedNavigation;
139  else if ( cameraNavigationMode == QLatin1String( "walk-navigation" ) )
140  mCameraNavigationMode = QgsCameraController::NavigationMode::WalkNavigation;
141  mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
142  }
143 
144  QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
145  if ( !elemColor.isNull() )
146  {
147  mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "background" ) ) );
148  mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "selection" ) ) );
149  }
150 
151  QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
152  mCrs.readXml( elemCrs );
153 
154  QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
155  mTerrainRenderingEnabled = elemTerrain.attribute( QStringLiteral( "terrain-rendering-enabled" ), QStringLiteral( "1" ) ).toInt();
156  mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
157  mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
158  mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
159  mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
160  mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
161  mTerrainElevationOffset = elemTerrain.attribute( QStringLiteral( "elevation-offset" ), QStringLiteral( "0.0" ) ).toFloat();
162 
163  QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
164  if ( !elemTerrainShadingMaterial.isNull() )
165  mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
166  mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
167  mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
168 
169  qDeleteAll( mLightSources );
170  mLightSources.clear();
171  const QDomElement lightsElem = elem.firstChildElement( QStringLiteral( "lights" ) );
172  if ( !lightsElem.isNull() )
173  {
174  const QDomNodeList lightNodes = lightsElem.childNodes();
175  for ( int i = 0; i < lightNodes.size(); ++i )
176  {
177  const QDomElement lightElement = lightNodes.at( i ).toElement();
178  if ( QgsLightSource *light = QgsLightSource::createFromXml( lightElement, context ) )
179  mLightSources << light;
180  }
181  }
182  else
183  {
184  // older project format
185  QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
186  if ( !elemPointLights.isNull() )
187  {
188  QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
189  while ( !elemPointLight.isNull() )
190  {
191  std::unique_ptr< QgsPointLightSettings > pointLight = std::make_unique< QgsPointLightSettings >();
192  pointLight->readXml( elemPointLight, context );
193  mLightSources << pointLight.release();
194  elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
195  }
196  }
197  else
198  {
199  // QGIS <= 3.4 did not have light configuration
200  std::unique_ptr< QgsPointLightSettings > defaultLight = std::make_unique< QgsPointLightSettings >();
201  defaultLight->setPosition( QgsVector3D( 0, 1000, 0 ) );
202  mLightSources << defaultLight.release();
203  }
204 
205  QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
206  if ( !elemDirectionalLights.isNull() )
207  {
208  QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
209  while ( !elemDirectionalLight.isNull() )
210  {
211  std::unique_ptr< QgsDirectionalLightSettings > directionalLight = std::make_unique< QgsDirectionalLightSettings >();
212  directionalLight->readXml( elemDirectionalLight, context );
213  mLightSources << directionalLight.release();
214  elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
215  }
216  }
217  }
218 
219  QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
220  QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
221  QList<QgsMapLayerRef> mapLayers;
222  while ( !elemMapLayer.isNull() )
223  {
224  mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
225  elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
226  }
227  mLayers = mapLayers; // needs to resolve refs afterwards
228 
229  QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
230  QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
231  if ( terrainGenType == QLatin1String( "dem" ) )
232  {
233  QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
234  demTerrainGenerator->setCrs( mCrs, mTransformContext );
235  setTerrainGenerator( demTerrainGenerator );
236  }
237  else if ( terrainGenType == QLatin1String( "online" ) )
238  {
239  QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
240  onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
241  setTerrainGenerator( onlineTerrainGenerator );
242  }
243  else if ( terrainGenType == QLatin1String( "mesh" ) )
244  {
245  QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
246  meshTerrainGenerator->setCrs( mCrs, mTransformContext );
247  setTerrainGenerator( meshTerrainGenerator );
248  }
249  else // "flat"
250  {
252  flatGen->setCrs( mCrs );
253  setTerrainGenerator( flatGen );
254  }
255  mTerrainGenerator->readXml( elemTerrainGenerator );
256 
257  qDeleteAll( mRenderers );
258  mRenderers.clear();
259 
260  QDomElement elemRenderers = elem.firstChildElement( QStringLiteral( "renderers" ) );
261  QDomElement elemRenderer = elemRenderers.firstChildElement( QStringLiteral( "renderer" ) );
262  while ( !elemRenderer.isNull() )
263  {
264  QgsAbstract3DRenderer *renderer = nullptr;
265  QString type = elemRenderer.attribute( QStringLiteral( "type" ) );
266  if ( type == QLatin1String( "vector" ) )
267  {
268  renderer = new QgsVectorLayer3DRenderer;
269  }
270  else if ( type == QLatin1String( "mesh" ) )
271  {
272  renderer = new QgsMeshLayer3DRenderer;
273  }
274  else if ( type == QLatin1String( "pointcloud" ) )
275  {
276  renderer = new QgsPointCloudLayer3DRenderer;
277  }
278 
279  if ( renderer )
280  {
281  renderer->readXml( elemRenderer, context );
282  mRenderers.append( renderer );
283  }
284  elemRenderer = elemRenderer.nextSiblingElement( QStringLiteral( "renderer" ) );
285  }
286 
287  QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
288  mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
289  mSkyboxSettings.readXml( elemSkybox, context );
290 
291  QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
292  mShadowSettings.readXml( elemShadows, context );
293 
294  QDomElement elemAmbientOcclusion = elem.firstChildElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
295  mAmbientOcclusionSettings.readXml( elemAmbientOcclusion, context );
296 
297  QDomElement elemEyeDomeLighting = elem.firstChildElement( QStringLiteral( "eye-dome-lighting" ) );
298  mEyeDomeLightingEnabled = elemEyeDomeLighting.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
299  mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
300  mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();
301 
302  QDomElement elemNavigationSync = elem.firstChildElement( QStringLiteral( "navigation-sync" ) );
303  mViewSyncMode = ( Qgis::ViewSyncModeFlags )( elemNavigationSync.attribute( QStringLiteral( "view-sync-mode" ), QStringLiteral( "0" ) ).toInt() );
304  mVisualizeViewFrustum = elemNavigationSync.attribute( QStringLiteral( "view-frustum-visualization-enabled" ), QStringLiteral( "0" ) ).toInt();
305 
306  QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
307  mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
308  mDebugShadowMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), "0" ).toInt() );
309  mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
310 
311  mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
312  mDebugDepthMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "1" ) ).toInt() );
313  mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
314 
315  QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
316  mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
317  mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
318  mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
319  mShowCameraRotationCenter = elemDebug.attribute( QStringLiteral( "camera-rotation-center" ), QStringLiteral( "0" ) ).toInt();
320  mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
321  mIsFpsCounterEnabled = elemDebug.attribute( QStringLiteral( "show-fps-counter" ), QStringLiteral( "0" ) ).toInt();
322 
323  QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
324  QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
325  QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
326  setTemporalRange( QgsDateTimeRange( start, end ) );
327 
328  QDomElement elem3dAxis = elem.firstChildElement( QStringLiteral( "axis3d" ) );
329  m3dAxisSettings.readXml( elem3dAxis, context );
330 
331 }
332 
333 QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
334 {
335  QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
336 
337  QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
338  elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
339  elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
340  elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
341  elem.appendChild( elemOrigin );
342 
343  QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
344  elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
345  elemCamera.setAttribute( QStringLiteral( "projection-type" ), static_cast< int >( mProjectionType ) );
346  switch ( mCameraNavigationMode )
347  {
349  elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
350  break;
352  elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
353  break;
354  }
355  elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
356  elem.appendChild( elemCamera );
357 
358  QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
359  elemColor.setAttribute( QStringLiteral( "background" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
360  elemColor.setAttribute( QStringLiteral( "selection" ), QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
361  elem.appendChild( elemColor );
362 
363  QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
364  mCrs.writeXml( elemCrs, doc );
365  elem.appendChild( elemCrs );
366 
367  QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
368  elemTerrain.setAttribute( QStringLiteral( "terrain-rendering-enabled" ), mTerrainRenderingEnabled ? 1 : 0 );
369  elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
370  elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
371  elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
372  elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
373  elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
374  elemTerrain.setAttribute( QStringLiteral( "elevation-offset" ), mTerrainElevationOffset );
375 
376  QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
377  mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
378  elemTerrain.appendChild( elemTerrainShadingMaterial );
379  elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
380  elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
381 
382  {
383  QDomElement elemLights = doc.createElement( QStringLiteral( "lights" ) );
384  for ( const QgsLightSource *light : mLightSources )
385  {
386  const QDomElement elemLight = light->writeXml( doc, context );
387  elemLights.appendChild( elemLight );
388  }
389  elem.appendChild( elemLights );
390  }
391 
392  QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
393  for ( const QgsMapLayerRef &layerRef : mLayers )
394  {
395  QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
396  elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
397  elemMapLayers.appendChild( elemMapLayer );
398  }
399  elemTerrain.appendChild( elemMapLayers );
400 
401  QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
402  elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
403  mTerrainGenerator->writeXml( elemTerrainGenerator );
404  elemTerrain.appendChild( elemTerrainGenerator );
405  elem.appendChild( elemTerrain );
406 
407  QDomElement elemRenderers = doc.createElement( QStringLiteral( "renderers" ) );
408  for ( const QgsAbstract3DRenderer *renderer : mRenderers )
409  {
410  QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
411  elemRenderer.setAttribute( QStringLiteral( "type" ), renderer->type() );
412  renderer->writeXml( elemRenderer, context );
413  elemRenderers.appendChild( elemRenderer );
414  }
415  elem.appendChild( elemRenderers );
416 
417  QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
418  elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
419  mSkyboxSettings.writeXml( elemSkybox, context );
420  elem.appendChild( elemSkybox );
421 
422  QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
423  mShadowSettings.writeXml( elemShadows, context );
424  elem.appendChild( elemShadows );
425 
426  QDomElement elemAmbientOcclusion = doc.createElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
427  mAmbientOcclusionSettings.writeXml( elemAmbientOcclusion, context );
428  elem.appendChild( elemAmbientOcclusion );
429 
430  QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
431  elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
432  elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
433  elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
434  elemDebug.setAttribute( QStringLiteral( "camera-rotation-center" ), mShowCameraRotationCenter ? 1 : 0 );
435  elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
436  elemDebug.setAttribute( QStringLiteral( "show-fps-counter" ), mIsFpsCounterEnabled ? 1 : 0 );
437  elem.appendChild( elemDebug );
438 
439  QDomElement elemEyeDomeLighting = doc.createElement( QStringLiteral( "eye-dome-lighting" ) );
440  elemEyeDomeLighting.setAttribute( QStringLiteral( "enabled" ), mEyeDomeLightingEnabled ? 1 : 0 );
441  elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-strength" ), mEyeDomeLightingStrength );
442  elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-distance" ), mEyeDomeLightingDistance );
443  elem.appendChild( elemEyeDomeLighting );
444 
445  QDomElement elemNavigationSync = doc.createElement( QStringLiteral( "navigation-sync" ) );
446  elemNavigationSync.setAttribute( QStringLiteral( "view-sync-mode" ), ( int )mViewSyncMode );
447  elemNavigationSync.setAttribute( QStringLiteral( "view-frustum-visualization-enabled" ), mVisualizeViewFrustum ? 1 : 0 );
448  elem.appendChild( elemNavigationSync );
449 
450  QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
451  elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
452  elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
453  elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
454  elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
455  elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
456  elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
457  elem.appendChild( elemDebugSettings );
458 
459  QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
460  elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
461  elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
462 
463  QDomElement elem3dAxis = doc.createElement( QStringLiteral( "axis3d" ) );
464  m3dAxisSettings.writeXml( elem3dAxis, context );
465  elem.appendChild( elem3dAxis );
466 
467  return elem;
468 }
469 
471 {
472  for ( int i = 0; i < mLayers.count(); ++i )
473  {
474  QgsMapLayerRef &layerRef = mLayers[i];
475  layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
476  }
477 
478  mTerrainGenerator->resolveReferences( project );
479 
480  for ( int i = 0; i < mRenderers.count(); ++i )
481  {
482  QgsAbstract3DRenderer *renderer = mRenderers[i];
483  renderer->resolveReferences( project );
484  }
485 }
486 
488 {
489  return Qgs3DUtils::mapToWorldCoordinates( mapCoords, mOrigin );
490 }
491 
493 {
494  return Qgs3DUtils::worldToMapCoordinates( worldCoords, mOrigin );
495 }
496 
498 {
499  mCrs = crs;
500 }
501 
503 {
504  return mTransformContext;
505 }
506 
508 {
509  mTransformContext = context;
510 }
511 
512 void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
513 {
514  if ( color == mBackgroundColor )
515  return;
516 
517  mBackgroundColor = color;
518  emit backgroundColorChanged();
519 }
520 
522 {
523  return mBackgroundColor;
524 }
525 
526 void Qgs3DMapSettings::setSelectionColor( const QColor &color )
527 {
528  if ( color == mSelectionColor )
529  return;
530 
531  mSelectionColor = color;
532  emit selectionColorChanged();
533 }
534 
536 {
537  return mSelectionColor;
538 }
539 
541 {
542  if ( zScale == mTerrainVerticalScale )
543  return;
544 
545  mTerrainVerticalScale = zScale;
547 }
548 
550 {
551  return mTerrainVerticalScale;
552 }
553 
554 void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
555 {
556  QList<QgsMapLayerRef> lst;
557  lst.reserve( layers.count() );
558  for ( QgsMapLayer *layer : layers )
559  {
560  lst.append( layer );
561  }
562 
563  if ( mLayers == lst )
564  return;
565 
566  mLayers = lst;
567  emit layersChanged();
568 }
569 
570 QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
571 {
572  QList<QgsMapLayer *> lst;
573  lst.reserve( mLayers.count() );
574  for ( const QgsMapLayerRef &layerRef : mLayers )
575  {
576  if ( layerRef.layer )
577  lst.append( layerRef.layer );
578  }
579  return lst;
580 }
581 
583 {
584  if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
585  {
587  flatTerrain->setCrs( crs() );
588  flatTerrain->setExtent( fullExtent );
589  setTerrainGenerator( flatTerrain );
590 
592  }
593  else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
594  {
595  QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast< QgsRasterDemTerrainProvider * >( properties->terrainProvider() );
596 
597  QgsDemTerrainGenerator *demTerrainGen = new QgsDemTerrainGenerator;
598  demTerrainGen->setCrs( crs(), QgsProject::instance()->transformContext() );
599  demTerrainGen->setLayer( rasterProvider->layer() );
600  setTerrainGenerator( demTerrainGen );
601 
603  setTerrainVerticalScale( properties->terrainProvider()->scale() );
604  }
605  else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
606  {
607  QgsMeshTerrainProvider *meshProvider = qgis::down_cast< QgsMeshTerrainProvider * >( properties->terrainProvider() );
608 
609  QgsMeshTerrainGenerator *newTerrainGenerator = new QgsMeshTerrainGenerator;
610  newTerrainGenerator->setCrs( crs(), QgsProject::instance()->transformContext() );
611  newTerrainGenerator->setLayer( meshProvider->layer() );
612  std::unique_ptr< QgsMesh3DSymbol > symbol( newTerrainGenerator->symbol()->clone() );
613  symbol->setVerticalScale( properties->terrainProvider()->scale() );
614  newTerrainGenerator->setSymbol( symbol.release() );
615  setTerrainGenerator( newTerrainGenerator );
616 
618  setTerrainVerticalScale( properties->terrainProvider()->scale() );
619  }
620  else
621  {
623  flatTerrain->setCrs( crs() );
624  flatTerrain->setExtent( fullExtent );
625  setTerrainGenerator( flatTerrain );
626  }
627 }
628 
630 {
631  if ( mMapTileResolution == res )
632  return;
633 
634  mMapTileResolution = res;
636 }
637 
639 {
640  return mMapTileResolution;
641 }
642 
644 {
645  if ( mMaxTerrainScreenError == error )
646  return;
647 
648  mMaxTerrainScreenError = error;
650 }
651 
653 {
654  return mMaxTerrainScreenError;
655 }
656 
658 {
659  if ( mMaxTerrainGroundError == error )
660  return;
661 
662  mMaxTerrainGroundError = error;
664 }
665 
667 {
668  if ( mTerrainElevationOffset == offset )
669  return;
670  mTerrainElevationOffset = offset;
671  emit terrainElevationOffsetChanged( mTerrainElevationOffset );
672 }
673 
675 {
676  return mMaxTerrainGroundError;
677 }
678 
680 {
681  if ( mTerrainGenerator )
682  {
683  disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::extentChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
684  disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
685  }
686 
687  mTerrainGenerator.reset( gen );
688  connect( mTerrainGenerator.get(), &QgsTerrainGenerator::extentChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
689  connect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
690 
692 }
693 
695 {
696  if ( mTerrainShadingEnabled == enabled )
697  return;
698 
699  mTerrainShadingEnabled = enabled;
700  emit terrainShadingChanged();
701 }
702 
704 {
705  if ( mTerrainShadingMaterial == material )
706  return;
707 
708  mTerrainShadingMaterial = material;
709  emit terrainShadingChanged();
710 }
711 
712 void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
713 {
714  if ( mTerrainMapTheme == theme )
715  return;
716 
717  mTerrainMapTheme = theme;
718  emit terrainMapThemeChanged();
719 }
720 
721 void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
722 {
723  qDeleteAll( mRenderers );
724 
725  mRenderers = renderers;
726 
727  emit renderersChanged();
728 }
729 
731 {
732  if ( mShowTerrainBoundingBoxes == enabled )
733  return;
734 
735  mShowTerrainBoundingBoxes = enabled;
737 }
738 
740 {
741  if ( mShowTerrainTileInfo == enabled )
742  return;
743 
744  mShowTerrainTileInfo = enabled;
746 }
747 
749 {
750  if ( mShowCameraViewCenter == enabled )
751  return;
752 
753  mShowCameraViewCenter = enabled;
755 }
756 
758 {
759  if ( mShowCameraRotationCenter == enabled )
760  return;
761 
762  mShowCameraRotationCenter = enabled;
764 }
765 
766 
768 {
769  if ( mShowLightSources == enabled )
770  return;
771 
772  mShowLightSources = enabled;
774 }
775 
777 {
778  if ( mShowLabels == enabled )
779  return;
780 
781  mShowLabels = enabled;
782  emit showLabelsChanged();
783 }
784 
786 {
787  if ( mEyeDomeLightingEnabled == enabled )
788  return;
789  mEyeDomeLightingEnabled = enabled;
791 }
792 
794 {
795  if ( mEyeDomeLightingStrength == strength )
796  return;
797  mEyeDomeLightingStrength = strength;
799 }
800 
802 {
803  if ( mEyeDomeLightingDistance == distance )
804  return;
805  mEyeDomeLightingDistance = distance;
807 }
808 
809 QList<QgsLightSource *> Qgs3DMapSettings::lightSources() const
810 {
811  return mLightSources;
812 }
813 
814 void Qgs3DMapSettings::setLightSources( const QList<QgsLightSource *> &lights )
815 {
816  qDeleteAll( mLightSources );
817  mLightSources = lights;
818 
820  emit pointLightsChanged();
821  emit lightSourcesChanged();
822 }
823 
824 void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
825 {
826  if ( mFieldOfView == fieldOfView )
827  return;
828 
829  mFieldOfView = fieldOfView;
830  emit fieldOfViewChanged();
831 }
832 
833 void Qgs3DMapSettings::setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType )
834 {
835  if ( mProjectionType == projectionType )
836  return;
837 
838  mProjectionType = projectionType;
839  emit projectionTypeChanged();
840 }
841 
843 {
844  if ( mCameraNavigationMode == navigationMode )
845  return;
846 
847  mCameraNavigationMode = navigationMode;
849 }
850 
851 void Qgs3DMapSettings::setCameraMovementSpeed( double movementSpeed )
852 {
853  if ( mCameraMovementSpeed == movementSpeed )
854  return;
855 
856  mCameraMovementSpeed = movementSpeed;
858 }
859 
861 {
862  mSkyboxSettings = skyboxSettings;
863  emit skyboxSettingsChanged();
864 }
865 
867 {
868  mShadowSettings = shadowSettings;
869  emit shadowSettingsChanged();
870 }
871 
873 {
874  mAmbientOcclusionSettings = ambientOcclusionSettings;
876 }
877 
878 void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size )
879 {
880  mDebugShadowMapEnabled = enabled;
881  mDebugShadowMapCorner = corner;
882  mDebugShadowMapSize = size;
884 }
885 
886 void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size )
887 {
888  mDebugDepthMapEnabled = enabled;
889  mDebugDepthMapCorner = corner;
890  mDebugDepthMapSize = size;
892 }
893 
894 void Qgs3DMapSettings::setIsFpsCounterEnabled( bool fpsCounterEnabled )
895 {
896  if ( fpsCounterEnabled == mIsFpsCounterEnabled )
897  return;
898  mIsFpsCounterEnabled = fpsCounterEnabled;
899  emit fpsCounterEnabledChanged( mIsFpsCounterEnabled );
900 }
901 
902 void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled )
903 {
904  if ( terrainRenderingEnabled == mTerrainRenderingEnabled )
905  return;
906  mTerrainRenderingEnabled = terrainRenderingEnabled;
908 }
909 
911 {
912  return mRendererUsage;
913 }
914 
916 {
917  mRendererUsage = rendererUsage;
918 }
919 
920 void Qgs3DMapSettings::setViewSyncMode( Qgis::ViewSyncModeFlags mode )
921 {
922  mViewSyncMode = mode;
923 }
924 
926 {
927  if ( mVisualizeViewFrustum != enabled )
928  {
929  mVisualizeViewFrustum = enabled;
931  }
932 }
933 
934 void Qgs3DMapSettings::setIsDebugOverlayEnabled( bool debugOverlayEnabled )
935 {
936  if ( debugOverlayEnabled == mIsDebugOverlayEnabled )
937  return;
938 
939  mIsDebugOverlayEnabled = debugOverlayEnabled;
940  emit debugOverlayEnabledChanged( mIsDebugOverlayEnabled );
941 }
942 
943 
944 void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
945 {
977 }
978 
979 
980 void Qgs3DMapSettings::set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force )
981 {
982  if ( axisSettings == m3dAxisSettings )
983  {
984  if ( force )
985  {
986  // ie. refresh. We nned to disconnect and to reconnect to avoid 'dirty' project
988  emit axisSettingsChanged();
990  }
991  }
992  else
993  {
994  m3dAxisSettings = axisSettings;
995  emit axisSettingsChanged();
996  }
997 }
RendererUsage
Usage of the renderer.
Definition: qgis.h:1817
Contains the configuration of a 3d axis.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
void setEyeDomeLightingStrength(double strength)
Sets the eye dome lighting strength value.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void settingsChanged()
Emitted when one of the configuration settings has changed.
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void eyeDomeLightingDistanceChanged()
Emitted when the eye dome lighting distance has changed.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads configuration from a DOM element previously written by writeXml()
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
void setAmbientOcclusionSettings(const QgsAmbientOcclusionSettings &ambientOcclusionSettings)
Sets the current configuration of screen space ambient occlusion.
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
void setRenderers(const QList< QgsAbstract3DRenderer * > &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting will be used.
void setFieldOfView(const float fieldOfView)
Sets the camera lens' field of view.
void debugDepthMapSettingsChanged()
Emitted when depth map debugging has changed.
void setLightSources(const QList< QgsLightSource * > &lights)
Sets the list of light sources defined in the scene.
void backgroundColorChanged()
Emitted when the background color has changed.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
void setDebugDepthMapSettings(bool enabled, Qt::Corner corner, double size)
Sets the debugging settings of the depth map.
void showCameraRotationCenterChanged()
Emitted when the flag whether camera's rotation center is shown has changed.
QColor selectionColor() const
Returns color used for selected features.
void directionalLightsChanged()
Emitted when the list of directional lights changes.
void setTerrainShadingMaterial(const QgsPhongMaterialSettings &material)
Sets terrain shading material.
void cameraNavigationModeChanged()
Emitted when the camera navigation mode was changed.
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
void setViewFrustumVisualizationEnabled(bool enabled)
Sets whether the camera's view frustum is visualized on the 2D map canvas.
void setShowCameraRotationCenter(bool enabled)
Sets whether to show camera's rotation center as a sphere (for debugging)
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 setTerrainVerticalScale(double zScale)
Sets vertical scale (exaggeration) of terrain (1 = true scale, > 1 = hills get more pronounced)
void debugOverlayEnabledChanged(bool debugOverlayEnabled)
Emitted when the debug overaly is enabled or disabled.
void setShowLabels(bool enabled)
Sets whether to display labels on terrain tiles.
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
void setViewSyncMode(Qgis::ViewSyncModeFlags mode)
Sets the view sync mode (used to synchronize the 2D main map canvas and the 3D camera navigation)
void setMaxTerrainGroundError(float error)
Returns maximum ground error of terrain tiles in world units.
void setSkyboxSettings(const QgsSkyboxSettings &skyboxSettings)
Sets the current configuration of the skybox.
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
void setMapTileResolution(int res)
Sets resolution (in pixels) of the texture of a terrain tile.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of 3D map layers to be rendered in the scene.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
void terrainMapThemeChanged()
Emitted when terrain's map theme has changed.
void setShadowSettings(const QgsShadowSettings &shadowSettings)
Sets the current configuration of shadow rendering.
void setIsDebugOverlayEnabled(bool debugOverlayEnabled)
Sets whether debug overlay is enabled The debug overlay displays some debugging and profiling informa...
void pointLightsChanged()
Emitted when the list of point lights changes.
void setTerrainElevationOffset(float offset)
Sets the terrain elevation offset (used to move the terrain up or down)
QList< QgsLightSource * > lightSources() const
Returns list of directional light sources defined in the scene.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
void setEyeDomeLightingDistance(int distance)
Sets the eye dome lighting distance value (contributes to the contrast of the image.
void setShowLightSourceOrigins(bool enabled)
Sets whether to show light source origins as a sphere (for debugging)
void projectionTypeChanged()
Emitted when the camera lens projection type changes.
float fieldOfView() const
Returns the camera lens' field of view.
void selectionColorChanged()
Emitted when the selection color has changed.
QgsAmbientOcclusionSettings ambientOcclusionSettings() const
Returns the current configuration of screen space ambient occlusion.
void setTerrainShadingEnabled(bool enabled)
Sets whether terrain shading is enabled.
void setDebugShadowMapSettings(bool enabled, Qt::Corner corner, double size)
Sets the debugging settings of the shadow map.
void setSelectionColor(const QColor &color)
Sets color used for selected features.
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.
QColor backgroundColor() const
Returns background color of the 3D map view.
void resolveReferences(const QgsProject &project)
Resolves references to other objects (map layers) after the call to readXml()
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
~Qgs3DMapSettings() override
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
void setShowCameraViewCenter(bool enabled)
Sets whether to show camera's view center as a sphere (for debugging)
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
void set3DAxisSettings(const Qgs3DAxisSettings &axisSettings, bool force=false)
Sets the current configuration of 3d axis.
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
void setTerrainRenderingEnabled(bool terrainRenderingEnabled)
Sets whether the 2D terrain surface will be rendered in.
Qgs3DMapSettings()
Constructor for Qgs3DMapSettings.
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
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 viewFrustumVisualizationEnabledChanged()
Emitted when the camera's view frustum visualization on the main 2D map canvas is enabled or disabled...
void setProjectionType(const Qt3DRender::QCameraLens::ProjectionType projectionType)
Sets the camera lens' projection type.
void ambientOcclusionSettingsChanged()
Emitted when ambient occlusion rendering settings are changed.
void setCameraNavigationMode(QgsCameraController::NavigationMode navigationMode)
Sets the navigation mode for the camera.
void configureTerrainFromProject(QgsProjectElevationProperties *properties, const QgsRectangle &fullExtent)
Configures the map's terrain settings directly from a project's elevation properties.
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
void eyeDomeLightingStrengthChanged()
Emitted when the eye dome lighting strength has changed.
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the renderer usage.
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
void setShowTerrainBoundingBoxes(bool enabled)
Sets whether to display bounding boxes of terrain tiles (for debugging)
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
Qgis::RendererUsage rendererUsage() const
Returns the renderer usage.
void setIsFpsCounterEnabled(bool fpsCounterEnabled)
Sets whether FPS counter label is enabled.
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
void setTerrainMapTheme(const QString &theme)
Sets name of the map theme.
QgsCameraController::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator.
void debugShadowMapSettingsChanged()
Emitted when shadow map debugging has changed.
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:548
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:540
Base class for all renderers that may to participate in 3D view.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
virtual QString type() const =0
Returns the unique type ID string for the provider.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
class containing the configuration of ambient occlusion rendering 3
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
NavigationMode
The navigation mode used by the camera.
@ WalkNavigation
Uses WASD keys or arrows to navigate in walking (first person) manner.
@ TerrainBasedNavigation
The default navigation based on the terrain.
This class represents a coordinate reference system (CRS).
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Contains information about the context in which a coordinate transform is executed.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
void setLayer(QgsRasterLayer *layer)
Sets raster layer with elevation model to be used for terrain generation.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets CRS of the terrain.
void setExtent(const QgsRectangle &extent) override
sets the extent of the terrain in terrain's CRS
static QgsLightSource * createFromXml(const QDomElement &element, const QgsReadWriteContext &context)
Creates a new light source from an XML element.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
3D renderer that renders all mesh triangles of a mesh layer.
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
QgsMeshLayer * layer() const
Returns the mesh layer to be used as the terrain source.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
3D renderer that renders all points from a point cloud layer
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2348
Contains elevation properties for a QgsProject.
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:104
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void setDirty(bool b=true)
Flag the project as dirty (modified).
Definition: qgsproject.cpp:573
A terrain provider where the terrain source is a raster DEM layer.
QgsRasterLayer * layer() const
Returns the raster layer with elevation model to be used as the terrain source.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
class containing the configuration of shadows rendering 3
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Contains the configuration of a skybox entity.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
Base class for objects with an associated (optional) temporal range.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
void terrainChanged()
Emitted when the terrain changed (for example, raster DEM or mesh have data changed)
void extentChanged()
Emitted when the terrain extent has changed.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
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.
_LayerRef< QgsMapLayer > QgsMapLayerRef
const QgsCoordinateReferenceSystem & crs
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.