Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __CS_IMESH_ANIMNODE_RETARGET_H__
00022 #define __CS_IMESH_ANIMNODE_RETARGET_H__
00023
00028 #include "csutil/scf_interface.h"
00029
00030 #include "imesh/animnode/skeleton2anim.h"
00031 #include "csutil/hash.h"
00032 #include "csutil/stringquote.h"
00033
00037 namespace CS {
00038 namespace Animation {
00039
00040 struct iBodyChain;
00041 struct iSkeletonFactory;
00042 struct iSkeletonRetargetNodeFactory;
00043
00048 struct BoneMapping
00049 {
00051 void AddMapping (CS::Animation::BoneID sourceBone, CS::Animation::BoneID targetBone)
00052 {
00053 sourceBones.PutUnique (sourceBone, targetBone);
00054 targetBones.PutUnique (targetBone, sourceBone);
00055 }
00056
00058 void RemoveMapping (CS::Animation::BoneID sourceBone, CS::Animation::BoneID targetBone)
00059 {
00060 sourceBones.DeleteAll (sourceBone);
00061 targetBones.DeleteAll (targetBone);
00062 }
00063
00065 CS::Animation::BoneID GetSourceBone (CS::Animation::BoneID bone)
00066 {
00067 if (!targetBones.Contains (bone))
00068 return CS::Animation::InvalidBoneID;
00069
00070 return *targetBones.GetElementPointer (bone);
00071 }
00072
00074 CS::Animation::BoneID GetTargetBone (CS::Animation::BoneID bone)
00075 {
00076 if (!sourceBones.Contains (bone))
00077 return CS::Animation::InvalidBoneID;
00078
00079 return *sourceBones.GetElementPointer (bone);
00080 }
00081
00082 void DebugPrint (CS::Animation::iSkeletonFactory* sourceSkeleton,
00083 CS::Animation::iSkeletonFactory* targetSkeleton) const
00084 {
00085 csPrintf ("Bone mapping:\n");
00086
00087 for (csHash<CS::Animation::BoneID, CS::Animation::BoneID>::ConstGlobalIterator it =
00088 sourceBones.GetIterator (); it.HasNext (); )
00089 {
00090 csTuple2<CS::Animation::BoneID, CS::Animation::BoneID> tuple = it.NextTuple ();
00091
00092
00093
00094 csPrintf ("source bone %lu", (unsigned long)tuple.second);
00095 if (sourceSkeleton->HasBone (tuple.second))
00096 csPrintf (" (%s) to target bone %lu (",
00097 CS::Quote::Single (sourceSkeleton->GetBoneName (tuple.second)),
00098 (unsigned long)tuple.first);
00099 else
00100 csPrintf ("(invalid) to target bone %lu (", (unsigned long)tuple.first);
00101 if (targetSkeleton->HasBone (tuple.first))
00102 csPrintf ("%s)\n", CS::Quote::Single (targetSkeleton->GetBoneName (tuple.first)));
00103 else
00104 csPrintf ("invalid)\n");
00105 }
00106
00107 csPrintf ("End of bone mapping:\n");
00108 };
00109
00110 private:
00111 csHash<CS::Animation::BoneID, CS::Animation::BoneID> sourceBones;
00112 csHash<CS::Animation::BoneID, CS::Animation::BoneID> targetBones;
00113 };
00114
00117 struct NameBoneMappingHelper
00118 {
00120 static void GenerateMapping (CS::Animation::BoneMapping& mapping,
00121 CS::Animation::iSkeletonFactory* sourceSkeleton,
00122 CS::Animation::iSkeletonFactory* targetSkeleton)
00123 {
00124 for (size_t i = 0; i <= targetSkeleton->GetTopBoneID (); i++)
00125 {
00126 if (!targetSkeleton->HasBone (i))
00127 continue;
00128
00129 csString targetBoneName = targetSkeleton->GetBoneName (i);
00130 CS::Animation::BoneID sourceBoneID =
00131 sourceSkeleton->FindBone (targetBoneName.GetData ());
00132
00133 if (sourceBoneID != CS::Animation::InvalidBoneID)
00134 mapping.AddMapping (sourceBoneID, i);
00135 }
00136 }
00137 };
00138
00143 struct iSkeletonRetargetNodeManager
00144 : public virtual CS::Animation::iSkeletonAnimNodeManager<CS::Animation::iSkeletonRetargetNodeFactory>
00145 {
00146 SCF_ISKELETONANIMNODEMANAGER_INTERFACE (CS::Animation::iSkeletonRetargetNodeManager, 1, 0, 0);
00147 };
00148
00165 struct iSkeletonRetargetNodeFactory : public virtual iSkeletonAnimNodeFactory
00166 {
00167 SCF_INTERFACE(CS::Animation::iSkeletonRetargetNodeFactory, 2, 0, 0);
00168
00172 virtual void SetChildNode (iSkeletonAnimNodeFactory* node) = 0;
00173
00177 virtual iSkeletonAnimNodeFactory* GetChildNode () = 0;
00178
00182 virtual void ClearChildNode () = 0;
00183
00187 virtual void SetSourceSkeleton (CS::Animation::iSkeletonFactory* skeleton) = 0;
00188
00192 virtual void SetBoneMapping (CS::Animation::BoneMapping& mapping) = 0;
00193
00202 virtual void AddBodyChain (CS::Animation::iBodyChain* chain) = 0;
00203
00208 virtual void RemoveBodyChain (CS::Animation::iBodyChain* chain) = 0;
00209 };
00210
00215 struct iSkeletonRetargetNode : public iSkeletonAnimNode
00216 {
00217 SCF_INTERFACE(CS::Animation::iSkeletonRetargetNode, 1, 0, 0);
00218
00219 };
00220
00221 }
00222 }
00223
00226 #endif //__CS_IMESH_ANIMNODE_RETARGET_H__