|
Blender
V2.59
|
00001 /* 00002 * $Id: BL_ShapeActionActuator.h 36523 2011-05-06 20:18:42Z blendix $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 #ifndef BL_SHAPEACTIONACTUATOR 00035 #define BL_SHAPEACTIONACTUATOR 00036 00037 #include "CTR_HashedPtr.h" 00038 #include "SCA_IActuator.h" 00039 #include "BL_ActionActuator.h" 00040 #include "MT_Point3.h" 00041 #include <vector> 00042 00043 struct Key; 00044 class BL_ShapeActionActuator : public SCA_IActuator 00045 { 00046 public: 00047 Py_Header; 00048 BL_ShapeActionActuator(SCA_IObject* gameobj, 00049 const STR_String& propname, 00050 const STR_String& framepropname, 00051 float starttime, 00052 float endtime, 00053 struct bAction *action, 00054 short playtype, 00055 short blendin, 00056 short priority, 00057 float stride) 00058 : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION), 00059 00060 m_lastpos(0, 0, 0), 00061 m_blendframe(0), 00062 m_flag(0), 00063 m_startframe (starttime), 00064 m_endframe(endtime) , 00065 m_starttime(0), 00066 m_localtime(starttime), 00067 m_lastUpdate(-1), 00068 m_blendin(blendin), 00069 m_blendstart(0), 00070 m_stridelength(stride), 00071 m_playtype(playtype), 00072 m_priority(priority), 00073 m_action(action), 00074 m_framepropname(framepropname), 00075 m_propname(propname) 00076 { 00077 }; 00078 virtual ~BL_ShapeActionActuator(); 00079 virtual bool Update(double curtime, bool frame); 00080 virtual CValue* GetReplica(); 00081 virtual void ProcessReplica(); 00082 00083 void SetBlendTime (float newtime); 00084 void BlendShape(struct Key* key, float weigth); 00085 00086 bAction* GetAction() { return m_action; } 00087 void SetAction(bAction* act) { m_action= act; } 00088 00089 #ifdef WITH_PYTHON 00090 00091 static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); 00092 static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); 00093 00094 static int CheckBlendTime(void *self, const PyAttributeDef*) 00095 { 00096 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self); 00097 00098 if (act->m_blendframe > act->m_blendin) 00099 act->m_blendframe = act->m_blendin; 00100 00101 return 0; 00102 } 00103 static int CheckFrame(void *self, const PyAttributeDef*) 00104 { 00105 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self); 00106 00107 if (act->m_localtime < act->m_startframe) 00108 act->m_localtime = act->m_startframe; 00109 else if (act->m_localtime > act->m_endframe) 00110 act->m_localtime = act->m_endframe; 00111 00112 return 0; 00113 } 00114 static int CheckType(void *self, const PyAttributeDef*) 00115 { 00116 BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self); 00117 00118 switch (act->m_playtype) { 00119 case ACT_ACTION_PLAY: 00120 case ACT_ACTION_PINGPONG: 00121 case ACT_ACTION_FLIPPER: 00122 case ACT_ACTION_LOOP_STOP: 00123 case ACT_ACTION_LOOP_END: 00124 case ACT_ACTION_FROM_PROP: 00125 return 0; 00126 default: 00127 PyErr_SetString(PyExc_ValueError, "Shape Action Actuator, invalid play type supplied"); 00128 return 1; 00129 } 00130 00131 } 00132 00133 #endif // WITH_PYTHON 00134 00135 protected: 00136 00137 void SetStartTime(float curtime); 00138 void SetLocalTime(float curtime); 00139 bool ClampLocalTime(); 00140 00141 MT_Point3 m_lastpos; 00142 float m_blendframe; 00143 int m_flag; 00145 float m_startframe; 00147 float m_endframe; 00149 float m_starttime; 00151 float m_localtime; 00152 00153 float m_lastUpdate; 00154 float m_blendin; 00155 float m_blendstart; 00156 float m_stridelength; 00157 short m_playtype; 00158 short m_priority; 00159 struct bAction *m_action; 00160 STR_String m_framepropname; 00161 STR_String m_propname; 00162 vector<float> m_blendshape; 00163 }; 00164 00165 #endif 00166