merge
commit
f42868cf3f
|
@ -84,10 +84,26 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QListWidget" name="textureListWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Renderer::RendererGLWidget" name="openGLWidget">
|
||||
<property name="sizePolicy">
|
||||
|
|
|
@ -60,13 +60,13 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||
scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
|
||||
connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||
scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
|
||||
connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
|
||||
emit requireRefreshElementWidget();
|
||||
|
|
|
@ -78,13 +78,14 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
emit requireRefreshPreview();
|
||||
});
|
||||
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
|
||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->delSelf();
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
if(typeid(*layer) == typeid(FolderLayerWrapper))
|
||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||
layer->delSelf();
|
||||
layer->getParent()->removeChild(layer);
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
}
|
||||
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {
|
||||
menu.addAction(QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"), this, [this]() {
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Renderer
|
|||
glm::vec3 Position;
|
||||
glm::vec3 Normal;
|
||||
glm::vec2 TexCoords;
|
||||
Vertex(const aiVector3D& position, const aiVector3D& Normal, const aiVector3D& TexCoords);
|
||||
Vertex(const aiVector3D& position, const aiVector3D& normal, const aiVector3D& texCoords);
|
||||
};
|
||||
|
||||
struct Texture
|
||||
|
|
|
@ -32,14 +32,12 @@ Model::Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram,
|
|||
}
|
||||
|
||||
void Model::draw() {
|
||||
//shaderProgram->bind();
|
||||
for (auto& mesh : meshes) {
|
||||
mesh->draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Model::drawShadow() {
|
||||
//shaderProgram->bind();
|
||||
for (auto& mesh : meshes) {
|
||||
mesh->drawShadow();
|
||||
}
|
||||
|
@ -55,7 +53,7 @@ void Renderer::Model::loadModel(QString path)
|
|||
const aiScene* scene = importer.ReadFile(modelFile.absoluteFilePath().toUtf8(), aiProcess_Triangulate);
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
qCritical() << "ERROR::ASSIMP::" << importer.GetErrorString() << endl;
|
||||
qCritical() << "ERROR::ASSIMP::" << importer.GetErrorString();
|
||||
return;
|
||||
}
|
||||
qDebug() << modelFile.absoluteFilePath() << "Loaded Successfully";
|
||||
|
@ -63,9 +61,11 @@ void Renderer::Model::loadModel(QString path)
|
|||
qDebug() << "NumMaterials: " << scene->mNumMaterials;
|
||||
qDebug() << "NumTextures: " << scene->mNumTextures;
|
||||
|
||||
unloadModel();
|
||||
|
||||
|
||||
if (QFile paintingConfigFile(directory.filePath(name + ".txt")); paintingConfigFile.open(QFile::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
paintingMap.clear();
|
||||
QTextStream stream(&paintingConfigFile);
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
|
@ -81,6 +81,30 @@ void Renderer::Model::loadModel(QString path)
|
|||
{
|
||||
qWarning() << "Painting Config Not Found!";
|
||||
}
|
||||
|
||||
|
||||
aiMatrix4x4 transform;
|
||||
aiMatrix4x4::Scaling(aiVector3D(1 / 0.008), transform);
|
||||
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
|
||||
AABB.clear();
|
||||
AABB.emplace_back(minX, minY, minZ);
|
||||
AABB.emplace_back(minX, minY, maxZ);
|
||||
AABB.emplace_back(minX, maxY, minZ);
|
||||
AABB.emplace_back(minX, maxY, maxZ);
|
||||
AABB.emplace_back(maxX, minY, minZ);
|
||||
AABB.emplace_back(maxX, minY, maxZ);
|
||||
AABB.emplace_back(maxX, maxY, minZ);
|
||||
AABB.emplace_back(maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
void Renderer::Model::unloadModel()
|
||||
{
|
||||
paintingMap.clear();
|
||||
for(auto& i: paintingLoaded)
|
||||
vtManager->deleteVirtualTexture(i.second);
|
||||
paintingLoaded.clear();
|
||||
texturesLoaded.clear();
|
||||
meshes.clear();
|
||||
|
||||
minX = std::numeric_limits<float>::max();
|
||||
maxX = std::numeric_limits<float>::min();
|
||||
|
@ -88,17 +112,6 @@ void Renderer::Model::loadModel(QString path)
|
|||
maxY = std::numeric_limits<float>::min();
|
||||
minZ = std::numeric_limits<float>::max();
|
||||
maxZ = std::numeric_limits<float>::min();
|
||||
aiMatrix4x4 transform;
|
||||
aiMatrix4x4::Scaling(aiVector3D(1 / 0.008), transform);
|
||||
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
|
||||
AABB.push_back(QVector3D(minX, minY, minZ));
|
||||
AABB.push_back(QVector3D(minX, minY, maxZ));
|
||||
AABB.push_back(QVector3D(minX, maxY, minZ));
|
||||
AABB.push_back(QVector3D(minX, maxY, maxZ));
|
||||
AABB.push_back(QVector3D(maxX, minY, minZ));
|
||||
AABB.push_back(QVector3D(maxX, minY, maxZ));
|
||||
AABB.push_back(QVector3D(maxX, maxY, minZ));
|
||||
AABB.push_back(QVector3D(maxX, maxY, maxZ));
|
||||
}
|
||||
|
||||
void Model::processNode(aiNode* node, const aiScene* scene, aiMatrix4x4 mat4)
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Renderer
|
|||
void draw();
|
||||
void drawShadow();
|
||||
void loadModel(QString path);
|
||||
void unloadModel();
|
||||
Model(QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram, QOpenGLShaderProgram* paintingProgram, QOpenGLShaderProgram* shadowProgram, VirtualTextureManager* vtManager);
|
||||
private:
|
||||
QOpenGLContext* context = nullptr;
|
||||
|
@ -25,8 +26,8 @@ namespace Renderer
|
|||
VirtualTextureManager* vtManager = nullptr;
|
||||
|
||||
/**
|
||||
* @param key BaseColor路径
|
||||
* @param value json路径, 纹理坐标
|
||||
* @brief key BaseColor路径 \n
|
||||
* value json路径, 纹理坐标
|
||||
*/
|
||||
std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>> paintingMap;
|
||||
std::unordered_map<std::string, GLuint> paintingLoaded;
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Renderer
|
|||
~RendererWidget();
|
||||
public slots:
|
||||
void currentTabChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::RendererWidgetClass ui;
|
||||
};
|
||||
|
|
|
@ -76,7 +76,7 @@ Renderer::VirtualTextureManager::VirtualTextureManager(GladGLContext* glMain)
|
|||
pageIdBufferMutex.lock();
|
||||
currentBuffer = 1 - currentBuffer;
|
||||
pageIdBufferMutex.unlock();
|
||||
|
||||
|
||||
gl->BeginQuery(GL_TIME_ELAPSED, pageLoadTimeQuery);
|
||||
updatePages(pageIds);
|
||||
gl->EndQuery(GL_TIME_ELAPSED);
|
||||
|
@ -152,8 +152,26 @@ std::uint16_t Renderer::VirtualTextureManager::createVirtualTexture(Painting pai
|
|||
|
||||
}
|
||||
}
|
||||
paintings.emplace_back(baseColor, metallicRoughness, painting.buffers);
|
||||
return paintings.size();
|
||||
if (const auto it = std::find_if(paintings.begin(), paintings.end(), [](const PaintingHandle& i) { return i.baseColor == 0; });
|
||||
it != paintings.end())
|
||||
{
|
||||
*it = { baseColor, metallicRoughness, painting.buffers };
|
||||
return it - paintings.begin() + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
paintings.emplace_back(baseColor, metallicRoughness, painting.buffers);
|
||||
return paintings.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Renderer::VirtualTextureManager::deleteVirtualTexture(std::uint16_t id)
|
||||
{
|
||||
auto& painting = getPaintingHandle(id);
|
||||
glMain->DeleteTextures(2, (GLuint*)&painting);
|
||||
painting.baseColor = 0;
|
||||
painting.metallicRoughness = 0;
|
||||
}
|
||||
|
||||
Renderer::PaintingHandle& Renderer::VirtualTextureManager::getPaintingHandle(std::uint16_t id)
|
||||
|
|
|
@ -24,11 +24,12 @@ namespace Renderer
|
|||
VirtualTextureManager(GladGLContext* glMain);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param painting
|
||||
* @brief 创建彩绘虚拟纹理
|
||||
* @param painting 彩绘
|
||||
* @return 虚拟纹理id
|
||||
*/
|
||||
std::uint16_t createVirtualTexture(Painting painting);
|
||||
void deleteVirtualTexture(std::uint16_t id);
|
||||
PaintingHandle& getPaintingHandle(std::uint16_t id);
|
||||
void tryUpdatePages(const std::vector<glm::u16vec2>& pageIds);
|
||||
|
||||
|
|
Loading…
Reference in New Issue