QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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"
26#include "qgsterrainprovider.h"
27#include "qgslightsource.h"
28#include "qgscolorutils.h"
29#include "qgsrasterlayer.h"
32#include "qgs3drendercontext.h"
33#include "qgsthreadingutils.h"
35
36#include <QDomDocument>
37#include <QDomElement>
38
39
41 : QObject( nullptr )
42{
43 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
44 {
46 } );
47 connectChangedSignalsToSettingsChanged();
48}
49
51 : QObject( nullptr )
52 , QgsTemporalRangeObject( other )
53 , mOrigin( other.mOrigin )
54 , mCrs( other.mCrs )
55 , mBackgroundColor( other.mBackgroundColor )
56 , mSelectionColor( other.mSelectionColor )
57 , mTerrainVerticalScale( other.mTerrainVerticalScale )
58 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
59 , mMapTileResolution( other.mMapTileResolution )
60 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
61 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
62 , mTerrainElevationOffset( other.mTerrainElevationOffset )
63 , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
64 , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
65 , mTerrainMapTheme( other.mTerrainMapTheme )
66 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
67 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
68 , mShowCameraViewCenter( other.mShowCameraViewCenter )
69 , mShowCameraRotationCenter( other.mShowCameraRotationCenter )
70 , mShowLightSources( other.mShowLightSources )
71 , mShowLabels( other.mShowLabels )
72 , mFieldOfView( other.mFieldOfView )
73 , mProjectionType( other.mProjectionType )
74 , mCameraNavigationMode( other.mCameraNavigationMode )
75 , mCameraMovementSpeed( other.mCameraMovementSpeed )
76 , mLayers( other.mLayers )
77 , mTransformContext( other.mTransformContext )
78 , mPathResolver( other.mPathResolver )
79 , mMapThemes( other.mMapThemes )
80 , mDpi( other.mDpi )
81 , mIsFpsCounterEnabled( other.mIsFpsCounterEnabled )
82 , mIsSkyboxEnabled( other.mIsSkyboxEnabled )
83 , mSkyboxSettings( other.mSkyboxSettings )
84 , mShadowSettings( other.mShadowSettings )
85 , mAmbientOcclusionSettings( other.mAmbientOcclusionSettings )
86 , mEyeDomeLightingEnabled( other.mEyeDomeLightingEnabled )
87 , mEyeDomeLightingStrength( other.mEyeDomeLightingStrength )
88 , mEyeDomeLightingDistance( other.mEyeDomeLightingDistance )
89 , mViewSyncMode( other.mViewSyncMode )
90 , mVisualizeViewFrustum( other.mVisualizeViewFrustum )
91 , mDebugShadowMapEnabled( other.mDebugShadowMapEnabled )
92 , mDebugShadowMapCorner( other.mDebugShadowMapCorner )
93 , mDebugShadowMapSize( other.mDebugShadowMapSize )
94 , mDebugDepthMapEnabled( other.mDebugDepthMapEnabled )
95 , mDebugDepthMapCorner( other.mDebugDepthMapCorner )
96 , mDebugDepthMapSize( other.mDebugDepthMapSize )
97 , mTerrainRenderingEnabled( other.mTerrainRenderingEnabled )
98 , mRendererUsage( other.mRendererUsage )
99 , m3dAxisSettings( other.m3dAxisSettings )
100 , mIsDebugOverlayEnabled( other.mIsDebugOverlayEnabled )
101 , mExtent( other.mExtent )
102 , mShowExtentIn2DView( other.mShowExtentIn2DView )
103{
104 for ( QgsLightSource *source : std::as_const( other.mLightSources ) )
105 {
106 if ( source )
107 mLightSources << source->clone();
108 }
109
110 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
111 {
113 } );
114 connectChangedSignalsToSettingsChanged();
115}
116
118{
119 qDeleteAll( mLightSources );
120}
121
122void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
123{
125
127 QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
128 mOrigin = QgsVector3D(
129 elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
130 elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
131 elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
132
133 QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
134 if ( !elemExtent.isNull() )
135 {
136 mExtent = QgsRectangle(
137 elemExtent.attribute( QStringLiteral( "xMin" ) ).toDouble(),
138 elemExtent.attribute( QStringLiteral( "yMin" ) ).toDouble(),
139 elemExtent.attribute( QStringLiteral( "xMax" ) ).toDouble(),
140 elemExtent.attribute( QStringLiteral( "yMax" ) ).toDouble() );
141
142 mShowExtentIn2DView = elemExtent.attribute( QStringLiteral( "showIn2dView" ), QStringLiteral( "0" ) ).toInt();
143 }
144 else
145 {
147 }
148
149 QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
150 if ( !elemCamera.isNull() )
151 {
152 mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
153 mProjectionType = static_cast< Qt3DRender::QCameraLens::ProjectionType >( elemCamera.attribute( QStringLiteral( "projection-type" ), QStringLiteral( "1" ) ).toInt() );
154 QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
155 if ( cameraNavigationMode == QLatin1String( "terrain-based-navigation" ) )
156 mCameraNavigationMode = Qgis::NavigationMode::TerrainBased;
157 else if ( cameraNavigationMode == QLatin1String( "walk-navigation" ) )
158 mCameraNavigationMode = Qgis::NavigationMode::Walk;
159 mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
160 }
161
162 QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
163 if ( !elemColor.isNull() )
164 {
165 mBackgroundColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "background" ) ) );
166 mSelectionColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "selection" ) ) );
167 }
168
169 QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
170 mCrs.readXml( elemCrs );
171
172 QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
173 mTerrainRenderingEnabled = elemTerrain.attribute( QStringLiteral( "terrain-rendering-enabled" ), QStringLiteral( "1" ) ).toInt();
174 mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
175 mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
176 mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
177 mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
178 mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
179 mTerrainElevationOffset = elemTerrain.attribute( QStringLiteral( "elevation-offset" ), QStringLiteral( "0.0" ) ).toFloat();
180
181 QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
182 if ( !elemTerrainShadingMaterial.isNull() )
183 mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
184 mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
185 mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
186
187 qDeleteAll( mLightSources );
188 mLightSources.clear();
189 const QDomElement lightsElem = elem.firstChildElement( QStringLiteral( "lights" ) );
190 if ( !lightsElem.isNull() )
191 {
192 const QDomNodeList lightNodes = lightsElem.childNodes();
193 for ( int i = 0; i < lightNodes.size(); ++i )
194 {
195 const QDomElement lightElement = lightNodes.at( i ).toElement();
196 if ( QgsLightSource *light = QgsLightSource::createFromXml( lightElement, context ) )
197 mLightSources << light;
198 }
199 }
200 else
201 {
202 // older project format
203 QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
204 if ( !elemPointLights.isNull() )
205 {
206 QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
207 while ( !elemPointLight.isNull() )
208 {
209 std::unique_ptr< QgsPointLightSettings > pointLight = std::make_unique< QgsPointLightSettings >();
210 pointLight->readXml( elemPointLight, context );
211 mLightSources << pointLight.release();
212 elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
213 }
214 }
215 else
216 {
217 // QGIS <= 3.4 did not have light configuration
218 std::unique_ptr< QgsPointLightSettings > defaultLight = std::make_unique< QgsPointLightSettings >();
219 defaultLight->setPosition( QgsVector3D( 0, 1000, 0 ) );
220 mLightSources << defaultLight.release();
221 }
222
223 QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
224 if ( !elemDirectionalLights.isNull() )
225 {
226 QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
227 while ( !elemDirectionalLight.isNull() )
228 {
229 std::unique_ptr< QgsDirectionalLightSettings > directionalLight = std::make_unique< QgsDirectionalLightSettings >();
230 directionalLight->readXml( elemDirectionalLight, context );
231 mLightSources << directionalLight.release();
232 elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
233 }
234 }
235 }
236
237 QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
238 QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
239 QList<QgsMapLayerRef> mapLayers;
240 while ( !elemMapLayer.isNull() )
241 {
242 mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
243 elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
244 }
245 mLayers = mapLayers; // needs to resolve refs afterwards
246
247 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
248 QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
249 if ( terrainGenType == QLatin1String( "dem" ) )
250 {
251 QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
252 demTerrainGenerator->setCrs( mCrs, mTransformContext );
253 setTerrainGenerator( demTerrainGenerator );
254 }
255 else if ( terrainGenType == QLatin1String( "online" ) )
256 {
257 QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
258 onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
259 setTerrainGenerator( onlineTerrainGenerator );
260 }
261 else if ( terrainGenType == QLatin1String( "mesh" ) )
262 {
263 QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
264 meshTerrainGenerator->setCrs( mCrs, mTransformContext );
265 setTerrainGenerator( meshTerrainGenerator );
266 }
267 else if ( terrainGenType == QLatin1String( "quantizedmesh" ) )
268 {
270 setTerrainGenerator( qmTerrainGenerator );
271 }
272 else // "flat"
273 {
275 flatGen->setCrs( mCrs );
276 setTerrainGenerator( flatGen );
277 }
278 mTerrainGenerator->readXml( elemTerrainGenerator );
279
280 QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
281 mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
282 mSkyboxSettings.readXml( elemSkybox, context );
283
284 QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
285 mShadowSettings.readXml( elemShadows, context );
286
287 QDomElement elemAmbientOcclusion = elem.firstChildElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
288 mAmbientOcclusionSettings.readXml( elemAmbientOcclusion, context );
289
290 QDomElement elemEyeDomeLighting = elem.firstChildElement( QStringLiteral( "eye-dome-lighting" ) );
291 mEyeDomeLightingEnabled = elemEyeDomeLighting.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
292 mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
293 mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();
294
295 QDomElement elemNavigationSync = elem.firstChildElement( QStringLiteral( "navigation-sync" ) );
296 mViewSyncMode = ( Qgis::ViewSyncModeFlags )( elemNavigationSync.attribute( QStringLiteral( "view-sync-mode" ), QStringLiteral( "0" ) ).toInt() );
297 mVisualizeViewFrustum = elemNavigationSync.attribute( QStringLiteral( "view-frustum-visualization-enabled" ), QStringLiteral( "0" ) ).toInt();
298
299 QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
300 mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
301 mDebugShadowMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), "0" ).toInt() );
302 mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
303
304 mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
305 mDebugDepthMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "1" ) ).toInt() );
306 mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
307
308 QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
309 mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
310 mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
311 mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
312 mShowCameraRotationCenter = elemDebug.attribute( QStringLiteral( "camera-rotation-center" ), QStringLiteral( "0" ) ).toInt();
313 mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
314 mIsFpsCounterEnabled = elemDebug.attribute( QStringLiteral( "show-fps-counter" ), QStringLiteral( "0" ) ).toInt();
315
316 QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
317 QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
318 QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
319 setTemporalRange( QgsDateTimeRange( start, end ) );
320
321 QDomElement elem3dAxis = elem.firstChildElement( QStringLiteral( "axis3d" ) );
322 m3dAxisSettings.readXml( elem3dAxis, context );
323
324}
325
326QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
327{
329
330 QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
331
332 QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
333 elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
334 elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
335 elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
336 elem.appendChild( elemOrigin );
337
338 QDomElement elemExtent = doc.createElement( QStringLiteral( "extent" ) );
339 elemExtent.setAttribute( QStringLiteral( "xMin" ), mExtent.xMinimum() );
340 elemExtent.setAttribute( QStringLiteral( "yMin" ), mExtent.yMinimum() );
341 elemExtent.setAttribute( QStringLiteral( "xMax" ), mExtent.xMaximum() );
342 elemExtent.setAttribute( QStringLiteral( "yMax" ), mExtent.yMaximum() );
343 elemExtent.setAttribute( QStringLiteral( "showIn2dView" ), mShowExtentIn2DView );
344 elem.appendChild( elemExtent );
345
346 QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
347 elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
348 elemCamera.setAttribute( QStringLiteral( "projection-type" ), static_cast< int >( mProjectionType ) );
349 switch ( mCameraNavigationMode )
350 {
352 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
353 break;
355 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
356 break;
357 }
358 elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
359 elem.appendChild( elemCamera );
360
361 QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
362 elemColor.setAttribute( QStringLiteral( "background" ), QgsColorUtils::colorToString( mBackgroundColor ) );
363 elemColor.setAttribute( QStringLiteral( "selection" ), QgsColorUtils::colorToString( mSelectionColor ) );
364 elem.appendChild( elemColor );
365
366 QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
367 mCrs.writeXml( elemCrs, doc );
368 elem.appendChild( elemCrs );
369
370 QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
371 elemTerrain.setAttribute( QStringLiteral( "terrain-rendering-enabled" ), mTerrainRenderingEnabled ? 1 : 0 );
372 elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
373 elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
374 elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
375 elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
376 elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
377 elemTerrain.setAttribute( QStringLiteral( "elevation-offset" ), mTerrainElevationOffset );
378
379 QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
380 mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
381 elemTerrain.appendChild( elemTerrainShadingMaterial );
382 elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
383 elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
384
385 {
386 QDomElement elemLights = doc.createElement( QStringLiteral( "lights" ) );
387 for ( const QgsLightSource *light : mLightSources )
388 {
389 const QDomElement elemLight = light->writeXml( doc, context );
390 elemLights.appendChild( elemLight );
391 }
392 elem.appendChild( elemLights );
393 }
394
395 QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
396 for ( const QgsMapLayerRef &layerRef : mLayers )
397 {
398 QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
399 elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
400 elemMapLayers.appendChild( elemMapLayer );
401 }
402 elemTerrain.appendChild( elemMapLayers );
403
404 QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
405 elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
406 mTerrainGenerator->writeXml( elemTerrainGenerator );
407 elemTerrain.appendChild( elemTerrainGenerator );
408 elem.appendChild( elemTerrain );
409
410 QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
411 elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
412 mSkyboxSettings.writeXml( elemSkybox, context );
413 elem.appendChild( elemSkybox );
414
415 QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
416 mShadowSettings.writeXml( elemShadows, context );
417 elem.appendChild( elemShadows );
418
419 QDomElement elemAmbientOcclusion = doc.createElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
420 mAmbientOcclusionSettings.writeXml( elemAmbientOcclusion, context );
421 elem.appendChild( elemAmbientOcclusion );
422
423 QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
424 elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
425 elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
426 elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
427 elemDebug.setAttribute( QStringLiteral( "camera-rotation-center" ), mShowCameraRotationCenter ? 1 : 0 );
428 elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
429 elemDebug.setAttribute( QStringLiteral( "show-fps-counter" ), mIsFpsCounterEnabled ? 1 : 0 );
430 elem.appendChild( elemDebug );
431
432 QDomElement elemEyeDomeLighting = doc.createElement( QStringLiteral( "eye-dome-lighting" ) );
433 elemEyeDomeLighting.setAttribute( QStringLiteral( "enabled" ), mEyeDomeLightingEnabled ? 1 : 0 );
434 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-strength" ), mEyeDomeLightingStrength );
435 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-distance" ), mEyeDomeLightingDistance );
436 elem.appendChild( elemEyeDomeLighting );
437
438 QDomElement elemNavigationSync = doc.createElement( QStringLiteral( "navigation-sync" ) );
439 elemNavigationSync.setAttribute( QStringLiteral( "view-sync-mode" ), ( int )mViewSyncMode );
440 elemNavigationSync.setAttribute( QStringLiteral( "view-frustum-visualization-enabled" ), mVisualizeViewFrustum ? 1 : 0 );
441 elem.appendChild( elemNavigationSync );
442
443 QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
444 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
445 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
446 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
447 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
448 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
449 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
450 elem.appendChild( elemDebugSettings );
451
452 QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
453 elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
454 elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
455
456 QDomElement elem3dAxis = doc.createElement( QStringLiteral( "axis3d" ) );
457 m3dAxisSettings.writeXml( elem3dAxis, context );
458 elem.appendChild( elem3dAxis );
459
460 return elem;
461}
462
464{
466
467 for ( int i = 0; i < mLayers.count(); ++i )
468 {
469 QgsMapLayerRef &layerRef = mLayers[i];
470 layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
471 }
472
473 mTerrainGenerator->resolveReferences( project );
474
475 // Set extent now that layer-based generators actually have a chance to know their CRS
476 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, mTerrainGenerator->crs(), mTransformContext );
477 mTerrainGenerator->setExtent( terrainExtent );
478}
479
486
488{
490
491 if ( extent == mExtent )
492 return;
493
494 mExtent = extent;
495 const QgsPointXY center = mExtent.center();
496 setOrigin( QgsVector3D( center.x(), center.y(), 0 ) );
497 if ( mTerrainGenerator )
498 {
499 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, mTerrainGenerator->crs(), mTransformContext );
500 mTerrainGenerator->setExtent( terrainExtent );
501 }
502 emit extentChanged();
503}
504
506{
508
509 mOrigin = origin;
510}
511
513{
515
516 return mOrigin;
517}
518
525
532
539
546
553
555{
557
558 mTransformContext = context;
559}
560
562{
564
565 return mPathResolver;
566}
567
569{
571
572 mPathResolver = resolver;
573}
574
581
583{
585
586 mMapThemes = mapThemes;
587}
588
589void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
590{
592
593 if ( color == mBackgroundColor )
594 return;
595
596 mBackgroundColor = color;
598}
599
601{
603
604 return mBackgroundColor;
605}
606
607void Qgs3DMapSettings::setSelectionColor( const QColor &color )
608{
610
611 if ( color == mSelectionColor )
612 return;
613
614 mSelectionColor = color;
616}
617
619{
621
622 return mSelectionColor;
623}
624
626{
628
629 if ( zScale == mTerrainVerticalScale )
630 return;
631
632 mTerrainVerticalScale = zScale;
634}
635
637{
639
640 return mTerrainVerticalScale;
641}
642
643void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
644{
646
647 const QList<QgsMapLayer *> raw = _qgis_listRefToRaw( mLayers );
648
649 if ( layers == raw )
650 return;
651
652 mLayers = _qgis_listRawToRef( layers );
653 emit layersChanged();
654}
655
656QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
657{
659
660 QList<QgsMapLayer *> lst;
661 lst.reserve( mLayers.count() );
662 for ( const QgsMapLayerRef &layerRef : mLayers )
663 {
664 if ( layerRef.layer )
665 lst.append( layerRef.layer );
666 }
667 return lst;
668}
669
671{
673
674 setExtent( fullExtent );
675 if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
676 {
678 flatTerrain->setCrs( crs() );
679 setTerrainGenerator( flatTerrain );
680
682 }
683 else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
684 {
685 QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast< QgsRasterDemTerrainProvider * >( properties->terrainProvider() );
686
688 demTerrainGen->setCrs( crs(), QgsProject::instance()->transformContext() );
689 demTerrainGen->setLayer( rasterProvider->layer() );
690 setTerrainGenerator( demTerrainGen );
691
694 }
695 else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
696 {
697 QgsMeshTerrainProvider *meshProvider = qgis::down_cast< QgsMeshTerrainProvider * >( properties->terrainProvider() );
698
699 QgsMeshTerrainGenerator *newTerrainGenerator = new QgsMeshTerrainGenerator;
700 newTerrainGenerator->setCrs( crs(), QgsProject::instance()->transformContext() );
701 newTerrainGenerator->setLayer( meshProvider->layer() );
702 std::unique_ptr< QgsMesh3DSymbol > symbol( newTerrainGenerator->symbol()->clone() );
703 symbol->setVerticalScale( properties->terrainProvider()->scale() );
704 newTerrainGenerator->setSymbol( symbol.release() );
705 setTerrainGenerator( newTerrainGenerator );
706
709 }
710 else
711 {
713 flatTerrain->setCrs( crs() );
714 setTerrainGenerator( flatTerrain );
715 }
716}
717
719{
721
722 if ( mMapTileResolution == res )
723 return;
724
725 mMapTileResolution = res;
727}
728
730{
732
733 return mMapTileResolution;
734}
735
737{
739
740 if ( mMaxTerrainScreenError == error )
741 return;
742
743 mMaxTerrainScreenError = error;
745}
746
748{
750
751 return mMaxTerrainScreenError;
752}
753
755{
757
758 if ( mMaxTerrainGroundError == error )
759 return;
760
761 mMaxTerrainGroundError = error;
763}
764
766{
768
769 if ( mTerrainElevationOffset == offset )
770 return;
771 mTerrainElevationOffset = offset;
772 emit terrainElevationOffsetChanged( mTerrainElevationOffset );
773}
774
776{
778
779 return mTerrainElevationOffset;
780}
781
783{
785
786 return mMaxTerrainGroundError;
787}
788
790{
792
793 if ( mTerrainGenerator )
794 {
795 disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
796 }
797
798 if ( gen->crs().isValid() ) // Don't bother setting an extent rect in the wrong CRS
799 {
800 QgsRectangle terrainExtent = Qgs3DUtils::tryReprojectExtent2D( mExtent, mCrs, gen->crs(), mTransformContext );
801 gen->setExtent( terrainExtent );
802 }
803 mTerrainGenerator.reset( gen );
804 connect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
805
807}
808
810{
812
813 return mTerrainGenerator.get();
814}
815
817{
819
820 if ( mTerrainShadingEnabled == enabled )
821 return;
822
823 mTerrainShadingEnabled = enabled;
825}
826
828{
830
831 return mTerrainShadingEnabled;
832}
833
835{
837
838 if ( mTerrainShadingMaterial == material )
839 return;
840
841 mTerrainShadingMaterial = material;
843}
844
851
852void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
853{
855
856 if ( mTerrainMapTheme == theme )
857 return;
858
859 mTerrainMapTheme = theme;
861}
862
864{
866
867 return mTerrainMapTheme;
868}
869
871{
873
874 if ( mShowTerrainBoundingBoxes == enabled )
875 return;
876
877 mShowTerrainBoundingBoxes = enabled;
879}
880
882{
884
885 return mShowTerrainBoundingBoxes;
886}
887
888
890{
892
893 if ( mShowTerrainTileInfo == enabled )
894 return;
895
896 mShowTerrainTileInfo = enabled;
898}
899
901{
903
904 return mShowTerrainTileInfo;
905}
906
908{
910
911 if ( mShowCameraViewCenter == enabled )
912 return;
913
914 mShowCameraViewCenter = enabled;
916}
917
919{
921
922 return mShowCameraViewCenter;
923}
924
926{
928
929 if ( mShowCameraRotationCenter == enabled )
930 return;
931
932 mShowCameraRotationCenter = enabled;
934}
935
937{
939
940 return mShowCameraRotationCenter;
941}
942
944{
946
947 if ( mShowLightSources == enabled )
948 return;
949
950 mShowLightSources = enabled;
952}
953
955{
957
958 return mShowLightSources;
959}
960
962{
964
965 if ( mShowLabels == enabled )
966 return;
967
968 mShowLabels = enabled;
969 emit showLabelsChanged();
970}
971
973{
975
976 return mShowLabels;
977}
978
980{
982
983 if ( mEyeDomeLightingEnabled == enabled )
984 return;
985 mEyeDomeLightingEnabled = enabled;
987}
988
990{
992
993 return mEyeDomeLightingEnabled;
994}
995
997{
999
1000 if ( mEyeDomeLightingStrength == strength )
1001 return;
1002 mEyeDomeLightingStrength = strength;
1004}
1005
1007{
1009
1010 return mEyeDomeLightingStrength;
1011}
1012
1014{
1016
1017 if ( mEyeDomeLightingDistance == distance )
1018 return;
1019 mEyeDomeLightingDistance = distance;
1021}
1022
1024{
1026
1027 return mEyeDomeLightingDistance;
1028}
1029
1030QList<QgsLightSource *> Qgs3DMapSettings::lightSources() const
1031{
1033
1034 return mLightSources;
1035}
1036
1037void Qgs3DMapSettings::setLightSources( const QList<QgsLightSource *> &lights )
1038{
1040
1041 // have lights actually changed?
1042 if ( mLightSources.count() == lights.count() )
1043 {
1044 bool same = true;
1045 for ( int i = 0; i < mLightSources.count(); ++i )
1046 {
1047 if ( mLightSources[i]->type() == lights[i]->type() )
1048 {
1049 switch ( mLightSources[i]->type() )
1050 {
1052 if ( *static_cast< QgsPointLightSettings * >( mLightSources[i] ) == *static_cast< QgsPointLightSettings * >( lights[i] ) )
1053 continue;
1054 break;
1056 if ( *static_cast< QgsDirectionalLightSettings * >( mLightSources[i] ) == *static_cast< QgsDirectionalLightSettings * >( lights[i] ) )
1057 continue;
1058 break;
1059 }
1060 }
1061 same = false;
1062 break;
1063 }
1064 if ( same )
1065 {
1066 qDeleteAll( lights );
1067 return;
1068 }
1069 }
1070
1071 qDeleteAll( mLightSources );
1072 mLightSources = lights;
1073
1075 emit pointLightsChanged();
1076 emit lightSourcesChanged();
1077}
1078
1080{
1082
1083 return mFieldOfView;
1084}
1085
1086void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
1087{
1089
1090 if ( mFieldOfView == fieldOfView )
1091 return;
1092
1093 mFieldOfView = fieldOfView;
1094 emit fieldOfViewChanged();
1095}
1096
1097Qt3DRender::QCameraLens::ProjectionType Qgs3DMapSettings::projectionType() const
1098{
1100
1101 return mProjectionType;
1102}
1103
1104void Qgs3DMapSettings::setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType )
1105{
1107
1108 if ( mProjectionType == projectionType )
1109 return;
1110
1111 mProjectionType = projectionType;
1112 emit projectionTypeChanged();
1113}
1114
1116{
1118
1119 return mCameraNavigationMode;
1120}
1121
1123{
1125
1126 if ( mCameraNavigationMode == navigationMode )
1127 return;
1128
1129 mCameraNavigationMode = navigationMode;
1131}
1132
1134{
1136
1137 return mCameraMovementSpeed;
1138}
1139
1141{
1143
1144 if ( mCameraMovementSpeed == movementSpeed )
1145 return;
1146
1147 mCameraMovementSpeed = movementSpeed;
1149}
1150
1151void Qgs3DMapSettings::setOutputDpi( const double dpi )
1152{
1154
1155 mDpi = dpi;
1156}
1157
1159{
1161
1162 return mDpi;
1163}
1164
1166{
1168
1169 return mSkyboxSettings;
1170}
1171
1173{
1175
1176 return mShadowSettings;
1177}
1178
1180{
1182
1183 return mAmbientOcclusionSettings;
1184}
1185
1187{
1189
1190 mSkyboxSettings = skyboxSettings;
1191 emit skyboxSettingsChanged();
1192}
1193
1195{
1197
1198 mShadowSettings = shadowSettings;
1199 emit shadowSettingsChanged();
1200}
1201
1203{
1205
1206 mAmbientOcclusionSettings = ambientOcclusionSettings;
1208}
1209
1211{
1213
1214 return mIsSkyboxEnabled;
1215}
1216
1218{
1220
1221 mIsSkyboxEnabled = enabled;
1222}
1223
1225{
1227
1228 return mIsFpsCounterEnabled;
1229}
1230
1231void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size )
1232{
1234
1235 mDebugShadowMapEnabled = enabled;
1236 mDebugShadowMapCorner = corner;
1237 mDebugShadowMapSize = size;
1239}
1240
1242{
1244
1245 return mDebugShadowMapEnabled;
1246}
1247
1249{
1251
1252 return mDebugShadowMapCorner;
1253}
1254
1256{
1258
1259 return mDebugShadowMapSize;
1260}
1261
1262void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size )
1263{
1265
1266 mDebugDepthMapEnabled = enabled;
1267 mDebugDepthMapCorner = corner;
1268 mDebugDepthMapSize = size;
1270}
1271
1273{
1275
1276 return mDebugDepthMapEnabled;
1277}
1278
1280{
1282
1283 return mDebugDepthMapCorner;
1284}
1285
1287{
1289
1290 return mDebugDepthMapSize;
1291}
1292
1293void Qgs3DMapSettings::setIsFpsCounterEnabled( bool fpsCounterEnabled )
1294{
1296
1297 if ( fpsCounterEnabled == mIsFpsCounterEnabled )
1298 return;
1299 mIsFpsCounterEnabled = fpsCounterEnabled;
1300 emit fpsCounterEnabledChanged( mIsFpsCounterEnabled );
1301}
1302
1304{
1306
1307 return mTerrainRenderingEnabled;
1308}
1309
1310void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled )
1311{
1313
1314 if ( terrainRenderingEnabled == mTerrainRenderingEnabled )
1315 return;
1316 mTerrainRenderingEnabled = terrainRenderingEnabled;
1318}
1319
1321{
1323
1324 return mRendererUsage;
1325}
1326
1328{
1330
1331 mRendererUsage = rendererUsage;
1332}
1333
1340
1342{
1344
1345 mViewSyncMode = mode;
1346}
1347
1349{
1351
1352 return mVisualizeViewFrustum;
1353}
1354
1356{
1358
1359 if ( mVisualizeViewFrustum != enabled )
1360 {
1361 mVisualizeViewFrustum = enabled;
1363 }
1364}
1365
1367{
1369
1370 return m3dAxisSettings;
1371}
1372
1373void Qgs3DMapSettings::setIsDebugOverlayEnabled( bool debugOverlayEnabled )
1374{
1376
1377 if ( debugOverlayEnabled == mIsDebugOverlayEnabled )
1378 return;
1379
1380 mIsDebugOverlayEnabled = debugOverlayEnabled;
1381 emit debugOverlayEnabledChanged( mIsDebugOverlayEnabled );
1382}
1383
1385{
1387
1388 return mShowExtentIn2DView;
1389}
1390
1391void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
1392{
1394
1428}
1429
1430
1431void Qgs3DMapSettings::set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force )
1432{
1434
1435 if ( axisSettings == m3dAxisSettings )
1436 {
1437 if ( force )
1438 {
1439 // ie. refresh. We need to disconnect and to reconnect to avoid 'dirty' project
1441 emit axisSettingsChanged();
1443 }
1444 }
1445 else
1446 {
1447 m3dAxisSettings = axisSettings;
1448 emit axisSettingsChanged();
1449 }
1450}
1451
1453{
1455
1456 return mIsDebugOverlayEnabled;
1457}
1458
1460{
1462
1463 if ( show == mShowExtentIn2DView )
1464 return;
1465
1466 mShowExtentIn2DView = show;
1468}
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 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 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.