简体   繁体   中英

Qt3D QtQuick Scene2D using C++

I am attempting to render a QML component on the face of a cuboid or plane in a Scene3D scene. I have followed the example in documentation with success, but I am trying to convert this over to the C++ API as there's more I need to do with it and only C++ will suffice. This is the ctor for my class, which sets up the Entity and its components, based off the example code. I am only including the ctor for brevity. There isn't anything else in the class that should effect this.

ESEctoPointToast::ESEctoPointToast(Qt3DCore::QNode *parent)
:   Qt3DCore::QEntity(parent)
,   m_position(QVector3D(0,0,0))
,   m_quickItem(nullptr)
,   m_cuboid(new Qt3DExtras::QCuboidMesh())
,   m_textureMaterial(new Qt3DExtras::QTextureMaterial())
,   m_transform(new Qt3DCore::QTransform())
,   m_objectPicker(new Qt3DRender::QObjectPicker())
,   m_texture2d(new Qt3DRender::QTexture2D())
,   m_renderTargetOutput(new Qt3DRender::QRenderTargetOutput())
,   m_scene2d(new Qt3DRender::Quick::QScene2D())
{
    // g_RootQmlObject is the root item in the main scene, this was the only
    // way I could come up with to access qmlEngine. Is there a better way?
    auto engine = qmlEngine(g_RootQmlObject);
    QQmlComponent c(engine, QUrl("qrc:/components/E3DDummy.qml"));
    m_quickItem = qobject_cast<QQuickItem*>(c.create());
    Q_ASSERT(m_quickItem);

    m_texture2d->setWidth(256);
    m_texture2d->setHeight(256);
    m_texture2d->setFormat(Qt3DRender::QAbstractTexture::TextureFormat::RGB8_UNorm);
    m_texture2d->setGenerateMipMaps(true);
    m_texture2d->setMagnificationFilter(Qt3DRender::QAbstractTexture::Filter::Linear);
    m_texture2d->setMinificationFilter(Qt3DRender::QAbstractTexture::Filter::LinearMipMapLinear);
    m_texture2d->setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToEdge));
    m_renderTargetOutput->setAttachmentPoint(Qt3DRender::QRenderTargetOutput::AttachmentPoint::Color0);
    m_renderTargetOutput->setTexture(m_texture2d);
    m_textureMaterial->setTexture(m_texture2d);
    m_scene2d->setItem(m_quickItem);
    m_scene2d->setMouseEnabled(true);
    m_scene2d->setRenderPolicy(Qt3DRender::Quick::QScene2D::RenderPolicy::Continuous);
    m_scene2d->setOutput(m_renderTargetOutput);
    m_scene2d->addEntity(this);

    addComponent(m_transform);
    addComponent(m_textureMaterial);
    addComponent(m_cuboid);
    addComponent(m_objectPicker);
}

I include it in my Scene3D from another class where it renders as a black box with nonsense red text squeezed onto the face. Obviously this isn't right. Where have I gone wrong?

This is what is rendered: 我得到一个带有红色垃圾文本的黑匣子,但是每次文本都是相同的。

This is caused by a bug present in Qt 5.9.x. https://bugreports.qt.io/browse/QTBUG-60974 No workable solution at this point. Apparently rendering QML on the face of a plane is broken in 5.9.x.

Update: QT reports that the bug is not present anymore in 5.11.1. https://bugreports.qt.io/browse/QTBUG-60974?focusedCommentId=409471&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-409471

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM