Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

I can't load Texture with QVariant in QMetalRoughMaterial ? What happened With Qt3D 5.13.1 ?



  • 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 ?

    Oh yes, the QTextureLoader does not work anymore? is it deleted in this version?

    i tried this too nothing works

    Qt3DExtras::QMetalRoughMaterial *mat {new Qt3DExtras::QMetalRoughMaterial(this)};
    Qt3DRender::QTextureImage *baseColorTextureImage {new Qt3DRender::QTextureImage()};
    Qt3DRender::QTextureImage *metalnessTextureImage {new Qt3DRender::QTextureImage()};
    Qt3DRender::QTextureImage *roughnessTextureImage {new Qt3DRender::QTextureImage()};
    Qt3DRender::QTextureImage *normalTextureImage {new Qt3DRender::QTextureImage()};
    Qt3DRender::QTextureImage *ambientOcclusionTextureImage {new Qt3DRender::QTextureImage()};
    
    MTexture *baseColorTexture = new MTexture(); //MTexture is inherit QAbstractTexture
    MTexture *metalnessTexture = new MTexture();
    MTexture *roughnessTexture = new MTexture();
    MTexture *normalTexture = new MTexture();
    MTexture *ambientOcclusionTexture = new MTexture();
    
    baseColorTextureImage->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_col.jpg")));
    metalnessTextureImage->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_met.jpg")));
    roughnessTextureImage->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_rgh.jpg")));
    normalTextureImage->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_nrm.jpg")));
    ambientOcclusionTextureImage->setSource(QUrl(QStringLiteral("qrc:/texture/metal/Metal03_disp.jpg")));
    
    baseColorTexture->addTextureImage(baseColorTextureImage);
    metalnessTexture->addTextureImage(metalnessTextureImage);
    roughnessTexture->addTextureImage(roughnessTextureImage);
    normalTexture->addTextureImage(normalTextureImage);
    ambientOcclusionTexture->addTextureImage(ambientOcclusionTextureImage);
    
    mat->baseColor().setValue(QVariant::fromValue(baseColorTexture));
    mat->metalness().setValue(QVariant::fromValue(metalnessTexture));
    mat->roughness().setValue(QVariant::fromValue(roughnessTexture));
    mat->normal().setValue(QVariant::fromValue(normalTexture));
    mat->ambientOcclusion().setValue(QVariant::fromValue(ambientOcclusionTexture));
    

Log in to reply