Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Converter / BL_ActionActuator.cpp
1 /**
2 * $Id$
3 *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28 */
29
30 #if defined (__sgi)
31 #include <math.h>
32 #else
33 #include <cmath>
34 #endif
35
36 #include "SCA_LogicManager.h"
37 #include "BL_ActionActuator.h"
38 #include "BL_ArmatureObject.h"
39 #include "BL_SkinDeformer.h"
40 #include "KX_GameObject.h"
41 #include "STR_HashedString.h"
42 #include "DNA_nla_types.h"
43 #include "BKE_action.h"
44 #include "DNA_action_types.h"
45 #include "DNA_armature_types.h"
46 #include "DNA_scene_types.h"
47 #include "MEM_guardedalloc.h"
48 #include "BLI_blenlib.h"
49 #include "BLI_arithb.h"
50 #include "MT_Matrix4x4.h"
51 #include "BKE_utildefines.h"
52 #include "FloatValue.h"
53 #include "PyObjectPlus.h"
54 #include "KX_PyMath.h"
55
56 #ifdef HAVE_CONFIG_H
57 #include <config.h>
58 #endif
59
60 extern "C" {
61 #include "BKE_animsys.h"
62 #include "BKE_action.h"
63 #include "RNA_access.h"
64 #include "RNA_define.h"
65 }
66
67 BL_ActionActuator::~BL_ActionActuator()
68 {
69         if (m_pose)
70                 game_free_pose(m_pose);
71         if (m_userpose)
72                 game_free_pose(m_userpose);
73         if (m_blendpose)
74                 game_free_pose(m_blendpose);
75 }
76
77 void BL_ActionActuator::ProcessReplica()
78 {
79         SCA_IActuator::ProcessReplica();
80         
81         m_pose = NULL;
82         m_blendpose = NULL;
83         m_localtime=m_startframe;
84         m_lastUpdate=-1;
85         
86 }
87
88 void BL_ActionActuator::SetBlendTime (float newtime){
89         m_blendframe = newtime;
90 }
91
92 CValue* BL_ActionActuator::GetReplica() {
93         BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
94         replica->ProcessReplica();
95         return replica;
96 }
97
98 bool BL_ActionActuator::ClampLocalTime()
99 {
100         if (m_startframe < m_endframe)
101         {
102                 if (m_localtime < m_startframe)
103                 {
104                         m_localtime = m_startframe;
105                         return true;
106                 } 
107                 else if (m_localtime > m_endframe)
108                 {
109                         m_localtime = m_endframe;
110                         return true;
111                 }
112         } else {
113                 if (m_localtime > m_startframe)
114                 {
115                         m_localtime = m_startframe;
116                         return true;
117                 }
118                 else if (m_localtime < m_endframe)
119                 {
120                         m_localtime = m_endframe;
121                         return true;
122                 }
123         }
124         return false;
125 }
126
127 void BL_ActionActuator::SetStartTime(float curtime)
128 {
129         float direction = m_startframe < m_endframe ? 1.0 : -1.0;
130         
131         if (!(m_flag & ACT_FLAG_REVERSE))
132                 m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
133         else
134                 m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
135 }
136
137 void BL_ActionActuator::SetLocalTime(float curtime)
138 {
139         float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
140         
141         if (m_endframe < m_startframe)
142                 delta_time = -delta_time;
143
144         if (!(m_flag & ACT_FLAG_REVERSE))
145                 m_localtime = m_startframe + delta_time;
146         else
147                 m_localtime = m_endframe - delta_time;
148 }
149
150
151 bool BL_ActionActuator::Update(double curtime, bool frame)
152 {
153         bool bNegativeEvent = false;
154         bool bPositiveEvent = false;
155         bool keepgoing = true;
156         bool wrap = false;
157         bool apply=true;
158         int     priority;
159         float newweight;
160
161         curtime -= KX_KetsjiEngine::GetSuspendedDelta();
162         
163         // result = true if animation has to be continued, false if animation stops
164         // maybe there are events for us in the queue !
165         if (frame)
166         {
167                 bNegativeEvent = m_negevent;
168                 bPositiveEvent = m_posevent;
169                 RemoveAllEvents();
170                 
171                 if (bPositiveEvent)
172                         m_flag |= ACT_FLAG_ACTIVE;
173                 
174                 if (bNegativeEvent)
175                 {
176                         // dont continue where we left off when restarting
177                         if (m_end_reset) {
178                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
179                         }
180                         
181                         if (!(m_flag & ACT_FLAG_ACTIVE))
182                                 return false;
183                         m_flag &= ~ACT_FLAG_ACTIVE;
184                 }
185         }
186         
187         /*      We know that action actuators have been discarded from all non armature objects:
188         if we're being called, we're attached to a BL_ArmatureObject */
189         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
190         float length = m_endframe - m_startframe;
191         
192         priority = m_priority;
193         
194         /* Determine pre-incrementation behaviour and set appropriate flags */
195         switch (m_playtype){
196         case ACT_ACTION_MOTION:
197                 if (bNegativeEvent){
198                         keepgoing=false;
199                         apply=false;
200                 };
201                 break;
202         case ACT_ACTION_FROM_PROP:
203                 if (bNegativeEvent){
204                         apply=false;
205                         keepgoing=false;
206                 }
207                 break;
208         case ACT_ACTION_LOOP_END:
209                 if (bPositiveEvent){
210                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
211                                 m_flag &= ~ACT_FLAG_KEYUP;
212                                 m_flag &= ~ACT_FLAG_REVERSE;
213                                 m_flag |= ACT_FLAG_LOCKINPUT;
214                                 m_localtime = m_startframe;
215                                 m_starttime = curtime;
216                         }
217                 }
218                 if (bNegativeEvent){
219                         m_flag |= ACT_FLAG_KEYUP;
220                 }
221                 break;
222         case ACT_ACTION_LOOP_STOP:
223                 if (bPositiveEvent){
224                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
225                                 m_flag &= ~ACT_FLAG_REVERSE;
226                                 m_flag &= ~ACT_FLAG_KEYUP;
227                                 m_flag |= ACT_FLAG_LOCKINPUT;
228                                 SetStartTime(curtime);
229                         }
230                 }
231                 if (bNegativeEvent){
232                         m_flag |= ACT_FLAG_KEYUP;
233                         m_flag &= ~ACT_FLAG_LOCKINPUT;
234                         keepgoing=false;
235                         apply=false;
236                 }
237                 break;
238         case ACT_ACTION_FLIPPER:
239                 if (bPositiveEvent){
240                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
241                                 m_flag &= ~ACT_FLAG_REVERSE;
242                                 m_flag |= ACT_FLAG_LOCKINPUT;
243                                 SetStartTime(curtime);
244                         }
245                 }
246                 else if (bNegativeEvent){
247                         m_flag |= ACT_FLAG_REVERSE;
248                         m_flag &= ~ACT_FLAG_LOCKINPUT;
249                         SetStartTime(curtime);
250                 }
251                 break;
252         case ACT_ACTION_PLAY:
253                 if (bPositiveEvent){
254                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
255                                 m_flag &= ~ACT_FLAG_REVERSE;
256                                 m_localtime = m_starttime;
257                                 m_starttime = curtime;
258                                 m_flag |= ACT_FLAG_LOCKINPUT;
259                         }
260                 }
261                 break;
262         default:
263                 break;
264         }
265         
266         /* Perform increment */
267         if (keepgoing){
268                 if (m_playtype == ACT_ACTION_MOTION){
269                         MT_Point3       newpos;
270                         MT_Point3       deltapos;
271                         
272                         newpos = obj->NodeGetWorldPosition();
273                         
274                         /* Find displacement */
275                         deltapos = newpos-m_lastpos;
276                         m_localtime += (length/m_stridelength) * deltapos.length();
277                         m_lastpos = newpos;
278                 }
279                 else{
280                         SetLocalTime(curtime);
281                 }
282         }
283         
284         /* Check if a wrapping response is needed */
285         if (length){
286                 if (m_localtime < m_startframe || m_localtime > m_endframe)
287                 {
288                         m_localtime = m_startframe + fmod(m_localtime, length);
289                         wrap = true;
290                 }
291         }
292         else
293                 m_localtime = m_startframe;
294         
295         /* Perform post-increment tasks */
296         switch (m_playtype){
297         case ACT_ACTION_FROM_PROP:
298                 {
299                         CValue* propval = GetParent()->GetProperty(m_propname);
300                         if (propval)
301                                 m_localtime = propval->GetNumber();
302                         
303                         if (bNegativeEvent){
304                                 keepgoing=false;
305                         }
306                 }
307                 break;
308         case ACT_ACTION_MOTION:
309                 break;
310         case ACT_ACTION_LOOP_STOP:
311                 break;
312         case ACT_ACTION_FLIPPER:
313                 if (wrap){
314                         if (!(m_flag & ACT_FLAG_REVERSE)){
315                                 m_localtime=m_endframe;
316                                 //keepgoing = false;
317                         }
318                         else {
319                                 m_localtime=m_startframe;
320                                 keepgoing = false;
321                         }
322                 }
323                 break;
324         case ACT_ACTION_LOOP_END:
325                 if (wrap){
326                         if (m_flag & ACT_FLAG_KEYUP){
327                                 keepgoing = false;
328                                 m_localtime = m_endframe;
329                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
330                         }
331                         SetStartTime(curtime);
332                 }
333                 break;
334         case ACT_ACTION_PLAY:
335                 if (wrap){
336                         m_localtime = m_endframe;
337                         keepgoing = false;
338                         m_flag &= ~ACT_FLAG_LOCKINPUT;
339                 }
340                 break;
341         default:
342                 keepgoing = false;
343                 break;
344         }
345         
346         /* Set the property if its defined */
347         if (m_framepropname[0] != '\0') {
348                 CValue* propowner = GetParent();
349                 CValue* oldprop = propowner->GetProperty(m_framepropname);
350                 CValue* newval = new CFloatValue(m_localtime);
351                 if (oldprop) {
352                         oldprop->SetValue(newval);
353                 } else {
354                         propowner->SetProperty(m_framepropname, newval);
355                 }
356                 newval->Release();
357         }
358         
359         if (bNegativeEvent)
360                 m_blendframe=0.0;
361         
362         /* Apply the pose if necessary*/
363         if (apply){
364
365                 /* Priority test */
366                 if (obj->SetActiveAction(this, priority, curtime)){
367                         
368                         /* Get the underlying pose from the armature */
369                         obj->GetPose(&m_pose);
370
371 // 2.4x function, 
372                         /* Override the necessary channels with ones from the action */
373                         // XXX extract_pose_from_action(m_pose, m_action, m_localtime);
374                         
375                         
376 // 2.5x - replacement for extract_pose_from_action(...) above.
377                         {
378                                 struct PointerRNA id_ptr;
379                                 Object *arm= obj->GetArmatureObject();
380                                 bPose *pose_back= arm->pose;
381                                 
382                                 arm->pose= m_pose;
383                                 RNA_id_pointer_create((ID *)arm, &id_ptr);
384                                 animsys_evaluate_action(&id_ptr, m_action, NULL, m_localtime);
385                                 
386                                 arm->pose= pose_back;
387                         
388 // 2.5x - could also do this but looks too high level, constraints use this, it works ok.
389 //                              Object workob; /* evaluate using workob */
390 //                              what_does_obaction((Scene *)obj->GetScene(), obj->GetArmatureObject(), &workob, m_pose, m_action, NULL, m_localtime);
391                         }
392
393                         // done getting the pose from the action
394                         
395                         /* Perform the user override (if any) */
396                         if (m_userpose){
397                                 extract_pose_from_pose(m_pose, m_userpose);
398                                 game_free_pose(m_userpose); //cant use MEM_freeN(m_userpose) because the channels need freeing too.
399                                 m_userpose = NULL;
400                         }
401 #if 1
402                         /* Handle blending */
403                         if (m_blendin && (m_blendframe<m_blendin)){
404                                 /* If this is the start of a blending sequence... */
405                                 if ((m_blendframe==0.0) || (!m_blendpose)){
406                                         obj->GetMRDPose(&m_blendpose);
407                                         m_blendstart = curtime;
408                                 }
409                                 
410                                 /* Find percentages */
411                                 newweight = (m_blendframe/(float)m_blendin);
412                                 game_blend_poses(m_pose, m_blendpose, 1.0 - newweight);
413
414                                 /* Increment current blending percentage */
415                                 m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
416                                 if (m_blendframe>m_blendin)
417                                         m_blendframe = m_blendin;
418                                 
419                         }
420 #endif
421                         m_lastUpdate = m_localtime;
422                         obj->SetPose (m_pose);
423                 }
424                 else{
425                         m_blendframe = 0.0;
426                 }
427         }
428         
429         if (!keepgoing){
430                 m_blendframe = 0.0;
431         }
432         return keepgoing;
433 };
434
435 /* ------------------------------------------------------------------------- */
436 /* Python functions                                                          */
437 /* ------------------------------------------------------------------------- */
438
439 PyObject* BL_ActionActuator::PyGetChannel(PyObject* value) {
440         char *string= _PyUnicode_AsString(value);
441         
442         if (!string) {
443                 PyErr_SetString(PyExc_TypeError, "expected a single string");
444                 return NULL;
445         }
446         
447         bPoseChannel *pchan;
448         
449         if(m_userpose==NULL && m_pose==NULL) {
450                 BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
451                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
452         }
453         
454         // get_pose_channel accounts for NULL pose, run on both incase one exists but
455         // the channel doesnt
456         if(             !(pchan=get_pose_channel(m_userpose, string)) &&
457                         !(pchan=get_pose_channel(m_pose, string))  )
458         {
459                 PyErr_SetString(PyExc_ValueError, "channel doesnt exist");
460                 return NULL;
461         }
462
463         PyObject *ret = PyTuple_New(3);
464         
465         PyObject *list = PyList_New(3); 
466         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->loc[0]));
467         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->loc[1]));
468         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->loc[2]));
469         PyTuple_SET_ITEM(ret, 0, list);
470         
471         list = PyList_New(3);
472         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->size[0]));
473         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->size[1]));
474         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->size[2]));
475         PyTuple_SET_ITEM(ret, 1, list);
476         
477         list = PyList_New(4);
478         PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->quat[0]));
479         PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->quat[1]));
480         PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->quat[2]));
481         PyList_SET_ITEM(list, 3, PyFloat_FromDouble(pchan->quat[3]));
482         PyTuple_SET_ITEM(ret, 2, list);
483
484         return ret;
485 /*
486         return Py_BuildValue("([fff][fff][ffff])",
487                 pchan->loc[0], pchan->loc[1], pchan->loc[2],
488                 pchan->size[0], pchan->size[1], pchan->size[2],
489                 pchan->quat[0], pchan->quat[1], pchan->quat[2], pchan->quat[3] );
490 */
491 }
492
493 /*     setChannel                                                         */
494 KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
495 "setChannel(channel, matrix)\n"
496 "\t - channel   : A string specifying the name of the bone channel.\n"
497 "\t - matrix    : A 4x4 matrix specifying the overriding transformation\n"
498 "\t               as an offset from the bone's rest position.\n")
499 {
500         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
501         char *string;
502         PyObject *pymat= NULL;
503         PyObject *pyloc= NULL, *pysize= NULL, *pyquat= NULL;
504         bPoseChannel *pchan;
505         
506         if(PyTuple_Size(args)==2) {
507                 if (!PyArg_ParseTuple(args,"sO:setChannel", &string, &pymat)) // matrix
508                         return NULL;
509         }
510         else if(PyTuple_Size(args)==4) {
511                 if (!PyArg_ParseTuple(args,"sOOO:setChannel", &string, &pyloc, &pysize, &pyquat)) // loc/size/quat
512                         return NULL;
513         }
514         else {
515                 PyErr_SetString(PyExc_ValueError, "Expected a string and a 4x4 matrix (2 args) or a string and loc/size/quat sequences (4 args)");
516                 return NULL;
517         }
518         
519         if(pymat) {
520                 float matrix[4][4];
521                 MT_Matrix4x4 mat;
522                 
523                 if(!PyMatTo(pymat, mat))
524                         return NULL;
525                 
526                 mat.setValue((const float *)matrix);
527                 
528                 BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
529                 
530                 if (!m_userpose) {
531                         if(!m_pose)
532                                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
533                         game_copy_pose(&m_userpose, m_pose, 0);
534                 }
535                 // pchan= verify_pose_channel(m_userpose, string); // adds the channel if its not there.
536                 pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
537                 
538                 if(pchan) {
539                         VECCOPY (pchan->loc, matrix[3]);
540                         Mat4ToSize(matrix, pchan->size);
541                         Mat4ToQuat(matrix, pchan->quat);
542                 }
543         }
544         else {
545                 MT_Vector3 loc;
546                 MT_Vector3 size;
547                 MT_Quaternion quat;
548                 
549                 if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
550                         return NULL;
551                 
552                 // same as above
553                 if (!m_userpose) {
554                         if(!m_pose)
555                                 obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
556                         game_copy_pose(&m_userpose, m_pose, 0);
557                 }
558                 // pchan= verify_pose_channel(m_userpose, string);
559                 pchan= get_pose_channel(m_userpose, string); // adds the channel if its not there.
560                 
561                 // for some reason loc.setValue(pchan->loc) fails
562                 if(pchan) {
563                         pchan->loc[0]= loc[0]; pchan->loc[1]= loc[1]; pchan->loc[2]= loc[2];
564                         pchan->size[0]= size[0]; pchan->size[1]= size[1]; pchan->size[2]= size[2];
565                         pchan->quat[0]= quat[3]; pchan->quat[1]= quat[0]; pchan->quat[2]= quat[1]; pchan->quat[3]= quat[2]; /* notice xyzw -> wxyz is intentional */
566                 }
567         }
568         
569         if(pchan==NULL) {
570                 PyErr_SetString(PyExc_ValueError, "Channel could not be found, use the 'channelNames' attribute to get a list of valid channels");
571                 return NULL;
572         }
573         
574         Py_RETURN_NONE;
575 }
576
577 /* ------------------------------------------------------------------------- */
578 /* Python Integration Hooks                                                                      */
579 /* ------------------------------------------------------------------------- */
580
581 PyTypeObject BL_ActionActuator::Type = {
582         PyVarObject_HEAD_INIT(NULL, 0)
583         "BL_ActionActuator",
584         sizeof(PyObjectPlus_Proxy),
585         0,
586         py_base_dealloc,
587         0,
588         0,
589         0,
590         0,
591         py_base_repr,
592         0,0,0,0,0,0,0,0,0,
593         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
594         0,0,0,0,0,0,0,
595         Methods,
596         0,
597         0,
598         &SCA_IActuator::Type,
599         0,0,0,0,0,0,
600         py_base_new
601 };
602
603 PyMethodDef BL_ActionActuator::Methods[] = {
604         {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_O},
605         KX_PYMETHODTABLE(BL_ActionActuator, setChannel),
606         {NULL,NULL} //Sentinel
607 };
608
609 PyAttributeDef BL_ActionActuator::Attributes[] = {
610         KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
611         KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
612         KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
613         KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
614         KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
615         KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
616         KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ActionActuator, m_localtime, CheckFrame),
617         KX_PYATTRIBUTE_STRING_RW("propName", 0, 31, false, BL_ActionActuator, m_propname),
618         KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 31, false, BL_ActionActuator, m_framepropname),
619         KX_PYATTRIBUTE_BOOL_RW("useContinue", BL_ActionActuator, m_end_reset),
620         KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
621         KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
622         { NULL }        //Sentinel
623 };
624
625 PyObject* BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
626 {
627         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
628         return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
629 }
630
631 int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
632 {
633         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
634         
635         if (!PyUnicode_Check(value))
636         {
637                 PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
638                 return PY_SET_ATTR_FAIL;
639         }
640
641         bAction *action= NULL;
642         STR_String val = _PyUnicode_AsString(value);
643         
644         if (val != "")
645         {
646                 action= (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(val);
647                 if (!action)
648                 {
649                         PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
650                         return PY_SET_ATTR_FAIL;
651                 }
652         }
653         
654         self->SetAction(action);
655         return PY_SET_ATTR_SUCCESS;
656
657 }
658
659 PyObject* BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
660 {
661         BL_ActionActuator* self= static_cast<BL_ActionActuator*>(self_v);
662         PyObject *ret= PyList_New(0);
663         PyObject *item;
664         
665         bPose *pose= ((BL_ArmatureObject*)self->GetParent())->GetOrigPose();
666         
667         if(pose) {
668                 bPoseChannel *pchan;
669                 for(pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
670                         item= PyUnicode_FromString(pchan->name);
671                         PyList_Append(ret, item);
672                         Py_DECREF(item);
673                 }
674         }
675         
676         return ret;
677 }