synched with trunk at revision 30243
[blender.git] / source / gameengine / Converter / KX_ConvertActuators.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 * Convert Blender actuators for use in the GameEngine
29 */
30
31 #ifdef WIN32
32 #pragma warning (disable : 4786) 
33 #endif //WIN32
34
35 #define BLENDER_HACK_DTIME 0.02
36
37 #include "MEM_guardedalloc.h"
38
39 #include "KX_BlenderSceneConverter.h"
40 #include "KX_ConvertActuators.h"
41 #include "AUD_C-API.h"
42 // Actuators
43 //SCA logiclibrary native logicbricks
44 #include "SCA_PropertyActuator.h"
45 #include "SCA_LogicManager.h"
46 #include "SCA_RandomActuator.h"
47 #include "SCA_2DFilterActuator.h"
48
49 // Ketsji specific logicbricks
50 #include "KX_SceneActuator.h"
51 #include "KX_IpoActuator.h"
52 #include "KX_SoundActuator.h"
53 #include "KX_ObjectActuator.h"
54 #include "KX_TrackToActuator.h"
55 #include "KX_ConstraintActuator.h"
56 #include "KX_CameraActuator.h"
57 #include "KX_GameActuator.h"
58 #include "KX_StateActuator.h"
59 #include "KX_VisibilityActuator.h"
60 #include "KX_SCA_AddObjectActuator.h"
61 #include "KX_SCA_EndObjectActuator.h"
62 #include "KX_SCA_ReplaceMeshActuator.h"
63 #include "KX_ParentActuator.h"
64 #include "KX_SCA_DynamicActuator.h"
65 #include "KX_SteeringActuator.h"
66
67 #include "KX_Scene.h"
68 #include "KX_KetsjiEngine.h"
69
70 #include "IntValue.h"
71 #include "KX_GameObject.h"
72
73 /* This little block needed for linking to Blender... */
74 #include "BKE_text.h"
75 #include "BLI_blenlib.h"
76
77 #define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
78
79 #include "KX_NetworkMessageActuator.h"
80
81 #ifdef WIN32
82 #include "BLI_winstuff.h"
83 #endif
84
85 #include "DNA_object_types.h"
86 #include "DNA_sound_types.h"
87 #include "DNA_scene_types.h"
88 #include "DNA_actuator_types.h"
89 #include "DNA_packedFile_types.h"
90 #include "BL_ActionActuator.h"
91 #include "BL_ShapeActionActuator.h"
92 #include "BL_ArmatureActuator.h"
93 #include "RNA_access.h"
94 /* end of blender include block */
95
96 #include "BL_BlenderDataConversion.h"
97
98 /** 
99 KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set 
100 */
101
102 #define KX_BLENDERTRUNC(x)  (( x < 0.0001 && x > -0.0001 )  ? 0.0 : x)
103
104 void BL_ConvertActuators(char* maggiename,
105                                                  struct Object* blenderobject,
106                                                  KX_GameObject* gameobj,
107                                                  SCA_LogicManager* logicmgr,
108                                                  KX_Scene* scene,
109                                                  KX_KetsjiEngine* ketsjiEngine,
110                                                  int activeLayerBitInfo,
111                                                  bool isInActiveLayer,
112                                                  RAS_IRenderTools* rendertools,
113                                                  KX_BlenderSceneConverter* converter
114                                                  )
115 {
116         
117         int uniqueint = 0;
118         int actcount = 0;
119         int executePriority = 0;
120         bActuator* bact = (bActuator*) blenderobject->actuators.first;
121         while (bact)
122         {
123                 actcount++;
124                 bact = bact->next;
125         }
126         gameobj->ReserveActuator(actcount);
127         bact = (bActuator*) blenderobject->actuators.first;
128         while(bact)
129         {
130                 STR_String uniquename = bact->name;
131                 STR_String& objectname = gameobj->GetName();
132                 
133                 SCA_IActuator* baseact = NULL;
134                 switch (bact->type)
135                 {
136                 case ACT_OBJECT:
137                         {
138                                 bObjectActuator* obact = (bObjectActuator*) bact->data;
139                                 KX_GameObject* obref = NULL;
140                                 MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
141                                         KX_BLENDERTRUNC(obact->forceloc[1]),
142                                         KX_BLENDERTRUNC(obact->forceloc[2]));
143                                 MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
144                                 MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
145                                         KX_BLENDERTRUNC(obact->dloc[1]),
146                                         KX_BLENDERTRUNC(obact->dloc[2]));
147                                 MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
148                                 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
149                                         KX_BLENDERTRUNC(obact->linearvelocity[1]),
150                                         KX_BLENDERTRUNC(obact->linearvelocity[2]));
151                                 MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
152                                         KX_BLENDERTRUNC(obact->angularvelocity[1]),
153                                         KX_BLENDERTRUNC(obact->angularvelocity[2]));
154                                 short damping = obact->damping;
155                                 
156                                 drotvec /=              BLENDER_HACK_DTIME;
157                                 //drotvec /=            BLENDER_HACK_DTIME;
158                                 drotvec *= MT_2_PI/360.0;
159                                 //dlocvec /= BLENDER_HACK_DTIME;
160                                 //linvelvec /=  BLENDER_HACK_DTIME;
161                                 //angvelvec /=  BLENDER_HACK_DTIME;
162                                 
163                                 /* Blender uses a bit vector internally for the local-flags. In */
164                                 /* KX, we have four bools. The compiler should be smart enough  */
165                                 /* to do the right thing. We need to explicitly convert here!   */
166                                 
167                                 KX_LocalFlags bitLocalFlag;
168                                 
169                                 bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
170                                 bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
171                                 bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
172                                 bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
173                                 bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
174                                 bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
175                                 bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
176                                 bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
177                                 if (obact->reference && bitLocalFlag.ServoControl)
178                                 {
179                                         obref = converter->FindGameObject(obact->reference);
180                                 }
181                                 
182                                 KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
183                                         obref,
184                                         forcevec.getValue(),
185                                         torquevec.getValue(),
186                                         dlocvec.getValue(),
187                                         drotvec.getValue(),
188                                         linvelvec.getValue(),
189                                         angvelvec.getValue(),
190                                         damping,
191                                         bitLocalFlag
192                                         );
193                                 baseact = tmpbaseact;
194                                 break;
195                         }
196                 case ACT_ACTION:
197                         {
198                                 if (blenderobject->type==OB_ARMATURE){
199                                         bActionActuator* actact = (bActionActuator*) bact->data;
200                                         STR_String propname = (actact->name ? actact->name : "");
201                                         STR_String propframe = (actact->frameProp ? actact->frameProp : "");
202                                         
203                                         BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
204                                                 gameobj,
205                                                 propname,
206                                                 propframe,
207                                                 actact->sta,
208                                                 actact->end,
209                                                 actact->act,
210                                                 actact->type, // + 1, because Blender starts to count at zero,
211                                                 actact->blendin,
212                                                 actact->priority,
213                                                 actact->end_reset,
214                                                 actact->stridelength
215                                                 // Ketsji at 1, because zero is reserved for "NoDef"
216                                                 );
217                                         baseact= tmpbaseact;
218                                         break;
219                                 }
220                                 else
221                                         printf ("Discarded action actuator from non-armature object [%s]\n", blenderobject->id.name+2);
222                         }
223                 case ACT_SHAPEACTION:
224                         {
225                                 if (blenderobject->type==OB_MESH){
226                                         bActionActuator* actact = (bActionActuator*) bact->data;
227                                         STR_String propname = (actact->name ? actact->name : "");
228                                         STR_String propframe = (actact->frameProp ? actact->frameProp : "");
229                                         
230                                         BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
231                                                 gameobj,
232                                                 propname,
233                                                 propframe,
234                                                 actact->sta,
235                                                 actact->end,
236                                                 actact->act,
237                                                 actact->type, // + 1, because Blender starts to count at zero,
238                                                 actact->blendin,
239                                                 actact->priority,
240                                                 actact->stridelength
241                                                 // Ketsji at 1, because zero is reserved for "NoDef"
242                                                 );
243                                         baseact= tmpbaseact;
244                                         break;
245                                 }
246                                 else
247                                         printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
248                         }
249                 case ACT_IPO:
250                         {
251                                 bIpoActuator* ipoact = (bIpoActuator*) bact->data;
252                                 bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
253                                 STR_String propname = ipoact->name;
254                                 STR_String frameProp = ipoact->frameProp;
255                                 // first bit?
256                                 bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
257                                 bool local = (ipoact->flag & ACT_IPOLOCAL);
258                                 bool ipo_add = (ipoact->flag & ACT_IPOADD);
259                                 
260                                 KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
261                                         gameobj,
262                                         propname ,
263                                         frameProp,
264                                         ipoact->sta,
265                                         ipoact->end,
266                                         ipochild,
267                                         ipoact->type + 1, // + 1, because Blender starts to count at zero,
268                                         // Ketsji at 1, because zero is reserved for "NoDef"
269                                         ipo_as_force,
270                                         ipo_add,
271                                         local);
272                                 baseact = tmpbaseact;
273                                 break;
274                         }
275                 case ACT_LAMP:
276                         {
277                                 break;
278                         }
279                 case ACT_CAMERA:
280                         {
281                                 bCameraActuator *camact = (bCameraActuator *) bact->data;
282                                 if (camact->ob) {
283                                         KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
284                                         
285                                         /* visifac, fac and axis are not copied from the struct...   */ 
286                                         /* that's some internal state...                             */
287                                         KX_CameraActuator *tmpcamact
288                                                 = new KX_CameraActuator(gameobj,
289                                                 tmpgob,
290                                                 camact->height,
291                                                 camact->min,
292                                                 camact->max,
293                                                 camact->axis=='x');
294                                         baseact = tmpcamact;
295                                 }
296                                 break;
297                         }
298                 case ACT_MESSAGE:
299                         {
300                                 bMessageActuator *msgAct = (bMessageActuator *) bact->data;
301                                 
302                                 /**
303                                 * Get the name of the properties that objects must own that
304                                 * we're sending to, if present
305                                 */
306                                 STR_String toPropName = (msgAct->toPropName
307                                         ? (char*) msgAct->toPropName
308                                         : "");
309                                 
310                                 /**
311                                 * Get the Message Subject to send.
312                                 */
313                                 STR_String subject = (msgAct->subject
314                                         ? (char*) msgAct->subject
315                                         : "");
316                                 
317                                 /**
318                                 * Get the bodyType
319                                 */
320                                 int bodyType = msgAct->bodyType;
321                                 
322                                 /**
323                                 * Get the body (text message or property name whose value
324                                 * we'll be sending, might be empty
325                                 */
326                                 STR_String body = (msgAct->body
327                                         ? (char*) msgAct->body
328                                         : "");
329                                 
330                                 KX_NetworkMessageActuator *tmpmsgact = 
331                                         new KX_NetworkMessageActuator(
332                                         gameobj,                                        // actuator controlling object
333                                         scene->GetNetworkScene(),       // needed for replication
334                                         toPropName,
335                                         subject,
336                                         bodyType,
337                                         body);
338                                 baseact = tmpmsgact;
339                                 break;
340                         }
341                 case ACT_MATERIAL:
342                         {
343                                 break;
344                         }
345                 case ACT_SOUND:
346                         {
347                                 bSoundActuator* soundact = (bSoundActuator*) bact->data;
348                                 /* get type, and possibly a start and end frame */
349                                 KX_SoundActuator::KX_SOUNDACT_TYPE
350                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
351                                 
352                                 switch(soundact->type) {
353                                 case ACT_SND_PLAY_STOP_SOUND:
354                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
355                                         break;
356                                 case ACT_SND_PLAY_END_SOUND:
357                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
358                                         break;
359                                 case ACT_SND_LOOP_STOP_SOUND:
360                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
361                                         break;
362                                 case ACT_SND_LOOP_END_SOUND:
363                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
364                                         break;
365                                 case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
366                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
367                                         break;
368                                 case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
369                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
370                                         break;
371                                         
372                                 default:
373                                         /* This is an error!!! */
374                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
375                                 }
376                                 
377                                 if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) 
378                                 {
379                                         bSound* sound = soundact->sound;
380                                         bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
381                                         AUD_Sound* snd_sound = NULL;
382                                         KX_3DSoundSettings settings;
383                                         settings.cone_inner_angle = soundact->sound3D.cone_inner_angle;
384                                         settings.cone_outer_angle = soundact->sound3D.cone_outer_angle;
385                                         settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
386                                         settings.max_distance = soundact->sound3D.max_distance;
387                                         settings.max_gain = soundact->sound3D.max_gain;
388                                         settings.min_gain = soundact->sound3D.min_gain;
389                                         settings.reference_distance = soundact->sound3D.reference_distance;
390                                         settings.rolloff_factor = soundact->sound3D.rolloff_factor;
391
392                                         if(!sound)
393                                         {
394                                                 std::cout <<    "WARNING: Sound actuator \"" << bact->name <<
395                                                                                 "\" from object \"" <<  blenderobject->id.name+2 <<
396                                                                                 "\" has no sound datablock." << std::endl;
397                                         }
398                                         else
399                                                 snd_sound = sound->playback_handle;
400                                         KX_SoundActuator* tmpsoundact =
401                                                 new KX_SoundActuator(gameobj,
402                                                 snd_sound,
403                                                 soundact->volume,
404                                                 exp((soundact->pitch / 12.0) * log(2.0)),
405                                                 is3d,
406                                                 settings,
407                                                 soundActuatorType);
408
409                                         tmpsoundact->SetName(bact->name);
410                                         baseact = tmpsoundact;
411                                 }
412                                 break;
413                         }
414                 case ACT_PROPERTY:
415                         {
416                                 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
417                                 SCA_IObject* destinationObj = NULL;
418                                 
419                                 /*
420                                 here the destinationobject is searched. problem with multiple scenes: other scenes
421                                 have not been converted yet, so the destobj will not be found, so the prop will
422                                 not be copied.
423                                 possible solutions:
424                                 - convert everything when possible and not realtime only when needed.
425                                 - let the object-with-property report itself to the act when converted
426                                 */
427                                 if (propact->ob)
428                                         destinationObj = converter->FindGameObject(propact->ob);
429                                 
430                                 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
431                                         gameobj,
432                                         destinationObj,
433                                         propact->name,
434                                         propact->value,
435                                         propact->type+1); // + 1 because Ketsji Logic starts
436                                 // with 0 for KX_ACT_PROP_NODEF
437                                 baseact = tmppropact;
438                                 break;
439                         }
440                 case ACT_EDIT_OBJECT:
441                         {
442                                 bEditObjectActuator *editobact 
443                                         = (bEditObjectActuator *) bact->data;
444                                 /* There are four different kinds of 'edit object' thingies  */
445                                 /* The alternative to this lengthy conversion is packing     */
446                                 /* several actuators in one, which is not very nice design.. */
447                                 switch (editobact->type) {
448                                 case ACT_EDOB_ADD_OBJECT: 
449                                         {
450                                                 
451                                                 // does the 'original' for replication exists, and 
452                                                 // is it in a non-active layer ?
453                                                 SCA_IObject* originalval = NULL;
454                                                 if (editobact->ob)
455                                                 {
456                                                         if (editobact->ob->lay & activeLayerBitInfo)
457                                                         {
458                                                                 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
459                                                         }
460                                                         else {
461                                                                 originalval = converter->FindGameObject(editobact->ob);
462                                                         }
463                                                 }
464                                                 
465                                                 KX_SCA_AddObjectActuator* tmpaddact = 
466                                                         new KX_SCA_AddObjectActuator(
467                                                                 gameobj, 
468                                                                 originalval,
469                                                                 editobact->time,
470                                                                 scene,
471                                                                 editobact->linVelocity,
472                                                                 (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
473                                                                 editobact->angVelocity,
474                                                                 (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
475                                                                 );
476                                                                 
477                                                                 //editobact->ob to gameobj
478                                                                 baseact = tmpaddact;
479                                         }
480                                         break;
481                                 case ACT_EDOB_END_OBJECT:
482                                         {
483                                                 KX_SCA_EndObjectActuator* tmpendact 
484                                                         = new KX_SCA_EndObjectActuator(gameobj,scene);
485                                                 baseact = tmpendact;
486                                         }
487                                         break;
488                                 case ACT_EDOB_REPLACE_MESH:
489                                         {
490                                                 RAS_MeshObject *tmpmesh = NULL;
491                                                 if (editobact->me)
492                                                         tmpmesh = BL_ConvertMesh(
493                                                                 editobact->me,
494                                                                 blenderobject,
495                                                                 scene,
496                                                                 converter
497                                                                 );
498
499                                                 KX_SCA_ReplaceMeshActuator* tmpreplaceact
500                                                         = new KX_SCA_ReplaceMeshActuator(
501                                                                 gameobj,
502                                                                 tmpmesh,
503                                                                 scene,
504                                                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX)==0,
505                                                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS)!=0
506                                                                 
507                                                                 );
508                                                         
509                                                         baseact = tmpreplaceact;
510                                         }
511                                         break;
512                                 case ACT_EDOB_TRACK_TO:
513                                         {
514                                                 SCA_IObject* originalval = NULL;
515                                                 if (editobact->ob)
516                                                         originalval = converter->FindGameObject(editobact->ob);
517                                                         
518                                                 KX_TrackToActuator* tmptrackact 
519                                                         = new KX_TrackToActuator(gameobj, 
520                                                                 originalval,
521                                                                 editobact->time,
522                                                                 editobact->flag,
523                                                                 blenderobject->trackflag,
524                                                                 blenderobject->upflag
525                                                                 );
526                                                         baseact = tmptrackact;
527                                                 break;
528                                         }
529                                 case ACT_EDOB_DYNAMICS:
530                                         {
531                                                 KX_SCA_DynamicActuator* tmpdynact 
532                                                         = new KX_SCA_DynamicActuator(gameobj, 
533                                                                 editobact->dyn_operation,
534                                                                 editobact->mass
535                                                                 );
536                                                         baseact = tmpdynact;
537                                         }
538                                 }
539                                 break;
540                         }
541                 case ACT_CONSTRAINT:
542                         {
543                                 float min = 0.0, max = 0.0;
544                                 char *prop = NULL;
545                                 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
546                                 bConstraintActuator *conact 
547                                         = (bConstraintActuator*) bact->data;
548                                 /* convert settings... degrees in the ui become radians  */ 
549                                 /* internally                                            */ 
550                                 if (conact->type == ACT_CONST_TYPE_ORI) {
551                                         min = (MT_2_PI * conact->minloc[0])/360.0;
552                                         max = (MT_2_PI * conact->maxloc[0])/360.0;
553                                         switch (conact->mode) {
554                                         case ACT_CONST_DIRPX:
555                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
556                                                 break;
557                                         case ACT_CONST_DIRPY:
558                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
559                                                 break;
560                                         case ACT_CONST_DIRPZ:
561                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
562                                                 break;
563                                         }
564                                 } else if (conact->type == ACT_CONST_TYPE_DIST) {
565                                         switch (conact->mode) {
566                                         case ACT_CONST_DIRPX:
567                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
568                                                 min = conact->minloc[0];
569                                                 max = conact->maxloc[0];
570                                                 break;
571                                         case ACT_CONST_DIRPY:
572                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
573                                                 min = conact->minloc[1];
574                                                 max = conact->maxloc[1];
575                                                 break;
576                                         case ACT_CONST_DIRPZ:
577                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
578                                                 min = conact->minloc[2];
579                                                 max = conact->maxloc[2];
580                                                 break;
581                                         case ACT_CONST_DIRNX:
582                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
583                                                 min = conact->minloc[0];
584                                                 max = conact->maxloc[0];
585                                                 break;
586                                         case ACT_CONST_DIRNY:
587                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
588                                                 min = conact->minloc[1];
589                                                 max = conact->maxloc[1];
590                                                 break;
591                                         case ACT_CONST_DIRNZ:
592                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
593                                                 min = conact->minloc[2];
594                                                 max = conact->maxloc[2];
595                                                 break;
596                                         }
597                                         prop = conact->matprop;
598                                 } else if (conact->type == ACT_CONST_TYPE_FH) {
599                                         switch (conact->mode) {
600                                         case ACT_CONST_DIRPX:
601                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
602                                                 min = conact->minloc[0];
603                                                 max = conact->maxloc[0];
604                                                 break;
605                                         case ACT_CONST_DIRPY:
606                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
607                                                 min = conact->minloc[1];
608                                                 max = conact->maxloc[1];
609                                                 break;
610                                         case ACT_CONST_DIRPZ:
611                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
612                                                 min = conact->minloc[2];
613                                                 max = conact->maxloc[2];
614                                                 break;
615                                         case ACT_CONST_DIRNX:
616                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
617                                                 min = conact->minloc[0];
618                                                 max = conact->maxloc[0];
619                                                 break;
620                                         case ACT_CONST_DIRNY:
621                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
622                                                 min = conact->minloc[1];
623                                                 max = conact->maxloc[1];
624                                                 break;
625                                         case ACT_CONST_DIRNZ:
626                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
627                                                 min = conact->minloc[2];
628                                                 max = conact->maxloc[2];
629                                                 break;
630                                         }
631                                         prop = conact->matprop;
632                                 } else {
633                                         switch (conact->flag) {
634                                         case ACT_CONST_LOCX:
635                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
636                                                 min = conact->minloc[0];
637                                                 max = conact->maxloc[0];
638                                                 break;
639                                         case ACT_CONST_LOCY:
640                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
641                                                 min = conact->minloc[1];
642                                                 max = conact->maxloc[1];
643                                                 break;
644                                         case ACT_CONST_LOCZ:
645                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
646                                                 min = conact->minloc[2];
647                                                 max = conact->maxloc[2];
648                                                 break;
649                                         case ACT_CONST_ROTX:
650                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
651                                                 min = MT_2_PI * conact->minrot[0] / 360.0;
652                                                 max = MT_2_PI * conact->maxrot[0] / 360.0;
653                                                 break;
654                                         case ACT_CONST_ROTY:
655                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
656                                                 min = MT_2_PI * conact->minrot[1] / 360.0;
657                                                 max = MT_2_PI * conact->maxrot[1] / 360.0;
658                                                 break;
659                                         case ACT_CONST_ROTZ:
660                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
661                                                 min = MT_2_PI * conact->minrot[2] / 360.0;
662                                                 max = MT_2_PI * conact->maxrot[2] / 360.0;
663                                                 break;
664                                         default:
665                                                 ; /* error */ 
666                                         }
667                                 }
668                                 KX_ConstraintActuator *tmpconact 
669                                         = new KX_ConstraintActuator(gameobj,
670                                                 conact->damp,
671                                                 conact->rotdamp,
672                                                 min,
673                                                 max,
674                                                 conact->maxrot,
675                                                 locrot,
676                                                 conact->time,
677                                                 conact->flag,
678                                                 prop);
679                                 baseact = tmpconact;
680                                 break;
681                         }
682                 case ACT_GROUP:
683                         {
684                                 // deprecated
685                         }
686                         break;
687                 case ACT_SCENE:
688                         {
689                                 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
690                                 STR_String nextSceneName("");
691                                 
692                                 KX_SceneActuator* tmpsceneact;
693                                 int mode = KX_SceneActuator::KX_SCENE_NODEF;
694                                 KX_Camera *cam = NULL;
695                                 //KX_Scene* scene = NULL;
696                                 switch (sceneact->type)
697                                 {
698                                 case ACT_SCENE_RESUME:
699                                 case ACT_SCENE_SUSPEND:
700                                 case ACT_SCENE_ADD_FRONT:
701                                 case ACT_SCENE_ADD_BACK:
702                                 case ACT_SCENE_REMOVE:
703                                 case ACT_SCENE_SET:
704                                         {
705                                                 switch (sceneact->type)
706                                                 {
707                                                 case ACT_SCENE_RESUME:
708                                                         mode = KX_SceneActuator::KX_SCENE_RESUME;
709                                                         break;
710                                                 case ACT_SCENE_SUSPEND:
711                                                         mode = KX_SceneActuator::KX_SCENE_SUSPEND;
712                                                         break;
713                                                 case ACT_SCENE_ADD_FRONT:
714                                                         mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
715                                                         break;
716                                                 case ACT_SCENE_ADD_BACK:
717                                                         mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
718                                                         break;
719                                                 case ACT_SCENE_REMOVE:
720                                                         mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
721                                                         break;
722                                                 case ACT_SCENE_SET:
723                                                 default:
724                                                         mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
725                                                         break;
726                                                 };
727                                                 
728                                                 if (sceneact->scene)
729                                                 {
730                                                         nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
731                                                 }
732                                                 
733                                                 break;
734                                         }
735                                 case ACT_SCENE_CAMERA:
736                                         mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
737                                         if (sceneact->camera)
738                                         {
739                                                 cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
740                                         }
741                                         break;
742                                 case ACT_SCENE_RESTART:
743                                         {
744                                                 
745                                                 mode =  KX_SceneActuator::KX_SCENE_RESTART;
746                                                 break;
747                                         }
748                                 default:
749                                         ; /* flag error */
750                                 }
751                                 tmpsceneact = new KX_SceneActuator(gameobj,
752                                                 mode,
753                                                 scene,
754                                                 ketsjiEngine,
755                                                 nextSceneName,
756                                                 cam);
757                                         baseact = tmpsceneact;
758                                 break;
759                         }
760                 case ACT_GAME:
761                         {
762                                 bGameActuator *gameact = (bGameActuator *) bact->data;
763                                 KX_GameActuator* tmpgameact;
764                                 STR_String filename = maggiename;
765                                 STR_String loadinganimationname = "";
766                                 int mode = KX_GameActuator::KX_GAME_NODEF;
767                                 switch (gameact->type)
768                                 {
769                                 case ACT_GAME_LOAD:
770                                         {
771                                                 mode = KX_GameActuator::KX_GAME_LOAD;
772                                                 filename = gameact->filename;
773                                                 loadinganimationname = gameact->loadaniname;
774                                                 break;
775                                         }
776                                 case ACT_GAME_START:
777                                         {
778                                                 mode = KX_GameActuator::KX_GAME_START;
779                                                 filename = gameact->filename;
780                                                 loadinganimationname = gameact->loadaniname;
781                                                 break;
782                                         }
783                                 case ACT_GAME_RESTART:
784                                         {
785                                                 mode = KX_GameActuator::KX_GAME_RESTART;
786                                                 break;
787                                         }
788                                 case ACT_GAME_QUIT:
789                                         {
790                                                 mode = KX_GameActuator::KX_GAME_QUIT;
791                                                 break;
792                                         }
793                                 case ACT_GAME_SAVECFG:
794                                         {
795                                                 mode = KX_GameActuator::KX_GAME_SAVECFG;
796                                                 break;
797                                         }
798                                 case ACT_GAME_LOADCFG:
799                                         {
800                                                 mode = KX_GameActuator::KX_GAME_LOADCFG;
801                                                 break;
802                                         }
803                                 default:
804                                         ; /* flag error */
805                                 }
806                                         tmpgameact = new KX_GameActuator(gameobj,
807                                                 mode,
808                                                 filename,
809                                                 loadinganimationname,
810                                                 scene,
811                                                 ketsjiEngine);
812                                         baseact = tmpgameact;
813
814                                 break;
815                         }
816                 case ACT_RANDOM:
817                         {
818                                 bRandomActuator *randAct 
819                                         = (bRandomActuator *) bact->data;
820                                 
821                                 unsigned long seedArg = randAct->seed;
822                                 if (seedArg == 0)
823                                 {
824                                         seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
825                                         seedArg ^= (intptr_t)randAct;
826                                 }
827                                 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg 
828                                         = SCA_RandomActuator::KX_RANDOMACT_NODEF;
829                                 SCA_RandomActuator *tmprandomact;
830                                 float paraArg1 = 0.0;
831                                 float paraArg2 = 0.0;
832                                 
833                                 switch  (randAct->distribution) {
834                                 case ACT_RANDOM_BOOL_CONST:
835                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
836                                         paraArg1 = (float) randAct->int_arg_1;
837                                         break;
838                                 case ACT_RANDOM_BOOL_UNIFORM:
839                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
840                                         break;
841                                 case ACT_RANDOM_BOOL_BERNOUILLI:
842                                         paraArg1 = randAct->float_arg_1;
843                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
844                                         break;
845                                 case ACT_RANDOM_INT_CONST:
846                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
847                                         paraArg1 = (float) randAct->int_arg_1;
848                                         break;
849                                 case ACT_RANDOM_INT_UNIFORM:
850                                         paraArg1 = (float) randAct->int_arg_1;
851                                         paraArg2 = (float) randAct->int_arg_2;
852                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
853                                         break;
854                                 case ACT_RANDOM_INT_POISSON:
855                                         paraArg1 = randAct->float_arg_1;
856                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
857                                         break;
858                                 case ACT_RANDOM_FLOAT_CONST:
859                                         paraArg1 = randAct->float_arg_1;
860                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
861                                         break;
862                                 case ACT_RANDOM_FLOAT_UNIFORM:
863                                         paraArg1 = randAct->float_arg_1;
864                                         paraArg2 = randAct->float_arg_2;
865                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
866                                         break;
867                                 case ACT_RANDOM_FLOAT_NORMAL:
868                                         paraArg1 = randAct->float_arg_1;
869                                         paraArg2 = randAct->float_arg_2;
870                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
871                                         break;
872                                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
873                                         paraArg1 = randAct->float_arg_1;
874                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
875                                         break;
876                                 default:
877                                         ; /* error */                           
878                                 }
879                                 tmprandomact = new SCA_RandomActuator(gameobj,
880                                         seedArg,
881                                         modeArg, 
882                                         paraArg1,
883                                         paraArg2,
884                                         randAct->propname);
885                                 baseact = tmprandomact;
886                         }
887                         break;
888
889                 case ACT_VISIBILITY:
890                 {
891                         bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
892                         KX_VisibilityActuator * tmp_vis_act = NULL;
893                         bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
894                         bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
895                         bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
896
897                         tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
898                         
899                         baseact = tmp_vis_act;
900                 }
901                 break;
902
903                 case ACT_STATE:
904                 {
905                         bStateActuator *sta_act = (bStateActuator *) bact->data;
906                         KX_StateActuator * tmp_sta_act = NULL;
907
908                         tmp_sta_act = 
909                                 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
910                         
911                         baseact = tmp_sta_act;
912                 }
913                 break;
914
915                 case ACT_2DFILTER:
916                 {
917                         bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
918             SCA_2DFilterActuator *tmp = NULL;
919
920                         RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
921                         switch(_2dfilter->type)
922                         {
923                                 case ACT_2DFILTER_MOTIONBLUR:
924                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
925                                         break;
926                                 case ACT_2DFILTER_BLUR:
927                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
928                                         break;
929                                 case ACT_2DFILTER_SHARPEN:
930                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
931                                         break;
932                                 case ACT_2DFILTER_DILATION:
933                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
934                                         break;
935                                 case ACT_2DFILTER_EROSION:
936                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
937                                         break;
938                                 case ACT_2DFILTER_LAPLACIAN:
939                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
940                                         break;
941                                 case ACT_2DFILTER_SOBEL:
942                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
943                                         break;
944                                 case ACT_2DFILTER_PREWITT:
945                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
946                                         break;
947                                 case ACT_2DFILTER_GRAYSCALE:
948                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
949                                         break;
950                                 case ACT_2DFILTER_SEPIA:
951                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
952                                         break;
953                                 case ACT_2DFILTER_INVERT:
954                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
955                                         break;
956                                 case ACT_2DFILTER_CUSTOMFILTER:
957                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
958                                         break;
959                                 case ACT_2DFILTER_NOFILTER:
960                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
961                                         break;
962                                 case ACT_2DFILTER_DISABLED:
963                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
964                                         break;
965                                 case ACT_2DFILTER_ENABLED:
966                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
967                                         break;
968                                 default:
969                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
970                                         break;
971                         }
972             
973                         tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
974                                 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
975
976                         if (_2dfilter->text)
977                         {
978                                 char *buf;
979                                 // this is some blender specific code
980                                 buf = txt_to_buf(_2dfilter->text);
981                                 if (buf)
982                                 {
983                                         tmp->SetShaderText(buf);
984                                         MEM_freeN(buf);
985                                 }
986                         }
987
988             baseact = tmp;
989                         
990                 }
991                 break;
992                 case ACT_PARENT:
993                         {
994                                 bParentActuator *parAct = (bParentActuator *) bact->data;
995                                 int mode = KX_ParentActuator::KX_PARENT_NODEF;
996                                 bool addToCompound = true;
997                                 bool ghost = true;
998                                 KX_GameObject *tmpgob = NULL;
999
1000                                 switch(parAct->type)
1001                                 {
1002                                         case ACT_PARENT_SET:
1003                                                 mode = KX_ParentActuator::KX_PARENT_SET;
1004                                                 tmpgob = converter->FindGameObject(parAct->ob);
1005                                                 addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
1006                                                 ghost = !(parAct->flag & ACT_PARENT_GHOST);
1007                                                 break;
1008                                         case ACT_PARENT_REMOVE:
1009                                                 mode = KX_ParentActuator::KX_PARENT_REMOVE;
1010                                                 tmpgob = NULL;
1011                                                 break;
1012                                 }
1013         
1014                                 KX_ParentActuator *tmpparact
1015                                         = new KX_ParentActuator(gameobj,
1016                                         mode,
1017                                         addToCompound,
1018                                         ghost,
1019                                         tmpgob);
1020                                 baseact = tmpparact;
1021                                 break;
1022                         }
1023                 
1024                 case ACT_ARMATURE:
1025                         {
1026                                 bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
1027                                 KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
1028                                 KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
1029                                 BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(gameobj, armAct->type, armAct->posechannel, armAct->constraint, tmpgob, subgob, armAct->weight);
1030                                 baseact = tmparmact;
1031                                 break;
1032                         }
1033                 case ACT_STEERING:
1034                         {
1035                                 bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
1036                                 KX_GameObject *navmeshob = NULL;
1037                                 if (stAct->navmesh)
1038                                 {
1039                                         PointerRNA settings_ptr;
1040                                         RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
1041                                         if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
1042                                                 navmeshob = converter->FindGameObject(stAct->navmesh);
1043                                 }
1044                                 KX_GameObject *targetob = converter->FindGameObject(stAct->target);
1045
1046                                 int mode = KX_SteeringActuator::KX_STEERING_NODEF;
1047                                 switch(stAct->type)
1048                                 {
1049                                 case ACT_STEERING_SEEK:
1050                                         mode = KX_SteeringActuator::KX_STEERING_SEEK;
1051                                         break;
1052                                 case ACT_STEERING_FLEE:
1053                                         mode = KX_SteeringActuator::KX_STEERING_FLEE;
1054                                         break;
1055                                 case ACT_STEERING_PATHFOLLOWING:
1056                                         mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
1057                                         break;
1058                                 }
1059
1060                                 bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
1061                                 KX_SteeringActuator *tmpstact
1062                                         = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist, 
1063                                                                 stAct->velocity, stAct->acceleration, stAct->turnspeed, 
1064                                                                 selfTerminated, stAct->updateTime,
1065                                                                 scene->GetObstacleSimulation());
1066                                 baseact = tmpstact;
1067                                 break;
1068                         }
1069                 default:
1070                         ; /* generate some error */
1071                 }
1072                 
1073                 if (baseact)
1074                 {
1075                         baseact->SetExecutePriority(executePriority++);
1076                         uniquename += "#ACT#";
1077                         uniqueint++;
1078                         CIntValue* uniqueval = new CIntValue(uniqueint);
1079                         uniquename += uniqueval->GetText();
1080                         uniqueval->Release();
1081                         baseact->SetName(bact->name);
1082                         //gameobj->SetProperty(uniquename,baseact);
1083                         gameobj->AddActuator(baseact);
1084                         
1085                         converter->RegisterGameActuator(baseact, bact);
1086                         // done with baseact, release it
1087                         baseact->Release();
1088                 }
1089                 
1090                 bact = bact->next;
1091         }
1092 }
1093
1094