Qt3D:“网格是空的,没有可加载的”消息
Posted
技术标签:
【中文标题】Qt3D:“网格是空的,没有可加载的”消息【英文标题】:Qt3D: "Mesh is empty, nothing to load" message 【发布时间】:2019-10-07 16:22:36 【问题描述】:我需要将预定义网格中的几何图形加载到自定义网格中。 我这样做: mesh->setGeometry(spheremesh->geometry());(完整源代码如下)
结果,我收到一条消息:
"Qt3D.Renderer.Jobs: 虚拟Qt3DRender::QGeometry* Qt3DRender::MeshLoaderFunctor::operator()() Mesh 是空的,什么都没有 加载”
但代码正在运行。我的错误是什么?怎么做才对?
谢谢大家!
main.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
【问题讨论】:
【参考方案1】:我明白了。对于这个任务需要使用 Qt3DRender::QGeometryRenderer 类代替 Qt3DRender::QMesh。
【讨论】:
以上是关于Qt3D:“网格是空的,没有可加载的”消息的主要内容,如果未能解决你的问题,请参考以下文章
无法使用 Qt3D 查看/加载 .obj 文件,用 cpp 编写