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