Fix: painting.comp中zIndex计算错误,PaintingUtil包围盒计算错误

dev-wuyize
wuyize 2023-03-22 16:58:28 +08:00
parent 60c7695545
commit 512181f6a3
2 changed files with 16 additions and 11 deletions

View File

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

View File

@ -3,6 +3,7 @@
#include <QJsondocument>
#include "PainterPathUtil.h"
#include <queue>
#include <ranges>
#include <QFileInfo>
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<LayerNode> 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<LayerWrapper*, Contour>& 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<LayerWrapper> 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<vector<vector<Renderer::Point> >>(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<MaterialStyle> material;
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
qDebug() << "MaterialStyleType::kStroke";
std::shared_ptr copy = baseStyle.material->clone();
std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth /= maxLen;
lineWidth = std::static_pointer_cast<MaterialStyleStroke>(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);
}