QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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#include "moc_qgs3dmapsettings.cpp"
18
19#include "qgs3dutils.h"
22#include "qgsmeshterraingenerator.h"
27#include "qgsterrainprovider.h"
28#include "qgslightsource.h"
29#include "qgscolorutils.h"
30#include "qgsrasterlayer.h"
33#include "qgs3drendercontext.h"
34#include "qgsthreadingutils.h"
36
37#include <QDomDocument>
38#include <QDomElement>
39
40
42 : QObject( nullptr )
43{
44 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
45 {
47 } );
48 connectChangedSignalsToSettingsChanged();
49}
50
52 : QObject( nullptr )
53 , QgsTemporalRangeObject( other )
54 , mOrigin( other.mOrigin )
55 , mCrs( other.mCrs )
56 , mBackgroundColor( other.mBackgroundColor )
57 , mSelectionColor( other.mSelectionColor )
58 , mTerrainVerticalScale( other.mTerrainVerticalScale )
59 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
60 , mMapTileResolution( other.mMapTileResolution )
61 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
62 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
63 , mTerrainElevationOffset( other.mTerrainElevationOffset )
64 , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
65 , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
66 , mTerrainMapTheme( other.mTerrainMapTheme )
67 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
68 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
69 , mShowCameraViewCenter( other.mShowCameraViewCenter )
70 , mShowCameraRotationCenter( other.mShowCameraRotationCenter )
71 , mShowLightSources( other.mShowLightSources )
72 , mShowLabels( other.mShowLabels )
73 , mFieldOfView( other.mFieldOfView )
74 , mProjectionType( other.mProjectionType )
75 , mCameraNavigationMode( other.mCameraNavigationMode )
76 , mCameraMovementSpeed( other.mCameraMovementSpeed )
77 , mLayers( other.mLayers )
78 , mTransformContext( other.mTransformContext )
79 , mPathResolver( other.mPathResolver )
80 , mMapThemes( other.mMapThemes )
81 , mDpi( other.mDpi )
82 , mIsFpsCounterEnabled( other.mIsFpsCounterEnabled )
83 , mIsSkyboxEnabled( other.mIsSkyboxEnabled )
84 , mSkyboxSettings( other.mSkyboxSettings )
85 , mShadowSettings( other.mShadowSettings )
86 , mAmbientOcclusionSettings( other.mAmbientOcclusionSettings )
87 , mEyeDomeLightingEnabled( other.mEyeDomeLightingEnabled )
88 , mEyeDomeLightingStrength( other.mEyeDomeLightingStrength )
89 , mEyeDomeLightingDistance( other.mEyeDomeLightingDistance )
90 , mViewSyncMode( other.mViewSyncMode )
91 , mVisualizeViewFrustum( other.mVisualizeViewFrustum )
92 , mDebugShadowMapEnabled( other.mDebugShadowMapEnabled )
93 , mDebugShadowMapCorner( other.mDebugShadowMapCorner )
94 , mDebugShadowMapSize( other.mDebugShadowMapSize )
95 , mDebugDepthMapEnabled( other.mDebugDepthMapEnabled )
96 , mDebugDepthMapCorner( other.mDebugDepthMapCorner )
97 , mDebugDepthMapSize( other.mDebugDepthMapSize )
98 , mTerrainRenderingEnabled( other.mTerrainRenderingEnabled )
99 , mRendererUsage( other.mRendererUsage )
100 , m3dAxisSettings( other.m3dAxisSettings )
101 , mIsDebugOverlayEnabled( other.mIsDebugOverlayEnabled )
102 , mExtent( other.mExtent )
103 , mShowExtentIn2DView( other.mShowExtentIn2DView )
104{
105 for ( QgsLightSource *source : std::as_const( other.mLightSources ) )
106 {
107 if ( source )
108 mLightSources << source->clone();
109 }
110
111 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
112 {
114 } );
115 connectChangedSignalsToSettingsChanged();
116}
117
119{
120 qDeleteAll( mLightSources );
121}
122
123void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
124{
126
128 QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
129 mOrigin = QgsVector3D(
130 elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
131 elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
132 elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
133
134 QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
135 if ( !elemExtent.isNull() )
136 {
137 mExtent = QgsRectangle(
138 elemExtent.attribute( QStringLiteral( "xMin" ) ).toDouble(),
139 elemExtent.attribute( QStringLiteral( "yMin" ) ).toDouble(),
140 elemExtent.attribute( QStringLiteral( "xMax" ) ).toDouble(),
141 elemExtent.attribute( QStringLiteral( "yMax" ) ).toDouble() );
142
143 mShowExtentIn2DView = elemExtent.attribute( QStringLiteral( "showIn2dView" ), QStringLiteral( "0" ) ).toInt();
144 }
145 else
146 {
148 }
149
150 QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
151 if ( !elemCamera.isNull() )
152 {
153 mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
154 mProjectionType = static_cast< Qt3DRender::QCameraLens::ProjectionType >( elemCamera.attribute( QStringLiteral( "projection-type" ), QStringLiteral( "1" ) ).toInt() );
155 QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
156 if ( cameraNavigationMode == QLatin1String( "terrain-based-navigation" ) )
157 mCameraNavigationMode = Qgis::NavigationMode::TerrainBased;
158 else if ( cameraNavigationMode == QLatin1String( "walk-navigation" ) )
159 mCameraNavigationMode = Qgis::NavigationMode::Walk;
160 mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
161 }
162
163 QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
164 if ( !elemColor.isNull() )
165 {
166 mBackgroundColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "background" ) ) );
167 mSelectionColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "selection" ) ) );
168 }
169
170 QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
171 mCrs.readXml( elemCrs );
172
173 QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
174 mTerrainRenderingEnabled = elemTerrain.attribute( QStringLiteral( "terrain-rendering-enabled" ), QStringLiteral( "1" ) ).toInt();
175 mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
176 mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
177 mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
178 mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
179 mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
180 mTerrainElevationOffset = elemTerrain.attribute( QStringLiteral( "elevation-offset" ), QStringLiteral( "0.0" ) ).toFloat();
181
182 QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
183 if ( !elemTerrainShadingMaterial.isNull() )
184 mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
185 mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
186 mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
187
188 qDeleteAll( mLightSources );
189 mLightSources.clear();
190 const QDomElement lightsElem = elem.firstChildElement( QStringLiteral( "lights" ) );
191 if ( !lightsElem.isNull() )
192 {
193 const QDomNodeList lightNodes = lightsElem.childNodes();
194 for ( int i = 0; i < lightNodes.size(); ++i )
195 {
196 const QDomElement lightElement = lightNodes.at( i ).toElement();
197 if ( QgsLightSource *light = QgsLightSource::createFromXml( lightElement, context ) )
198 mLightSources << light;
199 }
200 }
201 else
202 {
203 // older project format
204 QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
205 if ( !elemPointLights.isNull() )
206 {
207 QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
208 while ( !elemPointLight.isNull() )
209 {
210 std::unique_ptr< QgsPointLightSettings > pointLight = std::make_unique< QgsPointLightSettings >();
211 pointLight->readXml( elemPointLight, context );
212 mLightSources << pointLight.release();
213 elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
214 }
215 }
216 else
217 {
218 // QGIS <= 3.4 did not have light configuration
219 std::unique_ptr< QgsPointLightSettings > defaultLight = std::make_unique< QgsPointLightSettings >();
220 defaultLight->setPosition( QgsVector3D( 0, 1000, 0 ) );
221 mLightSources << defaultLight.release();
222 }
223
224 QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
225 if ( !elemDirectionalLights.isNull() )
226 {
227 QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
228 while ( !elemDirectionalLight.isNull() )
229 {
230 std::unique_ptr< QgsDirectionalLightSettings > directionalLight = std::make_unique< QgsDirectionalLightSettings >();
231 directionalLight->readXml( elemDirectionalLight, context );
232 mLightSources << directionalLight.release();
233 elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
234 }
235 }
236 }
237
238 QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
239 QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
240 QList<QgsMapLayerRef> mapLayers;
241 while ( !elemMapLayer.isNull() )
242 {
243 mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
244 elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
245 }
246 mLayers = mapLayers; // needs to resolve refs afterwards
247
248 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
249 QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
250 if ( terrainGenType == QLatin1String( "dem" ) )
251 {
252 QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
253 demTerrainGenerator->setCrs( mCrs, mTransformContext );
254 setTerrainGenerator( demTerrainGenerator );
255 }
256 else if ( terrainGenType == QLatin1String( "online" ) )
257 {
258 QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
259 onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
260 setTerrainGenerator( onlineTerrainGenerator );
261 }
262 else if ( terrainGenType == QLatin1String( "mesh" ) )
263 {
264 QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
265 meshTerrainGenerator->setCrs( mCrs, mTransformContext );
266 setTerrainGenerator( meshTerrainGenerator );
267 }
268 else if ( terrainGenType == QLatin1String( "quantizedmesh" ) )
269 {
271 setTerrainGenerator( qmTerrainGenerator );
272 }
273 else // "flat"
274 {
276 flatGen->setCrs( mCrs );
277 setTerrainGenerator( flatGen );
278 }
279 mTerrainGenerator->readXml( elemTerrainGenerator );
280
281 QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
282 mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
283 mSkyboxSettings.readXml( elemSkybox, context );
284
285 QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
286 mShadowSettings.readXml( elemShadows, context );
287
288 QDomElement elemAmbientOcclusion = elem.firstChildElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
289 mAmbientOcclusionSettings.readXml( elemAmbientOcclusion, context );
290
291 QDomElement elemEyeDomeLighting = elem.firstChildElement( QStringLiteral( "eye-dome-lighting" ) );
292 mEyeDomeLightingEnabled = elemEyeDomeLighting.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
293 mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
294 mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();
295
296 QDomElement elemNavigationSync = elem.firstChildElement( QStringLiteral( "navigation-sync" ) );
297 mViewSyncMode = ( Qgis::ViewSyncModeFlags )( elemNavigationSync.attribute( QStringLiteral( "view-sync-mode" ), QStringLiteral( "0" ) ).toInt() );
298 mVisualizeViewFrustum = elemNavigationSync.attribute( QStringLiteral( "view-frustum-visualization-enabled" ), QStringLiteral( "0" ) ).toInt();
299
300 QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
301 mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
302 mDebugShadowMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), "0" ).toInt() );
303 mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
304
305 mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
306 mDebugDepthMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "1" ) ).toInt() );
307 mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
308
309 QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
310 mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
311 mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
312 mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
313 mShowCameraRotationCenter = elemDebug.attribute( QStringLiteral( "camera-rotation-center" ), QStringLiteral( "0" ) ).toInt();
314 mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
315 mIsFpsCounterEnabled = elemDebug.attribute( QStringLiteral( "show-fps-counter" ), QStringLiteral( "0" ) ).toInt();
316
317 QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
318 QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
319 QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
320 setTemporalRange( QgsDateTimeRange( start, end ) );
321
322 QDomElement elem3dAxis = elem.firstChildElement( QStringLiteral( "axis3d" ) );
323 m3dAxisSettings.readXml( elem3dAxis, context );
324
325}
326
327QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
328{
330
331 QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
332
333 QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
334 elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
335 elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
336 elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
337 elem.appendChild( elemOrigin );
338
339 QDomElement elemExtent = doc.createElement( QStringLiteral( "extent" ) );
340 elemExtent.setAttribute( QStringLiteral( "xMin" ), mExtent.xMinimum() );
341 elemExtent.setAttribute( QStringLiteral( "yMin" ), mExtent.yMinimum() );
342 elemExtent.setAttribute( QStringLiteral( "xMax" ), mExtent.xMaximum() );
343 elemExtent.setAttribute( QStringLiteral( "yMax" ), mExtent.yMaximum() );
344 elemExtent.setAttribute( QStringLiteral( "showIn2dView" ), mShowExtentIn2DView );
345 elem.appendChild( elemExtent );
346
347 QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
348 elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
349 elemCamera.setAttribute( QStringLiteral( "projection-type" ), static_cast< int >( mProjectionType ) );
350 switch ( mCameraNavigationMode )
351 {
353 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
354 break;
356 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
357 break;
358 }
359 elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
360 elem.appendChild( elemCamera );
361
362 QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
363 elemColor.setAttribute( QStringLiteral( "background" ), QgsColorUtils::colorToString( mBackgroundColor ) );
364 elemColor.setAttribute( QStringLiteral( "selection" ), QgsColorUtils::colorToString( mSelectionColor ) );
365 elem.appendChild( elemColor );
366
367 QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
368 mCrs.writeXml( elemCrs, doc );
369 elem.appendChild( elemCrs );
370
371 QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
372 elemTerrain.setAttribute( QStringLiteral( "terrain-rendering-enabled" ), mTerrainRenderingEnabled ? 1 : 0 );
373 elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
374 elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
375 elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
376 elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
377 elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
378 elemTerrain.setAttribute( QStringLiteral( "elevation-offset" ), mTerrainElevationOffset );
379
380 QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
381 mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
382 elemTerrain.appendChild( elemTerrainShadingMaterial );
383 elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
384 elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
385
386 {
387 QDomElement elemLights = doc.createElement( QStringLiteral( "lights" ) );
388 for ( const QgsLightSource *light : mLightSources )
389 {
390 const QDomElement elemLight = light->writeXml( doc, context );
391 elemLights.appendChild( elemLight );
392 }
393 elem.appendChild( elemLights );
394 }
395
396 QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
397 for ( const QgsMapLayerRef &layerRef : mLayers )
398 {
399 QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
400 elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
401 elemMapLayers.appendChild( elemMapLayer );
402 }
403 elemTerrain.appendChild( elemMapLayers );
404
405 QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
406 elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
407 mTerrainGenerator->writeXml( elemTerrainGenerator );
408 elemTerrain.appendChild( elemTerrainGenerator );
409 elem.appendChild( elemTerrain );
410
411 QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
412 elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
413 mSkyboxSettings.writeXml( elemSkybox, context );
414 elem.appendChild( elemSkybox );
415
416 QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
417 mShadowSettings.writeXml( elemShadows, context );
418 elem.appendChild( elemShadows );
419
420 QDomElement elemAmbientOcclusion = doc.createElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
421 mAmbientOcclusionSettings.writeXml( elemAmbientOcclusion, context );
422 elem.appendChild( elemAmbientOcclusion );
423
424 QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
425 elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
426 elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
427 elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
428 elemDebug.setAttribute( QStringLiteral( "camera-rotation-center" ), mShowCameraRotationCenter ? 1 : 0 );
429 elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
430 elemDebug.setAttribute( QStringLiteral( "show-fps-counter" ), mIsFpsCounterEnabled ? 1 : 0 );
431 elem.appendChild( elemDebug );
432
433 QDomElement elemEyeDomeLighting = doc.createElement( QStringLiteral( "eye-dome-lighting" ) );
434 elemEyeDomeLighting.setAttribute( QStringLiteral( "enabled" ), mEyeDomeLightingEnabled ? 1 : 0 );
435 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-strength" ), mEyeDomeLightingStrength );
436 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-distance" ), mEyeDomeLightingDistance );
437 elem.appendChild( elemEyeDomeLighting );
438
439 QDomElement elemNavigationSync = doc.createElement( QStringLiteral( "navigation-sync" ) );
440 elemNavigationSync.setAttribute( QStringLiteral( "view-sync-mode" ), ( int )mViewSyncMode );
441 elemNavigationSync.setAttribute( QStringLiteral( "view-frustum-visualization-enabled" ), mVisualizeViewFrustum ? 1 : 0 );
442 elem.appendChild( elemNavigationSync );
443
444 QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
445 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
446 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
447 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
448 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
449 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
450 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
451 elem.appendChild( elemDebugSettings );
452
453 QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
454 elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
455 elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
456
457 QDomElement elem3dAxis = doc.createElement( QStringLiteral( "axis3d" ) );
458 m3dAxisSettings.writeXml( elem3dAxis, context );
459 elem.appendChild( elem3dAxis );
460
461 return elem;
462}
463
465{
467
468 for ( int i = 0; i < mLayers.count(); ++i )
469 {
470 QgsMapLayerRef &layerRef = mLayers[i];
471 layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
472 }
473
474 mTerrainGenerator->resolveReferences( project );
475
476 // Set extent now that layer-based generators actually have a chance to know their CRS
477 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, mTerrainGenerator->crs(), mTransformContext );
478 mTerrainGenerator->setExtent( terrainExtent );
479}
480
487
489{
491
492 if ( extent == mExtent )
493 return;
494
495 mExtent = extent;
496 const QgsPointXY center = mExtent.center();
497 setOrigin( QgsVector3D( center.x(), center.y(), 0 ) );
498 if ( mTerrainGenerator )
499 {
500 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, mTerrainGenerator->crs(), mTransformContext );
501 mTerrainGenerator->setExtent( terrainExtent );
502 }
503 emit extentChanged();
504}
505
507{
509
510 mOrigin = origin;
511}
512
514{
516
517 return mOrigin;
518}
519
526
533
540
547
554
556{
558
559 mTransformContext = context;
560}
561
563{
565
566 return mPathResolver;
567}
568
570{
572
573 mPathResolver = resolver;
574}
575
582
584{
586
587 mMapThemes = mapThemes;
588}
589
590void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
591{
593
594 if ( color == mBackgroundColor )
595 return;
596
597 mBackgroundColor = color;
599}
600
602{
604
605 return mBackgroundColor;
606}
607
608void Qgs3DMapSettings::setSelectionColor( const QColor &color )
609{
611
612 if ( color == mSelectionColor )
613 return;
614
615 mSelectionColor = color;
617}
618
620{
622
623 return mSelectionColor;
624}
625
627{
629
630 if ( zScale == mTerrainVerticalScale )
631 return;
632
633 mTerrainVerticalScale = zScale;
635}
636
638{
640
641 return mTerrainVerticalScale;
642}
643
644void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
645{
647
648 const QList<QgsMapLayer *> raw = _qgis_listRefToRaw( mLayers );
649
650 if ( layers == raw )
651 return;
652
653 mLayers = _qgis_listRawToRef( layers );
654 emit layersChanged();
655}
656
657QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
658{
660
661 QList<QgsMapLayer *> lst;
662 lst.reserve( mLayers.count() );
663 for ( const QgsMapLayerRef &layerRef : mLayers )
664 {
665 if ( layerRef.layer )
666 lst.append( layerRef.layer );
667 }
668 return lst;
669}
670
672{
674
675 setExtent( fullExtent );
676 if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
677 {
679 flatTerrain->setCrs( crs() );
680 setTerrainGenerator( flatTerrain );
681
683 }
684 else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
685 {
686 QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast< QgsRasterDemTerrainProvider * >( properties->terrainProvider() );
687
689 demTerrainGen->setCrs( crs(), QgsProject::instance()->transformContext() );
690 demTerrainGen->setLayer( rasterProvider->layer() );
691 setTerrainGenerator( demTerrainGen );
692
695 }
696 else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
697 {
698 QgsMeshTerrainProvider *meshProvider = qgis::down_cast< QgsMeshTerrainProvider * >( properties->terrainProvider() );
699
700 QgsMeshTerrainGenerator *newTerrainGenerator = new QgsMeshTerrainGenerator;
701 newTerrainGenerator->setCrs( crs(), QgsProject::instance()->transformContext() );
702 newTerrainGenerator->setLayer( meshProvider->layer() );
703 std::unique_ptr< QgsMesh3DSymbol > symbol( newTerrainGenerator->symbol()->clone() );
704 symbol->setVerticalScale( properties->terrainProvider()->scale() );
705 newTerrainGenerator->setSymbol( symbol.release() );
706 setTerrainGenerator( newTerrainGenerator );
707
710 }
711 else
712 {
714 flatTerrain->setCrs( crs() );
715 setTerrainGenerator( flatTerrain );
716 }
717}
718
720{
722
723 if ( mMapTileResolution == res )
724 return;
725
726 mMapTileResolution = res;
728}
729
731{
733
734 return mMapTileResolution;
735}
736
738{
740
741 if ( mMaxTerrainScreenError == error )
742 return;
743
744 mMaxTerrainScreenError = error;
746}
747
749{
751
752 return mMaxTerrainScreenError;
753}
754
756{
758
759 if ( mMaxTerrainGroundError == error )
760 return;
761
762 mMaxTerrainGroundError = error;
764}
765
767{
769
770 if ( mTerrainElevationOffset == offset )
771 return;
772 mTerrainElevationOffset = offset;
773 emit terrainElevationOffsetChanged( mTerrainElevationOffset );
774}
775
777{
779
780 return mTerrainElevationOffset;
781}
782
784{
786
787 return mMaxTerrainGroundError;
788}
789
791{
793
794 if ( mTerrainGenerator )
795 {
796 disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
797 }
798
799 if ( gen->crs().isValid() ) // Don't bother setting an extent rect in the wrong CRS
800 {
801 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, gen->crs(), mTransformContext );
802 gen->setExtent( terrainExtent );
803 }
804 mTerrainGenerator.reset( gen );
805 connect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
806
808}
809
811{
813
814 return mTerrainGenerator.get();
815}
816
818{
820
821 if ( mTerrainShadingEnabled == enabled )
822 return;
823
824 mTerrainShadingEnabled = enabled;
826}
827
829{
831
832 return mTerrainShadingEnabled;
833}
834
836{
838
839 if ( mTerrainShadingMaterial == material )
840 return;
841
842 mTerrainShadingMaterial = material;
844}
845
852
853void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
854{
856
857 if ( mTerrainMapTheme == theme )
858 return;
859
860 mTerrainMapTheme = theme;
862}
863
865{
867
868 return mTerrainMapTheme;
869}
870
872{
874
875 if ( mShowTerrainBoundingBoxes == enabled )
876 return;
877
878 mShowTerrainBoundingBoxes = enabled;
880}
881
883{
885
886 return mShowTerrainBoundingBoxes;
887}
888
889
891{
893
894 if ( mShowTerrainTileInfo == enabled )
895 return;
896
897 mShowTerrainTileInfo = enabled;
899}
900
902{
904
905 return mShowTerrainTileInfo;
906}
907
909{
911
912 if ( mShowCameraViewCenter == enabled )
913 return;
914
915 mShowCameraViewCenter = enabled;
917}
918
920{
922
923 return mShowCameraViewCenter;
924}
925
927{
929
930 if ( mShowCameraRotationCenter == enabled )
931 return;
932
933 mShowCameraRotationCenter = enabled;
935}
936
938{
940
941 return mShowCameraRotationCenter;
942}
943
945{
947
948 if ( mShowLightSources == enabled )
949 return;
950
951 mShowLightSources = enabled;
953}
954
956{
958
959 return mShowLightSources;
960}
961
963{
965
966 if ( mShowLabels == enabled )
967 return;
968
969 mShowLabels = enabled;
970 emit showLabelsChanged();
971}
972
974{
976
977 return mShowLabels;
978}
979
981{
983
984 if ( mEyeDomeLightingEnabled == enabled )
985 return;
986 mEyeDomeLightingEnabled = enabled;
988}
989
991{
993
994 return mEyeDomeLightingEnabled;
995}
996
998{
1000
1001 if ( mEyeDomeLightingStrength == strength )
1002 return;
1003 mEyeDomeLightingStrength = strength;
1005}
1006
1008{
1010
1011 return mEyeDomeLightingStrength;
1012}
1013
1015{
1017
1018 if ( mEyeDomeLightingDistance == distance )
1019 return;
1020 mEyeDomeLightingDistance = distance;
1022}
1023
1025{
1027
1028 return mEyeDomeLightingDistance;
1029}
1030
1031QList<QgsLightSource *> Qgs3DMapSettings::lightSources() const
1032{
1034
1035 return mLightSources;
1036}
1037
1038void Qgs3DMapSettings::setLightSources( const QList<QgsLightSource *> &lights )
1039{
1041
1042 // have lights actually changed?
1043 if ( mLightSources.count() == lights.count() )
1044 {
1045 bool same = true;
1046 for ( int i = 0; i < mLightSources.count(); ++i )
1047 {
1048 if ( mLightSources[i]->type() == lights[i]->type() )
1049 {
1050 switch ( mLightSources[i]->type() )
1051 {
1053 if ( *static_cast< QgsPointLightSettings * >( mLightSources[i] ) == *static_cast< QgsPointLightSettings * >( lights[i] ) )
1054 continue;
1055 break;
1057 if ( *static_cast< QgsDirectionalLightSettings * >( mLightSources[i] ) == *static_cast< QgsDirectionalLightSettings * >( lights[i] ) )
1058 continue;
1059 break;
1060 }
1061 }
1062 same = false;
1063 break;
1064 }
1065 if ( same )
1066 {
1067 qDeleteAll( lights );
1068 return;
1069 }
1070 }
1071
1072 qDeleteAll( mLightSources );
1073 mLightSources = lights;
1074
1076 emit pointLightsChanged();
1077 emit lightSourcesChanged();
1078}
1079
1081{
1083
1084 return mFieldOfView;
1085}
1086
1087void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
1088{
1090
1091 if ( mFieldOfView == fieldOfView )
1092 return;
1093
1094 mFieldOfView = fieldOfView;
1095 emit fieldOfViewChanged();
1096}
1097
1098Qt3DRender::QCameraLens::ProjectionType Qgs3DMapSettings::projectionType() const
1099{
1101
1102 return mProjectionType;
1103}
1104
1105void Qgs3DMapSettings::setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType )
1106{
1108
1109 if ( mProjectionType == projectionType )
1110 return;
1111
1112 mProjectionType = projectionType;
1113 emit projectionTypeChanged();
1114}
1115
1117{
1119
1120 return mCameraNavigationMode;
1121}
1122
1124{
1126
1127 if ( mCameraNavigationMode == navigationMode )
1128 return;
1129
1130 mCameraNavigationMode = navigationMode;
1132}
1133
1135{
1137
1138 return mCameraMovementSpeed;
1139}
1140
1142{
1144
1145 if ( mCameraMovementSpeed == movementSpeed )
1146 return;
1147
1148 mCameraMovementSpeed = movementSpeed;
1150}
1151
1152void Qgs3DMapSettings::setOutputDpi( const double dpi )
1153{
1155
1156 mDpi = dpi;
1157}
1158
1160{
1162
1163 return mDpi;
1164}
1165
1167{
1169
1170 return mSkyboxSettings;
1171}
1172
1174{
1176
1177 return mShadowSettings;
1178}
1179
1181{
1183
1184 return mAmbientOcclusionSettings;
1185}
1186
1188{
1190
1191 mSkyboxSettings = skyboxSettings;
1192 emit skyboxSettingsChanged();
1193}
1194
1196{
1198
1199 mShadowSettings = shadowSettings;
1200 emit shadowSettingsChanged();
1201}
1202
1204{
1206
1207 mAmbientOcclusionSettings = ambientOcclusionSettings;
1209}
1210
1212{
1214
1215 return mIsSkyboxEnabled;
1216}
1217
1219{
1221
1222 mIsSkyboxEnabled = enabled;
1223}
1224
1226{
1228
1229 return mIsFpsCounterEnabled;
1230}
1231
1232void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size )
1233{
1235
1236 mDebugShadowMapEnabled = enabled;
1237 mDebugShadowMapCorner = corner;
1238 mDebugShadowMapSize = size;
1240}
1241
1243{
1245
1246 return mDebugShadowMapEnabled;
1247}
1248
1250{
1252
1253 return mDebugShadowMapCorner;
1254}
1255
1257{
1259
1260 return mDebugShadowMapSize;
1261}
1262
1263void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size )
1264{
1266
1267 mDebugDepthMapEnabled = enabled;
1268 mDebugDepthMapCorner = corner;
1269 mDebugDepthMapSize = size;
1271}
1272
1274{
1276
1277 return mDebugDepthMapEnabled;
1278}
1279
1281{
1283
1284 return mDebugDepthMapCorner;
1285}
1286
1288{
1290
1291 return mDebugDepthMapSize;
1292}
1293
1294void Qgs3DMapSettings::setIsFpsCounterEnabled( bool fpsCounterEnabled )
1295{
1297
1298 if ( fpsCounterEnabled == mIsFpsCounterEnabled )
1299 return;
1300 mIsFpsCounterEnabled = fpsCounterEnabled;
1301 emit fpsCounterEnabledChanged( mIsFpsCounterEnabled );
1302}
1303
1305{
1307
1308 return mTerrainRenderingEnabled;
1309}
1310
1311void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled )
1312{
1314
1315 if ( terrainRenderingEnabled == mTerrainRenderingEnabled )
1316 return;
1317 mTerrainRenderingEnabled = terrainRenderingEnabled;
1319}
1320
1322{
1324
1325 return mRendererUsage;
1326}
1327
1329{
1331
1332 mRendererUsage = rendererUsage;
1333}
1334
1341
1343{
1345
1346 mViewSyncMode = mode;
1347}
1348
1350{
1352
1353 return mVisualizeViewFrustum;
1354}
1355
1357{
1359
1360 if ( mVisualizeViewFrustum != enabled )
1361 {
1362 mVisualizeViewFrustum = enabled;
1364 }
1365}
1366
1368{
1370
1371 return m3dAxisSettings;
1372}
1373
1374void Qgs3DMapSettings::setIsDebugOverlayEnabled( bool debugOverlayEnabled )
1375{
1377
1378 if ( debugOverlayEnabled == mIsDebugOverlayEnabled )
1379 return;
1380
1381 mIsDebugOverlayEnabled = debugOverlayEnabled;
1382 emit debugOverlayEnabledChanged( mIsDebugOverlayEnabled );
1383}
1384
1386{
1388
1389 return mShowExtentIn2DView;
1390}
1391
1392void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
1393{
1395
1429}
1430
1431
1432void Qgs3DMapSettings::set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force )
1433{
1435
1436 if ( axisSettings == m3dAxisSettings )
1437 {
1438 if ( force )
1439 {
1440 // ie. refresh. We need to disconnect and to reconnect to avoid 'dirty' project
1442 emit axisSettingsChanged();
1444 }
1445 }
1446 else
1447 {
1448 m3dAxisSettings = axisSettings;
1449 emit axisSettingsChanged();
1450 }
1451}
1452
1454{
1456
1457 return mIsDebugOverlayEnabled;
1458}
1459
1461{
1463
1464 if ( show == mShowExtentIn2DView )
1465 return;
1466
1467 mShowExtentIn2DView = show;
1469}
QFlags< ViewSyncModeFlag > ViewSyncModeFlags
Definition qgis.h:3225
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:3864
@ TerrainBased
The default navigation based on the terrain.
@ Walk
Uses WASD keys or arrows to navigate in walking (first person) manner.
RendererUsage
Usage of the renderer.
Definition qgis.h:3188
@ Point
Point light source.
@ Directional
Directional light source.
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 extentChanged()
Emitted when the 3d view's 2d extent has changed.
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.
bool isDebugOverlayEnabled() const
Returns whether debug overlay is enabled.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
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.
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.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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,...
bool showExtentIn2DView() const
Returns whether the extent is displayed on the main 2D map canvas.
double cameraMovementSpeed() const
Returns the camera movement speed.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting will be used.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
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.
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Qgis::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
void backgroundColorChanged()
Emitted when the background color has changed.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
Qt::Corner debugShadowMapCorner() const
Returns the corner where the shadow map preview is displayed.
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
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.
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.
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 setExtent(const QgsRectangle &extent)
Sets the 3D scene's 2D extent in the 3D scene's CRS, while also setting the scene's origin to the ext...
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 setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
void setIsSkyboxEnabled(bool enabled)
Sets whether the skybox is enabled.
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 setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
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.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
Qgs3DAxisSettings get3DAxisSettings() const
Returns the current configuration of 3d axis.
void setEyeDomeLightingDistance(int distance)
Sets the eye dome lighting distance value (contributes to the contrast of the image.
bool viewFrustumVisualizationEnabled() const
Returns whether the camera's view frustum is visualized on the 2D map canvas.
void setShowLightSourceOrigins(bool enabled)
Sets whether to show light source origins as a sphere (for debugging)
void setShowExtentIn2DView(bool show)
Sets whether the extent is displayed on the main 2D map canvas.
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.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
void setTerrainShadingEnabled(bool enabled)
Sets whether terrain shading is enabled.
Qgis::ViewSyncModeFlags viewSyncMode() const
Returns the view sync mode (used to synchronize the 2D main map canvas and the 3D camera navigation)
void setDebugShadowMapSettings(bool enabled, Qt::Corner corner, double size)
Sets the debugging settings of the shadow map.
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down)
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image)
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.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
void setCameraNavigationMode(Qgis::NavigationMode navigationMode)
Sets the navigation mode for the camera.
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()
double debugShadowMapSize() const
Returns the size of the shadow map preview.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
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 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.
bool showLabels() const
Returns whether to display labels on terrain tiles.
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.
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
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.
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging)
void showExtentIn2DViewChanged()
Emitted when the parameter to display 3d view's extent in the 2D canvas has changed.
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.
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the renderer usage.
bool isFpsCounterEnabled() const
Returns whether FPS counter label is enabled.
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain's texture.
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.
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
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.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
void setTerrainGenerator(QgsTerrainGenerator *gen)
Sets terrain generator and sets extent() as the generator's extent.
void debugShadowMapSettingsChanged()
Emitted when shadow map debugging has changed.
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0).
bool showCameraRotationCenter() const
Returns whether to show camera's rotation center as a sphere (for debugging)
static QgsRectangle tryReprojectExtent2D(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Reprojects extent from crs1 to crs2 coordinate reference system with context context.
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset)
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset)
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.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
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.
static QgsLightSource * createFromXml(const QDomElement &element, const QgsReadWriteContext &context)
Creates a new light source from an XML element.
Container class that allows storage of map themes consisting of visible map layers and layer styles.
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.
Resolves relative paths into absolute paths and vice versa.
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.
A class to represent a 2D point.
Definition qgspointxy.h:60
double y
Definition qgspointxy.h:64
double x
Definition qgspointxy.h:63
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Contains elevation properties for a QgsProject.
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
QgsReferencedRectangle fullExtent() const
Returns the full extent of the project, which represents the maximal limits of the project.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
static QgsProject * instance()
Returns the QgsProject singleton instance.
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).
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
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.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
QgsPointXY center() const
Returns the center point of the rectangle.
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.
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.
T begin() const
Returns the beginning of the range.
Definition qgsrange.h:444
T end() const
Returns the upper bound of the range.
Definition qgsrange.h:451
void terrainChanged()
Emitted when the terrain changed (for example, raster DEM or mesh have data changed)
virtual void setExtent(const QgsRectangle &extent)
sets the extent of the terrain in terrain's CRS
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
virtual QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
double y() const
Returns Y coordinate.
Definition qgsvector3d.h:50
double z() const
Returns Z coordinate.
Definition qgsvector3d.h:52
double x() const
Returns X coordinate.
Definition qgsvector3d.h:48
_LayerRef< QgsMapLayer > QgsMapLayerRef
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:742
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
const QgsCoordinateReferenceSystem & crs
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.