imesh/animnode/skeleton2anim.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

imesh/animnode/skeleton2anim.h
Go to the documentation of this file.

    00001 /*
    00002   Copyright (C) 2008 by Marten Svanfeldt
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Library General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012   Library General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Library General Public
    00015   License along with this library; if not, write to the Free
    00016   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00017 */
    00018
    00019 #ifndef __CS_IMESH_ANIMNODE_SKELETON2ANIM_H__
    00020 #define __CS_IMESH_ANIMNODE_SKELETON2ANIM_H__
    00021
    00022 #include "csutil/scf_interface.h"
    00023 #include "csutil/ref.h"
    00024 #include "csutil/refcount.h"
    00025 #include "csutil/bitarray.h"
    00026 #include "csgeom/dualquaternion.h"
    00027 #include "imesh/skeleton2.h"
    00028
    00029 class csQuaternion;
    00030 class csVector3;
    00031
    00036 namespace CS {
    00037 namespace Animation {
    00038
    00039 struct iSkeleton;
    00040
    00041 struct iSkeletonAnimPacketFactory;
    00042 struct iSkeletonAnimPacket;
    00043
    00044 struct iSkeletonAnimation;
    00045
    00046 struct iSkeletonAnimNodeFactory;
    00047 struct iSkeletonAnimNode;
    00048
    00049 struct iSkeletonAnimationNodeFactory;
    00050 struct iSkeletonAnimationNode;
    00051
    00052 struct iSkeletonBlendNodeFactory;
    00053 struct iSkeletonBlendNode;
    00054
    00055 struct iSkeletonPriorityNodeFactory;
    00056 struct iSkeletonPriorityNode;
    00057
    00058 struct iSkeletonRandomNodeFactory;
    00059 struct iSkeletonRandomNode;
    00060
    00061 struct iSkeletonFSMNodeFactory;
    00062 struct iSkeletonFSMNode;
    00063
    00064 class AnimatedMeshState;
    00065
    00066
    00073
    00074 typedef unsigned int ChannelID;
    00075
    00077 typedef unsigned int KeyFrameID;
    00078
    00080 typedef unsigned int StateID;
    00081
    00083 static const ChannelID InvalidChannelID = (ChannelID)~0;
    00084
    00086 static const KeyFrameID InvalidKeyframeID = (KeyFrameID)~0;
    00087
    00089 static const StateID InvalidStateID = (StateID)~0;
    00090
    00092 enum SynchronizationMode
    00093 {
    00095   SYNC_NONE,
    00097   SYNC_FIRSTFRAME
    00098 };
    00099
    00100
    00117 struct iSkeletonAnimPacketFactory : public virtual iBase
    00118 {
    00119   SCF_INTERFACE(CS::Animation::iSkeletonAnimPacketFactory, 2, 0, 3);
    00120
    00124   virtual csPtr<iSkeletonAnimPacket> CreateInstance (iSkeleton* skeleton) = 0;
    00125
    00129   virtual iSkeletonAnimation* CreateAnimation (const char* name) = 0;
    00130
    00134   virtual iSkeletonAnimation* FindAnimation (const char* name) = 0;
    00135
    00139   virtual void ClearAnimations () = 0;
    00140
    00144   virtual iSkeletonAnimation* GetAnimation (size_t index) = 0;
    00145
    00149   virtual size_t GetAnimationCount () const = 0;
    00150
    00154   virtual void SetAnimationRoot (iSkeletonAnimNodeFactory* root) = 0;
    00155
    00159   virtual iSkeletonAnimNodeFactory* GetAnimationRoot () const = 0;
    00160
    00164   virtual csPtr<iSkeletonAnimationNodeFactory> CreateAnimationNode (const char* name) = 0;
    00165
    00169   virtual csPtr<iSkeletonBlendNodeFactory> CreateBlendNode (const char* name) = 0;
    00170
    00174   virtual csPtr<iSkeletonPriorityNodeFactory> CreatePriorityNode (const char* name) = 0;
    00175
    00179   virtual csPtr<iSkeletonRandomNodeFactory> CreateRandomNode (const char* name) = 0;
    00180
    00184   virtual csPtr<iSkeletonFSMNodeFactory> CreateFSMNode (const char* name) = 0;
    00185
    00189   virtual void RemoveAnimation (const char* name) = 0;
    00190
    00194   virtual void RemoveAnimation (size_t index) = 0;
    00195
    00201   virtual size_t FindAnimationIndex (const char* name) = 0;
    00202
    00206   virtual const char* GetName () const = 0;
    00207 };
    00208
    00221 struct iSkeletonAnimPacket : public virtual iBase
    00222 {
    00223   SCF_INTERFACE(CS::Animation::iSkeletonAnimPacket, 2, 0, 0);
    00224
    00228   virtual iSkeletonAnimPacketFactory* GetFactory () const = 0;
    00229
    00233   virtual iSkeletonAnimNode* GetAnimationRoot () const = 0;
    00234 };
    00235
    00272 struct iSkeletonAnimation : public virtual iBase
    00273 {
    00274   SCF_INTERFACE(CS::Animation::iSkeletonAnimation, 2, 0, 4);
    00275
    00279   virtual const char* GetName () const = 0;
    00280
    00287   virtual ChannelID AddChannel (BoneID bone) = 0;
    00288
    00293   virtual ChannelID FindChannel (BoneID bone) const = 0;
    00294
    00304   virtual void AddKeyFrame (ChannelID channel, float time,
    00305     const csQuaternion& rotation, const csVector3& offset) = 0;
    00306
    00311   virtual size_t GetKeyFrameCount (ChannelID channel) const = 0;
    00312
    00322   virtual void GetKeyFrame (ChannelID channel,
    00323     KeyFrameID keyframe, BoneID& bone,
    00324     float& time, csQuaternion& rotation, csVector3& offset) = 0;
    00325
    00338   CS_DEPRECATED_METHOD_MSG("Deprecated in 2.0. Don't use it anymore (or complain if you found a good reason to).")
    00339   virtual void GetTwoKeyFrames (ChannelID channel, float time, BoneID& bone,
    00340     float& timeBefore, csQuaternion& beforeRot, csVector3& beforeOffset,
    00341     float& timeAfter, csQuaternion& afterRot, csVector3& afterOffset) = 0;
    00342
    00351   CS_DEPRECATED_METHOD_MSG("Deprecated in 2.0. Use instead the version without the 'isPlayingCyclic' parameter.")
    00352   virtual void BlendState (AnimatedMeshState* state,
    00353     float baseWeight, float playbackTime, bool isPlayingCyclic) const = 0;
    00354
    00359   virtual float GetDuration () const = 0;
    00360
    00368   virtual void SetKeyFrame (ChannelID channel,
    00369     KeyFrameID keyframe, const csQuaternion& rotation,
    00370     const csVector3& offset) = 0;
    00371
    00380   virtual void SetFramesInBindSpace (bool isBindSpace) = 0;
    00381
    00388   virtual bool GetFramesInBindSpace () const = 0;
    00389
    00394   virtual void ConvertFrameSpace (CS::Animation::iSkeletonFactory* skeleton) = 0;
    00395
    00399   virtual size_t GetChannelCount () const = 0;
    00400
    00404   virtual BoneID GetChannelBone (ChannelID channel) const = 0;
    00405
    00411   virtual void SetChannelBone (ChannelID channel, BoneID bone) = 0;
    00412
    00417   virtual void RemoveChannel (ChannelID channel) = 0;
    00418
    00427   virtual void AddOrSetKeyFrame (ChannelID channel, float time,
    00428     const csQuaternion& rotation) = 0;
    00429
    00438   virtual void AddOrSetKeyFrame (ChannelID channel, float time,
    00439     const csVector3& offset) = 0;
    00440
    00453   virtual void BlendState (AnimatedMeshState* state,
    00454     float baseWeight, float playbackTime) const = 0;
    00455 };
    00456
    00457
    00465 struct iSkeletonAnimCallback : public virtual iBase
    00466 {
    00471   virtual void AnimationFinished (iSkeletonAnimNode* node) = 0;
    00472
    00476   virtual void AnimationCycled (iSkeletonAnimNode* node) = 0;
    00477
    00481   virtual void PlayStateChanged (iSkeletonAnimNode* node, bool isPlaying) = 0;
    00482
    00486   virtual void DurationChanged (iSkeletonAnimNode* node) = 0;
    00487 };
    00488
    00489
    00502 struct iSkeletonAnimNodeFactory : public virtual iBase
    00503 {
    00504   SCF_INTERFACE(CS::Animation::iSkeletonAnimNodeFactory, 1, 0, 0);
    00505
    00509   virtual csPtr<iSkeletonAnimNode> CreateInstance (
    00510     iSkeletonAnimPacket* packet, iSkeleton* skeleton) = 0;
    00511
    00515   virtual const char* GetNodeName () const = 0;
    00516
    00520   virtual iSkeletonAnimNodeFactory* FindNode (const char* name) = 0;
    00521 };
    00522
    00537 struct iSkeletonAnimNode : public virtual iBase
    00538 {
    00539   SCF_INTERFACE(CS::Animation::iSkeletonAnimNode, 1, 0, 0);
    00540
    00544   virtual void Play () = 0;
    00545
    00549   virtual void Stop () = 0;
    00550
    00555   virtual void SetPlaybackPosition (float time) = 0;
    00556
    00560   virtual float GetPlaybackPosition () const = 0;
    00561
    00565   virtual float GetDuration () const = 0;
    00566
    00570   virtual void SetPlaybackSpeed (float speed) = 0;
    00571
    00575   virtual float GetPlaybackSpeed () const = 0;
    00576
    00583   virtual void BlendState (AnimatedMeshState* state, float baseWeight = 1.0f) = 0;
    00584
    00589   virtual void TickAnimation (float dt) = 0;
    00590
    00594   virtual bool IsActive () const = 0;
    00595
    00599   virtual iSkeletonAnimNodeFactory* GetFactory () const = 0;
    00600
    00604   virtual iSkeletonAnimNode* FindNode (const char* name) = 0;
    00605
    00610   virtual void AddAnimationCallback (iSkeletonAnimCallback* callback) = 0;
    00611
    00616   virtual void RemoveAnimationCallback (iSkeletonAnimCallback* callback) = 0;
    00617 };
    00618
    00632 struct iSkeletonAnimationNodeFactory : public iSkeletonAnimNodeFactory
    00633 {
    00634   SCF_INTERFACE(CS::Animation::iSkeletonAnimationNodeFactory, 1, 0, 0);
    00635
    00639   virtual void SetAnimation (iSkeletonAnimation* animation) = 0;
    00640
    00644   virtual iSkeletonAnimation* GetAnimation () const = 0;
    00645
    00649   virtual void SetCyclic (bool cyclic) = 0;
    00650
    00654   virtual bool IsCyclic () const = 0;
    00655
    00659   virtual void SetPlaybackSpeed (float speed) = 0;
    00660
    00664   virtual float GetPlaybackSpeed () const = 0;
    00665
    00670   virtual void SetAutomaticReset (bool reset) = 0;
    00671
    00676   virtual bool GetAutomaticReset () const = 0;
    00677
    00682   virtual void SetAutomaticStop (bool enabed) = 0;
    00683
    00688   virtual bool GetAutomaticStop () const = 0;
    00689 };
    00690
    00705 struct iSkeletonAnimationNode : public iSkeletonAnimNode
    00706 {
    00707   SCF_INTERFACE(CS::Animation::iSkeletonAnimationNode, 1, 0, 0);
    00708 };
    00709
    00724 struct iSkeletonBlendNodeFactory : public iSkeletonAnimNodeFactory
    00725 {
    00726   SCF_INTERFACE(CS::Animation::iSkeletonBlendNodeFactory, 1, 0, 0);
    00727
    00733   virtual void AddNode (iSkeletonAnimNodeFactory* node, float weight) = 0;
    00734
    00739   virtual void SetNodeWeight (uint node, float weight) = 0;
    00740
    00745   virtual void NormalizeWeights () = 0;
    00746
    00751   virtual iSkeletonAnimNodeFactory* GetNode (uint node) = 0;
    00752
    00756   virtual uint GetNodeCount () const = 0;
    00757
    00761   virtual void ClearNodes () = 0;
    00762
    00766   virtual void SetSynchronizationMode (SynchronizationMode mode) = 0;
    00767
    00771   virtual SynchronizationMode GetSynchronizationMode () const = 0;
    00772 };
    00773
    00774
    00791 struct iSkeletonBlendNode : public iSkeletonAnimNode
    00792 {
    00793   SCF_INTERFACE(CS::Animation::iSkeletonBlendNode, 1, 0, 0);
    00794
    00798   virtual void SetNodeWeight (uint node, float weight) = 0;
    00799
    00803   virtual void NormalizeWeights () = 0;
    00804 };
    00805
    00806
    00822 struct iSkeletonPriorityNodeFactory : public iSkeletonAnimNodeFactory
    00823 {
    00824   SCF_INTERFACE(CS::Animation::iSkeletonPriorityNodeFactory, 1, 0, 0);
    00825
    00831   virtual void AddNode (iSkeletonAnimNodeFactory* node, unsigned int priority) = 0;
    00832
    00836   virtual void SetNodePriority (uint node, unsigned int priority) = 0;
    00837
    00842   virtual iSkeletonAnimNodeFactory* GetNode (uint node) = 0;
    00843
    00847   virtual uint GetNodeCount () const = 0;
    00848
    00852   virtual void ClearNodes () = 0;
    00853 };
    00854
    00873 struct iSkeletonPriorityNode : public iSkeletonAnimNode
    00874 {
    00875   SCF_INTERFACE(CS::Animation::iSkeletonPriorityNode, 1, 0, 0);
    00876
    00880   virtual void SetNodePriority (uint node, unsigned int priority) = 0;
    00881 };
    00882
    00897 struct iSkeletonRandomNodeFactory : public iSkeletonAnimNodeFactory
    00898 {
    00899   SCF_INTERFACE(CS::Animation::iSkeletonRandomNodeFactory, 1, 0, 0);
    00900
    00914   virtual void AddNode (iSkeletonAnimNodeFactory* node, float probability) = 0;
    00915
    00921   virtual void SetNodeProbability (uint node, float weight) = 0;
    00922
    00928   virtual void SetAutomaticSwitch (bool automatic) = 0;
    00929
    00934   virtual iSkeletonAnimNodeFactory* GetNode (uint node) = 0;
    00935
    00939   virtual uint GetNodeCount () const = 0;
    00940
    00944   virtual void ClearNodes () = 0;
    00945 };
    00946
    00947
    00961 struct iSkeletonRandomNode : public iSkeletonAnimNode
    00962 {
    00963   SCF_INTERFACE(CS::Animation::iSkeletonRandomNode, 1, 0, 0);
    00964
    00969   virtual void Switch () = 0;
    00970
    00974   virtual iSkeletonAnimNode* GetCurrentNode () const = 0;
    00975 };
    00976
    00998 struct iSkeletonFSMNodeFactory : public iSkeletonAnimNodeFactory
    00999 {
    01000   SCF_INTERFACE(CS::Animation::iSkeletonFSMNodeFactory, 1, 0, 2);
    01001
    01005   virtual StateID AddState () = 0;
    01006
    01011   virtual void SetStateNode (StateID id, iSkeletonAnimNodeFactory* nodeFact) = 0;
    01012
    01017   virtual iSkeletonAnimNodeFactory* GetStateNode (StateID id) const = 0;
    01018
    01022   virtual void SetStateName (StateID id, const char* name) = 0;
    01023
    01027   virtual const char* GetStateName (StateID id) const = 0;
    01028
    01032   virtual StateID FindState (const char* name) const = 0;
    01033
    01038   virtual void SetStartState (StateID id) = 0;
    01039
    01044   virtual StateID GetStartState () const = 0;
    01045
    01049   virtual uint GetStateCount () const = 0;
    01050
    01054   virtual void ClearStates () = 0;
    01055
    01064   virtual void SetStateTransition (StateID fromState,
    01065     StateID toState, iSkeletonAnimNodeFactory* fact) = 0;
    01066
    01076   virtual void SetTransitionCrossfade (StateID fromState,
    01077     StateID toState, float time1, float time2) = 0;
    01078
    01082   virtual StateID AddState (const char* name,
    01083     iSkeletonAnimNodeFactory *nodeFact) = 0;
    01084
    01092   virtual void SetAutomaticTransition (StateID fromState,
    01093                                        StateID toState,
    01094                                        bool automatic) = 0;
    01095 };
    01096
    01097
    01112 struct iSkeletonFSMNode : public iSkeletonAnimNode
    01113 {
    01114   SCF_INTERFACE(CS::Animation::iSkeletonFSMNode, 1, 0, 1);
    01115
    01126   virtual void SwitchToState (StateID newState) = 0;
    01127
    01131   virtual StateID GetCurrentState () const = 0;
    01132
    01136   virtual iSkeletonAnimNode* GetStateNode (StateID state) const = 0;
    01137 };
    01138
    01151 /* Implementation note: bump number before '*10' in
    01152  * SCF_ISKELETONANIMNODEMANAGER_INTERFACE when changing this interface. */
    01153 template <class FactoryInterface>
    01154 struct iSkeletonAnimNodeManager : public virtual iBase
    01155 {
    01156   typedef FactoryInterface FactoryInterfaceType;
    01157
    01159   virtual FactoryInterface* CreateAnimNodeFactory (const char* name) = 0;
    01160
    01162   virtual FactoryInterface* FindAnimNodeFactory (const char* name) = 0;
    01163
    01168   virtual void RemoveAnimNodeFactory (const char* name) = 0;
    01169
    01171   virtual void ClearAnimNodeFactories () = 0;
    01172 };
    01173
    01174 #define SCF_ISKELETONANIMNODEMANAGER_INTERFACE(Name, a, b, c)   \
    01175   SCF_INTERFACE (Name, ((0*10)+(a)), (b), (c))
    01176
    01177
    01178 } // namespace Animation
    01179 } // namespace CS
    01180
    01185 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimation instead")
    01186 typedef CS::Animation::iSkeletonAnimation iSkeletonAnimation2;
    01187 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimationNode instead")
    01188 typedef CS::Animation::iSkeletonAnimationNode iSkeletonAnimationNode2;
    01189 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimationNodeFactory instead")
    01190 typedef CS::Animation::iSkeletonAnimationNodeFactory iSkeletonAnimationNodeFactory2;
    01191 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimCallback instead")
    01192 typedef CS::Animation::iSkeletonAnimCallback iSkeletonAnimCallback2;
    01193 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimNode instead")
    01194 typedef CS::Animation::iSkeletonAnimNode iSkeletonAnimNode2;
    01195 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimNodeFactory instead")
    01196 typedef CS::Animation::iSkeletonAnimNodeFactory iSkeletonAnimNodeFactory2;
    01197 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimPacket instead")
    01198 typedef CS::Animation::iSkeletonAnimPacket iSkeletonAnimPacket2;
    01199 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonAnimPacketFactory instead")
    01200 typedef CS::Animation::iSkeletonAnimPacketFactory iSkeletonAnimPacketFactory2;
    01201 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonBlendNode instead")
    01202 typedef CS::Animation::iSkeletonBlendNode iSkeletonBlendNode2;
    01203 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonBlendNodeFactory instead")
    01204 typedef CS::Animation::iSkeletonBlendNodeFactory iSkeletonBlendNodeFactory2;
    01205 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonFSMNode instead")
    01206 typedef CS::Animation::iSkeletonFSMNode iSkeletonFSMNode2;
    01207 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonFSMNodeFactory instead")
    01208 typedef CS::Animation::iSkeletonFSMNodeFactory iSkeletonFSMNodeFactory2;
    01209 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonPriorityNode instead")
    01210 typedef CS::Animation::iSkeletonPriorityNode iSkeletonPriorityNode2;
    01211 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonPriorityNodeFactory instead")
    01212 typedef CS::Animation::iSkeletonPriorityNodeFactory iSkeletonPriorityNodeFactory2;
    01213 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonRandomNode instead")
    01214 typedef CS::Animation::iSkeletonRandomNode iSkeletonRandomNode2;
    01215 CS_DEPRECATED_METHOD_MSG("Use CS::Animation::iSkeletonRandomNodeFactory instead")
    01216 typedef CS::Animation::iSkeletonRandomNodeFactory iSkeletonRandomNodeFactory2;
    01217
    01218 #endif // __CS_IMESH_ANIMNODE_SKELETON2ANIM_H__