Skip to content
Permalink
Browse files

[3d] Abstract out material settings

Opens the possibilities for non-phong based materials for 3d symbols
  • Loading branch information
nyalldawson committed Jul 24, 2020
1 parent a345ae9 commit f2e4ac606e88f7fe1cfece080fdc3b7a51b31ff0
Showing with 840 additions and 389 deletions.
  1. +1 −0 python/3d/3d_auto.sip
  2. +108 −0 python/3d/auto_generated/qgsabstractmaterialsettings.sip.in
  3. +8 −9 python/3d/auto_generated/qgsphongmaterialsettings.sip.in
  4. +8 −4 python/3d/auto_generated/symbols/qgsline3dsymbol.sip.in
  5. +8 −4 python/3d/auto_generated/symbols/qgspoint3dsymbol.sip.in
  6. +9 −4 python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in
  7. +5 −0 python/core/auto_generated/3d/qgsabstract3dsymbol.sip.in
  8. +1 −0 src/3d/CMakeLists.txt
  9. +18 −19 src/3d/mesh/qgsmesh3dentity_p.cpp
  10. +4 −4 src/3d/mesh/qgsmesh3dentity_p.h
  11. +20 −22 src/3d/mesh/qgsmesh3dgeometry_p.cpp
  12. +3 −3 src/3d/mesh/qgsmesh3dgeometry_p.h
  13. +22 −22 src/3d/mesh/qgsmesh3dmaterial_p.cpp
  14. +2 −2 src/3d/mesh/qgsmesh3dmaterial_p.h
  15. +23 −12 src/3d/mesh/qgsmeshterraingenerator.cpp
  16. +6 −6 src/3d/mesh/qgsmeshterraingenerator.h
  17. +1 −1 src/3d/qgs3dmapscene.cpp
  18. +2 −2 src/3d/qgs3dmapsettings.cpp
  19. +127 −0 src/3d/qgsabstractmaterialsettings.h
  20. +1 −1 src/3d/qgsmeshlayer3drenderer.cpp
  21. +119 −2 src/3d/qgsphongmaterialsettings.cpp
  22. +11 −5 src/3d/qgsphongmaterialsettings.h
  23. +34 −4 src/3d/symbols/qgsline3dsymbol.cpp
  24. +13 −7 src/3d/symbols/qgsline3dsymbol.h
  25. +12 −35 src/3d/symbols/qgsline3dsymbol_p.cpp
  26. +50 −4 src/3d/symbols/qgsmesh3dsymbol.cpp
  27. +14 −7 src/3d/symbols/qgsmesh3dsymbol.h
  28. +5 −9 src/3d/symbols/qgsmesh3dsymbol_p.cpp
  29. +1 −1 src/3d/symbols/qgsmesh3dsymbol_p.h
  30. +19 −5 src/3d/symbols/qgspoint3dsymbol.cpp
  31. +12 −6 src/3d/symbols/qgspoint3dsymbol.h
  32. +5 −21 src/3d/symbols/qgspoint3dsymbol_p.cpp
  33. +38 −3 src/3d/symbols/qgspolygon3dsymbol.cpp
  34. +14 −7 src/3d/symbols/qgspolygon3dsymbol.h
  35. +17 −83 src/3d/symbols/qgspolygon3dsymbol_p.cpp
  36. +4 −4 src/app/3d/qgs3dmapconfigwidget.cpp
  37. +3 −3 src/app/3d/qgs3dmaptoolmeasureline.cpp
  38. +4 −3 src/app/3d/qgsline3dsymbolwidget.cpp
  39. +2 −0 src/app/3d/qgsline3dsymbolwidget.h
  40. +41 −41 src/app/3d/qgsmesh3dsymbolwidget.cpp
  41. +3 −3 src/app/3d/qgsmesh3dsymbolwidget.h
  42. +2 −2 src/app/3d/qgsmeshlayer3drendererwidget.cpp
  43. +4 −2 src/app/3d/qgspoint3dsymbolwidget.cpp
  44. +5 −3 src/app/3d/qgspolygon3dsymbolwidget.cpp
  45. +4 −1 src/app/3d/qgsrulebased3drendererwidget.cpp
  46. +6 −5 src/app/3d/qgssymbol3dwidget.cpp
  47. +2 −1 src/app/3d/qgssymbol3dwidget.h
  48. +4 −2 src/app/3d/qgsvectorlayer3drendererwidget.cpp
  49. +1 −1 src/app/3d/qgsvectorlayer3drendererwidget.h
  50. +5 −0 src/core/3d/qgsabstract3dsymbol.cpp
  51. +5 −0 src/core/3d/qgsabstract3dsymbol.h
  52. +4 −4 tests/src/3d/testqgs3drendering.cpp
@@ -3,6 +3,7 @@
%Include auto_generated/qgs3d.sip
%Include auto_generated/qgs3dmapsettings.sip
%Include auto_generated/qgs3dtypes.sip
%Include auto_generated/qgsabstractmaterialsettings.sip
%Include auto_generated/qgsabstractvectorlayer3drenderer.sip
%Include auto_generated/qgscamerapose.sip
%Include auto_generated/qgslayoutitem3dmap.sip
@@ -0,0 +1,108 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsabstractmaterialsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsMaterialContext
{
%Docstring
Context settings for a material.

.. 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
%End

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

bool isSelected() const;
%Docstring
Returns ``True`` if the material should represent a selected state.

.. seealso:: :py:func:`setIsSelected`
%End

void setIsSelected( bool isSelected );
%Docstring
Sets whether the material should represent a selected state.

.. seealso:: :py:func:`isSelected`
%End

QColor selectionColor() const;
%Docstring
Returns the color for representing materials in a selected state.

.. seealso:: :py:func:`setSelectionColor`
%End

void setSelectionColor( const QColor &color );
%Docstring
Sets the color for representing materials in a selected state.

.. seealso:: :py:func:`selectionColor`
%End

};

class QgsAbstractMaterialSettings /Abstract/
{
%Docstring
Abstract base class for material settings.

.. 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.0
%End

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

virtual ~QgsAbstractMaterialSettings();

virtual QgsAbstractMaterialSettings *clone() const = 0 /Factory/;
%Docstring
Clones the material settings.

Caller takes ownership of the returned object.
%End

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

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


};


/************************************************************************
* This file has been generated automatically from *
* *
* src/3d/qgsabstractmaterialsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -10,7 +10,7 @@



class QgsPhongMaterialSettings
class QgsPhongMaterialSettings : QgsAbstractMaterialSettings
{
%Docstring
Basic shading material used for rendering based on the Phong shading model
@@ -34,6 +34,9 @@ with three color components: ambient, diffuse and specular.
Constructor for QgsPhongMaterialSettings.
%End

virtual QgsPhongMaterialSettings *clone() const /Factory/;


QColor ambient() const;
%Docstring
Returns ambient color component
@@ -162,14 +165,10 @@ If the texture scale is less than 1 the texture will be stretched
Sets the texture rotation in degrees
%End

void readXml( const QDomElement &elem );
%Docstring
Reads settings from a DOM element
%End
void writeXml( QDomElement &elem ) const;
%Docstring
Writes settings to a DOM element
%End
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );

virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;


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

@@ -10,7 +10,7 @@



class QgsLine3DSymbol : QgsAbstract3DSymbol
class QgsLine3DSymbol : QgsAbstract3DSymbol /NoDefaultCtors/
{
%Docstring
3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer with given thickness).
@@ -31,6 +31,7 @@ class QgsLine3DSymbol : QgsAbstract3DSymbol
%Docstring
Constructor for QgsLine3DSymbol
%End
~QgsLine3DSymbol();

static QgsAbstract3DSymbol *create() /Factory/;
%Docstring
@@ -102,13 +103,16 @@ Returns whether the renderer will render data with simple lines (otherwise it us
Sets whether the renderer will render data with simple lines (otherwise it uses buffer)
%End

QgsPhongMaterialSettings material() const;
QgsAbstractMaterialSettings *material() const;
%Docstring
Returns material used for shading of the symbol
%End
void setMaterial( const QgsPhongMaterialSettings &material );

void setMaterial( QgsAbstractMaterialSettings *material /Transfer/ );
%Docstring
Sets material used for shading of the symbol
Sets the ``material`` settings used for shading of the symbol.

Ownership of ``material`` is transferred to the symbol.
%End

};
@@ -10,7 +10,8 @@



class QgsPoint3DSymbol : QgsAbstract3DSymbol

class QgsPoint3DSymbol : QgsAbstract3DSymbol /NoDefaultCtors/
{
%Docstring
3D symbol that draws point geometries as 3D objects using one of the predefined shapes.
@@ -62,13 +63,16 @@ Returns method that determines altitude (whether to clamp to feature to terrain)
Sets method that determines altitude (whether to clamp to feature to terrain)
%End

QgsPhongMaterialSettings material() const;
QgsAbstractMaterialSettings *material() const;
%Docstring
Returns material used for shading of the symbol
%End
void setMaterial( const QgsPhongMaterialSettings &material );

void setMaterial( QgsAbstractMaterialSettings *material /Transfer/ );
%Docstring
Sets material used for shading of the symbol
Sets the ``material`` settings used for shading of the symbol.

Ownership of ``material`` is transferred to the symbol.
%End

enum Shape
@@ -10,7 +10,8 @@



class QgsPolygon3DSymbol : QgsAbstract3DSymbol

class QgsPolygon3DSymbol : QgsAbstract3DSymbol /NoDefaultCtors/
{
%Docstring
3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls).
@@ -31,6 +32,7 @@ class QgsPolygon3DSymbol : QgsAbstract3DSymbol
%Docstring
Constructor for QgsPolygon3DSymbol
%End
~QgsPolygon3DSymbol();

virtual QString type() const;
virtual QgsAbstract3DSymbol *clone() const /Factory/;
@@ -84,13 +86,16 @@ Returns extrusion height (in map units)
Sets extrusion height (in map units)
%End

QgsPhongMaterialSettings material() const;
QgsAbstractMaterialSettings *material() const;
%Docstring
Returns material used for shading of the symbol
%End
void setMaterial( const QgsPhongMaterialSettings &material );

void setMaterial( QgsAbstractMaterialSettings *material /Transfer/ );
%Docstring
Sets material used for shading of the symbol
Sets the ``material`` settings used for shading of the symbol.

Ownership of ``material`` is transferred to the symbol.
%End

Qgs3DTypes::CullingMode cullingMode() const;
@@ -80,6 +80,11 @@ Sets the symbol layer's property collection, used for data defined overrides.

protected:

void copyBaseSettings( QgsAbstract3DSymbol *destination ) const;
%Docstring
Copies base class settings from this object to a ``destination`` object.
%End

};


@@ -81,6 +81,7 @@ SET(QGIS_3D_HDRS
qgs3dutils.h
qgsaabb.h
qgsabstract3dengine.h
qgsabstractmaterialsettings.h
qgsabstractvectorlayer3drenderer.h
qgscameracontroller.h
qgscamerapose.h
@@ -28,17 +28,16 @@



QgsMesh3dEntity::QgsMesh3dEntity( const Qgs3DMapSettings &map, QgsMeshLayer *meshLayer, const QgsMesh3DSymbol &symbol ):
mMapSettings( map ),
mLayerRef( meshLayer ),
mSymbol( symbol )
QgsMesh3dEntity::QgsMesh3dEntity( const Qgs3DMapSettings &map, QgsMeshLayer *meshLayer, const QgsMesh3DSymbol *symbol )
: mMapSettings( map )
, mLayerRef( meshLayer )
, mSymbol( symbol->clone() )
{}

QgsMeshDataset3dEntity::QgsMeshDataset3dEntity(
const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol &symbol ):
QgsMesh3dEntity( map, meshLayer, symbol )
QgsMeshDataset3dEntity::QgsMeshDataset3dEntity( const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol *symbol )
: QgsMesh3dEntity( map, meshLayer, symbol )
{}

void QgsMesh3dEntity::build()
@@ -53,30 +52,30 @@ void QgsMeshDataset3dEntity::buildGeometry()
return;

Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;
mesh->setGeometry( new QgsMeshDataset3dGeometry( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol, mesh ) );
mesh->setGeometry( new QgsMeshDataset3dGeometry( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol.get(), mesh ) );
addComponent( mesh );
}

void QgsMeshDataset3dEntity::applyMaterial()
{
if ( mSymbol.renderingStyle() == QgsMesh3DSymbol::ColorRamp2DRendering && layer() )
if ( mSymbol->renderingStyle() == QgsMesh3DSymbol::ColorRamp2DRendering && layer() )
{
const QgsMeshRendererSettings rendererSettings = layer()->rendererSettings();
int datasetGroupIndex = rendererSettings.activeScalarDatasetGroup();
if ( datasetGroupIndex >= 0 )
mSymbol.setColorRampShader( rendererSettings.scalarSettings( datasetGroupIndex ).colorRampShader() );
mSymbol->setColorRampShader( rendererSettings.scalarSettings( datasetGroupIndex ).colorRampShader() );
}
QgsMesh3dMaterial *material = new QgsMesh3dMaterial( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol, QgsMesh3dMaterial::ScalarDataSet );
QgsMesh3dMaterial *material = new QgsMesh3dMaterial( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol.get(), QgsMesh3dMaterial::ScalarDataSet );
addComponent( material );
}

QgsMesh3dTerrainTileEntity::QgsMesh3dTerrainTileEntity( const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol &symbol,
const QgsMesh3DSymbol *symbol,
QgsChunkNodeId nodeId,
Qt3DCore::QNode *parent ):
QgsMesh3dEntity( map, meshLayer, symbol ),
QgsTerrainTileEntity( nodeId, parent )
Qt3DCore::QNode *parent )
: QgsMesh3dEntity( map, meshLayer, symbol )
, QgsTerrainTileEntity( nodeId, parent )
{}

void QgsMesh3dTerrainTileEntity::buildGeometry()
@@ -85,7 +84,7 @@ void QgsMesh3dTerrainTileEntity::buildGeometry()
return;

Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;
mesh->setGeometry( new QgsMeshTerrain3dGeometry( layer(), mMapSettings.origin(), mSymbol, mesh ) );
mesh->setGeometry( new QgsMeshTerrain3dGeometry( layer(), mMapSettings.origin(), mSymbol.get(), mesh ) );
addComponent( mesh );
}

@@ -94,7 +93,7 @@ void QgsMesh3dTerrainTileEntity::applyMaterial()
QgsMesh3dMaterial *material = new QgsMesh3dMaterial(
layer(), mMapSettings.temporalRange(),
mMapSettings.origin(),
mSymbol,
mSymbol.get(),
QgsMesh3dMaterial::ZValue );
addComponent( material );
}
@@ -55,15 +55,15 @@ class QgsMesh3dEntity
//! Constructor
QgsMesh3dEntity( const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol &symbol );
const QgsMesh3DSymbol *symbol );

virtual ~QgsMesh3dEntity() = default;

QgsMeshLayer *layer() const;

Qgs3DMapSettings mMapSettings;
QgsMapLayerRef mLayerRef;
QgsMesh3DSymbol mSymbol;
std::unique_ptr< QgsMesh3DSymbol > mSymbol;

private:
virtual void buildGeometry() = 0;
@@ -77,7 +77,7 @@ class QgsMeshDataset3dEntity: public QgsMesh3dEntity, public Qt3DCore::QEntity
//! Constructor
QgsMeshDataset3dEntity( const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol &symbol );
const QgsMesh3DSymbol *symbol );

private:
virtual void buildGeometry();
@@ -91,7 +91,7 @@ class QgsMesh3dTerrainTileEntity: public QgsMesh3dEntity, public QgsTerrainTileE
public:
QgsMesh3dTerrainTileEntity( const Qgs3DMapSettings &map,
QgsMeshLayer *meshLayer,
const QgsMesh3DSymbol &symbol,
const QgsMesh3DSymbol *symbol,
QgsChunkNodeId nodeId,
Qt3DCore::QNode *parent = nullptr );

0 comments on commit f2e4ac6

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