diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index b06b955..2ca822f 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -14,7 +14,7 @@
{3FE96A33-2BB7-4686-A710-3EB8E3BBD709}
QtVS_v304
10.0
- 10.0.19041.0
+ 10.0
$(MSBuildProjectDirectory)\QtMsBuild
@@ -61,13 +61,13 @@
- stdcpp17
+ stdcpp20
$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);$(Qt_INCLUDEPATH_)
- stdcpp17
+ stdcpp20
$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);
@@ -118,6 +118,7 @@
+
@@ -175,6 +176,7 @@
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index 0d4ccee..f6b745d 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -174,6 +174,9 @@
Source Files\Editor\third-party modules
+
+ Source Files\Renderer\Painting
+
@@ -354,6 +357,9 @@
Header Files\Editor\util
+
+ Header Files\Renderer\Painting
+
diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp
index 3df1c25..7f27e23 100644
--- a/ArchitectureColoredPainting/Shaders/painting.comp
+++ b/ArchitectureColoredPainting/Shaders/painting.comp
@@ -909,8 +909,8 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
debugBVH.r += 1;
}
//uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y;
- uint elementType = bvhChildren[elementBvhRoot + elementBvhIndex].y;
-
+ //uint elementType = bvhChildren[elementBvhRoot + elementBvhIndex].y;
+ float elementType = elementData[styleIndex];
// for(int i = 0; i<200;i++)
if (elementType == 0) //面
{
diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp
index 7bde75f..20a3b56 100644
--- a/ArchitectureColoredPainting/src/Renderer/Model.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp
@@ -8,7 +8,9 @@
#include
#include "Painting/BvhTree.h"
#include "Painting/ShortCutTree.h"
+#include "Painting/Painting.h"
#include "../SvgParser.h"
+
using namespace Renderer;
using std::vector;
Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram)
@@ -176,257 +178,8 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
m_mesh->indices.push_back(face.mIndices[j]);
}
}
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////
- BvhTree rootBvhTree;
- vector rootBvhTreeData;
- for (int i = 0; i < 1000; i++)
- {
- float x = (float)rand() / RAND_MAX * 2 - 1;
- float y = (float)rand() / RAND_MAX * 2 - 1;
- float z = 0.05 + x;//(float)rand() / RAND_MAX * (0.1) + x;
- float w = 0.05 + y;//(float)rand() / RAND_MAX * (0.1) + y;
- rootBvhTreeData.push_back(BvhTreeData(QVector4D(x, y, z, w), 0, encodeZIndexAngle(1, (float)rand() / RAND_MAX * 360)));
- //rootBvhTreeData.push_back(BvhTreeData(QVector4D(x, y, z, w), 0, encodeZIndexAngle(1, 0)));
- }
- /*rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.7, -0.7, -0.1, -0.1), 0, encodeZIndexAngle(1, 0)));
- rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.8, 0.2, -0.2, 0.8), 0, encodeZIndexAngle(1, 0)));
- rootBvhTreeData.push_back(BvhTreeData(QVector4D(0.2, -0.8, 0.8, -0.2), 0, encodeZIndexAngle(1, 0)));
- rootBvhTreeData.push_back(BvhTreeData(QVector4D(0.1, 0.1, 0.7, 0.7), 0, encodeZIndexAngle(1, 0)));*/
- //rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.8, -0.8, -0.2, -0.1), 0, 0));
- //rootBvhTreeData.push_back(BvhTreeData(QVector4D(-0.7, -0.8, -0.2, -0.1), 0, 0));
- /* initBound.push_back(QVector4D(-0.8, -0.8, -0.7, -0.7));
- initBound.push_back(QVector4D(-0.8, 0.7, -0.7, 0.8));
- initBound.push_back(QVector4D(0.7, -0.8, 0.8, -0.7));
- initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/
- rootBvhTree.buildBvhTree(rootBvhTreeData.data(), rootBvhTreeData.size());
-
-
- //vector> lineSet = SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse();
- //vector> lineSet = 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();
- //vector < vector > lineSet = {
- // {{-0.5,0.9}, {0.1,0.3}},
- // {{0.1,0.3}, {0.0204656,0.379534}, {-0.2,0.0632573}, {-0.2,0.175736}},
- // {{-0.2,0.175736}, {-0.2,0.288215}, {-0.579534,0.220466}, {-0.5,0.3}},
- // {{-0.5,0.3}, {-0.420466,0.379534}, {-0.736743,0.6}, {-0.624264,0.6}},
- // {{-0.624264,0.6}, {-0.511785,0.6}, {-0.579534,0.979534}, {-0.5,0.9}}
- //};
- vector> lineSet = 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();
- qDebug() << lineSet.size();
- for (vector& line : lineSet)
- {
- for (Point& p : line)
- p.show();
- std::cout << std::endl;
- }
-
-
- ShortCutTree shortCutTree(20);
- shortCutTree.buildShortCutTree(lineSet);
- vector pointVector;
- vector lineVector;
- vector bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector);
- for (auto& data : bvhTreeData)
- data.rightSon = 0;
- qDebug() << "----------------------------------------------";
- qDebug() << "element0CellNum: " << bvhTreeData.size();
- //qDebug() << pointVector;
- //qDebug() << lineVector;
- /*for (BvhTreeData data : bvhTreeData)
- {
- data.show();
- }*/
- BvhTree element0Bvh;
- element0Bvh.buildBvhTree(bvhTreeData.data(), bvhTreeData.size());
- std::vector element0Children;
- std::vector element0Bounds;
- element0Bvh.getBvhArray(element0Children, element0Bounds);
- //qDebug() << element0Children;
- //qDebug() << element0Bounds;
-
- //std::vector bvhChildren = {
- // //root
- // 1,2,
- // 3,4, 5,6,
- // encodeChild(0),0, encodeChild(0),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(0),0, encodeChild(0),0
- //};
- //std::vector bvhBounds = {
- // //root
- // QVector4D(-1,-1,1,1),
- // QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9),
- // QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.2,0.1,0.8,0.8),
- //};
- std::vector bvhChildren;
- std::vector bvhBounds;
- rootBvhTree.getBvhArray(bvhChildren, bvhBounds);
-
- //qDebug() << bvhChildren;
- bvhChildren.insert(bvhChildren.end(), element0Children.begin(), element0Children.end());
- bvhBounds.insert(bvhBounds.end(), element0Bounds.begin(), element0Bounds.end());
-
-
- std::vector elementIndex = lineVector;
- std::vector elementData = {
- //fillStyle
- //fill
- 0,
- //fillType
- 0, //单色
- //fillColorMetallicRoughness
- 240/255.,220/255.,160/255., 0.996,0.18,
- };
- std::vector elementOffset = {
- //element0
- rootBvhTree.getBvhNodeNum(), //elementBvhRoot
- 0, //styleOffset
- (GLuint)elementData.size(), //pointsOffset
- 0, //linesOffset
- };
- elementData.insert(elementData.end(), pointVector.begin(), pointVector.end());
- //qDebug() << elementIndex;
- //qDebug() << elementData;
-
- /////////////////////////////////////////////////////////////////////////////////////////////////
- std::vector bvhChildren0 = {
- //root
- 1,2,
- 3,4, 5,6,
- encodeChild(2),0, encodeChild(1),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(3),0, encodeChild(0),0,
- //elememt0
- 1,2,
- encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,0/*封闭图形*/, encodeChild(24), 0,
- //elememt1
- encodeChild(12)/*contour索引*/, 1/*线*/
-
- };
- std::vector bvhBounds0 = {
- //root
- QVector4D(-1,-1,1,1),
- QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9),
- QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.3,0.2,0.7,0.7),
- //elememt0
- QVector4D(-1,-1,1,1),
- QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1),
- //elememt1
- QVector4D(-1,-1,1,1)
- };
- std::vector elementOffset0 = {
- //element0
- 7, //elementBvhRoot
- 14, //styleOffset
- 0, //pointsOffset
- 0, //linesOffset
- //element1
- 10, //elementBvhRoot
- 39, //styleOffset
- 21, //pointsOffset
- 28, //linesOffset
- //element2
- 10, //elementBvhRoot
- 51, //styleOffset
- 21, //pointsOffset
- 28, //linesOffset
- //element3
- 10, //elementBvhRoot
- 63, //styleOffset
- 21, //pointsOffset
- 28, //linesOffset
- };
-
- std::vector elementIndex0 = {
- //element0
- //lines, 全部当作三阶贝塞尔, 每条线四个点索引
- 0,1,1,2,
- 0,0,3,3,
- 3,4,4,5,
- 2,2,5,5,
- 5,5,6,6,
- //contours, 第一个元素为线数,后面为轮廓线索引
- 3, 1,2,4,
- 3, 0,2,3,
- //element1
- //lines
- 0,7,8,1,
- 1,2,3,4,
- 5,5,6,6,
- //contours
- 2, 0 ,1
- };
-
- std::vector elementData0 = {
- //element0
- //points
- -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
- //fillStyle
- //fill
- 0,
- //fillType
- 0, //单色
- //fillColorMetallicRoughness
- 1,1,0, 0,0.8,
-
- //element1
- //points
- 0.5,-0.5, 0.5,0.5, -0.2,0.5, -0.5,0.2, -0.5,-0.5, -0.8,-0.5, -0.8,0.5, 0.5,-0.4, 0.5,0.4,
- //strokeStyle
- //stroke
- 1,
- //strokeWidth
- 0.1,
- //strokeEndType
- 0, //圆角
- //strokeFillType
- 0, //单色
- //线类型
- 2, //左侧
- //线外描边宽度
- 0,
- //线外描边方式
- 0, //单色
- //strokeFillColorMetallicRoughness
- 1,0,1, 0,0.8,
- //strokeStyle
- //stroke
- 1,
- //strokeWidth
- 0.1,
- //strokeEndType
- 0, //圆角
- //strokeFillType
- 2, //单色
- //线类型
- 1, //左侧
- //线外描边宽度
- 0,
- //线外描边方式
- 0, //单色
- //strokeFillColorMetallicRoughness
- 1,0,1, 0,0.8,
- //strokeStyle
- //stroke
- 1,
- //strokeWidth
- 0.1,
- //strokeEndType
- 0, //圆角
- //strokeFillType
- 1, //单色
- //线类型
- 0, //左侧
- //线外描边宽度
- 0,
- //线外描边方式
- 0, //单色
- //strokeFillColorMetallicRoughness
- 1,0,1, 0,0.8,
- };
-
- //m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector(children.begin()+2, children.end()), bounds,
- // elementOffset, elementIndex, elementData);
- /* m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds,
- elementOffset, elementIndex, elementData);*/
- m_mesh->paintingIndex = paintingHelper->addPainting(7, bvhChildren0, bvhBounds0,
- elementOffset0, elementIndex0, elementData0);
+ m_mesh->paintingIndex = loadPainting(std::string(str.C_Str()));
m_mesh->setupMesh();
return m_mesh;
}
@@ -537,7 +290,7 @@ QVector Model::loadMaterialTextures(aiMaterial* mat, aiTextureType typ
if (std::strcmp(textures_loaded[j]->path.toStdString().c_str(), str.C_Str()) == 0)
{
textures.push_back(textures_loaded[j]);
- skip = true; //【优化】 带有相同filepath的纹理已经加载,继续到下一个
+ skip = true;
break;
}
}
@@ -559,3 +312,226 @@ QVector Model::loadMaterialTextures(aiMaterial* mat, aiTextureType typ
}
return textures;
}
+
+GLuint Renderer::Model::loadPainting(std::string path)
+{
+ auto iter = paintingLoaded.find(path);
+ if (iter != paintingLoaded.end())
+ return iter->second;
+
+ //vector < vector > lineSet = {
+ // {{-0.5,0.9}, {0.1,0.3}},
+ // {{0.1,0.3}, {0.0204656,0.379534}, {-0.2,0.0632573}, {-0.2,0.175736}},
+ // {{-0.2,0.175736}, {-0.2,0.288215}, {-0.579534,0.220466}, {-0.5,0.3}},
+ // {{-0.5,0.3}, {-0.420466,0.379534}, {-0.736743,0.6}, {-0.624264,0.6}},
+ // {{-0.624264,0.6}, {-0.511785,0.6}, {-0.579534,0.979534}, {-0.5,0.9}}
+ //};
+
+ vector> contour = {
+ std::make_shared(SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse()),
+ std::make_shared(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()),
+ std::make_shared(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())
+ };
+ vector> style = {
+ std::make_shared(std::vector{
+ //strokeStyle
+ //stroke
+ 1,
+ //strokeWidth
+ 0.01,
+ //strokeEndType
+ 0, //圆角
+ //strokeFillType
+ 0, //单色
+ //线类型
+ 2, //双侧
+ //线外描边宽度
+ 0,
+ //线外描边方式
+ 0, //单色
+ //strokeFillColorMetallicRoughness
+ 1,0,1, 0,0.8,
+ }),
+ std::make_shared(std::vector{
+ //fillStyle
+ //fill
+ 0,
+ //fillType
+ 0, //单色
+ //fillColorMetallicRoughness
+ 240 / 255., 220 / 255., 160 / 255., 0.996, 0.18,
+ }),
+ std::make_shared(std::vector{
+ //fillStyle
+ //fill
+ 0,
+ //fillType
+ 0, //单色
+ //fillColorMetallicRoughness
+ 24 / 255., 220 / 255., 16 / 255., 0., 0.18,
+ }),
+ };
+ vector> element = {
+ std::make_shared(Element{ contour[0], style[1]}),
+ std::make_shared(Element{ contour[1], style[2]}),
+ std::make_shared(Element{ contour[2], style[0]}),
+ };
+ Painting painting;
+ //for (int i = 0; i < 3; i++)
+ //{
+ // float x = (float)rand() / RAND_MAX * 2 - 1;
+ // float y = (float)rand() / RAND_MAX * 2 - 1;
+ // float z = 0.05 + x;//(float)rand() / RAND_MAX * (0.1) + x;
+ // float w = 0.05 + y;//(float)rand() / RAND_MAX * (0.1) + y;
+ // //rootBvhTreeData.push_back(BvhTreeData(QVector4D(x, y, z, w), 0, encodeZIndexAngle(1, (float)rand() / RAND_MAX * 360)));
+ // painting.addElement(element[i%3], QVector4D(x, y, z, w), (float)rand() / RAND_MAX * 360, 1);
+ //}
+ painting.addElement(element[0], QVector4D(-0.8, -0.8, -0.2, -0.1), 0, 0);
+ painting.addElement(element[1], QVector4D(-0.7, 0.2, -0.2, 0.7), 0, 0);
+ painting.addElement(element[2], QVector4D(0.2, -0.8, 0.8, -0.1), 0, 0);
+
+ painting.generateBuffers();
+ /////////////////////////////////////////////////////////////////////////////////////////////////
+ std::vector bvhChildren0 = {
+ //root
+ 1,2,
+ 3,4, 5,6,
+ encodeChild(2),0, encodeChild(1),GLuint(30. / 360 * 65536 + 1 * 65536) /*右儿子用来表示旋转角度和zIndex*/, encodeChild(3),0, encodeChild(0),0,
+ //elememt0
+ 1,2,
+ encodeChild(20)/*contour索引,由于contour不定长,这里需要给到contour在elementIndex中位置*/,0/*封闭图形*/, encodeChild(24), 0,
+ //elememt1
+ encodeChild(12)/*contour索引*/, 1/*线*/
+
+ };
+ std::vector bvhBounds0 = {
+ //root
+ QVector4D(-1,-1,1,1),
+ QVector4D(-0.9,-0.9,-0.1,0.9), QVector4D(0.1, -0.9,0.9,0.9),
+ QVector4D(-0.8,-0.8,-0.2,-0.1), QVector4D(-0.7,0.2,-0.2,0.7), QVector4D(0.2,-0.8,0.8,-0.1), QVector4D(0.3,0.2,0.7,0.7),
+ //elememt0
+ QVector4D(-1,-1,1,1),
+ QVector4D(-1,-1,-0.2,1), QVector4D(-0.2,-1,1,1),
+ //elememt1
+ QVector4D(-1,-1,1,1)
+ };
+ std::vector elementOffset0 = {
+ //element0
+ 7, //elementBvhRoot
+ 14, //styleOffset
+ 0, //pointsOffset
+ 0, //linesOffset
+ //element1
+ 10, //elementBvhRoot
+ 39, //styleOffset
+ 21, //pointsOffset
+ 28, //linesOffset
+ //element2
+ 10, //elementBvhRoot
+ 51, //styleOffset
+ 21, //pointsOffset
+ 28, //linesOffset
+ //element3
+ 10, //elementBvhRoot
+ 63, //styleOffset
+ 21, //pointsOffset
+ 28, //linesOffset
+ };
+
+ std::vector elementIndex0 = {
+ //element0
+ //lines, 全部当作三阶贝塞尔, 每条线四个点索引
+ 0,1,1,2,
+ 0,0,3,3,
+ 3,4,4,5,
+ 2,2,5,5,
+ 5,5,6,6,
+ //contours, 第一个元素为线数,后面为轮廓线索引
+ 3, 1,2,4,
+ 3, 0,2,3,
+ //element1
+ //lines
+ 0,7,8,1,
+ 1,2,3,4,
+ 5,5,6,6,
+ //contours
+ 2, 0 ,1
+ };
+
+ std::vector elementData0 = {
+ //element0
+ //points
+ -0.2,1, -0.2,-0.2, 1,-0.2, -1,1, -1,-1, 1,-1, 1,1,
+ //fillStyle
+ //fill
+ 0,
+ //fillType
+ 0, //单色
+ //fillColorMetallicRoughness
+ 1,1,0, 0,0.8,
+
+ //element1
+ //points
+ 0.5,-0.5, 0.5,0.5, -0.2,0.5, -0.5,0.2, -0.5,-0.5, -0.8,-0.5, -0.8,0.5, 0.5,-0.4, 0.5,0.4,
+ //strokeStyle
+ //stroke
+ 1,
+ //strokeWidth
+ 0.1,
+ //strokeEndType
+ 0, //圆角
+ //strokeFillType
+ 0, //单色
+ //线类型
+ 2, //左侧
+ //线外描边宽度
+ 0,
+ //线外描边方式
+ 0, //单色
+ //strokeFillColorMetallicRoughness
+ 1,0,1, 0,0.8,
+ //strokeStyle
+ //stroke
+ 1,
+ //strokeWidth
+ 0.1,
+ //strokeEndType
+ 0, //圆角
+ //strokeFillType
+ 2, //单色
+ //线类型
+ 1, //左侧
+ //线外描边宽度
+ 0,
+ //线外描边方式
+ 0, //单色
+ //strokeFillColorMetallicRoughness
+ 1,0,1, 0,0.8,
+ //strokeStyle
+ //stroke
+ 1,
+ //strokeWidth
+ 0.1,
+ //strokeEndType
+ 0, //圆角
+ //strokeFillType
+ 1, //单色
+ //线类型
+ 0, //左侧
+ //线外描边宽度
+ 0,
+ //线外描边方式
+ 0, //单色
+ //strokeFillColorMetallicRoughness
+ 1,0,1, 0,0.8,
+ };
+
+
+ //m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector(children.begin()+2, children.end()), bounds,
+ // elementOffset, elementIndex, elementData);
+ /*m_mesh->paintingIndex = paintingHelper->addPainting(bvhChildren0, bvhBounds0,
+ elementOffset0, elementIndex0, elementData0);*/
+ GLuint index = paintingHelper->addPainting(painting);
+ paintingLoaded.insert({ path, index });
+ return index;
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Model.h b/ArchitectureColoredPainting/src/Renderer/Model.h
index 325ef9c..51febb5 100644
--- a/ArchitectureColoredPainting/src/Renderer/Model.h
+++ b/ArchitectureColoredPainting/src/Renderer/Model.h
@@ -29,6 +29,7 @@ namespace Renderer
PaintingHelper* paintingHelper = nullptr;
/* 模型数据 */
+ std::unordered_map paintingLoaded;
QVector textures_loaded; //纹理
QVector meshes; //网格
QDir directory; //模型所在路径
@@ -49,5 +50,6 @@ namespace Renderer
//加载材质纹理
QVector loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
+ GLuint loadPainting(std::string path);
};
}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp
new file mode 100644
index 0000000..685165e
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.cpp
@@ -0,0 +1,18 @@
+#include "ElementStyle.h"
+
+using namespace Renderer;
+
+ElementStyle::ElementStyle(std::vector style)
+ :style(style)
+{
+}
+
+bool Renderer::ElementStyle::isLine()
+{
+ return style[0];
+}
+
+std::vector ElementStyle::encoded()
+{
+ return style;
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h
new file mode 100644
index 0000000..18a61f4
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/ElementStyle.h
@@ -0,0 +1,16 @@
+#pragma once
+#include
+#include
+
+namespace Renderer
+{
+ class ElementStyle
+ {
+ public:
+ ElementStyle(std::vector style);
+ bool isLine();
+ std::vector encoded();
+ private:
+ std::vector style;
+ };
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.h b/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.h
index 877f9f7..7c1ed9e 100644
--- a/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.h
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/LineTree.h
@@ -45,8 +45,8 @@ namespace Renderer {
public:
void init();
void setLineWidth(double width);
- LineTree(int lineMin = 3, double width = 0.3, int type = 0)
- : requiredLineMin(lineMin), lineWidth(width), lineType(type), numLine(0), numPoint(0) {}
+ LineTree(int lineMin = 3)
+ : requiredLineMin(lineMin), numLine(0), numPoint(0) {}
void buildLineTree(std::vector& lineSet, double width, int type = 0);
std::vector getPointLineAndBvhTree(std::vector& pointSet, std::vector& lineSet);
};
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp
index 55cf5f6..6fd5edc 100644
--- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp
@@ -1,35 +1,63 @@
#include "Painting.h"
#include "../../SvgParser.h"
#include "ShortCutTree.h"
+#include "LineTree.h"
+#include
using namespace Renderer;
+
+constexpr int maxLineCount = 20;
+
Painting::Painting()
{
- Contour 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();
- std::shared_ptr contourPtr = std::make_shared(contour);
- contourPool.insert({ contourPtr, {nullptr, nullptr} });
+}
-
- std::vector style = {
- //fillStyle
- //fill
- 0,
- //fillType
- 0, //单色
- //fillColorMetallicRoughness
- 240 / 255.,220 / 255.,160 / 255., 0.996,0.18,
- };
-
- Element element{ contourPtr, style, QVector4D(-0.8,-0.8,-0.2,-0.1), 0, 0 };
- elements.push_back(element);
- if (style[0] == 0 && contourPool[contourPtr].first == nullptr)
+void Renderer::Painting::addElement(ElementWithTransform elementWithTransform)
+{
+ auto it = elementPool.find(elementWithTransform.element);
+ if (it == elementPool.end())
{
- ShortCutTree shortCutTree(20);
- shortCutTree.buildShortCutTree(*contourPtr);
- ElementBuffer elementBuffer;
- elementBuffer.bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
- contourPool[contourPtr].first = std::make_shared(elementBuffer);
+ auto element = elementWithTransform.element;
+ auto iter = contourPool.insert({ element->contour, {nullptr, nullptr} }).first;
+
+ if (!element->style->isLine() && iter->second.first == nullptr)
+ {
+ qDebug() << "Build ShortCutTree---------------------------------------------------------------------------------------------------";
+ ShortCutTree shortCutTree(maxLineCount);
+ shortCutTree.buildShortCutTree(*element->contour);
+ ContourBuffer elementBuffer;
+ std::vector bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
+ BvhTree bvhTree;
+ bvhTree.buildBvhTree(bvhLeaves.data(), bvhLeaves.size());
+ bvhTree.getBvhArray(elementBuffer.bvhChildren, elementBuffer.bvhBounds);
+ iter->second.first = std::make_shared(elementBuffer);
+ qDebug() << "---------------------------------------------------------------------------------------------------------------------";
+ }
+ else if (element->style->isLine() && iter->second.second == nullptr)
+ {
+ qDebug() << "Build LineTree-------------------------------------------------------------------------------------------------------";
+ LineTree lineTree(maxLineCount);
+ lineTree.buildLineTree(*element->contour, element->style->encoded()[1]);
+ ContourBuffer elementBuffer;
+ std::vector bvhLeaves = lineTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer);
+ BvhTree bvhTree;
+ bvhTree.buildBvhTree(bvhLeaves.data(), bvhLeaves.size());
+ bvhTree.getBvhArray(elementBuffer.bvhChildren, elementBuffer.bvhBounds);
+ iter->second.second = std::make_shared(elementBuffer);
+ qDebug() << "---------------------------------------------------------------------------------------------------------------------";
+
+
+ }
+ stylePool.insert({ element->style, 0 });
+ elementPool.insert({ element, 0});
}
+
+ elements.push_back(elementWithTransform);
+}
+
+void Renderer::Painting::addElement(std::shared_ptr element, QVector4D bound, float rotation, int zIndex)
+{
+ addElement(ElementWithTransform{ element, bound, rotation, zIndex });
}
GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
@@ -37,28 +65,77 @@ GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
return GLuint(rotation / 360 * 0x10000 + zIndex * 0x10000);
}
-//void Painting::addElement(Contour contour, std::vector style, QVector4D bound, float rotation, int zIndex)
-//{
-// BvhTreeData(bound, 0, encodeZIndexRotation(zIndex, rotation));
-//
-// std::shared_ptr element = nullptr;
-// auto iterator = elementMap.find(lines);
-// if (iterator != elementMap.end())
-// element = iterator->second;
-// else
-// {
-// element = std::make_shared(lines);
-// elementMap.insert({ lines, element });
-// }
-//
-//}
-
void Painting::generateBuffers()
{
- //std::unordered_map < std::shared_ptr, int>
- for (auto& iter : contourPool)
- {
- elementData.insert(elementData.end(), iter.second.first->pointBuffer.begin(), iter.second.first->pointBuffer.end());
+ qDebug() << elementPool.size();
+ qDebug() << contourPool.size();
+ qDebug() << stylePool.size();
+
+ bvhChildren.clear();
+ bvhBounds.clear();
+ elementOffset.clear();
+ elementIndex.clear();
+ elementData.clear();
+
+ int index = 0;
+ for (auto& i : elementPool)
+ {
+ i.second = index++;
+ }
+
+ std::vector rootBvhTreeData;
+ for (auto& i:elements)
+ {
+ rootBvhTreeData.push_back(BvhTreeData(i.bound, elementPool[i.element], encodeZIndexRotation(i.zIndex, i.rotation)));
+ //rootBvhTreeData.push_back(BvhTreeData(i.bound, 1, encodeZIndexRotation(i.zIndex, i.rotation)));
+ }
+ BvhTree rootBvhTree;
+ rootBvhTree.buildBvhTree(rootBvhTreeData.data(), rootBvhTreeData.size());
+ std::vector rootBvhChildren;
+ std::vector rootBvhBounds;
+ rootBvhTree.getBvhArray(rootBvhChildren, rootBvhBounds);
+
+ bvhChildren.insert(bvhChildren.end(), rootBvhChildren.begin(), rootBvhChildren.end());
+ bvhBounds.insert(bvhBounds.end(), rootBvhBounds.begin(), rootBvhBounds.end());
+
+ for (auto& i : contourPool)
+ {
+ if (i.second.first != nullptr)
+ insertContourBuffer(i.second.first);
+ if (i.second.second != nullptr)
+ insertContourBuffer(i.second.second);
+ }
+
+ for (auto& i : stylePool)
+ {
+ i.second = elementData.size();
+ std::vector encodedStyle = i.first->encoded();
+ elementData.insert(elementData.end(), encodedStyle.begin(), encodedStyle.end());
+ }
+
+ for (auto& i : elementPool)
+ {
+ //qDebug() <<"element:" << i.second;
+ std::shared_ptr contourBuffer = i.first->style->isLine() ? contourPool[i.first->contour].second : contourPool[i.first->contour].first;
+ elementOffset.push_back({ contourBuffer->bvhOffset, stylePool[i.first->style], contourBuffer->pointsOffset, contourBuffer->linesOffset });
+ //std::cout << std::format("{} {} {} {}\n", contourBuffer->bvhOffset, stylePool[i.first->style], contourBuffer->pointsOffset, contourBuffer->linesOffset);
}
}
+
+GLuint Renderer::Painting::getElementCount()
+{
+ return elements.size();
+}
+
+void Renderer::Painting::insertContourBuffer(std::shared_ptr buffer)
+{
+ buffer->pointsOffset = elementData.size();
+ buffer->linesOffset = elementIndex.size();
+ buffer->bvhOffset = bvhBounds.size();
+
+ elementData.insert(elementData.end(), buffer->pointBuffer.begin(), buffer->pointBuffer.end());
+ elementIndex.insert(elementIndex.end(), buffer->lineBuffer.begin(), buffer->lineBuffer.end());
+ bvhChildren.insert(bvhChildren.end(), buffer->bvhChildren.begin(), buffer->bvhChildren.end());
+ bvhBounds.insert(bvhBounds.end(), buffer->bvhBounds.begin(), buffer->bvhBounds.end());
+}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h
index 53b3a5c..e8ce576 100644
--- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h
@@ -3,6 +3,8 @@
#include
#include "Line.h"
#include "BvhTree.h"
+#include "ElementStyle.h"
+#include
//#include "Element.h"
namespace Renderer
@@ -12,38 +14,50 @@ namespace Renderer
struct Element
{
std::shared_ptr contour;
- std::vector style;
+ std::shared_ptr style;
+ };
+
+ struct ElementWithTransform
+ {
+ std::shared_ptr element;
QVector4D bound;
float rotation;
int zIndex;
};
- struct ElementBuffer
+ struct ContourBuffer
{
std::vector pointBuffer;
std::vector lineBuffer;
- std::vector bvhLeaves;
+ std::vector bvhChildren;
+ std::vector bvhBounds;
+ //std::vector bvhLeaves;
+ GLuint pointsOffset;
+ GLuint linesOffset;
+ GLuint bvhOffset;
};
class Painting
{
public:
std::vector bvhChildren;
- std::vector bvhBound;
- std::vector elementOffset;
+ std::vector bvhBounds;
+ std::vector elementOffset;
std::vector elementIndex;
std::vector elementData;
int paintingId = 0;
Painting();
- //void addElement(Contour contour, std::vector style, QVector4D bound, float rotation, int zIndex);
+ void addElement(ElementWithTransform element);
+ void addElement(std::shared_ptr element, QVector4D bound, float rotation, int zIndex);
void generateBuffers();
+ GLuint getElementCount();
private:
- std::vector bvhLeaves;
- std::unordered_map< std::shared_ptr, std::pair, std::shared_ptr>> contourPool;
- //std::vector> contourPool;
- std::vector elements;
- //std::unordered_map>, std::shared_ptr> elementMap;
+ std::unordered_map, std::pair/*面*/, std::shared_ptr/*线*/>> contourPool;
+ std::unordered_map, GLuint> stylePool;
+ std::map, GLuint> elementPool;
+ std::vector elements;
+ void insertContourBuffer(std::shared_ptr buffer);
};
}
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
index 38053be..f0d7caf 100644
--- a/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.cpp
@@ -6,10 +6,15 @@ PaintingHelper::PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc) :glFu
}
-int PaintingHelper::addPainting(GLuint paintingBvhLength, std::vector bvhChildren, std::vector bvhBound, std::vector elementOffset, std::vector elementIndex, std::vector elementData)
+int Renderer::PaintingHelper::addPainting(Painting painting)
+{
+ return addPainting(painting.bvhChildren, painting.bvhBounds, painting.elementOffset, painting.elementIndex, painting.elementData);
+}
+
+int PaintingHelper::addPainting(std::vector bvhChildren, std::vector bvhBound, std::vector elementOffset, std::vector elementIndex, std::vector elementData)
{
this->paintingOffsets.push_back(0);//paintingBvhRoot
- this->paintingOffsets.push_back(paintingBvhLength);
+ this->paintingOffsets.push_back(0);
this->bvhChildren.insert(this->bvhChildren.end(), bvhChildren.begin(), bvhChildren.end());
this->bvhBound.insert(this->bvhBound.end(), bvhBound.begin(), bvhBound.end());
@@ -40,7 +45,7 @@ void PaintingHelper::allocateBuffers()
glFunc->glGenBuffers(1, &elementOffsetSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, elementOffsetSSBO);
- glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementOffset.size() * sizeof(GLuint), elementOffset.data(), GL_STATIC_READ);
+ glFunc->glBufferData(GL_SHADER_STORAGE_BUFFER, elementOffset.size() * sizeof(glm::uvec4), elementOffset.data(), GL_STATIC_READ);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h
index 8b2b81b..dbd66fe 100644
--- a/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h
+++ b/ArchitectureColoredPainting/src/Renderer/Painting/PaintingHelper.h
@@ -5,6 +5,7 @@
#include
#include
#include "BvhTree.h"
+#include "Painting.h"
namespace Renderer
{
class PaintingHelper
@@ -15,15 +16,16 @@ namespace Renderer
std::vector paintingOffsets;
std::vector bvhChildren;
std::vector bvhBound;
- std::vector elementOffset;
+ std::vector elementOffset;
std::vector elementIndex;
std::vector elementData;
int paintingCount = 0;
public:
PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc);
- int addPainting(GLuint paintingBvhLength, std::vector bvhChildren, std::vector bvhBound,
- std::vector elementOffset, std::vector elementIndex, std::vector elementData);
+ int addPainting(Painting painting);
+ int addPainting(std::vector bvhChildren, std::vector bvhBound,
+ std::vector elementOffset, std::vector elementIndex, std::vector elementData);
void allocateBuffers();
void bindPaintingBuffers();
};
diff --git a/README.md b/README.md
index b091f37..0a8cc6e 100644
--- a/README.md
+++ b/README.md
@@ -13,8 +13,19 @@
## 杩涘害
+### 绾圭悊缂栬緫锛圗ditor锛
+
+瀹屾垚layer淇℃伅灞曠ず鍜屾暟鎹慨鏀癸紙閮ㄥ垎锛
+
+### 鍦烘櫙娓叉煋锛圧enderer锛
+
閲囩敤 PBR (閲戝睘搴-绮楃硻搴) 鏉愯川妯″瀷锛屽満鏅腑瀛樺湪涓涓柟鍚戝厜锛屽彲鎷栧姩婊戝姩鏉¤皟鏁村厜婧愭柟鍚戣瀵熸潗璐ㄦ晥鏋溿
宸插疄鐜癇VH鍔犻熺粨鏋勭殑寤虹珛
-宸插疄鐜板崟鍥惧厓鐨勬媶鍒嗭紝鍗冲垝鍒嗙綉鏍煎苟鐢熸垚蹇嵎娈靛拰缂犵粫澧為噺
\ No newline at end of file
+宸插疄鐜板崟鍥惧厓鐨勬媶鍒嗭紝鍗冲垝鍒嗙綉鏍煎苟鐢熸垚蹇嵎娈靛拰缂犵粫澧為噺
+
+宸插疄鐜扮敱鍥惧厓鏁版嵁寤虹珛瀹屾暣褰╃粯缂栫爜
+
+寰呭畬鍠勭嚎鐨勫崟渚ф弿杈
+