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