qt3d-examples icon indicating copy to clipboard operation
qt3d-examples copied to clipboard

I can't load Texture with QVariant in QMetalRoughMaterial ? Qt 5.15.0

Open maouache opened this issue 4 years ago • 3 comments

hello,

I tried to use QMetalRoughMaterial for my cube to see how it's work. i saw the example in QML and i tried to translate it in C++ code That's it :

Qt3DExtras::QMorphPhongMaterial *mat {new Qt3DExtras::QMorphPhongMaterial(this)}; mat->baseColor().setValue(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_col.jpg"))); mat->metalness().setValue(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_met.jpg"))); mat->roughness().setValue(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_rgh.jpg"))); mat->normal().setValue(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_nrm.jpg"))); mat->ambientOcclusion().setValue(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_disp.jpg")));

Not Working, so I say to go the documentation to see how the methods work, the properties are Qvariant type. I looked how to do, QVariant :: FromValue() it does not work either.

My question is how to get textures through qvariant or QAbsractTexture ?

Please i need help ???

maouache avatar Aug 23 '20 09:08 maouache

You have to first load the texture and then pass it on the material. Something like: QMetalRoughMaterial *mat = new QMetalRoughMaterial(); Qt3DRender::QTextureLoader *textureLoader = new Qt3DRender::QTextureLoader(); textureLoader->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_col.jpg")); mat->baseColor().setValue(QVariant::fromValue(textureLoader));

lemirep avatar Aug 24 '20 06:08 lemirep

sorry but is not work. i used just the example of Qt basicshapes-cpp and i added your code by replace it into sphere material, and the result is this:

image

the code is here:

Qt3DExtras::QMetalRoughMaterial *mat = new Qt3DExtras::QMetalRoughMaterial(); Qt3DRender::QTextureLoader *textureLoader = new Qt3DRender::QTextureLoader(); textureLoader->setSource(QUrl(QStringLiteral("qrc:/texture/Rock035_2K_Color.jpg"))); mat->baseColor().setValue(QVariant::fromValue(textureLoader));

I noticed this message in execution: QObject::connect(QOpenGLContext, Unknown): invalid nullptr parameter QString::arg: Argument missing: " Max Work Group Size: 1024, 1024, 64\n Max Work Group Count: 65535, 65535, 65535\n Max Invocations: 65535\n Max Shared Memory Size: 1024\n" , 32768

i was thinking if I reduced the size of the images, maybe is gonna work , but nothing

PS: the material that i used is this : https://cc0textures.com/view?id=Rock035

maouache avatar Aug 24 '20 17:08 maouache

@lemirep your code is not working

maouache avatar Aug 31 '20 05:08 maouache