0
我正在尝试在Scene3D
场景中呈现长方体或平面的脸部上的QML组件。我已经成功地跟随了文档中的示例,但我试图将其转换为C++ API,因为我需要处理更多的内容,只有C++就足够了。这是我的类的ctor,它根据示例代码设置实体及其组件。为了简洁,我只包含了ctor。班上没有其他任何事情会影响这一点。Qt3D使用C++的QtQuick Scene2D
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中,从另一个类中渲染为黑盒子,并将无意义的红色文本挤压在脸上。显然这是不对的。我哪里错了?
是现有的运行QQmlEngine的g_RootQmlObject部分?如果没有,您可能需要启动一个新的QQmlEngine。请参阅下面的“详细描述”下的示例:http://doc.qt.io/qt-5/qqmlengine.html – dragly
是的,g_RootQmlObject正在运行。不过,我会尝试启动一个新的QQmlEngine以防万一。 –
不幸的是,没有。创建一个新的QQmlEngine会得到相同的结果。 –