Compare commits

...

6 Commits

Author SHA1 Message Date
wuyize 53c6a4fbe5 解决了painting.comp爆炸的问题 2023-01-19 16:42:40 +08:00
白封羽 f3f3266dc9 合并分支 2023-01-19 16:33:23 +08:00
yang.yongquan e19aac0dd2 修改了一些Bug 2023-01-19 12:58:06 +08:00
yang.yongquan 3efb7973b0 修改了points的检测格式 2023-01-19 12:54:14 +08:00
wuyize 18429b6867 实现从图元及其变换信息建立完整Painting编码 2023-01-18 17:33:45 +08:00
wuyize 1f6998d05b 修改了Renderer的部分编码 2023-01-16 15:20:38 +08:00
16 changed files with 501 additions and 349 deletions

View File

@ -14,7 +14,7 @@
<ProjectGuid>{3FE96A33-2BB7-4686-A710-3EB8E3BBD709}</ProjectGuid> <ProjectGuid>{3FE96A33-2BB7-4686-A710-3EB8E3BBD709}</ProjectGuid>
<Keyword>QtVS_v304</Keyword> <Keyword>QtVS_v304</Keyword>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0.19041.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -120,6 +120,7 @@
<ClCompile Include="src\Renderer\Painting\CubicMonotonization.cpp" /> <ClCompile Include="src\Renderer\Painting\CubicMonotonization.cpp" />
<ClCompile Include="src\Renderer\Light.cpp" /> <ClCompile Include="src\Renderer\Light.cpp" />
<ClCompile Include="src\Renderer\Painting\Element.cpp" /> <ClCompile Include="src\Renderer\Painting\Element.cpp" />
<ClCompile Include="src\Renderer\Painting\ElementStyle.cpp" />
<ClCompile Include="src\Renderer\Painting\Line.cpp" /> <ClCompile Include="src\Renderer\Painting\Line.cpp" />
<ClCompile Include="src\Renderer\Mesh.cpp" /> <ClCompile Include="src\Renderer\Mesh.cpp" />
<ClCompile Include="src\Renderer\Model.cpp" /> <ClCompile Include="src\Renderer\Model.cpp" />
@ -179,6 +180,7 @@
<ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h" /> <ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h" />
<ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" /> <ClInclude Include="src\Renderer\Painting\CubicBezierSignedDistance.h" />
<ClInclude Include="src\Renderer\Painting\Element.h" /> <ClInclude Include="src\Renderer\Painting\Element.h" />
<ClInclude Include="src\Renderer\Painting\ElementStyle.h" />
<ClInclude Include="src\Renderer\Painting\LineTree.h" /> <ClInclude Include="src\Renderer\Painting\LineTree.h" />
<ClInclude Include="src\Renderer\Painting\Painting.h" /> <ClInclude Include="src\Renderer\Painting\Painting.h" />
<ClInclude Include="src\SvgParser.h" /> <ClInclude Include="src\SvgParser.h" />

View File

@ -181,6 +181,9 @@
<ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp"> <ClCompile Include="src\Editor\RightBar\InfoDisplayWidget.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Renderer\Painting\ElementStyle.cpp">
<Filter>Source Files\Renderer\Painting</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="src\Renderer\RendererGLWidget.h"> <QtMoc Include="src\Renderer\RendererGLWidget.h">
@ -371,6 +374,9 @@
<ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h"> <ClInclude Include="src\Editor\third-party modules\util\SvgFileLoader.h">
<Filter>Header Files\Editor\util</Filter> <Filter>Header Files\Editor\util</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Renderer\Painting\ElementStyle.h">
<Filter>Header Files\Renderer\Painting</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtRcc Include="MainWindow.qrc"> <QtRcc Include="MainWindow.qrc">

View File

@ -909,8 +909,8 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal
debugBVH.r += 1; debugBVH.r += 1;
} }
//uint styleIndex = bvhChildren[elementBvhRoot + elementBvhIndex].y; //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++) // for(int i = 0; i<200;i++)
if (elementType == 0) //Ãæ if (elementType == 0) //Ãæ
{ {

View File

@ -62,14 +62,20 @@ QMap<QString, QString> SvgFileLoader::transformStyle(QString style) {
return resStyleMap; return resStyleMap;
} }
QVector<QPointF> SvgFileLoader::transformPoints(QString points) { QPolygonF SvgFileLoader::transformPoints(QString points) {
QVector<QPointF> resPointVector; QPolygonF resPointVector;
QPointF pointBegin(0, 0); QPointF point(0, 0);
bool isX = true;
for (auto& onePoint : points.split(' ')) { for (auto& onePoint : points.split(' ')) {
QString x = *(onePoint.split(',').begin()); for (auto& value : onePoint.split(',')) {
QString y = *(onePoint.split(',').rbegin()); if (value.trimmed().isEmpty()) continue;
resPointVector.push_back(QPointF(x.toDouble(), y.toDouble())); if (isX) point.setX(value.toDouble());
else {
point.setY(value.toDouble());
resPointVector.push_back(point);
}
isX = !isX;
}
} }
return resPointVector; return resPointVector;
} }
@ -79,6 +85,9 @@ void SvgFileLoader::handleLabelG(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("style")) { if (attr.name().toString() == QLatin1String("style")) {
styleMap = transformStyle(attr.value().toLatin1()); styleMap = transformStyle(attr.value().toLatin1());
} }
else {
styleMap.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
existFatherLabelG = true; existFatherLabelG = true;
qDebug() << styleMap; qDebug() << styleMap;
@ -90,9 +99,12 @@ void SvgFileLoader::handleLabelPath(QPainterPath& painterPath) {
if (attr.name().toString() == QLatin1String("d")) { if (attr.name().toString() == QLatin1String("d")) {
QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath); QQuickSvgParser::parsePathDataFast(attr.value().toLatin1(), painterPath);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
} }
@ -102,20 +114,21 @@ void SvgFileLoader::handleLabelRect(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("x")) { if (attr.name().toString() == QLatin1String("x")) {
xBegin = attr.value().toDouble(); xBegin = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("y")) {
if (attr.name().toString() == QLatin1String("y")) {
yBegin = attr.value().toDouble(); yBegin = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("width")) {
if (attr.name().toString() == QLatin1String("width")) {
width = attr.value().toDouble(); width = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("height")) {
if (attr.name().toString() == QLatin1String("height")) {
height = attr.value().toDouble(); height = attr.value().toDouble();
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
qDebug() << labelStyle;
painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height); painterPath.addRect(xBegin, yBegin, xBegin + width, yBegin + height);
} }
@ -125,17 +138,19 @@ void SvgFileLoader::handleLabelCircle(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) { if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble(); cx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("cy")) {
if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble(); cy = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("r")) {
if (attr.name().toString() == QLatin1String("r")) {
r = attr.value().toDouble(); r = attr.value().toDouble();
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, r, r); painterPath.addEllipse(cx, cy, r, r);
} }
@ -145,20 +160,20 @@ void SvgFileLoader::handleLabelEllipse(QPainterPath& painterPath) {
for (auto& attr : xmlReader->attributes()) { for (auto& attr : xmlReader->attributes()) {
if (attr.name().toString() == QLatin1String("cx")) { if (attr.name().toString() == QLatin1String("cx")) {
cx = attr.value().toDouble(); cx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("cy")) {
if (attr.name().toString() == QLatin1String("cy")) {
cy = attr.value().toDouble(); cy = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("rx")) {
if (attr.name().toString() == QLatin1String("rx")) {
rx = attr.value().toDouble(); rx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("ry")) {
if (attr.name().toString() == QLatin1String("ry")) {
rx = attr.value().toDouble(); rx = attr.value().toDouble();
} } else if (attr.name().toString() == QLatin1String("style")) {
if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
qDebug() << labelStyle;
painterPath.addEllipse(cx, cy, rx, ry); painterPath.addEllipse(cx, cy, rx, ry);
} }
@ -169,10 +184,14 @@ void SvgFileLoader::handleLabelPolyline(QPainterPath& painterPath) {
QPolygonF points = transformPoints(attr.value().toLatin1()); QPolygonF points = transformPoints(attr.value().toLatin1());
painterPath.addPolygon(points); painterPath.addPolygon(points);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
qDebug() << labelStyle;
} }
void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) { void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
@ -183,8 +202,12 @@ void SvgFileLoader::handleLabelPolygon(QPainterPath & painterPath) {
points.push_back(*points.begin()); points.push_back(*points.begin());
painterPath.addPolygon(points); painterPath.addPolygon(points);
} }
if (attr.name().toString() == QLatin1String("style")) { else if (attr.name().toString() == QLatin1String("style")) {
labelStyle = transformStyle(attr.value().toLatin1()); labelStyle = transformStyle(attr.value().toLatin1());
} }
else {
labelStyle.insert(attr.name().toLatin1(), attr.value().toLatin1());
}
} }
qDebug() << labelStyle;
} }

View File

@ -13,7 +13,7 @@ private:
bool existFatherLabelG; bool existFatherLabelG;
QMap<QString, QString> styleMap; QMap<QString, QString> styleMap;
std::shared_ptr<QXmlStreamReader> xmlReader; std::shared_ptr<QXmlStreamReader> xmlReader;
QVector<QPointF> transformPoints(QString points); QPolygonF transformPoints(QString points);
QMap<QString, QString> transformStyle(QString style); QMap<QString, QString> transformStyle(QString style);
void handleLabelG(QPainterPath& painterPath); void handleLabelG(QPainterPath& painterPath);
void handleLabelPath(QPainterPath& painterPath); void handleLabelPath(QPainterPath& painterPath);

View File

@ -8,7 +8,9 @@
#include <QtMath> #include <QtMath>
#include "Painting/BvhTree.h" #include "Painting/BvhTree.h"
#include "Painting/ShortCutTree.h" #include "Painting/ShortCutTree.h"
#include "Painting/Painting.h"
#include "../SvgParser.h" #include "../SvgParser.h"
using namespace Renderer; using namespace Renderer;
using std::vector; using std::vector;
Model::Model(QString path, QOpenGLContext* context, QOpenGLShaderProgram* shaderProgram) 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]); m_mesh->indices.push_back(face.mIndices[j]);
} }
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
BvhTree rootBvhTree;
vector<BvhTreeData> 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());
m_mesh->paintingIndex = loadPainting(std::string(str.C_Str()));
//vector<vector<Point>> lineSet = SvgParser("M100,100C-.5,100,0,100.5,0,0L40,.07C40,59.5,39.5,60,100,60Z", 100, 100).parse();
//vector<vector<Point>> 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 <Point>> 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<vector<Point>> 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<Point>& line : lineSet)
{
for (Point& p : line)
p.show();
std::cout << std::endl;
}
ShortCutTree shortCutTree(20);
shortCutTree.buildShortCutTree(lineSet);
vector<GLfloat> pointVector;
vector<GLuint> lineVector;
vector<BvhTreeData> 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<GLuint> element0Children;
std::vector<QVector4D> element0Bounds;
element0Bvh.getBvhArray(element0Children, element0Bounds);
//qDebug() << element0Children;
//qDebug() << element0Bounds;
//std::vector<GLuint> 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<QVector4D> 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<GLuint> bvhChildren;
std::vector<QVector4D> 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<GLuint> elementIndex = lineVector;
std::vector<GLfloat> elementData = {
//fillStyle
//fill
0,
//fillType
0, //单色
//fillColorMetallicRoughness
240/255.,220/255.,160/255., 0.996,0.18,
};
std::vector<GLuint> 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<GLuint> 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<QVector4D> 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<GLuint> 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<GLuint> 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<GLfloat> 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<GLuint>(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->setupMesh(); m_mesh->setupMesh();
return m_mesh; return m_mesh;
} }
@ -537,7 +290,7 @@ QVector<Texture*> Model::loadMaterialTextures(aiMaterial* mat, aiTextureType typ
if (std::strcmp(textures_loaded[j]->path.toStdString().c_str(), str.C_Str()) == 0) if (std::strcmp(textures_loaded[j]->path.toStdString().c_str(), str.C_Str()) == 0)
{ {
textures.push_back(textures_loaded[j]); textures.push_back(textures_loaded[j]);
skip = true; //【优化】 带有相同filepath的纹理已经加载继续到下一个 skip = true;
break; break;
} }
} }
@ -559,3 +312,226 @@ QVector<Texture*> Model::loadMaterialTextures(aiMaterial* mat, aiTextureType typ
} }
return textures; return textures;
} }
GLuint Renderer::Model::loadPainting(std::string path)
{
auto iter = paintingLoaded.find(path);
if (iter != paintingLoaded.end())
return iter->second;
//vector < vector <Point>> 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<std::shared_ptr<Contour>> contour = {
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()),
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()),
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())
};
vector<std::shared_ptr<ElementStyle>> style = {
std::make_shared<ElementStyle>(std::vector<GLfloat>{
//strokeStyle
//stroke
1,
//strokeWidth
0.01,
//strokeEndType
0, //圆角
//strokeFillType
0, //单色
//线类型
2, //双侧
//线外描边宽度
0,
//线外描边方式
0, //单色
//strokeFillColorMetallicRoughness
1,0,1, 0,0.8,
}),
std::make_shared<ElementStyle>(std::vector<GLfloat>{
//fillStyle
//fill
0,
//fillType
0, //单色
//fillColorMetallicRoughness
240 / 255., 220 / 255., 160 / 255., 0.996, 0.18,
}),
std::make_shared<ElementStyle>(std::vector<GLfloat>{
//fillStyle
//fill
0,
//fillType
0, //单色
//fillColorMetallicRoughness
24 / 255., 220 / 255., 16 / 255., 0., 0.18,
}),
};
vector<std::shared_ptr<Element>> element = {
std::make_shared<Element>(Element{ contour[0], style[1]}),
std::make_shared<Element>(Element{ contour[1], style[2]}),
std::make_shared<Element>(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<GLuint> 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<QVector4D> 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<GLuint> 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<GLuint> 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<GLfloat> 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<GLuint>(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;
}

View File

@ -29,6 +29,7 @@ namespace Renderer
PaintingHelper* paintingHelper = nullptr; PaintingHelper* paintingHelper = nullptr;
/* 模型数据 */ /* 模型数据 */
std::unordered_map<std::string, GLuint> paintingLoaded;
QVector<Texture*> textures_loaded; //纹理 QVector<Texture*> textures_loaded; //纹理
QVector<Drawable*> meshes; //网格 QVector<Drawable*> meshes; //网格
QDir directory; //模型所在路径 QDir directory; //模型所在路径
@ -49,5 +50,6 @@ namespace Renderer
//加载材质纹理 //加载材质纹理
QVector<Texture*> loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName); QVector<Texture*> loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName);
GLuint loadPainting(std::string path);
}; };
} }

View File

@ -0,0 +1,18 @@
#include "ElementStyle.h"
using namespace Renderer;
ElementStyle::ElementStyle(std::vector<GLfloat> style)
:style(style)
{
}
bool Renderer::ElementStyle::isLine()
{
return style[0];
}
std::vector<GLfloat> ElementStyle::encoded()
{
return style;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <vector>
#include <QOpenGLFunctions_4_5_Compatibility>
namespace Renderer
{
class ElementStyle
{
public:
ElementStyle(std::vector<GLfloat> style);
bool isLine();
std::vector<GLfloat> encoded();
private:
std::vector<GLfloat> style;
};
}

View File

@ -45,8 +45,8 @@ namespace Renderer {
public: public:
void init(); void init();
void setLineWidth(double width); void setLineWidth(double width);
LineTree(int lineMin = 3, double width = 0.3, int type = 0) LineTree(int lineMin = 3)
: requiredLineMin(lineMin), lineWidth(width), lineType(type), numLine(0), numPoint(0) {} : requiredLineMin(lineMin), numLine(0), numPoint(0) {}
void buildLineTree(std::vector<PointVector>& lineSet, double width, int type = 0); void buildLineTree(std::vector<PointVector>& lineSet, double width, int type = 0);
std::vector<BvhTreeData> getPointLineAndBvhTree(std::vector<float>& pointSet, std::vector<GLuint>& lineSet); std::vector<BvhTreeData> getPointLineAndBvhTree(std::vector<float>& pointSet, std::vector<GLuint>& lineSet);
}; };

View File

@ -1,35 +1,63 @@
#include "Painting.h" #include "Painting.h"
#include "../../SvgParser.h" #include "../../SvgParser.h"
#include "ShortCutTree.h" #include "ShortCutTree.h"
#include "LineTree.h"
#include <QDebug>
using namespace Renderer; using namespace Renderer;
constexpr int maxLineCount = 20;
Painting::Painting() 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<Contour> contourPtr = std::make_shared<Contour>(contour);
contourPool.insert({ contourPtr, {nullptr, nullptr} });
void Renderer::Painting::addElement(ElementWithTransform elementWithTransform)
std::vector<GLfloat> style = { {
//fillStyle auto it = elementPool.find(elementWithTransform.element);
//fill if (it == elementPool.end())
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)
{ {
ShortCutTree shortCutTree(20); auto element = elementWithTransform.element;
shortCutTree.buildShortCutTree(*contourPtr); auto iter = contourPool.insert({ element->contour, {nullptr, nullptr} }).first;
ElementBuffer elementBuffer;
elementBuffer.bvhLeaves = shortCutTree.getPointLineAndBvhTree(elementBuffer.pointBuffer, elementBuffer.lineBuffer); if (!element->style->isLine() && iter->second.first == nullptr)
contourPool[contourPtr].first = std::make_shared<ElementBuffer>(elementBuffer); {
qDebug() << "Build ShortCutTree---------------------------------------------------------------------------------------------------";
ShortCutTree shortCutTree(maxLineCount);
shortCutTree.buildShortCutTree(*element->contour);
ContourBuffer elementBuffer;
std::vector<BvhTreeData> 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<ContourBuffer>(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<BvhTreeData> 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<ContourBuffer>(elementBuffer);
qDebug() << "---------------------------------------------------------------------------------------------------------------------";
}
stylePool.insert({ element->style, 0 });
elementPool.insert({ element, 0});
} }
elements.push_back(elementWithTransform);
}
void Renderer::Painting::addElement(std::shared_ptr<Element> element, QVector4D bound, float rotation, int zIndex)
{
addElement(ElementWithTransform{ element, bound, rotation, zIndex });
} }
GLuint encodeZIndexRotation(GLuint zIndex, float rotation) GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
@ -37,28 +65,77 @@ GLuint encodeZIndexRotation(GLuint zIndex, float rotation)
return GLuint(rotation / 360 * 0x10000 + zIndex * 0x10000); return GLuint(rotation / 360 * 0x10000 + zIndex * 0x10000);
} }
//void Painting::addElement(Contour contour, std::vector<GLfloat> style, QVector4D bound, float rotation, int zIndex)
//{
// BvhTreeData(bound, 0, encodeZIndexRotation(zIndex, rotation));
//
// std::shared_ptr<Element> element = nullptr;
// auto iterator = elementMap.find(lines);
// if (iterator != elementMap.end())
// element = iterator->second;
// else
// {
// element = std::make_shared<Element>(lines);
// elementMap.insert({ lines, element });
// }
//
//}
void Painting::generateBuffers() void Painting::generateBuffers()
{ {
//std::unordered_map < std::shared_ptr<Contour>, int> qDebug() << elementPool.size();
for (auto& iter : contourPool) qDebug() << contourPool.size();
{ qDebug() << stylePool.size();
elementData.insert(elementData.end(), iter.second.first->pointBuffer.begin(), iter.second.first->pointBuffer.end());
bvhChildren.clear();
bvhBounds.clear();
elementOffset.clear();
elementIndex.clear();
elementData.clear();
int index = 0;
for (auto& i : elementPool)
{
i.second = index++;
}
std::vector<BvhTreeData> 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<GLuint> rootBvhChildren;
std::vector<QVector4D> 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<GLfloat> encodedStyle = i.first->encoded();
elementData.insert(elementData.end(), encodedStyle.begin(), encodedStyle.end());
}
for (auto& i : elementPool)
{
//qDebug() <<"element:" << i.second;
std::shared_ptr<ContourBuffer> 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<ContourBuffer> 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());
}

View File

@ -3,6 +3,8 @@
#include <QOpenGLFunctions_4_5_Compatibility> #include <QOpenGLFunctions_4_5_Compatibility>
#include "Line.h" #include "Line.h"
#include "BvhTree.h" #include "BvhTree.h"
#include "ElementStyle.h"
#include <glm/glm.hpp>
//#include "Element.h" //#include "Element.h"
namespace Renderer namespace Renderer
@ -12,38 +14,50 @@ namespace Renderer
struct Element struct Element
{ {
std::shared_ptr<Contour> contour; std::shared_ptr<Contour> contour;
std::vector<GLfloat> style; std::shared_ptr<ElementStyle> style;
};
struct ElementWithTransform
{
std::shared_ptr<Element> element;
QVector4D bound; QVector4D bound;
float rotation; float rotation;
int zIndex; int zIndex;
}; };
struct ElementBuffer struct ContourBuffer
{ {
std::vector<GLfloat> pointBuffer; std::vector<GLfloat> pointBuffer;
std::vector<GLuint> lineBuffer; std::vector<GLuint> lineBuffer;
std::vector<BvhTreeData> bvhLeaves; std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBounds;
//std::vector<BvhTreeData> bvhLeaves;
GLuint pointsOffset;
GLuint linesOffset;
GLuint bvhOffset;
}; };
class Painting class Painting
{ {
public: public:
std::vector<GLuint> bvhChildren; std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound; std::vector<QVector4D> bvhBounds;
std::vector<GLuint> elementOffset; std::vector<glm::uvec4> elementOffset;
std::vector<GLuint> elementIndex; std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData; std::vector<GLfloat> elementData;
int paintingId = 0; int paintingId = 0;
Painting(); Painting();
//void addElement(Contour contour, std::vector<GLfloat> style, QVector4D bound, float rotation, int zIndex); void addElement(ElementWithTransform element);
void addElement(std::shared_ptr<Element> element, QVector4D bound, float rotation, int zIndex);
void generateBuffers(); void generateBuffers();
GLuint getElementCount();
private: private:
std::vector<BvhTreeData> bvhLeaves; std::unordered_map<std::shared_ptr<Contour>, std::pair<std::shared_ptr<ContourBuffer>/*Ãæ*/, std::shared_ptr<ContourBuffer>/*Ïß*/>> contourPool;
std::unordered_map< std::shared_ptr<Contour>, std::pair<std::shared_ptr<ElementBuffer>, std::shared_ptr<ElementBuffer>>> contourPool; std::unordered_map<std::shared_ptr<ElementStyle>, GLuint> stylePool;
//std::vector<std::shared_ptr<Contour>> contourPool; std::map<std::shared_ptr<Element>, GLuint> elementPool;
std::vector<Element> elements; std::vector<ElementWithTransform> elements;
//std::unordered_map<std::vector<std::vector<Point>>, std::shared_ptr<Element>> elementMap; void insertContourBuffer(std::shared_ptr<ContourBuffer> buffer);
}; };
} }

View File

@ -6,10 +6,15 @@ PaintingHelper::PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc) :glFu
} }
int PaintingHelper::addPainting(GLuint paintingBvhLength, std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound, std::vector<GLuint> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData) int Renderer::PaintingHelper::addPainting(Painting painting)
{
return addPainting(painting.bvhChildren, painting.bvhBounds, painting.elementOffset, painting.elementIndex, painting.elementData);
}
int PaintingHelper::addPainting(std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound, std::vector<glm::uvec4> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData)
{ {
this->paintingOffsets.push_back(0);//paintingBvhRoot 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->bvhChildren.insert(this->bvhChildren.end(), bvhChildren.begin(), bvhChildren.end());
this->bvhBound.insert(this->bvhBound.end(), bvhBound.begin(), bvhBound.end()); this->bvhBound.insert(this->bvhBound.end(), bvhBound.begin(), bvhBound.end());
@ -40,7 +45,7 @@ void PaintingHelper::allocateBuffers()
glFunc->glGenBuffers(1, &elementOffsetSSBO); glFunc->glGenBuffers(1, &elementOffsetSSBO);
glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 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); glFunc->glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);

View File

@ -5,6 +5,7 @@
#include <QVector4D> #include <QVector4D>
#include <QOpenGLFunctions_4_5_Compatibility> #include <QOpenGLFunctions_4_5_Compatibility>
#include "BvhTree.h" #include "BvhTree.h"
#include "Painting.h"
namespace Renderer namespace Renderer
{ {
class PaintingHelper class PaintingHelper
@ -15,15 +16,16 @@ namespace Renderer
std::vector<GLuint> paintingOffsets; std::vector<GLuint> paintingOffsets;
std::vector<GLuint> bvhChildren; std::vector<GLuint> bvhChildren;
std::vector<QVector4D> bvhBound; std::vector<QVector4D> bvhBound;
std::vector<GLuint> elementOffset; std::vector<glm::uvec4> elementOffset;
std::vector<GLuint> elementIndex; std::vector<GLuint> elementIndex;
std::vector<GLfloat> elementData; std::vector<GLfloat> elementData;
int paintingCount = 0; int paintingCount = 0;
public: public:
PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc); PaintingHelper(QOpenGLFunctions_4_5_Compatibility* glFunc);
int addPainting(GLuint paintingBvhLength, std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound, int addPainting(Painting painting);
std::vector<GLuint> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData); int addPainting(std::vector<GLuint> bvhChildren, std::vector<QVector4D> bvhBound,
std::vector<glm::uvec4> elementOffset, std::vector<GLuint> elementIndex, std::vector<GLfloat> elementData);
void allocateBuffers(); void allocateBuffers();
void bindPaintingBuffers(); void bindPaintingBuffers();
}; };

View File

@ -10,7 +10,7 @@ extern "C"
_declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; _declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
} }
int main(int argc, char *argv[]) int main(int argc, char* argv[])
{ {
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);

View File

@ -13,8 +13,19 @@
## 进度 ## 进度
### 纹理编辑Editor
完成layer信息展示和数据修改部分
### 场景渲染Renderer
采用 PBR (金属度-粗糙度) 材质模型,场景中存在一个方向光,可拖动滑动条调整光源方向观察材质效果。 采用 PBR (金属度-粗糙度) 材质模型,场景中存在一个方向光,可拖动滑动条调整光源方向观察材质效果。
已实现BVH加速结构的建立 已实现BVH加速结构的建立
已实现单图元的拆分,即划分网格并生成快捷段和缠绕增量 已实现单图元的拆分,即划分网格并生成快捷段和缠绕增量
已实现由图元数据建立完整彩绘编码
待完善线的单侧描边