Skip to content

Commit

Permalink
#5746: Implementing PatchNode component selection (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 19, 2021
1 parent 11159a4 commit 5d83e3b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
38 changes: 24 additions & 14 deletions radiantcore/selection/textool/PatchNode.h
Expand Up @@ -103,34 +103,44 @@ class PatchNode :
{
Selector_add(selector, *this);
}
#if 0
foreachVertex([&](PatchControl& vertex)
{
SelectionIntersection intersection;

test.TestPoint(Vector3(vertex.texcoord.x(), vertex.texcoord.y(), 0), intersection);

if (intersection.isValid())
{
Selector_add(selector, *this);
}
});
#endif
}

bool hasSelectedComponents() const override
{
for (auto& vertex : _vertices)
{
if (vertex.isSelected())
{
return true;
}
}

return false;
}

void clearComponentSelection() override
{

for (auto& vertex : _vertices)
{
vertex.setSelected(false);
}
}

void testSelectComponents(Selector& selector, SelectionTest& test) override
{
test.BeginMesh(Matrix4::getIdentity(), true);

for (auto& vertex : _vertices)
{
SelectionIntersection intersection;

test.TestPoint(Vector3(vertex.getVertex().x(), vertex.getVertex().y(), 0), intersection);

if (intersection.isValid())
{
Selector_add(selector, vertex);
}
}
}

void render(SelectionMode mode) override
Expand Down
35 changes: 24 additions & 11 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -324,11 +324,7 @@ void TextureToolSelectionSystem::selectPoint(SelectionTest& test, SelectionSyste
{
selection::SelectionPool selectionPool;

GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
node->testSelect(selectionPool, test);
return true;
});
performSelectionTest(selectionPool, test);

if (selectionPool.empty()) return;

Expand Down Expand Up @@ -375,25 +371,42 @@ void TextureToolSelectionSystem::selectPoint(SelectionTest& test, SelectionSyste
}
break;
}

}

void TextureToolSelectionSystem::selectArea(SelectionTest& test, SelectionSystem::EModifier modifier)
{
selection::SelectionPool selectionPool;

GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
node->testSelect(selectionPool, test);
return true;
});
performSelectionTest(selectionPool, test);

for (const auto& pair : selectionPool)
{
pair.second->setSelected(!pair.second->isSelected());
}
}

void TextureToolSelectionSystem::performSelectionTest(Selector& selector, SelectionTest& test)
{
GlobalTextureToolSceneGraph().foreachNode([&](const INode::Ptr& node)
{
if (getMode() == SelectionMode::Surface)
{
node->testSelect(selector, test);
}
else
{
auto componentSelectable = std::dynamic_pointer_cast<IComponentSelectable>(node);

if (componentSelectable)
{
componentSelectable->testSelectComponents(selector, test);
}
}

return true;
});
}

module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;

}
2 changes: 2 additions & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -64,6 +64,8 @@ class TextureToolSelectionSystem :

void toggleSelectionMode(SelectionMode mode);
void toggleSelectionModeCmd(const cmd::ArgumentList& args);

void performSelectionTest(Selector& selector, SelectionTest& test);
};

}
2 changes: 1 addition & 1 deletion test/TextureTool.cpp
Expand Up @@ -527,7 +527,7 @@ TEST_F(TextureToolTest, TestSelectPatchVertexByPoint)
EXPECT_EQ(getAllSelectedComponentNodes().size(), 1) << "Only one patch should be selected";

// Hitting another vertex should not de-select the patch
auto secondVertex = patch->ctrlAt(3, 0).texcoord;
auto secondVertex = patch->ctrlAt(2, 0).texcoord;
performPointSelection(secondVertex, view);
EXPECT_EQ(getAllSelectedComponentNodes().size(), 1) << "Only one patch should still be selected";

Expand Down

0 comments on commit 5d83e3b

Please sign in to comment.