Skip to content

Commit

Permalink
#5746: Implement "Merge selected" for face vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 26, 2021
1 parent 2b76d72 commit 8e879ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion radiantcore/selection/textool/FaceNode.h
Expand Up @@ -193,7 +193,16 @@ class FaceNode :

void mergeComponentsWith(const Vector2& center) override
{
// TODO
// We can only merge exactly one of the face vertices, keep track
bool centerAssigned = false;

transformSelectedAndRecalculateTexDef([&](Vector2& selectedTexcoord)
{
if (centerAssigned) return;

selectedTexcoord = center;
centerAssigned = true;
});
}

private:
Expand Down
14 changes: 12 additions & 2 deletions test/TextureTool.cpp
Expand Up @@ -1873,12 +1873,22 @@ TEST_F(TextureToolTest, MergeTwoVerticesOfSameFace)
EXPECT_NE(vertex1.x(), vertex2.x()) << "Vertex 1 is alredy merged with Vertex 2";
EXPECT_NE(vertex1.y(), vertex2.y()) << "Vertex 1 is alredy merged with Vertex 2";

// We expect the vertices to be at the center if merge items is called with no arguments
auto center = (vertex1 + vertex2 + vertex3) / 3;
AABB selectionBounds;

GlobalTextureToolSelectionSystem().foreachSelectedComponentNode([&](const textool::INode::Ptr& node)
{
auto componentSelectable = std::dynamic_pointer_cast<textool::IComponentSelectable>(node);
if (!componentSelectable) return true;

selectionBounds.includeAABB(componentSelectable->getSelectedComponentBounds());

return true;
});

GlobalCommandSystem().executeCommand("TexToolMergeItems");

// Only one face vertex should be at the center
auto center = selectionBounds.origin;
EXPECT_TRUE((vertex1.x() == center.x() && vertex1.y() == center.y()) ||
(vertex1.x() == center.x() && vertex3.y() == center.y()))
<< "Vertex 1 or 3 should be at center " << center;
Expand Down

0 comments on commit 8e879ee

Please sign in to comment.