diff --git a/application/sources/component_list_model.cc b/application/sources/component_list_model.cc index 357641a5..d5a0ab0a 100644 --- a/application/sources/component_list_model.cc +++ b/application/sources/component_list_model.cc @@ -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) { diff --git a/application/sources/component_list_model.h b/application/sources/component_list_model.h index aa8e4c31..95e3bb8f 100644 --- a/application/sources/component_list_model.h +++ b/application/sources/component_list_model.h @@ -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); diff --git a/application/sources/component_preview_grid_widget.cc b/application/sources/component_preview_grid_widget.cc index c9306bd4..c6ca1ffd 100644 --- a/application/sources/component_preview_grid_widget.cc +++ b/application/sources/component_preview_grid_widget.cc @@ -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 ComponentPreviewGridWidget::getSelectedCo std::vector 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 ComponentPreviewGridWidget::getSelectedComponentIds() const +{ + std::vector 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 ComponentPreviewGridWidget::getSelectedPartIds() const +{ + auto selectedComponents = getSelectedComponents(); + std::vector partIds; + for (const auto &component: selectedComponents) { + if (component->linkToPartId.isNull()) + continue; + partIds.push_back(component->linkToPartId); + } + return partIds; +} diff --git a/application/sources/component_preview_grid_widget.h b/application/sources/component_preview_grid_widget.h index 7b94f044..7b22f3d7 100644 --- a/application/sources/component_preview_grid_widget.h +++ b/application/sources/component_preview_grid_widget.h @@ -2,6 +2,7 @@ #define DUST3D_APPLICATION_COMPONENT_PREVIEW_GRID_WIDGET_H_ #include +#include #include #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 getSelectedComponents() const; + std::vector getSelectedComponentIds() const; + std::vector getSelectedPartIds() const; private: std::unique_ptr m_componentListModel; - const Document *m_document = nullptr; + Document *m_document = nullptr; }; #endif diff --git a/application/sources/part_manage_widget.cc b/application/sources/part_manage_widget.cc index b85cc523..e3bea5fb 100644 --- a/application/sources/part_manage_widget.cc +++ b/application/sources/part_manage_widget.cc @@ -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); diff --git a/application/sources/part_manage_widget.h b/application/sources/part_manage_widget.h index 9f418a81..c16ec87b 100644 --- a/application/sources/part_manage_widget.h +++ b/application/sources/part_manage_widget.h @@ -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; diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index b9a72a4b..09c19d1d 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -816,9 +816,9 @@ std::unique_ptr 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 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 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>> combineGroups; int currentGroupIndex = -1;