Add part round end

master
Jeremy HU 2022-10-17 21:29:40 +11:00
parent 73c13a9cb4
commit d075ee3ba7
5 changed files with 42 additions and 0 deletions

View File

@ -164,8 +164,19 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document *document,
emit groupOperationAdded();
});
QCheckBox *roundEndStateBox = new QCheckBox();
Theme::initCheckbox(roundEndStateBox);
roundEndStateBox->setText(tr("Round end"));
roundEndStateBox->setChecked(m_part->rounded);
connect(roundEndStateBox, &QCheckBox::stateChanged, this, [=]() {
emit setPartRoundState(m_partId, roundEndStateBox->isChecked());
emit groupOperationAdded();
});
QHBoxLayout *optionsLayout = new QHBoxLayout;
optionsLayout->addStretch();
optionsLayout->addWidget(roundEndStateBox);
optionsLayout->addWidget(chamferStateBox);
optionsLayout->addWidget(subdivStateBox);
@ -194,6 +205,7 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document *document,
connect(this, &ComponentPropertyWidget::setPartCutRotation, m_document, &Document::setPartCutRotation);
connect(this, &ComponentPropertyWidget::setPartSubdivState, m_document, &Document::setPartSubdivState);
connect(this, &ComponentPropertyWidget::setPartChamferState, m_document, &Document::setPartChamferState);
connect(this, &ComponentPropertyWidget::setPartRoundState, m_document, &Document::setPartRoundState);
connect(this, &ComponentPropertyWidget::groupOperationAdded, m_document, &Document::saveSnapshot);
setLayout(mainLayout);

View File

@ -19,6 +19,7 @@ signals:
void setPartDeformUnified(const dust3d::Uuid &partId, bool unified);
void setPartSubdivState(const dust3d::Uuid &partId, bool subdived);
void setPartChamferState(const dust3d::Uuid &partId, bool chamfered);
void setPartRoundState(const dust3d::Uuid &partId, bool rounded);
void setPartCutRotation(const dust3d::Uuid &partId, float cutRotation);
void groupOperationAdded();
public:

View File

@ -664,6 +664,7 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combinePartMesh(const std::st
buildParameters.deformUnified = deformUnified;
buildParameters.baseNormalRotation = cutRotation * Math::Pi;
buildParameters.cutFace = cutTemplate;
buildParameters.frontEndRounded = buildParameters.backEndRounded = rounded;
auto tubeMeshBuilder = std::make_unique<TubeMeshBuilder>(buildParameters, std::move(meshNodes), isCircle);
tubeMeshBuilder->build();

View File

@ -49,8 +49,33 @@ const std::vector<std::vector<size_t>> &TubeMeshBuilder::generatedFaces()
return m_generatedFaces;
}
void TubeMeshBuilder::applyRoundEnd()
{
if (m_isCircle)
return;
if (m_nodes.size() <= 1)
return;
if (m_buildParameters.frontEndRounded) {
auto newNode = m_nodes.front();
newNode.radius *= 0.5;
newNode.origin += (m_nodes[0].origin - m_nodes[1].origin).normalized() * newNode.radius;
m_nodes.insert(m_nodes.begin(), newNode);
}
if (m_buildParameters.backEndRounded) {
auto newNode = m_nodes.back();
newNode.radius *= 0.5;
newNode.origin += (m_nodes[m_nodes.size() - 1].origin - m_nodes[m_nodes.size() - 2].origin).normalized() * newNode.radius;
m_nodes.emplace_back(newNode);
}
}
void TubeMeshBuilder::preprocessNodes()
{
applyRoundEnd();
// TODO: Interpolate...
}

View File

@ -41,6 +41,8 @@ public:
double deformWidth = 1.0;
bool deformUnified = false;
double baseNormalRotation = 0.0;
bool frontEndRounded = false;
bool backEndRounded = false;
};
TubeMeshBuilder(const BuildParameters &buildParameters, std::vector<MeshNode> &&nodes, bool isCircle);
@ -64,6 +66,7 @@ private:
std::vector<Vector3> buildCutFaceVertices(const Vector3 &origin,
double radius,
const Vector3 &forwardDirection);
void applyRoundEnd();
};
};