Skip to content

Commit

Permalink
[3d] Add new material type "QgsNullMaterialSettings"
Browse files Browse the repository at this point in the history
This is a "null" shading material which should be used when
rendering models or scenes with native textures and no material
should be explicitly set on the loaded entities.
  • Loading branch information
nyalldawson committed Nov 13, 2020
1 parent 6224ea9 commit 2dcbf95
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/3d/3d_auto.sip
Expand Up @@ -14,6 +14,7 @@
%Include auto_generated/materials/qgsabstractmaterialsettings.sip %Include auto_generated/materials/qgsabstractmaterialsettings.sip
%Include auto_generated/materials/qgsgoochmaterialsettings.sip %Include auto_generated/materials/qgsgoochmaterialsettings.sip
%Include auto_generated/materials/qgsmaterialregistry.sip %Include auto_generated/materials/qgsmaterialregistry.sip
%Include auto_generated/materials/qgsnullmaterialsettings.sip
%Include auto_generated/materials/qgsphongmaterialsettings.sip %Include auto_generated/materials/qgsphongmaterialsettings.sip
%Include auto_generated/materials/qgsphongtexturedmaterialsettings.sip %Include auto_generated/materials/qgsphongtexturedmaterialsettings.sip
%Include auto_generated/materials/qgssimplelinematerialsettings.sip %Include auto_generated/materials/qgssimplelinematerialsettings.sip
Expand Down
Expand Up @@ -104,6 +104,10 @@ Abstract base class for material settings.
{ {
sipType = sipType_QgsSimpleLineMaterialSettings; sipType = sipType_QgsSimpleLineMaterialSettings;
} }
else if ( sipCpp->type() == "null" )
{
sipType = sipType_QgsNullMaterialSettings;
}
else else
{ {
sipType = 0; sipType = 0;
Expand Down
65 changes: 65 additions & 0 deletions python/3d/auto_generated/materials/qgsnullmaterialsettings.sip.in
@@ -0,0 +1,65 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/materials/qgsnullmaterialsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsNullMaterialSettings : QgsAbstractMaterialSettings
{
%Docstring
Null shading material used for rendering models and scenes with native textures.

.. warning::

This is not considered stable API, and may change in future QGIS releases. It is
exposed to the Python bindings as a tech preview only.

.. versionadded:: 3.16.2
%End

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

QgsNullMaterialSettings();
%Docstring
Constructor for QgsNullMaterialSettings.
%End

virtual QString type() const;


static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );
%Docstring
Returns ``True`` if the specified ``technique`` is supported by the material.
%End

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

virtual QgsNullMaterialSettings *clone() const /Factory/;


virtual QMap<QString, QString> toExportParameters() const;


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/materials/qgsnullmaterialsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2 changes: 2 additions & 0 deletions src/3d/CMakeLists.txt
Expand Up @@ -50,6 +50,7 @@ set(QGIS_3D_SRCS
materials/qgsabstractmaterialsettings.cpp materials/qgsabstractmaterialsettings.cpp
materials/qgsgoochmaterialsettings.cpp materials/qgsgoochmaterialsettings.cpp
materials/qgsmaterialregistry.cpp materials/qgsmaterialregistry.cpp
materials/qgsnullmaterialsettings.cpp
materials/qgsphongmaterialsettings.cpp materials/qgsphongmaterialsettings.cpp
materials/qgsphongtexturedmaterialsettings.cpp materials/qgsphongtexturedmaterialsettings.cpp
materials/qgssimplelinematerialsettings.cpp materials/qgssimplelinematerialsettings.cpp
Expand Down Expand Up @@ -125,6 +126,7 @@ set(QGIS_3D_HDRS
materials/qgsabstractmaterialsettings.h materials/qgsabstractmaterialsettings.h
materials/qgsgoochmaterialsettings.h materials/qgsgoochmaterialsettings.h
materials/qgsmaterialregistry.h materials/qgsmaterialregistry.h
materials/qgsnullmaterialsettings.h
materials/qgsphongmaterialsettings.h materials/qgsphongmaterialsettings.h
materials/qgsphongtexturedmaterialsettings.h materials/qgsphongtexturedmaterialsettings.h
materials/qgssimplelinematerialsettings.h materials/qgssimplelinematerialsettings.h
Expand Down
4 changes: 4 additions & 0 deletions src/3d/materials/qgsabstractmaterialsettings.h
Expand Up @@ -131,6 +131,10 @@ class _3D_EXPORT QgsAbstractMaterialSettings SIP_ABSTRACT
{ {
sipType = sipType_QgsSimpleLineMaterialSettings; sipType = sipType_QgsSimpleLineMaterialSettings;
} }
else if ( sipCpp->type() == "null" )
{
sipType = sipType_QgsNullMaterialSettings;
}
else else
{ {
sipType = 0; sipType = 0;
Expand Down
65 changes: 65 additions & 0 deletions src/3d/materials/qgsnullmaterialsettings.cpp
@@ -0,0 +1,65 @@
/***************************************************************************
qgsnullmaterialsettings.cpp
--------------------------------------
Date : November 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 "qgsnullmaterialsettings.h"
#include <QMap>


QString QgsNullMaterialSettings::type() const
{
return QStringLiteral( "null" );
}

bool QgsNullMaterialSettings::supportsTechnique( QgsMaterialSettingsRenderingTechnique technique )
{
switch ( technique )
{
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
return true;

case QgsMaterialSettingsRenderingTechnique::Triangles:
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::Lines:
return false;
}
return false;
}

QgsAbstractMaterialSettings *QgsNullMaterialSettings::create()
{
return new QgsNullMaterialSettings();
}

QgsNullMaterialSettings *QgsNullMaterialSettings::clone() const
{
return new QgsNullMaterialSettings( *this );
}

Qt3DRender::QMaterial *QgsNullMaterialSettings::toMaterial( QgsMaterialSettingsRenderingTechnique, const QgsMaterialContext & ) const
{
return nullptr;
}

QMap<QString, QString> QgsNullMaterialSettings::toExportParameters() const
{
QMap<QString, QString> parameters;
return parameters;
}

void QgsNullMaterialSettings::addParametersToEffect( Qt3DRender::QEffect * ) const
{
}
68 changes: 68 additions & 0 deletions src/3d/materials/qgsnullmaterialsettings.h
@@ -0,0 +1,68 @@
/***************************************************************************
qgsnullmaterialsettings.h
--------------------------------------
Date : November 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. *
* *
***************************************************************************/


#ifndef QGSNULLMATERIALSETTINGS_H
#define QGSNULLMATERIALSETTINGS_H

#include "qgis_3d.h"
#include "qgsabstractmaterialsettings.h"

#include <QColor>

class QDomElement;

/**
* \ingroup 3d
* Null shading material used for rendering models and scenes with native textures.
*
* \warning This is not considered stable API, and may change in future QGIS releases. It is
* exposed to the Python bindings as a tech preview only.
*
* \since QGIS 3.16.2
*/
class _3D_EXPORT QgsNullMaterialSettings : public QgsAbstractMaterialSettings
{
public:

/**
* Constructor for QgsNullMaterialSettings.
*/
QgsNullMaterialSettings() = default;

QString type() const override;

/**
* Returns TRUE if the specified \a technique is supported by the material.
*/
static bool supportsTechnique( QgsMaterialSettingsRenderingTechnique technique );

/**
* Returns a new instance of QgsNullMaterialSettings.
*/
static QgsAbstractMaterialSettings *create() SIP_FACTORY;

QgsNullMaterialSettings *clone() const override SIP_FACTORY;

QMap<QString, QString> toExportParameters() const override;
#ifndef SIP_RUN
Qt3DRender::QMaterial *toMaterial( QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context ) const override SIP_FACTORY;
void addParametersToEffect( Qt3DRender::QEffect *effect ) const override;
#endif

};


#endif // QGSNULLMATERIALSETTINGS_H
3 changes: 3 additions & 0 deletions src/3d/qgs3d.cpp
Expand Up @@ -38,6 +38,7 @@
#include "qgsgoochmaterialsettings.h" #include "qgsgoochmaterialsettings.h"
#include "qgssimplelinematerialsettings.h" #include "qgssimplelinematerialsettings.h"
#include "qgsphongtexturedmaterialsettings.h" #include "qgsphongtexturedmaterialsettings.h"
#include "qgsnullmaterialsettings.h"


#include "qgsstyle.h" #include "qgsstyle.h"


Expand Down Expand Up @@ -70,6 +71,8 @@ void Qgs3D::initialize()
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ), QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
&QgsPolygon3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPolygon3DSymbol ) ); &QgsPolygon3DSymbol::create, nullptr, Qgs3DSymbolImpl::handlerForPolygon3DSymbol ) );


instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "null" ), QObject::tr( "Embedded Textures" ),
QgsNullMaterialSettings::create, QgsNullMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconPhongTexturedMaterial.svg" ) ) ) );
instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phong" ), QObject::tr( "Realistic (Phong)" ), instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phong" ), QObject::tr( "Realistic (Phong)" ),
QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconPhongMaterial.svg" ) ) ) ); QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconPhongMaterial.svg" ) ) ) );
instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phongtextured" ), QObject::tr( "Realistic Textured (Phong)" ), instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phongtextured" ), QObject::tr( "Realistic Textured (Phong)" ),
Expand Down
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dapputils.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsphongtexturedmaterialwidget.h" #include "qgsphongtexturedmaterialwidget.h"
#include "qgsgoochmaterialwidget.h" #include "qgsgoochmaterialwidget.h"
#include "qgssimplelinematerialwidget.h" #include "qgssimplelinematerialwidget.h"
#include "qgsnullmaterialwidget.h"
#include "qgs3dicongenerator.h" #include "qgs3dicongenerator.h"


void Qgs3DAppUtils::initialize() void Qgs3DAppUtils::initialize()
Expand All @@ -33,6 +34,7 @@ void Qgs3DAppUtils::initialize()
dynamic_cast< Qgs3DSymbolMetadata * >( QgsApplication::symbol3DRegistry()->symbolMetadata( QStringLiteral( "line" ) ) )->setWidgetFunction( QgsLine3DSymbolWidget::create ); dynamic_cast< Qgs3DSymbolMetadata * >( QgsApplication::symbol3DRegistry()->symbolMetadata( QStringLiteral( "line" ) ) )->setWidgetFunction( QgsLine3DSymbolWidget::create );
dynamic_cast< Qgs3DSymbolMetadata * >( QgsApplication::symbol3DRegistry()->symbolMetadata( QStringLiteral( "polygon" ) ) )->setWidgetFunction( QgsPolygon3DSymbolWidget::create ); dynamic_cast< Qgs3DSymbolMetadata * >( QgsApplication::symbol3DRegistry()->symbolMetadata( QStringLiteral( "polygon" ) ) )->setWidgetFunction( QgsPolygon3DSymbolWidget::create );


dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "null" ) ) )->setWidgetFunction( QgsNullMaterialWidget::create );
dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "phong" ) ) )->setWidgetFunction( QgsPhongMaterialWidget::create ); dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "phong" ) ) )->setWidgetFunction( QgsPhongMaterialWidget::create );
dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "phongtextured" ) ) )->setWidgetFunction( QgsPhongTexturedMaterialWidget::create ); dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "phongtextured" ) ) )->setWidgetFunction( QgsPhongTexturedMaterialWidget::create );
dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "gooch" ) ) )->setWidgetFunction( QgsGoochMaterialWidget::create ); dynamic_cast< QgsMaterialSettingsMetadata * >( Qgs3D::materialRegistry()->materialSettingsMetadata( QStringLiteral( "gooch" ) ) )->setWidgetFunction( QgsGoochMaterialWidget::create );
Expand Down
39 changes: 39 additions & 0 deletions src/app/3d/qgsnullmaterialwidget.cpp
@@ -0,0 +1,39 @@
/***************************************************************************
qgsnullmaterialwidget.cpp
--------------------------------------
Date : November 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 "qgsnullmaterialwidget.h"

#include "qgsnullmaterialsettings.h"
#include "qgis.h"

QgsNullMaterialWidget::QgsNullMaterialWidget( QWidget *parent )
: QgsMaterialSettingsWidget( parent )
{
setupUi( this );
}

QgsMaterialSettingsWidget *QgsNullMaterialWidget::create()
{
return new QgsNullMaterialWidget();
}

void QgsNullMaterialWidget::setSettings( const QgsAbstractMaterialSettings *, QgsVectorLayer * )
{
}

QgsAbstractMaterialSettings *QgsNullMaterialWidget::settings()
{
return new QgsNullMaterialSettings();
}
39 changes: 39 additions & 0 deletions src/app/3d/qgsnullmaterialwidget.h
@@ -0,0 +1,39 @@
/***************************************************************************
qgsnullmaterialwidget.h
--------------------------------------
Date : November 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. *
* *
***************************************************************************/

#ifndef QGSNULLMATERIALWIDGET_H
#define QGSNULLMATERIALWIDGET_H

#include "qgsmaterialsettingswidget.h"

#include <ui_nullmaterialwidget.h>

class QgsNullMaterialSettings;


//! Widget for configuration of null material settings
class QgsNullMaterialWidget : public QgsMaterialSettingsWidget, private Ui::NullMaterialWidget
{
Q_OBJECT
public:
explicit QgsNullMaterialWidget( QWidget *parent = nullptr );

static QgsMaterialSettingsWidget *create();
void setSettings( const QgsAbstractMaterialSettings *settings, QgsVectorLayer *layer ) override;
QgsAbstractMaterialSettings *settings() override;

};

#endif // QGSNULLMATERIALWIDGET_H
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -273,6 +273,7 @@ if (WITH_3D)
3d/qgsline3dsymbolwidget.cpp 3d/qgsline3dsymbolwidget.cpp
3d/qgsmaterialwidget.cpp 3d/qgsmaterialwidget.cpp
3d/qgsmesh3dsymbolwidget.cpp 3d/qgsmesh3dsymbolwidget.cpp
3d/qgsnullmaterialwidget.cpp
3d/qgspoint3dsymbolwidget.cpp 3d/qgspoint3dsymbolwidget.cpp
3d/qgspolygon3dsymbolwidget.cpp 3d/qgspolygon3dsymbolwidget.cpp
3d/qgsphongmaterialwidget.cpp 3d/qgsphongmaterialwidget.cpp
Expand Down
28 changes: 28 additions & 0 deletions src/ui/3d/nullmaterialwidget.ui
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NullMaterialWidget</class>
<widget class="QWidget" name="NullMaterialWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>394</width>
<height>242</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblAmbient">
<property name="text">
<string>Embedded textures from source model will be used.</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 2dcbf95

Please sign in to comment.