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