yang.yongquan 2023-03-11 19:52:39 +08:00
commit 631f0f8af7
19 changed files with 158 additions and 103 deletions

View File

@ -18,7 +18,7 @@ LayerStyleDialog::LayerStyleDialog(
if (existedStyle) if (existedStyle)
{ {
this->modifyingStyle = std::make_unique<LayerStyle>(existedStyle->clonePtr()); this->modifyingStyle = existedStyle->clonePtr();
this->styleContainer = nullptr; this->styleContainer = nullptr;
this->styleWidget = modifyingStyle->getInputWidget(); this->styleWidget = modifyingStyle->getInputWidget();

View File

@ -45,4 +45,26 @@ QJsonObject ElementManager::toJson() const
QJsonObject result; QJsonObject result;
result.insert("elements", elementsJson); result.insert("elements", elementsJson);
return result; return result;
}
int ElementManager::getElementIndex(GraphicElement* pelement)
{
for (int i = 0; i < elements.size(); i++)
if (elements[i] == pelement)
return i;
return -1;
}
int ElementManager::getLayerReferencedBy(const FolderLayerWrapper* layer)
{
for (int i = 0; i < elements.size(); i++)
if (typeid(*elements[i]) == typeid(GroupElement)) {
qDebug() << ((GroupElement*)elements[i])->sourceLayer;
qDebug() << layer;
qDebug() << "------------";
if (((GroupElement*)elements[i])->sourceLayer == layer)
return i;
}
return -1;
} }

View File

@ -8,6 +8,7 @@ using std::vector;
class LayerManager; class LayerManager;
class GraphicElement; class GraphicElement;
class Renderer::ElementRenderer; class Renderer::ElementRenderer;
class FolderLayerWrapper;
class ElementManager class ElementManager
{ {
@ -24,4 +25,6 @@ class ElementManager
* only used in initialization * only used in initialization
*/ */
GraphicElement *getElementById(int index); GraphicElement *getElementById(int index);
int getElementIndex(GraphicElement* pElement);
int getLayerReferencedBy(const FolderLayerWrapper* layer);
}; };

View File

@ -54,9 +54,9 @@ StrokeElementLayerStyle::StrokeElementLayerStyle(const StrokeElementLayerStyle&
} }
} }
std::shared_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const std::unique_ptr<LayerStyle> StrokeElementLayerStyle::clonePtr() const
{ {
return std::make_shared<LayerStyle>(StrokeElementLayerStyle(*this)); return std::make_unique<StrokeElementLayerStyle>(StrokeElementLayerStyle(*this));
} }
std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const std::vector<Renderer::BaseStyle> FillElementLayerStyle::toBaseStyles() const
@ -97,7 +97,7 @@ FillElementLayerStyle::FillElementLayerStyle(const FillElementLayerStyle& other)
} }
} }
std::shared_ptr<LayerStyle> FillElementLayerStyle::clonePtr() const std::unique_ptr<LayerStyle> FillElementLayerStyle::clonePtr() const
{ {
return std::make_shared<LayerStyle>(FillElementLayerStyle(*this)); return std::make_unique<FillElementLayerStyle>(FillElementLayerStyle(*this));
} }

View File

@ -24,7 +24,7 @@ public:
virtual QWidget* getInputWidget() const = 0; virtual QWidget* getInputWidget() const = 0;
virtual QWidget* getListDisplayWidget() const = 0; virtual QWidget* getListDisplayWidget() const = 0;
virtual ~LayerStyle() {}; virtual ~LayerStyle() {};
virtual std::shared_ptr<LayerStyle> clonePtr() const = 0; virtual std::unique_ptr<LayerStyle> clonePtr() const = 0;
}; };
class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle class StrokeElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
@ -38,7 +38,7 @@ public:
StrokeElementLayerStyle(const StrokeElementLayerStyle& other); StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
~StrokeElementLayerStyle() = default; ~StrokeElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>> materialStyles; std::vector<std::shared_ptr<Renderer::MaterialStyleStroke>> materialStyles;
std::shared_ptr<LayerStyle> clonePtr() const override; std::unique_ptr<LayerStyle> clonePtr() const override;
}; };
class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle class FillElementLayerStyle : public Renderer::ElementStyle, public LayerStyle
@ -52,5 +52,5 @@ public:
FillElementLayerStyle(const FillElementLayerStyle& other); FillElementLayerStyle(const FillElementLayerStyle& other);
~FillElementLayerStyle() = default; ~FillElementLayerStyle() = default;
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles; std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
std::shared_ptr<LayerStyle> clonePtr() const override; std::unique_ptr<LayerStyle> clonePtr() const override;
}; };

View File

@ -30,9 +30,11 @@ PixelPath LayerWrapper::getCache()
} }
// TODO: undone // TODO: undone
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent) LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager)
{ {
this->parent = parent; this->parent = parent;
this->elementManager = elementManager;
this->qTreeWidgetItem = new QTreeWidgetItem();
auto transformJson = json.value("transform").toObject(); auto transformJson = json.value("transform").toObject();
property.name = json.value("name").toString(); property.name = json.value("name").toString();
property.offset = {transformJson.value("offset").toObject().value("x").toDouble(), property.offset = {transformJson.value("offset").toObject().value("x").toDouble(),
@ -43,7 +45,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
} }
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
: LayerWrapper(json, parent) : LayerWrapper(json, parent, elementManager)
{ {
qDebug() << json.value("name").toString() << " " << this; qDebug() << json.value("name").toString() << " " << this;
QJsonArray childrenJson = json.value("children").toArray(); QJsonArray childrenJson = json.value("children").toArray();
@ -119,22 +121,22 @@ void LayerWrapper::setParent(FolderLayerWrapper* newParent)
void FolderLayerWrapper::removeAllChild() void FolderLayerWrapper::removeAllChild()
{ {
children.clear(); children.clear();
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
} }
void LayerWrapper::del() { void LayerWrapper::del() {
qDebug() << "LayerWrapper::del()"; qDebug() << "LayerWrapper::del()";
if (parent != nullptr){ if (parent != nullptr){
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem); parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
} }
} }
void LayerWrapper::delSelf() { void LayerWrapper::delSelf() {
qDebug() << "LayerWrapper::delSelf()"; qDebug() << "LayerWrapper::delSelf()";
if (parent != nullptr) { if (parent != nullptr) {
qTreeWidgetItem.takeChildren(); qTreeWidgetItem->takeChildren();
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem); parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
} }
} }
@ -154,7 +156,7 @@ void FolderLayerWrapper::delSelf() {
qDebug() << this; qDebug() << this;
for (auto& child : this->children) { for (auto& child : this->children) {
this->parent->addChild(child); this->parent->addChild(child);
this->parent->qTreeWidgetItem.addChild(&child.get()->qTreeWidgetItem); this->parent->qTreeWidgetItem->addChild(child.get()->qTreeWidgetItem);
child->setParent(this->parent); child->setParent(this->parent);
} }
while (!this->children.empty()) { while (!this->children.empty()) {
@ -166,18 +168,18 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem() QTreeWidgetItem* LayerWrapper::getQTreeItem()
{ {
this->qTreeWidgetItem.setText(0, this->property.name); this->qTreeWidgetItem->setText(0, this->property.name);
this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this)); this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
return &this->qTreeWidgetItem; return this->qTreeWidgetItem;
} }
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem() QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
{ {
while (this->qTreeWidgetItem.childCount() > 0) { while (this->qTreeWidgetItem->childCount() > 0) {
this->qTreeWidgetItem.removeChild(this->qTreeWidgetItem.child(0)); this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
} }
for (auto& child : this->children) { for (auto& child : this->children) {
this->qTreeWidgetItem.addChild(child->getQTreeItem()); this->qTreeWidgetItem->addChild(child->getQTreeItem());
} }
return LayerWrapper::getQTreeItem(); return LayerWrapper::getQTreeItem();
} }
@ -204,8 +206,8 @@ QJsonObject FolderLayerWrapper::toJson() const
childrenJson.push_back(child->toJson()); childrenJson.push_back(child->toJson());
json.insert("children", childrenJson); json.insert("children", childrenJson);
json.insert("is-folder", true); json.insert("is-folder", true);
if(this->referencedBy != -1) if(this->getReferencedBy() != -1)
json.insert("referenced-by", this->referencedBy); json.insert("referenced-by", this->getReferencedBy());
else else
json.insert("referenced-by", QJsonValue()); json.insert("referenced-by", QJsonValue());
return json; return json;
@ -217,4 +219,12 @@ QJsonObject LeafLayerWrapper::toJson() const
json.insert("element", wrappedElement->index); json.insert("element", wrappedElement->index);
json.insert("is-folder", false); json.insert("is-folder", false);
return json; return json;
}
int FolderLayerWrapper::getReferencedBy()const
{
if (this->elementManager != nullptr)
return this->elementManager->getLayerReferencedBy(this);
else
return -1;
} }

View File

@ -28,12 +28,13 @@ class LayerWrapper
protected: protected:
FolderLayerWrapper* parent; FolderLayerWrapper* parent;
QPointF referencePoint; QPointF referencePoint;
ElementManager* elementManager;
// vector<LayerStyle> styles; // vector<LayerStyle> styles;
// TODO: 将cache移到子类对Leaf用ComposedPainterPath对Folder用FolderBitmapPath // TODO: 将cache移到子类对Leaf用ComposedPainterPath对Folder用FolderBitmapPath
PixelPath cache; PixelPath cache;
public: public:
QTreeWidgetItem qTreeWidgetItem; QTreeWidgetItem* qTreeWidgetItem;
struct SimpleProperty struct SimpleProperty
{ {
QString name = ""; QString name = "";
@ -51,7 +52,7 @@ class LayerWrapper
// TODO: 将QPainterPath改为BitmapPath/QImage或者直接将其删除绘制时直接使用BitmapPath的paint方法 // TODO: 将QPainterPath改为BitmapPath/QImage或者直接将其删除绘制时直接使用BitmapPath的paint方法
virtual PixelPath getCache(); virtual PixelPath getCache();
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent); LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
LayerWrapper() = default; LayerWrapper() = default;
// TODO : export Function // TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only // virtual LayerWrapper *addChild() = 0; // Leaf Child Only
@ -84,6 +85,7 @@ class FolderLayerWrapper : public LayerWrapper
void delSelf() override; void delSelf() override;
QTreeWidgetItem* getQTreeItem() override; QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override; QJsonObject toJson() const override;
int getReferencedBy()const;
}; };
class LeafLayerWrapper : public LayerWrapper class LeafLayerWrapper : public LayerWrapper

View File

@ -51,7 +51,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
else else
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer); newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer)); folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem()); folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
qDebug() << jsonObj<<"----------------------"; qDebug() << jsonObj<<"----------------------";
this->refresh(); this->refresh();
emit requireRefreshPreview(); emit requireRefreshPreview();

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QOpenGLFunctions_4_5_Core> #include <QOpenGLFunctions_4_5_Core>
#include <QString> #include <QString>
#include <QVector> #include <vector>
#include <QVector2D> #include <QVector2D>
#include <QVector3D> #include <QVector3D>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
@ -38,8 +38,8 @@ namespace Renderer
class Mesh : public Drawable class Mesh : public Drawable
{ {
public: public:
QVector<Vertex> vertices; std::vector<Vertex> vertices;
QVector<unsigned int> indices; std::vector<unsigned int> indices;
//QVector<Texture*> textures; //QVector<Texture*> textures;
GLuint textureBasecolor = 0; GLuint textureBasecolor = 0;
GLuint textureMetallicRoughness = 0; GLuint textureMetallicRoughness = 0;

View File

@ -86,7 +86,9 @@ void Renderer::Model::loadModel(QString path)
maxY = std::numeric_limits<float>::min(); maxY = std::numeric_limits<float>::min();
minZ = std::numeric_limits<float>::max(); minZ = std::numeric_limits<float>::max();
maxZ = std::numeric_limits<float>::min(); maxZ = std::numeric_limits<float>::min();
processNode(scene->mRootNode, scene); aiMatrix4x4 transform;
aiMatrix4x4::Scaling(aiVector3D(1 / 0.008), transform);
processNode(scene->mRootNode, scene, transform * scene->mRootNode->mTransformation);
AABB.push_back(QVector3D(minX, minY, minZ)); AABB.push_back(QVector3D(minX, minY, minZ));
AABB.push_back(QVector3D(minX, minY, maxZ)); AABB.push_back(QVector3D(minX, minY, maxZ));
AABB.push_back(QVector3D(minX, maxY, minZ)); AABB.push_back(QVector3D(minX, maxY, minZ));
@ -121,36 +123,35 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
aiString str; aiString str;
material->GetTexture(aiTextureType_BASE_COLOR, 0, &str); material->GetTexture(aiTextureType_BASE_COLOR, 0, &str);
std::vector<Vertex> vertices;
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mNormals && mesh->mTextureCoords[0])
{
auto pos = mesh->mVertices[i];
vertices.push_back(Vertex(pos, mesh->mNormals[i], mesh->mTextureCoords[0][i]));
auto worldPos = model * pos;
minX = std::min(minX, worldPos.x);
maxX = std::max(maxX, worldPos.x);
minY = std::min(minY, worldPos.y);
maxY = std::max(maxY, worldPos.y);
minZ = std::min(minZ, worldPos.z);
maxZ = std::max(maxZ, worldPos.z);
}
}
std::vector<unsigned int> indices;
for (auto face = mesh->mFaces; face < mesh->mFaces + mesh->mNumFaces; face++)
indices.insert(indices.end(), face->mIndices, face->mIndices + face->mNumIndices);
if (auto iter = paintingMap.find(std::string(str.C_Str())); paintingProgram != nullptr && iter != paintingMap.end()) if (auto iter = paintingMap.find(std::string(str.C_Str())); paintingProgram != nullptr && iter != paintingMap.end())
{ {
auto& [paintingPath, leftBottom, rightTop] = iter->second; auto& [paintingPath, leftBottom, rightTop] = iter->second;
qDebug() << str.C_Str() << "Replaced"; qDebug() << str.C_Str() << "Replaced";
// 初始化网格
auto m_mesh = std::make_unique<PaintingMesh>(glFunc, paintingProgram, shadowProgram, modelQ);
// 遍历网格的每个顶点
for (unsigned int i = 0; i < mesh->mNumVertices; i++)
{
if (mesh->mNormals && mesh->mTextureCoords[0])
{
Vertex vertex(mesh->mVertices[i], mesh->mNormals[i], mesh->mTextureCoords[0][i]);
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());
m_mesh->vertices.push_back(vertex);
}
}
for (unsigned int i = 0; i < mesh->mNumFaces; i++) auto m_mesh = std::make_unique<PaintingMesh>(glFunc, paintingProgram, shadowProgram, modelQ);
{ m_mesh->vertices = vertices;
aiFace face = mesh->mFaces[i]; m_mesh->indices = indices;
// 将所有面的索引数据添加到索引数组中
for (unsigned int j = 0; j < face.mNumIndices; j++) {
m_mesh->indices.push_back(face.mIndices[j]);
}
}
m_mesh->paintingId = loadPainting(paintingPath); m_mesh->paintingId = loadPainting(paintingPath);
auto& handle = vtManager->getPaintingHandle(m_mesh->paintingId); auto& handle = vtManager->getPaintingHandle(m_mesh->paintingId);
@ -161,28 +162,9 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
} }
else else
{ {
// 初始化网格
auto m_mesh = std::make_unique<Mesh>(glFunc, shaderProgram, shadowProgram, modelQ); auto m_mesh = std::make_unique<Mesh>(glFunc, shaderProgram, shadowProgram, modelQ);
// 遍历网格的每个顶点 m_mesh->vertices = vertices;
for (unsigned int i = 0; i < mesh->mNumVertices; i++) m_mesh->indices = indices;
{
if (mesh->mNormals && mesh->mTextureCoords[0])
{
Vertex vertex(mesh->mVertices[i], mesh->mNormals[i], mesh->mTextureCoords[0][i]);
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());
m_mesh->vertices.push_back(vertex);
}
}
// 将所有面的索引数据添加到索引数组中
for (auto face = mesh->mFaces; face < mesh->mFaces + mesh->mNumFaces; face++)
for (auto indice = face->mIndices; indice < face->mIndices + face->mNumIndices; indice++)
m_mesh->indices.push_back(*indice);
// ´¦Àí²ÄÖÊ // ´¦Àí²ÄÖÊ
if (!(m_mesh->textureBasecolor = loadMaterialTextures(material, aiTextureType_BASE_COLOR))) if (!(m_mesh->textureBasecolor = loadMaterialTextures(material, aiTextureType_BASE_COLOR)))

View File

@ -23,6 +23,7 @@ namespace Renderer
public: public:
virtual MaterialStyleType type() const = 0; virtual MaterialStyleType type() const = 0;
virtual std::vector<GLfloat> encoded() const = 0; virtual std::vector<GLfloat> encoded() const = 0;
virtual std::unique_ptr<MaterialStyle> clone() const = 0;
virtual bool operator==(const MaterialStyle&) const = 0; virtual bool operator==(const MaterialStyle&) const = 0;
}; };

View File

@ -18,6 +18,11 @@ std::vector<GLfloat> Renderer::FillPlain::encoded() const
glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())))}; glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())))};
} }
std::unique_ptr<MaterialFill> Renderer::FillPlain::clone() const
{
return std::make_unique<FillPlain>(*this);
}
bool Renderer::FillPlain::operator==(const MaterialFill& m) const bool Renderer::FillPlain::operator==(const MaterialFill& m) const
{ {
return type() == m.type() return type() == m.type()
@ -42,6 +47,11 @@ std::vector<GLfloat> Renderer::MaterialStyleFill::encoded() const
return materialFill->encoded(); return materialFill->encoded();
} }
std::unique_ptr<MaterialStyle> Renderer::MaterialStyleFill::clone() const
{
return std::make_unique<MaterialStyleFill>(materialFill->clone());
}
bool Renderer::MaterialStyleFill::operator==(const MaterialStyle& m) const bool Renderer::MaterialStyleFill::operator==(const MaterialStyle& m) const
{ {
return type() == m.type() && *materialFill == *static_cast<const MaterialStyleFill&>(m).materialFill; return type() == m.type() && *materialFill == *static_cast<const MaterialStyleFill&>(m).materialFill;

View File

@ -10,6 +10,7 @@ namespace Renderer
public: public:
virtual MaterialFillType type() const = 0; virtual MaterialFillType type() const = 0;
virtual std::vector<GLfloat> encoded() const = 0; virtual std::vector<GLfloat> encoded() const = 0;
virtual std::unique_ptr<MaterialFill> clone() const = 0;
virtual bool operator==(const MaterialFill&) const = 0; virtual bool operator==(const MaterialFill&) const = 0;
}; };
@ -19,6 +20,7 @@ namespace Renderer
FillPlain(QColor color, float metallic, float roughness); FillPlain(QColor color, float metallic, float roughness);
virtual MaterialFillType type() const override; virtual MaterialFillType type() const override;
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual std::unique_ptr<MaterialFill> clone() const override;
virtual bool operator==(const MaterialFill&) const override; virtual bool operator==(const MaterialFill&) const override;
QColor color; QColor color;
@ -26,16 +28,17 @@ namespace Renderer
float roughness; float roughness;
}; };
class MaterialStyleFill : public MaterialStyle class MaterialStyleFill : public MaterialStyle
{ {
public: public:
MaterialStyleFill(std::shared_ptr<MaterialFill> materialFill); MaterialStyleFill(std::shared_ptr<MaterialFill> materialFill);
virtual MaterialStyleType type() const override; virtual MaterialStyleType type() const override;
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual std::unique_ptr<MaterialStyle> clone() const override;
virtual bool operator==(const MaterialStyle&) const override; virtual bool operator==(const MaterialStyle&) const override;
//protected: //protected:
std::shared_ptr<MaterialFill> materialFill; std::shared_ptr<MaterialFill> materialFill;
}; };
} }

View File

@ -18,6 +18,11 @@ MaterialStrokeType Renderer::StrokePlain::type() const
return MaterialStrokeType::kPlain; return MaterialStrokeType::kPlain;
} }
std::unique_ptr<MaterialStroke> Renderer::StrokePlain::clone() const
{
return std::make_unique<StrokePlain>(*this);
}
std::vector<GLfloat> Renderer::StrokePlain::encoded() const std::vector<GLfloat> Renderer::StrokePlain::encoded() const
{ {
return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))), return { glm::uintBitsToFloat(glm::packUnorm4x8(glm::vec4(material.toVec().second, 0.f, 0.f))),
@ -58,6 +63,11 @@ std::vector<GLfloat> Renderer::StrokeRadialGradient::encoded() const
return result; return result;
} }
std::unique_ptr<MaterialStroke> Renderer::StrokeRadialGradient::clone() const
{
return std::make_unique<StrokeRadialGradient>(*this);
}
bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const
{ {
return type() == m.type() return type() == m.type()
@ -70,12 +80,6 @@ Renderer::MaterialStyleStroke::MaterialStyleStroke(float width, StrokeType strok
{ {
} }
Renderer::MaterialStyleStroke::MaterialStyleStroke(const MaterialStyleStroke& s)
:halfWidth(s.halfWidth), strokeType(s.strokeType), endType(s.endType), materialStroke(std::make_shared<MaterialStroke>(*s.materialStroke))
{
}
MaterialStyleType Renderer::MaterialStyleStroke::type() const MaterialStyleType Renderer::MaterialStyleStroke::type() const
{ {
return MaterialStyleType::kStroke; return MaterialStyleType::kStroke;
@ -93,6 +97,11 @@ std::vector<GLfloat> Renderer::MaterialStyleStroke::encoded() const
return v; return v;
} }
std::unique_ptr<MaterialStyle> Renderer::MaterialStyleStroke::clone() const
{
return std::make_unique<MaterialStyleStroke>(halfWidth*2, strokeType, endType, materialStroke->clone());
}
bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const bool Renderer::MaterialStyleStroke::operator==(const MaterialStyle& m) const
{ {
return type() == m.type() && *materialStroke == *static_cast<const MaterialStyleStroke&>(m).materialStroke; return type() == m.type() && *materialStroke == *static_cast<const MaterialStyleStroke&>(m).materialStroke;

View File

@ -11,6 +11,7 @@ namespace Renderer
public: public:
virtual MaterialStrokeType type() const = 0; virtual MaterialStrokeType type() const = 0;
virtual std::vector<GLfloat> encoded() const = 0; virtual std::vector<GLfloat> encoded() const = 0;
virtual std::unique_ptr<MaterialStroke> clone() const = 0;
virtual bool operator==(const MaterialStroke&) const = 0; virtual bool operator==(const MaterialStroke&) const = 0;
}; };
@ -20,7 +21,9 @@ namespace Renderer
StrokePlain(QColor color, float metallic, float roughness); StrokePlain(QColor color, float metallic, float roughness);
StrokePlain(const Material& material); StrokePlain(const Material& material);
virtual MaterialStrokeType type() const override; virtual MaterialStrokeType type() const override;
virtual std::unique_ptr<MaterialStroke> clone() const override;
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual bool operator==(const MaterialStroke&) const override; virtual bool operator==(const MaterialStroke&) const override;
Material material; Material material;
@ -32,6 +35,7 @@ namespace Renderer
StrokeRadialGradient(const std::map<float, Material>& materialMap, bool gradual); StrokeRadialGradient(const std::map<float, Material>& materialMap, bool gradual);
virtual MaterialStrokeType type() const override; virtual MaterialStrokeType type() const override;
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual std::unique_ptr<MaterialStroke> clone() const override;
virtual bool operator==(const MaterialStroke&) const override; virtual bool operator==(const MaterialStroke&) const override;
std::map<float, Material> materialMap; std::map<float, Material> materialMap;
@ -45,9 +49,9 @@ namespace Renderer
{ {
public: public:
MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke); MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke);
MaterialStyleStroke(const MaterialStyleStroke&);
virtual MaterialStyleType type() const override; virtual MaterialStyleType type() const override;
virtual std::vector<GLfloat> encoded() const override; virtual std::vector<GLfloat> encoded() const override;
virtual std::unique_ptr<MaterialStyle> clone() const override;
virtual bool operator==(const MaterialStyle&) const override; virtual bool operator==(const MaterialStyle&) const override;
float getHalfWidth() const; float getHalfWidth() const;
//protected: //protected:

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QOpenGLFunctions_4_5_Core> #include <QOpenGLFunctions_4_5_Core>
#include <QString> #include <QString>
#include <QVector> #include <vector>
#include <QVector2D> #include <QVector2D>
#include <QVector3D> #include <QVector3D>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
@ -18,8 +18,8 @@ namespace Renderer
class PaintingMesh : public Drawable class PaintingMesh : public Drawable
{ {
public: public:
QVector<Vertex> vertices; std::vector<Vertex> vertices;
QVector<GLuint> indices; std::vector<GLuint> indices;
GLuint textureBasecolor; GLuint textureBasecolor;
GLuint textureMetallicRoughness; GLuint textureMetallicRoughness;
QMatrix4x4 model; QMatrix4x4 model;

View File

@ -73,17 +73,14 @@ void RendererGLWidget::stopTimer()
timerId = -1; timerId = -1;
} }
void RendererGLWidget::setModel() void RendererGLWidget::setModel(QString path)
{ {
makeCurrent(); makeCurrent();
model->loadModel("Models/Sponza/Sponza.gltf"); //model->loadModel("Models/Sponza/Sponza.gltf");
//model = new Model("E:\\3D Objects\\gallery_gltf\\gallery_gltf.gltf", context(), modelProgramPtr, paintingProgramPtr, shadowProgramPtr, paintingHelper); //model->loadModel("E:\\3D Objects\\Gate\\gltf\\Gate.gltf");
model->loadModel(path);
light.model = model; light.model = model;
qDebug() << model->AABB; qDebug() << model->AABB;
//paintingHelper->allocateBuffers();
//paintingCompProgramPtr->bind();
//paintingHelper->bindPaintingBuffers();
//paintingCompProgramPtr->release();
doneCurrent(); doneCurrent();
} }

View File

@ -26,7 +26,7 @@ namespace Renderer
void startTimer(); void startTimer();
void stopTimer(); void stopTimer();
public slots: public slots:
void setModel(); void setModel(QString path);
void setMainLightPitch(float pitch); void setMainLightPitch(float pitch);
void setMainLightYaw(float yaw); void setMainLightYaw(float yaw);
void setExposure(float exposure); void setExposure(float exposure);

View File

@ -1,6 +1,7 @@
#include "RendererWidget.h" #include "RendererWidget.h"
#include "RendererGLWidget.h" #include "RendererGLWidget.h"
#include "../FluentMenu.h" #include "../FluentMenu.h"
#include <QFileDialog>
Renderer::RendererWidget::RendererWidget(QWidget* parent) Renderer::RendererWidget::RendererWidget(QWidget* parent)
: QWidget(parent) : QWidget(parent)
@ -10,8 +11,10 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
FluentMenu* menu = new FluentMenu(this); FluentMenu* menu = new FluentMenu(this);
auto openAction = new QAction(QStringLiteral("´ò¿ª"), menu); auto openAction = new QAction(QStringLiteral("´ò¿ª"), menu);
auto saveAction = new QAction(QStringLiteral("±£´æ"), menu); auto saveAction = new QAction(QStringLiteral("±£´æ"), menu);
auto testAction = new QAction(QStringLiteral("²âÊÔ"), menu);
menu->addAction(openAction); menu->addAction(openAction);
menu->addAction(saveAction); menu->addAction(saveAction);
menu->addAction(testAction);
ui.openButton->setHaloVisible(false); ui.openButton->setHaloVisible(false);
ui.openButton->setOverlayStyle(::Material::TintedOverlay); ui.openButton->setOverlayStyle(::Material::TintedOverlay);
@ -34,7 +37,16 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
QObject::connect(ui.exposureSlider, &QSlider::valueChanged, [&](int value) { QObject::connect(ui.exposureSlider, &QSlider::valueChanged, [&](int value) {
ui.openGLWidget->setExposure(value / 100.f); ui.openGLWidget->setExposure(value / 100.f);
}); });
QObject::connect(openAction, &QAction::triggered, ui.openGLWidget, &Renderer::RendererGLWidget::setModel);
QObject::connect(openAction, &QAction::triggered, [&] {
QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral("´ò¿ªÄ£ÐÍ"), QString(), QStringLiteral("glTF 2.0 (*.gltf)"));
qDebug() << fileName;
if (fileName != QString())
ui.openGLWidget->setModel(fileName);
});
QObject::connect(testAction, &QAction::triggered, [&] {
ui.openGLWidget->setModel("Models/Sponza/Sponza.gltf");
});
ui.horizontalSlider->setValue(105); ui.horizontalSlider->setValue(105);
ui.horizontalSlider_2->setValue(80); ui.horizontalSlider_2->setValue(80);