Skip to content
Permalink
Browse files

[3d] Add a registry for 3d material settings

  • Loading branch information
nyalldawson committed Jul 28, 2020
1 parent bc96ffd commit d579d67a4a1d3d59638c4191d64221153b22d740
@@ -7,6 +7,7 @@
%Include auto_generated/qgsabstractvectorlayer3drenderer.sip
%Include auto_generated/qgscamerapose.sip
%Include auto_generated/qgslayoutitem3dmap.sip
%Include auto_generated/qgsmaterialregistry.sip
%Include auto_generated/qgsphongmaterialsettings.sip
%Include auto_generated/qgspointlightsettings.sip
%Include auto_generated/qgsdirectionallightsettings.sip
@@ -9,6 +9,7 @@




class Qgs3D
{
%Docstring
@@ -35,6 +36,11 @@ Returns a pointer to the singleton instance.
static void initialize();
%Docstring
Initializes the 3D framework.
%End

static QgsMaterialRegistry *materialRegistry();
%Docstring
Returns the material registry, used for managing 3D materials.
%End

private:
@@ -0,0 +1,117 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsmaterialregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsMaterialSettingsAbstractMetadata
{
%Docstring
Stores metadata about one 3D material settings class.

.. note::

It's necessary to implement :py:func:`~createMaterialSettings` function.
In C++ you can use QgsMaterialSettingsMetadata convenience class.

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsmaterialregistry.h"
%End
public:

QgsMaterialSettingsAbstractMetadata( const QString &type, const QString &visibleName );
%Docstring
Constructor for QgsMaterialSettingsAbstractMetadata, with the specified ``type`` and ``visibleName``.
%End

virtual ~QgsMaterialSettingsAbstractMetadata();

QString type() const;
%Docstring
Returns the unique material type string.
%End

QString visibleName() const;
%Docstring
Returns the material's visible (translated) name.
%End

virtual QgsAbstractMaterialSettings *create() = 0 /Factory/;
%Docstring
Creates a new instance of this material settings type.

Caller takes ownership of the returned object.
%End


};





class QgsMaterialRegistry
{
%Docstring
Registry of available 3d material settings classes.

QgsMaterialRegistry is not usually directly created, but rather accessed through
Qgs3D.materialRegistry().

.. versionadded:: 3.16
%End

%TypeHeaderCode
#include "qgsmaterialregistry.h"
%End
public:

QgsMaterialRegistry();
~QgsMaterialRegistry();


QgsMaterialSettingsAbstractMetadata *materialSettingsMetadata( const QString &type ) const;
%Docstring
Returns metadata for specified material settings ``type``. Returns ``None`` if not found
%End

QStringList materialSettingsTypes() const;
%Docstring
Returns a list of all available material settings types.
%End

bool addMaterialSettingsType( QgsMaterialSettingsAbstractMetadata *metadata /Transfer/ );
%Docstring
Registers a new material settings type. Takes ownership of the ``metadata`` instance.
%End

QgsAbstractMaterialSettings *createMaterialSettings( const QString &type ) const /Factory/;
%Docstring
Creates a new instance of the material settings of the specified ``type``.

The caller takes ownership of the returned object.

Returns ``None`` if the specified type is not found in the registry.
%End

private:
QgsMaterialRegistry( const QgsMaterialRegistry &rh );
};


/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsmaterialregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -32,6 +32,11 @@ with three color components: ambient, diffuse and specular.
QgsPhongMaterialSettings();
%Docstring
Constructor for QgsPhongMaterialSettings.
%End

static QgsAbstractMaterialSettings *create() /Factory/;
%Docstring
Returns a new instance of QgsPhongMaterialSettings.
%End

virtual QgsPhongMaterialSettings *clone() const /Factory/;
@@ -14,6 +14,7 @@ SET(QGIS_3D_SRCS
qgscamerapose.cpp
qgsfeature3dhandler_p.cpp
qgslayoutitem3dmap.cpp
qgsmaterialregistry.cpp
qgsoffscreen3dengine.cpp
qgsphongmaterialsettings.cpp
qgspointlightsettings.cpp
@@ -86,6 +87,7 @@ SET(QGIS_3D_HDRS
qgscameracontroller.h
qgscamerapose.h
qgslayoutitem3dmap.h
qgsmaterialregistry.h
qgsmeshlayer3drenderer.h
qgsoffscreen3dengine.h
qgsphongmaterialsettings.h
@@ -29,6 +29,7 @@
#include "qgspoint3dsymbol.h"
#include "qgsline3dsymbol.h"
#include "qgspolygon3dsymbol.h"
#include "qgsmaterialregistry.h"

#include "qgspolygon3dsymbol_p.h"
#include "qgspoint3dsymbol_p.h"
@@ -61,8 +62,17 @@ void Qgs3D::initialize()
&QgsLine3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForLine3DSymbol ) );
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
&QgsPolygon3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPolygon3DSymbol ) );

instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phong" ), QObject::tr( "Phong" ),
QgsPhongMaterialSettings::create, nullptr ) );
}

QgsMaterialRegistry *Qgs3D::materialRegistry()
{
return instance()->mMaterialRegistry;
}

Qgs3D::Qgs3D()
{
mMaterialRegistry = new QgsMaterialRegistry();
}
@@ -21,6 +21,8 @@
#include "qgis_3d.h"
#include "qgis_sip.h"

class QgsMaterialRegistry;

/**
* \ingroup gui
* Qgs3D is a singleton class containing various registries and other global members
@@ -50,6 +52,11 @@ class _3D_EXPORT Qgs3D
*/
static void initialize();

/**
* Returns the material registry, used for managing 3D materials.
*/
static QgsMaterialRegistry *materialRegistry();

private:

Qgs3D();
@@ -60,6 +67,8 @@ class _3D_EXPORT Qgs3D

bool mInitialized = false;

QgsMaterialRegistry *mMaterialRegistry = nullptr;

};

#endif // QGS3D_H
@@ -0,0 +1,53 @@
/***************************************************************************
qgsmaterialregistry.cpp
--------------------------------------
Date : July 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmaterialregistry.h"
#include "qgsabstractmaterialsettings.h"

QgsMaterialRegistry::QgsMaterialRegistry()
{
}

QgsMaterialRegistry::~QgsMaterialRegistry()
{
qDeleteAll( mMetadata );
}

bool QgsMaterialRegistry::addMaterialSettingsType( QgsMaterialSettingsAbstractMetadata *metadata )
{
if ( !metadata || mMetadata.contains( metadata->type() ) )
return false;

mMetadata[metadata->type()] = metadata;
return true;
}

QgsAbstractMaterialSettings *QgsMaterialRegistry::createMaterialSettings( const QString &type ) const
{
if ( !mMetadata.contains( type ) )
return nullptr;

return mMetadata[type]->create();
}

QgsMaterialSettingsAbstractMetadata *QgsMaterialRegistry::materialSettingsMetadata( const QString &type ) const
{
return mMetadata.value( type );
}

QStringList QgsMaterialRegistry::materialSettingsTypes() const
{
return mMetadata.keys();
}

0 comments on commit d579d67

Please sign in to comment.
You can’t perform that action at this time.