本文介绍了Qt3d与Qt 5.8一起使用QSceneLoader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我未能尝试使用QSceneLoader加载在外部编辑器中创建的3d场景.在加载阶段,我总是会断言.我使用OBJ模型qt的示例,该示例很容易作为QMesh加载.

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.

测试库 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(正在加载)在io \ qsceneloader.cpp文件的第215行中声明:"entities.size()== 1"调试错误!

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

程序:C:\ Qt \ Qt5.8.0 \ 5.8 \ msvc2015 \ bin \ Qt5Cored.dll模组:5.8.0档案:global \ qglobal.cpp线:3070

Program: C:\Qt\Qt5.8.0\5.8\msvc2015\bin\Qt5Cored.dllModule: 5.8.0File: global\qglobal.cppLine: 3070

在文件io \ qsceneloader.cpp的第215行中,ASSERT:"entities.size()== 1"

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

(按重试"以调试应用程序)Qt3DRender :: QSceneLoader :: Status(就绪)

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

推荐答案

我使用 http://code.qt.io/cgit/qt/qt3d.git/tree/tests/manual/assimp-cpp 加载我自己的Collada机器人模型错误.重要的几行是:

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

因此,请尝试使用您的obj文件.

So try it out with your obj file.

这篇关于Qt3d与Qt 5.8一起使用QSceneLoader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 02:38