imesh/animnode/retarget.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2010 Christian Van Brussel, Institute of Information 00003 and Communication Technologies, Electronics and Applied Mathematics 00004 at Universite catholique de Louvain, Belgium 00005 http://www.uclouvain.be/en-icteam.html 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public 00018 License along with this library; if not, write to the Free 00019 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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 /* Note: 'real' BoneID format is %zu, but use %lu here to quell warnings 00093 when compiling with -ansi -pedantic. */ 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 } // namespace Animation 00222 } // namespace CS 00223 00226 #endif //__CS_IMESH_ANIMNODE_RETARGET_H__
Generated for Crystal Space 2.0 by doxygen 1.6.1