diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index 0fc9db8..d6f4f60 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -69,8 +69,14 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p treeWidget->elementManager = elementManager; //qDebug() << layerManager->toJson(); previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toInt(),jsonDoc.object().value("height").toInt())); - previewWindow->canvasRoughness = jsonDoc.object().value("roughness").toDouble(); - previewWindow->canvasMetallic = jsonDoc.object().value("metallic").toDouble(); + if (source.contains("metallic")) + previewWindow->canvasMetallic = jsonDoc.object().value("metallic").toDouble(); + else + previewWindow->canvasMetallic = 0; + if (source.contains("roughness")) + previewWindow->canvasRoughness = jsonDoc.object().value("roughness").toDouble(); + else + previewWindow->canvasRoughness = 0.5; if (layerManager->getRoot() != nullptr) diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index 176849f..fe13151 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -36,13 +36,19 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { QJsonObject jsonObj = readJsonFile(jsonFilePath); //qDebug() << jsonObj; std::unordered_map contourMap; - Painting painting(Renderer::Material(jsonObj.value("background-color").toVariant().value())); + Renderer::Material background(jsonObj.value("background-color").toVariant().value()); + if (jsonObj.contains("metallic")) + background.setMetallicF(jsonObj.value("metallic").toDouble()); + if (jsonObj.contains("roughness")) + background.setRoughnessF(jsonObj.value("roughness").toDouble()); + Painting painting(Renderer::Material(jsonObj.value("background-color").toVariant().value(), jsonObj.value("metallic").toDouble())); shared_ptr elementManager = make_shared(jsonObj, QFileInfo(jsonFilePath).absolutePath()); shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); LayerWrapper* root = layerManager->getRoot(); root->getCache(); double maxWidth = getMaxLineWidth(root, QTransform()); - handleLayerWrapper(root, QTransform(), painting, maxWidth, contourMap, QSize(jsonObj.value("width").toVariant().value(), jsonObj.value("height").toVariant().value())); + painting.widthHeightRatio = (double)jsonObj.value("width").toInt() / jsonObj.value("height").toInt(); + handleLayerWrapper(root, QTransform(), painting, maxWidth, contourMap, QSize(jsonObj.value("width").toInt(), jsonObj.value("height").toInt())); clear(); return painting; //qDebug() << elementManager->toJson(); diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 87e2253..6b0663a 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -68,6 +68,7 @@ void Renderer::Model::loadModel(QString path) if (QFile paintingConfigFile(directory.filePath(name + ".txt")); paintingConfigFile.open(QFile::ReadOnly | QIODevice::Text)) { QTextStream stream(&paintingConfigFile); + stream.setCodec("UTF-8"); while (!stream.atEnd()) { QString source, target; @@ -102,7 +103,7 @@ void Renderer::Model::unloadModel() { paintingMap.clear(); for (auto& i : paintingLoaded) - vtManager->deleteVirtualTexture(i.second); + vtManager->deleteVirtualTexture(i.second.first); paintingLoaded.clear(); texturesLoaded.clear(); meshes.clear(); @@ -161,6 +162,11 @@ std::unique_ptr Model::processMesh(aiMesh* mesh, const aiScene* scene, auto mesh = std::make_unique(glFunc, paintingProgram, shadowProgram, modelQ); auto& [paintingPath, leftBottom, rightTop] = iter->second; + auto [paintingId, ratio] = loadPainting(paintingPath); + mesh->paintingId = paintingId; + auto& handle = vtManager->getPaintingHandle(mesh->paintingId); + mesh->textureBasecolor = handle.baseColor; + mesh->textureMetallicRoughness = handle.metallicRoughness; for (auto& v : vertices) { @@ -171,10 +177,6 @@ std::unique_ptr Model::processMesh(aiMesh* mesh, const aiScene* scene, mesh->vertices = vertices; mesh->indices = indices; - mesh->paintingId = loadPainting(paintingPath); - auto& handle = vtManager->getPaintingHandle(mesh->paintingId); - mesh->textureBasecolor = handle.baseColor; - mesh->textureMetallicRoughness = handle.metallicRoughness; mesh->setupMesh(); return mesh; } @@ -234,7 +236,7 @@ GLuint Model::loadMaterialTextures(aiMaterial* mat, aiTextureType type) return texture.textureId(); } -GLuint Renderer::Model::loadPainting(std::string path) +std::pair Renderer::Model::loadPainting(std::string path) { auto iter = paintingLoaded.find(path); if (iter != paintingLoaded.end()) @@ -367,6 +369,6 @@ GLuint Renderer::Model::loadPainting(std::string path) painting.generateBuffers(glFunc); auto index = vtManager->createVirtualTexture(painting); - paintingLoaded.emplace(path, index); - return index; + paintingLoaded.emplace(path, std::make_pair(index, painting.widthHeightRatio)); + return { index, painting.widthHeightRatio }; } diff --git a/ArchitectureColoredPainting/src/Renderer/Model.h b/ArchitectureColoredPainting/src/Renderer/Model.h index 21c5674..b535522 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.h +++ b/ArchitectureColoredPainting/src/Renderer/Model.h @@ -30,7 +30,7 @@ namespace Renderer * value json路径, 纹理坐标 */ std::unordered_map> paintingMap; - std::unordered_map paintingLoaded; + std::unordered_map> paintingLoaded; std::unordered_map texturesLoaded; std::vector> meshes; @@ -49,6 +49,6 @@ namespace Renderer /// 加载材质纹理 GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type); - GLuint loadPainting(std::string path); + std::pair loadPainting(std::string path); }; } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h index 1dbde54..14542e8 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h @@ -56,6 +56,7 @@ namespace Renderer std::array buffers; //QColor backgroundColor; Material background; + float widthHeightRatio = 1; Painting(Material background = Material(Qt::white)); void addElement(const BaseElement& element, const ElementTransform& transform); diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 0e3d73b..c21acaf 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -38,7 +38,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt QString(context.file).splitRef("\\").back().toLocal8Bit().data(), context.line, QString(context.function).splitRef("(").first().split(" ").back().split(":").back().toLocal8Bit().data(), - msg.toStdString()); + msg.toLocal8Bit().data()); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); }