QGIS API Documentation 3.39.0-Master (734b709c2f9)
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
18#include "qgs3dutils.h"
21#include "qgsmeshterraingenerator.h"
25#include "qgsterrainprovider.h"
26#include "qgslightsource.h"
27#include "qgscolorutils.h"
28#include "qgsrasterlayer.h"
31#include "qgs3drendercontext.h"
32#include "qgsthreadingutils.h"
33
34#include <QDomDocument>
35#include <QDomElement>
36
37
39 : QObject( nullptr )
40{
41 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
42 {
44 } );
45 connectChangedSignalsToSettingsChanged();
46}
47
49 : QObject( nullptr )
50 , QgsTemporalRangeObject( other )
51 , mOrigin( other.mOrigin )
52 , mCrs( other.mCrs )
53 , mBackgroundColor( other.mBackgroundColor )
54 , mSelectionColor( other.mSelectionColor )
55 , mTerrainVerticalScale( other.mTerrainVerticalScale )
56 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
57 , mMapTileResolution( other.mMapTileResolution )
58 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
59 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
60 , mTerrainElevationOffset( other.mTerrainElevationOffset )
61 , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
62 , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
63 , mTerrainMapTheme( other.mTerrainMapTheme )
64 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
65 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
66 , mShowCameraViewCenter( other.mShowCameraViewCenter )
67 , mShowCameraRotationCenter( other.mShowCameraRotationCenter )
68 , mShowLightSources( other.mShowLightSources )
69 , mShowLabels( other.mShowLabels )
70 , mFieldOfView( other.mFieldOfView )
71 , mProjectionType( other.mProjectionType )
72 , mCameraNavigationMode( other.mCameraNavigationMode )
73 , mCameraMovementSpeed( other.mCameraMovementSpeed )
74 , mLayers( other.mLayers )
75 , mTransformContext( other.mTransformContext )
76 , mPathResolver( other.mPathResolver )
77 , mMapThemes( other.mMapThemes )
78 , mDpi( other.mDpi )
79 , mIsFpsCounterEnabled( other.mIsFpsCounterEnabled )
80 , mIsSkyboxEnabled( other.mIsSkyboxEnabled )
81 , mSkyboxSettings( other.mSkyboxSettings )
82 , mShadowSettings( other.mShadowSettings )
83 , mAmbientOcclusionSettings( other.mAmbientOcclusionSettings )
84 , mEyeDomeLightingEnabled( other.mEyeDomeLightingEnabled )
85 , mEyeDomeLightingStrength( other.mEyeDomeLightingStrength )
86 , mEyeDomeLightingDistance( other.mEyeDomeLightingDistance )
87 , mViewSyncMode( other.mViewSyncMode )
88 , mVisualizeViewFrustum( other.mVisualizeViewFrustum )
89 , mDebugShadowMapEnabled( other.mDebugShadowMapEnabled )
90 , mDebugShadowMapCorner( other.mDebugShadowMapCorner )
91 , mDebugShadowMapSize( other.mDebugShadowMapSize )
92 , mDebugDepthMapEnabled( other.mDebugDepthMapEnabled )
93 , mDebugDepthMapCorner( other.mDebugDepthMapCorner )
94 , mDebugDepthMapSize( other.mDebugDepthMapSize )
95 , mTerrainRenderingEnabled( other.mTerrainRenderingEnabled )
96 , mRendererUsage( other.mRendererUsage )
97 , m3dAxisSettings( other.m3dAxisSettings )
98 , mIsDebugOverlayEnabled( other.mIsDebugOverlayEnabled )
99 , mExtent( other.mExtent )
100 , mShowExtentIn2DView( other.mShowExtentIn2DView )
101{
102 for ( QgsLightSource *source : std::as_const( other.mLightSources ) )
103 {
104 if ( source )
105 mLightSources << source->clone();
106 }
107
108 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
109 {
111 } );
112 connectChangedSignalsToSettingsChanged();
113}
114
116{
117 qDeleteAll( mLightSources );
118}
119
120void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
121{
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 elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
132 if ( !elemExtent.isNull() )
133 {
134 mExtent = QgsRectangle(
135 elemExtent.attribute( QStringLiteral( "xMin" ) ).toDouble(),
136 elemExtent.attribute( QStringLiteral( "yMin" ) ).toDouble(),
137 elemExtent.attribute( QStringLiteral( "xMax" ) ).toDouble(),
138 elemExtent.attribute( QStringLiteral( "yMax" ) ).toDouble() );
139
140 mShowExtentIn2DView = elemExtent.attribute( QStringLiteral( "showIn2dView" ), QStringLiteral( "0" ) ).toInt();
141 }
142 else
143 {
145 }
146
147 QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
148 if ( !elemCamera.isNull() )
149 {
150 mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
151 mProjectionType = static_cast< Qt3DRender::QCameraLens::ProjectionType >( elemCamera.attribute( QStringLiteral( "projection-type" ), QStringLiteral( "1" ) ).toInt() );
152 QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
153 if ( cameraNavigationMode == QLatin1String( "terrain-based-navigation" ) )
154 mCameraNavigationMode = Qgis::NavigationMode::TerrainBased;
155 else if ( cameraNavigationMode == QLatin1String( "walk-navigation" ) )
156 mCameraNavigationMode = Qgis::NavigationMode::Walk;
157 mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
158 }
159
160 QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
161 if ( !elemColor.isNull() )
162 {
163 mBackgroundColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "background" ) ) );
164 mSelectionColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "selection" ) ) );
165 }
166
167 QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
168 mCrs.readXml( elemCrs );
169
170 QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
171 mTerrainRenderingEnabled = elemTerrain.attribute( QStringLiteral( "terrain-rendering-enabled" ), QStringLiteral( "1" ) ).toInt();
172 mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
173 mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
174 mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
175 mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
176 mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
177 mTerrainElevationOffset = elemTerrain.attribute( QStringLiteral( "elevation-offset" ), QStringLiteral( "0.0" ) ).toFloat();
178
179 QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
180 if ( !elemTerrainShadingMaterial.isNull() )
181 mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
182 mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
183 mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
184
185 qDeleteAll( mLightSources );
186 mLightSources.clear();
187 const QDomElement lightsElem = elem.firstChildElement( QStringLiteral( "lights" ) );
188 if ( !lightsElem.isNull() )
189 {
190 const QDomNodeList lightNodes = lightsElem.childNodes();
191 for ( int i = 0; i < lightNodes.size(); ++i )
192 {
193 const QDomElement lightElement = lightNodes.at( i ).toElement();
194 if ( QgsLightSource *light = QgsLightSource::createFromXml( lightElement, context ) )
195 mLightSources << light;
196 }
197 }
198 else
199 {
200 // older project format
201 QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
202 if ( !elemPointLights.isNull() )
203 {
204 QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
205 while ( !elemPointLight.isNull() )
206 {
207 std::unique_ptr< QgsPointLightSettings > pointLight = std::make_unique< QgsPointLightSettings >();
208 pointLight->readXml( elemPointLight, context );
209 mLightSources << pointLight.release();
210 elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
211 }
212 }
213 else
214 {
215 // QGIS <= 3.4 did not have light configuration
216 std::unique_ptr< QgsPointLightSettings > defaultLight = std::make_unique< QgsPointLightSettings >();
217 defaultLight->setPosition( QgsVector3D( 0, 1000, 0 ) );
218 mLightSources << defaultLight.release();
219 }
220
221 QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
222 if ( !elemDirectionalLights.isNull() )
223 {
224 QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
225 while ( !elemDirectionalLight.isNull() )
226 {
227 std::unique_ptr< QgsDirectionalLightSettings > directionalLight = std::make_unique< QgsDirectionalLightSettings >();
228 directionalLight->readXml( elemDirectionalLight, context );
229 mLightSources << directionalLight.release();
230 elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
231 }
232 }
233 }
234
235 QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
236 QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
237 QList<QgsMapLayerRef> mapLayers;
238 while ( !elemMapLayer.isNull() )
239 {
240 mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
241 elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
242 }
243 mLayers = mapLayers; // needs to resolve refs afterwards
244
245 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
246 QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
247 if ( terrainGenType == QLatin1String( "dem" ) )
248 {
249 QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
250 demTerrainGenerator->setCrs( mCrs, mTransformContext );
251 setTerrainGenerator( demTerrainGenerator );
252 }
253 else if ( terrainGenType == QLatin1String( "online" ) )
254 {
255 QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
256 onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
257 setTerrainGenerator( onlineTerrainGenerator );
258 }
259 else if ( terrainGenType == QLatin1String( "mesh" ) )
260 {
261 QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
262 meshTerrainGenerator->setCrs( mCrs, mTransformContext );
263 setTerrainGenerator( meshTerrainGenerator );
264 }
265 else // "flat"
266 {
268 flatGen->setCrs( mCrs );
269 setTerrainGenerator( flatGen );
270 }
271 mTerrainGenerator->readXml( elemTerrainGenerator );
272
273 QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
274 mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
275 mSkyboxSettings.readXml( elemSkybox, context );
276
277 QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
278 mShadowSettings.readXml( elemShadows, context );
279
280 QDomElement elemAmbientOcclusion = elem.firstChildElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
281 mAmbientOcclusionSettings.readXml( elemAmbientOcclusion, context );
282
283 QDomElement elemEyeDomeLighting = elem.firstChildElement( QStringLiteral( "eye-dome-lighting" ) );
284 mEyeDomeLightingEnabled = elemEyeDomeLighting.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
285 mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
286 mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();
287
288 QDomElement elemNavigationSync = elem.firstChildElement( QStringLiteral( "navigation-sync" ) );
289 mViewSyncMode = ( Qgis::ViewSyncModeFlags )( elemNavigationSync.attribute( QStringLiteral( "view-sync-mode" ), QStringLiteral( "0" ) ).toInt() );
290 mVisualizeViewFrustum = elemNavigationSync.attribute( QStringLiteral( "view-frustum-visualization-enabled" ), QStringLiteral( "0" ) ).toInt();
291
292 QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
293 mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
294 mDebugShadowMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), "0" ).toInt() );
295 mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
296
297 mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
298 mDebugDepthMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "1" ) ).toInt() );
299 mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
300
301 QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
302 mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
303 mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
304 mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
305 mShowCameraRotationCenter = elemDebug.attribute( QStringLiteral( "camera-rotation-center" ), QStringLiteral( "0" ) ).toInt();
306 mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
307 mIsFpsCounterEnabled = elemDebug.attribute( QStringLiteral( "show-fps-counter" ), QStringLiteral( "0" ) ).toInt();
308
309 QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
310 QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
311 QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
312 setTemporalRange( QgsDateTimeRange( start, end ) );
313
314 QDomElement elem3dAxis = elem.firstChildElement( QStringLiteral( "axis3d" ) );
315 m3dAxisSettings.readXml( elem3dAxis, context );
316
317}
318
319QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
320{
322
323 QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
324
325 QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
326 elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
327 elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
328 elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
329 elem.appendChild( elemOrigin );
330
331 QDomElement elemExtent = doc.createElement( QStringLiteral( "extent" ) );
332 elemExtent.setAttribute( QStringLiteral( "xMin" ), mExtent.xMinimum() );
333 elemExtent.setAttribute( QStringLiteral( "yMin" ), mExtent.yMinimum() );
334 elemExtent.setAttribute( QStringLiteral( "xMax" ), mExtent.xMaximum() );
335 elemExtent.setAttribute( QStringLiteral( "yMax" ), mExtent.yMaximum() );
336 elemExtent.setAttribute( QStringLiteral( "showIn2dView" ), mShowExtentIn2DView );
337 elem.appendChild( elemExtent );
338
339 QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
340 elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
341 elemCamera.setAttribute( QStringLiteral( "projection-type" ), static_cast< int >( mProjectionType ) );
342 switch ( mCameraNavigationMode )
343 {
345 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
346 break;
348 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
349 break;
350 }
351 elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
352 elem.appendChild( elemCamera );
353
354 QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
355 elemColor.setAttribute( QStringLiteral( "background" ), QgsColorUtils::colorToString( mBackgroundColor ) );
356 elemColor.setAttribute( QStringLiteral( "selection" ), QgsColorUtils::colorToString( mSelectionColor ) );
357 elem.appendChild( elemColor );
358
359 QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
360 mCrs.writeXml( elemCrs, doc );
361 elem.appendChild( elemCrs );
362
363 QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
364 elemTerrain.setAttribute( QStringLiteral( "terrain-rendering-enabled" ), mTerrainRenderingEnabled ? 1 : 0 );
365 elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
366 elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
367 elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
368 elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
369 elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
370 elemTerrain.setAttribute( QStringLiteral( "elevation-offset" ), mTerrainElevationOffset );
371
372 QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
373 mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
374 elemTerrain.appendChild( elemTerrainShadingMaterial );
375 elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
376 elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
377
378 {
379 QDomElement elemLights = doc.createElement( QStringLiteral( "lights" ) );
380 for ( const QgsLightSource *light : mLightSources )
381 {
382 const QDomElement elemLight = light->writeXml( doc, context );
383 elemLights.appendChild( elemLight );
384 }
385 elem.appendChild( elemLights );
386 }
387
388 QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
389 for ( const QgsMapLayerRef &layerRef : mLayers )
390 {
391 QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
392 elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
393 elemMapLayers.appendChild( elemMapLayer );
394 }
395 elemTerrain.appendChild( elemMapLayers );
396
397 QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
398 elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
399 mTerrainGenerator->writeXml( elemTerrainGenerator );
400 elemTerrain.appendChild( elemTerrainGenerator );
401 elem.appendChild( elemTerrain );
402
403 QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
404 elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
405 mSkyboxSettings.writeXml( elemSkybox, context );
406 elem.appendChild( elemSkybox );
407
408 QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
409 mShadowSettings.writeXml( elemShadows, context );
410 elem.appendChild( elemShadows );
411
412 QDomElement elemAmbientOcclusion = doc.createElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
413 mAmbientOcclusionSettings.writeXml( elemAmbientOcclusion, context );
414 elem.appendChild( elemAmbientOcclusion );
415
416 QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
417 elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
418 elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
419 elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
420 elemDebug.setAttribute( QStringLiteral( "camera-rotation-center" ), mShowCameraRotationCenter ? 1 : 0 );
421 elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
422 elemDebug.setAttribute( QStringLiteral( "show-fps-counter" ), mIsFpsCounterEnabled ? 1 : 0 );
423 elem.appendChild( elemDebug );
424
425 QDomElement elemEyeDomeLighting = doc.createElement( QStringLiteral( "eye-dome-lighting" ) );
426 elemEyeDomeLighting.setAttribute( QStringLiteral( "enabled" ), mEyeDomeLightingEnabled ? 1 : 0 );
427 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-strength" ), mEyeDomeLightingStrength );
428 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-distance" ), mEyeDomeLightingDistance );
429 elem.appendChild( elemEyeDomeLighting );
430
431 QDomElement elemNavigationSync = doc.createElement( QStringLiteral( "navigation-sync" ) );
432 elemNavigationSync.setAttribute( QStringLiteral( "view-sync-mode" ), ( int )mViewSyncMode );
433 elemNavigationSync.setAttribute( QStringLiteral( "view-frustum-visualization-enabled" ), mVisualizeViewFrustum ? 1 : 0 );
434 elem.appendChild( elemNavigationSync );
435
436 QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
437 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
438 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
439 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
440 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
441 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
442 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
443 elem.appendChild( elemDebugSettings );
444
445 QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
446 elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
447 elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
448
449 QDomElement elem3dAxis = doc.createElement( QStringLiteral( "axis3d" ) );
450 m3dAxisSettings.writeXml( elem3dAxis, context );
451 elem.appendChild( elem3dAxis );
452
453 return elem;
454}
455
457{
459
460 for ( int i = 0; i < mLayers.count(); ++i )
461 {
462 QgsMapLayerRef &layerRef = mLayers[i];
463 layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
464 }
465
466 mTerrainGenerator->resolveReferences( project );
467}
468
475
477{
479
480 if ( extent == mExtent )
481 return;
482
483 mExtent = extent;
484 const QgsPointXY center = mExtent.center();
485 setOrigin( QgsVector3D( center.x(), center.y(), 0 ) );
486 if ( mTerrainGenerator )
487 {
488 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, mTerrainGenerator->crs(), mTransformContext );
489 mTerrainGenerator->setExtent( terrainExtent );
490 }
491 emit extentChanged();
492}
493
495{
497
498 mOrigin = origin;
499}
500
502{
504
505 return mOrigin;
506}
507
514
521
528
535
542
544{
546
547 mTransformContext = context;
548}
549
551{
553
554 return mPathResolver;
555}
556
558{
560
561 mPathResolver = resolver;
562}
563
570
572{
574
575 mMapThemes = mapThemes;
576}
577
578void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
579{
581
582 if ( color == mBackgroundColor )
583 return;
584
585 mBackgroundColor = color;
587}
588
590{
592
593 return mBackgroundColor;
594}
595
596void Qgs3DMapSettings::setSelectionColor( const QColor &color )
597{
599
600 if ( color == mSelectionColor )
601 return;
602
603 mSelectionColor = color;
605}
606
608{
610
611 return mSelectionColor;
612}
613
615{
617
618 if ( zScale == mTerrainVerticalScale )
619 return;
620
621 mTerrainVerticalScale = zScale;
623}
624
626{
628
629 return mTerrainVerticalScale;
630}
631
632void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
633{
635
636 QList<QgsMapLayerRef> lst;
637 lst.reserve( layers.count() );
638 for ( QgsMapLayer *layer : layers )
639 {
640 lst.append( layer );
641 }
642
643 if ( mLayers == lst )
644 return;
645
646 mLayers = lst;
647 emit layersChanged();
648}
649
650QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
651{
653
654 QList<QgsMapLayer *> lst;
655 lst.reserve( mLayers.count() );
656 for ( const QgsMapLayerRef &layerRef : mLayers )
657 {
658 if ( layerRef.layer )
659 lst.append( layerRef.layer );
660 }
661 return lst;
662}
663
665{
667
668 setExtent( fullExtent );
669 if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
670 {
672 flatTerrain->setCrs( crs() );
673 setTerrainGenerator( flatTerrain );
674
676 }
677 else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
678 {
679 QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast< QgsRasterDemTerrainProvider * >( properties->terrainProvider() );
680
682 demTerrainGen->setCrs( crs(), QgsProject::instance()->transformContext() );
683 demTerrainGen->setLayer( rasterProvider->layer() );
684 setTerrainGenerator( demTerrainGen );
685
688 }
689 else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
690 {
691 QgsMeshTerrainProvider *meshProvider = qgis::down_cast< QgsMeshTerrainProvider * >( properties->terrainProvider() );
692
693 QgsMeshTerrainGenerator *newTerrainGenerator = new QgsMeshTerrainGenerator;
694 newTerrainGenerator->setCrs( crs(), QgsProject::instance()->transformContext() );
695 newTerrainGenerator->setLayer( meshProvider->layer() );
696 std::unique_ptr< QgsMesh3DSymbol > symbol( newTerrainGenerator->symbol()->clone() );
697 symbol->setVerticalScale( properties->terrainProvider()->scale() );
698 newTerrainGenerator->setSymbol( symbol.release() );
699 setTerrainGenerator( newTerrainGenerator );
700
703 }
704 else
705 {
707 flatTerrain->setCrs( crs() );
708 setTerrainGenerator( flatTerrain );
709 }
710}
711
713{
715
716 if ( mMapTileResolution == res )
717 return;
718
719 mMapTileResolution = res;
721}
722
724{
726
727 return mMapTileResolution;
728}
729
731{
733
734 if ( mMaxTerrainScreenError == error )
735 return;
736
737 mMaxTerrainScreenError = error;
739}
740
742{
744
745 return mMaxTerrainScreenError;
746}
747
749{
751
752 if ( mMaxTerrainGroundError == error )
753 return;
754
755 mMaxTerrainGroundError = error;
757}
758
760{
762
763 if ( mTerrainElevationOffset == offset )
764 return;
765 mTerrainElevationOffset = offset;
766 emit terrainElevationOffsetChanged( mTerrainElevationOffset );
767}
768
770{
772
773 return mTerrainElevationOffset;
774}
775
777{
779
780 return mMaxTerrainGroundError;
781}
782
784{
786
787 if ( mTerrainGenerator )
788 {
789 disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
790 }
791
792 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, gen->crs(), mTransformContext );
793 gen->setExtent( terrainExtent );
794 mTerrainGenerator.reset( gen );
795 connect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
796
798}
799
801{
803
804 return mTerrainGenerator.get();
805}
806
808{
810
811 if ( mTerrainShadingEnabled == enabled )
812 return;
813
814 mTerrainShadingEnabled = enabled;
816}
817
819{
821
822 return mTerrainShadingEnabled;
823}
824
826{
828
829 if ( mTerrainShadingMaterial == material )
830 return;
831
832 mTerrainShadingMaterial = material;
834}
835
842
843void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
844{
846
847 if ( mTerrainMapTheme == theme )
848 return;
849
850 mTerrainMapTheme = theme;
852}
853
855{
857
858 return mTerrainMapTheme;
859}
860
862{
864
865 if ( mShowTerrainBoundingBoxes == enabled )
866 return;
867
868 mShowTerrainBoundingBoxes = enabled;
870}
871
873{
875
876 return mShowTerrainBoundingBoxes;
877}
878
879
881{
883
884 if ( mShowTerrainTileInfo == enabled )
885 return;
886
887 mShowTerrainTileInfo = enabled;
889}
890
892{
894
895 return mShowTerrainTileInfo;
896}
897
899{
901
902 if ( mShowCameraViewCenter == enabled )
903 return;
904
905 mShowCameraViewCenter = enabled;
907}
908
910{
912
913 return mShowCameraViewCenter;
914}
915
917{
919
920 if ( mShowCameraRotationCenter == enabled )
921 return;
922
923 mShowCameraRotationCenter = enabled;
925}
926
928{
930
931 return mShowCameraRotationCenter;
932}
933
935{
937
938 if ( mShowLightSources == enabled )
939 return;
940
941 mShowLightSources = enabled;
943}
944
946{
948
949 return mShowLightSources;
950}
951
953{
955
956 if ( mShowLabels == enabled )
957 return;
958
959 mShowLabels = enabled;
960 emit showLabelsChanged();
961}
962
964{
966
967 return mShowLabels;
968}
969
971{
973
974 if ( mEyeDomeLightingEnabled == enabled )
975 return;
976 mEyeDomeLightingEnabled = enabled;
978}
979
981{
983
984 return mEyeDomeLightingEnabled;
985}
986
988{
990
991 if ( mEyeDomeLightingStrength == strength )
992 return;
993 mEyeDomeLightingStrength = strength;
995}
996
998{
1000
1001 return mEyeDomeLightingStrength;
1002}
1003
1005{
1007
1008 if ( mEyeDomeLightingDistance == distance )
1009 return;
1010 mEyeDomeLightingDistance = distance;
1012}
1013
1015{
1017
1018 return mEyeDomeLightingDistance;
1019}
1020
1021QList<QgsLightSource *> Qgs3DMapSettings::lightSources() const
1022{
1024
1025 return mLightSources;
1026}
1027
1028void Qgs3DMapSettings::setLightSources( const QList<QgsLightSource *> &lights )
1029{
1031
1032 // have lights actually changed?
1033 if ( mLightSources.count() == lights.count() )
1034 {
1035 bool same = true;
1036 for ( int i = 0; i < mLightSources.count(); ++i )
1037 {
1038 if ( mLightSources[i]->type() == lights[i]->type() )
1039 {
1040 switch ( mLightSources[i]->type() )
1041 {
1043 if ( *static_cast< QgsPointLightSettings * >( mLightSources[i] ) == *static_cast< QgsPointLightSettings * >( lights[i] ) )
1044 continue;
1045 break;
1047 if ( *static_cast< QgsDirectionalLightSettings * >( mLightSources[i] ) == *static_cast< QgsDirectionalLightSettings * >( lights[i] ) )
1048 continue;
1049 break;
1050 }
1051 }
1052 same = false;
1053 break;
1054 }
1055 if ( same )
1056 {
1057 qDeleteAll( lights );
1058 return;
1059 }
1060 }
1061
1062 qDeleteAll( mLightSources );
1063 mLightSources = lights;
1064
1066 emit pointLightsChanged();
1067 emit lightSourcesChanged();
1068}
1069
1071{
1073
1074 return mFieldOfView;
1075}
1076
1077void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
1078{
1080
1081 if ( mFieldOfView == fieldOfView )
1082 return;
1083
1084 mFieldOfView = fieldOfView;
1085 emit fieldOfViewChanged();
1086}
1087
1088Qt3DRender::QCameraLens::ProjectionType Qgs3DMapSettings::projectionType() const
1089{
1091
1092 return mProjectionType;
1093}
1094
1095void Qgs3DMapSettings::setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType )
1096{
1098
1099 if ( mProjectionType == projectionType )
1100 return;
1101
1102 mProjectionType = projectionType;
1103 emit projectionTypeChanged();
1104}
1105
1107{
1109
1110 return mCameraNavigationMode;
1111}
1112
1114{
1116
1117 if ( mCameraNavigationMode == navigationMode )
1118 return;
1119
1120 mCameraNavigationMode = navigationMode;
1122}
1123
1125{
1127
1128 return mCameraMovementSpeed;
1129}
1130
1132{
1134
1135 if ( mCameraMovementSpeed == movementSpeed )
1136 return;
1137
1138 mCameraMovementSpeed = movementSpeed;
1140}
1141
1142void Qgs3DMapSettings::setOutputDpi( const double dpi )
1143{
1145
1146 mDpi = dpi;
1147}
1148
1150{
1152
1153 return mDpi;
1154}
1155
1157{
1159
1160 return mSkyboxSettings;
1161}
1162
1164{
1166
1167 return mShadowSettings;
1168}
1169
1171{
1173
1174 return mAmbientOcclusionSettings;
1175}
1176
1178{
1180
1181 mSkyboxSettings = skyboxSettings;
1182 emit skyboxSettingsChanged();
1183}
1184
1186{
1188
1189 mShadowSettings = shadowSettings;
1190 emit shadowSettingsChanged();
1191}
1192
1194{
1196
1197 mAmbientOcclusionSettings = ambientOcclusionSettings;
1199}
1200
1202{
1204
1205 return mIsSkyboxEnabled;
1206}
1207
1209{
1211
1212 mIsSkyboxEnabled = enabled;
1213}
1214
1216{
1218
1219 return mIsFpsCounterEnabled;
1220}
1221
1222void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size )
1223{
1225
1226 mDebugShadowMapEnabled = enabled;
1227 mDebugShadowMapCorner = corner;
1228 mDebugShadowMapSize = size;
1230}
1231
1233{
1235
1236 return mDebugShadowMapEnabled;
1237}
1238
1240{
1242
1243 return mDebugShadowMapCorner;
1244}
1245
1247{
1249
1250 return mDebugShadowMapSize;
1251}
1252
1253void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size )
1254{
1256
1257 mDebugDepthMapEnabled = enabled;
1258 mDebugDepthMapCorner = corner;
1259 mDebugDepthMapSize = size;
1261}
1262
1264{
1266
1267 return mDebugDepthMapEnabled;
1268}
1269
1271{
1273
1274 return mDebugDepthMapCorner;
1275}
1276
1278{
1280
1281 return mDebugDepthMapSize;
1282}
1283
1284void Qgs3DMapSettings::setIsFpsCounterEnabled( bool fpsCounterEnabled )
1285{
1287
1288 if ( fpsCounterEnabled == mIsFpsCounterEnabled )
1289 return;
1290 mIsFpsCounterEnabled = fpsCounterEnabled;
1291 emit fpsCounterEnabledChanged( mIsFpsCounterEnabled );
1292}
1293
1295{
1297
1298 return mTerrainRenderingEnabled;
1299}
1300
1301void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled )
1302{
1304
1305 if ( terrainRenderingEnabled == mTerrainRenderingEnabled )
1306 return;
1307 mTerrainRenderingEnabled = terrainRenderingEnabled;
1309}
1310
1312{
1314
1315 return mRendererUsage;
1316}
1317
1319{
1321
1322 mRendererUsage = rendererUsage;
1323}
1324
1331
1333{
1335
1336 mViewSyncMode = mode;
1337}
1338
1340{
1342
1343 return mVisualizeViewFrustum;
1344}
1345
1347{
1349
1350 if ( mVisualizeViewFrustum != enabled )
1351 {
1352 mVisualizeViewFrustum = enabled;
1354 }
1355}
1356
1358{
1360
1361 return m3dAxisSettings;
1362}
1363
1364void Qgs3DMapSettings::setIsDebugOverlayEnabled( bool debugOverlayEnabled )
1365{
1367
1368 if ( debugOverlayEnabled == mIsDebugOverlayEnabled )
1369 return;
1370
1371 mIsDebugOverlayEnabled = debugOverlayEnabled;
1372 emit debugOverlayEnabledChanged( mIsDebugOverlayEnabled );
1373}
1374
1376{
1378
1379 return mShowExtentIn2DView;
1380}
1381
1382void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
1383{
1385
1419}
1420
1421
1422void Qgs3DMapSettings::set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force )
1423{
1425
1426 if ( axisSettings == m3dAxisSettings )
1427 {
1428 if ( force )
1429 {
1430 // ie. refresh. We need to disconnect and to reconnect to avoid 'dirty' project
1432 emit axisSettingsChanged();
1434 }
1435 }
1436 else
1437 {
1438 m3dAxisSettings = axisSettings;
1439 emit axisSettingsChanged();
1440 }
1441}
1442
1444{
1446
1447 return mIsDebugOverlayEnabled;
1448}
1449
1451{
1453
1454 if ( show == mShowExtentIn2DView )
1455 return;
1456
1457 mShowExtentIn2DView = show;
1459}
QFlags< ViewSyncModeFlag > ViewSyncModeFlags
Definition qgis.h:3088
NavigationMode
The navigation mode used by 3D cameras.
Definition qgis.h:3726
@ 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:3070
@ 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 and turns (x,y,z) into (x,...
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,...
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 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.
Base class for all map layer types.
Definition qgsmaplayer.h:76
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)
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
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.
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.