diff --git a/application/sources/component_preview_grid_widget.cc b/application/sources/component_preview_grid_widget.cc index c6ca1ffd..fe969721 100644 --- a/application/sources/component_preview_grid_widget.cc +++ b/application/sources/component_preview_grid_widget.cc @@ -12,7 +12,14 @@ ComponentPreviewGridWidget::ComponentPreviewGridWidget(Document *document, QWidg connect(this, &ComponentPreviewGridWidget::doubleClicked, [this](const QModelIndex &index) { const SkeletonComponent *component = this->componentListModel()->modelIndexToComponent(index); - if (nullptr != component && !component->childrenIds.empty()) { + if (nullptr == component) + return; + if (component->childrenIds.empty()) { + std::vector partIds; + this->m_document->collectComponentDescendantParts(component->id, partIds); + for (const auto &partId: partIds) + emit this->selectPartOnCanvas(partId); + } else { this->componentListModel()->setListingComponentId(component->id); } }); diff --git a/application/sources/component_preview_grid_widget.h b/application/sources/component_preview_grid_widget.h index 7b22f3d7..2393d928 100644 --- a/application/sources/component_preview_grid_widget.h +++ b/application/sources/component_preview_grid_widget.h @@ -5,13 +5,17 @@ #include #include #include "preview_grid_view.h" +#include "component_list_model.h" -class ComponentListModel; class Document; class SkeletonComponent; class ComponentPreviewGridWidget: public PreviewGridView { + Q_OBJECT +signals: + void unselectAllOnCanvas(); + void selectPartOnCanvas(const dust3d::Uuid &partId); public: ComponentPreviewGridWidget(Document *document, QWidget *parent=nullptr); ComponentListModel *componentListModel(); diff --git a/application/sources/part_manage_widget.cc b/application/sources/part_manage_widget.cc index 353b0a39..6a189bfc 100644 --- a/application/sources/part_manage_widget.cc +++ b/application/sources/part_manage_widget.cc @@ -46,6 +46,8 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent): connect(m_componentPreviewGridWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &PartManageWidget::updateToolButtons); connect(m_componentPreviewGridWidget->componentListModel(), &ComponentListModel::listingComponentChanged, this, &PartManageWidget::updateLevelUpButton); + connect(m_componentPreviewGridWidget, &ComponentPreviewGridWidget::unselectAllOnCanvas, this, &PartManageWidget::unselectAllOnCanvas); + connect(m_componentPreviewGridWidget, &ComponentPreviewGridWidget::selectPartOnCanvas, this, &PartManageWidget::selectPartOnCanvas); connect(m_levelUpButton, &QPushButton::clicked, [this]() { const auto &parent = m_document->findComponentParent(this->m_componentPreviewGridWidget->componentListModel()->listingComponentId()); diff --git a/application/sources/theme.cc b/application/sources/theme.cc index 06e1470a..faa4a5fa 100644 --- a/application/sources/theme.cc +++ b/application/sources/theme.cc @@ -55,7 +55,7 @@ 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 * 2); + Theme::partPreviewImageSize = (Theme::miniIconSize * 2.3); Theme::sidebarPreferredWidth = Theme::partPreviewImageSize * 4.5; Theme::materialPreviewImageSize = Theme::sidebarPreferredWidth * 0.4; Theme::previewIconBorderSize = std::max(1, Theme::partPreviewImageSize / 20); diff --git a/dust3d/base/debug.h b/dust3d/base/debug.h index a071bbe2..e53a4d32 100644 --- a/dust3d/base/debug.h +++ b/dust3d/base/debug.h @@ -75,7 +75,7 @@ private: #define DEBUG_STRINGIZE1(x) #x #define DEBUG_STRINGIZE2(x) DEBUG_STRINGIZE1(x) -#define dust3dDebug dust3d::Debug() << __FILE__ "(" DEBUG_STRINGIZE2(__LINE__) "):" +#define dust3dDebug dust3d::Debug() << __FILE__ "(" DEBUG_STRINGIZE2(__LINE__) ")#" << __func__ << ":" #endif diff --git a/dust3d/mesh/rope_mesh.cc b/dust3d/mesh/rope_mesh.cc index 7d2a20ab..6c2f7e9e 100644 --- a/dust3d/mesh/rope_mesh.cc +++ b/dust3d/mesh/rope_mesh.cc @@ -121,14 +121,19 @@ Vector3 RopeMesh::calculateTubeBaseNormal(const std::vector &vertices) void RopeMesh::addRope(const std::vector &positions, bool isCircle) { + if (positions.size() < 2) { + dust3dDebug << "Expected at least 2 nodes, current:" << positions.size(); + return; + } Vector3 baseNormal = isCircle ? calculateCircleBaseNormal(positions) : calculateTubeBaseNormal(positions); std::vector> circles; circles.reserve(positions.size()); - for (size_t j = isCircle ? 0 : 1; j < positions.size(); ++j) { - size_t i = (j + positions.size() - 1) % positions.size(); + Vector3 forwardDirection = (positions[1] - positions[0]).normalized(); + for (size_t i = isCircle ? 0 : 1; i < positions.size(); ++i) { + size_t j = (i + 1) % positions.size(); auto circlePositions = calculateCircleVertices(m_buildParameters.defaultRadius, m_buildParameters.sectionSegments, - (positions[j] - positions[i]).normalized(), + forwardDirection, baseNormal, positions[i]); std::vector indices(circlePositions.size()); @@ -137,6 +142,7 @@ void RopeMesh::addRope(const std::vector &positions, bool isCircle) m_resultVertices.push_back(circlePositions[k]); } circles.emplace_back(indices); + forwardDirection = (positions[j] - positions[i]).normalized(); } for (size_t j = isCircle ? 0 : 1; j < circles.size(); ++j) { size_t i = (j + circles.size() - 1) % circles.size(); diff --git a/dust3d/mesh/rope_mesh.h b/dust3d/mesh/rope_mesh.h index c2ed7ef3..bc038e53 100644 --- a/dust3d/mesh/rope_mesh.h +++ b/dust3d/mesh/rope_mesh.h @@ -34,8 +34,8 @@ class RopeMesh public: struct BuildParameters { - double defaultRadius = 0.01; - size_t sectionSegments = 5; + double defaultRadius = 0.008; + size_t sectionSegments = 8; }; RopeMesh(const BuildParameters ¶meters);