Skip to content

Commit

Permalink
#5767: Replace the old Face::flipTexture algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 1, 2021
1 parent 3e0b6a0 commit 1f9ece6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 46 deletions.
8 changes: 4 additions & 4 deletions radiantcore/brush/Face.cpp
Expand Up @@ -9,6 +9,7 @@
#include "shaderlib.h"
#include "texturelib.h"
#include "Winding.h"
#include "selection/algorithm/Texturing.h"

#include "Brush.h"
#include "BrushNode.h"
Expand Down Expand Up @@ -635,10 +636,9 @@ void Face::fitTexture(float s_repeat, float t_repeat) {
texdefChanged();
}

void Face::flipTexture(unsigned int flipAxis) {
undoSave();
_texdef.flipTexture(flipAxis);
texdefChanged();
void Face::flipTexture(unsigned int flipAxis)
{
selection::algorithm::TextureFlipper::FlipFace(*this, flipAxis);
}

void Face::alignTexture(AlignEdge align)
Expand Down
33 changes: 0 additions & 33 deletions radiantcore/brush/TextureProjection.cpp
Expand Up @@ -201,39 +201,6 @@ void TextureProjection::fitTexture(std::size_t width, std::size_t height,
normalise((float)width, (float)height);
}

void TextureProjection::flipTexture(unsigned int flipAxis)
{
// Retrieve the "fake" texture coordinates (shift, scale, rotation)
TexDef texdef = matrix.getFakeTexCoords();

// Check for x flip (x-component not zero)
if (flipAxis == 0)
{
// Invert the x scale and rotate 180�
auto scale = texdef.getScale();
scale[0] *= -1;
texdef.setScale(scale);

texdef.setRotation(texdef.getRotation() - 180);
}
else if (flipAxis == 1)
{
// Invert the y scale and rotate 180�
auto scale = texdef.getScale();
scale[1] *= -1;
texdef.setScale(scale);

texdef.setRotation(texdef.getRotation() - 180);
}
else
{
// Do nothing, leave the TextureMatrix untouched
return;
}

matrix = TextureMatrix(texdef);
}

void TextureProjection::alignTexture(IFace::AlignEdge align, const Winding& winding)
{
if (winding.empty()) return;
Expand Down
6 changes: 0 additions & 6 deletions radiantcore/brush/TextureProjection.h
Expand Up @@ -52,12 +52,6 @@ class TextureProjection
// Fits a texture to a brush face
void fitTexture(std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat);

/** greebo: Mirrors the texture around the given axis.
*
* @flipAxis: 0 = flip x, 1 = flip y
*/
void flipTexture(unsigned int flipAxis);

// Aligns this texture to the given edge of the winding
void alignTexture(IFace::AlignEdge align, const Winding& winding);

Expand Down
15 changes: 12 additions & 3 deletions radiantcore/selection/algorithm/Texturing.cpp
@@ -1,5 +1,6 @@
#include "Texturing.h"

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

namespace selection
Expand Down Expand Up @@ -48,16 +49,24 @@ bool TextureFlipper::processNode(const textool::INode::Ptr& node)
return true;
}

void TextureFlipper::FlipPatch(IPatch& patch, int flipAxis)
void TextureFlipper::FlipNode(const textool::INode::Ptr& node, int flipAxis)
{
auto node = std::make_shared<textool::PatchNode>(patch);

const auto& bounds = node->localAABB();
TextureFlipper flipper({ bounds.origin.x(), bounds.origin.y() }, flipAxis);

flipper.processNode(node);
}

void TextureFlipper::FlipPatch(IPatch& patch, int flipAxis)
{
FlipNode(std::make_shared<textool::PatchNode>(patch), flipAxis);
}

void TextureFlipper::FlipFace(IFace& face, int flipAxis)
{
FlipNode(std::make_shared<textool::FaceNode>(face), flipAxis);
}

}

}
9 changes: 9 additions & 0 deletions radiantcore/selection/algorithm/Texturing.h
Expand Up @@ -4,6 +4,9 @@
#include "math/AABB.h"
#include "math/Matrix3.h"

class IPatch;
class IFace;

namespace selection
{

Expand Down Expand Up @@ -54,6 +57,12 @@ class TextureFlipper :

// Directly flip the texture of the given patch
static void FlipPatch(IPatch& patch, int flipAxis);

// Directly flip the texture of the given face
static void FlipFace(IFace& face, int flipAxis);

private:
static void FlipNode(const textool::INode::Ptr& node, int flipAxis);
};

}
Expand Down

0 comments on commit 1f9ece6

Please sign in to comment.