I'm using QQuickImageProvider to pass 3d scanner images from C++ to QML and then use these images as customer texture for model (using qt quick 3d here). I faced a problem that texture blinks getting to black for a second. It repeats quite often. I used to investigate streaming images as VideoOutput but this approach doesn't suit me as I have to use geometry data of surface and in case of VideoOutput it doesn't allow to map these images on geometry coordinates. Could you advise something in this case? Below is example of my code.
QML:
Image {
id: textureImage
source: renderControl.sourceUrl
anchors.fill: parent
visible: false // tried with cache true and false both
}
Node {
id: mainScene
DirectionalLight {
position: Qt.vector3d(-500, 500, -100)
ambientColor: Qt.rgba(1.0, 1.0, 1.0, 0.5)
}
Model {
id: viewModel
position: Qt.vector3d(0, 50, 0)
visible: true
scale: Qt.vector3d(10, 11, 4)
geometry: RenderData{ // C++ class which sends url to image provider
id: renderControl
objectName: "geometryData"
}
DefaultMaterial {
id: defaultMaterial
Texture {
id: baseColorMap
sourceItem: textureImage
}
cullMode: DefaultMaterial.NoCulling
diffuseMap: baseColorMap
}
materials: [
defaultMaterial
]
}
C++
.h
class TextureImageProvider : public QObject, public QQuickImageProvider
{
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override;
Q_SIGNALS:
void imageUpdated(const QUrl& imageUrl);
std::shared_ptr<QImage> textureImage_;
}
class RenderData : public QQuick3DGeometry
{
Q_OBJECT
Q_PROPERTY(QUrl sourceUrl READ sourceUrl WRITE setSourceUrl NOTIFY sourceUrlChanged)
TextureImageProvider* imageProvider_;
}
.cpp
void RenderData::updateData(QImage& textureImage)
{
const QUrl imageUrl = QString("image://texture_image_provider/%1").arg(Uuid::createUuid().toString().c_str());
textureImage_ = std::make_shared<QImage>(image);
Q_EMIT imageUpdated(url);
}
QImage TextureImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
return *textureImage_;
}
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
engine_->addImageProvider("texture_image_provider", &renderData_-getImageProvider());
}