Merge branch 'main' of http://101.34.228.45:3000/BigC/ArchitectureColoredPainting
commit
631f0f8af7
|
@ -18,7 +18,7 @@ LayerStyleDialog::LayerStyleDialog(
|
|||
|
||||
if (existedStyle)
|
||||
{
|
||||
this->modifyingStyle = std::make_unique<LayerStyle>(existedStyle->clonePtr());
|
||||
this->modifyingStyle = existedStyle->clonePtr();
|
||||
|
||||
this->styleContainer = nullptr;
|
||||
this->styleWidget = modifyingStyle->getInputWidget();
|
||||
|
|
|
@ -45,4 +45,26 @@ QJsonObject ElementManager::toJson() const
|
|||
QJsonObject result;
|
||||
result.insert("elements", elementsJson);
|
||||
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;
|
||||
}
|
|
@ -8,6 +8,7 @@ using std::vector;
|
|||
class LayerManager;
|
||||
class GraphicElement;
|
||||
class Renderer::ElementRenderer;
|
||||
class FolderLayerWrapper;
|
||||
|
||||
class ElementManager
|
||||
{
|
||||
|
@ -24,4 +25,6 @@ class ElementManager
|
|||
* only used in initialization
|
||||
*/
|
||||
GraphicElement *getElementById(int index);
|
||||
int getElementIndex(GraphicElement* pElement);
|
||||
int getLayerReferencedBy(const FolderLayerWrapper* layer);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
virtual QWidget* getInputWidget() const = 0;
|
||||
virtual QWidget* getListDisplayWidget() const = 0;
|
||||
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
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
StrokeElementLayerStyle(const StrokeElementLayerStyle& other);
|
||||
~StrokeElementLayerStyle() = default;
|
||||
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
|
||||
|
@ -52,5 +52,5 @@ public:
|
|||
FillElementLayerStyle(const FillElementLayerStyle& other);
|
||||
~FillElementLayerStyle() = default;
|
||||
std::vector<std::shared_ptr<Renderer::MaterialStyleFill>> materialStyles;
|
||||
std::shared_ptr<LayerStyle> clonePtr() const override;
|
||||
std::unique_ptr<LayerStyle> clonePtr() const override;
|
||||
};
|
|
@ -30,9 +30,11 @@ PixelPath LayerWrapper::getCache()
|
|||
}
|
||||
|
||||
// TODO: undone
|
||||
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent)
|
||||
LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager)
|
||||
{
|
||||
this->parent = parent;
|
||||
this->elementManager = elementManager;
|
||||
this->qTreeWidgetItem = new QTreeWidgetItem();
|
||||
auto transformJson = json.value("transform").toObject();
|
||||
property.name = json.value("name").toString();
|
||||
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)
|
||||
: LayerWrapper(json, parent)
|
||||
: LayerWrapper(json, parent, elementManager)
|
||||
{
|
||||
qDebug() << json.value("name").toString() << " " << this;
|
||||
QJsonArray childrenJson = json.value("children").toArray();
|
||||
|
@ -119,22 +121,22 @@ void LayerWrapper::setParent(FolderLayerWrapper* newParent)
|
|||
void FolderLayerWrapper::removeAllChild()
|
||||
{
|
||||
children.clear();
|
||||
qTreeWidgetItem.takeChildren();
|
||||
qTreeWidgetItem->takeChildren();
|
||||
}
|
||||
|
||||
void LayerWrapper::del() {
|
||||
qDebug() << "LayerWrapper::del()";
|
||||
if (parent != nullptr){
|
||||
qTreeWidgetItem.takeChildren();
|
||||
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem);
|
||||
qTreeWidgetItem->takeChildren();
|
||||
parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
|
||||
}
|
||||
}
|
||||
|
||||
void LayerWrapper::delSelf() {
|
||||
qDebug() << "LayerWrapper::delSelf()";
|
||||
if (parent != nullptr) {
|
||||
qTreeWidgetItem.takeChildren();
|
||||
parent->qTreeWidgetItem.removeChild(&qTreeWidgetItem);
|
||||
qTreeWidgetItem->takeChildren();
|
||||
parent->qTreeWidgetItem->removeChild(qTreeWidgetItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +156,7 @@ void FolderLayerWrapper::delSelf() {
|
|||
qDebug() << this;
|
||||
for (auto& child : this->children) {
|
||||
this->parent->addChild(child);
|
||||
this->parent->qTreeWidgetItem.addChild(&child.get()->qTreeWidgetItem);
|
||||
this->parent->qTreeWidgetItem->addChild(child.get()->qTreeWidgetItem);
|
||||
child->setParent(this->parent);
|
||||
}
|
||||
while (!this->children.empty()) {
|
||||
|
@ -166,18 +168,18 @@ void FolderLayerWrapper::delSelf() {
|
|||
|
||||
QTreeWidgetItem* LayerWrapper::getQTreeItem()
|
||||
{
|
||||
this->qTreeWidgetItem.setText(0, this->property.name);
|
||||
this->qTreeWidgetItem.setData(0, Qt::UserRole, QVariant::fromValue(this));
|
||||
return &this->qTreeWidgetItem;
|
||||
this->qTreeWidgetItem->setText(0, this->property.name);
|
||||
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
|
||||
return this->qTreeWidgetItem;
|
||||
}
|
||||
|
||||
QTreeWidgetItem* FolderLayerWrapper::getQTreeItem()
|
||||
{
|
||||
while (this->qTreeWidgetItem.childCount() > 0) {
|
||||
this->qTreeWidgetItem.removeChild(this->qTreeWidgetItem.child(0));
|
||||
while (this->qTreeWidgetItem->childCount() > 0) {
|
||||
this->qTreeWidgetItem->removeChild(this->qTreeWidgetItem->child(0));
|
||||
}
|
||||
for (auto& child : this->children) {
|
||||
this->qTreeWidgetItem.addChild(child->getQTreeItem());
|
||||
this->qTreeWidgetItem->addChild(child->getQTreeItem());
|
||||
}
|
||||
return LayerWrapper::getQTreeItem();
|
||||
}
|
||||
|
@ -204,8 +206,8 @@ QJsonObject FolderLayerWrapper::toJson() const
|
|||
childrenJson.push_back(child->toJson());
|
||||
json.insert("children", childrenJson);
|
||||
json.insert("is-folder", true);
|
||||
if(this->referencedBy != -1)
|
||||
json.insert("referenced-by", this->referencedBy);
|
||||
if(this->getReferencedBy() != -1)
|
||||
json.insert("referenced-by", this->getReferencedBy());
|
||||
else
|
||||
json.insert("referenced-by", QJsonValue());
|
||||
return json;
|
||||
|
@ -217,4 +219,12 @@ QJsonObject LeafLayerWrapper::toJson() const
|
|||
json.insert("element", wrappedElement->index);
|
||||
json.insert("is-folder", false);
|
||||
return json;
|
||||
}
|
||||
|
||||
int FolderLayerWrapper::getReferencedBy()const
|
||||
{
|
||||
if (this->elementManager != nullptr)
|
||||
return this->elementManager->getLayerReferencedBy(this);
|
||||
else
|
||||
return -1;
|
||||
}
|
|
@ -28,12 +28,13 @@ class LayerWrapper
|
|||
protected:
|
||||
FolderLayerWrapper* parent;
|
||||
QPointF referencePoint;
|
||||
ElementManager* elementManager;
|
||||
// vector<LayerStyle> styles;
|
||||
// TODO: 将cache移到子类,对Leaf用ComposedPainterPath,对Folder用FolderBitmapPath
|
||||
PixelPath cache;
|
||||
|
||||
public:
|
||||
QTreeWidgetItem qTreeWidgetItem;
|
||||
QTreeWidgetItem* qTreeWidgetItem;
|
||||
struct SimpleProperty
|
||||
{
|
||||
QString name = "";
|
||||
|
@ -51,7 +52,7 @@ class LayerWrapper
|
|||
// TODO: 将QPainterPath改为BitmapPath/QImage,或者直接将其删除,绘制时直接使用BitmapPath的paint方法
|
||||
virtual PixelPath getCache();
|
||||
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;
|
||||
// TODO : export Function
|
||||
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only
|
||||
|
@ -84,6 +85,7 @@ class FolderLayerWrapper : public LayerWrapper
|
|||
void delSelf() override;
|
||||
QTreeWidgetItem* getQTreeItem() override;
|
||||
QJsonObject toJson() const override;
|
||||
int getReferencedBy()const;
|
||||
};
|
||||
|
||||
class LeafLayerWrapper : public LayerWrapper
|
||||
|
|
|
@ -51,7 +51,7 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
else
|
||||
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
|
||||
folderLayer->qTreeWidgetItem.addChild(newLayer->getQTreeItem());
|
||||
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
|
||||
qDebug() << jsonObj<<"----------------------";
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <QOpenGLFunctions_4_5_Core>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
@ -38,8 +38,8 @@ namespace Renderer
|
|||
class Mesh : public Drawable
|
||||
{
|
||||
public:
|
||||
QVector<Vertex> vertices;
|
||||
QVector<unsigned int> indices;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
//QVector<Texture*> textures;
|
||||
GLuint textureBasecolor = 0;
|
||||
GLuint textureMetallicRoughness = 0;
|
||||
|
|
|
@ -86,7 +86,9 @@ void Renderer::Model::loadModel(QString path)
|
|||
maxY = std::numeric_limits<float>::min();
|
||||
minZ = std::numeric_limits<float>::max();
|
||||
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, maxZ));
|
||||
AABB.push_back(QVector3D(minX, maxY, minZ));
|
||||
|
@ -121,36 +123,35 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
|||
aiString 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())
|
||||
{
|
||||
auto& [paintingPath, leftBottom, rightTop] = iter->second;
|
||||
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++)
|
||||
{
|
||||
aiFace face = mesh->mFaces[i];
|
||||
// 将所有面的索引数据添加到索引数组中
|
||||
for (unsigned int j = 0; j < face.mNumIndices; j++) {
|
||||
m_mesh->indices.push_back(face.mIndices[j]);
|
||||
}
|
||||
}
|
||||
auto m_mesh = std::make_unique<PaintingMesh>(glFunc, paintingProgram, shadowProgram, modelQ);
|
||||
m_mesh->vertices = vertices;
|
||||
m_mesh->indices = indices;
|
||||
|
||||
m_mesh->paintingId = loadPainting(paintingPath);
|
||||
auto& handle = vtManager->getPaintingHandle(m_mesh->paintingId);
|
||||
|
@ -161,28 +162,9 @@ std::unique_ptr<Drawable> Model::processMesh(aiMesh* mesh, const aiScene* scene,
|
|||
}
|
||||
else
|
||||
{
|
||||
// 初始化网格
|
||||
auto m_mesh = std::make_unique<Mesh>(glFunc, shaderProgram, 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 (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);
|
||||
m_mesh->vertices = vertices;
|
||||
m_mesh->indices = indices;
|
||||
|
||||
// ´¦Àí²ÄÖÊ
|
||||
if (!(m_mesh->textureBasecolor = loadMaterialTextures(material, aiTextureType_BASE_COLOR)))
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Renderer
|
|||
public:
|
||||
virtual MaterialStyleType type() const = 0;
|
||||
virtual std::vector<GLfloat> encoded() const = 0;
|
||||
virtual std::unique_ptr<MaterialStyle> clone() const = 0;
|
||||
virtual bool operator==(const MaterialStyle&) const = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -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())))};
|
||||
}
|
||||
|
||||
std::unique_ptr<MaterialFill> Renderer::FillPlain::clone() const
|
||||
{
|
||||
return std::make_unique<FillPlain>(*this);
|
||||
}
|
||||
|
||||
bool Renderer::FillPlain::operator==(const MaterialFill& m) const
|
||||
{
|
||||
return type() == m.type()
|
||||
|
@ -42,6 +47,11 @@ std::vector<GLfloat> Renderer::MaterialStyleFill::encoded() const
|
|||
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
|
||||
{
|
||||
return type() == m.type() && *materialFill == *static_cast<const MaterialStyleFill&>(m).materialFill;
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Renderer
|
|||
public:
|
||||
virtual MaterialFillType type() const = 0;
|
||||
virtual std::vector<GLfloat> encoded() const = 0;
|
||||
virtual std::unique_ptr<MaterialFill> clone() const = 0;
|
||||
virtual bool operator==(const MaterialFill&) const = 0;
|
||||
};
|
||||
|
||||
|
@ -19,6 +20,7 @@ namespace Renderer
|
|||
FillPlain(QColor color, float metallic, float roughness);
|
||||
virtual MaterialFillType type() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
virtual std::unique_ptr<MaterialFill> clone() const override;
|
||||
virtual bool operator==(const MaterialFill&) const override;
|
||||
|
||||
QColor color;
|
||||
|
@ -26,16 +28,17 @@ namespace Renderer
|
|||
float roughness;
|
||||
};
|
||||
|
||||
class MaterialStyleFill : public MaterialStyle
|
||||
{
|
||||
public:
|
||||
class MaterialStyleFill : public MaterialStyle
|
||||
{
|
||||
public:
|
||||
MaterialStyleFill(std::shared_ptr<MaterialFill> materialFill);
|
||||
virtual MaterialStyleType type() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
virtual MaterialStyleType type() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
virtual std::unique_ptr<MaterialStyle> clone() const override;
|
||||
virtual bool operator==(const MaterialStyle&) const override;
|
||||
//protected:
|
||||
//protected:
|
||||
std::shared_ptr<MaterialFill> materialFill;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,11 @@ MaterialStrokeType Renderer::StrokePlain::type() const
|
|||
return MaterialStrokeType::kPlain;
|
||||
}
|
||||
|
||||
std::unique_ptr<MaterialStroke> Renderer::StrokePlain::clone() const
|
||||
{
|
||||
return std::make_unique<StrokePlain>(*this);
|
||||
}
|
||||
|
||||
std::vector<GLfloat> Renderer::StrokePlain::encoded() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
std::unique_ptr<MaterialStroke> Renderer::StrokeRadialGradient::clone() const
|
||||
{
|
||||
return std::make_unique<StrokeRadialGradient>(*this);
|
||||
}
|
||||
|
||||
bool Renderer::StrokeRadialGradient::operator==(const MaterialStroke& m) const
|
||||
{
|
||||
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
|
||||
{
|
||||
return MaterialStyleType::kStroke;
|
||||
|
@ -93,6 +97,11 @@ std::vector<GLfloat> Renderer::MaterialStyleStroke::encoded() const
|
|||
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
|
||||
{
|
||||
return type() == m.type() && *materialStroke == *static_cast<const MaterialStyleStroke&>(m).materialStroke;
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Renderer
|
|||
public:
|
||||
virtual MaterialStrokeType type() const = 0;
|
||||
virtual std::vector<GLfloat> encoded() const = 0;
|
||||
virtual std::unique_ptr<MaterialStroke> clone() const = 0;
|
||||
virtual bool operator==(const MaterialStroke&) const = 0;
|
||||
};
|
||||
|
||||
|
@ -20,7 +21,9 @@ namespace Renderer
|
|||
StrokePlain(QColor color, float metallic, float roughness);
|
||||
StrokePlain(const Material& material);
|
||||
virtual MaterialStrokeType type() const override;
|
||||
virtual std::unique_ptr<MaterialStroke> clone() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
|
||||
virtual bool operator==(const MaterialStroke&) const override;
|
||||
|
||||
Material material;
|
||||
|
@ -32,6 +35,7 @@ namespace Renderer
|
|||
StrokeRadialGradient(const std::map<float, Material>& materialMap, bool gradual);
|
||||
virtual MaterialStrokeType type() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
virtual std::unique_ptr<MaterialStroke> clone() const override;
|
||||
virtual bool operator==(const MaterialStroke&) const override;
|
||||
|
||||
std::map<float, Material> materialMap;
|
||||
|
@ -45,9 +49,9 @@ namespace Renderer
|
|||
{
|
||||
public:
|
||||
MaterialStyleStroke(float width, StrokeType strokeType, StrokeEndType endType, std::shared_ptr<MaterialStroke> materialStroke);
|
||||
MaterialStyleStroke(const MaterialStyleStroke&);
|
||||
virtual MaterialStyleType type() const override;
|
||||
virtual std::vector<GLfloat> encoded() const override;
|
||||
virtual std::unique_ptr<MaterialStyle> clone() const override;
|
||||
virtual bool operator==(const MaterialStyle&) const override;
|
||||
float getHalfWidth() const;
|
||||
//protected:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <QOpenGLFunctions_4_5_Core>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <vector>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QOpenGLShaderProgram>
|
||||
|
@ -18,8 +18,8 @@ namespace Renderer
|
|||
class PaintingMesh : public Drawable
|
||||
{
|
||||
public:
|
||||
QVector<Vertex> vertices;
|
||||
QVector<GLuint> indices;
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<GLuint> indices;
|
||||
GLuint textureBasecolor;
|
||||
GLuint textureMetallicRoughness;
|
||||
QMatrix4x4 model;
|
||||
|
|
|
@ -73,17 +73,14 @@ void RendererGLWidget::stopTimer()
|
|||
timerId = -1;
|
||||
}
|
||||
|
||||
void RendererGLWidget::setModel()
|
||||
void RendererGLWidget::setModel(QString path)
|
||||
{
|
||||
makeCurrent();
|
||||
model->loadModel("Models/Sponza/Sponza.gltf");
|
||||
//model = new Model("E:\\3D Objects\\gallery_gltf\\gallery_gltf.gltf", context(), modelProgramPtr, paintingProgramPtr, shadowProgramPtr, paintingHelper);
|
||||
//model->loadModel("Models/Sponza/Sponza.gltf");
|
||||
//model->loadModel("E:\\3D Objects\\Gate\\gltf\\Gate.gltf");
|
||||
model->loadModel(path);
|
||||
light.model = model;
|
||||
qDebug() << model->AABB;
|
||||
//paintingHelper->allocateBuffers();
|
||||
//paintingCompProgramPtr->bind();
|
||||
//paintingHelper->bindPaintingBuffers();
|
||||
//paintingCompProgramPtr->release();
|
||||
doneCurrent();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace Renderer
|
|||
void startTimer();
|
||||
void stopTimer();
|
||||
public slots:
|
||||
void setModel();
|
||||
void setModel(QString path);
|
||||
void setMainLightPitch(float pitch);
|
||||
void setMainLightYaw(float yaw);
|
||||
void setExposure(float exposure);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "RendererWidget.h"
|
||||
#include "RendererGLWidget.h"
|
||||
#include "../FluentMenu.h"
|
||||
#include <QFileDialog>
|
||||
|
||||
Renderer::RendererWidget::RendererWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
|
@ -10,8 +11,10 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
|
|||
FluentMenu* menu = new FluentMenu(this);
|
||||
auto openAction = new QAction(QStringLiteral("´ò¿ª"), menu);
|
||||
auto saveAction = new QAction(QStringLiteral("±£´æ"), menu);
|
||||
auto testAction = new QAction(QStringLiteral("²âÊÔ"), menu);
|
||||
menu->addAction(openAction);
|
||||
menu->addAction(saveAction);
|
||||
menu->addAction(testAction);
|
||||
|
||||
ui.openButton->setHaloVisible(false);
|
||||
ui.openButton->setOverlayStyle(::Material::TintedOverlay);
|
||||
|
@ -34,7 +37,16 @@ Renderer::RendererWidget::RendererWidget(QWidget* parent)
|
|||
QObject::connect(ui.exposureSlider, &QSlider::valueChanged, [&](int value) {
|
||||
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_2->setValue(80);
|
||||
|
|
Loading…
Reference in New Issue