Define preview grid view style

master
Jeremy HU 2022-10-03 09:04:46 +11:00
parent b7b71b9c2e
commit efc6c09bbd
7 changed files with 45 additions and 97 deletions

View File

@ -7,10 +7,15 @@ ComponentListModel::ComponentListModel(const Document *document, QObject *parent
QAbstractListModel(parent),
m_document(document)
{
connect(m_document, &Document::componentPreviewImageChanged, [this](const dust3d::Uuid &componentId) {
emit this->layoutChanged();
});
}
int ComponentListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
const SkeletonComponent *listingComponent = m_document->findComponent(m_listingComponentId);
if (nullptr == listingComponent)
return 0;
@ -19,6 +24,8 @@ int ComponentListModel::rowCount(const QModelIndex &parent) const
int ComponentListModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return 1;
}
@ -53,7 +60,7 @@ QVariant ComponentListModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole: {
const SkeletonComponent *component = modelIndexToComponent(index);
if (nullptr != component) {
// TODO:
return component->previewPixmap;
}
}
break;

View File

@ -13,45 +13,6 @@ MonochromeMesh::MonochromeMesh(MonochromeMesh &&mesh)
MonochromeMesh::MonochromeMesh(const dust3d::Object &object)
{
/*
auto buildSection = [](const dust3d::Vector3 &origin,
const dust3d::Vector3 &faceNormal,
const dust3d::Vector3 &tagent,
double radius)
{
auto upDirection = dust3d::Vector3::crossProduct(tagent, faceNormal);
return std::vector<dust3d::Vector3> {
origin + tagent * radius,
origin - upDirection * radius,
origin - tagent * radius,
origin + upDirection * radius
};
};
auto calculateTagent = [](const dust3d::Vector3 &direction) {
const std::vector<dust3d::Vector3> axisList = {
dust3d::Vector3 {1, 0, 0},
dust3d::Vector3 {0, 1, 0},
dust3d::Vector3 {0, 0, 1},
};
float maxDot = -1;
size_t nearAxisIndex = 0;
bool reversed = false;
for (size_t i = 0; i < axisList.size(); ++i) {
const auto axis = axisList[i];
auto dot = dust3d::Vector3::dotProduct(axis, direction);
auto positiveDot = std::abs(dot);
if (positiveDot >= maxDot) {
reversed = dot < 0;
maxDot = positiveDot;
nearAxisIndex = i;
}
}
const auto& choosenAxis = axisList[(nearAxisIndex + 1) % 3];
auto startDirection = dust3d::Vector3::crossProduct(direction, choosenAxis).normalized();
return reversed ? -startDirection : startDirection;
};
*/
std::set<std::pair<size_t, size_t>> halfEdges;
for (const auto &face: object.triangleAndQuads) {
if (3 == face.size()) {
@ -72,7 +33,6 @@ MonochromeMesh::MonochromeMesh(const dust3d::Object &object)
halfEdges.insert({face[3], face[0]});
halfEdges.insert({face[0], face[3]});
}
//m_triangleVertices.reserve(halfEdges.size() * 24);
m_lineVertices.reserve(halfEdges.size() * 2);
for (const auto &halfEdge: halfEdges) {
// For two halfedges shared one edge, only output one line
@ -90,50 +50,6 @@ MonochromeMesh::MonochromeMesh(const dust3d::Object &object)
(GLfloat)to.y(),
(GLfloat)to.z()
});
/*
auto direction = to - from;
auto sectionNormal = direction.normalized();
auto sectionTagent = calculateTagent(sectionNormal);
auto sectionTo = buildSection(to, sectionNormal, sectionTagent, 0.002);
auto sectionFrom = sectionTo;
for (auto &it: sectionFrom)
it = it - direction;
for (size_t i = 0; i < sectionTo.size(); ++i) {
size_t j = (i + 1) % sectionTo.size();
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionTo[i].x(),
(GLfloat)sectionTo[i].y(),
(GLfloat)sectionTo[i].z()
});
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionFrom[i].x(),
(GLfloat)sectionFrom[i].y(),
(GLfloat)sectionFrom[i].z()
});
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionTo[j].x(),
(GLfloat)sectionTo[j].y(),
(GLfloat)sectionTo[j].z()
});
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionFrom[i].x(),
(GLfloat)sectionFrom[i].y(),
(GLfloat)sectionFrom[i].z()
});
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionFrom[j].x(),
(GLfloat)sectionFrom[j].y(),
(GLfloat)sectionFrom[j].z()
});
m_triangleVertices.emplace_back(MonochromeOpenGLVertex {
(GLfloat)sectionTo[j].x(),
(GLfloat)sectionTo[j].y(),
(GLfloat)sectionTo[j].z()
});
}
*/
}
}

View File

@ -4,8 +4,22 @@
PreviewGridView::PreviewGridView(QWidget *parent):
QListView(parent)
{
QPalette viewPalette = palette();
viewPalette.setColor(QPalette::Window, Qt::transparent);
viewPalette.setColor(QPalette::Base, Qt::transparent);
setPalette(viewPalette);
auto borderSize = std::max(1, Theme::partPreviewImageSize / 20);
auto margin = std::max(1, borderSize / 2);
auto borderRadius = std::max(3, Theme::partPreviewImageSize / 10);
setStyleSheet(
"QListView::item {border:" + QString::number(borderSize) + "px solid transparent; margin:" + QString::number(margin) + "px; background-color: " + Theme::gray.name() +"; border-radius: " + QString::number(borderRadius) + ";}" +
"QListView::item:selected {border-color: " + Theme::red.name() + ";}"
);
setViewMode(QListView::IconMode);
setGridSize(QSize(Theme::partPreviewImageSize, Theme::partPreviewImageSize));
setMovement(QListView::Snap);
setFlow(QListView::LeftToRight);
setSelectionMode(QAbstractItemView::ExtendedSelection);
}

View File

@ -9,6 +9,8 @@ QColor Theme::white = QColor(0xf7, 0xd9, 0xc8);
QColor Theme::red = QColor(0xfc, 0x66, 0x21);
QColor Theme::green = QColor(0xaa, 0xeb, 0xc4);
QColor Theme::blue = QColor(0x0d, 0xa9, 0xf1);
QColor Theme::black = QColor(25, 25, 25);
QColor Theme::gray = QColor(0x32, 0x32, 0x32);
float Theme::normalAlpha = 96.0 / 255;
float Theme::checkedAlpha = 1.0;
float Theme::edgeAlpha = 1.0;
@ -50,8 +52,8 @@ void Theme::initialize()
Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.5);
Theme::miniIconFontSize = (int)(Theme::toolIconFontSize * 0.85);
Theme::miniIconSize = (int)(Theme::miniIconFontSize * 1.67);
Theme::partPreviewImageSize = (Theme::miniIconSize * 3);
Theme::sidebarPreferredWidth = Theme::partPreviewImageSize * 4;
Theme::partPreviewImageSize = (Theme::miniIconSize * 2);
Theme::sidebarPreferredWidth = Theme::partPreviewImageSize * 4.5;
Theme::materialPreviewImageSize = Theme::sidebarPreferredWidth * 0.4;
}

View File

@ -15,6 +15,8 @@ public:
static QColor red;
static QColor green;
static QColor blue;
static QColor black;
static QColor gray;
static float normalAlpha;
static float checkedAlpha;
static float edgeAlpha;

View File

@ -586,8 +586,9 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
partCache.objectNodeVertices.clear();
partCache.vertices.clear();
partCache.faces.clear();
partCache.previewTriangles.clear();
partCache.previewVertices.clear();
partCache.color = partColor;
partCache.metalness = metalness;
partCache.roughness = roughness;
partCache.isSuccessful = false;
partCache.joined = (target == PartTarget::Model && !isDisabled);
@ -806,6 +807,10 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
} else {
hasMeshError = true;
}
if (nullptr != mesh) {
partCache.isSuccessful = true;
}
if (mesh && mesh->isNull()) {
mesh.reset();
@ -934,7 +939,13 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
componentCache.objectEdges.push_back(it);
for (const auto &it: partCache.objectNodeVertices)
componentCache.objectNodeVertices.push_back(it);
addComponentPreview(componentId, ComponentPreview {partCache.vertices, partCache.faces});
ComponentPreview preview;
if (mesh)
mesh->fetch(preview.vertices, preview.triangles);
preview.color = partCache.color;
preview.metalness = partCache.metalness;
preview.roughness = partCache.roughness;
addComponentPreview(componentId, std::move(preview));
} else {
std::vector<std::pair<CombineMode, std::vector<std::string>>> combineGroups;
int currentGroupIndex = -1;
@ -1185,11 +1196,6 @@ void MeshGenerator::collectErroredParts()
updateVertexIndices(errorTriangleAndQuads, m_object->vertices.size());
m_object->vertices.insert(m_object->vertices.end(), it.second.vertices.begin(), it.second.vertices.end());
m_object->triangleAndQuads.insert(m_object->triangleAndQuads.end(), errorTriangleAndQuads.begin(), errorTriangleAndQuads.end());
auto errorTriangles = it.second.previewTriangles;
updateVertexIndices(errorTriangles, m_object->vertices.size());
m_object->vertices.insert(m_object->vertices.end(), it.second.previewVertices.begin(), it.second.previewVertices.end());
m_object->triangles.insert(m_object->triangles.end(), errorTriangles.begin(), errorTriangles.end());
}
}
}

View File

@ -50,8 +50,9 @@ public:
std::vector<ObjectNode> objectNodes;
std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges;
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices;
std::vector<Vector3> previewVertices;
std::vector<std::vector<size_t>> previewTriangles;
Color color = Color(1.0, 1.0, 1.0);
float metalness = 0.0;
float roughness = 1.0;
bool isSuccessful = false;
bool joined = true;
};