我尝试使用 QSceneLoader 加载在外部编辑器中创建的 3D 场景,但没有成功。我总是在加载阶段得到断言。我使用 OBJ 模型 qt 的示例,它很容易加载为 QMesh。
测试仓库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::状态(正在加载)
断言:文件 io\qsceneloader.cpp 第 215 行中的“entities.size() == 1”
调试错误!
程序:C:\Qt\Qt5.8.0\5.8\msvc2015\bin\Qt5Cored.dll
模块:5.8.0
文件:global\qglobal.cpp
专线:3070
断言:文件 io\qsceneloader.cpp 第 215 行中的“entities.size() == 1”
(按“重试”来调试应用程序)
Qt3DRender::QSceneLoader::状态(就绪)
I use http://code.qt.io/cgit/qt/qt3d.git/tree/tests/manual/assimp-cpp加载我自己的 Collada 机器人模型,该模型可以正常工作。重要的几行是:
// 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);
因此,请尝试使用您的 obj 文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)