Skip to content

Commit

Permalink
#5773: Add dedicated TextureProjection constructor to create a projec…
Browse files Browse the repository at this point in the history
…tion that matches the default texture scale for the given image.
  • Loading branch information
codereader committed Oct 9, 2021
1 parent d1ce07f commit c4a89cf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion radiantcore/brush/Face.cpp
Expand Up @@ -680,7 +680,7 @@ void Face::emitTextureCoordinates()

void Face::applyDefaultTextureScale()
{
_texdef.getTextureMatrix().addScale(_shader.getWidth(), _shader.getHeight());
_texdef = TextureProjection::ConstructDefault(_shader.getWidth(), _shader.getHeight());
texdefChanged();
}

Expand Down
13 changes: 7 additions & 6 deletions radiantcore/brush/TextureProjection.cpp
Expand Up @@ -17,14 +17,15 @@ TextureProjection::TextureProjection(const TextureMatrix& otherMatrix) :
_matrix(otherMatrix)
{}

const TextureMatrix& TextureProjection::getTextureMatrix() const
TextureProjection TextureProjection::ConstructDefault(std::size_t width, std::size_t height)
{
return _matrix;
}
// Default-construct to get the default matrix
TextureProjection projection;

TextureMatrix& TextureProjection::getTextureMatrix()
{
return _matrix;
// Scale the matrix components to fit the texture dimensions
projection._matrix.addScale(width, height);

return projection;
}

TextureMatrix TextureProjection::Default()
Expand Down
10 changes: 4 additions & 6 deletions radiantcore/brush/TextureProjection.h
Expand Up @@ -2,10 +2,8 @@

#include "ibrush.h"
#include "math/Matrix3.h"
#include "texturelib.h"
#include "math/Matrix4.h"
#include "Winding.h"
#include "math/AABB.h"
#include "iregistry.h"
#include "TextureMatrix.h"
#include "selection/algorithm/Shader.h"

Expand Down Expand Up @@ -35,9 +33,6 @@ class TextureProjection final
// Construct using an existing texture matrix
TextureProjection(const TextureMatrix& otherMatrix);

const TextureMatrix& getTextureMatrix() const;
TextureMatrix& getTextureMatrix();

TextureProjection& operator=(const TextureProjection& other);

void setTransform(const Matrix3& transform);
Expand Down Expand Up @@ -68,6 +63,9 @@ class TextureProjection final
// Calculate the texture projection for the desired set of UVs and XYZ
void calculateFromPoints(const Vector3 points[3], const Vector2 uvs[3], const Vector3& normal);

// Returns a texture projection using the default scale for the given texture dimensions
static TextureProjection ConstructDefault(std::size_t width, std::size_t height);

private:
static TextureMatrix Default();

Expand Down
4 changes: 0 additions & 4 deletions radiantcore/selection/algorithm/Shader.cpp
Expand Up @@ -61,12 +61,8 @@ void applyClipboardPatchToFace(Face& target)
// Get a reference to the source Texturable in the clipboard
Texturable& source = ShaderClipboard::Instance().getSource();

// Apply a default projection to the face
TextureProjection projection;

// Copy just the shader name, the rest is default value
target.setShader(source.patch->getShader());
target.SetTexdef(projection);

// To fix the extremely small scale we get when applying a default TextureProjection
target.applyDefaultTextureScale();
Expand Down

0 comments on commit c4a89cf

Please sign in to comment.