Fix rope mesh builder
parent
5b06f64fdd
commit
c3f70e982c
|
@ -12,7 +12,14 @@ ComponentPreviewGridWidget::ComponentPreviewGridWidget(Document *document, QWidg
|
||||||
|
|
||||||
connect(this, &ComponentPreviewGridWidget::doubleClicked, [this](const QModelIndex &index) {
|
connect(this, &ComponentPreviewGridWidget::doubleClicked, [this](const QModelIndex &index) {
|
||||||
const SkeletonComponent *component = this->componentListModel()->modelIndexToComponent(index);
|
const SkeletonComponent *component = this->componentListModel()->modelIndexToComponent(index);
|
||||||
if (nullptr != component && !component->childrenIds.empty()) {
|
if (nullptr == component)
|
||||||
|
return;
|
||||||
|
if (component->childrenIds.empty()) {
|
||||||
|
std::vector<dust3d::Uuid> partIds;
|
||||||
|
this->m_document->collectComponentDescendantParts(component->id, partIds);
|
||||||
|
for (const auto &partId: partIds)
|
||||||
|
emit this->selectPartOnCanvas(partId);
|
||||||
|
} else {
|
||||||
this->componentListModel()->setListingComponentId(component->id);
|
this->componentListModel()->setListingComponentId(component->id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,13 +5,17 @@
|
||||||
#include <dust3d/base/uuid.h>
|
#include <dust3d/base/uuid.h>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include "preview_grid_view.h"
|
#include "preview_grid_view.h"
|
||||||
|
#include "component_list_model.h"
|
||||||
|
|
||||||
class ComponentListModel;
|
|
||||||
class Document;
|
class Document;
|
||||||
class SkeletonComponent;
|
class SkeletonComponent;
|
||||||
|
|
||||||
class ComponentPreviewGridWidget: public PreviewGridView
|
class ComponentPreviewGridWidget: public PreviewGridView
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
signals:
|
||||||
|
void unselectAllOnCanvas();
|
||||||
|
void selectPartOnCanvas(const dust3d::Uuid &partId);
|
||||||
public:
|
public:
|
||||||
ComponentPreviewGridWidget(Document *document, QWidget *parent=nullptr);
|
ComponentPreviewGridWidget(Document *document, QWidget *parent=nullptr);
|
||||||
ComponentListModel *componentListModel();
|
ComponentListModel *componentListModel();
|
||||||
|
|
|
@ -46,6 +46,8 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent):
|
||||||
|
|
||||||
connect(m_componentPreviewGridWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &PartManageWidget::updateToolButtons);
|
connect(m_componentPreviewGridWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &PartManageWidget::updateToolButtons);
|
||||||
connect(m_componentPreviewGridWidget->componentListModel(), &ComponentListModel::listingComponentChanged, this, &PartManageWidget::updateLevelUpButton);
|
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]() {
|
connect(m_levelUpButton, &QPushButton::clicked, [this]() {
|
||||||
const auto &parent = m_document->findComponentParent(this->m_componentPreviewGridWidget->componentListModel()->listingComponentId());
|
const auto &parent = m_document->findComponentParent(this->m_componentPreviewGridWidget->componentListModel()->listingComponentId());
|
||||||
|
|
|
@ -55,7 +55,7 @@ void Theme::initialize()
|
||||||
Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.5);
|
Theme::toolIconSize = (int)(Theme::toolIconFontSize * 1.5);
|
||||||
Theme::miniIconFontSize = (int)(Theme::toolIconFontSize * 0.85);
|
Theme::miniIconFontSize = (int)(Theme::toolIconFontSize * 0.85);
|
||||||
Theme::miniIconSize = (int)(Theme::miniIconFontSize * 1.67);
|
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::sidebarPreferredWidth = Theme::partPreviewImageSize * 4.5;
|
||||||
Theme::materialPreviewImageSize = Theme::sidebarPreferredWidth * 0.4;
|
Theme::materialPreviewImageSize = Theme::sidebarPreferredWidth * 0.4;
|
||||||
Theme::previewIconBorderSize = std::max(1, Theme::partPreviewImageSize / 20);
|
Theme::previewIconBorderSize = std::max(1, Theme::partPreviewImageSize / 20);
|
||||||
|
|
|
@ -75,7 +75,7 @@ private:
|
||||||
#define DEBUG_STRINGIZE1(x) #x
|
#define DEBUG_STRINGIZE1(x) #x
|
||||||
#define DEBUG_STRINGIZE2(x) DEBUG_STRINGIZE1(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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -121,14 +121,19 @@ Vector3 RopeMesh::calculateTubeBaseNormal(const std::vector<Vector3> &vertices)
|
||||||
|
|
||||||
void RopeMesh::addRope(const std::vector<Vector3> &positions, bool isCircle)
|
void RopeMesh::addRope(const std::vector<Vector3> &positions, bool isCircle)
|
||||||
{
|
{
|
||||||
|
if (positions.size() < 2) {
|
||||||
|
dust3dDebug << "Expected at least 2 nodes, current:" << positions.size();
|
||||||
|
return;
|
||||||
|
}
|
||||||
Vector3 baseNormal = isCircle ? calculateCircleBaseNormal(positions) : calculateTubeBaseNormal(positions);
|
Vector3 baseNormal = isCircle ? calculateCircleBaseNormal(positions) : calculateTubeBaseNormal(positions);
|
||||||
std::vector<std::vector<size_t>> circles;
|
std::vector<std::vector<size_t>> circles;
|
||||||
circles.reserve(positions.size());
|
circles.reserve(positions.size());
|
||||||
for (size_t j = isCircle ? 0 : 1; j < positions.size(); ++j) {
|
Vector3 forwardDirection = (positions[1] - positions[0]).normalized();
|
||||||
size_t i = (j + positions.size() - 1) % positions.size();
|
for (size_t i = isCircle ? 0 : 1; i < positions.size(); ++i) {
|
||||||
|
size_t j = (i + 1) % positions.size();
|
||||||
auto circlePositions = calculateCircleVertices(m_buildParameters.defaultRadius,
|
auto circlePositions = calculateCircleVertices(m_buildParameters.defaultRadius,
|
||||||
m_buildParameters.sectionSegments,
|
m_buildParameters.sectionSegments,
|
||||||
(positions[j] - positions[i]).normalized(),
|
forwardDirection,
|
||||||
baseNormal,
|
baseNormal,
|
||||||
positions[i]);
|
positions[i]);
|
||||||
std::vector<size_t> indices(circlePositions.size());
|
std::vector<size_t> indices(circlePositions.size());
|
||||||
|
@ -137,6 +142,7 @@ void RopeMesh::addRope(const std::vector<Vector3> &positions, bool isCircle)
|
||||||
m_resultVertices.push_back(circlePositions[k]);
|
m_resultVertices.push_back(circlePositions[k]);
|
||||||
}
|
}
|
||||||
circles.emplace_back(indices);
|
circles.emplace_back(indices);
|
||||||
|
forwardDirection = (positions[j] - positions[i]).normalized();
|
||||||
}
|
}
|
||||||
for (size_t j = isCircle ? 0 : 1; j < circles.size(); ++j) {
|
for (size_t j = isCircle ? 0 : 1; j < circles.size(); ++j) {
|
||||||
size_t i = (j + circles.size() - 1) % circles.size();
|
size_t i = (j + circles.size() - 1) % circles.size();
|
||||||
|
|
|
@ -34,8 +34,8 @@ class RopeMesh
|
||||||
public:
|
public:
|
||||||
struct BuildParameters
|
struct BuildParameters
|
||||||
{
|
{
|
||||||
double defaultRadius = 0.01;
|
double defaultRadius = 0.008;
|
||||||
size_t sectionSegments = 5;
|
size_t sectionSegments = 8;
|
||||||
};
|
};
|
||||||
|
|
||||||
RopeMesh(const BuildParameters ¶meters);
|
RopeMesh(const BuildParameters ¶meters);
|
||||||
|
|
Loading…
Reference in New Issue