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