From 512181f6a3a61714331b15964a281389214c9691 Mon Sep 17 00:00:00 2001 From: wuyize Date: Wed, 22 Mar 2023 16:58:28 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20painting.comp=E4=B8=ADzIndex=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=94=99=E8=AF=AF=EF=BC=8CPaintingUtil=E5=8C=85?= =?UTF-8?q?=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); }