Skip to content

Commit 1efb5e3

Browse files
authored
Merge pull request #68 from klaussilveira/feat/normalise
Restore Normalise feature to Texture Tool and Surface Inspector
2 parents 9fcb248 + ed28fd3 commit 1efb5e3

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

radiant/ui/surfaceinspector/SurfaceInspector.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ void SurfaceInspector::connectButtons()
202202
_alignTexture.right->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
203203
_alignTexture.left->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
204204
_modifyTex.natural->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
205+
_modifyTex.normalise->Connect(wxEVT_BUTTON, wxCommandEventHandler(SurfaceInspector::onUpdateAfterButtonClick), NULL, this);
205206

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

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

@@ -647,6 +652,7 @@ void SurfaceInspector::doUpdate()
647652

648653
// The natural/normalise widget sensitivity
649654
_modifyTex.natural->Enable(haveSelection);
655+
_modifyTex.normalise->Enable(haveSelection);
650656

651657
// Current shader name
652658
_shaderEntry->SetValue(selection::getShaderFromSelection());

radiant/ui/surfaceinspector/SurfaceInspector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SurfaceInspector :
7979
struct ModifyTextureWidgets
8080
{
8181
wxButton* natural;
82+
wxButton* normalise;
8283
} _modifyTex;
8384

8485
wxSpinCtrlDouble* _defaultTexScale;

radiantcore/selection/textool/TextureToolSelectionSystem.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -734,21 +734,26 @@ void TextureToolSelectionSystem::normaliseSelectionCmd(const cmd::ArgumentList&
734734
return;
735735
}
736736

737-
// Calculate the center based on the selection
738-
selection::algorithm::TextureBoundsAccumulator accumulator;
739-
foreachSelectedNode(accumulator);
740-
741-
if (!accumulator.getBounds().isValid())
742-
{
743-
return;
744-
}
745-
746-
Vector2 normaliseCenter(accumulator.getBounds().origin.x(), accumulator.getBounds().origin.y());
737+
bool hasSelection = countSelected() > 0;
747738

748739
UndoableCommand cmd("normaliseTexcoords");
749740

750-
selection::algorithm::TextureNormaliser normaliser(normaliseCenter);
751-
foreachSelectedNode(normaliser);
741+
auto normaliseNode = [](const INode::Ptr& node)
742+
{
743+
const auto& bounds = node->localAABB();
744+
selection::algorithm::TextureNormaliser normaliser({ bounds.origin.x(), bounds.origin.y() });
745+
normaliser.processNode(node);
746+
return true;
747+
};
748+
749+
if (hasSelection)
750+
{
751+
foreachSelectedNode(normaliseNode);
752+
}
753+
else
754+
{
755+
GlobalTextureToolSceneGraph().foreachNode(normaliseNode);
756+
}
752757
}
753758

754759
void TextureToolSelectionSystem::shiftSelectionCmd(const cmd::ArgumentList& args)

0 commit comments

Comments
 (0)