/
Texturing.h
131 lines (99 loc) · 3.22 KB
/
Texturing.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once
#include "itexturetoolmodel.h"
#include "math/AABB.h"
#include "math/Matrix3.h"
class IPatch;
class IFace;
namespace selection
{
namespace algorithm
{
class TextureNodeProcessor
{
protected:
TextureNodeProcessor() = default;
public:
// Conversion operator, to be able to pass an instance reference directly to
// ITextureToolSelectionSystem.foreachSelected() without having to set up the std::bind
operator std::function<bool(const textool::INode::Ptr& node)>();
// Required processor method to be implemented by subclasses
virtual bool processNode(const textool::INode::Ptr& node) = 0;
};
class TextureBoundsAccumulator :
public TextureNodeProcessor
{
private:
AABB _bounds;
public:
bool processNode(const textool::INode::Ptr& node) override;
const AABB& getBounds() const
{
return _bounds;
}
};
// Will dispatch a TextureChangedMessage after processing at least one node
class TextureNodeManipulator :
public TextureNodeProcessor
{
protected:
Matrix3 _transform;
std::size_t _numProcessedNodes;
TextureNodeManipulator();
public:
virtual ~TextureNodeManipulator();
bool processNode(const textool::INode::Ptr& node) override;
};
// Flips all the visited node about the given axis and the given flip center point (in UV space)
class TextureFlipper :
public TextureNodeManipulator
{
public:
TextureFlipper(const Vector2& flipCenter, int axis);
// 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);
};
class TextureRotator :
public TextureNodeManipulator
{
public:
TextureRotator(const Vector2& pivot, double angle);
// Directly rotate the texture of the given patch around its UV center
static void RotatePatch(IPatch& patch, double angle);
// Directly rotate the texture of the given face around its UV center
static void RotateFace(IFace& face, double angle);
private:
static void RotateNode(const textool::INode::Ptr& node, double angle);
};
class TextureScaler :
public TextureNodeManipulator
{
public:
// A scale component value of 1.0 == 100%
TextureScaler(const Vector2& pivot, const Vector2& scale);
// Directly scale the texture of the given patch with its UV center as pivot
static void ScalePatch(IPatch& patch, const Vector2& scale);
// Directly scale the texture of the given face with its UV center as pivot
static void ScaleFace(IFace& face, const Vector2& scale);
private:
static void ScaleNode(const textool::INode::Ptr& node, const Vector2& scale);
};
// Will shift the texture coordinates towards the origin,
// using the integer part of the given bounds center
class TextureNormaliser :
public TextureNodeManipulator
{
public:
TextureNormaliser(const Vector2& boundsCenter);
// Normalise the texture of the given patch
static void NormalisePatch(IPatch& patch);
// Normalise the texture of the given face
static void NormaliseFace(IFace& face);
private:
static void NormaliseNode(const textool::INode::Ptr& node);
};
}
}