Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions radiant/ui/surfaceinspector/SurfaceInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void SurfaceInspector::connectButtons()
_alignTexture.right->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
_alignTexture.left->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
_modifyTex.natural->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
_modifyTex.normalise->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);

for (ManipulatorMap::iterator i = _manipulators.begin(); i != _manipulators.end(); ++i)
{
Expand All @@ -212,6 +213,7 @@ void SurfaceInspector::connectButtons()
wxutil::button::connectToCommand(_flipTexture.flipX, "FlipTextureX");
wxutil::button::connectToCommand(_flipTexture.flipY, "FlipTextureY");
wxutil::button::connectToCommand(_modifyTex.natural, "TextureNatural");
wxutil::button::connectToCommand(_modifyTex.normalise, "NormaliseTexture");

wxutil::button::connectToCommand(_alignTexture.top, "TexAlignTop");
wxutil::button::connectToCommand(_alignTexture.bottom, "TexAlignBottom");
Expand Down Expand Up @@ -452,6 +454,9 @@ void SurfaceInspector::populateWindow()
_modifyTex.natural = new wxButton(this, wxID_ANY, _(LABEL_NATURAL));
_modifyTex.natural->SetToolTip(_(TT_NATURAL));
modTextureBox->Add(_modifyTex.natural, 0, wxEXPAND);
_modifyTex.normalise = new wxButton(this, wxID_ANY, _("Normalise"));
_modifyTex.normalise->SetToolTip(_("Shift texture coordinates towards the origin"));
modTextureBox->Add(_modifyTex.normalise, 0, wxEXPAND | wxLEFT, 6);
wxStaticText* defaultScaleLabel = new wxStaticText(this, wxID_ANY, _(LABEL_DEFAULT_SCALE));
modTextureBox->Add(defaultScaleLabel, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 6);

Expand Down Expand Up @@ -647,6 +652,7 @@ void SurfaceInspector::doUpdate()

// The natural/normalise widget sensitivity
_modifyTex.natural->Enable(haveSelection);
_modifyTex.normalise->Enable(haveSelection);

// Current shader name
_shaderEntry->SetValue(selection::getShaderFromSelection());
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/surfaceinspector/SurfaceInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class SurfaceInspector :
struct ModifyTextureWidgets
{
wxButton* natural;
wxButton* normalise;
} _modifyTex;

wxSpinCtrlDouble* _defaultTexScale;
Expand Down
29 changes: 17 additions & 12 deletions radiantcore/selection/textool/TextureToolSelectionSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,26 @@ void TextureToolSelectionSystem::normaliseSelectionCmd(const cmd::ArgumentList&
return;
}

// 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());
bool hasSelection = countSelected() > 0;

UndoableCommand cmd("normaliseTexcoords");

selection::algorithm::TextureNormaliser normaliser(normaliseCenter);
foreachSelectedNode(normaliser);
auto normaliseNode = [](const INode::Ptr& node)
{
const auto& bounds = node->localAABB();
selection::algorithm::TextureNormaliser normaliser({ bounds.origin.x(), bounds.origin.y() });
normaliser.processNode(node);
return true;
};

if (hasSelection)
{
foreachSelectedNode(normaliseNode);
}
else
{
GlobalTextureToolSceneGraph().foreachNode(normaliseNode);
}
}

void TextureToolSelectionSystem::shiftSelectionCmd(const cmd::ArgumentList& args)
Expand Down