Skip to content
Permalink
Browse files

Merge pull request #40037 from nyalldawson/model_mat

Fix confusing UX for overridding model textures
  • Loading branch information
nyalldawson committed Nov 14, 2020
2 parents 9225441 + 17a4b07 commit 2c349b251251528c337748d33c28b635a6f045bc
@@ -14,6 +14,7 @@
%Include auto_generated/materials/qgsabstractmaterialsettings.sip
%Include auto_generated/materials/qgsgoochmaterialsettings.sip
%Include auto_generated/materials/qgsmaterialregistry.sip
%Include auto_generated/materials/qgsnullmaterialsettings.sip
%Include auto_generated/materials/qgsphongmaterialsettings.sip
%Include auto_generated/materials/qgsphongtexturedmaterialsettings.sip
%Include auto_generated/materials/qgssimplelinematerialsettings.sip
@@ -11,5 +11,7 @@
QgsAbstractMaterialSettings.Points.__doc__ = "Point based rendering, requires point data"
QgsAbstractMaterialSettings.TrianglesWithFixedTexture = QgsMaterialSettingsRenderingTechnique.TrianglesWithFixedTexture
QgsAbstractMaterialSettings.TrianglesWithFixedTexture.__doc__ = "Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering)"
QgsMaterialSettingsRenderingTechnique.__doc__ = 'Material rendering techniques\n\n.. versionadded:: 3.16\n\n' + '* ``Triangles``: ' + QgsMaterialSettingsRenderingTechnique.Triangles.__doc__ + '\n' + '* ``Lines``: ' + QgsMaterialSettingsRenderingTechnique.Lines.__doc__ + '\n' + '* ``InstancedPoints``: ' + QgsMaterialSettingsRenderingTechnique.InstancedPoints.__doc__ + '\n' + '* ``Points``: ' + QgsMaterialSettingsRenderingTechnique.Points.__doc__ + '\n' + '* ``TrianglesWithFixedTexture``: ' + QgsMaterialSettingsRenderingTechnique.TrianglesWithFixedTexture.__doc__
QgsAbstractMaterialSettings.TrianglesFromModel = QgsMaterialSettingsRenderingTechnique.TrianglesFromModel
QgsAbstractMaterialSettings.TrianglesFromModel.__doc__ = "Triangle based rendering, using a model object source"
QgsMaterialSettingsRenderingTechnique.__doc__ = 'Material rendering techniques\n\n.. versionadded:: 3.16\n\n' + '* ``Triangles``: ' + QgsMaterialSettingsRenderingTechnique.Triangles.__doc__ + '\n' + '* ``Lines``: ' + QgsMaterialSettingsRenderingTechnique.Lines.__doc__ + '\n' + '* ``InstancedPoints``: ' + QgsMaterialSettingsRenderingTechnique.InstancedPoints.__doc__ + '\n' + '* ``Points``: ' + QgsMaterialSettingsRenderingTechnique.Points.__doc__ + '\n' + '* ``TrianglesWithFixedTexture``: ' + QgsMaterialSettingsRenderingTechnique.TrianglesWithFixedTexture.__doc__ + '\n' + '* ``TrianglesFromModel``: ' + QgsMaterialSettingsRenderingTechnique.TrianglesFromModel.__doc__
# --
@@ -18,6 +18,7 @@ enum class QgsMaterialSettingsRenderingTechnique
InstancedPoints,
Points,
TrianglesWithFixedTexture,
TrianglesFromModel,
};


@@ -103,6 +104,10 @@ Abstract base class for material settings.
{
sipType = sipType_QgsSimpleLineMaterialSettings;
}
else if ( sipCpp->type() == "null" )
{
sipType = sipType_QgsNullMaterialSettings;
}
else
{
sipType = 0;
@@ -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 *
************************************************************************/
@@ -50,6 +50,7 @@ set(QGIS_3D_SRCS
materials/qgsabstractmaterialsettings.cpp
materials/qgsgoochmaterialsettings.cpp
materials/qgsmaterialregistry.cpp
materials/qgsnullmaterialsettings.cpp
materials/qgsphongmaterialsettings.cpp
materials/qgsphongtexturedmaterialsettings.cpp
materials/qgssimplelinematerialsettings.cpp
@@ -125,6 +126,7 @@ set(QGIS_3D_HDRS
materials/qgsabstractmaterialsettings.h
materials/qgsgoochmaterialsettings.h
materials/qgsmaterialregistry.h
materials/qgsnullmaterialsettings.h
materials/qgsphongmaterialsettings.h
materials/qgsphongtexturedmaterialsettings.h
materials/qgssimplelinematerialsettings.h
@@ -47,6 +47,7 @@ enum class QgsMaterialSettingsRenderingTechnique SIP_MONKEYPATCH_SCOPEENUM_UNNES
InstancedPoints, //!< Instanced based rendering, requiring triangles and point data
Points, //!< Point based rendering, requires point data
TrianglesWithFixedTexture, //!< Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering)
TrianglesFromModel, //!< Triangle based rendering, using a model object source
};


@@ -130,6 +131,10 @@ class _3D_EXPORT QgsAbstractMaterialSettings SIP_ABSTRACT
{
sipType = sipType_QgsSimpleLineMaterialSettings;
}
else if ( sipCpp->type() == "null" )
{
sipType = sipType_QgsNullMaterialSettings;
}
else
{
sipType = 0;
@@ -42,6 +42,7 @@ bool QgsGoochMaterialSettings::supportsTechnique( QgsMaterialSettingsRenderingTe
{
case QgsMaterialSettingsRenderingTechnique::Triangles:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
return true;

case QgsMaterialSettingsRenderingTechnique::Lines:
@@ -94,6 +95,7 @@ Qt3DRender::QMaterial *QgsGoochMaterialSettings::toMaterial( QgsMaterialSettings
{
case QgsMaterialSettingsRenderingTechnique::Triangles:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
{
if ( dataDefinedProperties().hasActiveProperties() )
return dataDefinedMaterial();
@@ -31,6 +31,7 @@ bool QgsMaterialRegistry::addMaterialSettingsType( QgsMaterialSettingsAbstractMe
return false;

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

@@ -49,5 +50,11 @@ QgsMaterialSettingsAbstractMetadata *QgsMaterialRegistry::materialSettingsMetada

QStringList QgsMaterialRegistry::materialSettingsTypes() const
{
return mMetadata.keys();
QStringList types;
for ( const QString &material : mMaterialsOrder )
{
if ( mMetadata.value( material ) )
types << material;
}
return types;
}
@@ -220,6 +220,8 @@ class _3D_EXPORT QgsMaterialRegistry
#endif

QMap<QString, QgsMaterialSettingsAbstractMetadata *> mMetadata;
//! List of materials, maintained in the order that they have been added
QStringList mMaterialsOrder;
};


@@ -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
{
}
@@ -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
@@ -43,6 +43,7 @@ bool QgsPhongMaterialSettings::supportsTechnique( QgsMaterialSettingsRenderingTe
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
return true;

case QgsMaterialSettingsRenderingTechnique::Lines:
@@ -90,6 +91,7 @@ Qt3DRender::QMaterial *QgsPhongMaterialSettings::toMaterial( QgsMaterialSettings
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
{
if ( dataDefinedProperties().hasActiveProperties() )
return dataDefinedMaterial();
@@ -41,6 +41,7 @@ bool QgsPhongTexturedMaterialSettings::supportsTechnique( QgsMaterialSettingsRen

case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Lines:
return false;
@@ -118,6 +119,7 @@ Qt3DRender::QMaterial *QgsPhongTexturedMaterialSettings::toMaterial( QgsMaterial
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
{
bool fitsInCache = false;
QImage textureSourceImage = QgsApplication::imageCache()->pathAsImage( mDiffuseTexturePath, QSize(), true, 1.0, fitsInCache );
@@ -38,6 +38,7 @@ bool QgsSimpleLineMaterialSettings::supportsTechnique( QgsMaterialSettingsRender
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
return false;
}
return false;
@@ -71,6 +72,7 @@ Qt3DRender::QMaterial *QgsSimpleLineMaterialSettings::toMaterial( QgsMaterialSet
case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
case QgsMaterialSettingsRenderingTechnique::Points:
case QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture:
case QgsMaterialSettingsRenderingTechnique::TrianglesFromModel:
return nullptr;

case QgsMaterialSettingsRenderingTechnique::Lines:
@@ -38,6 +38,7 @@
#include "qgsgoochmaterialsettings.h"
#include "qgssimplelinematerialsettings.h"
#include "qgsphongtexturedmaterialsettings.h"
#include "qgsnullmaterialsettings.h"

#include "qgsstyle.h"

@@ -70,6 +71,8 @@ void Qgs3D::initialize()
QgsApplication::symbol3DRegistry()->addSymbolType( new Qgs3DSymbolMetadata( QStringLiteral( "polygon" ), QObject::tr( "Polygon" ),
&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)" ),
QgsPhongMaterialSettings::create, QgsPhongMaterialSettings::supportsTechnique, nullptr, QgsApplication::getThemeIcon( QStringLiteral( "/mIconPhongMaterial.svg" ) ) ) );
instance()->materialRegistry()->addMaterialSettingsType( new QgsMaterialSettingsMetadata( QStringLiteral( "phongtextured" ), QObject::tr( "Realistic Textured (Phong)" ),
@@ -413,7 +413,9 @@ void QgsModelPoint3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
}
else
{
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool() )
// "overwriteMaterial" is a legacy setting indicating that non-embedded material should be used
if ( mSymbol->shapeProperties()[QStringLiteral( "overwriteMaterial" )].toBool()
|| ( mSymbol->material() && mSymbol->material()->type() != QLatin1String( "null" ) ) )
{
addMeshEntities( context.map(), out.positions, mSymbol.get(), parent, false );
}

0 comments on commit 2c349b2

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