My Project
ParaXBone.h
1 #pragma once
2 #include "animated.h"
3 #include "IAttributeFields.h"
4 
5 namespace ParaEngine
6 {
7  class CBVHSerializer;
8 
15  class Bone : public IAttributeFields
16  {
17  public:
18  Bone();
19  virtual ~Bone();
20 
21  ATTRIBUTE_DEFINE_CLASS(Bone);
22 
24  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
25 
26  ATTRIBUTE_METHOD1(Bone, GetRotName_s, const char**) { *p1 = cls->GetRotName().c_str(); return S_OK; }
27  ATTRIBUTE_METHOD1(Bone, GetTransName_s, const char**) { *p1 = cls->GetTransName().c_str(); return S_OK; }
28  ATTRIBUTE_METHOD1(Bone, GetScaleName_s, const char**) { *p1 = cls->GetScaleName().c_str(); return S_OK; }
29 
30  ATTRIBUTE_METHOD1(Bone, IsBillBoarded_s, bool*) { *p1 = cls->IsBillBoarded(); return S_OK; }
31  ATTRIBUTE_METHOD1(Bone, IsPivotBone_s, bool*) { *p1 = cls->IsPivotBone(); return S_OK; }
32  ATTRIBUTE_METHOD1(Bone, IsOffsetMatrixBone_s, bool*){ *p1 = cls->IsOffsetMatrixBone(); return S_OK; }
33  ATTRIBUTE_METHOD1(Bone, IsTransformationNode_s, bool*) { *p1 = cls->IsTransformationNode(); return S_OK; }
34  ATTRIBUTE_METHOD1(Bone, IsStaticTransform_s, bool*) { *p1 = cls->IsStaticTransform(); return S_OK; }
35  ATTRIBUTE_METHOD1(Bone, IsAnimated_s, bool*) { *p1 = cls->IsAnimated(); return S_OK; }
36 
37  ATTRIBUTE_METHOD1(Bone, SetOffsetMatrix_s, const Matrix4&) { cls->SetOffsetMatrix(p1); return S_OK; }
38  ATTRIBUTE_METHOD1(Bone, SetStaticTransform_s, const Matrix4&) { cls->SetStaticTransform(p1); return S_OK; }
39 
40  ATTRIBUTE_METHOD(Bone, RemoveRedundentKeys_s) { cls->RemoveRedundentKeys(); return S_OK; }
41 
42  ATTRIBUTE_METHOD1(Bone, GetFinalMatrix_s, Matrix4*) { *p1 = cls->GetFinalMatrix(); return S_OK; }
43  ATTRIBUTE_METHOD1(Bone, GetFinalRotMatrix_s, Matrix4*) { *p1 = cls->GetFinalRotMatrix(); return S_OK; }
44  ATTRIBUTE_METHOD1(Bone, GetPivotRotMatrix_s, Matrix4*) { *p1 = cls->GetPivotRotMatrix(); return S_OK; }
45 
46  ATTRIBUTE_METHOD1(Bone, GetPivotPoint_s, Vector3*) { *p1 = cls->GetPivotPoint(); return S_OK; }
47  ATTRIBUTE_METHOD1(Bone, GetAnimatedPivotPoint_s, Vector3*) { *p1 = cls->GetAnimatedPivotPoint(); return S_OK; }
48 
49  ATTRIBUTE_METHOD1(Bone, SetFinalRot_s, Quaternion) { cls->SetFinalRot(p1); return S_OK; }
50  ATTRIBUTE_METHOD1(Bone, GetFinalRot_s, Quaternion*) { *p1 = cls->GetFinalRot(); return S_OK; }
51 
52  ATTRIBUTE_METHOD1(Bone, SetFinalTrans_s, Vector3) { cls->SetFinalTrans(p1); return S_OK; }
53  ATTRIBUTE_METHOD1(Bone, GetFinalTrans_s, Vector3*) { *p1 = cls->GetFinalTrans(); return S_OK; }
54 
55  ATTRIBUTE_METHOD1(Bone, SetFinalScaling_s, Vector3) { cls->SetFinalScaling(p1); return S_OK; }
56  ATTRIBUTE_METHOD1(Bone, GetFinalScaling_s, Vector3*) { *p1 = cls->GetFinalScaling(); return S_OK; }
57 
58  ATTRIBUTE_METHOD1(Bone, GetParentIndex_s, int*) { *p1 = cls->GetParentIndex(); return S_OK; }
59  ATTRIBUTE_METHOD1(Bone, GetBoneIndex_s, int*) { *p1 = cls->GetBoneIndex(); return S_OK; }
60 
61  ATTRIBUTE_METHOD1(Bone, GetBoneID_s, int*) { *p1 = cls->GetBoneID(); return S_OK; }
62  ATTRIBUTE_METHOD1(Bone, SetBoneID_s, int) { cls->SetBoneID(p1); return S_OK; }
63 
64  public:
66  virtual const std::string& GetIdentifier();
67  virtual void SetIdentifier(const std::string& sID);
68 
70  bool IsBillBoarded() const { return (flags & BONE_BILLBOARDED) != 0; };
72  bool IsPivotBone() const { return (flags & BONE_OFFSET_MATRIX) == 0; };
74  bool IsOffsetMatrixBone() const { return (flags & BONE_OFFSET_MATRIX) != 0; };
76  bool IsStaticTransform() const { return (flags & BONE_STATIC_TRANSFORM) != 0; };
78  bool IsTransformationNode() const { return (flags & BONE_TRANSFORMATION_NODE) != 0; };
79 
81  void SetOffsetMatrix(const Matrix4& mat);
82 
84  void SetStaticTransform(const Matrix4& mat);
85 
87  bool CheckHasAnimation();
88 
89  const std::string& GetName() const;
90  void SetName(const std::string& val);
91 
94 
96  bool IsAnimated();
110  bool calcMatrix(Bone* allbones, const AnimIndex & CurrentAnim, const AnimIndex & BlendingAnim, float blendingFactor, IAttributeFields* pAnimInstance = NULL);
112  void calcMatrix(Bone* allbones);
113 
117  bool GetExternalRot(IAttributeFields* pAnimInstance, Quaternion& outQuat);
118  bool GetExternalTranslation(IAttributeFields* pAnimInstance, Vector3& outTrans);
119  bool GetExternalScaling(IAttributeFields* pAnimInstance, Vector3& outScaling);
120 
122  void RemoveRedundentKeys();
123 
124  /* rotation and offset matrix are processed */
125  void PostCalculateBoneMatrix();
126 
127  const ParaEngine::Matrix4& GetFinalMatrix();
129  const Vector3& GetPivotPoint();
130 
133 
134  int GetParentIndex() const { return parent; }
135  int GetBoneIndex() const { return nIndex; }
136  int GetBoneID() const { return nBoneID; }
137  int IsAttachment() const;
139  int GetAttachmentId() const;
140  void SetBoneID(int val) { nBoneID = val; }
141 
142  const ParaEngine::Quaternion& GetFinalRot() const;
143  void SetFinalRot(const ParaEngine::Quaternion& val);
144 
145  const Vector3 & GetFinalTrans() const;
146  void SetFinalTrans(const Vector3 &val);
147 
148  const Vector3& GetFinalScaling() const;
149  void SetFinalScaling(const Vector3& val);
150 
151  const ParaEngine::Matrix4& GetFinalRotMatrix() const;
154 
158  void MakeDirty(bool bForce = false);
159 
160  friend class CBVHSerializer;
161  public:
163  {
169  BONE_BILLBOARDED = (0x1 << 3),
173  BONE_OFFSET_MATRIX = (0x1 << 4),
175  BONE_STATIC_TRANSFORM = (0x1 << 5),
176  /* the bone is the transformation node */
177  BONE_TRANSFORMATION_NODE = (0x1 << 6),
178  };
179  std::string m_sIdentifer;
180  std::string m_sRotName;
181  std::string m_sTransName;
182  std::string m_sScaleName;
183  const std::string& GetRotName();
184  const std::string& GetTransName();
185  const std::string& GetScaleName();
186 
187  Animated<Vector3> trans;
189  Animated<Vector3> scale;
190 
191  // pivot point in binding pos
192  Vector3 pivot;
193 
194  // offset matrix that transforms from mesh space to the current bone space.
195  Matrix4 matOffset;
196  // the bone has no animation and a static transform is used to transform from current bone space to its parent bone space.
197  Matrix4 matTransform;
198 
199  // index of the parent bone
200  int parent;
201 
202  // the predefined bone ID. it is 0 for unknown bones, positive for known bones. one of the KNOWN_BONE_NODES
203  int nBoneID;
204 
205  // index of this bone
206  int nIndex;
207 
208  // bitwise fields of bone attributes. BONE_BILLBOARDED for bill boarded.
209  DWORD flags;
210 
211  // temporary final matrix
212  Matrix4 mat;
213 
214  // temporary final rotation matrix
215  Matrix4 mrot;
216 
217  // temporary final m_finalRot used in composing the final mat
218  Quaternion m_finalRot;
219 
220  // temporary final m_finalTrans used in composing the final mat
221  Vector3 m_finalTrans;
222 
223  // temporary final m_finalScaling used in composing the final mat
224  Vector3 m_finalScaling;
225 
226  bool calc;
227  bool bUsePivot;
228 
230  const static int s_MaxBonesPerVertex = 4;
231  };
232 }
bool IsBillBoarded() const
whether the bone is billboarded
Definition: ParaXBone.h:70
void MakeDirty(bool bForce=false)
mark this bone as un-calculated bone.
Definition: ParaXBone.cpp:1168
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
bool CheckHasAnimation()
whether the bone contains animation data.
Definition: ParaXBone.cpp:1019
different physics engine has different winding order.
Definition: EventBinding.h:32
a single animated bone, it contains both the bone instance data and all animation data of the bone...
Definition: ParaXBone.h:15
virtual const std::string & GetIdentifier()
get the name or identifier.
Definition: ParaXBone.cpp:584
Implementation of a Quaternion, i.e.
Definition: ParaQuaternion.h:10
calculate bone matrix using offset matrix (which transform from mesh to local bone space) and SRT tra...
Definition: ParaXBone.h:173
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
bool IsStaticTransform() const
whether the bone has no animation and a static transform is used to transform from current bone space...
Definition: ParaXBone.h:76
BONE_FLAGS
Definition: ParaXBone.h:162
bool IsTransformationNode() const
whether the bone is transformation node
Definition: ParaXBone.h:78
Definition: animated.h:23
Vector3 GetAnimatedPivotPoint()
return the current pivot point
Definition: ParaXBone.cpp:1094
bool IsOffsetMatrixBone() const
whether calculate bone matrix using offset matrix (which transform from mesh to local bone space) and...
Definition: ParaXBone.h:74
bool GetExternalRot(IAttributeFields *pAnimInstance, Quaternion &outQuat)
get external rot quaternion from animation instance.
Definition: ParaXBone.cpp:1029
void AutoSetBoneInfoFromName()
automatically set bone id from bone name.
Definition: ParaXBone.cpp:758
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
it presents a given in bone animation providers or parax local model bone animation pools ...
Definition: AnimInstanceBase.h:13
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
whether the bone is billboarded
Definition: ParaXBone.h:169
bool IsPivotBone() const
whether calculate bone matrix using each bone&#39;s pivot point and SRT transforms relative to the curren...
Definition: ParaXBone.h:72
virtual int InstallFields(CAttributeClass *pClass, bool bOverride)
this class should be implemented if one wants to add new attribute.
Definition: ParaXBone.cpp:1201
calculate bone matrix using each bone&#39;s pivot point and SRT transforms relative to the current bone...
Definition: ParaXBone.h:167
the bone has no animation and a static transform is used to transform from current bone space to its ...
Definition: ParaXBone.h:175
Matrix4 GetPivotRotMatrix()
similar to GetFinalRotMatrix(), except that it will remove rotation in its offset matrix...
Definition: ParaXBone.cpp:1152
const Vector3 & GetPivotPoint()
return the pivot point in binding space
Definition: ParaXBone.cpp:1088
bool IsAnimated()
whether bone is animated.
Definition: ParaXBone.cpp:1024
bool calcMatrix(Bone *allbones, const AnimIndex &CurrentAnim, const AnimIndex &BlendingAnim, float blendingFactor, IAttributeFields *pAnimInstance=NULL)
calc bone matrix and all of its parent bones.
Definition: ParaXBone.cpp:68
void SetOffsetMatrix(const Matrix4 &mat)
calling this function means that you want to use BONE_OFFSET_MATRIX for final bone matrix calculation...
Definition: ParaXBone.cpp:1000
static const int s_MaxBonesPerVertex
max number of bones per vertex, currently this is 4.
Definition: ParaXBone.h:230
BioVision Hierarchy (BVH) motion capture file serializer for ParaX file.
Definition: BVHSerializer.h:23
int GetAttachmentId() const
return -1 if it is not attachment id.
Definition: ParaXBone.cpp:1112
void SetStaticTransform(const Matrix4 &mat)
calling this function means that you want to use BONE_STATIC_TRANSFORM for final bone matrix calculat...
Definition: ParaXBone.cpp:1012
void RemoveRedundentKeys()
Always call this function after loading data from files.
Definition: ParaXBone.cpp:26