Skip to content

Commit

Permalink
#5733: Use the texture aspect ratio to scale the visible UV space
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Sep 10, 2021
1 parent 7b9689c commit 2a7c274
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion radiant/textool/TexTool.cpp
Expand Up @@ -418,6 +418,18 @@ void TexTool::recalculateVisibleTexSpace()
_texSpaceAABB.extents[0] = std::max(_texSpaceAABB.extents[0], _texSpaceAABB.extents[1]);
_texSpaceAABB.extents[1] = std::max(_texSpaceAABB.extents[0], _texSpaceAABB.extents[1]);

// Make the visible space non-uniform if the texture has a width/height ratio != 1
double aspect = getTextureAspectRatio();

if (aspect < 1)
{
_texSpaceAABB.extents.x() /= getTextureAspectRatio();
}
else
{
_texSpaceAABB.extents.y() *= getTextureAspectRatio();
}

updateProjection();
}

Expand All @@ -434,7 +446,8 @@ AABB& TexTool::getExtents()
return _selAABB;
}

AABB& TexTool::getVisibleTexSpace() {
AABB& TexTool::getVisibleTexSpace()
{
return _texSpaceAABB;
}

Expand Down Expand Up @@ -791,6 +804,16 @@ void TexTool::drawGrid()
}
}

double TexTool::getTextureAspectRatio()
{
if (!_shader) return 1;

auto editorImage = _shader->getEditorImage();
if (!editorImage) return 1;

return static_cast<double>(editorImage->getWidth()) / editorImage->getHeight();
}

void TexTool::updateProjection()
{
double windowAspect = _windowDims[0] / _windowDims[1];
Expand Down
1 change: 1 addition & 0 deletions radiant/textool/TexTool.h
Expand Up @@ -290,6 +290,7 @@ class TexTool :

private:
void updateProjection();
double getTextureAspectRatio();

TextureToolMouseEvent createMouseEvent(const Vector2& point, const Vector2& delta = Vector2(0, 0));

Expand Down

0 comments on commit 2a7c274

Please sign in to comment.