24#include <Qt3DRender/QPaintedTextureImage> 
   25#include <Qt3DRender/QTexture> 
   26#include <Qt3DRender/QParameter> 
   27#include <Qt3DRender/QEffect> 
   28#include <Qt3DRender/QTechnique> 
   29#include <Qt3DRender/QGraphicsApiFilter> 
   35  return QStringLiteral( 
"phongtextured" );
 
 
   72  return *
this == *otherPhong;
 
 
   77  return mTextureRotation;
 
 
   84  mShininess = elem.attribute( QStringLiteral( 
"shininess" ) ).toDouble();
 
   85  mOpacity = elem.attribute( QStringLiteral( 
"opacity" ), QStringLiteral( 
"1.0" ) ).toDouble();
 
   86  mDiffuseTexturePath = elem.attribute( QStringLiteral( 
"diffuse_texture_path" ), QString() );
 
   87  mTextureScale = elem.attribute( QStringLiteral( 
"texture_scale" ), QString( 
"1.0" ) ).toDouble();
 
   88  mTextureRotation = elem.attribute( QStringLiteral( 
"texture-rotation" ), QString( 
"0.0" ) ).toDouble();
 
 
   97  elem.setAttribute( QStringLiteral( 
"shininess" ), mShininess );
 
   98  elem.setAttribute( QStringLiteral( 
"opacity" ), mOpacity );
 
   99  elem.setAttribute( QStringLiteral( 
"diffuse_texture_path" ), mDiffuseTexturePath );
 
  100  elem.setAttribute( QStringLiteral( 
"texture_scale" ), mTextureScale );
 
  101  elem.setAttribute( QStringLiteral( 
"texture-rotation" ), mTextureRotation );
 
 
  117      bool fitsInCache = 
false;
 
  119      ( void ) fitsInCache;
 
  123      if ( textureSourceImage.isNull() )
 
  127        phongSettings.
setDiffuse( QColor::fromRgbF( 0.7f, 0.7f, 0.7f, 1.0f ) ); 
 
  135      QgsPhongTexturedMaterial *material = 
new QgsPhongTexturedMaterial();
 
  137      int opacity = 
static_cast<int>( mOpacity * 255.0 );
 
  140      material->setSpecular( QColor( mSpecular.red(), mSpecular.green(), mSpecular.blue(), 
opacity ) );
 
  141      material->setShininess( 
static_cast<float>( mShininess ) );
 
  142      material->setOpacity( 
static_cast<float>( mOpacity ) );
 
  147      Qt3DRender::QTexture2D *texture = 
new Qt3DRender::QTexture2D();
 
  148      texture->addTextureImage( textureImage );
 
  150      texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
 
  151      texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
 
  152      texture->wrapMode()->setZ( Qt3DRender::QTextureWrapMode::Repeat );
 
  154      texture->setSamples( 4 );
 
  156      texture->setGenerateMipMaps( 
true );
 
  157      texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
 
  158      texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
 
  160      material->setDiffuseTexture( texture );
 
  161      material->setDiffuseTextureScale( 
static_cast<float>( mTextureScale ) );
 
 
  174  QMap<QString, QString> parameters;
 
  175  parameters[QStringLiteral( 
"Ka" )] = QStringLiteral( 
"%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
 
  176  parameters[QStringLiteral( 
"Ks" )] = QStringLiteral( 
"%1 %2 %3" ).arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
 
  177  parameters[QStringLiteral( 
"Ns" )] = QString::number( mShininess );
 
 
  185  Qt3DRender::QParameter *ambientParameter = 
new Qt3DRender::QParameter( QStringLiteral( 
"ambientColor" ), ambientColor );
 
  186  Qt3DRender::QParameter *specularParameter = 
new Qt3DRender::QParameter( QStringLiteral( 
"specularColor" ), mSpecular );
 
  187  Qt3DRender::QParameter *shininessParameter = 
new Qt3DRender::QParameter( QStringLiteral( 
"shininess" ), 
static_cast<float>( mShininess ) );
 
  189  effect->addParameter( ambientParameter );
 
  190  effect->addParameter( specularParameter );
 
  191  effect->addParameter( shininessParameter );
 
 
Abstract base class for material settings.
 
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
 
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
 
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
 
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
 
static QString colorToString(const QColor &color)
Encodes a color into a string value.
 
QImage pathAsImage(const QString &path, const QSize size, const bool keepAspectRatio, const double opacity, bool &fitsInCache, bool blocking=false, double targetDpi=96, int frameNumber=-1, bool *isMissing=nullptr)
Returns the specified path rendered as an image.
 
Holds an image that can be used as a texture in the 3D view.
 
Context settings for a material.
 
QColor selectionColor() const
Returns the color for representing materials in a selected state.
 
bool isSelected() const
Returns true if the material should represent a selected state.
 
Base class for all materials used within QGIS 3D views.
 
Basic shading material used for rendering based on the Phong shading model with three color component...
 
void setOpacity(double opacity)
Sets opacity of the surface.
 
QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
 
void setDiffuse(const QColor &diffuse)
Sets diffuse color component.
 
void setShininess(double shininess)
Sets shininess of the surface.
 
void setAmbient(const QColor &ambient)
Sets ambient color component.
 
void setSpecular(const QColor &specular)
Sets specular color component.
 
A Phong shading model with diffuse texture map.
 
QgsPhongTexturedMaterialSettings()=default
 
void addParametersToEffect(Qt3DRender::QEffect *effect, const QgsMaterialContext &materialContext) const override
Adds parameters from the material to a destination effect.
 
QgsMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QgsMaterial object representing the material settings.
 
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
 
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
 
double textureRotation() const
Returns the texture rotation, in degrees.
 
QString type() const override
Returns the unique type name for the material.
 
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
 
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
 
double opacity() const
Returns the opacity of the surface.
 
QgsPhongTexturedMaterialSettings * clone() const override
Clones the material settings.
 
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongTexturedMaterialSettings.
 
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
 
QColor ambient() const
Returns ambient color component.
 
A container for the context for various read/write operations on objects.
 
QgsMaterialSettingsRenderingTechnique
Material rendering techniques.
 
@ Points
Point based rendering, requires point data.
 
@ Triangles
Triangle based rendering (default)
 
@ TrianglesFromModel
Triangle based rendering, using a model object source.
 
@ Lines
Line based rendering, requires line data.
 
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
 
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
 
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering)