Fix: painting.comp中zIndex计算错误,PaintingUtil包围盒计算错误
parent
60c7695545
commit
512181f6a3
|
@ -1376,7 +1376,7 @@ void main()
|
||||||
// vec4 color = vec4(0.76, 0.33, 0.15, -1);
|
// vec4 color = vec4(0.76, 0.33, 0.15, -1);
|
||||||
vec4 color = vec4(backgroundRed, backgroundGreen, backgroundBlue, -1);
|
vec4 color = vec4(backgroundRed, backgroundGreen, backgroundBlue, -1);
|
||||||
vec2 metallicRoughness = vec2(backgroundMetallic, backgroundRoughness);
|
vec2 metallicRoughness = vec2(backgroundMetallic, backgroundRoughness);
|
||||||
int zIndex = 1<<15;
|
uint zIndex = 1 << 15;
|
||||||
// vec4 color = vec4(0.72f, 0.66f, 0.55f, -1);
|
// vec4 color = vec4(0.72f, 0.66f, 0.55f, -1);
|
||||||
// vec2 metallicRoughness = vec2(0,0.5);
|
// vec2 metallicRoughness = vec2(0,0.5);
|
||||||
stack.top = 0;
|
stack.top = 0;
|
||||||
|
@ -1412,6 +1412,7 @@ void main()
|
||||||
vec2 elementMetallicRoughness;
|
vec2 elementMetallicRoughness;
|
||||||
if (drawElement(elementIndex, localUV, elementColor, elementMetallicRoughness, debugBVH))
|
if (drawElement(elementIndex, localUV, elementColor, elementMetallicRoughness, debugBVH))
|
||||||
{
|
{
|
||||||
|
zIndex = elementZIndex;
|
||||||
color = vec4(elementColor, elementZIndex);
|
color = vec4(elementColor, elementZIndex);
|
||||||
metallicRoughness = elementMetallicRoughness;
|
metallicRoughness = elementMetallicRoughness;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QJsondocument>
|
#include <QJsondocument>
|
||||||
#include "PainterPathUtil.h"
|
#include "PainterPathUtil.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <ranges>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
using Renderer::Painting;
|
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() << ((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;
|
//qDebug() << ((LeafLayerWrapper*)((FolderLayerWrapper*)((FolderLayerWrapper*)layerManager->getRoot())->children[0].get())->children[0].get())->getCache().painterPath;
|
||||||
//queue<LayerNode> layerQueue;
|
//queue<LayerNode> layerQueue;
|
||||||
|
|
||||||
//double maxLineWidth = getMaxLineWidth(root);
|
//double maxLineWidth = getMaxLineWidth(root);
|
||||||
//layerQueue.push({ root, QTransform()});
|
//layerQueue.push({ root, QTransform()});
|
||||||
/*while (!layerQueue.empty()) {
|
/*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) {
|
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;
|
QTransform trans;
|
||||||
double maxLen = std::max(bound.width(), bound.height()) * 1.00001;
|
double maxLen = std::max(bound.width(), bound.height()) * 1.00001;
|
||||||
//qDebug() << maxLen << bound;
|
//qDebug() << maxLen << bound;
|
||||||
trans.scale(2 / maxLen, 2 / maxLen);
|
trans.scale(1 / maxLen, 1 / maxLen);
|
||||||
trans.translate(-bound.center().x(), -bound.center().y());
|
trans.translate(-bound.center().x(), -bound.center().y());
|
||||||
|
painterPath = trans.map(painterPath);
|
||||||
//std::shared_ptr<LayerWrapper> keyLayerPtr(nowLayer);
|
//std::shared_ptr<LayerWrapper> keyLayerPtr(nowLayer);
|
||||||
auto iterContour = contourMap.find(nowLayer);
|
auto iterContour = contourMap.find(nowLayer);
|
||||||
PaintingUtil::Contour contour = nullptr;
|
PaintingUtil::Contour contour = nullptr;
|
||||||
|
@ -101,26 +102,27 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
|
||||||
contour = iterContour->second;
|
contour = iterContour->second;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
painterPath = trans.map(painterPath);
|
|
||||||
contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(painterPath));
|
contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(painterPath));
|
||||||
contourMap.insert({ nowLayer, contour });
|
contourMap.insert({ nowLayer, contour });
|
||||||
; }
|
;
|
||||||
|
}
|
||||||
QSize screenSize = QSize(1080, 1080);
|
QSize screenSize = QSize(1080, 1080);
|
||||||
|
|
||||||
ElementTransform elementTransform;
|
ElementTransform elementTransform;
|
||||||
QTransform leafTransform = trans.inverted() * transform * QTransform::fromScale(2. / screenSize.width(), 2. / screenSize.height()) * QTransform::fromTranslate(-1, -1) * QTransform::fromScale(1, -1);
|
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();
|
QTransform transformInverted = leafTransform.inverted();
|
||||||
|
|
||||||
++zIndexCount;
|
//++zIndexCount;
|
||||||
auto baseStyles = leafLayer->styles.toBaseStyles();
|
auto baseStyles = leafLayer->styles.toBaseStyles();
|
||||||
|
qDebug() << baseStyles.size();
|
||||||
for (auto& baseStyle : baseStyles) {
|
for (auto& baseStyle : std::views::reverse(baseStyles)) {
|
||||||
double lineWidth = 0;
|
double lineWidth = 0;
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
|
||||||
std::shared_ptr<MaterialStyle> material;
|
std::shared_ptr<MaterialStyle> material;
|
||||||
|
|
||||||
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
|
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
|
||||||
|
qDebug() << "MaterialStyleType::kStroke";
|
||||||
std::shared_ptr copy = baseStyle.material->clone();
|
std::shared_ptr copy = baseStyle.material->clone();
|
||||||
std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth /= maxLen;
|
std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth /= maxLen;
|
||||||
lineWidth = std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth;
|
lineWidth = std::static_pointer_cast<MaterialStyleStroke>(copy)->halfWidth;
|
||||||
|
@ -134,17 +136,19 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
qDebug() << "MaterialStyleType::kFill";
|
||||||
material = baseStyle.material;
|
material = baseStyle.material;
|
||||||
path = painterPath;
|
path = painterPath;
|
||||||
}
|
}
|
||||||
auto rect = leafTransform.map(path).boundingRect();
|
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(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;
|
//qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z;
|
||||||
elementTransform.transform = glm::mat3x2(
|
elementTransform.transform = glm::mat3x2(
|
||||||
transformInverted.m11(), transformInverted.m12(), transformInverted.m21(),
|
transformInverted.m11(), transformInverted.m12(), transformInverted.m21(),
|
||||||
transformInverted.m22(), transformInverted.m31(), transformInverted.m32()
|
transformInverted.m22(), transformInverted.m31(), transformInverted.m32()
|
||||||
);
|
);
|
||||||
elementTransform.zIndex = zIndexCount;
|
elementTransform.zIndex = ++zIndexCount;
|
||||||
painting.addElement(BaseElement{ contour, material }, elementTransform);
|
painting.addElement(BaseElement{ contour, material }, elementTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue