qt - 如何使用 QExtrudedTextMesh 设置 QMetalRoughMaterial
问题描述
我正在尝试将金属材质纹理应用于 3D 挤压文本网格。
我的示例代码基于此: https ://code.woboq.org/qt5/qt3d/examples/qt3d/3d-text/main.cpp.html
该示例使用QPhongMaterial
. 我天真地以为我可以简单地替换QMetalRoughMaterial
我尝试过的材料。
#include <QCoreApplication>
#include <Qt3DCore/Qt3DCore>
#include <Qt3DExtras/Qt3DExtras>
#include <Qt3DExtras/QExtrudedTextMesh>
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
view->setTitle(QStringLiteral("3D Text CPP"));
view->defaultFrameGraph()->setClearColor(QColor("white"));
auto *root = new Qt3DCore::QEntity();
//Light
Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(root);
Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
light->setColor("white");
light->setIntensity(0.5);
lightEntity->addComponent(light);
//auto *textMaterial = new Qt3DExtras::QPhongMaterial(root);
auto *textMaterial = new Qt3DExtras::QMetalRoughMaterial(root);
auto *text = new Qt3DCore::QEntity(root);
auto *textMesh = new Qt3DExtras::QExtrudedTextMesh();
auto *textTransform = new Qt3DCore::QTransform();
QFont font("Arial", 32, -1, false);
textTransform->setTranslation(QVector3D(-2.45f, 2.0 * .5f, 0));
textTransform->setScale(.8f);
textMesh->setDepth(.25f);
textMesh->setFont(font);
textMesh->setText("TEST");
//FOR PHONG MATERIAL
//textMaterial->setDiffuse(QColor("white"));
//textMaterial->setShininess(1.0);
//textMaterial->setSpecular(QColor("white"));
//FOR METAL
textMaterial->setBaseColor(QColor("blue"));
textMaterial->setMetalness(1.0);
textMaterial->setRoughness(0.2);
//textMaterial->setNormal(...)); //<-- what needs to come here?
text->addComponent(textMaterial);
text->addComponent(textMesh);
text->addComponent(textTransform);
// Camera
float aspect = static_cast<float>(view->screen()->size().width()) / view->screen()->size().height();
Qt3DRender::QCamera *camera = view->camera();
camera->lens()->setPerspectiveProjection(65.f, aspect, 0.1f, 100.f);
camera->setPosition(QVector3D(0, 1, 3));
camera->setViewCenter(QVector3D(0, 1, 0));
auto *cameraController = new Qt3DExtras::QOrbitCameraController(root);
cameraController->setCamera(camera);
view->setRootEntity(root);
view->show();
return a.exec();
}
使用上面的代码,我在应用程序窗口中看不到任何文本,而在使用QPhongMaterial
.
我在这里想念什么?