summaryrefslogtreecommitdiff
path: root/Runtime/Animation/Avatar.h
blob: d99dbd00e0618bd1886410d050e3200c17f465cc (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
#ifndef AVATAR_H
#define AVATAR_H

#include "Runtime/BaseClasses/NamedObject.h"
#include "Runtime/Misc/UserList.h"
#include "Runtime/BaseClasses/MessageIdentifier.h"
#include "Runtime/Serialize/SerializeTraits.h"
#include "Runtime/mecanim/animation/avatar.h"

#include "Runtime/Animation/MecanimUtility.h"

namespace mecanim {  namespace animation { struct AvatarConstant; } }

enum HumanParameter
{
	UpperArmTwist = 0,
	LowerArmTwist,
	UpperLegTwist,
	LowerLegTwsit,
	ArmStretch,
	LegStretch,
	FeetSpacing
};

class Avatar : public NamedObject
{
public:	
	REGISTER_DERIVED_CLASS (Avatar, NamedObject)
	DECLARE_OBJECT_SERIALIZE (Avatar)
	
	static void InitializeClass (){};
	static void CleanupClass () {}
	
	Avatar (MemLabelId label, ObjectCreationMode mode);	

	virtual void AwakeFromLoad(AwakeFromLoadMode mode);
	virtual void CheckConsistency ();		

	void SetAsset (mecanim::animation::AvatarConstant* avatarConstant, TOSVector const& tos);

	mecanim::animation::AvatarConstant*	GetAsset();
	const mecanim::animation::AvatarConstant*	GetAsset() const;
	TOSVector const&					GetTOS() const;

	bool	IsValid()const;


	void	SetMuscleMinMax(int muscleId, float min, float max);
	void	SetParameter(int parameterId, float value);	

	void	NotifyObjectUsers(const MessageIdentifier& msg);
	void	AddObjectUser( UserListNode& node ) { m_ObjectUsers.AddUser(node); }
	
	bool	IsHuman() const;
	bool	HasRootMotion() const;
	float	GetHumanScale() const;
	float	GetLeftFeetBottomHeight() const;
	float	GetRightFeetBottomHeight() const;

	float		GetAxisLength(int humanId)const;
	Quaternionf GetPreRotation(int humanId)const;
	Quaternionf GetPostRotation(int humanId)const;
	Quaternionf GetZYPostQ(int index, Quaternionf const& parentQ, Quaternionf const& q)const;
	Quaternionf GetZYRoll(int index, Vector3f const& v)const;
	Vector3f    GetLimitSign(int index)const;

protected:
	
	mecanim::memory::ChainedAllocator   m_Allocator;
	mecanim::animation::AvatarConstant* m_Avatar;
	TOSVector							m_TOS;

	UInt32							m_AvatarSize;
	
	UserList                                m_ObjectUsers; 
};

class HumanTrait
{
public:
	enum {
		LastDoF = mecanim::human::kLastDoF,
		LastLeftFingerDoF = LastDoF + mecanim::hand::s_DoFCount,
		LastRightFingerDoF = LastLeftFingerDoF + mecanim::hand::s_DoFCount,
		MuscleCount = LastRightFingerDoF
	};

	enum {
		LastBone = mecanim::human::kLastBone,
		LastLeftFingerBone = LastBone + mecanim::hand::s_BoneCount,
		LastRightFingerBone = LastLeftFingerBone + mecanim::hand::s_BoneCount,
		BoneCount = LastRightFingerBone
	};

	static std::string GetFingerMuscleName(int index, bool left);
	static std::string GetFingerName(int index, bool left);

	class Body
	{
	public:
		static int GetBoneCount();
		static std::string GetBoneName(int index);
		static int GetMuscleCount();
		static std::string GetMuscleName(int index);		
	};

	class LeftFinger
	{
	public:
		static int GetBoneCount();
		static std::string GetBoneName(int index);
		static int GetMuscleCount();
		static std::string GetMuscleName(int index);		
		static bool IsLeftHand();
	};

	class RightFinger
	{
	public:
		static int GetBoneCount();
		static std::string GetBoneName(int index);
		static int GetMuscleCount();
		static std::string GetMuscleName(int index);	
		static bool IsLeftHand();
	};	

	static std::vector<string> GetMuscleName();
	static std::vector<string> GetBoneName();
	static int MuscleFromBone(int i, int dofIndex);
	static int BoneFromMuscle(int i);
	static int GetBoneId(Avatar const& avatar, int humanId);
	static bool RequiredBone(int humanId);
	static int RequiredBoneCount();
	static bool HasCollider(Avatar& avatar, int humanId);
	static int GetColliderId(Avatar& avatar, int humanId);

	static int GetParent(int humanId);

	static float GetMuscleDefaultMin(int i);
	static float GetMuscleDefaultMax(int i);
	
protected:
	static std::vector<string> InternalGetMuscleName();
	static std::vector<string> InternalGetBoneName();	
};


#endif