2017-10-19 10 views
0

Scene3D 장면에서 직육면체 또는 평면의면에 QML 구성 요소를 렌더링하려고합니다. 나는 성공에 대한 문서화의 예를 따라 갔지만,이 작업을 C++ API로 변환하려고하는데, 더 많은 작업이 필요하고 C++만으로 충분할 것이다. 이것은 예제 코드를 기반으로 Entity와 그 구성 요소를 설정하는 클래스입니다. 나는 간결함을 위해서만 ctor를 포함합니다. 반원들에게 이것에 영향을주는 다른 어떤 것도 없습니다.Qt3D QtQuick Scene2D (C++ 사용)

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.

+0

g_RootQmlObject가 기존의 실행중인 QQmlEngine의 일부입니까? 그렇지 않은 경우 새 QQmlEngine을 시작하고자 할 수 있습니다. 자세한 내용은 아래의 예제를 참조하십시오. http://doc.qt.io/qt-5/qqmlengine.html – dragly

+0

예, g_RootQmlObject가 실행 중입니다. 그러나 나는 단지 새로운 QQmlEngine을 시작하려고 노력할 것이다. –

+0

불행히도, 아니오. 새 QQmlEngine을 작성하면 동일한 결과가 산출됩니다. –

답변

0

이것은 Qt는 5.9.x. 버그 존재에 의해 발생된다

이 렌더링되는 것이다 https://bugreports.qt.io/browse/QTBUG-60974 현재 실행 가능한 해결책이 없습니다. 외관상으로는 비행기의 얼굴에 QML를 렌더링하는 것은이 현재 시간에 깨졌습니다.