summaryrefslogtreecommitdiff
path: root/Runtime/mecanim/graph/xformnode.h
blob: d0abf24a8df9203e6d30bd8a348637fc64a215b3 (plain)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 Copyright (c) 7244339 Canada Inc. (Mecanim)
 All Rights Reserved.
*/
#pragma once

#include "Runtime/mecanim/defs.h"
#include "Runtime/mecanim/memory.h"
#include "Runtime/mecanim/types.h"
#include "Runtime/mecanim/object.h"

#include "Runtime/Math/Simd/math.h" 

#include "Runtime/mecanim/graph/plug.h"
#include "Runtime/mecanim/graph/node.h"

#include "Runtime/mecanim/graph/unarynode.h"

#include "Runtime/mecanim/generic/stringtable.h"

namespace mecanim
{

namespace graph
{
	class IdentityOp
	{
	public:
		template<typename RESULT> static math::xform Operation(){ return math::xformIdentity(); } 
	};

	class xformIdentity : public ResultNode<math::xform, IdentityOp> 
	{
	public: 
		static const eNodeType mId = xformIdentityId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformMulVecOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::float4 Operation( math::xform const& l, math::float4 const& r){ return math::xformMulVec(l, r); } 
	};

	class xformMulVec : public BinaryNode<math::xform, math::float4, math::float4, xformMulVecOp> 
	{
	public: 
		static const eNodeType mId = xformMulVecId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformInvMulVecOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::float4 Operation( math::xform const& l, math::float4 const& r){ return math::xformInvMulVec(l, r); } 
	};

	class xformInvMulVec : public BinaryNode<math::xform, math::float4, math::float4, xformInvMulVecOp> 
	{
	public: 
		static const eNodeType mId = xformInvMulVecId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformMulOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, math::xform const& r){ return math::xformMul(l, r); } 
	};

	class xformMul : public BinaryNode<math::xform, math::xform, math::xform, xformMulOp> 
	{
	public: 
		static const eNodeType mId = xformMulId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformInvMulOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, math::xform const& r){ return math::xformInvMul(l, r); } 
	};

	class xformInvMul : public BinaryNode<math::xform, math::xform, math::xform, xformInvMulOp> 
	{
	public: 
		static const eNodeType mId = xformInvMulId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformMulInvOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, math::xform const& r){ return math::xformMulInv(l, r); } 
	};

	class xformMulInv : public BinaryNode<math::xform, math::xform, math::xform, xformMulInvOp> 
	{
	public: 
		static const eNodeType mId = xformMulInvId; 
		virtual eNodeType NodeType(){ return mId;}
	};

	class xformEqualOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static bool Operation( math::xform const& l, math::xform const& r){ return l == r; } 
	};

	class xformEqual : public BinaryNode<math::xform, math::xform, bool, xformEqualOp> 
	{
	public: 
		static const eNodeType mId = xformEqualId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformWeightOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, float r){ return math::xformWeight(l, math::float1(r)); } 
	};

	class xformWeight : public BinaryNode<math::xform, float, math::xform, xformWeightOp> 
	{
	public: 
		static const eNodeType mId = xformWeightId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformBlendOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename TYPE3, typename RESULT> static math::xform Operation( math::xform const& a,math::xform const& b, float const& c){ return math::xformBlend(a,b,math::float1(c)); } 
	};

	class xformBlend : public TernaryNode<math::xform, math::xform, float, math::xform, xformBlendOp> 
	{
	public: 
		static const eNodeType mId = xformBlendId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformAddOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, math::xform const& r){ return math::xformAdd(l, r); } 
	};

	class xformAdd : public BinaryNode<math::xform, math::xform, math::xform, xformAddOp> 
	{
	public: 
		static const eNodeType mId = xformAddId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformSubOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename RESULT> static math::xform Operation( math::xform const& l, math::xform const& r){ return math::xformSub(l, r); } 
	};

	class xformSub : public BinaryNode<math::xform, math::xform, math::xform, xformSubOp> 
	{
	public: 
		static const eNodeType mId = xformSubId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformComposeOp
	{
	public:
		template<typename TYPE1, typename TYPE2, typename TYPE3, typename RESULT> static math::xform Operation( math::float4 const& t, math::float4 const& q, math::float4 const& s){ return math::xform(t, q, s); } 
	};

	class xformCompose : public TernaryNode<math::float4, math::float4, math::float4, math::xform, xformComposeOp> 
	{
	public: 
		xformCompose()
		{
			mA.m_ID = CRCKey(eT);
			mB.m_ID = CRCKey(eQ);
			mC.m_ID = CRCKey(eS);
		}
		static const eNodeType mId = xformComposeId; 
		virtual eNodeType NodeType(){return mId;}
	};

	class xformDecompose : public Node
	{
	public:
		static const eNodeType mId = xformDecomposeId; 
		virtual eNodeType NodeType(){return mId;}

		TypePlug<math::xform> mX;
		TypePlug<math::float4> mT;
		TypePlug<math::float4> mQ;
		TypePlug<math::float4> mS;

		xformDecompose()
			:mX(true,CRCKey(eX)),
			mT(false,CRCKey(eT)),
			mQ(false,CRCKey(eQ)),
			mS(false,CRCKey(eS))
		{
			mX.m_Owner = this;
			mT.m_Owner = this;
			mQ.m_Owner = this;
			mS.m_Owner = this;
		}

		virtual ~xformDecompose(){}

		virtual uint32_t GetPlugCount()const 
		{
			return 4;
		}
		virtual GraphPlug& GetPlug(uint32_t aIndex)
		{
			switch(aIndex)
			{
				case 0: return mX;
				case 1: return mT;
				case 2: return mQ;
				case 3: 
				default:return mS;
			}
		}
		virtual GraphPlug const& GetPlug(uint32_t aIndex)const
		{
			switch(aIndex)
			{
				case 0: return mX;
				case 1: return mT;
				case 2: return mQ;
				case 3: 
				default:return mS;
			}
		}

		virtual void Evaluate(EvaluationInfo& arEvaluationInfo)
		{
			math::xform x;
			
			mX.ReadData(&x, arEvaluationInfo);	
			
			mT.WriteData(&x.t, arEvaluationInfo);
			mQ.WriteData(&x.q, arEvaluationInfo);
			mS.WriteData(&x.s, arEvaluationInfo);
		}
	};

	class xformRefChange : public Node
	{
	public:
		static const eNodeType mId = xformRefChangeId; 
		virtual eNodeType NodeType(){return mId;}

		TypePlug<math::xform> mSrcRefX;
		TypePlug<math::xform> mDstRefX;
		TypePlug<math::xform> mSrcPivotX;
		TypePlug<math::xform> mDstPivotX;
		TypePlug<float> mRefWeight;
		TypePlug<float> mPivotWeight;
		TypePlug<math::xform> mXI;
		TypePlug<math::xform> mXO;

		xformRefChange()	:	mSrcRefX(true,CRCKey(eSrcRefX)),
								mDstRefX(true,CRCKey(eDstRefX)),
								mSrcPivotX(true,CRCKey(eSrcPivotX)),
								mDstPivotX(true,CRCKey(eDstPivotX)),
								mRefWeight(true,CRCKey(eRefWeight)),
								mPivotWeight(true,CRCKey(ePivotWeight)),
								mXI(true,CRCKey(eXI)),
								mXO(false,CRCKey(eXO))
		{
			mSrcRefX.m_Owner = this;
			mDstRefX.m_Owner = this;
			mSrcPivotX.m_Owner = this;
			mDstPivotX.m_Owner = this;
			mRefWeight.m_Owner = this;
			mPivotWeight.m_Owner = this;
			mXI.m_Owner = this;
			mXO.m_Owner = this;
		}

		virtual ~xformRefChange(){}

		virtual uint32_t GetPlugCount()const 
		{
			return 8;
		}
		virtual GraphPlug& GetPlug(uint32_t aIndex)
		{
			switch(aIndex)
			{
				case 0:		return mSrcRefX;
				case 1:		return mDstRefX;
				case 2:		return mSrcPivotX;
				case 3:		return mDstPivotX;
				case 4:		return mRefWeight;
				case 5:		return mPivotWeight;
				case 6:		return mXI;
				case 7:
				default:	return mXO;
			}
		}
		virtual GraphPlug const& GetPlug(uint32_t aIndex)const
		{
			switch(aIndex)
			{
				case 0:		return mSrcRefX;
				case 1:		return mDstRefX;
				case 2:		return mSrcPivotX;
				case 3:		return mDstPivotX;
				case 4:		return mRefWeight;
				case 5:		return mPivotWeight;
				case 6:		return mXI;
				case 7:
				default:	return mXO;
			}
		}

		virtual void Evaluate(EvaluationInfo& arEvaluationInfo)
		{
			math::xform srcRefX, dstRefX, srcPivotX, dstPivotX, xi, xo;
			float rw,pw;
			
			mSrcRefX.ReadData(&srcRefX, arEvaluationInfo);	
			mDstRefX.ReadData(&dstRefX, arEvaluationInfo);	
			mSrcPivotX.ReadData(&srcPivotX, arEvaluationInfo);	
			mDstPivotX.ReadData(&dstPivotX, arEvaluationInfo);	
			mRefWeight.ReadData(&rw, arEvaluationInfo);	
			mPivotWeight.ReadData(&pw, arEvaluationInfo);	
			mXI.ReadData(&xi,arEvaluationInfo);	

			xo = math::xformMul(xi,srcPivotX);
			xo = math::xformInvMul(srcRefX,xo);
			xo = math::xformWeight(xo,math::float1(1-pw));
			xo = math::xformMul(dstRefX,xo);
			xo = math::xformMulInv(xo,dstPivotX);
			xo = math::xformBlend(xi,xo,math::float1(rw));

			mXO.WriteData(&xo, arEvaluationInfo);
		}
	};
}

}