Skip to content

Commit

Permalink
#5767: Start unifying the algorithms by moving the texture tool node …
Browse files Browse the repository at this point in the history
…processor to selection::algorithm namespace, into Texturing.h/.cpp
  • Loading branch information
codereader committed Oct 1, 2021
1 parent 834dab9 commit d3aa245
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Expand Up @@ -235,6 +235,7 @@ add_library(radiantcore MODULE
selection/algorithm/Planes.cpp
selection/algorithm/Primitives.cpp
selection/algorithm/Shader.cpp
selection/algorithm/Texturing.cpp
selection/algorithm/Transformation.cpp
selection/clipboard/Clipboard.cpp
selection/group/SelectionGroupInfoFileModule.cpp
Expand Down
37 changes: 37 additions & 0 deletions radiantcore/selection/algorithm/Texturing.cpp
@@ -0,0 +1,37 @@
#include "Texturing.h"

namespace selection
{

namespace algorithm
{

TextureFlipper::TextureFlipper(const Vector2& flipCenter, int axis)
{
auto flipMatrix = Matrix3::getIdentity();

if (axis == 0)
{
flipMatrix.xx() = -1;
}
else // axis == 1
{
flipMatrix.yy() = -1;
}

_transform = Matrix3::getTranslation(-flipCenter);
_transform.premultiplyBy(flipMatrix);
_transform.premultiplyBy(Matrix3::getTranslation(+flipCenter));
}

bool TextureFlipper::operator()(const textool::INode::Ptr& node)
{
node->beginTransformation();
node->transform(_transform);
node->commitTransformation();
return true;
}

}

}
27 changes: 27 additions & 0 deletions radiantcore/selection/algorithm/Texturing.h
@@ -0,0 +1,27 @@
#pragma once

#include "itexturetoolmodel.h"
#include "math/Matrix3.h"

namespace selection
{

namespace algorithm
{

// Flips all the visited node about the given axis and the given flip center point (in UV space)
class TextureFlipper
{
private:
Matrix3 _transform;

public:
TextureFlipper(const Vector2& flipCenter, int axis);

// Function operator, makes this class suitable to pass to e.g. ITextureToolSelectionSystem.foreachSelected()
bool operator()(const textool::INode::Ptr& node);
};

}

}
24 changes: 3 additions & 21 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -9,6 +9,7 @@
#include "selection/SelectionPool.h"
#include "string/case_conv.h"
#include "math/Matrix3.h"
#include "selection/algorithm/Texturing.h"

namespace textool
{
Expand Down Expand Up @@ -697,30 +698,11 @@ void TextureToolSelectionSystem::flipSelected(int axis)

// Move center to origin, flip around the specified axis, and move back
Vector2 flipCenter(selectionBounds.origin.x(), selectionBounds.origin.y());
auto flipMatrix = Matrix3::getIdentity();

if (axis == 0)
{
flipMatrix.xx() = -1;
}
else // axis == 1
{
flipMatrix.yy() = -1;
}

auto flipTransformation = Matrix3::getTranslation(-flipCenter);
flipTransformation.premultiplyBy(flipMatrix);
flipTransformation.premultiplyBy(Matrix3::getTranslation(+flipCenter));

UndoableCommand cmd("flipSelectedTexcoords " + string::to_string(axis));

foreachSelectedNode([&](const INode::Ptr& node)
{
node->beginTransformation();
node->transform(flipTransformation);
node->commitTransformation();
return true;
});
selection::algorithm::TextureFlipper flipper(flipCenter, axis);
foreachSelectedNode(flipper);

radiant::TextureChangedMessage::Send();
}
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -648,6 +648,7 @@
<ClCompile Include="..\..\radiantcore\selection\algorithm\Planes.cpp" />
<ClCompile Include="..\..\radiantcore\selection\algorithm\Primitives.cpp" />
<ClCompile Include="..\..\radiantcore\selection\algorithm\Shader.cpp" />
<ClCompile Include="..\..\radiantcore\selection\algorithm\Texturing.cpp" />
<ClCompile Include="..\..\radiantcore\selection\algorithm\Transformation.cpp" />
<ClCompile Include="..\..\radiantcore\selection\clipboard\Clipboard.cpp" />
<ClCompile Include="..\..\radiantcore\selection\group\SelectionGroupInfoFileModule.cpp" />
Expand Down Expand Up @@ -1003,6 +1004,7 @@
<ClInclude Include="..\..\radiantcore\selection\algorithm\Primitives.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\SelectionPolicies.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\Shader.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\Texturing.h" />
<ClInclude Include="..\..\radiantcore\selection\algorithm\Transformation.h" />
<ClInclude Include="..\..\radiantcore\selection\BasicSelectable.h" />
<ClInclude Include="..\..\radiantcore\selection\BestSelector.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1108,6 +1108,9 @@
<ClCompile Include="..\..\radiantcore\selection\textool\ColourSchemeManager.cpp">
<Filter>src\selection\textool</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\selection\algorithm\Texturing.cpp">
<Filter>src\selection\algorithm</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2253,5 +2256,8 @@
<ClInclude Include="..\..\radiantcore\selection\textool\SelectableVertex.h">
<Filter>src\selection\textool</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\selection\algorithm\Texturing.h">
<Filter>src\selection\algorithm</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit d3aa245

Please sign in to comment.