diff --git a/ArchitectureColoredPainting/RendererWidget.ui b/ArchitectureColoredPainting/RendererWidget.ui index e116c32..e0d5a12 100644 --- a/ArchitectureColoredPainting/RendererWidget.ui +++ b/ArchitectureColoredPainting/RendererWidget.ui @@ -84,10 +84,26 @@ - + QLayout::SetDefaultConstraint + + + + + 0 + 0 + + + + + 0 + 16777215 + + + + diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 6e84bd7..ca1e2ca 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -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(); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index a27da25..13f8e4e 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -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(); - 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(); + 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]() { diff --git a/ArchitectureColoredPainting/src/Renderer/Mesh.h b/ArchitectureColoredPainting/src/Renderer/Mesh.h index ec452fd..35348bc 100644 --- a/ArchitectureColoredPainting/src/Renderer/Mesh.h +++ b/ArchitectureColoredPainting/src/Renderer/Mesh.h @@ -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 diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index e96d36a..bcbfbb5 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -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::max(); maxX = std::numeric_limits::min(); @@ -88,17 +112,6 @@ void Renderer::Model::loadModel(QString path) maxY = std::numeric_limits::min(); minZ = std::numeric_limits::max(); maxZ = std::numeric_limits::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) diff --git a/ArchitectureColoredPainting/src/Renderer/Model.h b/ArchitectureColoredPainting/src/Renderer/Model.h index d9a6bea..d8112f9 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.h +++ b/ArchitectureColoredPainting/src/Renderer/Model.h @@ -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> paintingMap; std::unordered_map paintingLoaded; diff --git a/ArchitectureColoredPainting/src/Renderer/RendererWidget.h b/ArchitectureColoredPainting/src/Renderer/RendererWidget.h index 258a173..d5a3725 100644 --- a/ArchitectureColoredPainting/src/Renderer/RendererWidget.h +++ b/ArchitectureColoredPainting/src/Renderer/RendererWidget.h @@ -13,6 +13,7 @@ namespace Renderer ~RendererWidget(); public slots: void currentTabChanged(int index); + private: Ui::RendererWidgetClass ui; }; diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp index b926ad4..87888db 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.cpp @@ -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) diff --git a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h index 520800b..bd31cbe 100644 --- a/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h +++ b/ArchitectureColoredPainting/src/Renderer/VirtualTextureManager.h @@ -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& pageIds);