From 5d83e3b54b990ae737748ed8a742cbe089db956b Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 19 Sep 2021 11:28:53 +0200 Subject: [PATCH] #5746: Implementing PatchNode component selection (WIP) --- radiantcore/selection/textool/PatchNode.h | 38 ++++++++++++------- .../textool/TextureToolSelectionSystem.cpp | 35 +++++++++++------ .../textool/TextureToolSelectionSystem.h | 2 + test/TextureTool.cpp | 2 +- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/radiantcore/selection/textool/PatchNode.h b/radiantcore/selection/textool/PatchNode.h index c84734143e..af83828008 100644 --- a/radiantcore/selection/textool/PatchNode.h +++ b/radiantcore/selection/textool/PatchNode.h @@ -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 diff --git a/radiantcore/selection/textool/TextureToolSelectionSystem.cpp b/radiantcore/selection/textool/TextureToolSelectionSystem.cpp index e1d2fa9d44..1bbfb0c933 100644 --- a/radiantcore/selection/textool/TextureToolSelectionSystem.cpp +++ b/radiantcore/selection/textool/TextureToolSelectionSystem.cpp @@ -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; @@ -375,18 +371,13 @@ 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) { @@ -394,6 +385,28 @@ void TextureToolSelectionSystem::selectArea(SelectionTest& test, SelectionSystem } } +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(node); + + if (componentSelectable) + { + componentSelectable->testSelectComponents(selector, test); + } + } + + return true; + }); +} + module::StaticModule _textureToolSelectionSystemModule; } diff --git a/radiantcore/selection/textool/TextureToolSelectionSystem.h b/radiantcore/selection/textool/TextureToolSelectionSystem.h index 55227e8646..99670995fa 100644 --- a/radiantcore/selection/textool/TextureToolSelectionSystem.h +++ b/radiantcore/selection/textool/TextureToolSelectionSystem.h @@ -64,6 +64,8 @@ class TextureToolSelectionSystem : void toggleSelectionMode(SelectionMode mode); void toggleSelectionModeCmd(const cmd::ArgumentList& args); + + void performSelectionTest(Selector& selector, SelectionTest& test); }; } diff --git a/test/TextureTool.cpp b/test/TextureTool.cpp index 8a689c5716..30a4ba0028 100644 --- a/test/TextureTool.cpp +++ b/test/TextureTool.cpp @@ -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";