Cleanup & preparation commit for getting Armatures/Poses/Actions working
[blender.git] / source / gameengine / Converter / BL_ActionActuator.cpp
1 /**
2 * $Id$
3 *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31 */
32
33 #if defined (__sgi)
34 #include <math.h>
35 #else
36 #include <cmath>
37 #endif
38
39 #include "SCA_LogicManager.h"
40 #include "BL_ActionActuator.h"
41 #include "BL_ArmatureObject.h"
42 #include "BL_SkinDeformer.h"
43 #include "KX_GameObject.h"
44 #include "STR_HashedString.h"
45 #include "DNA_action_types.h"
46 #include "DNA_actuator_types.h"
47 #include "BKE_action.h"
48 #include "DNA_armature_types.h"
49 #include "MEM_guardedalloc.h"
50 #include "BLI_blenlib.h"
51 #include "BLI_arithb.h"
52 #include "MT_Matrix4x4.h"
53 #include "BKE_utildefines.h"
54
55 #ifdef HAVE_CONFIG_H
56 #include <config.h>
57 #endif
58
59 BL_ActionActuator::~BL_ActionActuator()
60 {
61         if (m_pose) {
62                 free_pose_channels(m_pose);
63                 MEM_freeN(m_pose);
64                 m_pose = NULL;
65         };
66         
67         if (m_userpose){
68                 free_pose_channels(m_userpose);
69                 MEM_freeN(m_userpose);
70                 m_userpose=NULL;
71         }
72         if (m_blendpose) {
73                 free_pose_channels(m_blendpose);
74                 MEM_freeN(m_blendpose);
75                 m_blendpose = NULL;
76         };
77         
78 }
79
80 void BL_ActionActuator::ProcessReplica(){
81 //      bPose *oldpose = m_pose;
82 //      bPose *oldbpose = m_blendpose;
83         
84         m_pose = NULL;
85         m_blendpose = NULL;
86         m_localtime=m_startframe;
87         m_lastUpdate=-1;
88         
89 }
90
91 void BL_ActionActuator::SetBlendTime (float newtime){
92         m_blendframe = newtime;
93 }
94
95 CValue* BL_ActionActuator::GetReplica() {
96         BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
97         replica->ProcessReplica();
98         
99         // this will copy properties and so on...
100         CValue::AddDataToReplica(replica);
101         return replica;
102 }
103
104 bool BL_ActionActuator::ClampLocalTime()
105 {
106         if (m_startframe < m_endframe)
107         {
108                 if (m_localtime < m_startframe)
109                 {
110                         m_localtime = m_startframe;
111                         return true;
112                 } 
113                 else if (m_localtime > m_endframe)
114                 {
115                         m_localtime = m_endframe;
116                         return true;
117                 }
118         } else {
119                 if (m_localtime > m_startframe)
120                 {
121                         m_localtime = m_startframe;
122                         return true;
123                 }
124                 else if (m_localtime < m_endframe)
125                 {
126                         m_localtime = m_endframe;
127                         return true;
128                 }
129         }
130         return false;
131 }
132
133 void BL_ActionActuator::SetStartTime(float curtime)
134 {
135         float direction = m_startframe < m_endframe ? 1.0 : -1.0;
136         
137         if (!(m_flag & ACT_FLAG_REVERSE))
138                 m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_FIXED_FRAME_PER_SEC;
139         else
140                 m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_FIXED_FRAME_PER_SEC;
141 }
142
143 void BL_ActionActuator::SetLocalTime(float curtime)
144 {
145         float delta_time = (curtime - m_starttime)*KX_FIXED_FRAME_PER_SEC;
146         
147         if (m_endframe < m_startframe)
148                 delta_time = -delta_time;
149
150         if (!(m_flag & ACT_FLAG_REVERSE))
151                 m_localtime = m_startframe + delta_time;
152         else
153                 m_localtime = m_endframe - delta_time;
154 }
155
156
157 bool BL_ActionActuator::Update(double curtime, bool frame)
158 {
159         bool bNegativeEvent = false;
160         bool bPositiveEvent = false;
161         bool keepgoing = true;
162         bool wrap = false;
163         bool apply=true;
164         int     priority;
165         float newweight;
166         
167         // result = true if animation has to be continued, false if animation stops
168         // maybe there are events for us in the queue !
169         if (frame)
170         {
171                 for (vector<CValue*>::iterator i=m_events.end(); !(i==m_events.begin());)
172                 {
173                         i--;
174                         if ((*i)->GetNumber() == 0.0f)
175                                 bNegativeEvent = true;
176                         else
177                                 bPositiveEvent= true;
178                         (*i)->Release();
179                         m_events.pop_back();
180                 }
181                 
182                 if (bPositiveEvent)
183                         m_flag |= ACT_FLAG_ACTIVE;
184                 
185                 if (bNegativeEvent)
186                 {
187                         if (!(m_flag & ACT_FLAG_ACTIVE))
188                                 return false;
189                         m_flag &= ~ACT_FLAG_ACTIVE;
190                 }
191         }
192         
193         /*      We know that action actuators have been discarded from all non armature objects:
194         if we're being called, we're attached to a BL_ArmatureObject */
195         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
196         float length = m_endframe - m_startframe;
197         
198         priority = m_priority;
199         
200         /* Determine pre-incrementation behaviour and set appropriate flags */
201         switch (m_playtype){
202         case ACT_ACTION_MOTION:
203                 if (bNegativeEvent){
204                         keepgoing=false;
205                         apply=false;
206                 };
207                 break;
208         case ACT_ACTION_FROM_PROP:
209                 if (bNegativeEvent){
210                         apply=false;
211                         keepgoing=false;
212                 }
213                 break;
214         case ACT_ACTION_LOOP_END:
215                 if (bPositiveEvent){
216                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
217                                 m_flag &= ~ACT_FLAG_KEYUP;
218                                 m_flag &= ~ACT_FLAG_REVERSE;
219                                 m_flag |= ACT_FLAG_LOCKINPUT;
220                                 m_localtime = m_startframe;
221                                 m_starttime = curtime;
222                         }
223                 }
224                 if (bNegativeEvent){
225                         m_flag |= ACT_FLAG_KEYUP;
226                 }
227                 break;
228         case ACT_ACTION_LOOP_STOP:
229                 if (bPositiveEvent){
230                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
231                                 m_flag &= ~ACT_FLAG_REVERSE;
232                                 m_flag &= ~ACT_FLAG_KEYUP;
233                                 m_flag |= ACT_FLAG_LOCKINPUT;
234                                 SetStartTime(curtime);
235                         }
236                 }
237                 if (bNegativeEvent){
238                         m_flag |= ACT_FLAG_KEYUP;
239                         m_flag &= ~ACT_FLAG_LOCKINPUT;
240                         keepgoing=false;
241                         apply=false;
242                 }
243                 break;
244         case ACT_ACTION_FLIPPER:
245                 if (bPositiveEvent){
246                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
247                                 m_flag &= ~ACT_FLAG_REVERSE;
248                                 m_flag |= ACT_FLAG_LOCKINPUT;
249                                 SetStartTime(curtime);
250                         }
251                 }
252                 else if (bNegativeEvent){
253                         m_flag |= ACT_FLAG_REVERSE;
254                         m_flag &= ~ACT_FLAG_LOCKINPUT;
255                         SetStartTime(curtime);
256                 }
257                 break;
258         case ACT_ACTION_PLAY:
259                 if (bPositiveEvent){
260                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
261                                 m_flag &= ~ACT_FLAG_REVERSE;
262                                 m_localtime = m_starttime;
263                                 m_starttime = curtime;
264                                 m_flag |= ACT_FLAG_LOCKINPUT;
265                         }
266                 }
267                 break;
268         default:
269                 break;
270         }
271         
272         /* Perform increment */
273         if (keepgoing){
274                 if (m_playtype == ACT_ACTION_MOTION){
275                         MT_Point3       newpos;
276                         MT_Point3       deltapos;
277                         
278                         newpos = obj->NodeGetWorldPosition();
279                         
280                         /* Find displacement */
281                         deltapos = newpos-m_lastpos;
282                         m_localtime += (length/m_stridelength) * deltapos.length();
283                         m_lastpos = newpos;
284                 }
285                 else{
286                         SetLocalTime(curtime);
287                 }
288         }
289         
290         /* Check if a wrapping response is needed */
291         if (length){
292                 if (m_localtime < m_startframe || m_localtime > m_endframe)
293                 {
294                         m_localtime = m_startframe + fmod(m_localtime, length);
295                         wrap = true;
296                 }
297         }
298         else
299                 m_localtime = m_startframe;
300         
301         /* Perform post-increment tasks */
302         switch (m_playtype){
303         case ACT_ACTION_FROM_PROP:
304                 {
305                         CValue* propval = GetParent()->GetProperty(m_propname);
306                         if (propval)
307                                 m_localtime = propval->GetNumber();
308                         
309                         if (bNegativeEvent){
310                                 keepgoing=false;
311                         }
312                 }
313                 break;
314         case ACT_ACTION_MOTION:
315                 break;
316         case ACT_ACTION_LOOP_STOP:
317                 break;
318         case ACT_ACTION_FLIPPER:
319                 if (wrap){
320                         if (!(m_flag & ACT_FLAG_REVERSE)){
321                                 m_localtime=m_endframe;
322                                 //keepgoing = false;
323                         }
324                         else {
325                                 m_localtime=m_startframe;
326                                 keepgoing = false;
327                         }
328                 }
329                 break;
330         case ACT_ACTION_LOOP_END:
331                 if (wrap){
332                         if (m_flag & ACT_FLAG_KEYUP){
333                                 keepgoing = false;
334                                 m_localtime = m_endframe;
335                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
336                         }
337                         SetStartTime(curtime);
338                 }
339                 break;
340         case ACT_ACTION_PLAY:
341                 if (wrap){
342                         m_localtime = m_endframe;
343                         keepgoing = false;
344                         m_flag &= ~ACT_FLAG_LOCKINPUT;
345                 }
346                 break;
347         default:
348                 keepgoing = false;
349                 break;
350         }
351         
352         
353         if (bNegativeEvent)
354                 m_blendframe=0.0;
355         
356         /* Apply the pose if necessary*/
357         if (apply){
358
359                 /* Priority test */
360                 if (obj->SetActiveAction(this, priority, curtime)){
361                         
362                         /* Get the underlying pose from the armature */
363                         obj->GetPose(&m_pose);
364                         
365                         /* Override the necessary channels with ones from the action */
366                         extract_pose_from_action(m_pose, m_action, m_localtime);
367
368                         /* Perform the user override (if any) */
369                         if (m_userpose){
370                                 extract_pose_from_pose(m_pose, m_userpose);
371 //                              clear_pose(m_userpose);
372                                 MEM_freeN(m_userpose);
373                                 m_userpose = NULL;
374                         }
375 #if 1
376                         /* Handle blending */
377                         if (m_blendin && (m_blendframe<m_blendin)){
378                                 /* If this is the start of a blending sequence... */
379                                 if ((m_blendframe==0.0) || (!m_blendpose)){
380                                         obj->GetMRDPose(&m_blendpose);
381                                         m_blendstart = curtime;
382                                 }
383                                 
384                                 /* Find percentages */
385                                 newweight = (m_blendframe/(float)m_blendin);
386                                 blend_poses(m_pose, m_blendpose, 1.0 - newweight, POSE_BLEND);
387
388                                 /* Increment current blending percentage */
389                                 m_blendframe = (curtime - m_blendstart)*KX_FIXED_FRAME_PER_SEC;
390                                 if (m_blendframe>m_blendin)
391                                         m_blendframe = m_blendin;
392                                 
393                         }
394 #endif
395                         m_lastUpdate = m_localtime;
396                         obj->SetPose (m_pose);
397                 }
398                 else{
399                         m_blendframe = 0.0;
400                 }
401         }
402         
403         if (!keepgoing){
404                 m_blendframe = 0.0;
405         }
406         return keepgoing;
407 };
408
409 /* ------------------------------------------------------------------------- */
410 /* Python functions                                                          */
411 /* ------------------------------------------------------------------------- */
412
413 /* Integration hooks ------------------------------------------------------- */
414
415 PyTypeObject BL_ActionActuator::Type = {
416         PyObject_HEAD_INIT(&PyType_Type)
417                 0,
418                 "BL_ActionActuator",
419                 sizeof(BL_ActionActuator),
420                 0,
421                 PyDestructor,
422                 0,
423                 __getattr,
424                 __setattr,
425                 0, //&MyPyCompare,
426                 __repr,
427                 0, //&cvalue_as_number,
428                 0,
429                 0,
430                 0,
431                 0
432 };
433
434 PyParentObject BL_ActionActuator::Parents[] = {
435         &BL_ActionActuator::Type,
436                 &SCA_IActuator::Type,
437                 &SCA_ILogicBrick::Type,
438                 &CValue::Type,
439                 NULL
440 };
441
442 PyMethodDef BL_ActionActuator::Methods[] = {
443         {"setAction", (PyCFunction) BL_ActionActuator::sPySetAction, METH_VARARGS, SetAction_doc},
444         {"setStart", (PyCFunction) BL_ActionActuator::sPySetStart, METH_VARARGS, SetStart_doc},
445         {"setEnd", (PyCFunction) BL_ActionActuator::sPySetEnd, METH_VARARGS, SetEnd_doc},
446         {"setBlendin", (PyCFunction) BL_ActionActuator::sPySetBlendin, METH_VARARGS, SetBlendin_doc},
447         {"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, SetPriority_doc},
448         {"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, SetFrame_doc},
449         {"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, SetProperty_doc},
450         {"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, SetBlendtime_doc},
451
452         {"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, GetAction_doc},
453         {"getStart", (PyCFunction) BL_ActionActuator::sPyGetStart, METH_VARARGS, GetStart_doc},
454         {"getEnd", (PyCFunction) BL_ActionActuator::sPyGetEnd, METH_VARARGS, GetEnd_doc},
455         {"getBlendin", (PyCFunction) BL_ActionActuator::sPyGetBlendin, METH_VARARGS, GetBlendin_doc},
456         {"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, GetPriority_doc},
457         {"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, GetFrame_doc},
458         {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
459         {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
460 //      {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
461         {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},    
462         {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
463         {NULL,NULL} //Sentinel
464 };
465
466 PyObject* BL_ActionActuator::_getattr(const STR_String& attr) {
467         _getattr_up(SCA_IActuator);
468 }
469
470 /*     setStart                                                              */
471 char BL_ActionActuator::GetAction_doc[] = 
472 "getAction()\n"
473 "\tReturns a string containing the name of the current action.\n";
474
475 PyObject* BL_ActionActuator::PyGetAction(PyObject* self, 
476                                                                                  PyObject* args, 
477                                                                                  PyObject* kwds) {
478         PyObject *result;
479         
480         if (m_action){
481                 result = Py_BuildValue("s", m_action->id.name+2);
482         }
483         else{
484                 Py_INCREF(Py_None);
485                 result = Py_None;
486         }
487         
488         return result;
489 }
490
491 /*     getProperty                                                             */
492 char BL_ActionActuator::GetProperty_doc[] = 
493 "getProperty()\n"
494 "\tReturns the name of the property to be used in FromProp mode.\n";
495
496 PyObject* BL_ActionActuator::PyGetProperty(PyObject* self, 
497                                                                                    PyObject* args, 
498                                                                                    PyObject* kwds) {
499         PyObject *result;
500         
501         result = Py_BuildValue("s", (const char *)m_propname);
502         
503         return result;
504 }
505
506 /*     getFrame                                                              */
507 char BL_ActionActuator::GetFrame_doc[] = 
508 "getFrame()\n"
509 "\tReturns the current frame number.\n";
510
511 PyObject* BL_ActionActuator::PyGetFrame(PyObject* self, 
512                                                                                 PyObject* args, 
513                                                                                 PyObject* kwds) {
514         PyObject *result;
515         
516         result = Py_BuildValue("f", m_localtime);
517         
518         return result;
519 }
520
521 /*     getEnd                                                                */
522 char BL_ActionActuator::GetEnd_doc[] = 
523 "getEnd()\n"
524 "\tReturns the last frame of the action.\n";
525
526 PyObject* BL_ActionActuator::PyGetEnd(PyObject* self, 
527                                                                           PyObject* args, 
528                                                                           PyObject* kwds) {
529         PyObject *result;
530         
531         result = Py_BuildValue("f", m_endframe);
532         
533         return result;
534 }
535
536 /*     getStart                                                              */
537 char BL_ActionActuator::GetStart_doc[] = 
538 "getStart()\n"
539 "\tReturns the starting frame of the action.\n";
540
541 PyObject* BL_ActionActuator::PyGetStart(PyObject* self, 
542                                                                                 PyObject* args, 
543                                                                                 PyObject* kwds) {
544         PyObject *result;
545         
546         result = Py_BuildValue("f", m_startframe);
547         
548         return result;
549 }
550
551 /*     getBlendin                                                            */
552 char BL_ActionActuator::GetBlendin_doc[] = 
553 "getBlendin()\n"
554 "\tReturns the number of interpolation animation frames to be\n"
555 "\tgenerated when this actuator is triggered.\n";
556
557 PyObject* BL_ActionActuator::PyGetBlendin(PyObject* self, 
558                                                                                   PyObject* args, 
559                                                                                   PyObject* kwds) {
560         PyObject *result;
561         
562         result = Py_BuildValue("f", m_blendin);
563         
564         return result;
565 }
566
567 /*     getPriority                                                           */
568 char BL_ActionActuator::GetPriority_doc[] = 
569 "getPriority()\n"
570 "\tReturns the priority for this actuator.  Actuators with lower\n"
571 "\tPriority numbers will override actuators with higher numbers.\n";
572
573 PyObject* BL_ActionActuator::PyGetPriority(PyObject* self, 
574                                                                                    PyObject* args, 
575                                                                                    PyObject* kwds) {
576         PyObject *result;
577         
578         result = Py_BuildValue("i", m_priority);
579         
580         return result;
581 }
582
583 /*     setAction                                                             */
584 char BL_ActionActuator::SetAction_doc[] = 
585 "setAction(action, (reset))\n"
586 "\t - action    : The name of the action to set as the current action.\n"
587 "\t - reset     : Optional parameter indicating whether to reset the\n"
588 "\t               blend timer or not.  A value of 1 indicates that the\n"
589 "\t               timer should be reset.  A value of 0 will leave it\n"
590 "\t               unchanged.  If reset is not specified, the timer will"
591 "\t                   be reset.\n";
592
593 PyObject* BL_ActionActuator::PySetAction(PyObject* self, 
594                                                                                  PyObject* args, 
595                                                                                  PyObject* kwds) {
596         char *string;
597         int     reset = 1;
598
599         if (PyArg_ParseTuple(args,"s|i",&string, &reset))
600         {
601                 bAction *action;
602                 
603                 action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(STR_String(string));
604                 
605                 if (!action){
606                         /* NOTE!  Throw an exception or something */
607                         //                      printf ("setAction failed: Action not found\n", string);
608                 }
609                 else{
610                         m_action=action;
611                         if (reset)
612                                 m_blendframe = 0;
613                 }
614         }
615         
616         Py_INCREF(Py_None);
617         return Py_None;
618 }
619
620 /*     setStart                                                              */
621 char BL_ActionActuator::SetStart_doc[] = 
622 "setStart(start)\n"
623 "\t - start     : Specifies the starting frame of the animation.\n";
624
625 PyObject* BL_ActionActuator::PySetStart(PyObject* self, 
626                                                                                 PyObject* args, 
627                                                                                 PyObject* kwds) {
628         float start;
629         
630         if (PyArg_ParseTuple(args,"f",&start))
631         {
632                 m_startframe = start;
633         }
634         
635         Py_INCREF(Py_None);
636         return Py_None;
637 }
638
639 /*     setEnd                                                                */
640 char BL_ActionActuator::SetEnd_doc[] = 
641 "setEnd(end)\n"
642 "\t - end       : Specifies the ending frame of the animation.\n";
643
644 PyObject* BL_ActionActuator::PySetEnd(PyObject* self, 
645                                                                           PyObject* args, 
646                                                                           PyObject* kwds) {
647         float end;
648         
649         if (PyArg_ParseTuple(args,"f",&end))
650         {
651                 m_endframe = end;
652         }
653         
654         Py_INCREF(Py_None);
655         return Py_None;
656 }
657
658 /*     setBlendin                                                            */
659 char BL_ActionActuator::SetBlendin_doc[] = 
660 "setBlendin(blendin)\n"
661 "\t - blendin   : Specifies the number of frames of animation to generate\n"
662 "\t               when making transitions between actions.\n";
663
664 PyObject* BL_ActionActuator::PySetBlendin(PyObject* self, 
665                                                                                   PyObject* args, 
666                                                                                   PyObject* kwds) {
667         float blendin;
668         
669         if (PyArg_ParseTuple(args,"f",&blendin))
670         {
671                 m_blendin = blendin;
672         }
673         
674         Py_INCREF(Py_None);
675         return Py_None;
676 }
677
678 /*     setBlendtime                                                          */
679 char BL_ActionActuator::SetBlendtime_doc[] = 
680 "setBlendtime(blendtime)\n"
681 "\t - blendtime : Allows the script to directly modify the internal timer\n"
682 "\t               used when generating transitions between actions.  This\n"
683 "\t               parameter must be in the range from 0.0 to 1.0.\n";
684
685 PyObject* BL_ActionActuator::PySetBlendtime(PyObject* self, 
686                                                                                   PyObject* args, 
687                                                                                   PyObject* kwds) {
688         float blendframe;
689         
690         if (PyArg_ParseTuple(args,"f",&blendframe))
691         {
692                 m_blendframe = blendframe * m_blendin;
693                 if (m_blendframe<0)
694                         m_blendframe = 0;
695                 if (m_blendframe>m_blendin)
696                         m_blendframe = m_blendin;
697         }
698         
699         Py_INCREF(Py_None);
700         return Py_None;
701 }
702
703 /*     setPriority                                                           */
704 char BL_ActionActuator::SetPriority_doc[] = 
705 "setPriority(priority)\n"
706 "\t - priority  : Specifies the new priority.  Actuators will lower\n"
707 "\t               priority numbers will override actuators with higher\n"
708 "\t               numbers.\n";
709
710 PyObject* BL_ActionActuator::PySetPriority(PyObject* self, 
711                                                                                    PyObject* args, 
712                                                                                    PyObject* kwds) {
713         int priority;
714         
715         if (PyArg_ParseTuple(args,"i",&priority))
716         {
717                 m_priority = priority;
718         }
719         
720         Py_INCREF(Py_None);
721         return Py_None;
722 }
723
724 /*     setFrame                                                              */
725 char BL_ActionActuator::SetFrame_doc[] = 
726 "setFrame(frame)\n"
727 "\t - frame     : Specifies the new current frame for the animation\n";
728
729 PyObject* BL_ActionActuator::PySetFrame(PyObject* self, 
730                                                                                 PyObject* args, 
731                                                                                 PyObject* kwds) {
732         float frame;
733         
734         if (PyArg_ParseTuple(args,"f",&frame))
735         {
736                 m_localtime = frame;
737                 if (m_localtime<m_startframe)
738                         m_localtime=m_startframe;
739                 else if (m_localtime>m_endframe)
740                         m_localtime=m_endframe;
741         }
742         
743         Py_INCREF(Py_None);
744         return Py_None;
745 }
746
747 /*     setProperty                                                           */
748 char BL_ActionActuator::SetProperty_doc[] = 
749 "setProperty(prop)\n"
750 "\t - prop      : A string specifying the property name to be used in\n"
751 "\t               FromProp playback mode.\n";
752
753 PyObject* BL_ActionActuator::PySetProperty(PyObject* self, 
754                                                                                    PyObject* args, 
755                                                                                    PyObject* kwds) {
756         char *string;
757         
758         if (PyArg_ParseTuple(args,"s",&string))
759         {
760                 m_propname = string;
761         }
762         
763         Py_INCREF(Py_None);
764         return Py_None;
765 }
766
767 /*
768 PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, 
769                                                                                    PyObject* args, 
770                                                                                    PyObject* kwds) {
771         char *string;
772         
773         if (PyArg_ParseTuple(args,"s",&string))
774         {
775                 m_propname = string;
776         }
777         
778         Py_INCREF(Py_None);
779         return Py_None;
780 }
781 */
782
783 /*     setChannel                                                            */
784 char BL_ActionActuator::SetChannel_doc[] = 
785 "setChannel(channel, matrix)\n"
786 "\t - channel   : A string specifying the name of the bone channel.\n"
787 "\t - matrix    : A 4x4 matrix specifying the overriding transformation\n"
788 "\t               as an offset from the bone's rest position.\n";
789
790 PyObject* BL_ActionActuator::PySetChannel(PyObject* self, 
791                                                                                    PyObject* args, 
792                                                                                    PyObject* kwds) 
793 {
794         float matrix[4][4];
795         char *string;
796         PyObject* pylist;
797         bool    error = false;
798         int row,col;
799         int     mode = 0;       /* 0 for bone space, 1 for armature/world space */
800         
801         PyArg_ParseTuple(args,"sO|i", &string, &pylist, &mode);
802         
803         if (pylist->ob_type == &CListValue::Type)
804         {
805                 CListValue* listval = (CListValue*) pylist;
806                 if (listval->GetCount() == 4)
807                 {
808                         for (row=0;row<4;row++) // each row has a 4-vector [x,y,z, w]
809                         {
810                                 CListValue* vecval = (CListValue*)listval->GetValue(row);
811                                 for (col=0;col<4;col++)
812                                 {
813                                         matrix[row][col] = vecval->GetValue(col)->GetNumber();
814                                         
815                                 }
816                         }
817                 }
818                 else
819                 {
820                         error = true;
821                 }
822         }
823         else
824         {
825                 // assert the list is long enough...
826                 int numitems = PyList_Size(pylist);
827                 if (numitems == 4)
828                 {
829                         for (row=0;row<4;row++) // each row has a 4-vector [x,y,z, w]
830                         {
831                                 
832                                 PyObject* veclist = PyList_GetItem(pylist,row); // here we have a vector4 list
833                                 for (col=0;col<4;col++)
834                                 {
835                                         matrix[row][col] =  PyFloat_AsDouble(PyList_GetItem(veclist,col));
836                                         
837                                 }
838                         }
839                 }
840                 else
841                 {
842                         error = true;
843                 }
844         }
845         
846         if (!error)
847         {
848
849 /*      DO IT HERE */
850                 bPoseChannel *pchan= verify_pose_channel(m_userpose, string);
851
852                 Mat4ToQuat(matrix, pchan->quat);
853                 Mat4ToSize(matrix, pchan->size);
854                 VECCOPY (pchan->loc, matrix[3]);
855                 
856                 pchan->flag |= POSE_ROT|POSE_LOC|POSE_SIZE;
857
858                 if (!m_userpose){
859                         m_userpose = (bPose*)MEM_callocN(sizeof(bPose), "userPose");
860                 }
861         }
862         
863         Py_INCREF(Py_None);
864         return Py_None;
865 }
866
867 /* getType */
868 char BL_ActionActuator::GetType_doc[] =
869 "getType()\n"
870 "\tReturns the operation mode of the actuator.\n";
871 PyObject* BL_ActionActuator::PyGetType(PyObject* self,
872                                        PyObject* args, 
873                                        PyObject* kwds) {
874     return Py_BuildValue("h", m_playtype);
875 }
876
877 /* setType */
878 char BL_ActionActuator::SetType_doc[] =
879 "setType(mode)\n"
880 "\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
881 "\tSet the operation mode of the actuator.\n";
882 PyObject* BL_ActionActuator::PySetType(PyObject* self,
883                                        PyObject* args,
884                                        PyObject* kwds) {
885         short typeArg;
886                                                                                                              
887     if (!PyArg_ParseTuple(args, "h", &typeArg)) {
888         return NULL;
889     }
890
891         switch (typeArg) {
892         case KX_ACT_ACTION_PLAY:
893         case KX_ACT_ACTION_FLIPPER:
894         case KX_ACT_ACTION_LOOPSTOP:
895         case KX_ACT_ACTION_LOOPEND:
896         case KX_ACT_ACTION_PROPERTY:
897                 m_playtype = typeArg;
898                 break;
899         default:
900                 printf("Invalid type for action actuator: %d\n", typeArg); /* error */
901     }
902         
903     Py_Return;
904 }
905