Skip to content

Commit

Permalink
symbols: rename material to material settings (#50977)
Browse files Browse the repository at this point in the history
* qgspoint3dsymbol: Rename mMaterial attribute to mMaterialSettings

mMaterial is not a material but an attribute to handle material
settings. Renaming it makes it easier to understand its usage.

* qgspoint3dsymbol: Rename materialSettings getter and setter

See previous commit.

* qgsline3dsymbol: Rename mMaterial attribute to mMaterialSettings

mMaterial is not a material but an attribute to handle material
settings. Renaming it makes it easier to understand its usage.

* qgsline3dsymbol: Rename materialSettings getter and setter

See previous commit.

* qgspolygon3dsymbol: Rename mMaterial attribute to mMaterialSettings

mMaterial is not a material but an attribute to handle material
settings. Renaming it makes it easier to understand its usage.

* qgspolygon3dsymbol: Rename materialSettings getter and setter

See previous commit.

* qgsmesh3dsymbol: Rename mMaterial attribute to mMaterialSettings

mMaterial is not a material but an attribute to handle material
settings. Renaming it makes it easier to understand its usage.

* qgsmesh3dsymbol: Rename materialSettings getter and setter

See previous commit.

* qgsgoochmaterialsettings: fix indentation
  • Loading branch information
ptitjano committed Nov 30, 2022
1 parent 205865f commit 5d14d84
Show file tree
Hide file tree
Showing 20 changed files with 142 additions and 144 deletions.
6 changes: 3 additions & 3 deletions python/3d/auto_generated/symbols/qgsline3dsymbol.sip.in
Expand Up @@ -107,12 +107,12 @@ 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

QgsAbstractMaterialSettings *material() const;
QgsAbstractMaterialSettings *materialSettings() const;
%Docstring
Returns material used for shading of the symbol
Returns material settings used for shading of the symbol
%End

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

Expand Down
6 changes: 3 additions & 3 deletions python/3d/auto_generated/symbols/qgspoint3dsymbol.sip.in
Expand Up @@ -69,12 +69,12 @@ 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

QgsAbstractMaterialSettings *material() const;
QgsAbstractMaterialSettings *materialSettings() const;
%Docstring
Returns material used for shading of the symbol
Returns material settings used for shading of the symbol
%End

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

Expand Down
6 changes: 3 additions & 3 deletions python/3d/auto_generated/symbols/qgspolygon3dsymbol.sip.in
Expand Up @@ -90,12 +90,12 @@ Returns extrusion height (in map units)
Sets extrusion height (in map units)
%End

QgsAbstractMaterialSettings *material() const;
QgsAbstractMaterialSettings *materialSettings() const;
%Docstring
Returns material used for shading of the symbol
Returns material settings used for shading of the symbol
%End

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

Expand Down
3 changes: 1 addition & 2 deletions src/3d/materials/qgsgoochmaterialsettings.cpp
Expand Up @@ -206,8 +206,7 @@ void QgsGoochMaterialSettings::applyDataDefinedToGeometry( Qt3DQGeometry *geomet
warmAttribute->setByteStride( 12 * sizeof( unsigned char ) );
warmAttribute->setByteOffset( 3 * sizeof( unsigned char ) );
warmAttribute->setCount( vertexCount );
geometry->addAttribute( warmAttribute
);
geometry->addAttribute( warmAttribute );

Qt3DQAttribute *coolAttribute = new Qt3DQAttribute( geometry );
coolAttribute->setName( QStringLiteral( "dataDefinedCoolColor" ) );
Expand Down
28 changes: 14 additions & 14 deletions src/3d/symbols/qgsline3dsymbol.cpp
Expand Up @@ -23,7 +23,7 @@
#include "qgsvectorlayerelevationproperties.h"

QgsLine3DSymbol::QgsLine3DSymbol()
: mMaterial( std::make_unique< QgsPhongMaterialSettings >() )
: mMaterialSettings( std::make_unique< QgsPhongMaterialSettings >() )
{

}
Expand All @@ -39,7 +39,7 @@ QgsAbstract3DSymbol *QgsLine3DSymbol::clone() const
result->mHeight = mHeight;
result->mExtrusionHeight = mExtrusionHeight;
result->mRenderAsSimpleLines = mRenderAsSimpleLines;
result->mMaterial.reset( mMaterial->clone() );
result->mMaterialSettings.reset( mMaterialSettings->clone() );
copyBaseSettings( result.get() );
return result.release();
}
Expand All @@ -59,9 +59,9 @@ void QgsLine3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
elemDataProperties.setAttribute( QStringLiteral( "width" ), mWidth );
elem.appendChild( elemDataProperties );

elem.setAttribute( QStringLiteral( "material_type" ), mMaterial->type() );
elem.setAttribute( QStringLiteral( "material_type" ), mMaterialSettings->type() );
QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
mMaterial->writeXml( elemMaterial, context );
mMaterialSettings->writeXml( elemMaterial, context );
elem.appendChild( elemMaterial );
}

Expand All @@ -79,23 +79,23 @@ void QgsLine3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex

const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
const QString materialType = elem.attribute( QStringLiteral( "material_type" ), QStringLiteral( "phong" ) );
mMaterial.reset( Qgs3D::materialRegistry()->createMaterialSettings( materialType ) );
if ( !mMaterial )
mMaterial.reset( Qgs3D::materialRegistry()->createMaterialSettings( QStringLiteral( "phong" ) ) );
mMaterial->readXml( elemMaterial, context );
mMaterialSettings.reset( Qgs3D::materialRegistry()->createMaterialSettings( materialType ) );
if ( !mMaterialSettings )
mMaterialSettings.reset( Qgs3D::materialRegistry()->createMaterialSettings( QStringLiteral( "phong" ) ) );
mMaterialSettings->readXml( elemMaterial, context );
}

QgsAbstractMaterialSettings *QgsLine3DSymbol::material() const
QgsAbstractMaterialSettings *QgsLine3DSymbol::materialSettings() const
{
return mMaterial.get();
return mMaterialSettings.get();
}

void QgsLine3DSymbol::setMaterial( QgsAbstractMaterialSettings *material )
void QgsLine3DSymbol::setMaterialSettings( QgsAbstractMaterialSettings *materialSettings )
{
if ( material == mMaterial.get() )
if ( materialSettings == mMaterialSettings.get() )
return;

mMaterial.reset( material );
mMaterialSettings.reset( materialSettings );
}

QList<QgsWkbTypes::GeometryType> QgsLine3DSymbol::compatibleGeometryTypes() const
Expand Down Expand Up @@ -133,7 +133,7 @@ bool QgsLine3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::
{
Qgs3DExportObject *object = exporter->processGeometryRenderer( r, objectNamePrefix );
if ( object == nullptr ) continue;
object->setupMaterial( material() );
object->setupMaterial( materialSettings() );
exporter->mObjects.push_back( object );
}
return renderers.size() != 0;
Expand Down
8 changes: 4 additions & 4 deletions src/3d/symbols/qgsline3dsymbol.h
Expand Up @@ -84,15 +84,15 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTORS
//! Sets whether the renderer will render data with simple lines (otherwise it uses buffer)
void setRenderAsSimpleLines( bool enabled ) { mRenderAsSimpleLines = enabled; }

//! Returns material used for shading of the symbol
QgsAbstractMaterialSettings *material() const;
//! Returns material settings used for shading of the symbol
QgsAbstractMaterialSettings *materialSettings() const;

/**
* Sets the \a material settings used for shading of the symbol.
*
* Ownership of \a material is transferred to the symbol.
*/
void setMaterial( QgsAbstractMaterialSettings *material SIP_TRANSFER );
void setMaterialSettings( QgsAbstractMaterialSettings *materialSettings SIP_TRANSFER );

/**
* Exports the geometries contained within the hierarchy of entity.
Expand All @@ -110,7 +110,7 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol SIP_NODEFAULTCTORS
float mHeight = 0.0f; //!< Base height of polygons
float mExtrusionHeight = 0.0f; //!< How much to extrude (0 means no walls)
bool mRenderAsSimpleLines = false; //!< Whether to render data with simple lines (otherwise it uses buffer)
std::unique_ptr< QgsAbstractMaterialSettings > mMaterial; //!< Defines appearance of objects
std::unique_ptr< QgsAbstractMaterialSettings > mMaterialSettings; //!< Defines appearance of objects
};


Expand Down
10 changes: 5 additions & 5 deletions src/3d/symbols/qgsline3dsymbol_p.cpp
Expand Up @@ -96,7 +96,7 @@ bool QgsBufferedLine3DSymbolHandler::prepare( const Qgs3DRenderContext &context,
{
Q_UNUSED( attributeNames )

const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( mSymbol->material() );
const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( mSymbol->materialSettings() );

outNormal.tessellator.reset( new QgsTessellator( context.map().origin().x(), context.map().origin().y(), true,
false, false, false, texturedMaterialSettings ? texturedMaterialSettings->requiresTextureCoordinates() : false,
Expand Down Expand Up @@ -196,13 +196,13 @@ void QgsBufferedLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, cons
QgsMaterialContext materialContext;
materialContext.setIsSelected( selected );
materialContext.setSelectionColor( context.map().selectionColor() );
Qt3DRender::QMaterial *mat = mSymbol->material()->toMaterial( QgsMaterialSettingsRenderingTechnique::Triangles, materialContext );
Qt3DRender::QMaterial *mat = mSymbol->materialSettings()->toMaterial( QgsMaterialSettingsRenderingTechnique::Triangles, materialContext );

// extract vertex buffer data from tessellator
const QByteArray data( ( const char * )out.tessellator->data().constData(), out.tessellator->data().count() * sizeof( float ) );
const int nVerts = data.count() / out.tessellator->stride();

const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( mSymbol->material() );
const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( mSymbol->materialSettings() );

QgsTessellatedPolygonGeometry *geometry = new QgsTessellatedPolygonGeometry( true, false, false,
texturedMaterialSettings ? texturedMaterialSettings->requiresTextureCoordinates() : false );
Expand Down Expand Up @@ -314,7 +314,7 @@ void QgsSimpleLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
QgsMaterialContext materialContext;
materialContext.setIsSelected( selected );
materialContext.setSelectionColor( context.map().selectionColor() );
Qt3DRender::QMaterial *mat = mSymbol->material()->toMaterial( QgsMaterialSettingsRenderingTechnique::Lines, materialContext );
Qt3DRender::QMaterial *mat = mSymbol->materialSettings()->toMaterial( QgsMaterialSettingsRenderingTechnique::Lines, materialContext );

// geometry renderer

Expand Down Expand Up @@ -436,7 +436,7 @@ void QgsThickLine3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Q
QgsMaterialContext materialContext;
materialContext.setIsSelected( selected );
materialContext.setSelectionColor( context.map().selectionColor() );
Qt3DRender::QMaterial *mat = mSymbol->material()->toMaterial( QgsMaterialSettingsRenderingTechnique::Lines, materialContext );
Qt3DRender::QMaterial *mat = mSymbol->materialSettings()->toMaterial( QgsMaterialSettingsRenderingTechnique::Lines, materialContext );
if ( !mat )
{
const QgsSimpleLineMaterialSettings defaultMaterial;
Expand Down
18 changes: 9 additions & 9 deletions src/3d/symbols/qgsmesh3dsymbol.cpp
Expand Up @@ -19,7 +19,7 @@
#include "qgsphongmaterialsettings.h"

QgsMesh3DSymbol::QgsMesh3DSymbol()
: mMaterial( std::make_unique< QgsPhongMaterialSettings >() )
: mMaterialSettings( std::make_unique< QgsPhongMaterialSettings >() )
{

}
Expand All @@ -32,7 +32,7 @@ QgsMesh3DSymbol *QgsMesh3DSymbol::clone() const

result->mAltClamping = mAltClamping;
result->mHeight = mHeight;
result->mMaterial.reset( mMaterial->clone() );
result->mMaterialSettings.reset( mMaterialSettings->clone() );
result->mAddBackFaces = mAddBackFaces;
result->mEnabled = mEnabled;
result->mSmoothedTriangles = mSmoothedTriangles;
Expand Down Expand Up @@ -67,7 +67,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
elem.appendChild( elemDataProperties );

QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
mMaterial->writeXml( elemMaterial, context );
mMaterialSettings->writeXml( elemMaterial, context );
elem.appendChild( elemMaterial );

//Advanced symbol
Expand Down Expand Up @@ -105,7 +105,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
mAddBackFaces = elemDataProperties.attribute( QStringLiteral( "add-back-faces" ) ).toInt();

const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
mMaterial->readXml( elemMaterial, context );
mMaterialSettings->readXml( elemMaterial, context );

//Advanced symbol
const QDomElement elemAdvancedSettings = elem.firstChildElement( QStringLiteral( "advanced-settings" ) );
Expand Down Expand Up @@ -293,15 +293,15 @@ void QgsMesh3DSymbol::setEnabled( bool enabled )
}


QgsAbstractMaterialSettings *QgsMesh3DSymbol::material() const
QgsAbstractMaterialSettings *QgsMesh3DSymbol::materialSettings() const
{
return mMaterial.get();
return mMaterialSettings.get();
}

void QgsMesh3DSymbol::setMaterial( QgsAbstractMaterialSettings *material )
void QgsMesh3DSymbol::setMaterialSettings( QgsAbstractMaterialSettings *materialSettings )
{
if ( material == mMaterial.get() )
if ( materialSettings == mMaterialSettings.get() )
return;

mMaterial.reset( material );
mMaterialSettings.reset( materialSettings );
}
8 changes: 4 additions & 4 deletions src/3d/symbols/qgsmesh3dsymbol.h
Expand Up @@ -106,15 +106,15 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
//! Sets height (altitude) of the symbol (in map units)
void setHeight( float height ) { mHeight = height; }

//! Returns material used for shading of the symbol
QgsAbstractMaterialSettings *material() const;
//! Returns material settings used for shading of the symbol
QgsAbstractMaterialSettings *materialSettings() const;

/**
* Sets the \a material settings used for shading of the symbol.
*
* Ownership of \a material is transferred to the symbol.
*/
void setMaterial( QgsAbstractMaterialSettings *material SIP_TRANSFER );
void setMaterialSettings( QgsAbstractMaterialSettings *materialSettings SIP_TRANSFER );

/**
* Returns whether also triangles facing the other side will be created. Useful if input data have inconsistent order of vertices
Expand Down Expand Up @@ -347,7 +347,7 @@ class _3D_EXPORT QgsMesh3DSymbol : public QgsAbstract3DSymbol
//! how to handle altitude of vector features
Qgis::AltitudeClamping mAltClamping = Qgis::AltitudeClamping::Relative;
float mHeight = 0.0f; //!< Base height of triangles
std::unique_ptr< QgsAbstractMaterialSettings > mMaterial; //!< Defines appearance of objects
std::unique_ptr< QgsAbstractMaterialSettings > mMaterialSettings; //!< Defines appearance of objects
bool mAddBackFaces = false;

bool mEnabled = true;
Expand Down
4 changes: 2 additions & 2 deletions src/3d/symbols/qgsmesh3dsymbol_p.cpp
Expand Up @@ -66,7 +66,7 @@ QgsMesh3DSymbolEntity::QgsMesh3DSymbolEntity( const Qgs3DMapSettings &map,
Qt3DRender::QMaterial *QgsMesh3DSymbolEntity::material( const QgsMesh3DSymbol &symbol ) const
{
const QgsMaterialContext context;
Qt3DRender::QMaterial *material = symbol.material()->toMaterial( QgsMaterialSettingsRenderingTechnique::Triangles, context );
Qt3DRender::QMaterial *material = symbol.materialSettings()->toMaterial( QgsMaterialSettingsRenderingTechnique::Triangles, context );

// front/back side culling
const auto techniques = material->effect()->techniques();
Expand Down Expand Up @@ -136,7 +136,7 @@ Qt3DRender::QGeometryRenderer *QgsMesh3DSymbolEntityNode::renderer( const Qgs3DM
// call QgsTessellatedPolygonGeometry to
// use symbol settings for back faces, normals, etc

const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( symbol.material() );
const QgsPhongTexturedMaterialSettings *texturedMaterialSettings = dynamic_cast< const QgsPhongTexturedMaterialSettings * >( symbol.materialSettings() );

mGeometry = new QgsTessellatedPolygonGeometry( true, false, symbol.addBackFaces(), texturedMaterialSettings ? texturedMaterialSettings->requiresTextureCoordinates() : false );
const QList<float> extrusionHeightPerPolygon;
Expand Down
32 changes: 16 additions & 16 deletions src/3d/symbols/qgspoint3dsymbol.cpp
Expand Up @@ -38,14 +38,14 @@ QgsAbstract3DSymbol *QgsPoint3DSymbol::create()
}

QgsPoint3DSymbol::QgsPoint3DSymbol()
: mMaterial( std::make_unique< QgsPhongMaterialSettings >() )
: mMaterialSettings( std::make_unique< QgsPhongMaterialSettings >() )
{
setBillboardSymbol( static_cast<QgsMarkerSymbol *>( QgsSymbol::defaultSymbol( QgsWkbTypes::PointGeometry ) ) );
}

QgsPoint3DSymbol::QgsPoint3DSymbol( const QgsPoint3DSymbol &other )
: mAltClamping( other.altitudeClamping() )
, mMaterial( other.material() ? other.material()->clone() : nullptr )
, mMaterialSettings( other.materialSettings() ? other.materialSettings()->clone() : nullptr )
, mShape( other.shape() )
, mShapeProperties( other.shapeProperties() )
, mTransform( other.transform() )
Expand All @@ -64,9 +64,9 @@ void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &c
elemDataProperties.setAttribute( QStringLiteral( "alt-clamping" ), Qgs3DUtils::altClampingToString( mAltClamping ) );
elem.appendChild( elemDataProperties );

elem.setAttribute( QStringLiteral( "material_type" ), mMaterial->type() );
elem.setAttribute( QStringLiteral( "material_type" ), mMaterialSettings->type() );
QDomElement elemMaterial = doc.createElement( QStringLiteral( "material" ) );
mMaterial->writeXml( elemMaterial, context );
mMaterialSettings->writeXml( elemMaterial, context );
elem.appendChild( elemMaterial );

elem.setAttribute( QStringLiteral( "shape" ), shapeToString( mShape ) );
Expand Down Expand Up @@ -97,10 +97,10 @@ void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteConte

const QDomElement elemMaterial = elem.firstChildElement( QStringLiteral( "material" ) );
const QString materialType = elem.attribute( QStringLiteral( "material_type" ), QStringLiteral( "phong" ) );
mMaterial.reset( Qgs3D::materialRegistry()->createMaterialSettings( materialType ) );
if ( !mMaterial )
mMaterial.reset( Qgs3D::materialRegistry()->createMaterialSettings( QStringLiteral( "phong" ) ) );
mMaterial->readXml( elemMaterial, context );
mMaterialSettings.reset( Qgs3D::materialRegistry()->createMaterialSettings( materialType ) );
if ( !mMaterialSettings )
mMaterialSettings.reset( Qgs3D::materialRegistry()->createMaterialSettings( QStringLiteral( "phong" ) ) );
mMaterialSettings->readXml( elemMaterial, context );

mShape = shapeFromString( elem.attribute( QStringLiteral( "shape" ) ) );

Expand Down Expand Up @@ -177,17 +177,17 @@ QMatrix4x4 QgsPoint3DSymbol::billboardTransform() const
return billboardTransformMatrix;
}

QgsAbstractMaterialSettings *QgsPoint3DSymbol::material() const
QgsAbstractMaterialSettings *QgsPoint3DSymbol::materialSettings() const
{
return mMaterial.get();
return mMaterialSettings.get();
}

void QgsPoint3DSymbol::setMaterial( QgsAbstractMaterialSettings *material )
void QgsPoint3DSymbol::setMaterialSettings( QgsAbstractMaterialSettings *materialSettings )
{
if ( material == mMaterial.get() )
if ( materialSettings == mMaterialSettings.get() )
return;

mMaterial.reset( material );
mMaterialSettings.reset( materialSettings );
}

bool QgsPoint3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore::QEntity *entity, const QString &objectNamePrefix ) const
Expand All @@ -201,7 +201,7 @@ bool QgsPoint3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore:
for ( Qgs3DExportObject *obj : objects )
{
obj->setSmoothEdges( exporter->smoothEdges() );
obj->setupMaterial( material() );
obj->setupMaterial( materialSettings() );
}
exporter->mObjects << objects;
}
Expand All @@ -213,7 +213,7 @@ bool QgsPoint3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore:
Qgs3DExportObject *object = exporter->processGeometryRenderer( mesh, objectNamePrefix );
if ( object == nullptr ) continue;
object->setSmoothEdges( exporter->smoothEdges() );
object->setupMaterial( material() );
object->setupMaterial( materialSettings() );
exporter->mObjects << object;
}
}
Expand All @@ -233,7 +233,7 @@ bool QgsPoint3DSymbol::exportGeometries( Qgs3DSceneExporter *exporter, Qt3DCore:
const QVector<Qgs3DExportObject *> objects = exporter->processInstancedPointGeometry( entity, objectNamePrefix );
for ( Qgs3DExportObject *obj : objects )
{
obj->setupMaterial( material() );
obj->setupMaterial( materialSettings() );
exporter->mObjects << obj;
}
return true;
Expand Down

0 comments on commit 5d14d84

Please sign in to comment.