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

Qt3D: "Mesh is empty, nothing to load" message

本文关键字:nothing to load 消息 empty Mesh is Qt3D      更新时间:2023-10-16

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

结果,我收到一条消息:

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

但是代码正在工作。我的错误是什么?怎么做对?

谢谢大家!

主.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