我想在Qt 3D中绘制一个半透明的纹理球体(在其上绘制某种颜色图)。
我正在尝试绘制球体并添加纹理。纹理在球体的某些区域非常适合,但是在极点附近的poligons上它会变得嘶哑。
你能告诉我,我的错误是什么?
这是我尝试绘制球体的代码:
#include <QApplication>
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DCore/QEntity>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DExtras/QTextureMaterial>
#include <Qt3DExtras/QOrbitCameraController>
#include <Qt3DRender/QTexture>
#include <QPhongAlphaMaterial>
#include <qt3dwindow.h>
#include <QtWidgets/QWidget>
#include <qcamera.h>
#include <qforwardrenderer.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Qt3DExtras::Qt3DWindow* m_view = new Qt3DExtras::Qt3DWindow();
QWidget* container = QWidget::createWindowContainer(m_view);
container->show();
Qt3DCore::QEntity* m_rootEntity = new Qt3DCore::QEntity();
m_view->setRootEntity(m_rootEntity);
m_view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f)));
// let's make a sphere
Qt3DCore::QEntity* m_sphereEntity = new Qt3DCore::QEntity(m_rootEntity);
Qt3DExtras::QSphereMesh* m_sphereMesh = new Qt3DExtras::QSphereMesh();
m_sphereMesh->setRadius(12.);
m_sphereEntity->addComponent(m_sphereMesh);
// and glue some texture onto our sphere
Qt3DRender::QTextureLoader *loader = new Qt3DRender::QTextureLoader(m_sphereEntity);
Qt3DExtras::QTextureMaterial *material = new Qt3DExtras::QTextureMaterial(m_sphereEntity);
loader->setSource(QUrl::fromLocalFile(a.applicationDirPath() + QStringLiteral("/temp1.png")));
material->setTexture(loader);
m_sphereEntity->addComponent(material);
// initialise camera
Qt3DRender::QCamera *camera = m_view->camera();
camera->lens()->setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0);
camera->setPosition(QVector3D(0.0, 0.0, 40.0));
camera->setViewCenter(QVector3D(0.0, 0.0, 0.0));
// For camera controls.
Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(m_rootEntity);
camController->setLinearSpeed(50.0);
camController->setLookSpeed(180.0);
camController->setCamera(camera);
return a.exec();
}
这是temp1.png(色彩图的纹理):
P.S。另外,你能告诉我,有没有办法在我的Qt 3D纹理素材中添加alpha通道?这对我来说非常有用。