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