场景渲染增加纹理列表

main
wuyize 2023-04-08 21:07:10 +08:00
parent 4be720a677
commit 9cc5466abc
8 changed files with 113 additions and 24 deletions

View File

@ -85,23 +85,63 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QListWidget" name="textureListWidget">
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<width>260</width>
<height>16777215</height>
</size>
</property>
<property name="tabPosition">
<enum>QTabWidget::West</enum>
</property>
<widget class="QWidget" name="textureTab">
<attribute name="title">
<string>纹理</string>
</attribute>
<layout class="QVBoxLayout" name="vboxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4"/>
</item>
<item>
<widget class="QListWidget" name="textureListWidget">
<property name="styleSheet">
<string notr="true">QListWidget{
border: 0
}</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>

View File

@ -112,6 +112,11 @@ void Renderer::Model::unloadModel()
maxPos = glm::vec3(std::numeric_limits<float>::min());
}
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& Renderer::Model::getPaintingMap()
{
return paintingMap;
}
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
{
// 处理节点所有的网格(如果有的话)

View File

@ -10,13 +10,15 @@ namespace Renderer
class Model
{
public:
std::vector<QVector3D> AABB;
Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager);
void draw();
void drawShadow();
void loadModel(QString path);
void unloadModel();
Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager);
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& getPaintingMap();
std::vector<QVector3D> AABB;
private:
QOpenGLContext* context = nullptr;
QOpenGLFunctions_4_5_Core* glFunc = nullptr;

View File

@ -73,6 +73,11 @@ void RendererGLWidget::stopTimer()
timerId = -1;
}
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& Renderer::RendererGLWidget::getPaintingMap()
{
return model->getPaintingMap();
}
void RendererGLWidget::setModel(QString path)
{
makeCurrent();

View File

@ -25,6 +25,8 @@ namespace Renderer
void startTimer();
void stopTimer();
const std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>>& getPaintingMap();
public slots:
void setModel(QString path);
void setMainLightPitch(float pitch);

View File

@ -10,13 +10,60 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
auto openAction = new QAction(QStringLiteral("´ò¿ª"), ui.openButton);
auto saveAction = new QAction(QStringLiteral("±£´æ"), ui.openButton);
auto refreshAction = new QAction(QStringLiteral("ÖØмÓÔØ"), ui.openButton);
auto testAction = new QAction(QStringLiteral("²âÊÔ"), ui.openButton);
auto test2Action = new QAction(QStringLiteral("²âÊÔ2"), ui.openButton);
ui.openButton->addMenuAction(openAction);
ui.openButton->addMenuAction(saveAction);
ui.openButton->addMenuAction(refreshAction);
//ui.openButton->addMenuAction(testAction);
//ui.openButton->addMenuAction(test2Action);
static QString modelFileName;
QObject::connect(openAction, &QAction::triggered, [&] {
QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral("´ò¿ªÄ£ÐÍ"), QString(), QStringLiteral("glTF 2.0 (*.gltf)"));
qDebug() << fileName;
if (fileName != QString())
{
modelFileName = fileName;
ui.openGLWidget->setModel(fileName);
QStringList list;
for (auto& i : ui.openGLWidget->getPaintingMap())
{
auto& [paintingPath, leftBottom, rightTop] = i.second;
list.append(QString::fromStdString(paintingPath));
}
ui.textureListWidget->clear();
ui.textureListWidget->addItems(list);
}
});
QObject::connect(refreshAction, &QAction::triggered, [&] {
if (modelFileName != QString())
ui.openGLWidget->setModel(modelFileName);
});
QObject::connect(testAction, &QAction::triggered, [&] {
ui.openGLWidget->setModel("Models/Sponza/Sponza.gltf");
});
QObject::connect(test2Action, &QAction::triggered, [&] {
ui.openGLWidget->setModel("E:\\3D Objects\\Gate\\Gate.gltf");
});
QObject::connect(ui.tabWidget, &QTabWidget::tabBarClicked, [&] {
static bool hide = false;
static int maxWidth = ui.tabWidget->maximumWidth();
hide = !hide;
ui.tabWidget->setStyleSheet(hide
? "QTabBar::tab {background-color:rgba(0,0,0,0);} QTabBar::tab:hover{background-color: rgb(213, 213, 213);}"
: "QTabBar::tab:hover{background-color: rgb(213, 213, 213);}");
ui.tabWidget->setFixedWidth(hide ? ui.tabWidget->tabBar()->width() : maxWidth);
});
QObject::connect(ui.textureListWidget, &QListWidget::itemDoubleClicked, [&](QListWidgetItem* item) {
QString paintingPath = QFileInfo(modelFileName).dir().filePath(item->text());
qDebug() << paintingPath;
});
QObject::connect(ui.horizontalSlider, &QSlider::valueChanged,
ui.openGLWidget, &Renderer::RendererGLWidget::setMainLightPitch);
QObject::connect(ui.horizontalSlider_2, &QSlider::valueChanged,
@ -24,19 +71,6 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
QObject::connect(ui.exposureSlider, &QSlider::valueChanged, [&](int value) {
ui.openGLWidget->setExposure(value / 100.f);
});
QObject::connect(openAction, &QAction::triggered, [&] {
QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral("´ò¿ªÄ£ÐÍ"), QString(), QStringLiteral("glTF 2.0 (*.gltf)"));
qDebug() << fileName;
if (fileName != QString())
ui.openGLWidget->setModel(fileName);
});
QObject::connect(testAction, &QAction::triggered, [&] {
ui.openGLWidget->setModel("Models/Sponza/Sponza.gltf");
});
QObject::connect(test2Action, &QAction::triggered, [&] {
ui.openGLWidget->setModel("E:\\3D Objects\\Gate\\Gate.gltf");
});
ui.horizontalSlider->setValue(105);
ui.horizontalSlider_2->setValue(80);
ui.exposureSlider->setValue(60);

View File

@ -14,6 +14,7 @@ namespace Renderer
public slots:
void currentTabChanged(int index);
private:
Ui::RendererWidgetClass ui;
};

View File

@ -85,7 +85,7 @@ Renderer::VirtualTextureManager::VirtualTextureManager(GladGLContext* glMain)
//qDebug() << duration;
pageLoadDuration += duration;
}
std::this_thread::yield();
//std::this_thread::yield();
}
});