22 #include <Qt3DExtras/QDiffuseSpecularMaterial>
23 #include <Qt3DExtras/QPhongMaterial>
24 #include <Qt3DRender/QPaintedTextureImage>
25 #include <Qt3DRender/QTexture>
26 #include <Qt3DRender/QParameter>
27 #include <Qt3DRender/QEffect>
33 return QStringLiteral(
"phongtextured" );
66 return mTextureRotation;
73 mShininess = elem.attribute( QStringLiteral(
"shininess" ) ).toFloat();
74 mDiffuseTexturePath = elem.attribute( QStringLiteral(
"diffuse_texture_path" ), QString() );
75 mTextureScale = elem.attribute( QStringLiteral(
"texture_scale" ), QString(
"1.0" ) ).toFloat();
76 mTextureRotation = elem.attribute( QStringLiteral(
"texture-rotation" ), QString(
"0.0" ) ).toFloat();
85 elem.setAttribute( QStringLiteral(
"shininess" ), mShininess );
86 elem.setAttribute( QStringLiteral(
"diffuse_texture_path" ), mDiffuseTexturePath );
87 elem.setAttribute( QStringLiteral(
"texture_scale" ), mTextureScale );
88 elem.setAttribute( QStringLiteral(
"texture-rotation" ), mTextureRotation );
105 bool fitsInCache =
false;
109 if ( !textureSourceImage.isNull() )
112 Qt3DExtras::QDiffuseSpecularMaterial *material =
new Qt3DExtras::QDiffuseSpecularMaterial;
114 Qt3DRender::QTexture2D *texture =
new Qt3DRender::QTexture2D();
115 texture->addTextureImage( textureImage );
117 texture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::Repeat );
118 texture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::Repeat );
119 texture->wrapMode()->setZ( Qt3DRender::QTextureWrapMode::Repeat );
121 texture->setSamples( 4 );
123 texture->setGenerateMipMaps(
true );
124 texture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
125 texture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
127 material->setDiffuse( QVariant::fromValue( texture ) );
129 material->setSpecular( mSpecular );
130 material->setAmbient( mAmbient );
131 material->setShininess( mShininess );
132 material->setTextureScale( mTextureScale );
146 Qt3DExtras::QPhongMaterial *material =
new Qt3DExtras::QPhongMaterial;
147 material->setAmbient( mAmbient );
148 material->setSpecular( mSpecular );
149 material->setShininess( mShininess );
170 QMap<QString, QString> parameters;
171 parameters[ QStringLiteral(
"Ka" ) ] = QStringLiteral(
"%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
172 parameters[ QStringLiteral(
"Ks" ) ] = QStringLiteral(
"%1 %2 %3" ).arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
173 parameters[ QStringLiteral(
"Ns" ) ] = QString::number( mShininess );
179 Qt3DRender::QParameter *ambientParameter =
new Qt3DRender::QParameter( QStringLiteral(
"ka" ), QColor::fromRgbF( 0.05f, 0.05f, 0.05f, 1.0f ) );
180 Qt3DRender::QParameter *specularParameter =
new Qt3DRender::QParameter( QStringLiteral(
"ks" ), QColor::fromRgbF( 0.01f, 0.01f, 0.01f, 1.0f ) );
181 Qt3DRender::QParameter *shininessParameter =
new Qt3DRender::QParameter( QStringLiteral(
"shininess" ), 150.0f );
183 ambientParameter->setValue( mAmbient );
184 specularParameter->setValue( mSpecular );
185 shininessParameter->setValue( mShininess );
187 effect->addParameter( ambientParameter );
188 effect->addParameter( specularParameter );
189 effect->addParameter( shininessParameter );