我编写了一个简单的应用程序,以显示来自Blender的DEA文件,该文件存储在应用程序的资源文件中,以学习Qt3D模块,但似乎都在QML上,但是我最需要在c ++上工作。
enter code here
void add3dElements(Qt3DExtras::Qt3DWindow *view){
//To control input
Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
view->registerAspect(input);
// Root entity
Qt3DCore::QEntity *eRoot = new Qt3DCore::QEntity();
// Camera Entity
Qt3DRender::QCamera *eCamera = view->camera();
eCamera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
eCamera->setPosition(QVector3D(0, 0, 20.0f));
eCamera->setUpVector(QVector3D(0, 1, 0));
eCamera->setViewCenter(QVector3D(0, 0, 0));
//Light Entity
Qt3DCore::QEntity *eLight = new Qt3DCore::QEntity(eRoot);
//Light Point Entity
Qt3DRender::QPointLight *plLight = new Qt3DRender::QPointLight(eLight);
plLight->setColor("white");
plLight->setIntensity(1);
eLight->addComponent(plLight);
//Light Manager/Transformer
Qt3DCore::QTransform *tLightMng = new Qt3DCore::QTransform(eLight);
tLightMng->setTranslation(eCamera->position());
eLight->addComponent(tLightMng);
//Uploading Mesh
Qt3DRender::QMesh *mVehicle = new Qt3DRender::QMesh();
mVehicle->setSource(QUrl("://truck"));
//Mesh Manager/Trasnformer
Qt3DCore::QTransform *tMesh = new Qt3DCore::QTransform();
tMesh->setScale(5.f);
tMesh->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f));
tMesh->setTranslation(QVector3D(-5.0f, 4.0f, -1.5));
//set Mesh Material l
Qt3DExtras::QPhongMaterial *pmMesh = new Qt3DExtras::QPhongMaterial();
pmMesh->setDiffuse(QColor(QRgb(0x7733DD)));
//add Mesh Obj
Qt3DCore::QEntity *eMesh = new Qt3DCore::QEntity(eRoot);
eMesh->addComponent(mVehicle);
eMesh->addComponent(tMesh);
eMesh->addComponent(pmMesh);
//set Main Entity
view->setRootEntity(eRoot);
};
在主要功能中。我调用上面的过程来显示对象,这是一个存储在应用程序资源文件中的简单卡车,但是当我什么也不显示时,有人可以帮助我吗?
int main(int argc, char **argv)
{
QApplication app(argc, argv);
//key pad global management
QGlobalEventFilter *filter = new QGlobalEventFilter(qApp);
app.installEventFilter(filter);
QDesktopWidget *dtw = new QDesktopWidget();
Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
QWidget *container = QWidget::createWindowContainer(view);
QSize screenSize = view->screen()->size();
container->setMinimumSize(QSize(200, 100));
container->setMaximumSize(screenSize);
QWidget *widget = new QWidget;
widget->setWindowTitle("C.A.");
widget->setWindowState(Qt::WindowMaximized);
widget->setGeometry(dtw->availableGeometry());
add3dElements(view);
widget->show();
return app.exec();
}