21 #include <Qt3DExtras/QDiffuseMapMaterial>
22 #include <Qt3DExtras/QPhongMaterial>
23 #include <Qt3DRender/QPaintedTextureImage>
24 #include <Qt3DRender/QTexture>
25 #include <Qt3DRender/QParameter>
26 #include <Qt3DRender/QEffect>
32 return QStringLiteral(
"phongtextured" );
39 case QgsMaterialSettingsRenderingTechnique::Triangles:
44 case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
45 case QgsMaterialSettingsRenderingTechnique::Lines:
63 return mTextureRotation;
70 mShininess = elem.attribute( QStringLiteral(
"shininess" ) ).toFloat();
71 mDiffuseTexturePath = elem.attribute( QStringLiteral(
"diffuse_texture_path" ), QString() );
72 mTextureScale = elem.attribute( QStringLiteral(
"texture_scale" ), QString(
"1.0" ) ).toFloat();
73 mTextureRotation = elem.attribute( QStringLiteral(
"texture-rotation" ), QString(
"0.0" ) ).toFloat();
80 elem.setAttribute( QStringLiteral(
"shininess" ), mShininess );
81 elem.setAttribute( QStringLiteral(
"diffuse_texture_path" ), mDiffuseTexturePath );
82 elem.setAttribute( QStringLiteral(
"texture_scale" ), mTextureScale );
83 elem.setAttribute( QStringLiteral(
"texture-rotation" ), mTextureRotation );
87 class QgsQImageTextureImage :
public Qt3DRender::QPaintedTextureImage
90 QgsQImageTextureImage(
const QImage &image, Qt3DCore::QNode *parent =
nullptr )
94 setSize( mImage.size() );
97 void paint( QPainter *painter )
override
99 painter->drawImage( mImage.rect(), mImage, mImage.rect() );
113 case QgsMaterialSettingsRenderingTechnique::Triangles:
114 case QgsMaterialSettingsRenderingTechnique::InstancedPoints:
118 bool fitsInCache =
false;
122 if ( !textureSourceImage.isNull() )
124 Qt3DExtras::QDiffuseMapMaterial *material =
new Qt3DExtras::QDiffuseMapMaterial;
126 QgsQImageTextureImage *textureImage =
new QgsQImageTextureImage( textureSourceImage );
127 material->diffuse()->addTextureImage( textureImage );
129 material->diffuse()->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
130 material->diffuse()->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
131 material->diffuse()->wrapMode()->setZ( Qt3DRender::QTextureWrapMode::Repeat );
132 material->setSpecular( mSpecular );
133 material->setAmbient( mAmbient );
134 material->setShininess( mShininess );
135 material->setTextureScale( mTextureScale );
149 Qt3DExtras::QPhongMaterial *material =
new Qt3DExtras::QPhongMaterial;
150 material->setAmbient( mAmbient );
151 material->setSpecular( mSpecular );
152 material->setShininess( mShininess );
164 case QgsMaterialSettingsRenderingTechnique::Lines:
173 QMap<QString, QString> parameters;
174 parameters[ QStringLiteral(
"Ka" ) ] = QStringLiteral(
"%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
175 parameters[ QStringLiteral(
"Ks" ) ] = QStringLiteral(
"%1 %2 %3" ).arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
176 parameters[ QStringLiteral(
"Ns" ) ] = QString::number( mShininess );
182 Qt3DRender::QParameter *ambientParameter =
new Qt3DRender::QParameter( QStringLiteral(
"ka" ), QColor::fromRgbF( 0.05f, 0.05f, 0.05f, 1.0f ) );
183 Qt3DRender::QParameter *specularParameter =
new Qt3DRender::QParameter( QStringLiteral(
"ks" ), QColor::fromRgbF( 0.01f, 0.01f, 0.01f, 1.0f ) );
184 Qt3DRender::QParameter *shininessParameter =
new Qt3DRender::QParameter( QStringLiteral(
"shininess" ), 150.0f );
186 ambientParameter->setValue( mAmbient );
187 specularParameter->setValue( mSpecular );
188 shininessParameter->setValue( mShininess );
190 effect->addParameter( ambientParameter );
191 effect->addParameter( specularParameter );
192 effect->addParameter( shininessParameter );