Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 f2e4ac6
Show file tree
Hide file tree
Showing 52 changed files with 840 additions and 389 deletions.
1 change: 1 addition & 0 deletions python/3d/3d_auto.sip
Expand Up @@ -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
Expand Down
108 changes: 108 additions & 0 deletions python/3d/auto_generated/qgsabstractmaterialsettings.sip.in
@@ -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 *
************************************************************************/
17 changes: 8 additions & 9 deletions python/3d/auto_generated/qgsphongmaterialsettings.sip.in
Expand Up @@ -10,7 +10,7 @@



class QgsPhongMaterialSettings
class QgsPhongMaterialSettings : QgsAbstractMaterialSettings
{
%Docstring
Basic shading material used for rendering based on the Phong shading model
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions python/3d/auto_generated/symbols/qgsline3dsymbol.sip.in
Expand Up @@ -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).
Expand All @@ -31,6 +31,7 @@ class QgsLine3DSymbol : QgsAbstract3DSymbol
%Docstring
Constructor for QgsLine3DSymbol
%End
~QgsLine3DSymbol();

static QgsAbstract3DSymbol *create() /Factory/;
%Docstring
Expand Down Expand Up @@ -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

};
Expand Down
12 changes: 8 additions & 4 deletions python/3d/auto_generated/symbols/qgspoint3dsymbol.sip.in
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in
Expand Up @@ -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).
Expand All @@ -31,6 +32,7 @@ class QgsPolygon3DSymbol : QgsAbstract3DSymbol
%Docstring
Constructor for QgsPolygon3DSymbol
%End
~QgsPolygon3DSymbol();

virtual QString type() const;
virtual QgsAbstract3DSymbol *clone() const /Factory/;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions python/core/auto_generated/3d/qgsabstract3dsymbol.sip.in
Expand Up @@ -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

};


Expand Down
1 change: 1 addition & 0 deletions src/3d/CMakeLists.txt
Expand Up @@ -81,6 +81,7 @@ SET(QGIS_3D_HDRS
qgs3dutils.h
qgsaabb.h
qgsabstract3dengine.h
qgsabstractmaterialsettings.h
qgsabstractvectorlayer3drenderer.h
qgscameracontroller.h
qgscamerapose.h
Expand Down
37 changes: 18 additions & 19 deletions src/3d/mesh/qgsmesh3dentity_p.cpp
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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 );
}

Expand All @@ -94,7 +93,7 @@ void QgsMesh3dTerrainTileEntity::applyMaterial()
QgsMesh3dMaterial *material = new QgsMesh3dMaterial(
layer(), mMapSettings.temporalRange(),
mMapSettings.origin(),
mSymbol,
mSymbol.get(),
QgsMesh3dMaterial::ZValue );
addComponent( material );
}
Expand Down
8 changes: 4 additions & 4 deletions src/3d/mesh/qgsmesh3dentity_p.h
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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 );

Expand Down

0 comments on commit f2e4ac6

Please sign in to comment.