使用C ++的Qt3D QtQuick Scene2D

时间:2017-10-19 00:32:44

标签: c++ 3d qt5 qt3d

我试图在Scene3D场景中的长方体或平面上渲染QML组件。我已经成功地遵循了文档中的示例,但我试图将其转换为C ++ API,因为我需要做更多的事情,只有C ++就足够了。这是我的类的ctor,它根据示例代码设置实体及其组件。我只是为了简洁而包括ctor。该课程中没有任何其他内容可以影响到这一点。

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);
}

我将它包含在另一个类的Scene3D中,在那里它呈现为一个黑色的盒子,上面有无意义的红色文字。显然这不对。我哪里出错?

这是呈现的内容: I'm getting a black box with red garbage text, however the text is the same every time.

1 个答案:

答案 0 :(得分:0)

这是由Qt 5.9.x中存在的错误引起的。 https://bugreports.qt.io/browse/QTBUG-60974此时没有可行的解决方案。显然在飞机表面上渲染QML在当前时间被打破。