dev-wuyize
karlis 2023-03-22 19:59:42 +08:00
commit f175e50b7b
8 changed files with 44 additions and 47 deletions

View File

@ -66,11 +66,11 @@
<property name="widgetResizable"> <property name="widgetResizable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="scrollAreaWidgetContents"> <widget class="PreviewWindow" name="Preview">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-17</y>
<width>1024</width> <width>1024</width>
<height>1024</height> <height>1024</height>
</rect> </rect>
@ -89,34 +89,10 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>10241024</width> <width>1024</width>
<height>10241024</height> <height>1024</height>
</size> </size>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="PreviewWindow" name="Preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1024</width>
<height>1024</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1024</width>
<height>1024</height>
</size>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</widget> </widget>
</item> </item>

View File

@ -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;
@ -1402,7 +1402,7 @@ void main()
if (elementZIndex <= zIndex) if (elementZIndex <= zIndex)
{ {
uint transformIndex = leftChild - 0x80000000; uint transformIndex = leftChild - 0x80000000;
uint elementIndex = bvhChildren[index].y - elementZIndex; uint elementIndex = bvhChildren[index].y & 0x3FFFF;
mat3x2 transform = elementTranform[transformIndex]; mat3x2 transform = elementTranform[transformIndex];
vec2 localUV = vec2 localUV =
(mat3(vec3(transform[0], 0), vec3(transform[1], 0), vec3(transform[2], 1)) * vec3(uv, 1)) (mat3(vec3(transform[0], 0), vec3(transform[1], 0), vec3(transform[2], 1)) * vec3(uv, 1))
@ -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;
} }

View File

@ -92,6 +92,15 @@ LeafLayerWrapper::~LeafLayerWrapper()
wrappedElement->referencedCount--; wrappedElement->referencedCount--;
} }
void LayerWrapper::SimpleProperty::setRotation(double newRotation)
{
if (newRotation <= -360 || 360 <= newRotation)
{
newRotation -= static_cast<int>(std::round(newRotation)) / 360 * 360;
}
rotation = newRotation;
}
void LayerWrapper::SimpleProperty::apply(PixelPath&cache) void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
{ {
transform.reset(); transform.reset();

View File

@ -49,6 +49,7 @@ class LayerWrapper
bool flipY = 0; bool flipY = 0;
QTransform transform; QTransform transform;
// TODO: 将QPainterPath改为BitmapPath // TODO: 将QPainterPath改为BitmapPath
void setRotation(double newRotation);
void apply(PixelPath&cache); void apply(PixelPath&cache);
} property; } property;
virtual void setParent(FolderLayerWrapper*newParent); virtual void setParent(FolderLayerWrapper*newParent);

View File

@ -106,7 +106,7 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event)
else if (event->buttons() & Qt::RightButton) { else if (event->buttons() & Qt::RightButton) {
// 如果按下的是右键,那么旋转图形 // 如果按下的是右键,那么旋转图形
qreal angle = dx; qreal angle = dx;
currentLayer->property.rotation += angle; currentLayer->property.setRotation(currentLayer->property.rotation + angle);
} }
auto layer = currentLayer; auto layer = currentLayer;
while (layer != nullptr) while (layer != nullptr)

View File

@ -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;
@ -93,7 +94,7 @@ void PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, QTransform transfo
//qDebug() << maxLen << bound; //qDebug() << maxLen << bound;
trans.scale(1 / maxLen, 1 / 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,45 +102,53 @@ 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;
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;
material = copy; material = copy;
QPainterPathStroker stroker;
stroker.setWidth(lineWidth * 2);
stroker.setCapStyle(Qt::RoundCap);
stroker.setJoinStyle(Qt::RoundJoin);
path = stroker.createStroke(painterPath);
} }
else else
{
qDebug() << "MaterialStyleType::kFill";
material = baseStyle.material; material = baseStyle.material;
QPainterPathStroker stroker; path = painterPath;
stroker.setWidth(lineWidth * 2); }
stroker.setCapStyle(Qt::RoundCap); auto rect = leafTransform.map(path).boundingRect();
stroker.setJoinStyle(Qt::RoundJoin);
QPainterPath strokePath = stroker.createStroke(painterPath);
auto rect = leafTransform.map(strokePath).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);
} }

View File

@ -351,7 +351,7 @@ GLuint Renderer::Model::loadPainting(std::string path)
trans.m13(), trans.m23(), trans.m33()).c_str(); trans.m13(), trans.m23(), trans.m33()).c_str();
//painting.addElement(*element[0], ElementTransform{ glm::vec4(-1,-1,1,1), mat, 0}); //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[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[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 }); //painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.535,0.33), glm::vec2(0.15), 0, glm::bvec2(false), 0 });

1
svg/正方形.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 116.45 116.45"><defs><style>.cls-1{fill:#fff;stroke:#231815;stroke-miterlimit:10;}</style></defs><g id="图层_2" data-name="图层 2"><g id="图层_1-2" data-name="图层 1"><rect class="cls-1" x="0.5" y="0.5" width="115.45" height="115.45"/></g></g></svg>

After

Width:  |  Height:  |  Size: 310 B