PaintingUtil添加背景金属度、粗糙度的读取
parent
cdf9ec3c9c
commit
798dfddce8
|
@ -69,8 +69,14 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
treeWidget->elementManager = elementManager;
|
treeWidget->elementManager = elementManager;
|
||||||
//qDebug() << layerManager->toJson();
|
//qDebug() << layerManager->toJson();
|
||||||
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toInt(),jsonDoc.object().value("height").toInt()));
|
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toInt(),jsonDoc.object().value("height").toInt()));
|
||||||
previewWindow->canvasRoughness = jsonDoc.object().value("roughness").toDouble();
|
if (source.contains("metallic"))
|
||||||
previewWindow->canvasMetallic = jsonDoc.object().value("metallic").toDouble();
|
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)
|
if (layerManager->getRoot() != nullptr)
|
||||||
|
|
|
@ -36,13 +36,19 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
|
||||||
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
||||||
//qDebug() << jsonObj;
|
//qDebug() << jsonObj;
|
||||||
std::unordered_map<LayerWrapper*, Contour> contourMap;
|
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<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, QFileInfo(jsonFilePath).absolutePath());
|
||||||
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
|
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
|
||||||
LayerWrapper* root = layerManager->getRoot();
|
LayerWrapper* root = layerManager->getRoot();
|
||||||
root->getCache();
|
root->getCache();
|
||||||
double maxWidth = getMaxLineWidth(root, QTransform());
|
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();
|
clear();
|
||||||
return painting;
|
return painting;
|
||||||
//qDebug() << elementManager->toJson();
|
//qDebug() << elementManager->toJson();
|
||||||
|
|
|
@ -68,6 +68,7 @@ void Renderer::Model::loadModel(QString path)
|
||||||
if (QFile paintingConfigFile(directory.filePath(name + ".txt")); paintingConfigFile.open(QFile::ReadOnly | QIODevice::Text))
|
if (QFile paintingConfigFile(directory.filePath(name + ".txt")); paintingConfigFile.open(QFile::ReadOnly | QIODevice::Text))
|
||||||
{
|
{
|
||||||
QTextStream stream(&paintingConfigFile);
|
QTextStream stream(&paintingConfigFile);
|
||||||
|
stream.setCodec("UTF-8");
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
{
|
{
|
||||||
QString source, target;
|
QString source, target;
|
||||||
|
@ -102,7 +103,7 @@ void Renderer::Model::unloadModel()
|
||||||
{
|
{
|
||||||
paintingMap.clear();
|
paintingMap.clear();
|
||||||
for (auto& i : paintingLoaded)
|
for (auto& i : paintingLoaded)
|
||||||
vtManager->deleteVirtualTexture(i.second);
|
vtManager->deleteVirtualTexture(i.second.first);
|
||||||
paintingLoaded.clear();
|
paintingLoaded.clear();
|
||||||
texturesLoaded.clear();
|
texturesLoaded.clear();
|
||||||
meshes.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 mesh = std::make_unique<PaintingMesh>(glFunc, paintingProgram, shadowProgram, modelQ);
|
||||||
|
|
||||||
auto& [paintingPath, leftBottom, rightTop] = iter->second;
|
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)
|
for (auto& v : vertices)
|
||||||
{
|
{
|
||||||
|
@ -171,10 +177,6 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
||||||
mesh->vertices = vertices;
|
mesh->vertices = vertices;
|
||||||
mesh->indices = indices;
|
mesh->indices = indices;
|
||||||
|
|
||||||
mesh->paintingId = loadPainting(paintingPath);
|
|
||||||
auto& handle = vtManager->getPaintingHandle(mesh->paintingId);
|
|
||||||
mesh->textureBasecolor = handle.baseColor;
|
|
||||||
mesh->textureMetallicRoughness = handle.metallicRoughness;
|
|
||||||
mesh->setupMesh();
|
mesh->setupMesh();
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +236,7 @@ GLuint Model::loadMaterialTextures(aiMaterial* mat, aiTextureType type)
|
||||||
return texture.textureId();
|
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);
|
auto iter = paintingLoaded.find(path);
|
||||||
if (iter != paintingLoaded.end())
|
if (iter != paintingLoaded.end())
|
||||||
|
@ -367,6 +369,6 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
||||||
painting.generateBuffers(glFunc);
|
painting.generateBuffers(glFunc);
|
||||||
|
|
||||||
auto index = vtManager->createVirtualTexture(painting);
|
auto index = vtManager->createVirtualTexture(painting);
|
||||||
paintingLoaded.emplace(path, index);
|
paintingLoaded.emplace(path, std::make_pair(index, painting.widthHeightRatio));
|
||||||
return index;
|
return { index, painting.widthHeightRatio };
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace Renderer
|
||||||
* value json路径, 纹理坐标
|
* value json路径, 纹理坐标
|
||||||
*/
|
*/
|
||||||
std::unordered_map<std::string, std::tuple<std::string, glm::vec2, glm::vec2>> paintingMap;
|
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::unordered_map<std::string, QOpenGLTexture> texturesLoaded;
|
||||||
std::vector<std::unique_ptr<Drawable>> meshes;
|
std::vector<std::unique_ptr<Drawable>> meshes;
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ namespace Renderer
|
||||||
/// 加载材质纹理
|
/// 加载材质纹理
|
||||||
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
|
GLuint loadMaterialTextures(aiMaterial* mat, aiTextureType type);
|
||||||
|
|
||||||
GLuint loadPainting(std::string path);
|
std::pair<GLuint, float> loadPainting(std::string path);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -56,6 +56,7 @@ namespace Renderer
|
||||||
std::array<GLuint, 7> buffers;
|
std::array<GLuint, 7> buffers;
|
||||||
//QColor backgroundColor;
|
//QColor backgroundColor;
|
||||||
Material background;
|
Material background;
|
||||||
|
float widthHeightRatio = 1;
|
||||||
|
|
||||||
Painting(Material background = Material(Qt::white));
|
Painting(Material background = Material(Qt::white));
|
||||||
void addElement(const BaseElement& element, const ElementTransform& transform);
|
void addElement(const BaseElement& element, const ElementTransform& transform);
|
||||||
|
|
|
@ -38,7 +38,7 @@ void messageHandler(QtMsgType type, const QMessageLogContext& context, const QSt
|
||||||
QString(context.file).splitRef("\\").back().toLocal8Bit().data(),
|
QString(context.file).splitRef("\\").back().toLocal8Bit().data(),
|
||||||
context.line,
|
context.line,
|
||||||
QString(context.function).splitRef("(").first().split(" ").back().split(":").back().toLocal8Bit().data(),
|
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);
|
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue