【问题标题】:Qt3D: "Mesh is empty, nothing to load" messageQt3D:“网格是空的,没有可加载的”消息
【发布时间】:2019-10-07 16:22:36
【问题描述】:

我需要将预定义网格中的几何图形加载到自定义网格中。 我这样做: mesh->setGeometry(spheremesh->geometry());(完整源代码如下)

结果,我收到一条消息:

"Qt3D.Renderer.Jobs: 虚拟Qt3DRender::QGeometry* Qt3DRender::MeshLoaderFunctor::operator()() Mesh 是空的,什么都没有 加载”

但代码正在运行。我的错误是什么?怎么做才对?

谢谢大家!

ma​​in.cpp:

 #include <QGuiApplication>
 #include <Qt3DCore/QEntity>
 #include <Qt3DCore/QTransform>
 #include <Qt3DExtras/Qt3DWindow>
 #include <Qt3DExtras/QSphereMesh>
 #include <Qt3DExtras/QPhongMaterial>
 #include <Qt3DExtras/QFirstPersonCameraController>
 #include <Qt3DRender/QMesh>
 #include <Qt3DRender/QCamera>

    int main(int argc, char *argv[])
    {
        QGuiApplication application(argc, argv);

        Qt3DExtras::Qt3DWindow window;

        auto scene = new Qt3DCore::QEntity;
        window.setRootEntity(scene);

        auto entity = new Qt3DCore::QEntity(scene);

        auto transform = new Qt3DCore::QTransform(entity);
        transform->setTranslation(QVector3D(0.0f, 0.0f, -10.0f));

        auto material = new Qt3DExtras::QPhongMaterial(entity);
        material->setAmbient(QColor(245-30, 245-15, 245));
        material->setDiffuse(QColor(125-30, 125-15, 125));
        material->setSpecular(QColor(215-30, 255-15, 255));

        auto spheremesh = new Qt3DExtras::QSphereMesh(entity);
        spheremesh->setRadius(15.0);
        spheremesh->setSlices(32);
        spheremesh->setRings(32);

        auto mesh = new Qt3DRender::QMesh(entity);
        mesh->setGeometry(spheremesh->geometry());

        entity->addComponent(transform);
        entity->addComponent(material);
        //entity->addComponent(spheremesh);
        entity->addComponent(mesh);

        auto camera = window.camera();
        camera->lens()->setPerspectiveProjection(60.0f, static_cast<float>(window.width()) / window.height(), 0.1f, 1000.0f);
        camera->setPosition(QVector3D(0.0f, 0.0f, 40.0f));
        camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));

        auto camController = new Qt3DExtras::QFirstPersonCameraController(scene);
        camController->setCamera(camera);

        window.show();
        return application.exec();
    }

qt3dsimpletest.pro:

QT       += core 3dlogic 3dextras 3dinput

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
    main.cpp

HEADERS +=

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

【问题讨论】:

    标签: c++ qt qt3d


    【解决方案1】:

    我明白了。对于这个任务需要使用 Qt3DRender::QGeometryRenderer 类代替 Qt3DRender::QMesh

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 1970-01-01
      • 2018-11-06
      相关资源
      最近更新 更多