setGeometry(spheremesh->geometry());(完整源代码如下) 结果,我收到一条消息: "Qt3D.R-6ren">
gpt4 book ai didi

c++ - Qt3D: "Mesh is empty, nothing to load"消息

转载 作者:行者123 更新时间:2023-11-30 04:43:27 25 4
gpt4 key购买 nike

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

结果,我收到一条消息:

"Qt3D.Renderer.Jobs: virtual Qt3DRender::QGeometry* Qt3DRender::MeshLoaderFunctor::operator()() Mesh is empty, nothing to load"

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

感谢大家!

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

最佳答案

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

关于c++ - Qt3D: "Mesh is empty, nothing to load"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com