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