添加金属度和粗糙度设置

main
karlis 2023-04-03 19:37:09 +08:00
parent 0d5c513523
commit dfcad45b8c
8 changed files with 66 additions and 2 deletions

View File

@ -119,6 +119,10 @@ void EditorWidget::initProjectMenu()
currentEditorWidgetItem, &EditorWidgetItem::handleBackgroundColorChange); currentEditorWidgetItem, &EditorWidgetItem::handleBackgroundColorChange);
connect(dialog, &ProjectPropertyDialog::canvasSizeChanged, connect(dialog, &ProjectPropertyDialog::canvasSizeChanged,
currentEditorWidgetItem, &EditorWidgetItem::handleCanvasSizeChange); currentEditorWidgetItem, &EditorWidgetItem::handleCanvasSizeChange);
connect(dialog, &ProjectPropertyDialog::canvasRoughnessChanged,
currentEditorWidgetItem, &EditorWidgetItem::handleCanvasRoughnessChange);
connect(dialog, &ProjectPropertyDialog::canvasMetallicChanged,
currentEditorWidgetItem, &EditorWidgetItem::handleCanvasMetallicChange);
dialog->exec(); dialog->exec();
}); });
} }

View File

@ -69,6 +69,8 @@ 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();
previewWindow->canvasMetallic = jsonDoc.object().value("metallic").toDouble();
if (layerManager->getRoot() != nullptr) if (layerManager->getRoot() != nullptr)
@ -147,6 +149,8 @@ void EditorWidgetItem::saveImpl(QString filePath) const
QJsonObject source1 = layerManager->toJson(); QJsonObject source1 = layerManager->toJson();
QJsonObject source2 = elementManager->toJson(); QJsonObject source2 = elementManager->toJson();
QJsonObject json; QJsonObject json;
json.insert("roughness", previewWindow->canvasRoughness);
json.insert("metallic", previewWindow->canvasMetallic);
json.insert("width", previewWindow->referSize.width()); json.insert("width", previewWindow->referSize.width());
json.insert("height", previewWindow->referSize.height()); json.insert("height", previewWindow->referSize.height());
json.insert("root-layer", source1.value("root-layer")); json.insert("root-layer", source1.value("root-layer"));
@ -182,7 +186,27 @@ void EditorWidgetItem::handleCanvasSizeChange(const QSize& size)
previewWindow->resize(size); previewWindow->resize(size);
} }
void EditorWidgetItem::handleCanvasRoughnessChange(const float& roughness)
{
previewWindow->canvasRoughness = roughness;
}
void EditorWidgetItem::handleCanvasMetallicChange(const float& metallic)
{
previewWindow->canvasMetallic = metallic;
}
QSize EditorWidgetItem::getCanvasReferSize() const QSize EditorWidgetItem::getCanvasReferSize() const
{ {
return previewWindow->referSize; return previewWindow->referSize;
} }
float EditorWidgetItem::getCanvasRoughness() const
{
return previewWindow->canvasRoughness;
}
float EditorWidgetItem::getCanvasMetallic() const
{
return previewWindow->canvasMetallic;
}

View File

@ -47,7 +47,11 @@ public:
void handleBackgroundColorChange(const QColor& color); void handleBackgroundColorChange(const QColor& color);
void handleProjectNameChange(const QString& name); void handleProjectNameChange(const QString& name);
void handleCanvasSizeChange(const QSize& size); void handleCanvasSizeChange(const QSize& size);
void handleCanvasRoughnessChange(const float& roughness);
void handleCanvasMetallicChange(const float& metallic);
QSize getCanvasReferSize() const; QSize getCanvasReferSize() const;
float getCanvasRoughness() const;
float getCanvasMetallic() const;
private slots: private slots:
void onLayerChange(LayerWrapper *layer); void onLayerChange(LayerWrapper *layer);

View File

@ -39,6 +39,8 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions
void wheelEvent(QWheelEvent* event) override; void wheelEvent(QWheelEvent* event) override;
public: public:
float canvasRoughness;
float canvasMetallic;
QSize referSize; QSize referSize;
PreviewWindow(QWidget *parent = nullptr); PreviewWindow(QWidget *parent = nullptr);
void initialize(LayerManager *layerManager,QSize referSize, QSize windowSize = QSize(720, 720)); void initialize(LayerManager *layerManager,QSize referSize, QSize windowSize = QSize(720, 720));

View File

@ -4,23 +4,31 @@
CanvasPropertyWidget::CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent) CanvasPropertyWidget::CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent)
:PropertyWidget( :PropertyWidget(
std::make_unique<CanvasProperties>(editorWidgetItem->backgroundColor, editorWidgetItem->getCanvasReferSize()), std::make_unique<CanvasProperties>(editorWidgetItem->backgroundColor, editorWidgetItem->getCanvasReferSize(), editorWidgetItem->getCanvasRoughness(), editorWidgetItem->getCanvasMetallic()),
parent parent
), ),
backgroundColorPicker(new ColorPicker(clonedModel->backgroundColor, this)), backgroundColorPicker(new ColorPicker(clonedModel->backgroundColor, this)),
canvasWidth(new QtMaterialTextField(this)), canvasWidth(new QtMaterialTextField(this)),
canvasHeight(new QtMaterialTextField(this)) canvasHeight(new QtMaterialTextField(this)),
canvasRoughness(new QtMaterialTextField(this)),
canvasMetallic(new QtMaterialTextField(this))
{ {
auto* layout = new QFormLayout(this); auto* layout = new QFormLayout(this);
layout->addRow(QStringLiteral("画布背景颜色"), backgroundColorPicker); layout->addRow(QStringLiteral("画布背景颜色"), backgroundColorPicker);
layout->addRow(QStringLiteral("画布宽度"), canvasWidth); layout->addRow(QStringLiteral("画布宽度"), canvasWidth);
layout->addRow(QStringLiteral("画布高度"), canvasHeight); layout->addRow(QStringLiteral("画布高度"), canvasHeight);
layout->addRow(QStringLiteral("»­²¼´Ö²Ú¶È"), canvasRoughness);
layout->addRow(QStringLiteral("»­²¼½ðÊô¶È"), canvasMetallic);
canvasWidth->setText(QString::number(clonedModel->canvasSize.width())); canvasWidth->setText(QString::number(clonedModel->canvasSize.width()));
canvasHeight->setText(QString::number(clonedModel->canvasSize.height())); canvasHeight->setText(QString::number(clonedModel->canvasSize.height()));
canvasRoughness->setText(QString::number(clonedModel->canvasRoughness, 10, 3));
canvasMetallic->setText(QString::number(clonedModel->canvasMetallic, 10, 3));
canvasWidth->setValidator(new QIntValidator(1, std::numeric_limits<int>::max())); canvasWidth->setValidator(new QIntValidator(1, std::numeric_limits<int>::max()));
canvasHeight->setValidator(new QIntValidator(1, std::numeric_limits<int>::max())); canvasHeight->setValidator(new QIntValidator(1, std::numeric_limits<int>::max()));
canvasRoughness->setValidator(new QDoubleValidator(0, 1, 3));
canvasMetallic->setValidator(new QDoubleValidator(0, 1, 3));
connect(backgroundColorPicker, &ColorPicker::colorChanged, [this](const QColor& color) connect(backgroundColorPicker, &ColorPicker::colorChanged, [this](const QColor& color)
{ {
@ -34,4 +42,12 @@ CanvasPropertyWidget::CanvasPropertyWidget(const EditorWidgetItem* editorWidgetI
{ {
this->clonedModel->canvasSize.setHeight(newText.toInt()); this->clonedModel->canvasSize.setHeight(newText.toInt());
}); });
connect(canvasRoughness, &QtMaterialTextField::textEdited, [this](const QString& newText)
{
this->clonedModel->canvasRoughness = newText.toFloat();
});
connect(canvasMetallic, &QtMaterialTextField::textEdited, [this](const QString& newText)
{
this->clonedModel->canvasMetallic = newText.toFloat();
});
} }

View File

@ -8,6 +8,8 @@ struct CanvasProperties
{ {
QColor backgroundColor; QColor backgroundColor;
QSize canvasSize; QSize canvasSize;
float canvasRoughness;
float canvasMetallic;
}; };
class CanvasPropertyWidget : public PropertyWidget<CanvasProperties> class CanvasPropertyWidget : public PropertyWidget<CanvasProperties>
@ -17,6 +19,8 @@ private:
ColorPicker* backgroundColorPicker; ColorPicker* backgroundColorPicker;
QtMaterialTextField* canvasWidth; QtMaterialTextField* canvasWidth;
QtMaterialTextField* canvasHeight; QtMaterialTextField* canvasHeight;
QtMaterialTextField* canvasRoughness;
QtMaterialTextField* canvasMetallic;
public: public:
CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent = nullptr); CanvasPropertyWidget(const EditorWidgetItem* editorWidgetItem, QWidget* parent = nullptr);

View File

@ -40,5 +40,13 @@ void ProjectPropertyDialog::accept()
{ {
emit canvasSizeChanged(canvasProperties->canvasSize); emit canvasSizeChanged(canvasProperties->canvasSize);
} }
if (canvasProperties->canvasRoughness >= 0.0f && canvasProperties->canvasRoughness <= 1.0f)
{
emit canvasRoughnessChanged(canvasProperties->canvasRoughness);
}
if (canvasProperties->canvasMetallic >= 0.0f && canvasProperties->canvasMetallic <= 1.0f)
{
emit canvasMetallicChanged(canvasProperties->canvasMetallic);
}
QDialog::accept(); QDialog::accept();
} }

View File

@ -19,6 +19,8 @@ signals:
void backgroundColorChanged(const QColor& newBackgroundColor); void backgroundColorChanged(const QColor& newBackgroundColor);
void canvasSizeChanged(const QSize& newCanvasSize); void canvasSizeChanged(const QSize& newCanvasSize);
void projectNameChanged(const QString& newProjectName); void projectNameChanged(const QString& newProjectName);
void canvasRoughnessChanged(const float& newCanvasRoughness);
void canvasMetallicChanged(const float& newCanvasMetallic);
private slots: private slots:
void accept() override; void accept() override;