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