QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgs3d.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3d.cpp
3  ----------
4  begin : July 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgs3d.h"
19 
20 #include "qgsapplication.h"
21 #include "qgs3drendererregistry.h"
22 
23 #include "qgsabstract3drenderer.h"
24 #include "qgs3drendererregistry.h"
25 #include "qgsrulebased3drenderer.h"
27 #include "qgsmeshlayer3drenderer.h"
28 #include "qgs3dsymbolregistry.h"
29 #include "qgspoint3dsymbol.h"
30 #include "qgsline3dsymbol.h"
31 #include "qgspolygon3dsymbol.h"
32 #include "qgsmaterialregistry.h"
33 
34 #include "qgspolygon3dsymbol_p.h"
35 #include "qgspoint3dsymbol_p.h"
36 #include "qgsline3dsymbol_p.h"
40 
41 #include "qgsstyle.h"
42 
44 {
45  static Qgs3D *sInstance( new Qgs3D() );
46  return sInstance;
47 }
48 
50 {
51 }
52 
54 {
55  if ( instance()->mInitialized )
56  return;
57 
58  instance()->mInitialized = true;
59 
63 
64  QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "point" ), QObject::tr( "Point" ),
65  &QgsPoint3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPoint3DSymbol ) );
66  QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "line" ), QObject::tr( "Line" ),
67  &QgsLine3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForLine3DSymbol ) );
68  QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
69  &QgsPolygon3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPolygon3DSymbol ) );
70 
71  instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phong" ), QObject::tr( "Realistic (Phong)" ),
72  QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconPhongMaterial.svg" ) ) ) );
73  instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phongtextured" ), QObject::tr( "Realistic Textured (Phong)" ),
75  instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "simpleline" ), QObject::tr( "Single Color (Unlit)" ),
76  QgsSimpleLineMaterialSettings::create, QgsSimpleLineMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconSimpleLineMaterial.svg" ) ) ) );
77  instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "gooch" ), QObject::tr( "CAD (Gooch)" ),
78  QgsGoochMaterialSettings::create, QgsGoochMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconGoochMaterial.svg" ) ) ) );
79 
80  // because we are usually populating the 3d registry AFTER QgsApplication initialization, we need to defer creation
81  // of 3d symbols in the default style until now
82  QgsStyle::defaultStyle()->handleDeferred3DSymbolCreation();
83 }
84 
86 {
87  return instance()->mMaterialRegistry;
88 }
89 
90 Qgs3D::Qgs3D()
91 {
92  mMaterialRegistry = new QgsMaterialRegistry();
93 }
Qgs3D::instance
static Qgs3D * instance()
Returns a pointer to the singleton instance.
Definition: qgs3d.cpp:43
qgsgoochmaterialsettings.h
QgsPhongTexturedMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
Definition: qgsphongtexturedmaterialsettings.cpp:35
qgs3d.h
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:626
QgsPhongTexturedMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongTexturedMaterialSettings.
Definition: qgsphongtexturedmaterialsettings.cpp:51
qgsline3dsymbol.h
Qgs3D::materialRegistry
static QgsMaterialRegistry * materialRegistry()
Returns the material registry, used for managing 3D materials.
Definition: qgs3d.cpp:85
qgsmaterialregistry.h
qgsphongtexturedmaterialsettings.h
QgsApplication::symbol3DRegistry
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
Definition: qgsapplication.cpp:2288
QgsVectorLayer3DRendererMetadata
Metadata for vector layer 3D renderer to allow creation of its instances from XML.
Definition: qgsvectorlayer3drenderer.h:45
QgsSimpleLineMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsSimpleLineMaterialSettings.
Definition: qgssimplelinematerialsettings.cpp:46
qgsabstract3drenderer.h
QgsMaterialRegistry
Registry of available 3d material settings classes.
Definition: qgsmaterialregistry.h:186
qgs3dsymbolregistry.h
Qgs3DRendererRegistry::addRenderer
void addRenderer(Qgs3DRendererAbstractMetadata *metadata)
Registers a new 3D renderer type.
Definition: qgs3drendererregistry.cpp:38
QgsSimpleLineMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
Definition: qgssimplelinematerialsettings.cpp:30
QgsStyle::defaultStyle
static QgsStyle * defaultStyle()
Returns default application-wide style.
Definition: qgsstyle.cpp:127
qgsapplication.h
QgsMaterialSettingsMetadata
Convenience metadata class that uses static functions to create a 3D material settings object and its...
Definition: qgsmaterialregistry.h:122
qgsmeshlayer3drenderer.h
QgsPoint3DSymbol::create
static QgsAbstract3DSymbol * create() SIP_FACTORY
Creates a new QgsPoint3DSymbol.
Definition: qgspoint3dsymbol.cpp:32
qgssimplelinematerialsettings.h
QgsMaterialRegistry::addMaterialSettingsType
bool addMaterialSettingsType(QgsMaterialSettingsAbstractMetadata *metadata)
Registers a new material settings type. Takes ownership of the metadata instance.
Definition: qgsmaterialregistry.cpp:28
QgsMeshLayer3DRendererMetadata
Metadata for mesh layer 3D renderer to allow creation of its instances from XML.
Definition: qgsmeshlayer3drenderer.h:45
qgs3drendererregistry.h
QgsPhongMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongMaterialSettings.
Definition: qgsphongmaterialsettings.cpp:49
qgsstyle.h
qgspolygon3dsymbol_p.h
qgspolygon3dsymbol.h
QgsLine3DSymbol::create
static QgsAbstract3DSymbol * create() SIP_FACTORY
Creates a new QgsLine3DSymbol.
Definition: qgsline3dsymbol.cpp:104
QgsApplication::renderer3DRegistry
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
Definition: qgsapplication.cpp:2283
qgsrulebased3drenderer.h
qgspoint3dsymbol.h
QgsPolygon3DSymbol::create
static QgsAbstract3DSymbol * create() SIP_FACTORY
Creates a new QgsPolygon3DSymbol.
Definition: qgspolygon3dsymbol.cpp:125
QgsGoochMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsGoochMaterialSettings.
Definition: qgsgoochmaterialsettings.cpp:27
qgsvectorlayer3drenderer.h
Qgs3DSymbolRegistry::addSymbolType
bool addSymbolType(Qgs3DSymbolAbstractMetadata *metadata)
Registers a new symbol type. Takes ownership of the metadata instance.
Definition: qgs3dsymbolregistry.cpp:28
QgsGoochMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Gooch material.
Definition: qgsgoochmaterialsettings.cpp:32
Qgs3D::~Qgs3D
~Qgs3D()
Definition: qgs3d.cpp:49
Qgs3D::initialize
static void initialize()
Initializes the 3D framework.
Definition: qgs3d.cpp:53
qgsline3dsymbol_p.h
Qgs3D
Qgs3D is a singleton class containing various registries and other global members related to 3D class...
Definition: qgs3d.h:33
qgspoint3dsymbol_p.h
QgsPhongMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
Definition: qgsphongmaterialsettings.cpp:33
Qgs3DSymbolMetadata
Convenience metadata class that uses static functions to create a 3D symbol and its widget.
Definition: qgs3dsymbolregistry.h:118
QgsRuleBased3DRendererMetadata
3 Metadata for rule-based 3D renderer to allow creation of its instances from XML
Definition: qgsrulebased3drenderer.h:41