Implement tool button actions

master
Jeremy HU 2022-10-04 22:45:21 +11:00
parent 9a6f0c39f8
commit 03a9be6d4f
7 changed files with 114 additions and 19 deletions

View File

@ -48,6 +48,19 @@ const SkeletonComponent *ComponentListModel::modelIndexToComponent(const QModelI
return component;
}
const dust3d::Uuid ComponentListModel::modelIndexToComponentId(const QModelIndex &index) const
{
const SkeletonComponent *listingComponent = m_document->findComponent(m_listingComponentId);
if (nullptr == listingComponent)
return dust3d::Uuid();
if (index.row() >= (int)listingComponent->childrenIds.size()) {
dust3dDebug << "Component list row is out of range, size:" << listingComponent->childrenIds.size() << "row:" << index.row();
return dust3d::Uuid();
}
const auto &componentId = listingComponent->childrenIds[index.row()];
return componentId;
}
QVariant ComponentListModel::data(const QModelIndex &index, int role) const
{
switch (role) {

View File

@ -18,6 +18,7 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
const SkeletonComponent *modelIndexToComponent(const QModelIndex &index) const;
const dust3d::Uuid modelIndexToComponentId(const QModelIndex &index) const;
const dust3d::Uuid listingComponentId() const;
public slots:
void setListingComponentId(const dust3d::Uuid &componentId);

View File

@ -3,7 +3,7 @@
#include "component_list_model.h"
#include "document.h"
ComponentPreviewGridWidget::ComponentPreviewGridWidget(const Document *document, QWidget *parent):
ComponentPreviewGridWidget::ComponentPreviewGridWidget(Document *document, QWidget *parent):
PreviewGridView(parent),
m_document(document)
{
@ -28,7 +28,35 @@ std::vector<const SkeletonComponent *> ComponentPreviewGridWidget::getSelectedCo
std::vector<const SkeletonComponent *> components;
QModelIndexList selected = selectionModel()->selectedIndexes();
for (const auto &it: selected) {
components.push_back(m_componentListModel->modelIndexToComponent(it));
const auto &component = m_componentListModel->modelIndexToComponent(it);
if (nullptr == component)
continue;
components.push_back(component);
}
return components;
}
std::vector<dust3d::Uuid> ComponentPreviewGridWidget::getSelectedComponentIds() const
{
std::vector<dust3d::Uuid> componentIds;
QModelIndexList selected = selectionModel()->selectedIndexes();
for (const auto &it: selected) {
const auto &componentId = m_componentListModel->modelIndexToComponentId(it);
if (componentId.isNull())
continue;
componentIds.push_back(componentId);
}
return componentIds;
}
std::vector<dust3d::Uuid> ComponentPreviewGridWidget::getSelectedPartIds() const
{
auto selectedComponents = getSelectedComponents();
std::vector<dust3d::Uuid> partIds;
for (const auto &component: selectedComponents) {
if (component->linkToPartId.isNull())
continue;
partIds.push_back(component->linkToPartId);
}
return partIds;
}

View File

@ -2,6 +2,7 @@
#define DUST3D_APPLICATION_COMPONENT_PREVIEW_GRID_WIDGET_H_
#include <memory>
#include <dust3d/base/uuid.h>
#include <QAbstractListModel>
#include "preview_grid_view.h"
@ -12,12 +13,14 @@ class SkeletonComponent;
class ComponentPreviewGridWidget: public PreviewGridView
{
public:
ComponentPreviewGridWidget(const Document *document, QWidget *parent=nullptr);
ComponentPreviewGridWidget(Document *document, QWidget *parent=nullptr);
ComponentListModel *componentListModel();
std::vector<const SkeletonComponent *> getSelectedComponents() const;
std::vector<dust3d::Uuid> getSelectedComponentIds() const;
std::vector<dust3d::Uuid> getSelectedPartIds() const;
private:
std::unique_ptr<ComponentListModel> m_componentListModel;
const Document *m_document = nullptr;
Document *m_document = nullptr;
};
#endif

View File

@ -5,7 +5,7 @@
#include "theme.h"
#include "document.h"
PartManageWidget::PartManageWidget(const Document *document, QWidget *parent):
PartManageWidget::PartManageWidget(Document *document, QWidget *parent):
QWidget(parent),
m_document(document)
{
@ -52,6 +52,50 @@ PartManageWidget::PartManageWidget(const Document *document, QWidget *parent):
this->m_componentPreviewGridWidget->componentListModel()->setListingComponentId(parent->id);
});
connect(m_hideButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartVisibleState(partId, false);
this->m_document->saveSnapshot();
});
connect(m_showButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartVisibleState(partId, true);
this->m_document->saveSnapshot();
});
connect(m_unlockButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartLockState(partId, false);
this->m_document->saveSnapshot();
});
connect(m_lockButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartLockState(partId, true);
this->m_document->saveSnapshot();
});
connect(m_unlinkButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartDisableState(partId, true);
this->m_document->saveSnapshot();
});
connect(m_linkButton, &QPushButton::clicked, [this]() {
for (const auto &partId: m_componentPreviewGridWidget->getSelectedPartIds())
this->m_document->setPartDisableState(partId, false);
this->m_document->saveSnapshot();
});
connect(m_removeButton, &QPushButton::clicked, [this]() {
for (const auto &componentId: m_componentPreviewGridWidget->getSelectedComponentIds())
this->m_document->removeComponent(componentId);
this->m_document->saveSnapshot();
});
connect(m_document, &Document::partLockStateChanged, this, &PartManageWidget::updateToolButtons);
connect(m_document, &Document::partVisibleStateChanged, this, &PartManageWidget::updateToolButtons);
connect(m_document, &Document::partDisableStateChanged, this, &PartManageWidget::updateToolButtons);
connect(m_document, &Document::componentChildrenChanged, this, &PartManageWidget::updateToolButtons);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(toolsLayout);
mainLayout->addWidget(m_componentPreviewGridWidget);

View File

@ -11,9 +11,9 @@ class PartManageWidget : public QWidget
{
Q_OBJECT
public:
PartManageWidget(const Document *document, QWidget *parent=nullptr);
PartManageWidget(Document *document, QWidget *parent=nullptr);
private:
const Document *m_document = nullptr;
Document *m_document = nullptr;
ComponentPreviewGridWidget *m_componentPreviewGridWidget = nullptr;
QPushButton *m_levelUpButton = nullptr;
QPushButton *m_lockButton = nullptr;

View File

@ -816,9 +816,9 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
mesh.reset();
}
if (isDisabled) {
mesh.reset();
}
//if (isDisabled) {
// mesh.reset();
//}
if (target != PartTarget::Model) {
mesh.reset();
@ -930,15 +930,17 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
}
}
const auto &partCache = m_cacheContext->parts[partIdString];
for (const auto &vertex: partCache.vertices)
componentCache.noneSeamVertices.insert(vertex);
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
for (const auto &it: partCache.objectNodes)
componentCache.objectNodes.push_back(it);
for (const auto &it: partCache.objectEdges)
componentCache.objectEdges.push_back(it);
for (const auto &it: partCache.objectNodeVertices)
componentCache.objectNodeVertices.push_back(it);
if (partCache.joined) {
for (const auto &vertex: partCache.vertices)
componentCache.noneSeamVertices.insert(vertex);
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
for (const auto &it: partCache.objectNodes)
componentCache.objectNodes.push_back(it);
for (const auto &it: partCache.objectEdges)
componentCache.objectEdges.push_back(it);
for (const auto &it: partCache.objectNodeVertices)
componentCache.objectNodeVertices.push_back(it);
}
ComponentPreview preview;
if (mesh)
mesh->fetch(preview.vertices, preview.triangles);
@ -946,6 +948,10 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineComponentMesh(const st
preview.metalness = partCache.metalness;
preview.roughness = partCache.roughness;
addComponentPreview(componentId, std::move(preview));
if (!partCache.joined) {
if (mesh)
mesh.reset();
}
} else {
std::vector<std::pair<CombineMode, std::vector<std::string>>> combineGroups;
int currentGroupIndex = -1;