summaryrefslogtreecommitdiff
path: root/Runtime/mecanim/animation/avatar.h
blob: e90be7af04e73dfd565d788219aeb979266f89dd (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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
#pragma once

#include "Runtime/mecanim/defs.h"
#include "Runtime/mecanim/memory.h"
#include "Runtime/mecanim/types.h"
#include "Runtime/mecanim/bind.h"
#include "Runtime/Math/Simd/float4.h"

#include "Runtime/mecanim/skeleton/skeleton.h"
#include "Runtime/mecanim/human/human.h"
#include "Runtime/mecanim/animation/clipmuscle.h"
#include "Runtime/mecanim/animation/curvedata.h"
#include "Runtime/mecanim/statemachine/statemachine.h"

#include "Runtime/Serialize/Blobification/offsetptr.h"
#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h"
#include "Runtime/Animation/MecanimArraySerialization.h" 

typedef UInt32 BindingHash;

namespace mecanim
{

	static const uint32_t DISABLED_SYNCED_LAYER_IN_NON_PRO = 0xffffffff;
	struct ValueArrayConstant;

	typedef int ProcessString(mecanim::String const&);
	
	namespace animation
	{
		struct ClipMuscleConstant;
		struct AvatarConstant;
		struct ControllerConstant;

		enum LayerBlendingMode
		{
			kLayerBlendingModeOverride,
			kLayerBlendingModeAdditive		
		};
	
		struct LayerConstant
		{
			DEFINE_GET_TYPESTRING(LayerConstant)

			LayerConstant():m_IKPass(true), m_SyncedLayerAffectsTiming(false), m_LayerBlendingMode(kLayerBlendingModeOverride){}

			uint32_t				m_StateMachineIndex;
			uint32_t				m_StateMachineMotionSetIndex;

			human::HumanPoseMask	m_BodyMask;
			OffsetPtr<skeleton::SkeletonMask> m_SkeletonMask;
									
			uint32_t				m_Binding;
			uint32_t				m_LayerBlendingMode; //LayerBlendingMode
			float					m_DefaultWeight;
			bool					m_IKPass;
			bool					m_SyncedLayerAffectsTiming;

			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{				

				TRANSFER(m_StateMachineIndex);
				TRANSFER(m_StateMachineMotionSetIndex);
				TRANSFER(m_BodyMask);
				TRANSFER(m_SkeletonMask);				
				TRANSFER(m_Binding);			
				TRANSFER((int&)m_LayerBlendingMode);
				TRANSFER(m_DefaultWeight);
				TRANSFER(m_IKPass);
				TRANSFER(m_SyncedLayerAffectsTiming);
				transfer.Align();	
				
				
			}
		};

		struct ControllerConstant
		{
			DEFINE_GET_TYPESTRING(ControllerConstant)

			ControllerConstant():	m_LayerCount(0),
									m_StateMachineCount(0) {}

			uint32_t													m_LayerCount;
			OffsetPtr< OffsetPtr<LayerConstant> >						m_LayerArray;

			uint32_t													m_StateMachineCount;
			OffsetPtr< OffsetPtr<statemachine::StateMachineConstant> >	m_StateMachineArray;

			OffsetPtr<ValueArrayConstant>								m_Values;													
			OffsetPtr<ValueArray>										m_DefaultValues;		

			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{
				TRANSFER_BLOB_ONLY(m_LayerCount);
				MANUAL_ARRAY_TRANSFER2( OffsetPtr<mecanim::animation::LayerConstant>, m_LayerArray, m_LayerCount);
				
				TRANSFER_BLOB_ONLY(m_StateMachineCount);
				MANUAL_ARRAY_TRANSFER2( OffsetPtr<mecanim::statemachine::StateMachineConstant>, m_StateMachineArray, m_StateMachineCount);
				
				TRANSFER(m_Values);							
				TRANSFER(m_DefaultValues);
				
			}	

			static void InitializeClass();
		};

		struct SkeletonTQSMap
		{
			SkeletonTQSMap() : m_TIndex(-1), m_QIndex(-1), m_SIndex(-1) {};

			int32_t m_TIndex;
			int32_t m_QIndex;
			int32_t m_SIndex;
		};
		
		struct ClipBindings
		{
			ClipBindings () : m_PositionIndex(0), m_QuaternionIndex(0), m_ScaleIndex(0), m_FloatIndex(0), m_IntIndex(0), m_IntegerRemap(0)  {}
			
			// Maps from the curve float array of the clip to the ValueArrayConstant.
			// This allows us to bring the curve float array into a ValueArray that has the same layout between all clips.
			int16_t* m_PositionIndex;
			int16_t* m_QuaternionIndex;
			int16_t* m_ScaleIndex;
			int16_t* m_FloatIndex;
			int16_t* m_IntIndex;
			
			// Points directly to AnimationClipBindingConstant pptrCurveMapping.
			int32_t* m_IntegerRemap;
		};

		struct AnimationSet
		{	
			struct Clip
			{
				Clip() : m_Clip(0), m_TotalUsedOptimizedCurveCount(0), m_ClipIndex(-1) {}

				// The referenced constant clip
				ClipMuscleConstant*	m_Clip;
				int32_t m_ClipIndex;
				// The amount of ConstantClip curves that need to be sampled (Constant curves are often ignored during binding if they are determined to have no impact)
				uint32_t            m_TotalUsedOptimizedCurveCount;
				// Binding indices to index from the curve float[] to the ValueArray
				ClipBindings        m_Bindings;
			};

			AnimationSet() :	m_MaxBlendState(0),
								m_LayerCount(0), 
								m_ClipPerLayer(0),
								m_ClipConstant(0), 
								m_AdditionalCount(0), 
								m_AdditionalIndexArray(0),
								m_DynamicFullValuesConstant(0),
								m_DynamicValuesMaskArray(0),
								m_GravityWeightIndex(-1),
								m_IntegerRemapStride(-1)
								{}

			uint32_t										m_MaxBlendState;
			uint32_t										m_LayerCount;
			uint32_t*										m_ClipPerLayer;

			Clip**											m_ClipConstant;
			
			uint32_t										m_AdditionalCount;
			int32_t*										m_AdditionalIndexArray;

			mecanim::ValueArrayConstant*					m_DynamicFullValuesConstant;
			mecanim::ValueArrayMask**						m_DynamicValuesMaskArray;

			int32_t											m_GravityWeightIndex;
			int32_t											m_IntegerRemapStride;
		};

		struct ControllerBindingConstant
		{
			ControllerBindingConstant():	m_DynamicValuesDefault(0),
											m_SkeletonTQSMap(0),
											m_RootMotionLayerMask(0),
											m_Avatar(0),
											m_Controller(0),
											m_DynamicValuesConstant(0),
											m_AnimationSet(0) {}

			ValueArrayConstant*								m_DynamicValuesConstant;
			ValueArray*										m_DynamicValuesDefault;		

			SkeletonTQSMap*									m_SkeletonTQSMap;

			bool*											m_RootMotionLayerMask;

			AvatarConstant const*							m_Avatar;
			ControllerConstant const*						m_Controller;
			AnimationSet const*								m_AnimationSet;
		};

		struct AnimationSetMemory
		{
			AnimationSetMemory() : m_LayerCount(0), m_ClipPerLayer(0), m_ClipMemory(0), m_ClipOutput(0) {}

			uint32_t				m_LayerCount;
			uint32_t*				m_ClipPerLayer;
			ClipMemory***			m_ClipMemory;
			ClipOutput*				m_ClipOutput;
		};

		template<bool dynamic>
		struct BlendingState
		{
			BlendingState():
				m_DynamicValuesBlending(0),
				m_MotionBlending(0),
				m_HumanPoseBlending(0),
				m_BlendFactor(0)
			{}

			ValueArray**				m_DynamicValuesBlending;
			MotionOutput**				m_MotionBlending;
			human::HumanPose**			m_HumanPoseBlending;
			float* m_BlendFactor;

			uint32_t					m_Size;
		};

		template<>
		struct BlendingState<false>
		{
			BlendingState(): m_BlendFactor(0) {}

			OffsetPtr<ValueArray> m_DynamicValuesBlending;
			OffsetPtr<ValueArrayMask> m_DynamicValuesBlendingMask;
			OffsetPtr<MotionOutput>	m_MotionBlending;
			OffsetPtr<human::HumanPose>	m_HumanPoseBlending;
			float m_BlendFactor;
		};

		struct BlendingClip
		{
			BlendingClip() : m_ClipIndex(-1), m_LayerIndex(-1), m_Weight(0), m_PrevTime(0), m_Time(0), m_Reverse(false) {}

			int m_ClipIndex;
			int m_LayerIndex;
			float m_Weight;
			float m_PrevTime;
			float m_Time;
			bool m_Reverse;
		};

		struct ControllerMemory
		{
			DEFINE_GET_TYPESTRING(ControllerMemory)

			ControllerMemory():	m_StateMachineCount(0),
								m_LayerCount(0) {}

			uint32_t													m_StateMachineCount;
			OffsetPtr< OffsetPtr<statemachine::StateMachineMemory> >	m_StateMachineMemory;

			uint32_t													m_LayerCount;
			OffsetPtr<BlendingState<false> >							m_InteruptedTransitionsBlendingStateArray;
			OffsetPtr<float>											m_LayerWeights;

			OffsetPtr<ValueArray>										m_Values;

			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{
				TRANSFER_BLOB_ONLY(m_StateMachineCount);
				MANUAL_ARRAY_TRANSFER2( OffsetPtr<mecanim::statemachine::StateMachineMemory>, m_StateMachineMemory, m_StateMachineCount);

				TRANSFER_BLOB_ONLY(m_LayerCount);
				MANUAL_ARRAY_TRANSFER2( BlendingState<false>, m_InteruptedTransitionsBlendingStateArray, m_LayerCount);						
				MANUAL_ARRAY_TRANSFER2( float, m_LayerWeights, m_LayerCount);

				TRANSFER(m_Values);							
			}
		};

		struct ControllerWorkspace 
		{
			ControllerWorkspace() :	m_StateMachineWorkspace(0),
									m_StateMachineOutput(0),
									m_BlendingState(0),
									m_BlendingClipCount(0),
									m_BlendingClipArray(0),
									m_ValueArrayStart(0),
									m_ValueArrayStop(0),
									m_ReadMask(0),
									m_BlendMask(0),
									m_DefaultMask(0),
									m_DoIK(false),
									m_DoWrite(false) {}
	
			statemachine::StateMachineWorkspace**   m_StateMachineWorkspace;
			statemachine::StateMachineOutput**		m_StateMachineOutput;
			
			uint32_t								m_StateMachineCount;

			float*									m_MotionSetTimingWeightArray;

			BlendingState<true>*					m_BlendingState;
			BlendingState<false>					m_BlendingStateWs;

			int										m_BlendingClipCount;
			BlendingClip*							m_BlendingClipArray;

			ValueArray								*m_ValueArrayStart;
			ValueArray								*m_ValueArrayStop;

			ValueArrayMask							*m_ReadMask;
			ValueArrayMask							*m_BlendMask;
			ValueArrayMask							*m_DefaultMask;

			bool									m_DoIK;
			bool									m_DoWrite;
		};

		struct ExposedTransform
		{
			DEFINE_GET_TYPESTRING(ExposedTransform);

			// For SkinnedMeshRenderer, the following two indices are different
			// - 'skeletonIndex'
			//		corresponds to the SkinnedMeshRenderer itself
			// - 'skeletonIndexForUpdateTransform'
			//		corresponds to the root bone of the SkinnedMeshRenderer
			uint32_t	skeletonIndex;
			uint32_t    skeletonIndexForUpdateTransform;

			BindingHash	transformPath;		// flattened path

			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{
				TRANSFER(skeletonIndex);
				TRANSFER(skeletonIndexForUpdateTransform);
				TRANSFER(transformPath);
			}	
		};

		struct AvatarConstant
		{
			DEFINE_GET_TYPESTRING(AvatarConstant)

			AvatarConstant() :	m_SkeletonNameIDCount(0), 
								m_HumanSkeletonIndexCount(0),
								m_HumanSkeletonReverseIndexCount(0),
								m_RootMotionBoneIndex(-1), 
								m_RootMotionBoneX(math::xformIdentity()),
								m_RootMotionSkeletonIndexCount(0) {}

			OffsetPtr<skeleton::Skeleton>			m_AvatarSkeleton;
			OffsetPtr<skeleton::SkeletonPose>		m_AvatarSkeletonPose;

			OffsetPtr<skeleton::SkeletonPose>		m_DefaultPose;	// The default pose when model is imported.

			uint32_t								m_SkeletonNameIDCount;
			OffsetPtr<uint32_t>						m_SkeletonNameIDArray;	// CRC(name)

			OffsetPtr<human::Human>					m_Human;

			uint32_t								m_HumanSkeletonIndexCount;
			OffsetPtr<int32_t>						m_HumanSkeletonIndexArray;

			// needed to update human pose and additonal bones in optimize mode
			// decided to put the info in constant for perf and memory reason vs doing masking at runtime
			uint32_t								m_HumanSkeletonReverseIndexCount;
			OffsetPtr<int32_t>						m_HumanSkeletonReverseIndexArray;

			int32_t									m_RootMotionBoneIndex;
			math::xform								m_RootMotionBoneX;
			OffsetPtr<skeleton::Skeleton>			m_RootMotionSkeleton;
			OffsetPtr<skeleton::SkeletonPose>		m_RootMotionSkeletonPose;
			uint32_t								m_RootMotionSkeletonIndexCount;
			OffsetPtr<int32_t>						m_RootMotionSkeletonIndexArray;

			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{
				transfer.SetVersion(3);

				TRANSFER(m_AvatarSkeleton);

				TRANSFER(m_AvatarSkeletonPose);
				TRANSFER(m_DefaultPose);

				TRANSFER_BLOB_ONLY(m_SkeletonNameIDCount);
				MANUAL_ARRAY_TRANSFER2(uint32_t,m_SkeletonNameIDArray,m_SkeletonNameIDCount);	

				TRANSFER(m_Human);

				TRANSFER_BLOB_ONLY(m_HumanSkeletonIndexCount);
				MANUAL_ARRAY_TRANSFER2(int32_t,m_HumanSkeletonIndexArray,m_HumanSkeletonIndexCount);	

				TRANSFER_BLOB_ONLY(m_HumanSkeletonReverseIndexCount);
				MANUAL_ARRAY_TRANSFER2(int32_t,m_HumanSkeletonReverseIndexArray,m_HumanSkeletonReverseIndexCount);	

				TRANSFER(m_RootMotionBoneIndex);
				TRANSFER(m_RootMotionBoneX);
				TRANSFER(m_RootMotionSkeleton);
				TRANSFER(m_RootMotionSkeletonPose);

				TRANSFER_BLOB_ONLY(m_RootMotionSkeletonIndexCount);
				MANUAL_ARRAY_TRANSFER2(int32_t,m_RootMotionSkeletonIndexArray,m_RootMotionSkeletonIndexCount);	

				transfer.Align();

				if (transfer.IsVersionSmallerOrEqual (1))
				{
					if(m_RootMotionBoneIndex != -1)
					{
						mecanim::memory::Allocator *alloc = reinterpret_cast<mecanim::memory::Allocator *>(transfer.GetUserData());

						m_RootMotionSkeleton = skeleton::CreateSkeleton(m_AvatarSkeleton->m_Count,m_AvatarSkeleton->m_AxesCount,*alloc);
						skeleton::SkeletonCopy(m_AvatarSkeleton.Get(),m_RootMotionSkeleton.Get());

						m_RootMotionSkeletonPose = skeleton::CreateSkeletonPose(m_RootMotionSkeleton.Get(),*alloc);
						skeleton::SkeletonPoseCopy(m_AvatarSkeletonPose.Get(),m_RootMotionSkeletonPose.Get());						
						
						m_RootMotionSkeletonIndexCount = m_AvatarSkeleton->m_Count;
						m_RootMotionSkeletonIndexArray = alloc->ConstructArray<mecanim::int32_t>(m_RootMotionSkeletonIndexCount);

						for(int i = 0; i < m_RootMotionSkeletonIndexCount; i++)
						{
							m_RootMotionSkeletonIndexArray[i] = i;
						}
					}
				}

				if (transfer.IsVersionSmallerOrEqual (2))
				{
					if(isHuman())
					{
						mecanim::memory::Allocator *alloc = reinterpret_cast<mecanim::memory::Allocator *>(transfer.GetUserData());

						m_HumanSkeletonReverseIndexCount = m_AvatarSkeleton->m_Count;
						m_HumanSkeletonReverseIndexArray = alloc->ConstructArray<mecanim::int32_t>(m_HumanSkeletonReverseIndexCount);
						skeleton::SkeletonBuildReverseIndexArray(m_HumanSkeletonReverseIndexArray.Get(),m_HumanSkeletonIndexArray.Get(),m_Human->m_Skeleton.Get(),m_AvatarSkeleton.Get());
					}
				}
			}

			bool isHuman() const { return !m_Human.IsNull() && m_Human->GetTypeString() != 0 && m_Human->m_Skeleton->m_Count > 0; };

			static void InitializeClass();
		};

		struct AvatarInput 
		{
			AvatarInput() : m_GotoStateInfos(0), m_DeltaTime(0), m_TargetIndex(-1), m_TargetTime(1), m_FeetPivotActive(1), m_StabilizeFeet(false), m_ForceStateTime(false), m_StateTime(0), m_LayersAffectMassCenter(false) {}

			statemachine::GotoStateInfo*	m_GotoStateInfos;
			float			m_DeltaTime;
			int				m_TargetIndex;
			float			m_TargetTime;

			float			m_FeetPivotActive;
			bool			m_StabilizeFeet;

			bool			m_ForceStateTime;
			float			m_StateTime;
			bool			m_LayersAffectMassCenter;
		};
		
		struct AvatarMemory
		{
			DEFINE_GET_TYPESTRING(AvatarMemory)

			AvatarMemory() :	m_AvatarX(math::xformIdentity()),
								m_LeftFootX(math::xformIdentity()),
								m_RightFootX(math::xformIdentity()),
								m_Pivot(math::float4::zero()),
								m_PivotWeight(0.5),								
								m_FirstEval(1),
								m_SkeletonPoseOutputReady(0) {}

			OffsetPtr<ControllerMemory>		m_ControllerMemory;

			math::xform						m_AvatarX;
			
			math::xform						m_LeftFootX;
			math::xform						m_RightFootX;			
			math::float4					m_Pivot;

			float							m_PivotWeight;
			UInt8							m_FirstEval;
			UInt8							m_SkeletonPoseOutputReady;


			template<class TransferFunction>
			inline void Transfer (TransferFunction& transfer)
			{
				TRANSFER(m_ControllerMemory);
				TRANSFER(m_AvatarX);
				TRANSFER(m_LeftFootX);
				TRANSFER(m_RightFootX);
				TRANSFER(m_Pivot);
				TRANSFER(m_PivotWeight);
				TRANSFER(m_FirstEval);
				TRANSFER(m_SkeletonPoseOutputReady);
				transfer.Align();
			}
		};

		struct AvatarWorkspace 
		{
			AvatarWorkspace() : m_BodySkeletonPoseWs(0),
								m_BodySkeletonPoseWsA(0),
								m_BodySkeletonPoseWsB(0),
								m_RootMotionSkeletonPoseWsA(0),
								m_RootMotionSkeletonPoseWsB(0),
								m_HumanPoseWs(0),
								m_ControllerWorkspace(0),
								m_LeftFootSpeedT(0),
								m_LeftFootSpeedQ(0),
								m_RightFootSpeedT(0),
								m_RightFootSpeedQ(0),
								m_IKOnFeet(false)
								{} 
				
			skeleton::SkeletonPose*					m_BodySkeletonPoseWs;
			skeleton::SkeletonPose*					m_BodySkeletonPoseWsA;
			skeleton::SkeletonPose*					m_BodySkeletonPoseWsB;
		
			skeleton::SkeletonPose*					m_RootMotionSkeletonPoseWsA;
			skeleton::SkeletonPose*					m_RootMotionSkeletonPoseWsB;

			human::HumanPose*						m_HumanPoseWs;

			ControllerWorkspace*					m_ControllerWorkspace;
		
			math::xform								m_AvatarX;
			
			float									m_LeftFootSpeedT;
			float									m_LeftFootSpeedQ;
			float									m_RightFootSpeedT;
			float									m_RightFootSpeedQ;
			bool									m_IKOnFeet;
		};

		struct AvatarOutput 
		{
			AvatarOutput() :		m_DynamicValuesOutput(0),
									m_SkeletonPoseOutput(0),
									m_MotionOutput(0),
									m_HumanPoseBaseOutput(0),
									m_HumanPoseOutput(0) {}
	
			ValueArray*				m_DynamicValuesOutput;

			skeleton::SkeletonPose*	m_SkeletonPoseOutput;

			MotionOutput*			m_MotionOutput;
			human::HumanPose*		m_HumanPoseBaseOutput;
			human::HumanPose*		m_HumanPoseOutput;
		};

		AvatarConstant*     CreateAvatarConstant(	skeleton::Skeleton* skeleton,
													skeleton::SkeletonPose* skeletonPose,
													skeleton::SkeletonPose* defaultPose,
													human::Human* human,
													skeleton::Skeleton* rootMotionSkeleton,
													int rootMotionIndex,
													math::xform const& rootMotionX,
													memory::Allocator& alloc);

		void				DestroyAvatarConstant(AvatarConstant* constant, memory::Allocator& alloc);

		void				InitializeAvatarConstant(AvatarConstant * constant, memory::Allocator& alloc);
		void				ClearAvatarConstant(AvatarConstant * constant, memory::Allocator& alloc);

		ControllerConstant* CreateControllerConstant(	uint32_t LayerCount, LayerConstant** layerArray,
														uint32_t stateMachineCount, statemachine::StateMachineConstant** stateMachineConstant,
														ValueArrayConstant* values, ValueArray* defaultValues,
														memory::Allocator& alloc);

		void				DestroyControllerConstant(ControllerConstant* controller, memory::Allocator& alloc);

		void				InitializeControllerConstant(ControllerConstant * controller, memory::Allocator& alloc);
		void				ClearControllerConstant(ControllerConstant * controller, memory::Allocator& alloc);
		
		LayerConstant* CreateLayerConstant(mecanim::uint32_t stateMachineIndex, mecanim::uint32_t motionSetIndex, memory::Allocator& alloc);
		void				DestroyLayerConstant(LayerConstant* constant, memory::Allocator& alloc);

		ControllerMemory* CreateControllerMemory(ControllerConstant const* controller, AvatarConstant const *avatar, AnimationSet const *animationSet, const ValueArrayConstant* dynamicValueConstant, memory::Allocator& alloc);
		void						DestroyControllerMemory(ControllerMemory* memory, memory::Allocator& alloc);

		ControllerWorkspace*		CreateControllerWorkspace(ControllerConstant const* controller, AvatarConstant const *avatar, AnimationSet const *animationSet, const ValueArrayConstant* dynamicValueConstant, memory::Allocator& alloc);
		void						DestroyControllerWorkspace(ControllerWorkspace* workspace, memory::Allocator& alloc);

		AvatarInput*		CreateAvatarInput(AvatarConstant const* constant, memory::Allocator& alloc);
		void				DestroyAvatarInput(AvatarInput* input, memory::Allocator& alloc);

		AvatarMemory*		CreateAvatarMemory(AvatarConstant const* constant, memory::Allocator& alloc);
		void				DestroyAvatarMemory(AvatarMemory* memory, memory::Allocator& alloc);

		AvatarWorkspace*	CreateAvatarWorkspace(AvatarConstant const* constant, memory::Allocator& alloc);
		void				DestroyAvatarWorkspace(AvatarWorkspace* workspace, memory::Allocator& alloc);

		AvatarOutput*		CreateAvatarOutput(AvatarConstant const* constant, bool hasTransformHierarchy, memory::Allocator& alloc);
		void				DestroyAvatarOutput(AvatarOutput* output, memory::Allocator& alloc);

		AnimationSet*		CreateAnimationSet(ControllerConstant const* controller, memory::Allocator& alloc);
		void				DestroyAnimationSet(AnimationSet* animationSet, memory::Allocator& alloc);

		AnimationSetMemory*	CreateAnimationSetMemory(AnimationSet const* animationSet, bool allowConstantCurveOptimization, memory::Allocator& alloc);
		void				DestroyAnimationSetMemory(AnimationSetMemory* animationSetMemory, memory::Allocator& alloc);		

		void UpdateLeafNodeDuration(const ControllerConstant &controllerConstant, const AnimationSet &animationSet, ControllerMemory &controllerMemory);

		void				SetIKOnFeet(		bool left,
												AvatarConstant const &avatar, 
												const AvatarInput &input, 
												AvatarMemory &memory, 
												AvatarWorkspace &workspace, 
												AvatarOutput &output);

		void				EvaluateAvatarSM(	AvatarConstant const* constant, 
												AvatarInput const* input, 
												AvatarOutput * output, 
												AvatarMemory * memory, 
												AvatarWorkspace * workspace,
												ControllerConstant const* controllerConstant);

		void				EvaluateAvatarLayers(	ControllerBindingConstant const* controllerBindingConstant, 
													AvatarInput const* input, 
													AvatarOutput *output, 
													AvatarMemory *memory, 
													AvatarWorkspace *workspace,
													AnimationSetMemory* animationSetMemory);

		void				EvaluateAvatarX(	AvatarConstant const* constant, 
												AvatarInput const* input, 
												AvatarOutput *output, 
												AvatarMemory *memory, 
												AvatarWorkspace *workspace);

		void				EvaluateAvatarRetarget(	AvatarConstant const* constant, 
													AvatarInput const* input, 
													AvatarOutput *output, 
													AvatarMemory *memory, 
													AvatarWorkspace *workspace,
													ControllerConstant const* controllerConstant);

		void				EvaluateAvatarIK(	AvatarConstant const* constant, 
												AvatarInput const* input, 
												AvatarOutput *output, 
												AvatarMemory *memory, 
												AvatarWorkspace *workspace,
												ControllerConstant const* controllerConstant);

		void				EvaluateAvatarEnd(	AvatarConstant const* constant, 
													AvatarInput const* input, 
													AvatarOutput *output, 
													AvatarMemory *memory, 
													AvatarWorkspace *workspace,
													ControllerConstant const* controllerConstant);

	void ValuesFromClip(	mecanim::ValueArray const &valuesDefault,
							mecanim::animation::ClipMuscleConstant const &cst, 
							mecanim::animation::ClipOutput const &out,
							const ClipBindings& bindings,
							int32_t        integerRemapStride,
							mecanim::ValueArray &values,
							mecanim::ValueArrayMask &mask);

	void DeltasFromClip(	mecanim::animation::ClipMuscleConstant const &cst,
							const ClipBindings& bindings,
							const ValueArrayMask& mask,
							mecanim::ValueArray &starts,
							mecanim::ValueArray &stops);

	void SkeletonPoseFromValue(skeleton::Skeleton const &skeleton, skeleton::SkeletonPose const &defaultPose, ValueArray const &values, SkeletonTQSMap const *skeletonTQSMap, skeleton::SkeletonPose &pose,int32_t const *humanReverseIndex,bool skipRoot);
	void SkeletonPoseFromValue(skeleton::Skeleton const &skeleton, skeleton::SkeletonPose const &defaultPose, ValueArray const &values, SkeletonTQSMap const *skeletonTQSMap, int32_t const *indexArray, skeleton::SkeletonPose &pose,int index, int stopIndex);
	void ValueFromSkeletonPose(skeleton::Skeleton const &skeleton, skeleton::SkeletonPose const &pose, SkeletonTQSMap const *skeletonTQSMap, ValueArray &values);
	void ValueFromSkeletonPose(skeleton::Skeleton const &skeleton, skeleton::SkeletonPose const &pose, SkeletonTQSMap const *skeletonTQSMap, int32_t const *indexArray, ValueArray &values, int index, int stopIndex);
	}
}

template<>
class SerializeTraits< mecanim::animation::BlendingState<false> > : public SerializeTraitsBase< mecanim::animation::BlendingState<false> >
{
	public:

	typedef mecanim::animation::BlendingState<false>	value_type;
	inline static const char* GetTypeString (void*)	{ return "BlendingState<1>"; }
	inline static bool IsAnimationChannel ()	{ return false; }
	inline static bool MightContainPPtr ()	{ return true; }
	inline static bool AllowTransferOptimization ()	{ return false; }

	template<class TransferFunction> inline
	static void Transfer (value_type& data, TransferFunction& transfer)
	{
		transfer.Transfer(data.m_DynamicValuesBlending, "m_DynamicValuesBlending");
		transfer.Transfer(data.m_DynamicValuesBlendingMask, "m_DynamicValuesBlendingMask");
		transfer.Transfer(data.m_MotionBlending, "m_MotionBlending");
		transfer.Transfer(data.m_HumanPoseBlending, "m_HumanPoseBlending");
		transfer.Transfer(data.m_BlendFactor, "m_BlendFactor");
	}
};