Qt3d Using QSceneLoader with qt 5.8

£可爱£侵袭症+ 提交于 2019-12-01 06:00:38

问题


I unsuccessfully try to use QSceneLoader to load a 3d scene created in an external editor. And always I get assertions at loading stage. I use the example of OBJ model qt, which is easily loaded as QMesh.

test repo https://bitbucket.org/ibnz/test_qt3d

#include <QApplication>
#include <QEntity>
#include <QSceneLoader>
#include <Qt3DWindow>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();

    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();

    Qt3DRender::QSceneLoader *loader = new Qt3DRender::QSceneLoader(rootEntity);
    QObject::connect(loader, &Qt3DRender::QSceneLoader::statusChanged,
                     &app, [](Qt3DRender::QSceneLoader::Status s){qDebug() << s;});
    QUrl url = QUrl::fromLocalFile(":/obj/square-pot.obj");
    loader->setSource(url);

    view->setRootEntity(rootEntity);
    view->show();

    return app.exec();
}

Qt3DRender::QSceneLoader::Status(Loading) ASSERT: "entities.size() == 1" in file io\qsceneloader.cpp, line 215 Debug Error!

Program: C:\Qt\Qt5.8.0\5.8\msvc2015\bin\Qt5Cored.dll Module: 5.8.0 File: global\qglobal.cpp Line: 3070

ASSERT: "entities.size() == 1" in file io\qsceneloader.cpp, line 215

(Press Retry to debug the application) Qt3DRender::QSceneLoader::Status(Ready)


回答1:


I use http://code.qt.io/cgit/qt/qt3d.git/tree/tests/manual/assimp-cpp to load my own Collada robot model which works without errors. The important lines are:

// Root entity
Qt3DCore::QEntity *sceneRoot = new Qt3DCore::QEntity();
...
// Scene loader
Qt3DCore::QEntity *sceneLoaderEntity = new Qt3DCore::QEntity(sceneRoot);
Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(sceneLoaderEntity);
SceneWalker sceneWalker(sceneLoader);
QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged);
sceneLoaderEntity->addComponent(sceneLoader);

So try it out with your obj file.



来源:https://stackoverflow.com/questions/42974307/qt3d-using-qsceneloader-with-qt-5-8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!