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