From a2805c0b85e6eaf3277524ceed6b8de1665bdfbe Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 2 Oct 2021 06:57:05 +0200 Subject: [PATCH] #2272: Expand unit tests to check two selected patches which should be scaled independently when calling TexScale --- radiantcore/selection/algorithm/Shader.cpp | 9 ----- radiantcore/selection/algorithm/Texturing.cpp | 14 +++++++ radiantcore/selection/algorithm/Texturing.h | 6 +++ test/TextureManipulation.cpp | 38 +++++++++++++------ 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/radiantcore/selection/algorithm/Shader.cpp b/radiantcore/selection/algorithm/Shader.cpp index b883e768f7..2d27a14b4f 100644 --- a/radiantcore/selection/algorithm/Shader.cpp +++ b/radiantcore/selection/algorithm/Shader.cpp @@ -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) @@ -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) @@ -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() { diff --git a/radiantcore/selection/algorithm/Texturing.cpp b/radiantcore/selection/algorithm/Texturing.cpp index 3b09ad5b28..79f77bfa6d 100644 --- a/radiantcore/selection/algorithm/Texturing.cpp +++ b/radiantcore/selection/algorithm/Texturing.cpp @@ -2,6 +2,7 @@ #include "selection/textool/FaceNode.h" #include "selection/textool/PatchNode.h" +#include "messages/TextureChanged.h" namespace selection { @@ -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(); diff --git a/radiantcore/selection/algorithm/Texturing.h b/radiantcore/selection/algorithm/Texturing.h index 6bf006fba3..8ea40fddf2 100644 --- a/radiantcore/selection/algorithm/Texturing.h +++ b/radiantcore/selection/algorithm/Texturing.h @@ -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; }; diff --git a/test/TextureManipulation.cpp b/test/TextureManipulation.cpp index cb212a439f..607f4b70ff 100644 --- a/test/TextureManipulation.cpp +++ b/test/TextureManipulation.cpp @@ -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 oldTexCoords; - algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { oldTexCoords.push_back(ctrl.texcoord); }); + std::vector oldTexCoords1; + std::vector 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 newTexCoords; - algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { newTexCoords.push_back(ctrl.texcoord); }); + std::vector newTexCoords1; + std::vector 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); } }