Skip to content

Commit

Permalink
#5846: Fix texture being messed up by 90 degree rotations of brushes.…
Browse files Browse the repository at this point in the history
… Freezetransform is triggering a second evaluation of the current transformation (which is identity) - this was messing up the texDefTransformed() algorithm since the winding vertices were still at the old position. The face normal ended up being parallel to the face plane. The quick solution here is to ignore identity transforms in Face::transform.
  • Loading branch information
codereader committed Feb 28, 2022
1 parent 78e97bb commit aaf11c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -486,7 +486,12 @@ void BrushNode::evaluateTransform()
}
else
{
m_brush.transform(calculateTransform());
auto transform = calculateTransform();

if (transform != Matrix4::getIdentity())
{
m_brush.transform(transform);
}
}
}
else
Expand Down Expand Up @@ -562,7 +567,7 @@ void BrushNode::onPostRedo()

void BrushNode::_onTransformationChanged()
{
m_brush.transformChanged();
m_brush.transformChanged();

_renderableVertices.queueUpdate();
_renderableComponentsNeedUpdate = true;
Expand Down
17 changes: 15 additions & 2 deletions test/TextureManipulation.cpp
@@ -1,5 +1,6 @@
#include "RadiantTest.h"

#include <optional>
#include "itransformable.h"
#include "ishaders.h"
#include "ishaderclipboard.h"
Expand Down Expand Up @@ -829,14 +830,26 @@ TEST_F(TextureManipulationTest, RotateFuncStaticBrush90)

auto& faceAfter = *algorithm::findBrushFaceWithNormal(brush, { 1, 0, 0 });

std::optional<Vector2> distance;
auto old = oldVertices.begin();
for (const auto& vertex : faceAfter.getWinding())
{
// Assume the 3D coordinates have changed
EXPECT_FALSE(math::isNear(vertex.vertex, old->vertex, 0.01));

// The texture coordinates should remain unchanged (due to texture lock)
EXPECT_TRUE(math::isNear(vertex.texcoord, old->texcoord, 0.01));
// The texture coordinates should remain equivalent (due to texture lock)
// The absolute coordinates in UV space might be off by some integer number
// We expect the distance to the previous coordinates to be the same
if (distance.has_value())
{
EXPECT_TRUE(math::isNear(distance.value(), vertex.texcoord - old->texcoord, 0.01));
}
else
{
distance = vertex.texcoord - old->texcoord;
}

++old;
}
}

Expand Down

0 comments on commit aaf11c4

Please sign in to comment.