From 60c7695545feaad905f34a7ab0216e4342ca587b Mon Sep 17 00:00:00 2001 From: wuyize Date: Wed, 22 Mar 2023 14:51:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20PreviewWindow=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=B8=8D=E5=AE=8C=E6=95=B4=20|=20#26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditorWidgetItem.ui | 32 +++---------------- .../res/Shaders/painting.comp | 2 +- .../src/Editor/util/PaintingUtil.cpp | 19 +++++++---- .../src/Renderer/Model.cpp | 2 +- svg/正方形.svg | 1 + 5 files changed, 19 insertions(+), 37 deletions(-) create mode 100644 svg/正方形.svg diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index a02c38d..1ac2ea4 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -66,11 +66,11 @@ true - + 0 - 0 + -17 1024 1024 @@ -89,34 +89,10 @@ - 10241024 - 10241024 + 1024 + 1024 - - - - - - 0 - 0 - - - - - 1024 - 1024 - - - - - 1024 - 1024 - - - - - diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index d46c93d..2fc3e0a 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -1402,7 +1402,7 @@ void main() if (elementZIndex <= zIndex) { uint transformIndex = leftChild - 0x80000000; - uint elementIndex = bvhChildren[index].y - elementZIndex; + uint elementIndex = bvhChildren[index].y & 0x3FFFF; mat3x2 transform = elementTranform[transformIndex]; vec2 localUV = (mat3(vec3(transform[0], 0), vec3(transform[1], 0), vec3(transform[2], 1)) * vec3(uv, 1)) diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index 0d17267..1aab871 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -91,7 +91,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo QTransform trans; double maxLen = std::max(bound.width(), bound.height()) * 1.00001; //qDebug() << maxLen << bound; - trans.scale(1 / maxLen, 1 / maxLen); + trans.scale(2 / maxLen, 2 / maxLen); trans.translate(-bound.center().x(), -bound.center().y()); //std::shared_ptr keyLayerPtr(nowLayer); @@ -116,6 +116,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo for (auto& baseStyle : baseStyles) { double lineWidth = 0; + QPainterPath path; std::shared_ptr material; @@ -124,15 +125,19 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo std::static_pointer_cast(copy)->halfWidth /= maxLen; lineWidth = std::static_pointer_cast(copy)->halfWidth; material = copy; + + QPainterPathStroker stroker; + stroker.setWidth(lineWidth * 2); + stroker.setCapStyle(Qt::RoundCap); + stroker.setJoinStyle(Qt::RoundJoin); + path = stroker.createStroke(painterPath); } else + { material = baseStyle.material; - QPainterPathStroker stroker; - stroker.setWidth(lineWidth * 2); - stroker.setCapStyle(Qt::RoundCap); - stroker.setJoinStyle(Qt::RoundJoin); - QPainterPath strokePath = stroker.createStroke(painterPath); - auto rect = leafTransform.map(strokePath).boundingRect(); + path = painterPath; + } + auto rect = leafTransform.map(path).boundingRect(); elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); //qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z; elementTransform.transform = glm::mat3x2( diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index ee5f5cc..48382cb 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -351,7 +351,7 @@ GLuint Renderer::Model::loadPainting(std::string path) trans.m13(), trans.m23(), trans.m33()).c_str(); //painting.addElement(*element[0], ElementTransform{ glm::vec4(-1,-1,1,1), mat, 0}); - painting.addElement(*element[1], ElementTransform{ glm::vec4(-1,-1,0,1), mat, 0 }); + painting.addElement(*element[1], ElementTransform{ glm::vec4(-1,-1,0,1), mat, 1 }); painting.addElement(*element[2], ElementTransform{ glm::vec4(0,-1,1,1), mat2, 0 }); //painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.45,0.45), glm::vec2(0.25), 0, glm::bvec2(false), 0 }); //painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.535,0.33), glm::vec2(0.15), 0, glm::bvec2(false), 0 }); diff --git a/svg/正方形.svg b/svg/正方形.svg new file mode 100644 index 0000000..7d15a40 --- /dev/null +++ b/svg/正方形.svg @@ -0,0 +1 @@ + \ No newline at end of file From 512181f6a3a61714331b15964a281389214c9691 Mon Sep 17 00:00:00 2001 From: wuyize Date: Wed, 22 Mar 2023 16:58:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20painting.comp=E4=B8=ADzIndex?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=EF=BC=8CPaintingUtil?= =?UTF-8?q?=E5=8C=85=E5=9B=B4=E7=9B=92=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/Shaders/painting.comp | 3 ++- .../src/Editor/util/PaintingUtil.cpp | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index 2fc3e0a..c65a28b 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -1376,7 +1376,7 @@ void main() // vec4 color = vec4(0.76, 0.33, 0.15, -1); vec4 color = vec4(backgroundRed, backgroundGreen, backgroundBlue, -1); vec2 metallicRoughness = vec2(backgroundMetallic, backgroundRoughness); - int zIndex = 1<<15; + uint zIndex = 1 << 15; // vec4 color = vec4(0.72f, 0.66f, 0.55f, -1); // vec2 metallicRoughness = vec2(0,0.5); stack.top = 0; @@ -1412,6 +1412,7 @@ void main() vec2 elementMetallicRoughness; if (drawElement(elementIndex, localUV, elementColor, elementMetallicRoughness, debugBVH)) { + zIndex = elementZIndex; color = vec4(elementColor, elementZIndex); metallicRoughness = elementMetallicRoughness; } diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index 1aab871..9615563 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -3,6 +3,7 @@ #include #include "PainterPathUtil.h" #include +#include #include using Renderer::Painting; @@ -52,7 +53,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { //qDebug() << ((SimpleElement*)((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->wrappedElement)->painterPath; //qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath; //queue layerQueue; - + //double maxLineWidth = getMaxLineWidth(root); //layerQueue.push({ root, QTransform()}); /*while (!layerQueue.empty()) { @@ -66,7 +67,7 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { } }*/ - + } void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transform, Painting& painting, std::unordered_map& contourMap) { @@ -91,9 +92,9 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo QTransform trans; double maxLen = std::max(bound.width(), bound.height()) * 1.00001; //qDebug() << maxLen << bound; - trans.scale(2 / maxLen, 2 / maxLen); + trans.scale(1 / maxLen, 1 / maxLen); trans.translate(-bound.center().x(), -bound.center().y()); - + painterPath = trans.map(painterPath); //std::shared_ptr keyLayerPtr(nowLayer); auto iterContour = contourMap.find(nowLayer); PaintingUtil::Contour contour = nullptr; @@ -101,26 +102,27 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo contour = iterContour->second; } else { - painterPath = trans.map(painterPath); contour = std::make_shared >>(PainterPathUtil::transformToLines(painterPath)); contourMap.insert({ nowLayer, contour }); -; } + ; + } QSize screenSize = QSize(1080, 1080); ElementTransform elementTransform; QTransform leafTransform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1); QTransform transformInverted = leafTransform.inverted(); - ++zIndexCount; + //++zIndexCount; auto baseStyles = leafLayer->styles.toBaseStyles(); - - for (auto& baseStyle : baseStyles) { + qDebug() << baseStyles.size(); + for (auto& baseStyle : std::views::reverse(baseStyles)) { double lineWidth = 0; QPainterPath path; std::shared_ptr material; if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) { + qDebug() << "MaterialStyleType::kStroke"; std::shared_ptr copy = baseStyle.material->clone(); std::static_pointer_cast(copy)->halfWidth /= maxLen; lineWidth = std::static_pointer_cast(copy)->halfWidth; @@ -134,17 +136,19 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo } else { + qDebug() << "MaterialStyleType::kFill"; material = baseStyle.material; path = painterPath; } auto rect = leafTransform.map(path).boundingRect(); elementTransform.bound = glm::vec4(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height()); + //elementTransform.bound = glm::vec4(-1,-1,1,1); //qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z; elementTransform.transform = glm::mat3x2( transformInverted.m11(), transformInverted.m12(), transformInverted.m21(), transformInverted.m22(), transformInverted.m31(), transformInverted.m32() ); - elementTransform.zIndex = zIndexCount; + elementTransform.zIndex = ++zIndexCount; painting.addElement(BaseElement{ contour, material }, elementTransform); } From 62d887aa07f458f93c11e59eb4a273b7062f95c1 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Wed, 22 Mar 2023 17:01:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[editor]=20=E5=B0=86=E5=9B=BE=E5=B1=82?= =?UTF-8?q?=E7=9A=84=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E9=99=90=E5=88=B6?= =?UTF-8?q?=E5=9C=A8=E4=BA=86(-360,=20360)=20|=20#27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerWrapper.cpp | 9 +++++++++ .../src/Editor/LayerWrapper.h | 1 + .../src/Editor/PreviewWindow.cpp | 2 +- .../src/Editor/RightBar/InfoDisplayWidget.cpp | 14 +++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index bf4dcce..6e5773c 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -92,6 +92,15 @@ LeafLayerWrapper::~LeafLayerWrapper() wrappedElement->referencedCount--; } +void LayerWrapper::SimpleProperty::setRotation(double newRotation) +{ + if (newRotation <= -360 || 360 <= newRotation) + { + newRotation -= static_cast(std::round(newRotation)) / 360 * 360; + } + rotation = newRotation; +} + void LayerWrapper::SimpleProperty::apply(PixelPath&cache) { transform.reset(); diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 35b6c1f..95fc5f4 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -48,6 +48,7 @@ class LayerWrapper bool flipY = 0; QTransform transform; // TODO: ½«QPainterPath¸ÄΪBitmapPath + void setRotation(double newRotation); void apply(PixelPath&cache); } property; virtual void setParent(FolderLayerWrapper*newParent); diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 6cc9e27..f910c5a 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -106,7 +106,7 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) else if (event->buttons() & Qt::RightButton) { // Èç¹û°´ÏµÄÊÇÓÒ¼ü£¬ÄÇôÐýתͼÐÎ qreal angle = dx; - currentLayer->property.rotation += angle; + currentLayer->property.setRotation(currentLayer->property.rotation + angle); } auto layer = currentLayer; while (layer != nullptr) diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index df61f0a..a6d1e01 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -21,29 +21,29 @@ InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent) ui.rotation->setLabel(("旋转角度")); ui.scaleX->setLabel(("水平缩放")); ui.scaleY->setLabel(("垂直缩放")); - ui.rotation->setValidator(new QIntValidator(-10000, 10000, this)); + ui.rotation->setValidator(new QIntValidator(-360, 360, this)); ui.styleList->setDisabled(true); - connect(ui.rotation, &QLineEdit::textChanged, [=](QString content) { - this->displayLayer->property.rotation = content.toDouble(); + connect(ui.rotation, &QLineEdit::textChanged, [=](const QString& content) { + this->displayLayer->property.setRotation(content.toDouble()); emit triggerCentralRefresh(); }); ui.offsetX->setValidator(new QIntValidator(-10000, 10000, this)); - connect(ui.offsetX, &QLineEdit::textChanged, [=](QString content) { + connect(ui.offsetX, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.offset = { content.toDouble(), this->displayLayer->property.offset.y() }; emit triggerCentralRefresh(); }); ui.offsetY->setValidator(new QIntValidator(-10000, 10000, this)); - connect(ui.offsetY, &QLineEdit::textChanged, [=](QString content) { + connect(ui.offsetY, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.offset = { this->displayLayer->property.offset.x(), content.toDouble() }; emit triggerCentralRefresh(); }); ui.scaleX->setValidator(new QDoubleValidator(0, 1000, 4, this)); - connect(ui.scaleX, &QLineEdit::textChanged, [=](QString content) { + connect(ui.scaleX, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.scale = { content.toDouble(), this->displayLayer->property.scale.y() }; emit triggerCentralRefresh(); }); ui.scaleY->setValidator(new QDoubleValidator(0, 1000, 4, this)); - connect(ui.scaleY, &QLineEdit::textChanged, [=](QString content) { + connect(ui.scaleY, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.scale = { this->displayLayer->property.scale.x(), content.toDouble() }; emit triggerCentralRefresh(); });