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