QGIS API Documentation 3.43.0-Master (c67cf405802)
qgswindow3dengine.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgswindow3dengine.cpp
3 --------------------------------------
4 Date : July 2018
5 Copyright : (C) 2018 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 "qgswindow3dengine.h"
17#include "moc_qgswindow3dengine.cpp"
18
19#include <Qt3DExtras/QForwardRenderer>
20#include <Qt3DRender/QRenderSettings>
21
23#include "qgs3dmapcanvas.h"
24
25#include "qgsframegraph.h"
26#include "qgsshadowrenderview.h"
28
30 : QgsAbstract3DEngine( parent )
31{
32 mMapCanvas3D = parent;
33
34 mRoot = new Qt3DCore::QEntity;
35 mMapCanvas3D->setRootEntity( mRoot );
36
37 mFrameGraph = new QgsFrameGraph( mMapCanvas3D, QSize( 1024, 768 ), mMapCanvas3D->camera(), mRoot );
39
40 // force switching to no shadow rendering
42}
43
45{
46 return mMapCanvas3D;
47}
48
49Qt3DCore::QEntity *QgsWindow3DEngine::root() const
50{
51 return mRoot;
52}
53
54void QgsWindow3DEngine::setClearColor( const QColor &color )
55{
56 mFrameGraph->setClearColor( color );
57}
58
60{
61 // Not sure if this works properly
63}
64
65void QgsWindow3DEngine::setRootEntity( Qt3DCore::QEntity *root )
66{
67 mSceneRoot = root;
68 mSceneRoot->setParent( mRoot );
69 mSceneRoot->addComponent( mFrameGraph->forwardRenderView().renderLayer() );
70 mSceneRoot->addComponent( mFrameGraph->shadowRenderView().entityCastingShadowsLayer() );
71}
72
73Qt3DRender::QRenderSettings *QgsWindow3DEngine::renderSettings()
74{
75 return mMapCanvas3D->renderSettings();
76}
77
78Qt3DRender::QCamera *QgsWindow3DEngine::camera()
79{
80 return mMapCanvas3D->camera();
81}
82
84{
85 return mMapCanvas3D->size();
86}
87
89{
90 return mMapCanvas3D;
91}
92
94{
95 mSize = s;
96
97 mMapCanvas3D->setWidth( mSize.width() );
98 mMapCanvas3D->setHeight( mSize.height() );
99 mFrameGraph->setSize( mSize * mMapCanvas3D->devicePixelRatio() );
100 camera()->setAspectRatio( float( mSize.width() ) / float( mSize.height() ) );
101 emit sizeChanged();
102}
Convenience wrapper to simplify the creation of a 3D window ready to be used with QGIS.
Qt3DRender::QCamera * camera() const
Returns the default camera of the 3D Window.
void setRootEntity(Qt3DCore::QEntity *root)
Sets the specified root entity of the scene.
void setActiveFrameGraph(Qt3DRender::QFrameGraphNode *activeFrameGraph)
Activates the specified activeFrameGraph.
Qt3DRender::QRenderSettings * renderSettings() const
Returns the render settings of the 3D Window.
Base class for 3D engine implementation.
void sizeChanged()
Emitted after a call to setSize()
QgsFrameGraph * mFrameGraph
Qt3DRender::QLayer * renderLayer()
Returns a layer object used to indicate that the object is transparent.
Container class that holds different objects related to frame graphs of 3D scenes.
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
QgsForwardRenderView & forwardRenderView()
Returns forward renderview.
QgsShadowRenderView & shadowRenderView()
Returns shadow renderview.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Qt3DRender::QLayer * entityCastingShadowsLayer() const
Returns the layer to be used by entities to be included in this renderview.
virtual void setEnabled(bool enable) override
Enable or disable via enable the renderview sub tree.
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
QgsWindow3DEngine(Qgs3DMapCanvas *parent)
Constructor for QgsWindow3DEngine with the specified parent Qgs3DMapCanvas.
Qt3DRender::QRenderSettings * renderSettings() override
Returns access to the engine's render settings (the frame graph can be accessed from here)
void setSize(QSize s) override
Sets the size of the rendering area (in pixels)
QSize size() const override
Returns size of the engine's rendering area in pixels.
Qt3DCore::QEntity * root() const
Returns the root entity.
Qt3DRender::QCamera * camera() override
Returns pointer to the engine's camera entity.
QSurface * surface() const override
Returns the surface of the engine.
void setClearColor(const QColor &color) override
Sets background color of the scene.
QWindow * window()
Returns the internal 3D window where all the rendered output is displayed.
void setFrustumCullingEnabled(bool enabled) override
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...