Skip to content

Commit

Permalink
#2272: Expand unit tests to check two selected patches which should b…
Browse files Browse the repository at this point in the history
…e scaled independently when calling TexScale
  • Loading branch information
codereader committed Oct 2, 2021
1 parent 334ae08 commit a2805c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
9 changes: 0 additions & 9 deletions radiantcore/selection/algorithm/Shader.cpp
Expand Up @@ -470,8 +470,6 @@ void flipTexture(int flipAxis)
// Flip every node about its own center point
GlobalSelectionSystem().foreachFace([&](IFace& face) { TextureFlipper::FlipFace(face, flipAxis); });
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { TextureFlipper::FlipPatch(patch, flipAxis); });

radiant::TextureChangedMessage::Send();
}

void flipTextureS(const cmd::ArgumentList& args)
Expand Down Expand Up @@ -544,9 +542,6 @@ void scaleTexture(const Vector2& scale)
// Flip every node about its own center point
GlobalSelectionSystem().foreachFace([&](IFace& face) { TextureScaler::ScaleFace(face, patchScale); });
GlobalSelectionSystem().foreachPatch([&](IPatch& patch) { TextureScaler::ScalePatch(patch, patchScale); });

// Update the Texture Tools
radiant::TextureChangedMessage::Send();
}

void rotateTexture(const float angle)
Expand All @@ -558,10 +553,6 @@ void rotateTexture(const float angle)

GlobalSelectionSystem().foreachFace([&] (IFace& face) { face.rotateTexdef(angle); });
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.rotateTexture(angle); });

SceneChangeNotify();
// Update the Texture Tools
radiant::TextureChangedMessage::Send();
}

void shiftTextureLeft() {
Expand Down
14 changes: 14 additions & 0 deletions radiantcore/selection/algorithm/Texturing.cpp
Expand Up @@ -2,6 +2,7 @@

#include "selection/textool/FaceNode.h"
#include "selection/textool/PatchNode.h"
#include "messages/TextureChanged.h"

namespace selection
{
Expand Down Expand Up @@ -41,6 +42,19 @@ bool TextureNodeManipulator::processNode(const textool::INode::Ptr& node)
return true;
}

TextureNodeManipulator::TextureNodeManipulator() :
_numProcessedNodes(0)
{}

TextureNodeManipulator::~TextureNodeManipulator()
{
// Dispatch the texture changed signal if we processed at least one node
if (_numProcessedNodes)
{
radiant::TextureChangedMessage::Send();
}
}

TextureFlipper::TextureFlipper(const Vector2& flipCenter, int axis)
{
auto flipMatrix = Matrix3::getIdentity();
Expand Down
6 changes: 6 additions & 0 deletions radiantcore/selection/algorithm/Texturing.h
Expand Up @@ -42,13 +42,19 @@ class TextureBoundsAccumulator :
}
};

// Will dispatch a TextureChangedMessage after processing at least one node
class TextureNodeManipulator :
public TextureNodeProcessor
{
protected:
Matrix3 _transform;
std::size_t _numProcessedNodes;

TextureNodeManipulator();

public:
virtual ~TextureNodeManipulator();

bool processNode(const textool::INode::Ptr& node) override;
};

Expand Down
38 changes: 26 additions & 12 deletions test/TextureManipulation.cpp
Expand Up @@ -270,29 +270,43 @@ void performFaceScaleTest(const Vector2& scale)

void performPatchScaleTest(const Vector2& scale)
{
// We create two patches, each of them should be scaled independently
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patchNode = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1");
auto patchNode1 = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1");
auto patchNode2 = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, -5), Vector3(64, 128, 64)), "textures/numbers/1");

auto patch = Node_getIPatch(patchNode);
patch->scaleTextureNaturally();
patch->controlPointsChanged();
auto patch1 = Node_getIPatch(patchNode1);
auto patch2 = Node_getIPatch(patchNode2);
patch1->scaleTextureNaturally();
patch1->controlPointsChanged();
patch2->scaleTextureNaturally();
patch2->controlPointsChanged();

Node_setSelected(patchNode, true);
Node_setSelected(patchNode1, true);
Node_setSelected(patchNode2, true);

std::vector<Vector2> oldTexCoords;
algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { oldTexCoords.push_back(ctrl.texcoord); });
std::vector<Vector2> oldTexCoords1;
std::vector<Vector2> oldTexCoords2;
algorithm::foreachPatchVertex(*patch1, [&](const PatchControl& ctrl) { oldTexCoords1.push_back(ctrl.texcoord); });
algorithm::foreachPatchVertex(*patch2, [&](const PatchControl& ctrl) { oldTexCoords2.push_back(ctrl.texcoord); });

// The incoming scale values are absolute 1.05 == 105%, the command accepts relative values, 0.05 == 105%
auto zeroBasedScale = scale - Vector2(1, 1);
GlobalCommandSystem().executeCommand("TexScale", { cmd::Argument(zeroBasedScale) });

auto uvBounds = algorithm::getTextureSpaceBounds(*patch);
auto uvBounds1 = algorithm::getTextureSpaceBounds(*patch1);
auto uvBounds2 = algorithm::getTextureSpaceBounds(*patch2);

std::vector<Vector2> newTexCoords;
algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { newTexCoords.push_back(ctrl.texcoord); });
std::vector<Vector2> newTexCoords1;
std::vector<Vector2> newTexCoords2;
algorithm::foreachPatchVertex(*patch1, [&](const PatchControl& ctrl) { newTexCoords1.push_back(ctrl.texcoord); });
algorithm::foreachPatchVertex(*patch2, [&](const PatchControl& ctrl) { newTexCoords2.push_back(ctrl.texcoord); });

Vector2 pivot(uvBounds.origin.x(), uvBounds.origin.y());
assumeVerticesHaveBeenScaled(oldTexCoords, newTexCoords, scale, pivot);
Vector2 pivot(uvBounds1.origin.x(), uvBounds1.origin.y());
assumeVerticesHaveBeenScaled(oldTexCoords1, newTexCoords1, scale, pivot);

Vector2 pivot2(uvBounds2.origin.x(), uvBounds2.origin.y());
assumeVerticesHaveBeenScaled(oldTexCoords2, newTexCoords2, scale, pivot2);
}

}
Expand Down

0 comments on commit a2805c0

Please sign in to comment.