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