QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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"
28#include "qgsterrainprovider.h"
29#include "qgslightsource.h"
30#include "qgssymbollayerutils.h"
31#include "qgsrasterlayer.h"
34
35#include <QDomDocument>
36#include <QDomElement>
37
38
40 : QObject( nullptr )
41{
42 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
43 {
45 } );
46 connectChangedSignalsToSettingsChanged();
47}
48
50 : QObject( nullptr )
51 , QgsTemporalRangeObject( other )
52 , mOrigin( other.mOrigin )
53 , mCrs( other.mCrs )
54 , mBackgroundColor( other.mBackgroundColor )
55 , mSelectionColor( other.mSelectionColor )
56 , mTerrainVerticalScale( other.mTerrainVerticalScale )
57 , mTerrainGenerator( other.mTerrainGenerator ? other.mTerrainGenerator->clone() : nullptr )
58 , mMapTileResolution( other.mMapTileResolution )
59 , mMaxTerrainScreenError( other.mMaxTerrainScreenError )
60 , mMaxTerrainGroundError( other.mMaxTerrainGroundError )
61 , mTerrainElevationOffset( other.mTerrainElevationOffset )
62 , mTerrainShadingEnabled( other.mTerrainShadingEnabled )
63 , mTerrainShadingMaterial( other.mTerrainShadingMaterial )
64 , mTerrainMapTheme( other.mTerrainMapTheme )
65 , mShowTerrainBoundingBoxes( other.mShowTerrainBoundingBoxes )
66 , mShowTerrainTileInfo( other.mShowTerrainTileInfo )
67 , mShowCameraViewCenter( other.mShowCameraViewCenter )
68 , mShowCameraRotationCenter( other.mShowCameraRotationCenter )
69 , mShowLightSources( other.mShowLightSources )
70 , mShowLabels( other.mShowLabels )
71 , mFieldOfView( other.mFieldOfView )
72 , mProjectionType( other.mProjectionType )
73 , mCameraNavigationMode( other.mCameraNavigationMode )
74 , mCameraMovementSpeed( other.mCameraMovementSpeed )
75 , mLayers( other.mLayers )
76 , mRenderers() // initialized in body
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{
103 for ( QgsAbstract3DRenderer *renderer : std::as_const( other.mRenderers ) )
104 {
105 mRenderers << renderer->clone();
106 }
107
108 for ( QgsLightSource *source : std::as_const( other.mLightSources ) )
109 {
110 if ( source )
111 mLightSources << source->clone();
112 }
113
114 connect( this, &Qgs3DMapSettings::settingsChanged, [&]()
115 {
117 } );
118 connectChangedSignalsToSettingsChanged();
119}
120
122{
123 qDeleteAll( mRenderers );
124 qDeleteAll( mLightSources );
125}
126
127void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
128{
130 QDomElement elemOrigin = elem.firstChildElement( QStringLiteral( "origin" ) );
131 mOrigin = QgsVector3D(
132 elemOrigin.attribute( QStringLiteral( "x" ) ).toDouble(),
133 elemOrigin.attribute( QStringLiteral( "y" ) ).toDouble(),
134 elemOrigin.attribute( QStringLiteral( "z" ) ).toDouble() );
135
136 QDomElement elemExtent = elem.firstChildElement( QStringLiteral( "extent" ) );
137 if ( !elemExtent.isNull() )
138 {
139 mExtent = QgsRectangle(
140 elemExtent.attribute( QStringLiteral( "xMin" ) ).toDouble(),
141 elemExtent.attribute( QStringLiteral( "yMin" ) ).toDouble(),
142 elemExtent.attribute( QStringLiteral( "xMax" ) ).toDouble(),
143 elemExtent.attribute( QStringLiteral( "yMax" ) ).toDouble() );
144 }
145 else
146 {
148 }
149
150 QDomElement elemCamera = elem.firstChildElement( QStringLiteral( "camera" ) );
151 if ( !elemCamera.isNull() )
152 {
153 mFieldOfView = elemCamera.attribute( QStringLiteral( "field-of-view" ), QStringLiteral( "45" ) ).toFloat();
154 mProjectionType = static_cast< Qt3DRender::QCameraLens::ProjectionType >( elemCamera.attribute( QStringLiteral( "projection-type" ), QStringLiteral( "1" ) ).toInt() );
155 QString cameraNavigationMode = elemCamera.attribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "basic-navigation" ) );
156 if ( cameraNavigationMode == QLatin1String( "terrain-based-navigation" ) )
157 mCameraNavigationMode = Qgis::NavigationMode::TerrainBased;
158 else if ( cameraNavigationMode == QLatin1String( "walk-navigation" ) )
159 mCameraNavigationMode = Qgis::NavigationMode::Walk;
160 mCameraMovementSpeed = elemCamera.attribute( QStringLiteral( "camera-movement-speed" ), QStringLiteral( "5.0" ) ).toDouble();
161 }
162
163 QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) );
164 if ( !elemColor.isNull() )
165 {
166 mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "background" ) ) );
167 mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "selection" ) ) );
168 }
169
170 QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) );
171 mCrs.readXml( elemCrs );
172
173 QDomElement elemTerrain = elem.firstChildElement( QStringLiteral( "terrain" ) );
174 mTerrainRenderingEnabled = elemTerrain.attribute( QStringLiteral( "terrain-rendering-enabled" ), QStringLiteral( "1" ) ).toInt();
175 mTerrainVerticalScale = elemTerrain.attribute( QStringLiteral( "exaggeration" ), QStringLiteral( "1" ) ).toFloat();
176 mMapTileResolution = elemTerrain.attribute( QStringLiteral( "texture-size" ), QStringLiteral( "512" ) ).toInt();
177 mMaxTerrainScreenError = elemTerrain.attribute( QStringLiteral( "max-terrain-error" ), QStringLiteral( "3" ) ).toFloat();
178 mMaxTerrainGroundError = elemTerrain.attribute( QStringLiteral( "max-ground-error" ), QStringLiteral( "1" ) ).toFloat();
179 mTerrainShadingEnabled = elemTerrain.attribute( QStringLiteral( "shading-enabled" ), QStringLiteral( "0" ) ).toInt();
180 mTerrainElevationOffset = elemTerrain.attribute( QStringLiteral( "elevation-offset" ), QStringLiteral( "0.0" ) ).toFloat();
181
182 QDomElement elemTerrainShadingMaterial = elemTerrain.firstChildElement( QStringLiteral( "shading-material" ) );
183 if ( !elemTerrainShadingMaterial.isNull() )
184 mTerrainShadingMaterial.readXml( elemTerrainShadingMaterial, context );
185 mTerrainMapTheme = elemTerrain.attribute( QStringLiteral( "map-theme" ) );
186 mShowLabels = elemTerrain.attribute( QStringLiteral( "show-labels" ), QStringLiteral( "0" ) ).toInt();
187
188 qDeleteAll( mLightSources );
189 mLightSources.clear();
190 const QDomElement lightsElem = elem.firstChildElement( QStringLiteral( "lights" ) );
191 if ( !lightsElem.isNull() )
192 {
193 const QDomNodeList lightNodes = lightsElem.childNodes();
194 for ( int i = 0; i < lightNodes.size(); ++i )
195 {
196 const QDomElement lightElement = lightNodes.at( i ).toElement();
197 if ( QgsLightSource *light = QgsLightSource::createFromXml( lightElement, context ) )
198 mLightSources << light;
199 }
200 }
201 else
202 {
203 // older project format
204 QDomElement elemPointLights = elem.firstChildElement( QStringLiteral( "point-lights" ) );
205 if ( !elemPointLights.isNull() )
206 {
207 QDomElement elemPointLight = elemPointLights.firstChildElement( QStringLiteral( "point-light" ) );
208 while ( !elemPointLight.isNull() )
209 {
210 std::unique_ptr< QgsPointLightSettings > pointLight = std::make_unique< QgsPointLightSettings >();
211 pointLight->readXml( elemPointLight, context );
212 mLightSources << pointLight.release();
213 elemPointLight = elemPointLight.nextSiblingElement( QStringLiteral( "point-light" ) );
214 }
215 }
216 else
217 {
218 // QGIS <= 3.4 did not have light configuration
219 std::unique_ptr< QgsPointLightSettings > defaultLight = std::make_unique< QgsPointLightSettings >();
220 defaultLight->setPosition( QgsVector3D( 0, 1000, 0 ) );
221 mLightSources << defaultLight.release();
222 }
223
224 QDomElement elemDirectionalLights = elem.firstChildElement( QStringLiteral( "directional-lights" ) );
225 if ( !elemDirectionalLights.isNull() )
226 {
227 QDomElement elemDirectionalLight = elemDirectionalLights.firstChildElement( QStringLiteral( "directional-light" ) );
228 while ( !elemDirectionalLight.isNull() )
229 {
230 std::unique_ptr< QgsDirectionalLightSettings > directionalLight = std::make_unique< QgsDirectionalLightSettings >();
231 directionalLight->readXml( elemDirectionalLight, context );
232 mLightSources << directionalLight.release();
233 elemDirectionalLight = elemDirectionalLight.nextSiblingElement( QStringLiteral( "directional-light" ) );
234 }
235 }
236 }
237
238 QDomElement elemMapLayers = elemTerrain.firstChildElement( QStringLiteral( "layers" ) );
239 QDomElement elemMapLayer = elemMapLayers.firstChildElement( QStringLiteral( "layer" ) );
240 QList<QgsMapLayerRef> mapLayers;
241 while ( !elemMapLayer.isNull() )
242 {
243 mapLayers << QgsMapLayerRef( elemMapLayer.attribute( QStringLiteral( "id" ) ) );
244 elemMapLayer = elemMapLayer.nextSiblingElement( QStringLiteral( "layer" ) );
245 }
246 mLayers = mapLayers; // needs to resolve refs afterwards
247
248 QDomElement elemTerrainGenerator = elemTerrain.firstChildElement( QStringLiteral( "generator" ) );
249 QString terrainGenType = elemTerrainGenerator.attribute( QStringLiteral( "type" ) );
250 if ( terrainGenType == QLatin1String( "dem" ) )
251 {
252 QgsDemTerrainGenerator *demTerrainGenerator = new QgsDemTerrainGenerator;
253 demTerrainGenerator->setCrs( mCrs, mTransformContext );
254 setTerrainGenerator( demTerrainGenerator );
255 }
256 else if ( terrainGenType == QLatin1String( "online" ) )
257 {
258 QgsOnlineTerrainGenerator *onlineTerrainGenerator = new QgsOnlineTerrainGenerator;
259 onlineTerrainGenerator->setCrs( mCrs, mTransformContext );
260 setTerrainGenerator( onlineTerrainGenerator );
261 }
262 else if ( terrainGenType == QLatin1String( "mesh" ) )
263 {
264 QgsMeshTerrainGenerator *meshTerrainGenerator = new QgsMeshTerrainGenerator;
265 meshTerrainGenerator->setCrs( mCrs, mTransformContext );
266 setTerrainGenerator( meshTerrainGenerator );
267 }
268 else // "flat"
269 {
271 flatGen->setCrs( mCrs );
272 setTerrainGenerator( flatGen );
273 }
274 mTerrainGenerator->readXml( elemTerrainGenerator );
275
276 qDeleteAll( mRenderers );
277 mRenderers.clear();
278
279 QDomElement elemRenderers = elem.firstChildElement( QStringLiteral( "renderers" ) );
280 QDomElement elemRenderer = elemRenderers.firstChildElement( QStringLiteral( "renderer" ) );
281 while ( !elemRenderer.isNull() )
282 {
283 QgsAbstract3DRenderer *renderer = nullptr;
284 QString type = elemRenderer.attribute( QStringLiteral( "type" ) );
285 if ( type == QLatin1String( "vector" ) )
286 {
287 renderer = new QgsVectorLayer3DRenderer;
288 }
289 else if ( type == QLatin1String( "mesh" ) )
290 {
291 renderer = new QgsMeshLayer3DRenderer;
292 }
293 else if ( type == QLatin1String( "pointcloud" ) )
294 {
295 renderer = new QgsPointCloudLayer3DRenderer;
296 }
297
298 if ( renderer )
299 {
300 renderer->readXml( elemRenderer, context );
301 mRenderers.append( renderer );
302 }
303 elemRenderer = elemRenderer.nextSiblingElement( QStringLiteral( "renderer" ) );
304 }
305
306 QDomElement elemSkybox = elem.firstChildElement( QStringLiteral( "skybox" ) );
307 mIsSkyboxEnabled = elemSkybox.attribute( QStringLiteral( "skybox-enabled" ) ).toInt();
308 mSkyboxSettings.readXml( elemSkybox, context );
309
310 QDomElement elemShadows = elem.firstChildElement( QStringLiteral( "shadow-rendering" ) );
311 mShadowSettings.readXml( elemShadows, context );
312
313 QDomElement elemAmbientOcclusion = elem.firstChildElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
314 mAmbientOcclusionSettings.readXml( elemAmbientOcclusion, context );
315
316 QDomElement elemEyeDomeLighting = elem.firstChildElement( QStringLiteral( "eye-dome-lighting" ) );
317 mEyeDomeLightingEnabled = elemEyeDomeLighting.attribute( "enabled", QStringLiteral( "0" ) ).toInt();
318 mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
319 mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();
320
321 QDomElement elemNavigationSync = elem.firstChildElement( QStringLiteral( "navigation-sync" ) );
322 mViewSyncMode = ( Qgis::ViewSyncModeFlags )( elemNavigationSync.attribute( QStringLiteral( "view-sync-mode" ), QStringLiteral( "0" ) ).toInt() );
323 mVisualizeViewFrustum = elemNavigationSync.attribute( QStringLiteral( "view-frustum-visualization-enabled" ), QStringLiteral( "0" ) ).toInt();
324
325 QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
326 mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
327 mDebugShadowMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), "0" ).toInt() );
328 mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
329
330 mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
331 mDebugDepthMapCorner = static_cast<Qt::Corner>( elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "1" ) ).toInt() );
332 mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();
333
334 QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
335 mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
336 mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
337 mShowCameraViewCenter = elemDebug.attribute( QStringLiteral( "camera-view-center" ), QStringLiteral( "0" ) ).toInt();
338 mShowCameraRotationCenter = elemDebug.attribute( QStringLiteral( "camera-rotation-center" ), QStringLiteral( "0" ) ).toInt();
339 mShowLightSources = elemDebug.attribute( QStringLiteral( "show-light-sources" ), QStringLiteral( "0" ) ).toInt();
340 mIsFpsCounterEnabled = elemDebug.attribute( QStringLiteral( "show-fps-counter" ), QStringLiteral( "0" ) ).toInt();
341
342 QDomElement elemTemporalRange = elem.firstChildElement( QStringLiteral( "temporal-range" ) );
343 QDateTime start = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "start" ) ), Qt::ISODate );
344 QDateTime end = QDateTime::fromString( elemTemporalRange.attribute( QStringLiteral( "end" ) ), Qt::ISODate );
345 setTemporalRange( QgsDateTimeRange( start, end ) );
346
347 QDomElement elem3dAxis = elem.firstChildElement( QStringLiteral( "axis3d" ) );
348 m3dAxisSettings.readXml( elem3dAxis, context );
349
350}
351
352QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
353{
354 QDomElement elem = doc.createElement( QStringLiteral( "qgis3d" ) );
355
356 QDomElement elemOrigin = doc.createElement( QStringLiteral( "origin" ) );
357 elemOrigin.setAttribute( QStringLiteral( "x" ), QString::number( mOrigin.x() ) );
358 elemOrigin.setAttribute( QStringLiteral( "y" ), QString::number( mOrigin.y() ) );
359 elemOrigin.setAttribute( QStringLiteral( "z" ), QString::number( mOrigin.z() ) );
360 elem.appendChild( elemOrigin );
361
362 QDomElement elemExtent = doc.createElement( QStringLiteral( "extent" ) );
363 elemExtent.setAttribute( QStringLiteral( "xMin" ), mExtent.xMinimum() );
364 elemExtent.setAttribute( QStringLiteral( "yMin" ), mExtent.yMinimum() );
365 elemExtent.setAttribute( QStringLiteral( "xMax" ), mExtent.xMaximum() );
366 elemExtent.setAttribute( QStringLiteral( "yMax" ), mExtent.yMaximum() );
367 elem.appendChild( elemExtent );
368
369 QDomElement elemCamera = doc.createElement( QStringLiteral( "camera" ) );
370 elemCamera.setAttribute( QStringLiteral( "field-of-view" ), mFieldOfView );
371 elemCamera.setAttribute( QStringLiteral( "projection-type" ), static_cast< int >( mProjectionType ) );
372 switch ( mCameraNavigationMode )
373 {
375 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "terrain-based-navigation" ) );
376 break;
378 elemCamera.setAttribute( QStringLiteral( "camera-navigation-mode" ), QStringLiteral( "walk-navigation" ) );
379 break;
380 }
381 elemCamera.setAttribute( QStringLiteral( "camera-movement-speed" ), mCameraMovementSpeed );
382 elem.appendChild( elemCamera );
383
384 QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) );
385 elemColor.setAttribute( QStringLiteral( "background" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
386 elemColor.setAttribute( QStringLiteral( "selection" ), QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
387 elem.appendChild( elemColor );
388
389 QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) );
390 mCrs.writeXml( elemCrs, doc );
391 elem.appendChild( elemCrs );
392
393 QDomElement elemTerrain = doc.createElement( QStringLiteral( "terrain" ) );
394 elemTerrain.setAttribute( QStringLiteral( "terrain-rendering-enabled" ), mTerrainRenderingEnabled ? 1 : 0 );
395 elemTerrain.setAttribute( QStringLiteral( "exaggeration" ), QString::number( mTerrainVerticalScale ) );
396 elemTerrain.setAttribute( QStringLiteral( "texture-size" ), mMapTileResolution );
397 elemTerrain.setAttribute( QStringLiteral( "max-terrain-error" ), QString::number( mMaxTerrainScreenError ) );
398 elemTerrain.setAttribute( QStringLiteral( "max-ground-error" ), QString::number( mMaxTerrainGroundError ) );
399 elemTerrain.setAttribute( QStringLiteral( "shading-enabled" ), mTerrainShadingEnabled ? 1 : 0 );
400 elemTerrain.setAttribute( QStringLiteral( "elevation-offset" ), mTerrainElevationOffset );
401
402 QDomElement elemTerrainShadingMaterial = doc.createElement( QStringLiteral( "shading-material" ) );
403 mTerrainShadingMaterial.writeXml( elemTerrainShadingMaterial, context );
404 elemTerrain.appendChild( elemTerrainShadingMaterial );
405 elemTerrain.setAttribute( QStringLiteral( "map-theme" ), mTerrainMapTheme );
406 elemTerrain.setAttribute( QStringLiteral( "show-labels" ), mShowLabels ? 1 : 0 );
407
408 {
409 QDomElement elemLights = doc.createElement( QStringLiteral( "lights" ) );
410 for ( const QgsLightSource *light : mLightSources )
411 {
412 const QDomElement elemLight = light->writeXml( doc, context );
413 elemLights.appendChild( elemLight );
414 }
415 elem.appendChild( elemLights );
416 }
417
418 QDomElement elemMapLayers = doc.createElement( QStringLiteral( "layers" ) );
419 for ( const QgsMapLayerRef &layerRef : mLayers )
420 {
421 QDomElement elemMapLayer = doc.createElement( QStringLiteral( "layer" ) );
422 elemMapLayer.setAttribute( QStringLiteral( "id" ), layerRef.layerId );
423 elemMapLayers.appendChild( elemMapLayer );
424 }
425 elemTerrain.appendChild( elemMapLayers );
426
427 QDomElement elemTerrainGenerator = doc.createElement( QStringLiteral( "generator" ) );
428 elemTerrainGenerator.setAttribute( QStringLiteral( "type" ), QgsTerrainGenerator::typeToString( mTerrainGenerator->type() ) );
429 mTerrainGenerator->writeXml( elemTerrainGenerator );
430 elemTerrain.appendChild( elemTerrainGenerator );
431 elem.appendChild( elemTerrain );
432
433 QDomElement elemRenderers = doc.createElement( QStringLiteral( "renderers" ) );
434 for ( const QgsAbstract3DRenderer *renderer : mRenderers )
435 {
436 QDomElement elemRenderer = doc.createElement( QStringLiteral( "renderer" ) );
437 elemRenderer.setAttribute( QStringLiteral( "type" ), renderer->type() );
438 renderer->writeXml( elemRenderer, context );
439 elemRenderers.appendChild( elemRenderer );
440 }
441 elem.appendChild( elemRenderers );
442
443 QDomElement elemSkybox = doc.createElement( QStringLiteral( "skybox" ) );
444 elemSkybox.setAttribute( QStringLiteral( "skybox-enabled" ), mIsSkyboxEnabled );
445 mSkyboxSettings.writeXml( elemSkybox, context );
446 elem.appendChild( elemSkybox );
447
448 QDomElement elemShadows = doc.createElement( QStringLiteral( "shadow-rendering" ) );
449 mShadowSettings.writeXml( elemShadows, context );
450 elem.appendChild( elemShadows );
451
452 QDomElement elemAmbientOcclusion = doc.createElement( QStringLiteral( "screen-space-ambient-occlusion" ) );
453 mAmbientOcclusionSettings.writeXml( elemAmbientOcclusion, context );
454 elem.appendChild( elemAmbientOcclusion );
455
456 QDomElement elemDebug = doc.createElement( QStringLiteral( "debug" ) );
457 elemDebug.setAttribute( QStringLiteral( "bounding-boxes" ), mShowTerrainBoundingBoxes ? 1 : 0 );
458 elemDebug.setAttribute( QStringLiteral( "terrain-tile-info" ), mShowTerrainTileInfo ? 1 : 0 );
459 elemDebug.setAttribute( QStringLiteral( "camera-view-center" ), mShowCameraViewCenter ? 1 : 0 );
460 elemDebug.setAttribute( QStringLiteral( "camera-rotation-center" ), mShowCameraRotationCenter ? 1 : 0 );
461 elemDebug.setAttribute( QStringLiteral( "show-light-sources" ), mShowLightSources ? 1 : 0 );
462 elemDebug.setAttribute( QStringLiteral( "show-fps-counter" ), mIsFpsCounterEnabled ? 1 : 0 );
463 elem.appendChild( elemDebug );
464
465 QDomElement elemEyeDomeLighting = doc.createElement( QStringLiteral( "eye-dome-lighting" ) );
466 elemEyeDomeLighting.setAttribute( QStringLiteral( "enabled" ), mEyeDomeLightingEnabled ? 1 : 0 );
467 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-strength" ), mEyeDomeLightingStrength );
468 elemEyeDomeLighting.setAttribute( QStringLiteral( "eye-dome-lighting-distance" ), mEyeDomeLightingDistance );
469 elem.appendChild( elemEyeDomeLighting );
470
471 QDomElement elemNavigationSync = doc.createElement( QStringLiteral( "navigation-sync" ) );
472 elemNavigationSync.setAttribute( QStringLiteral( "view-sync-mode" ), ( int )mViewSyncMode );
473 elemNavigationSync.setAttribute( QStringLiteral( "view-frustum-visualization-enabled" ), mVisualizeViewFrustum ? 1 : 0 );
474 elem.appendChild( elemNavigationSync );
475
476 QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
477 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
478 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
479 elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
480 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
481 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
482 elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
483 elem.appendChild( elemDebugSettings );
484
485 QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
486 elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
487 elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
488
489 QDomElement elem3dAxis = doc.createElement( QStringLiteral( "axis3d" ) );
490 m3dAxisSettings.writeXml( elem3dAxis, context );
491 elem.appendChild( elem3dAxis );
492
493 return elem;
494}
495
497{
498 for ( int i = 0; i < mLayers.count(); ++i )
499 {
500 QgsMapLayerRef &layerRef = mLayers[i];
501 layerRef.setLayer( project.mapLayer( layerRef.layerId ) );
502 }
503
504 mTerrainGenerator->resolveReferences( project );
505
506 for ( int i = 0; i < mRenderers.count(); ++i )
507 {
508 QgsAbstract3DRenderer *renderer = mRenderers[i];
509 renderer->resolveReferences( project );
510 }
511}
512
514{
515 if ( extent == mExtent )
516 return;
517
518 mExtent = extent;
519 const QgsPointXY center = mExtent.center();
520 setOrigin( QgsVector3D( center.x(), center.y(), 0 ) );
521 if ( mTerrainGenerator )
522 {
523 QgsRectangle terrainExtent = mExtent;
524 if ( mCrs != mTerrainGenerator->crs() )
525 {
526 QgsCoordinateTransform ct = QgsCoordinateTransform( mCrs, mTerrainGenerator->crs(), mTransformContext );
528 try
529 {
530 terrainExtent = ct.transformBoundingBox( mExtent );
531 }
532 catch ( const QgsCsException & )
533 {
534 QgsDebugMsg( QStringLiteral( "Transformation of map extent to terrain crs failed." ) );
535 }
536 }
537 mTerrainGenerator->setExtent( terrainExtent );
538 }
539 emit extentChanged();
540}
541
543{
544 return Qgs3DUtils::mapToWorldCoordinates( mapCoords, mOrigin );
545}
546
548{
549 return Qgs3DUtils::worldToMapCoordinates( worldCoords, mOrigin );
550}
551
553{
554 mCrs = crs;
555}
556
558{
559 return mTransformContext;
560}
561
563{
564 mTransformContext = context;
565}
566
567void Qgs3DMapSettings::setBackgroundColor( const QColor &color )
568{
569 if ( color == mBackgroundColor )
570 return;
571
572 mBackgroundColor = color;
574}
575
577{
578 return mBackgroundColor;
579}
580
581void Qgs3DMapSettings::setSelectionColor( const QColor &color )
582{
583 if ( color == mSelectionColor )
584 return;
585
586 mSelectionColor = color;
588}
589
591{
592 return mSelectionColor;
593}
594
596{
597 if ( zScale == mTerrainVerticalScale )
598 return;
599
600 mTerrainVerticalScale = zScale;
602}
603
605{
606 return mTerrainVerticalScale;
607}
608
609void Qgs3DMapSettings::setLayers( const QList<QgsMapLayer *> &layers )
610{
611 QList<QgsMapLayerRef> lst;
612 lst.reserve( layers.count() );
613 for ( QgsMapLayer *layer : layers )
614 {
615 lst.append( layer );
616 }
617
618 if ( mLayers == lst )
619 return;
620
621 mLayers = lst;
622 emit layersChanged();
623}
624
625QList<QgsMapLayer *> Qgs3DMapSettings::layers() const
626{
627 QList<QgsMapLayer *> lst;
628 lst.reserve( mLayers.count() );
629 for ( const QgsMapLayerRef &layerRef : mLayers )
630 {
631 if ( layerRef.layer )
632 lst.append( layerRef.layer );
633 }
634 return lst;
635}
636
638{
639 setExtent( fullExtent );
640 if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
641 {
643 flatTerrain->setCrs( crs() );
644 setTerrainGenerator( flatTerrain );
645
647 }
648 else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
649 {
650 QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast< QgsRasterDemTerrainProvider * >( properties->terrainProvider() );
651
653 demTerrainGen->setCrs( crs(), QgsProject::instance()->transformContext() );
654 demTerrainGen->setLayer( rasterProvider->layer() );
655 setTerrainGenerator( demTerrainGen );
656
659 }
660 else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
661 {
662 QgsMeshTerrainProvider *meshProvider = qgis::down_cast< QgsMeshTerrainProvider * >( properties->terrainProvider() );
663
664 QgsMeshTerrainGenerator *newTerrainGenerator = new QgsMeshTerrainGenerator;
665 newTerrainGenerator->setCrs( crs(), QgsProject::instance()->transformContext() );
666 newTerrainGenerator->setLayer( meshProvider->layer() );
667 std::unique_ptr< QgsMesh3DSymbol > symbol( newTerrainGenerator->symbol()->clone() );
668 symbol->setVerticalScale( properties->terrainProvider()->scale() );
669 newTerrainGenerator->setSymbol( symbol.release() );
670 setTerrainGenerator( newTerrainGenerator );
671
674 }
675 else
676 {
678 flatTerrain->setCrs( crs() );
679 setTerrainGenerator( flatTerrain );
680 }
681}
682
684{
685 if ( mMapTileResolution == res )
686 return;
687
688 mMapTileResolution = res;
690}
691
693{
694 return mMapTileResolution;
695}
696
698{
699 if ( mMaxTerrainScreenError == error )
700 return;
701
702 mMaxTerrainScreenError = error;
704}
705
707{
708 return mMaxTerrainScreenError;
709}
710
712{
713 if ( mMaxTerrainGroundError == error )
714 return;
715
716 mMaxTerrainGroundError = error;
718}
719
721{
722 if ( mTerrainElevationOffset == offset )
723 return;
724 mTerrainElevationOffset = offset;
725 emit terrainElevationOffsetChanged( mTerrainElevationOffset );
726}
727
729{
730 return mMaxTerrainGroundError;
731}
732
734{
735 if ( mTerrainGenerator )
736 {
737 disconnect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
738 }
739
740 QgsRectangle terrainExtent = mExtent;
741 if ( mCrs != gen->crs() )
742 {
743 QgsCoordinateTransform ct = QgsCoordinateTransform( mCrs, gen->crs(), mTransformContext );
745 try
746 {
747 terrainExtent = ct.transformBoundingBox( mExtent );
748 }
749 catch ( const QgsCsException & )
750 {
751 QgsDebugMsg( QStringLiteral( "Transformation of map extent to terrain crs failed." ) );
752 }
753 }
754 gen->setExtent( terrainExtent );
755 mTerrainGenerator.reset( gen );
756 connect( mTerrainGenerator.get(), &QgsTerrainGenerator::terrainChanged, this, &Qgs3DMapSettings::terrainGeneratorChanged );
757
759}
760
762{
763 if ( mTerrainShadingEnabled == enabled )
764 return;
765
766 mTerrainShadingEnabled = enabled;
768}
769
771{
772 if ( mTerrainShadingMaterial == material )
773 return;
774
775 mTerrainShadingMaterial = material;
777}
778
779void Qgs3DMapSettings::setTerrainMapTheme( const QString &theme )
780{
781 if ( mTerrainMapTheme == theme )
782 return;
783
784 mTerrainMapTheme = theme;
786}
787
788void Qgs3DMapSettings::setRenderers( const QList<QgsAbstract3DRenderer *> &renderers )
789{
790 qDeleteAll( mRenderers );
791
792 mRenderers = renderers;
793
794 emit renderersChanged();
795}
796
798{
799 if ( mShowTerrainBoundingBoxes == enabled )
800 return;
801
802 mShowTerrainBoundingBoxes = enabled;
804}
805
807{
808 if ( mShowTerrainTileInfo == enabled )
809 return;
810
811 mShowTerrainTileInfo = enabled;
813}
814
816{
817 if ( mShowCameraViewCenter == enabled )
818 return;
819
820 mShowCameraViewCenter = enabled;
822}
823
825{
826 if ( mShowCameraRotationCenter == enabled )
827 return;
828
829 mShowCameraRotationCenter = enabled;
831}
832
833
835{
836 if ( mShowLightSources == enabled )
837 return;
838
839 mShowLightSources = enabled;
841}
842
844{
845 if ( mShowLabels == enabled )
846 return;
847
848 mShowLabels = enabled;
849 emit showLabelsChanged();
850}
851
853{
854 if ( mEyeDomeLightingEnabled == enabled )
855 return;
856 mEyeDomeLightingEnabled = enabled;
858}
859
861{
862 if ( mEyeDomeLightingStrength == strength )
863 return;
864 mEyeDomeLightingStrength = strength;
866}
867
869{
870 if ( mEyeDomeLightingDistance == distance )
871 return;
872 mEyeDomeLightingDistance = distance;
874}
875
876QList<QgsLightSource *> Qgs3DMapSettings::lightSources() const
877{
878 return mLightSources;
879}
880
881void Qgs3DMapSettings::setLightSources( const QList<QgsLightSource *> &lights )
882{
883 qDeleteAll( mLightSources );
884 mLightSources = lights;
885
887 emit pointLightsChanged();
888 emit lightSourcesChanged();
889}
890
891void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
892{
893 if ( mFieldOfView == fieldOfView )
894 return;
895
896 mFieldOfView = fieldOfView;
897 emit fieldOfViewChanged();
898}
899
900void Qgs3DMapSettings::setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType )
901{
902 if ( mProjectionType == projectionType )
903 return;
904
905 mProjectionType = projectionType;
907}
908
910{
911 if ( mCameraNavigationMode == navigationMode )
912 return;
913
914 mCameraNavigationMode = navigationMode;
916}
917
919{
920 if ( mCameraMovementSpeed == movementSpeed )
921 return;
922
923 mCameraMovementSpeed = movementSpeed;
925}
926
928{
929 mSkyboxSettings = skyboxSettings;
931}
932
934{
935 mShadowSettings = shadowSettings;
937}
938
940{
941 mAmbientOcclusionSettings = ambientOcclusionSettings;
943}
944
945void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size )
946{
947 mDebugShadowMapEnabled = enabled;
948 mDebugShadowMapCorner = corner;
949 mDebugShadowMapSize = size;
951}
952
953void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size )
954{
955 mDebugDepthMapEnabled = enabled;
956 mDebugDepthMapCorner = corner;
957 mDebugDepthMapSize = size;
959}
960
961void Qgs3DMapSettings::setIsFpsCounterEnabled( bool fpsCounterEnabled )
962{
963 if ( fpsCounterEnabled == mIsFpsCounterEnabled )
964 return;
965 mIsFpsCounterEnabled = fpsCounterEnabled;
966 emit fpsCounterEnabledChanged( mIsFpsCounterEnabled );
967}
968
969void Qgs3DMapSettings::setTerrainRenderingEnabled( bool terrainRenderingEnabled )
970{
971 if ( terrainRenderingEnabled == mTerrainRenderingEnabled )
972 return;
973 mTerrainRenderingEnabled = terrainRenderingEnabled;
975}
976
978{
979 return mRendererUsage;
980}
981
983{
984 mRendererUsage = rendererUsage;
985}
986
987void Qgs3DMapSettings::setViewSyncMode( Qgis::ViewSyncModeFlags mode )
988{
989 mViewSyncMode = mode;
990}
991
993{
994 if ( mVisualizeViewFrustum != enabled )
995 {
996 mVisualizeViewFrustum = enabled;
998 }
999}
1000
1001void Qgs3DMapSettings::setIsDebugOverlayEnabled( bool debugOverlayEnabled )
1002{
1003 if ( debugOverlayEnabled == mIsDebugOverlayEnabled )
1004 return;
1005
1006 mIsDebugOverlayEnabled = debugOverlayEnabled;
1007 emit debugOverlayEnabledChanged( mIsDebugOverlayEnabled );
1008}
1009
1010
1011void Qgs3DMapSettings::connectChangedSignalsToSettingsChanged()
1012{
1045}
1046
1047
1048void Qgs3DMapSettings::set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force )
1049{
1050 if ( axisSettings == m3dAxisSettings )
1051 {
1052 if ( force )
1053 {
1054 // ie. refresh. We nned to disconnect and to reconnect to avoid 'dirty' project
1056 emit axisSettingsChanged();
1058 }
1059 }
1060 else
1061 {
1062 m3dAxisSettings = axisSettings;
1063 emit axisSettingsChanged();
1064 }
1065}
NavigationMode
The navigation mode used by 3D cameras.
Definition: qgis.h:2421
@ 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:2205
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.
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.
void setAmbientOcclusionSettings(const QgsAmbientOcclusionSettings &ambientOcclusionSettings)
Sets the current configuration of screen space ambient occlusion.
void setShowTerrainTilesInfo(bool enabled)
Sets whether to display extra tile info on top of terrain tiles (for debugging)
QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords) const
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
void setRenderers(const QList< QgsAbstract3DRenderer * > &renderers)
Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting will be used.
void setFieldOfView(const float fieldOfView)
Sets the camera lens' field of view.
void debugDepthMapSettingsChanged()
Emitted when depth map debugging has changed.
void setLightSources(const QList< QgsLightSource * > &lights)
Sets the list of light sources defined in the scene.
Qgis::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
void backgroundColorChanged()
Emitted when the background color has changed.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Writes configuration to a DOM element, to be used later with readXml()
void setDebugDepthMapSettings(bool enabled, Qt::Corner corner, double size)
Sets the debugging settings of the depth map.
void showCameraRotationCenterChanged()
Emitted when the flag whether camera's rotation center is shown has changed.
QColor selectionColor() const
Returns color used for selected features.
void directionalLightsChanged()
Emitted when the list of directional lights changes.
void setTerrainShadingMaterial(const QgsPhongMaterialSettings &material)
Sets terrain shading material.
void cameraNavigationModeChanged()
Emitted when the camera navigation mode was changed.
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
void setViewFrustumVisualizationEnabled(bool enabled)
Sets whether the camera's view frustum is visualized on the 2D map canvas.
void setShowCameraRotationCenter(bool enabled)
Sets whether to show camera's rotation center as a sphere (for debugging)
float maxTerrainGroundError() const
Returns maximum ground error of terrain tiles in world units.
void setExtent(const QgsRectangle &extent)
Sets the 3D scene's 2D extent in project's CRS, while also setting the scene's origin to the extent's...
void eyeDomeLightingEnabledChanged()
Emitted when the flag whether eye dome lighting is used has changed.
void setTerrainVerticalScale(double zScale)
Sets vertical scale (exaggeration) of terrain (1 = true scale, > 1 = hills get more pronounced)
void debugOverlayEnabledChanged(bool debugOverlayEnabled)
Emitted when the debug overaly is enabled or disabled.
void setShowLabels(bool enabled)
Sets whether to display labels on terrain tiles.
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
void setViewSyncMode(Qgis::ViewSyncModeFlags mode)
Sets the view sync mode (used to synchronize the 2D main map canvas and the 3D camera navigation)
void 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.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets coordinate reference system used in the 3D scene.
void setEyeDomeLightingDistance(int distance)
Sets the eye dome lighting distance value (contributes to the contrast of the image.
void setShowLightSourceOrigins(bool enabled)
Sets whether to show light source origins as a sphere (for debugging)
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void projectionTypeChanged()
Emitted when the camera lens projection type changes.
float fieldOfView() const
Returns the camera lens' field of view.
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 project's CRS.
void setTerrainShadingEnabled(bool enabled)
Sets whether terrain shading is enabled.
void setDebugShadowMapSettings(bool enabled, Qt::Corner corner, double size)
Sets the debugging settings of the shadow map.
void setSelectionColor(const QColor &color)
Sets color used for selected features.
void lightSourcesChanged()
Emitted when any of the light source settings in the map changes.
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
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()
QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords) const
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
~Qgs3DMapSettings() override
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
void setShowCameraViewCenter(bool enabled)
Sets whether to show camera's view center as a sphere (for debugging)
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
void set3DAxisSettings(const Qgs3DAxisSettings &axisSettings, bool force=false)
Sets the current configuration of 3d axis.
void setCameraMovementSpeed(double movementSpeed)
Sets the camera movement speed.
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
void setTerrainRenderingEnabled(bool terrainRenderingEnabled)
Sets whether the 2D terrain surface will be rendered in.
Qgs3DMapSettings()
Constructor for Qgs3DMapSettings.
void setBackgroundColor(const QColor &color)
Sets background color of the 3D map view.
bool terrainRenderingEnabled() const
Returns whether the 2D terrain surface will be rendered.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is enabled or disabled.
void axisSettingsChanged()
Emitted when 3d axis rendering settings are changed.
void viewFrustumVisualizationEnabledChanged()
Emitted when the camera's view frustum visualization on the main 2D map canvas is enabled or disabled...
void setProjectionType(const Qt3DRender::QCameraLens::ProjectionType projectionType)
Sets the camera lens' projection type.
void ambientOcclusionSettingsChanged()
Emitted when ambient occlusion rendering settings are changed.
void configureTerrainFromProject(QgsProjectElevationProperties *properties, const QgsRectangle &fullExtent)
Configures the map's terrain settings directly from a project's elevation properties.
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
void eyeDomeLightingStrengthChanged()
Emitted when the eye dome lighting strength has changed.
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
void setMaxTerrainScreenError(float error)
Sets maximum allowed screen error of terrain tiles in pixels.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the renderer usage.
float maxTerrainScreenError() const
Returns maximum allowed screen error of terrain tiles in pixels.
void setShowTerrainBoundingBoxes(bool enabled)
Sets whether to display bounding boxes of terrain tiles (for debugging)
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
Qgis::RendererUsage rendererUsage() const
Returns the renderer usage.
void setIsFpsCounterEnabled(bool fpsCounterEnabled)
Sets whether FPS counter label is enabled.
QList< QgsMapLayer * > layers() const
Returns the list of 3D map layers to be rendered in the scene.
void setTerrainMapTheme(const QString &theme)
Sets name of the map theme.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
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...
static QgsVector3D worldToMapCoordinates(const QgsVector3D &worldCoords, const QgsVector3D &origin)
Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:551
static QgsVector3D mapToWorldCoordinates(const QgsVector3D &mapCoords, const QgsVector3D &origin)
Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,...
Definition: qgs3dutils.cpp:543
Base class for all renderers that may to participate in 3D view.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
virtual QString type() const =0
Returns the unique type ID string for the provider.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
class containing the configuration of ambient occlusion rendering 3
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
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.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
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:73
3D renderer that renders all mesh triangles of a mesh layer.
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
QgsMeshLayer * layer() const
Returns the mesh layer to be used as the terrain source.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets CRS of the terrain.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
3D renderer that renders all points from a point cloud layer
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
Temporarily blocks QgsProject "dirtying" for the lifetime of the object.
Definition: qgsproject.h:2396
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:105
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:477
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
void setDirty(bool b=true)
Flag the project as dirty (modified).
Definition: qgsproject.cpp:596
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.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
class containing the configuration of shadows rendering 3
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Contains the configuration of a skybox entity.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
Base class for objects with an associated (optional) temporal range.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
void terrainChanged()
Emitted when the terrain changed (for example, raster DEM or mesh have data changed)
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.
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
3D renderer that renders all features of a vector layer with the same 3D symbol.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
_LayerRef< QgsMapLayer > QgsMapLayerRef
const QgsCoordinateReferenceSystem & crs
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.