PaintingUtil添加背景金属度、粗糙度的读取

main
wuyize 2023-04-08 13:21:15 +08:00
parent cdf9ec3c9c
commit 798dfddce8
6 changed files with 30 additions and 15 deletions

View File

@ -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)

View File

@ -36,13 +36,19 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
QJsonObject jsonObj = readJsonFile(jsonFilePath);
//qDebug() << jsonObj;
std::unordered_map<LayerWrapper*, Contour> contourMap;
Painting painting(Renderer::Material(jsonObj.value("background-color").toVariant().value<QColor>()));
Renderer::Material background(jsonObj.value("background-color").toVariant().value<QColor>());
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<QColor>(), jsonObj.value("metallic").toDouble()));
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, QFileInfo(jsonFilePath).absolutePath());
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(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<int>(), jsonObj.value("height").toVariant().value<int>()));
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();

View File

@ -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<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
auto mesh = std::make_unique<PaintingMesh>(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<Drawable> 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<GLuint, float> 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 };
}

View File

@ -30,7 +30,7 @@ namespace Renderer
* value json,
*/
std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>> paintingMap;
std::unordered_map<std::string, GLuint> paintingLoaded;
std::unordered_map<std::string, std::pair<GLuint, float>> paintingLoaded;
std::unordered_map<std::string, QOpenGLTexture> texturesLoaded;
std::vector<std::unique_ptr<Drawable>> meshes;
@ -49,6 +49,6 @@ namespace Renderer
/// 加载材质纹理
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
GLuint loadPainting(std::string path);
std::pair<GLuint, float> loadPainting(std::string path);
};
}

View File

@ -56,6 +56,7 @@ namespace Renderer
std::array<GLuint, 7> buffers;
//QColor backgroundColor;
Material background;
float widthHeightRatio = 1;
Painting(Material background = Material(Qt::white));
void addElement(const BaseElement& element, const ElementTransform& transform);

View File

@ -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);
}