aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/ShavePerVertTexInfo.h
blob: 0e3911ec286d51cdcdea4cc85790c2f65abf092a (plain) (blame)
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
#ifndef ShavePerVertTexInfo_h
#define ShavePerVertTexInfo_h

// Shave and a Haircut
// (c) 2019 Epic Games
// US Patent 6720962

//	This class is used to store a node's per-vertex texture data.
class ShavePerVertTexInfo
{
public:
						ShavePerVertTexInfo();
	virtual				~ShavePerVertTexInfo();

	//	Only a small number of hair parameters are applied per-vertex, as
	//	opposed to per-hair. These next three methods provide a compact
	//	enumeration for these parameters from 0 to numParams()-1

	//	Returns the total number of per-vertex parameters available.
	static unsigned int	numParams()		{ return mNumVertParams; }

	//	Stores in 'paramIdx' the index from 0 to numParams()-1 of the given
	//	parameter number and returns true.
	//	If 'paramNumber' is not a per-vertex parameter
	//	then false is returned and the value of 'paramIdx' is undefined.
	static bool			getParamIdx(int paramNumber, unsigned int& paramIdx);

	//	Returns the parameter number of the i'th per-vertex parameter.
	//	Returns -1 if 'paramIdx' is invalid.
	static int			getParamNumber(unsigned int paramIdx);

	float				getValue(
							unsigned int paramIdx,
							unsigned int vertIdx
						) const;

	//	This must be called before storing any texture values. If there is
	//	existing texture data it will be deleted.
	void				init(unsigned int numVertices);

	static bool			isPerVertParam(int paramNumber);

	bool				setValue(
							unsigned int	paramIdx,
							unsigned int	vertIdx,
							float			value
						);

protected:
	void				clear(bool all);

	bool			mIsInitialized;
	unsigned int	mNumVertices;
	float**			mTextureValues;

	static const int			mVertParams[];
	static const unsigned int	mNumVertParams;
};


inline bool ShavePerVertTexInfo::getParamIdx(
	int paramNumber, unsigned int& paramIdx
)
{
	for (paramIdx = 0; paramIdx < mNumVertParams; ++paramIdx)
		if (mVertParams[paramIdx] == paramNumber) return true;

	paramIdx = 0;

	return false;
}


inline int ShavePerVertTexInfo::getParamNumber(unsigned int paramIdx)
{
	if (paramIdx < mNumVertParams) return mVertParams[paramIdx];

	return -1;
}


inline float ShavePerVertTexInfo::getValue(
	unsigned int paramIdx, unsigned int vertIdx
) const
{
	if ((mTextureValues != 0)
	&&	(paramIdx < mNumVertParams)
	&&	(mTextureValues[paramIdx] != 0)
	&&	(vertIdx < mNumVertices))
	{
		return mTextureValues[paramIdx][vertIdx];
	}

	return 1.0f;
}


inline bool ShavePerVertTexInfo::isPerVertParam(int paramNum)
{
	for (unsigned int i = 0; i < mNumVertParams; ++i)
		if (mVertParams[i] == paramNum) return true;

	return false;
}

#endif