Skip to content

Commit

Permalink
Implement point selection for edge addition in meshimporter (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Nov 17, 2023
1 parent 5c460cb commit 0fbfa2e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,11 @@ bool osc::AddStationAtLocation(

return AddStationAtLocation(cmg, *el, loc);
}

bool osc::CreateEdgeBetween(
CommittableModelGraph&,
UID,
UID)
{
return true; // TODO
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ namespace osc
UID elID,
Vec3 const& loc
);

bool CreateEdgeBetween(
CommittableModelGraph&,
UID firstSideID,
UID secondSideID
);
}
44 changes: 42 additions & 2 deletions src/OpenSimCreator/UI/Tabs/MeshImporter/MeshImporterTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,46 @@ class osc::MeshImporterTab::Impl final : public MeshImporterUILayerHost {
m_Maybe3DViewerModal = std::make_shared<ChooseElLayer>(*this, m_Shared, opts);
}

void transitionToPickingEdgeElSecondSide(SceneEl const& firstSide)
{
ChooseElLayerOptions opts;
opts.canChooseBodies = true;
opts.canChooseGround = true;
opts.canChooseJoints = true;
opts.canChooseMeshes = true;
opts.maybeElsAttachingTo = {firstSide.getID()};
opts.header = "choose other edge side";
opts.onUserChoice = [shared = m_Shared, firstSideID = firstSide.getID()](std::span<UID> choices)
{
if (choices.empty())
{
return false;
}
return CreateEdgeBetween(shared->updCommittableModelGraph(), firstSideID, choices.front());
};
m_Maybe3DViewerModal = std::make_shared<ChooseElLayer>(*this, m_Shared, opts);
}

void transitionToChoosingBothEdgeElSides()
{
ChooseElLayerOptions opts;
opts.canChooseBodies = true;
opts.canChooseGround = true;
opts.canChooseJoints = true;
opts.canChooseMeshes = true;
opts.numElementsUserMustChoose = 2;
opts.header = "choose two points for edge";
opts.onUserChoice = [shared = m_Shared](std::span<UID> choices)
{
if (choices.size() < 2)
{
return false;
}
return CreateEdgeBetween(shared->updCommittableModelGraph(), choices[0], choices[1]);
};
m_Maybe3DViewerModal = std::make_shared<ChooseElLayer>(*this, m_Shared, opts);
}

// ensure any stale references into the modelgrah are cleaned up
void garbageCollectStaleRefs()
{
Expand Down Expand Up @@ -1090,7 +1130,7 @@ class osc::MeshImporterTab::Impl final : public MeshImporterUILayerHost {
{
if (ImGui::MenuItem(ICON_FA_ARROWS_ALT "Edge"))
{
// TODO: transition into picking the other side of the edge
transitionToPickingEdgeElSecondSide(el);
}
osc::DrawTooltipIfItemHovered("Add Edge", EdgeEl::Class().getDescription());
}
Expand Down Expand Up @@ -1749,7 +1789,7 @@ class osc::MeshImporterTab::Impl final : public MeshImporterUILayerHost {

if (ImGui::MenuItem(ICON_FA_ARROWS_ALT " Edge"))
{
// TODO: transition into selecting two elements (or cancelling)
transitionToChoosingBothEdgeElSides();
}
osc::DrawTooltipIfItemHovered("Add Edge", EdgeEl::Class().getDescription());

Expand Down

0 comments on commit 0fbfa2e

Please sign in to comment.