Blender V2.61 - r43446

BL_ArmatureObject.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program 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
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef BL_ARMATUREOBJECT
00033 #define BL_ARMATUREOBJECT
00034 
00035 #include "KX_GameObject.h"
00036 #include "BL_ArmatureConstraint.h"
00037 #include "BL_ArmatureChannel.h"
00038 
00039 #include "SG_IObject.h"
00040 #include <vector>
00041 #include <algorithm>
00042 
00043 struct bArmature;
00044 struct Bone;
00045 struct bConstraint;
00046 class BL_ActionActuator;
00047 class BL_ArmatureActuator;
00048 class MT_Matrix4x4;
00049 struct Object;
00050 class KX_BlenderSceneConverter;
00051 
00052 class BL_ArmatureObject : public KX_GameObject  
00053 {
00054     Py_Header
00055 public:
00056 
00057     double GetLastFrame ();
00058     short GetActivePriority();
00059     virtual void ProcessReplica();
00060     virtual void ReParentLogic();
00061     virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
00062     virtual bool UnlinkObject(SCA_IObject* clientobj);
00063 
00064     class BL_ActionActuator * GetActiveAction();
00065     
00066     BL_ArmatureObject(
00067         void* sgReplicationInfo,
00068         SG_Callbacks callbacks,
00069         Object *armature,
00070         Scene *scene,
00071         int vert_deform_type
00072     );
00073     virtual ~BL_ArmatureObject();
00074 
00075     virtual CValue* GetReplica();
00076     void GetMRDPose(struct bPose **pose);
00077     void GetPose(struct bPose **pose);
00078     void SetPose (struct bPose *pose);
00079     struct bPose *GetOrigPose() {return m_pose;} // never edit this, only for accessing names
00080 
00081     void ApplyPose();
00082     void RestorePose();
00083 
00084     bool SetActiveAction(class BL_ActionActuator *act, short priority, double curtime);
00085     
00086     struct bArmature * GetArmature() { return m_armature; }
00087     const struct bArmature * GetArmature() const { return m_armature; }
00088     const struct Scene * GetScene() const { return m_scene; }
00089     
00090     Object* GetArmatureObject() {return m_objArma;}
00091 
00092     int GetVertDeformType() {return m_vert_deform_type;}
00093 
00094     // for constraint python API
00095     void LoadConstraints(KX_BlenderSceneConverter* converter);
00096     size_t GetConstraintNumber() const { return m_constraintNumber; }
00097     BL_ArmatureConstraint* GetConstraint(const char* posechannel, const char* constraint);
00098     BL_ArmatureConstraint* GetConstraint(const char* posechannelconstraint);
00099     BL_ArmatureConstraint* GetConstraint(int index);
00100     // for pose channel python API
00101     void LoadChannels();
00102     size_t GetChannelNumber() const { return m_channelNumber; }
00103     BL_ArmatureChannel* GetChannel(bPoseChannel* channel);
00104     BL_ArmatureChannel* GetChannel(const char* channel);
00105     BL_ArmatureChannel* GetChannel(int index);
00106 
00109     bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix);
00110     
00112     float GetBoneLength(Bone* bone) const;
00113 
00114     virtual int GetGameObjectType() { return OBJ_ARMATURE; }
00115 
00116 #ifdef WITH_PYTHON
00117 
00118     // PYTHON
00119     static PyObject* pyattr_get_constraints(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00120     static PyObject* pyattr_get_channels(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00121     KX_PYMETHOD_DOC_NOARGS(BL_ArmatureObject, update);
00122 
00123 #endif // WITH_PYTHON
00124 
00125 protected:
00126     /* list element: BL_ArmatureConstraint. Use SG_DListHead to have automatic list replication */
00127     SG_DListHead<BL_ArmatureConstraint>  m_controlledConstraints;
00128     /* list element: BL_ArmatureChannel. Use SG_DList to avoid list replication */
00129     SG_DList            m_poseChannels;
00130     Object              *m_objArma;
00131     struct bArmature    *m_armature;
00132     struct bPose        *m_pose;
00133     struct bPose        *m_armpose;
00134     struct bPose        *m_framePose;
00135     struct Scene        *m_scene; // need for where_is_pose 
00136     double  m_lastframe;
00137     double  m_timestep;     // delta since last pose evaluation.
00138     class BL_ActionActuator *m_activeAct;
00139     short   m_activePriority;
00140     int     m_vert_deform_type;
00141     size_t  m_constraintNumber;
00142     size_t  m_channelNumber;
00143     // store the original armature object matrix
00144     float m_obmat[4][4];
00145 
00146     double          m_lastapplyframe;
00147 };
00148 
00149 /* Pose function specific to the game engine */
00150 void game_blend_poses(struct bPose *dst, struct bPose *src, float srcweight/*, short mode*/); /* was blend_poses */
00151 //void extract_pose_from_pose(struct bPose *pose, const struct bPose *src);
00152 void game_copy_pose(struct bPose **dst, struct bPose *src, int copy_con);
00153 void game_free_pose(struct bPose *pose);
00154 
00155 
00156 #endif
00157