From c4a89cfe4c0dc346179ec8ab64710a2f159c1463 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 9 Oct 2021 09:30:04 +0200 Subject: [PATCH] #5773: Add dedicated TextureProjection constructor to create a projection that matches the default texture scale for the given image. --- radiantcore/brush/Face.cpp | 2 +- radiantcore/brush/TextureProjection.cpp | 13 +++++++------ radiantcore/brush/TextureProjection.h | 10 ++++------ radiantcore/selection/algorithm/Shader.cpp | 4 ---- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/radiantcore/brush/Face.cpp b/radiantcore/brush/Face.cpp index 0a72706ff8..66b4d15e2f 100644 --- a/radiantcore/brush/Face.cpp +++ b/radiantcore/brush/Face.cpp @@ -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(); } diff --git a/radiantcore/brush/TextureProjection.cpp b/radiantcore/brush/TextureProjection.cpp index 533d7e8e9b..ddda95a0ad 100644 --- a/radiantcore/brush/TextureProjection.cpp +++ b/radiantcore/brush/TextureProjection.cpp @@ -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() diff --git a/radiantcore/brush/TextureProjection.h b/radiantcore/brush/TextureProjection.h index b9e5445d29..fea1c86fae 100644 --- a/radiantcore/brush/TextureProjection.h +++ b/radiantcore/brush/TextureProjection.h @@ -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" @@ -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); @@ -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(); diff --git a/radiantcore/selection/algorithm/Shader.cpp b/radiantcore/selection/algorithm/Shader.cpp index 7571a4a366..d56501de5d 100644 --- a/radiantcore/selection/algorithm/Shader.cpp +++ b/radiantcore/selection/algorithm/Shader.cpp @@ -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();