Skip to content
Permalink
Browse files

3D material color data defined (#39683)

  • Loading branch information
vcloarec committed Nov 4, 2020
1 parent 0e758df commit b725a044ae3137d9d557a87817d026e76455a7b3
Showing with 1,131 additions and 108 deletions.
  1. +2 −2 python/3d/auto_generated/materials/qgsabstractmaterialsettings.sip.in
  2. +2 −0 python/3d/auto_generated/materials/qgsphongmaterialsettings.sip.in
  3. +1 −0 src/3d/CMakeLists.txt
  4. +76 −0 src/3d/materials/qgsabstractmaterialsettings.cpp
  5. +62 −2 src/3d/materials/qgsabstractmaterialsettings.h
  6. +148 −2 src/3d/materials/qgsgoochmaterialsettings.cpp
  7. +8 −0 src/3d/materials/qgsgoochmaterialsettings.h
  8. +121 −3 src/3d/materials/qgsphongmaterialsettings.cpp
  9. +16 −0 src/3d/materials/qgsphongmaterialsettings.h
  10. +6 −2 src/3d/materials/qgsphongtexturedmaterialsettings.cpp
  11. +0 −1 src/3d/mesh/qgsmesh3dentity_p.h
  12. +1 −1 src/3d/qgs3dutils.cpp
  13. +1 −1 src/3d/qgs3dutils.h
  14. +1 −1 src/3d/qgsfeature3dhandler_p.h
  15. +4 −0 src/3d/shaders.qrc
  16. +66 −0 src/3d/shaders/goochDataDefined.frag
  17. +37 −0 src/3d/shaders/goochDataDefined.vert
  18. +41 −0 src/3d/shaders/phongDataDefined.frag
  19. +43 −0 src/3d/shaders/phongDataDefined.vert
  20. +6 −6 src/3d/symbols/qgsline3dsymbol_p.cpp
  21. +6 −6 src/3d/symbols/qgspoint3dsymbol_p.cpp
  22. +18 −2 src/3d/symbols/qgspolygon3dsymbol_p.cpp
  23. +18 −1 src/app/3d/qgsgoochmaterialwidget.cpp
  24. +3 −2 src/app/3d/qgsmaterialwidget.cpp
  25. +1 −0 src/app/3d/qgsmaterialwidget.h
  26. +30 −1 src/app/3d/qgsphongmaterialwidget.cpp
  27. +85 −52 src/ui/3d/goochmaterialwidget.ui
  28. +49 −23 src/ui/3d/phongmaterialwidget.ui
  29. +2 −0 tests/src/3d/CMakeLists.txt
  30. +222 −0 tests/src/3d/testqgs3dmaterial.cpp
  31. +54 −0 tests/src/3d/testqgs3drendering.cpp
  32. +1 −0 tests/src/3d/testqgsmaterialregistry.cpp
  33. BIN ...d/expected_polygon3d_extrusion_data_defined/default/expected_polygon3d_extrusion_data_defined.png
  34. BIN ...3d/expected_polygon3d_extrusion_data_defined/travis/expected_polygon3d_extrusion_data_defined.png
@@ -124,12 +124,12 @@ Clones the material settings.
Caller takes ownership of the returned object.
%End

virtual void readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
virtual void readXml( const QDomElement &element, const QgsReadWriteContext & );
%Docstring
Reads settings from a DOM ``element``
%End

virtual void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const = 0;
virtual void writeXml( QDomElement &element, const QgsReadWriteContext & ) const;
%Docstring
Writes settings to a DOM ``element``
%End
@@ -10,6 +10,7 @@




class QgsPhongMaterialSettings : QgsAbstractMaterialSettings
{
%Docstring
@@ -92,6 +93,7 @@ Sets shininess of the surface
virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;



bool operator==( const QgsPhongMaterialSettings &other ) const;

};
@@ -47,6 +47,7 @@ SET(QGIS_3D_SRCS
chunks/qgschunknode_p.cpp
chunks/qgschunkqueuejob_p.cpp

materials/qgsabstractmaterialsettings.cpp
materials/qgsgoochmaterialsettings.cpp
materials/qgsmaterialregistry.cpp
materials/qgsphongmaterialsettings.cpp
@@ -0,0 +1,76 @@
/***************************************************************************
qgsabstractmaterialsettings.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 <qgsabstractmaterialsettings.h>

QgsPropertiesDefinition QgsAbstractMaterialSettings::sPropertyDefinitions;

void QgsAbstractMaterialSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
{
QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
if ( !elemDataDefinedProperties.isNull() )
mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
}

void QgsAbstractMaterialSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
{
QDomElement elemDataDefinedProperties = element.ownerDocument().createElement( QStringLiteral( "data-defined-properties" ) );
mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
element.appendChild( elemDataDefinedProperties );
}

void QgsAbstractMaterialSettings::setDataDefinedProperties( const QgsPropertyCollection &collection )
{
mDataDefinedProperties = collection;
}

QgsPropertyCollection QgsAbstractMaterialSettings::dataDefinedProperties() const {return mDataDefinedProperties;}

const QgsPropertiesDefinition &QgsAbstractMaterialSettings::propertyDefinitions() const
{
if ( sPropertyDefinitions.isEmpty() )
initPropertyDefinitions();
return sPropertyDefinitions;
}

QByteArray QgsAbstractMaterialSettings::dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const
{
Q_UNUSED( expressionContext )
return QByteArray();
}

void QgsAbstractMaterialSettings::applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const
{
Q_UNUSED( geometry )
Q_UNUSED( vertexCount )
Q_UNUSED( dataDefinedBytes )
}

void QgsAbstractMaterialSettings::initPropertyDefinitions() const
{
if ( !sPropertyDefinitions.isEmpty() )
return;

QString origin = QStringLiteral( "material3d" );

sPropertyDefinitions = QgsPropertiesDefinition
{
{ Diffuse, QgsPropertyDefinition( "diffuse", QObject::tr( "Diffuse" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
{ Ambient, QgsPropertyDefinition( "ambient", QObject::tr( "Ambient" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
{ Warm, QgsPropertyDefinition( "warm", QObject::tr( "Warm" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
{ Cool, QgsPropertyDefinition( "cool", QObject::tr( "Cool" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
{ Specular, QgsPropertyDefinition( "specular", QObject::tr( "Specular" ), QgsPropertyDefinition::ColorNoAlpha, origin ) }
};
}
@@ -21,11 +21,19 @@

#include <QColor>
#include <Qt3DRender/qmaterial.h>
#include "qgspropertycollection.h"

class QDomElement;
class QgsReadWriteContext;
class QgsLineMaterial;
class QgsExpressionContext;

#ifndef SIP_RUN
namespace Qt3DRender
{
class QGeometry;
}
#endif //SIP_RUN

/**
* Material rendering techniques
@@ -146,10 +154,10 @@ class _3D_EXPORT QgsAbstractMaterialSettings SIP_ABSTRACT
virtual QgsAbstractMaterialSettings *clone() const = 0 SIP_FACTORY;

//! Reads settings from a DOM \a element
virtual void readXml( const QDomElement &element, const QgsReadWriteContext &context ) = 0;
virtual void readXml( const QDomElement &element, const QgsReadWriteContext & );

//! Writes settings to a DOM \a element
virtual void writeXml( QDomElement &element, const QgsReadWriteContext &context ) const = 0;
virtual void writeXml( QDomElement &element, const QgsReadWriteContext & ) const;

#ifndef SIP_RUN

@@ -170,8 +178,60 @@ class _3D_EXPORT QgsAbstractMaterialSettings SIP_ABSTRACT
* Adds parameters from the material to a destination \a effect.
*/
virtual void addParametersToEffect( Qt3DRender::QEffect *effect ) const = 0;

//! Data definable properties.
enum Property
{
Diffuse, //!< Diffuse color
Ambient, //!< Ambient color (phong material)
Warm, //!< Warm color (gooch material)
Cool,//!< Cool color (gooch material)
Specular //!< Specular color
};

/**
* Sets the material property collection, used for data defined overrides.
* \since QGIS 3.18
*/
void setDataDefinedProperties( const QgsPropertyCollection &collection );

/**
* Returns the symbol material property collection, used for data defined overrides.
* \since QGIS 3.18
*/
QgsPropertyCollection dataDefinedProperties() const;

/**
* Returns a reference to the material properties definition, used for data defined overrides.
* \since QGIS 3.18
*/
const QgsPropertiesDefinition &propertyDefinitions() const;

/**
* Applies the data defined bytes, \a dataDefinedBytes, on the \a geometry by filling a specific vertex buffer that will be used by the shader.
* \since QGIS 3.18
*/
virtual void applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const;

/**
* Returns byte array corresponding to the data defined colors depending of the \a expressionContext,
* used to fill the specific vertex buffer used for rendering the geometry
* \see applyDataDefinedToGeometry()
* \since QGIS 3.18
*/
virtual QByteArray dataDefinedVertexColorsAsByte( const QgsExpressionContext &expressionContext ) const;

/**
* Returns byte stride of the data defined colors,used to fill the vertex colors data defined buffer for rendering
* \since QGIS 3.18
*/
virtual int dataDefinedByteStride() const {return 0;}
#endif

private:
QgsPropertyCollection mDataDefinedProperties;
static QgsPropertiesDefinition sPropertyDefinitions;
void initPropertyDefinitions() const;
};


0 comments on commit b725a04

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