Compare commits
2 Commits
2cf45455ba
...
f5d487afec
Author | SHA1 | Date |
---|---|---|
yang.yongquan | f5d487afec | |
yang.yongquan | 315794709e |
|
@ -1260,17 +1260,16 @@ void main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imageStore(gBaseColor, pixelLocation, vec4(color.rgb,1));
|
imageStore(gBaseColor, pixelLocation, vec4(color.rgb, 1));
|
||||||
imageStore(gMetallicRoughness, pixelLocation, vec4(metallicRoughness, 0, 1));
|
imageStore(gMetallicRoughness, pixelLocation, vec4(metallicRoughness, 0, 1));
|
||||||
//return;
|
return;
|
||||||
if (/*color.a!=-1&&*/debugBVH==vec3(0))
|
if (/*color.a!=-1&&*/ debugBVH == vec3(0))
|
||||||
{
|
{
|
||||||
//imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1));
|
// imageStore(gBaseColor, pixelLocation, vec4(vec3(1, 1, 0),1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
imageStore(gBaseColor, pixelLocation, vec4(debugBVH,1));
|
imageStore(gBaseColor, pixelLocation, vec4(debugBVH, 1));
|
||||||
imageStore(gMetallicRoughness, pixelLocation, vec4(0,0.8, 0, 1));
|
imageStore(gMetallicRoughness, pixelLocation, vec4(0, 0.8, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -55,6 +55,208 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
|
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
|
||||||
|
{
|
||||||
|
LayerStyleContainer container(isClosedElement);
|
||||||
|
for (const auto& style : jsonArray)
|
||||||
|
{
|
||||||
|
container.useStyle(LayerStyle::fromJson(style.toObject()));
|
||||||
|
}
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
LayerStyleContainer::LayerStyleContainer(bool isClosedElement) : hash(0)
|
||||||
|
{
|
||||||
|
for (const auto& style : commonStyles)
|
||||||
|
{
|
||||||
|
unusedStyles.insert(style);
|
||||||
|
}
|
||||||
|
if (isClosedElement)
|
||||||
|
{
|
||||||
|
for (const auto& style : closedOnlyStyles)
|
||||||
|
{
|
||||||
|
unusedStyles.insert(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (const auto& style : unclosedOnlyStyles)
|
||||||
|
{
|
||||||
|
unusedStyles.insert(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Renderer::BaseStyle> LayerStyleContainer::toBaseStyles() const
|
||||||
|
{
|
||||||
|
std::vector<Renderer::BaseStyle> result;
|
||||||
|
for (const auto& style : styles | std::views::values)
|
||||||
|
{
|
||||||
|
auto baseStyles = style->toBaseStyles();
|
||||||
|
result.insert(result.end(),
|
||||||
|
std::make_move_iterator(baseStyles.begin()),
|
||||||
|
std::make_move_iterator(baseStyles.end()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray LayerStyleContainer::toJson() const
|
||||||
|
{
|
||||||
|
QJsonArray json;
|
||||||
|
for (const auto& style : styles | std::views::values)
|
||||||
|
{
|
||||||
|
json.append(style->toJson());
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList LayerStyleContainer::unusedStyleNames() const
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
for(const auto& name : unusedStyles | std::views::keys)
|
||||||
|
{
|
||||||
|
result << name;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<LayerStyle> LayerStyleContainer::makeUnusedStyle(const QString& styleName) const
|
||||||
|
{
|
||||||
|
return unusedStyles.at(styleName)();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerStyleContainer::empty() const
|
||||||
|
{
|
||||||
|
return styles.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerStyleContainer::full() const
|
||||||
|
{
|
||||||
|
return unusedStyles.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<QString, std::shared_ptr<LayerStyle>>::iterator LayerStyleContainer::begin()
|
||||||
|
{
|
||||||
|
return styles.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<QString, std::shared_ptr<LayerStyle>>::iterator LayerStyleContainer::end()
|
||||||
|
{
|
||||||
|
return styles.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerStyleContainer::useStyle(const std::shared_ptr<LayerStyle>& style)
|
||||||
|
{
|
||||||
|
auto styleNode = unusedStyles.extract(style->getDisplayName());
|
||||||
|
if (styleNode.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
styles[styleNode.key()] = style;
|
||||||
|
usedStyles.insert(std::move(styleNode));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LayerStyleContainer::dropStyle(const QString& styleName)
|
||||||
|
{
|
||||||
|
auto styleNode = usedStyles.extract(styleName);
|
||||||
|
if (styleNode.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
styles.erase(styleName);
|
||||||
|
unusedStyles.insert(std::move(styleNode));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float LayerStyleContainer::boundingBoxAffectValue() const {
|
||||||
|
float maxLineWidth = 0;
|
||||||
|
const auto strokeStyle = styles.find(StrokeElementLayerStyle::displayName());
|
||||||
|
if (strokeStyle != styles.end())
|
||||||
|
{
|
||||||
|
if (const auto strokeElementLayerStyle =
|
||||||
|
std::dynamic_pointer_cast<StrokeElementLayerStyle>(strokeStyle->second);
|
||||||
|
strokeElementLayerStyle != nullptr)
|
||||||
|
{
|
||||||
|
const auto& leftStyleStroke = strokeElementLayerStyle->strokePair.first;
|
||||||
|
const auto& rightStyleStroke = strokeElementLayerStyle->strokePair.second;
|
||||||
|
if (leftStyleStroke != nullptr)
|
||||||
|
{
|
||||||
|
maxLineWidth = std::max(maxLineWidth, leftStyleStroke->halfWidth);
|
||||||
|
}
|
||||||
|
if (rightStyleStroke != nullptr)
|
||||||
|
{
|
||||||
|
maxLineWidth = std::max(maxLineWidth, rightStyleStroke->halfWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxLineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t LayerStyleContainer::getHash() const
|
||||||
|
{
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<StrokeElementLayerStyle> StrokeElementLayerStyle::fromJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
auto ptr = std::make_unique<StrokeElementLayerStyle>(
|
||||||
|
std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["left"].toString()))))
|
||||||
|
),
|
||||||
|
std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(MaterialStyle::decoded(EncodeUtil::fromBase64<GLfloat>(json["right"].toString()))))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
ptr->enableEachSideIndependent = json["enableEachSideIndependent"].toBool();
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
StrokeElementLayerStyle::StrokeElementLayerStyle()
|
||||||
|
{
|
||||||
|
const auto materialMap = std::map<float, Renderer::Material>();
|
||||||
|
this->strokePair.first = std::make_shared<MaterialStyleStroke>(
|
||||||
|
7,
|
||||||
|
Renderer::StrokeType::kLeftSide, Renderer::StrokeEndType::kFlat,
|
||||||
|
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||||
|
);
|
||||||
|
|
||||||
|
this->strokePair.second = std::make_shared<MaterialStyleStroke>(
|
||||||
|
7,
|
||||||
|
Renderer::StrokeType::kRightSide, Renderer::StrokeEndType::kFlat,
|
||||||
|
std::make_shared<Renderer::StrokeRadialGradient>(materialMap, false)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
StrokeElementLayerStyle::StrokeElementLayerStyle(const PMaterialStyleStroke& left, const PMaterialStyleStroke& right)
|
||||||
|
{
|
||||||
|
this->strokePair.first = left;
|
||||||
|
this->strokePair.second = right ? right : std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(left->clone()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle& other)
|
||||||
|
{
|
||||||
|
strokePair.first = std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(other.strokePair.first->clone()))
|
||||||
|
);
|
||||||
|
strokePair.second = std::static_pointer_cast<MaterialStyleStroke>(
|
||||||
|
std::shared_ptr(std::move(other.strokePair.second->clone()))
|
||||||
|
);
|
||||||
|
enableEachSideIndependent = other.enableEachSideIndependent;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject StrokeElementLayerStyle::toJson() const
|
||||||
|
{
|
||||||
|
auto json = LayerStyle::toJson();
|
||||||
|
json["enableEachSideIndependent"] = enableEachSideIndependent;
|
||||||
|
json["left"] = EncodeUtil::toBase64<GLfloat>(strokePair.first->encoded());
|
||||||
|
json["right"] = EncodeUtil::toBase64<GLfloat>(strokePair.second->encoded());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clone() const
|
||||||
{
|
{
|
||||||
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,17 @@
|
||||||
using Renderer::Painting;
|
using Renderer::Painting;
|
||||||
using Renderer::Element;
|
using Renderer::Element;
|
||||||
using Renderer::ElementTransform;
|
using Renderer::ElementTransform;
|
||||||
|
using Renderer::BaseElement;
|
||||||
using glm::bvec2;
|
using glm::bvec2;
|
||||||
using std::max;
|
using std::max;
|
||||||
|
|
||||||
|
const double PaintingUtil::pi = acos(-1);
|
||||||
|
|
||||||
|
struct LayerNode {
|
||||||
|
LayerWrapper* nowLayer;
|
||||||
|
QTransform transfrom;
|
||||||
|
};
|
||||||
|
|
||||||
QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) {
|
QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) {
|
||||||
QFile jsonFile(jsonFilePath);
|
QFile jsonFile(jsonFilePath);
|
||||||
jsonFile.open(QFile::ReadOnly);
|
jsonFile.open(QFile::ReadOnly);
|
||||||
|
@ -24,19 +32,34 @@ Painting PaintingUtil::transfromToPainting(QString jsonFilePath) {
|
||||||
QTransform transform;
|
QTransform transform;
|
||||||
glm::bvec2 flip(0, 0);
|
glm::bvec2 flip(0, 0);
|
||||||
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
QJsonObject jsonObj = readJsonFile(jsonFilePath);
|
||||||
ElementManager *elementManager = new ElementManager(jsonObj, Renderer::ElementRenderer::instance());
|
qDebug() << jsonObj;
|
||||||
LayerManager* layerManager = new LayerManager(jsonObj, elementManager);
|
shared_ptr<ElementManager> elementManager = make_shared<ElementManager>(jsonObj, Renderer::ElementRenderer::instance());
|
||||||
traverseLayTree(layerManager->getRoot(), transform, flip, painting);
|
shared_ptr<LayerManager> layerManager = make_shared<LayerManager>(jsonObj, elementManager.get());
|
||||||
// FIXME: 为了编译通过添加的返回
|
//qDebug() << elementManager->toJson();
|
||||||
|
//qDebug() << layerManager->toJson();
|
||||||
|
//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;
|
||||||
|
LayerWrapper* root = layerManager->getRoot();
|
||||||
|
root->getCache();
|
||||||
|
double maxLineWidth = getMaxLineWidth(root);
|
||||||
|
layerQueue.push({ root, root->property.transform });
|
||||||
|
while (!layerQueue.empty()) {
|
||||||
|
auto layerNode = layerQueue.front();
|
||||||
|
layerQueue.pop();
|
||||||
|
FolderLayerWrapper* nowLayer = handleLayerWrapper(layerNode.nowLayer, maxLineWidth, layerNode.transfrom, painting);
|
||||||
|
if (nowLayer != nullptr) {
|
||||||
|
for (auto sonLayer : nowLayer->children) {
|
||||||
|
layerQueue.push({ sonLayer.get(), layerNode.transfrom});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return painting;
|
return painting;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform, bvec2 flip, Painting& painting) {
|
FolderLayerWrapper* PaintingUtil::handleLayerWrapper(LayerWrapper* nowLayer, double& maxLineWidth, QTransform& transform, Painting& painting) {
|
||||||
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
|
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(nowLayer);
|
||||||
PixelPath pixelPath = nowLayer->getCache();
|
|
||||||
double centerX = pixelPath.getBoundingRect().center().x();
|
|
||||||
double centerY = pixelPath.getBoundingRect().center().y();
|
|
||||||
flip ^= bvec2(nowLayer->property.flipHorizontally, nowLayer->property.flipVertically);
|
|
||||||
|
|
||||||
QRectF transBound = transform.map(pixelPath.getPainterPath()).boundingRect();
|
QRectF transBound = transform.map(pixelPath.getPainterPath()).boundingRect();
|
||||||
|
|
||||||
|
@ -46,10 +69,21 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
|
||||||
.scale(nowLayer->property.scale.x(), nowLayer->property.scale.y())
|
.scale(nowLayer->property.scale.x(), nowLayer->property.scale.y())
|
||||||
.translate(centerX, centerY);
|
.translate(centerX, centerY);
|
||||||
if (leafLayer != nullptr) {
|
if (leafLayer != nullptr) {
|
||||||
Element element;
|
|
||||||
ElementTransform elementTrans;
|
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
|
||||||
QRectF bound = pixelPath.getBoundingRect();
|
if (wrapperElement != nullptr) {
|
||||||
element.ratio = bound.width() / bound.height();
|
transform = wrapperElement->sourceLayer->property.transform * transform;
|
||||||
|
return wrapperElement->sourceLayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
PixelPath pixelPath = nowLayer->getCache();
|
||||||
|
QPainterPath painterPath = pixelPath.getPainterPath();
|
||||||
|
QRectF bound = painterPath.boundingRect();
|
||||||
|
//qDebug() << leafLayer<<"------" << painterPath;
|
||||||
|
//qDebug() << transform;
|
||||||
|
//Element element;
|
||||||
|
//ElementTransform elementTrans;
|
||||||
|
//element.ratio = bound.width() / bound.height();
|
||||||
// transform to initial painterPath
|
// transform to initial painterPath
|
||||||
QTransform trans;
|
QTransform trans;
|
||||||
trans.translate(-centerX, -centerY)
|
trans.translate(-centerX, -centerY)
|
||||||
|
@ -59,19 +93,59 @@ void PaintingUtil::traverseLayTree(LayerWrapper* nowLayer, QTransform transform,
|
||||||
.translate(-nowLayer->property.offset.x(), -nowLayer->property.offset.y());
|
.translate(-nowLayer->property.offset.x(), -nowLayer->property.offset.y());
|
||||||
QPainterPath painterPath = trans.map(pixelPath.getPainterPath());
|
QPainterPath painterPath = trans.map(pixelPath.getPainterPath());
|
||||||
// transfrom to -1£¬ 1
|
// transfrom to -1£¬ 1
|
||||||
|
QTransform trans;
|
||||||
|
double maxLen = std::max(bound.width(), bound.height()) + maxLineWidth * 2;
|
||||||
|
qDebug() << maxLen << bound;
|
||||||
|
trans.scale(1 / maxLen, 1 / maxLen);
|
||||||
|
trans.translate(-bound.center().x(), -bound.center().y());
|
||||||
|
|
||||||
|
qDebug() << trans.map(painterPath);
|
||||||
|
shared_ptr<vector<vector<Renderer::Point> >> contour = std::make_shared<vector<vector<Renderer::Point> >>(PainterPathUtil::transformToLines(trans.map(painterPath)));
|
||||||
|
QSize screenSize = QSize(1024, 1024);
|
||||||
|
//element.style = std::make_shared<Renderer::ElementStyleStrokeDemo>(0.06);
|
||||||
|
|
||||||
|
|
||||||
|
painterPath = transform.map(painterPath);
|
||||||
|
qDebug() << painterPath;
|
||||||
bound = painterPath.boundingRect();
|
bound = painterPath.boundingRect();
|
||||||
trans.reset();
|
|
||||||
trans.translate(1, 1);
|
|
||||||
trans.scale(2 / bound.width(), 2 / bound.height());
|
|
||||||
trans.translate(bound.x(), bound.y());
|
|
||||||
painterPath = trans.map(painterPath);
|
|
||||||
|
|
||||||
element.contour.reset(new vector<vector<Renderer::Point> >(PainterPathUtil::transformToLines(painterPath)));
|
ElementTransform elementTransform;
|
||||||
QSize screenSize = pixelPath.getPixmap().size();
|
transform = transform * trans;
|
||||||
|
//elementTransform.bound = glm::vec4(-1, -1, 1, 1);
|
||||||
|
elementTransform.bound = glm::vec4(
|
||||||
|
2 * (bound.x() - maxLineWidth) / screenSize.width() - 1,
|
||||||
|
2 * (bound.y() - maxLineWidth) / screenSize.height() - 1,
|
||||||
|
2 * (bound.x() + bound.width() + maxLineWidth) / screenSize.width() - 1,
|
||||||
|
2 * (bound.y() + bound.height() + maxLineWidth) / screenSize.height() - 1
|
||||||
|
);
|
||||||
|
qDebug() << elementTransform.bound.x << elementTransform.bound.y << elementTransform.bound.z << elementTransform.bound.z;
|
||||||
|
transform = transform.inverted();
|
||||||
|
elementTransform.transform = glm::mat3x2(
|
||||||
|
transform.m11(), transform.m12(), transform.m21(),
|
||||||
|
transform.m22(), transform.m31(), transform.m32()
|
||||||
|
);
|
||||||
|
qDebug() << transform;
|
||||||
|
elementTransform.zIndex = 0;
|
||||||
|
|
||||||
elementTrans.center = glm::vec2(
|
auto baseStyles = leafLayer->styles.toBaseStyles();
|
||||||
(2 * (transBound.x() + transBound.width()) - screenSize.width()) / screenSize.width(),
|
BaseElement element; element.contour = contour;
|
||||||
(2 * (transBound.y() + transBound.height()) - screenSize.height()) / screenSize.height()
|
for (auto baseStyle : baseStyles) {
|
||||||
|
if (baseStyle.material->type() == Renderer::MaterialStyleType::kStroke) {
|
||||||
|
auto material = dynamic_cast<MaterialStyleStroke*>(baseStyle.material.get());
|
||||||
|
material->halfWidth = material->halfWidth / maxLen;
|
||||||
|
qDebug() << material->halfWidth;
|
||||||
|
}
|
||||||
|
element.style = baseStyle.material;
|
||||||
|
painting.addElement(element, elementTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug() << bound;
|
||||||
|
|
||||||
|
// TODO ¸ÄÓþØÕó
|
||||||
|
|
||||||
|
/* elementTrans.center = glm::vec2(
|
||||||
|
(2 * bound.center().x() - screenSize.width()) / screenSize.width(),
|
||||||
|
(2 * bound.center().y() - screenSize.height()) / screenSize.height()
|
||||||
);
|
);
|
||||||
decomposeTransform(transform, elementTrans.rotation, elementTrans.scale);
|
decomposeTransform(transform, elementTrans.rotation, elementTrans.scale);
|
||||||
elementTrans.flip = glm::bvec2(
|
elementTrans.flip = glm::bvec2(
|
||||||
|
@ -126,3 +200,33 @@ void PaintingUtil::decomposeTransform(QTransform trans, float& angle, glm::vec2&
|
||||||
scale = glm::vec2(R.m11(), R.m22());
|
scale = glm::vec2(R.m11(), R.m22());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double PaintingUtil::getMaxLineWidth(LayerWrapper* root) {
|
||||||
|
double maxWidth = 0;
|
||||||
|
queue<LayerWrapper* > layerQueue;
|
||||||
|
layerQueue.push(root);
|
||||||
|
while (!layerQueue.empty()) {
|
||||||
|
auto layer = layerQueue.front();
|
||||||
|
layerQueue.pop();
|
||||||
|
FolderLayerWrapper* nextLayer = nullptr;
|
||||||
|
LeafLayerWrapper* leafLayer = dynamic_cast<LeafLayerWrapper*>(layer);
|
||||||
|
if (leafLayer != nullptr) {
|
||||||
|
GroupElement* wrapperElement = dynamic_cast<GroupElement*>(leafLayer->wrappedElement);
|
||||||
|
if (wrapperElement != nullptr) {
|
||||||
|
nextLayer = wrapperElement->sourceLayer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
maxWidth = std::max(maxWidth, (double)leafLayer->styles.boundingBoxAffectValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nextLayer = dynamic_cast<FolderLayerWrapper*>(layer);
|
||||||
|
}
|
||||||
|
if (nextLayer != nullptr) {
|
||||||
|
for (auto sonLayer : nextLayer->children) {
|
||||||
|
layerQueue.push(sonLayer.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxWidth;
|
||||||
|
}
|
|
@ -6,8 +6,8 @@ class PaintingUtil
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static QJsonObject readJsonFile(QString jsonFilePath);
|
static QJsonObject readJsonFile(QString jsonFilePath);
|
||||||
static void traverseLayTree(LayerWrapper* nowLayer, QTransform transform, glm::bvec2 flip, Renderer::Painting& painting);
|
static FolderLayerWrapper* handleLayerWrapper(LayerWrapper* nowLayer, double& maxLineWidth, QTransform& transform, Renderer::Painting& painting);
|
||||||
static void decomposeTransform(QTransform trans, float& angle, glm::vec2& scale);
|
static double getMaxLineWidth(LayerWrapper* root);
|
||||||
public:
|
public:
|
||||||
static Renderer::Painting transfromToPainting(QString jsonFilePath);
|
static Renderer::Painting transfromToPainting(QString jsonFilePath);
|
||||||
|
|
||||||
|
|
|
@ -228,12 +228,13 @@ GLuint Renderer::Model::loadPainting(std::string path)
|
||||||
if (iter != paintingLoaded.end())
|
if (iter != paintingLoaded.end())
|
||||||
return iter->second;
|
return iter->second;
|
||||||
|
|
||||||
//vector<std::shared_ptr<Contour>> contour = {
|
Painting painting;
|
||||||
// std::make_shared<Contour>(SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse()),
|
//if (auto file = QFileInfo(QString(path.c_str())); file.isFile())
|
||||||
// std::make_shared<Contour>(SvgParser("M308.49,212.25l23,28.38-82,78.31c-14.28,13.64-26.34-20.6-53.44,9.32l-30.24-13.4,63.56-51.59L190.71,215.6l-32.92,26.72L149.5,232.1l32.92-26.72L173.2,194l-32.91,26.72-7.38-9.08L165.83,185l-38.69-47.66L94.22,164,85,152.65l32.91-26.72-9.21-11.35L75.79,141.3l-5.53-6.81,32.92-26.72L94,96.42,61.05,123.14l-12-14.76L37.72,117.6l12,14.75L30.41,148,0,110.55,136.2,0l30.4,37.46L147.31,53.12l-12-14.76L124,47.58l12,14.75L103.05,89.05l9.21,11.35,32.92-26.72,5.52,6.81-32.91,26.72L127,118.56l32.92-26.72,9.21,11.35-32.91,26.72,38.69,47.67,32.91-26.72,7.37,9.08-32.91,26.72L191.49,198l32.92-26.72,8.29,10.22-32.92,26.71,38.7,47.68L302,204.3l6.45,7.95Z", 331.52, 328.26).parse()),
|
if(auto file = QFileInfo(QString("../test.json")); file.isFile())
|
||||||
// std::make_shared<Contour>(SvgParser("M377,459.61a11.26,11.26,0,0,1,11.27-11.27H696.12a11.27,11.27,0,0,0,11-8.62A359.84,359.84,0,0,0,708,280.56a11.26,11.26,0,0,0-11-8.73H388.27A11.26,11.26,0,0,1,377,260.57h0a11.26,11.26,0,0,1,11.27-11.26H683.71A11.32,11.32,0,0,0,694.28,234C649.8,113.69,542.57,23.85,412.3,4.12a11.22,11.22,0,0,0-12.76,11.17v158.9a11.26,11.26,0,0,0,11.26,11.27H583.12a11.32,11.32,0,0,0,9.26-17.75c-31.67-46.59-78.51-75.2-109.11-90.07a11.25,11.25,0,0,0-16.13,10.17V115.2a11.24,11.24,0,0,0,6.22,10.07l7.51,3.76a11.28,11.28,0,0,1,5,15.12h0a11.27,11.27,0,0,1-15.11,5l-20-10a11.27,11.27,0,0,1-6.22-10.07V54a11.27,11.27,0,0,1,14.62-10.75c5.11,1.59,125.66,40.35,172.24,149A11.27,11.27,0,0,1,621.11,208H388.27A11.26,11.26,0,0,1,377,196.73V11.36A11.32,11.32,0,0,0,365.89.08C363.34,0,360.79,0,358.22,0s-5.11,0-7.66.08a11.32,11.32,0,0,0-11.11,11.28V196.74A11.26,11.26,0,0,1,328.18,208H95.35A11.27,11.27,0,0,1,85,192.3c46.57-108.67,167.12-147.42,172.23-149A11.26,11.26,0,0,1,271.86,54v75.11a11.25,11.25,0,0,1-6.23,10.07l-20,10a11.27,11.27,0,0,1-15.11-5h0a11.26,11.26,0,0,1,5-15.11l7.52-3.76a11.27,11.27,0,0,0,6.22-10.07V87.82a11.25,11.25,0,0,0-16.14-10.16c-30.6,14.87-77.45,43.48-109.1,90.07a11.3,11.3,0,0,0,9.25,17.74H305.66a11.26,11.26,0,0,0,11.27-11.26V15.31A11.22,11.22,0,0,0,304.17,4.14C173.88,23.86,66.66,113.71,22.17,234a11.32,11.32,0,0,0,10.56,15.29H328.18a11.26,11.26,0,0,1,11.27,11.26v0a11.26,11.26,0,0,1-11.27,11.26H19.52a11.26,11.26,0,0,0-11,8.72,359.84,359.84,0,0,0,.83,159.16,11.26,11.26,0,0,0,11,8.61H328.18a11.26,11.26,0,0,1,11.27,11.27h0a11.26,11.26,0,0,1-11.27,11.26h-294a11.32,11.32,0,0,0-10.53,15.4C69,604.65,175.3,692.78,304.16,712.3a11.21,11.21,0,0,0,12.76-11.16V542.22A11.26,11.26,0,0,0,305.66,531h-166c-9.53,0-14.89,11.22-8.69,18.47,34.09,39.77,74.45,65.66,101.77,80.18a11.25,11.25,0,0,0,16.53-10V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,271.85,591v63.85A11.27,11.27,0,0,1,256.8,665.5c-4.45-1.59-109.58-40-171-139.9a11.27,11.27,0,0,1,9.59-17.17H328.18a11.26,11.26,0,0,1,11.27,11.26V705.08a11.32,11.32,0,0,0,11.11,11.28q3.82.07,7.66.08c2.57,0,5.12,0,7.67-.08A11.32,11.32,0,0,0,377,705.08V519.69a11.25,11.25,0,0,1,11.27-11.26H621.1a11.26,11.26,0,0,1,9.59,17.16c-61.46,99.87-166.59,138.3-171,139.9a11.27,11.27,0,0,1-15-10.61V591a11.26,11.26,0,0,1,11.26-11.26h0A11.26,11.26,0,0,1,467.14,591v28.6a11.25,11.25,0,0,0,16.53,10c27.33-14.53,67.68-40.42,101.77-80.19,6.2-7.23.85-18.46-8.69-18.46h-166a11.26,11.26,0,0,0-11.26,11.26V701.12a11.21,11.21,0,0,0,12.76,11.17c128.86-19.51,235.14-107.66,280.48-226a11.33,11.33,0,0,0-10.53-15.41h-294A11.25,11.25,0,0,1,377,459.61ZM35.27,399.53V316.9a11.26,11.26,0,0,1,11.27-11.26H669.92a11.25,11.25,0,0,1,11.26,11.26v82.63a11.25,11.25,0,0,1-11.26,11.26H46.54a11.27,11.27,0,0,1-11.27-11.26Z", 716.45, 716.44).parse())
|
painting = PaintingUtil::transfromToPainting("../test.json");
|
||||||
//};
|
else
|
||||||
|
{
|
||||||
|
qDebug() << path.c_str() << "Not Found, Using Default Painting";
|
||||||
vector<std::pair<std::shared_ptr<Contour>, float>> contours;
|
vector<std::pair<std::shared_ptr<Contour>, float>> contours;
|
||||||
|
|
||||||
QPainterPath painterPaths[3];
|
QPainterPath painterPaths[3];
|
||||||
|
|
|
@ -20,12 +20,13 @@ QVector4D BvhTree::Union(QVector4D a, QVector4D b) {
|
||||||
|
|
||||||
QVector4D BvhTree::merge(BvhPtr lp, BvhPtr rp) {
|
QVector4D BvhTree::merge(BvhPtr lp, BvhPtr rp) {
|
||||||
QVector4D a = lp->bound, b = rp->bound;
|
QVector4D a = lp->bound, b = rp->bound;
|
||||||
|
/*
|
||||||
if (lp->isLeaf) {
|
if (lp->isLeaf) {
|
||||||
a = BvhTreeData::boundWithRotation(a, lp->getRightSon());
|
a = BvhTreeData::boundWithRotation(a, lp->getRightSon());
|
||||||
}
|
}
|
||||||
if (rp->isLeaf) {
|
if (rp->isLeaf) {
|
||||||
b = BvhTreeData::boundWithRotation(b, rp->getRightSon());
|
b = BvhTreeData::boundWithRotation(b, rp->getRightSon());
|
||||||
}
|
}*/
|
||||||
return Union(a, b);
|
return Union(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
{
|
||||||
|
"background-color": "#ffffff",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"include": "../svg/2.svg"
|
||||||
|
},
|
||||||
|
"name": "ababa",
|
||||||
|
"type": "svg-file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"reference-layer": "0.0"
|
||||||
|
},
|
||||||
|
"name": "ababa-group",
|
||||||
|
"type": "group"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"include": "../svg/0.svg"
|
||||||
|
},
|
||||||
|
"name": "ababa2",
|
||||||
|
"type": "svg-file"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"height": 1080,
|
||||||
|
"project-name": "",
|
||||||
|
"root-layer": {
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"element": 0,
|
||||||
|
"is-folder": false,
|
||||||
|
"name": "Leaf1",
|
||||||
|
"styles": [
|
||||||
|
{
|
||||||
|
"enableEachSideIndependent": false,
|
||||||
|
"left": "AACgQAEAIZwAf///AAAA/w==",
|
||||||
|
"right": "AADgQAAACJw=",
|
||||||
|
"type": "stroke"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform": {
|
||||||
|
"offset": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"rotation": 0,
|
||||||
|
"scale": {
|
||||||
|
"x": 1,
|
||||||
|
"y": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"is-folder": true,
|
||||||
|
"name": "GroupFolderExample",
|
||||||
|
"referenced-by": 1,
|
||||||
|
"transform": {
|
||||||
|
"offset": {
|
||||||
|
"x": 50,
|
||||||
|
"y": 50
|
||||||
|
},
|
||||||
|
"rotation": 0,
|
||||||
|
"scale": {
|
||||||
|
"x": 1,
|
||||||
|
"y": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"is-folder": true,
|
||||||
|
"name": "root",
|
||||||
|
"referenced-by": null,
|
||||||
|
"transform": {
|
||||||
|
"offset": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"rotation": 0,
|
||||||
|
"scale": {
|
||||||
|
"x": 1,
|
||||||
|
"y": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"width": 1080
|
||||||
|
}
|
Loading…
Reference in New Issue