summaryrefslogtreecommitdiff
path: root/Runtime/Animation/AnimatorGenericBindings.h
blob: 4e2023bf56f2361936a0b0fd615d1a2c1a752a82 (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
#pragma once

#include <limits>
#include "Runtime/Graphics/Transform.h"
#include "Runtime/Utilities/dynamic_array.h"
#include "Runtime/mecanim/generic/valuearray.h"
#include "Runtime/mecanim/skeleton/skeleton.h"
#include "Runtime/mecanim/animation/avatar.h"

typedef UInt32 BindingHash;

namespace Unity { class GameObject; }

namespace UnityEngine
{
namespace Animation
{
	struct AnimationClipBindingConstant;
	struct AnimationSetBindings;
	struct BoundCurve;
	
	
	struct ExposedTransform
	{
		Transform*			transform;
		int					skeletonIndex;
		int					skeletonIndexForUpdateTransform;
	};

	struct AvatarBindingConstant
	{
		// For non-optimized mode (the Transform hierarchy is there)
		size_t        skeletonBindingsCount;
		Transform**   skeletonBindings;

		int           transformChangedMask;

		// For optimized mode
		size_t				exposedTransformCount;
		ExposedTransform*	exposedTransforms;
	};

	struct AnimatorGenericBindingConstant
	{
		size_t				transformBindingsCount;
		BoundCurve*			transformBindings;

		size_t				genericBindingsCount;
		BoundCurve*			genericBindings;

		size_t				genericPPtrBindingsCount;
		BoundCurve*			genericPPtrBindings;

		int					transformChangedMask;
		
		mecanim::animation::ControllerBindingConstant*	controllerBindingConstant;
		
		bool				allowConstantClipSamplingOptimization;
	};
	
	AvatarBindingConstant* CreateAvatarBindingConstant (Transform& root, const mecanim::animation::AvatarConstant* avatar, mecanim::memory::Allocator& allocator);
	AvatarBindingConstant* CreateAvatarBindingConstantOpt (Transform& root, const mecanim::animation::AvatarConstant* avatar, mecanim::memory::Allocator& allocator);
	void DestroyAvatarBindingConstant (AvatarBindingConstant* bindingConstant, mecanim::memory::Allocator& allocator);

	/// Bind multiple animation clips against a GameObject
	/// outputCurveIndexToBindingIndex is an array of arrays that remaps from the curve index of each clip into the bound curves array
	/// returns a binding constant.
	AnimatorGenericBindingConstant* CreateAnimatorGenericBindings (const AnimationSetBindings& animationSet, Transform& root, const mecanim::animation::AvatarConstant* avatar, const mecanim::animation::ControllerConstant* controller, mecanim::memory::Allocator& allocator);
	AnimatorGenericBindingConstant* CreateAnimatorGenericBindingsOpt (const AnimationSetBindings& animationSet, Transform& root, const mecanim::animation::AvatarConstant* avatar, const mecanim::animation::ControllerConstant* controller, mecanim::memory::Allocator& allocator);
	void DestroyAnimatorGenericBindings (AnimatorGenericBindingConstant* bindingConstant, mecanim::memory::Allocator& allocator);

	/// Batch assign an array of values to the bound locations (Also calls AwakeFromLoad)
	/// Must always be called from the main thread
	void SetGenericFloatPropertyValues (const AnimatorGenericBindingConstant& bindings, const mecanim::ValueArray& values);
	void SetGenericPPtrPropertyValues   (const AnimatorGenericBindingConstant& bindings, const mecanim::ValueArray& values);

	/// Batch assign transform properties to the bound Transform components
	/// Can be invoked from another thread if we are sure no one will delete Transforms at the same time on another thread.
	void SetGenericTransformPropertyValues (const AnimatorGenericBindingConstant& bindings, const mecanim::ValueArray& values, Transform *skipTransform);
	void SetHumanTransformPropertyValues (const AvatarBindingConstant& bindings, const mecanim::skeleton::SkeletonPose& pose);
	
	/// Invoke TransformChanged callbacks and SetDirty
	/// Must always be called from the main thread
	void SetTransformPropertyApplyMainThread (Transform& root, const AnimatorGenericBindingConstant& bindings, const AvatarBindingConstant& avatarBindings, bool skipRoot);
	void SetTransformPropertyApplyMainThread (Transform& root, const AvatarBindingConstant& avatarBindings, bool skipRoot, int mask = std::numeric_limits<int>::max() );

	/// Set transforms for optimized characters
	/// Must always be called from the main thread
	void SetFlattenedSkeletonTransformsMainThread (const AvatarBindingConstant& bindings, const mecanim::skeleton::SkeletonPose& globalSpacePose, const mecanim::animation::AvatarConstant& avatar);

	void UnregisterAvatarBindingObjects(AvatarBindingConstant* bindingConstant);
	void UnregisterGenericBindingObjects(AnimatorGenericBindingConstant* bindingConstant);

}
}