实现从图元及其变换信息建立完整Painting编码
parent
1f6998d05b
commit
18429b6867
|
@ -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" />
|
||||||
|
@ -61,13 +61,13 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);$(Qt_INCLUDEPATH_)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);$(Qt_INCLUDEPATH_)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(SolutionDir)QGoodWindow;%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
|
@ -118,6 +118,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" />
|
||||||
|
@ -175,6 +176,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" />
|
||||||
|
|
|
@ -174,6 +174,9 @@
|
||||||
<ClCompile Include="src\Editor\third-party modules\SvgHelper.cpp">
|
<ClCompile Include="src\Editor\third-party modules\SvgHelper.cpp">
|
||||||
<Filter>Source Files\Editor\third-party modules</Filter>
|
<Filter>Source Files\Editor\third-party modules</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">
|
||||||
|
@ -354,6 +357,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">
|
||||||
|
|
|
@ -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) //Ãæ
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,34 +178,147 @@ 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;
|
m_mesh->paintingIndex = loadPainting(std::string(str.C_Str()));
|
||||||
vector<BvhTreeData> rootBvhTreeData;
|
m_mesh->setupMesh();
|
||||||
for (int i = 0; i < 1000; i++)
|
return m_mesh;
|
||||||
{
|
|
||||||
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)));
|
else
|
||||||
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)));*/
|
Mesh* m_mesh = new Mesh(glFunc, shaderProgram, shadowProgram, model);
|
||||||
//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));
|
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
||||||
/* initBound.push_back(QVector4D(-0.8, -0.8, -0.7, -0.7));
|
{
|
||||||
initBound.push_back(QVector4D(-0.8, 0.7, -0.7, 0.8));
|
Vertex vertex;
|
||||||
initBound.push_back(QVector4D(0.7, -0.8, 0.8, -0.7));
|
QVector3D vector; //将assimp的数据转化为QtOpenGL支持的数据
|
||||||
initBound.push_back(QVector4D(0.7, 0.7, 0.8, 0.8));*/
|
|
||||||
rootBvhTree.buildBvhTree(rootBvhTreeData.data(), rootBvhTreeData.size());
|
// 位置
|
||||||
|
vector.setX(mesh->mVertices[i].x);
|
||||||
|
vector.setY(mesh->mVertices[i].y);
|
||||||
|
vector.setZ(mesh->mVertices[i].z);
|
||||||
|
vertex.Position = vector;
|
||||||
|
minX = std::min(minX, vertex.Position.x());
|
||||||
|
maxX = std::max(maxX, vertex.Position.x());
|
||||||
|
minY = std::min(minY, vertex.Position.y());
|
||||||
|
maxY = std::max(maxY, vertex.Position.y());
|
||||||
|
minZ = std::min(minZ, vertex.Position.z());
|
||||||
|
maxZ = std::max(maxZ, vertex.Position.z());
|
||||||
|
|
||||||
|
|
||||||
|
// 法向量
|
||||||
|
if (mesh->mNormals) {
|
||||||
|
vector.setX(mesh->mNormals[i].x);
|
||||||
|
vector.setY(mesh->mNormals[i].y);
|
||||||
|
vector.setZ(mesh->mNormals[i].z);
|
||||||
|
vertex.Normal = vector;
|
||||||
|
}
|
||||||
|
// 纹理坐标
|
||||||
|
if (mesh->mTextureCoords[0]) // does the mesh contain texture coordinates?
|
||||||
|
{
|
||||||
|
QVector2D vec;
|
||||||
|
//一个顶点最多可以包含8个不同的纹理坐标。因此我们假设我们不用
|
||||||
|
//使用一个顶点可以有多个纹理坐标的模型,所以我们总是取第一个集合(0)。
|
||||||
|
vec.setX(mesh->mTextureCoords[0][i].x);
|
||||||
|
vec.setY(mesh->mTextureCoords[0][i].y);
|
||||||
|
vertex.TexCoords = vec;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vertex.TexCoords = QVector2D(0, 0);
|
||||||
|
}
|
||||||
|
if (mesh->mTangents) {
|
||||||
|
// tangent
|
||||||
|
vector.setX(mesh->mTangents[i].x);
|
||||||
|
vector.setY(mesh->mTangents[i].y);
|
||||||
|
vector.setZ(mesh->mTangents[i].z);
|
||||||
|
vertex.Tangent = vector;
|
||||||
|
}
|
||||||
|
if (mesh->mBitangents) {
|
||||||
|
vector.setX(mesh->mBitangents[i].x);
|
||||||
|
vector.setY(mesh->mBitangents[i].y);
|
||||||
|
vector.setZ(mesh->mBitangents[i].z);
|
||||||
|
vertex.Bitangent = vector;
|
||||||
|
}
|
||||||
|
// bitangent
|
||||||
|
m_mesh->vertices.push_back(vertex);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
|
||||||
|
{
|
||||||
|
aiFace face = mesh->mFaces[i];
|
||||||
|
// 将所有面的索引数据添加到索引数组中
|
||||||
|
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||||
|
m_mesh->indices.push_back(face.mIndices[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理材质
|
||||||
|
QVector<Texture*> diffuseMaps = loadMaterialTextures(material, aiTextureType_BASE_COLOR, "texture_basecolor");
|
||||||
|
for (auto& it : diffuseMaps)
|
||||||
|
m_mesh->textures.push_back(it);
|
||||||
|
|
||||||
|
QVector<Texture*> metalnessMaps = loadMaterialTextures(material, aiTextureType_METALNESS, "texture_metallic_roughness");
|
||||||
|
for (auto& it : metalnessMaps)
|
||||||
|
m_mesh->textures.push_back(it);
|
||||||
|
|
||||||
|
QVector<Texture*> normalMaps = loadMaterialTextures(material, aiTextureType_NORMALS, "texture_normal");
|
||||||
|
for (auto& it : normalMaps)
|
||||||
|
m_mesh->textures.push_back(it);
|
||||||
|
|
||||||
|
m_mesh->setupMesh();
|
||||||
|
return m_mesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<Texture*> Model::loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName)
|
||||||
|
{
|
||||||
|
|
||||||
|
QVector<Texture*> textures;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
||||||
|
{
|
||||||
|
//qDebug() << typeName;
|
||||||
|
aiString str;
|
||||||
|
mat->GetTexture(type, i, &str);
|
||||||
|
|
||||||
|
// 检查纹理是否在之前加载过,如果是,则继续到下一个迭代:跳过加载新纹理
|
||||||
|
bool skip = false;
|
||||||
|
for (unsigned int j = 0; j < textures_loaded.size(); j++)
|
||||||
|
{
|
||||||
|
if (std::strcmp(textures_loaded[j]->path.toStdString().c_str(), str.C_Str()) == 0)
|
||||||
|
{
|
||||||
|
textures.push_back(textures_loaded[j]);
|
||||||
|
skip = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!skip)
|
||||||
|
{ // 如果材质还没有加载,加载它
|
||||||
|
Texture* texture = new Texture;
|
||||||
|
QImage data(directory.filePath(str.C_Str()));
|
||||||
|
if (!data.isNull()) {
|
||||||
|
texture->texture.setData(data);
|
||||||
|
texture->type = typeName;
|
||||||
|
texture->path = str.C_Str();
|
||||||
|
textures.push_back(texture);
|
||||||
|
textures_loaded.push_back(texture); // store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures.
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "未能成功加载纹理:" << directory.filePath(str.C_Str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 = 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 = {
|
//vector < vector <Point>> lineSet = {
|
||||||
// {{-0.5,0.9}, {0.1,0.3}},
|
// {{-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.1,0.3}, {0.0204656,0.379534}, {-0.2,0.0632573}, {-0.2,0.175736}},
|
||||||
|
@ -211,81 +326,71 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
// {{-0.5,0.3}, {-0.420466,0.379534}, {-0.736743,0.6}, {-0.624264,0.6}},
|
// {{-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}}
|
// {{-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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
vector<std::shared_ptr<Contour>> contour = {
|
||||||
ShortCutTree shortCutTree(20);
|
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()),
|
||||||
shortCutTree.buildShortCutTree(lineSet);
|
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()),
|
||||||
vector<GLfloat> pointVector;
|
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<GLuint> lineVector;
|
};
|
||||||
vector<BvhTreeData> bvhTreeData = shortCutTree.getPointLineAndBvhTree(pointVector, lineVector);
|
vector<std::shared_ptr<ElementStyle>> style = {
|
||||||
for (auto& data : bvhTreeData)
|
std::make_shared<ElementStyle>(std::vector<GLfloat>{
|
||||||
data.rightSon = 0;
|
//strokeStyle
|
||||||
qDebug() << "----------------------------------------------";
|
//stroke
|
||||||
qDebug() << "element0CellNum: " << bvhTreeData.size();
|
1,
|
||||||
//qDebug() << pointVector;
|
//strokeWidth
|
||||||
//qDebug() << lineVector;
|
0.01,
|
||||||
/*for (BvhTreeData data : bvhTreeData)
|
//strokeEndType
|
||||||
{
|
0, //圆角
|
||||||
data.show();
|
//strokeFillType
|
||||||
}*/
|
0, //单色
|
||||||
BvhTree element0Bvh;
|
//线类型
|
||||||
element0Bvh.buildBvhTree(bvhTreeData.data(), bvhTreeData.size());
|
2, //双侧
|
||||||
std::vector<GLuint> element0Children;
|
//线外描边宽度
|
||||||
std::vector<QVector4D> element0Bounds;
|
0,
|
||||||
element0Bvh.getBvhArray(element0Children, element0Bounds);
|
//线外描边方式
|
||||||
//qDebug() << element0Children;
|
0, //单色
|
||||||
//qDebug() << element0Bounds;
|
//strokeFillColorMetallicRoughness
|
||||||
|
1,0,1, 0,0.8,
|
||||||
//std::vector<GLuint> bvhChildren = {
|
}),
|
||||||
// //root
|
std::make_shared<ElementStyle>(std::vector<GLfloat>{
|
||||||
// 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
|
//fillStyle
|
||||||
//fill
|
//fill
|
||||||
0,
|
0,
|
||||||
//fillType
|
//fillType
|
||||||
0, //µ¥É«
|
0, //µ¥É«
|
||||||
//fillColorMetallicRoughness
|
//fillColorMetallicRoughness
|
||||||
240/255.,220/255.,160/255., 0.996,0.18,
|
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,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
std::vector<GLuint> elementOffset = {
|
vector<std::shared_ptr<Element>> element = {
|
||||||
//element0
|
std::make_shared<Element>(Element{ contour[0], style[1]}),
|
||||||
rootBvhTree.getBvhNodeNum(), //elementBvhRoot
|
std::make_shared<Element>(Element{ contour[1], style[2]}),
|
||||||
0, //styleOffset
|
std::make_shared<Element>(Element{ contour[2], style[0]}),
|
||||||
(GLuint)elementData.size(), //pointsOffset
|
|
||||||
0, //linesOffset
|
|
||||||
};
|
};
|
||||||
elementData.insert(elementData.end(), pointVector.begin(), pointVector.end());
|
Painting painting;
|
||||||
//qDebug() << elementIndex;
|
//for (int i = 0; i < 3; i++)
|
||||||
//qDebug() << elementData;
|
//{
|
||||||
|
// 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 = {
|
std::vector<GLuint> bvhChildren0 = {
|
||||||
//root
|
//root
|
||||||
|
@ -421,141 +526,12 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod
|
||||||
1,0,1, 0,0.8,
|
1,0,1, 0,0.8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector<GLuint>(children.begin()+2, children.end()), bounds,
|
//m_mesh->paintingIndex = paintingHelper->addPainting(bounds.size(), std::vector<GLuint>(children.begin()+2, children.end()), bounds,
|
||||||
// elementOffset, elementIndex, elementData);
|
// elementOffset, elementIndex, elementData);
|
||||||
/* m_mesh->paintingIndex = paintingHelper->addPainting(rootBvhTree.getBvhNodeNum(), bvhChildren, bvhBounds,
|
/*m_mesh->paintingIndex = paintingHelper->addPainting(bvhChildren0, bvhBounds0,
|
||||||
elementOffset, elementIndex, elementData);*/
|
elementOffset0, elementIndex0, elementData0);*/
|
||||||
m_mesh->paintingIndex = paintingHelper->addPainting(7, bvhChildren0, bvhBounds0,
|
GLuint index = paintingHelper->addPainting(painting);
|
||||||
elementOffset0, elementIndex0, elementData0);
|
paintingLoaded.insert({ path, index });
|
||||||
m_mesh->setupMesh();
|
return index;
|
||||||
return m_mesh;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 初始化网格
|
|
||||||
Mesh* m_mesh = new Mesh(glFunc, shaderProgram, shadowProgram, model);
|
|
||||||
// 遍历网格的每个顶点
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
|
|
||||||
{
|
|
||||||
Vertex vertex;
|
|
||||||
QVector3D vector; //将assimp的数据转化为QtOpenGL支持的数据
|
|
||||||
|
|
||||||
// 位置
|
|
||||||
vector.setX(mesh->mVertices[i].x);
|
|
||||||
vector.setY(mesh->mVertices[i].y);
|
|
||||||
vector.setZ(mesh->mVertices[i].z);
|
|
||||||
vertex.Position = vector;
|
|
||||||
minX = std::min(minX, vertex.Position.x());
|
|
||||||
maxX = std::max(maxX, vertex.Position.x());
|
|
||||||
minY = std::min(minY, vertex.Position.y());
|
|
||||||
maxY = std::max(maxY, vertex.Position.y());
|
|
||||||
minZ = std::min(minZ, vertex.Position.z());
|
|
||||||
maxZ = std::max(maxZ, vertex.Position.z());
|
|
||||||
|
|
||||||
|
|
||||||
// 法向量
|
|
||||||
if (mesh->mNormals) {
|
|
||||||
vector.setX(mesh->mNormals[i].x);
|
|
||||||
vector.setY(mesh->mNormals[i].y);
|
|
||||||
vector.setZ(mesh->mNormals[i].z);
|
|
||||||
vertex.Normal = vector;
|
|
||||||
}
|
|
||||||
// 纹理坐标
|
|
||||||
if (mesh->mTextureCoords[0]) // does the mesh contain texture coordinates?
|
|
||||||
{
|
|
||||||
QVector2D vec;
|
|
||||||
//一个顶点最多可以包含8个不同的纹理坐标。因此我们假设我们不用
|
|
||||||
//使用一个顶点可以有多个纹理坐标的模型,所以我们总是取第一个集合(0)。
|
|
||||||
vec.setX(mesh->mTextureCoords[0][i].x);
|
|
||||||
vec.setY(mesh->mTextureCoords[0][i].y);
|
|
||||||
vertex.TexCoords = vec;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vertex.TexCoords = QVector2D(0, 0);
|
|
||||||
}
|
|
||||||
if (mesh->mTangents) {
|
|
||||||
// tangent
|
|
||||||
vector.setX(mesh->mTangents[i].x);
|
|
||||||
vector.setY(mesh->mTangents[i].y);
|
|
||||||
vector.setZ(mesh->mTangents[i].z);
|
|
||||||
vertex.Tangent = vector;
|
|
||||||
}
|
|
||||||
if (mesh->mBitangents) {
|
|
||||||
vector.setX(mesh->mBitangents[i].x);
|
|
||||||
vector.setY(mesh->mBitangents[i].y);
|
|
||||||
vector.setZ(mesh->mBitangents[i].z);
|
|
||||||
vertex.Bitangent = vector;
|
|
||||||
}
|
|
||||||
// bitangent
|
|
||||||
m_mesh->vertices.push_back(vertex);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < mesh->mNumFaces; i++)
|
|
||||||
{
|
|
||||||
aiFace face = mesh->mFaces[i];
|
|
||||||
// 将所有面的索引数据添加到索引数组中
|
|
||||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
|
||||||
m_mesh->indices.push_back(face.mIndices[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理材质
|
|
||||||
QVector<Texture*> diffuseMaps = loadMaterialTextures(material, aiTextureType_BASE_COLOR, "texture_basecolor");
|
|
||||||
for (auto& it : diffuseMaps)
|
|
||||||
m_mesh->textures.push_back(it);
|
|
||||||
|
|
||||||
QVector<Texture*> metalnessMaps = loadMaterialTextures(material, aiTextureType_METALNESS, "texture_metallic_roughness");
|
|
||||||
for (auto& it : metalnessMaps)
|
|
||||||
m_mesh->textures.push_back(it);
|
|
||||||
|
|
||||||
QVector<Texture*> normalMaps = loadMaterialTextures(material, aiTextureType_NORMALS, "texture_normal");
|
|
||||||
for (auto& it : normalMaps)
|
|
||||||
m_mesh->textures.push_back(it);
|
|
||||||
|
|
||||||
m_mesh->setupMesh();
|
|
||||||
return m_mesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QVector<Texture*> Model::loadMaterialTextures(aiMaterial* mat, aiTextureType type, QString typeName)
|
|
||||||
{
|
|
||||||
|
|
||||||
QVector<Texture*> textures;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
|
||||||
{
|
|
||||||
//qDebug() << typeName;
|
|
||||||
aiString str;
|
|
||||||
mat->GetTexture(type, i, &str);
|
|
||||||
|
|
||||||
// 检查纹理是否在之前加载过,如果是,则继续到下一个迭代:跳过加载新纹理
|
|
||||||
bool skip = false;
|
|
||||||
for (unsigned int j = 0; j < textures_loaded.size(); j++)
|
|
||||||
{
|
|
||||||
if (std::strcmp(textures_loaded[j]->path.toStdString().c_str(), str.C_Str()) == 0)
|
|
||||||
{
|
|
||||||
textures.push_back(textures_loaded[j]);
|
|
||||||
skip = true; //【优化】 带有相同filepath的纹理已经加载,继续到下一个
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!skip)
|
|
||||||
{ // 如果材质还没有加载,加载它
|
|
||||||
Texture* texture = new Texture;
|
|
||||||
QImage data(directory.filePath(str.C_Str()));
|
|
||||||
if (!data.isNull()) {
|
|
||||||
texture->texture.setData(data);
|
|
||||||
texture->type = typeName;
|
|
||||||
texture->path = str.C_Str();
|
|
||||||
textures.push_back(texture);
|
|
||||||
textures_loaded.push_back(texture); // store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures.
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug() << "未能成功加载纹理:" << directory.filePath(str.C_Str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return textures;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
||||||
|
}
|
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
};
|
};
|
||||||
|
|
11
README.md
11
README.md
|
@ -13,8 +13,19 @@
|
||||||
|
|
||||||
## 进度
|
## 进度
|
||||||
|
|
||||||
|
### 纹理编辑(Editor)
|
||||||
|
|
||||||
|
完成layer信息展示和数据修改(部分)
|
||||||
|
|
||||||
|
### 场景渲染(Renderer)
|
||||||
|
|
||||||
采用 PBR (金属度-粗糙度) 材质模型,场景中存在一个方向光,可拖动滑动条调整光源方向观察材质效果。
|
采用 PBR (金属度-粗糙度) 材质模型,场景中存在一个方向光,可拖动滑动条调整光源方向观察材质效果。
|
||||||
|
|
||||||
已实现BVH加速结构的建立
|
已实现BVH加速结构的建立
|
||||||
|
|
||||||
已实现单图元的拆分,即划分网格并生成快捷段和缠绕增量
|
已实现单图元的拆分,即划分网格并生成快捷段和缠绕增量
|
||||||
|
|
||||||
|
已实现由图元数据建立完整彩绘编码
|
||||||
|
|
||||||
|
待完善线的单侧描边
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue