Skip to content

Commit

Permalink
#5547: Add ability to normalise a set of texture tool items as a whole
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 5, 2021
1 parent 2eb9926 commit b2efa1c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Binary file added install/bitmaps/textool_normalise.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions install/user.xml
Expand Up @@ -310,6 +310,7 @@
<toggletoolbutton name="textoolvertexmode" action="TextureToolVertexSelectionMode" tooltip="Select Vertices" icon="modify_vertices.png"/>
<separator/>
<toolbutton name="mergeitems" action="TexToolMergeItems" tooltip="Merge Selection" icon="textool_merge.png"/>
<toolbutton name="normaliseitems" action="TexToolNormaliseItems" tooltip="Normalise" icon="textool_normalise.png"/>
<toolbutton name="texflips" action="TexToolFlipS" tooltip="Flip Selection Horiz (S-Axis)" icon="tex_flips.png"/>
<toolbutton name="texflipt" action="TexToolFlipT" tooltip="Flip Selection Vertical (T-Axis)" icon="tex_flipt.png"/>
<toolbutton name="selectrelated" action="TexToolSelectRelated" tooltip="Select Related Items" icon="textool_select_related.png"/>
Expand Down
23 changes: 21 additions & 2 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Expand Up @@ -50,6 +50,8 @@ void TextureToolSelectionSystem::initialiseModule(const IApplicationContext& ctx
std::bind(&TextureToolSelectionSystem::selectRelatedCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("TexToolSnapToGrid",
std::bind(&TextureToolSelectionSystem::snapSelectionToGridCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("TexToolNormaliseItems",
std::bind(&TextureToolSelectionSystem::normaliseSelectionCmd, this, std::placeholders::_1));
GlobalCommandSystem().addCommand("TexToolMergeItems",
std::bind(&TextureToolSelectionSystem::mergeSelectionCmd, this, std::placeholders::_1),
{ cmd::ARGTYPE_VECTOR2 | cmd::ARGTYPE_OPTIONAL });
Expand Down Expand Up @@ -700,8 +702,6 @@ void TextureToolSelectionSystem::flipSelected(int axis)

selection::algorithm::TextureFlipper flipper(flipCenter, axis);
foreachSelectedNode(flipper);

radiant::TextureChangedMessage::Send();
}

void TextureToolSelectionSystem::flipVerticallyCmd(const cmd::ArgumentList& args)
Expand All @@ -714,6 +714,25 @@ void TextureToolSelectionSystem::flipHorizontallyCmd(const cmd::ArgumentList& ar
flipSelected(0);
}

void TextureToolSelectionSystem::normaliseSelectionCmd(const cmd::ArgumentList& args)
{
// Calculate the center based on the selection
selection::algorithm::TextureBoundsAccumulator accumulator;
foreachSelectedNode(accumulator);

if (!accumulator.getBounds().isValid())
{
return;
}

Vector2 normaliseCenter(accumulator.getBounds().origin.x(), accumulator.getBounds().origin.y());

UndoableCommand cmd("normaliseTexcoords");

selection::algorithm::TextureNormaliser normaliser(normaliseCenter);
foreachSelectedNode(normaliser);
}

module::StaticModule<TextureToolSelectionSystem> _textureToolSelectionSystemModule;

}
1 change: 1 addition & 0 deletions radiantcore/selection/textool/TextureToolSelectionSystem.h
Expand Up @@ -92,6 +92,7 @@ class TextureToolSelectionSystem :
void mergeSelectionCmd(const cmd::ArgumentList& args);
void flipHorizontallyCmd(const cmd::ArgumentList& args);
void flipVerticallyCmd(const cmd::ArgumentList& args);
void normaliseSelectionCmd(const cmd::ArgumentList& args);

void flipSelected(int axis);
void performSelectionTest(Selector& selector, SelectionTest& test);
Expand Down

0 comments on commit b2efa1c

Please sign in to comment.