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