Skip to content

Commit

Permalink
#5746: Test for manipulating patch vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 19, 2021
1 parent 4a00a5a commit 66e019a
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 12 deletions.
57 changes: 45 additions & 12 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -284,11 +284,22 @@ Matrix4 TextureToolSelectionSystem::getPivot2World()

void TextureToolSelectionSystem::onManipulationStart()
{
foreachSelectedNode([&](const INode::Ptr& node)
if (getMode() == SelectionMode::Surface)
{
node->beginTransformation();
return true;
});
foreachSelectedNode([&](const INode::Ptr& node)
{
node->beginTransformation();
return true;
});
}
else
{
foreachSelectedComponentNode([&](const INode::Ptr& node)
{
node->beginTransformation();
return true;
});
}
}

void TextureToolSelectionSystem::onManipulationChanged()
Expand All @@ -297,22 +308,44 @@ void TextureToolSelectionSystem::onManipulationChanged()

void TextureToolSelectionSystem::onManipulationFinished()
{
foreachSelectedNode([&](const INode::Ptr& node)
if (getMode() == SelectionMode::Surface)
{
node->commitTransformation();
return true;
});
foreachSelectedNode([&](const INode::Ptr& node)
{
node->commitTransformation();
return true;
});
}
else
{
foreachSelectedComponentNode([&](const INode::Ptr& node)
{
node->commitTransformation();
return true;
});
}

getActiveManipulator()->setSelected(false);
}

void TextureToolSelectionSystem::onManipulationCancelled()
{
foreachSelectedNode([&](const INode::Ptr& node)
if (getMode() == SelectionMode::Surface)
{
node->revertTransformation();
return true;
});
foreachSelectedNode([&](const INode::Ptr& node)
{
node->revertTransformation();
return true;
});
}
else
{
foreachSelectedComponentNode([&](const INode::Ptr& node)
{
node->revertTransformation();
return true;
});
}
}

sigc::signal<void, selection::IManipulator::Type>& TextureToolSelectionSystem::signal_activeManipulatorChanged()
Expand Down
52 changes: 52 additions & 0 deletions test/TextureTool.cpp
Expand Up @@ -769,4 +769,56 @@ TEST_F(TextureToolTest, DragManipulatePatch)
});
}

TEST_F(TextureToolTest, DragManipulatePatchVertices)
{
auto patchNode = setupPatchNodeForTextureTool();
auto patch = Node_getIPatch(patchNode);

// Remember the texcoords before manipulation
std::vector<Vector2> oldTexcoords;
foreachPatchVertex(*patch, [&](const PatchControl& control) { oldTexcoords.push_back(control.texcoord); });

// Get the texture space bounds of this patch
auto bounds = getTextureSpaceBounds(*patch);
bounds.extents *= 1.2f;

render::TextureToolView view;
view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT);

GlobalTextureToolSelectionSystem().setMode(textool::SelectionMode::Vertex);

// Select every odd vertex
for (auto i = 0; i < oldTexcoords.size(); ++i)
{
if (i % 2 == 1)
{
performPointSelection(oldTexcoords[i], view);
}
}

EXPECT_EQ(getAllSelectedComponentNodes().size(), 1) << "No component node selected";

// Drag-manipulate the first odd vertex
dragManipulateSelectionTowardsLowerRight(oldTexcoords[1], view);

std::vector<Vector2> changedTexcoords;
foreachPatchVertex(*patch, [&](const PatchControl& control) { changedTexcoords.push_back(control.texcoord); });

// All odd texcoords should have been moved to the lower right (U increased, V increased)
for (auto i = 0; i < oldTexcoords.size(); ++i)
{
if (i % 2 == 1)
{
EXPECT_LT(oldTexcoords[i].x(), changedTexcoords[i].x());
EXPECT_LT(oldTexcoords[i].y(), changedTexcoords[i].y());
}
else
{
// should be unchanged
EXPECT_NEAR(oldTexcoords[i].x(), changedTexcoords[i].x(), 0.01);
EXPECT_NEAR(oldTexcoords[i].y(), changedTexcoords[i].y(), 0.01);
}
}
}

}

0 comments on commit 66e019a

Please sign in to comment.